| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ libgit2.types.forEach(function(type) { | |||
| 18 | 18 | Array.prototype.push.apply(libgit2.types, supplement.new.types); | |
| 19 | 19 | ||
| 20 | 20 | var output = []; | |
| 21 | - var groupNames = []; | ||
| 22 | 21 | var dependencyLookup = {}; | |
| 23 | 22 | var types = []; | |
| 24 | 23 | var enums = []; | |
@@ -27,43 +26,36 @@ var enums = []; | |||
| 27 | 26 | var groups = libgit2.groups.reduce(function(memo, group) { | |
| 28 | 27 | group[1].typeName = group[0]; | |
| 29 | 28 | memo[group[0]] = group[1]; | |
| 30 | - groupNames.push(group[0]); | ||
| 31 | 29 | return memo; | |
| 32 | 30 | }, {}); | |
| 33 | 31 | ||
| 34 | 32 | ||
| 35 | - // Process each type in the types array into classes and structs and | ||
| 36 | - // decorate the definitions with required data to build the C++ files | ||
| 33 | + // Split each type from the array into classes/structs and enums | ||
| 34 | + // each entry is of type ['name', {definingobject}] | ||
| 37 | 35 | libgit2.types.forEach(function(current) { | |
| 38 | - var typeName = current[0]; | ||
| 39 | - var typeDefOverrides = descriptor.types[typeName] || {}; | ||
| 40 | - var typeDef = current[1]; | ||
| 41 | - | ||
| 42 | - typeDef.typeName = typeName; | ||
| 36 | + current[1].typeName = current[0]; | ||
| 43 | 37 | ||
| 44 | 38 | // just log these out to a file for fun | |
| 45 | - if (typeDef.type === "enum") { | ||
| 46 | - enums.push(typeDef); | ||
| 39 | + if (current[1].type === "enum") { | ||
| 40 | + enums.push(current[1]); | ||
| 47 | 41 | } | |
| 48 | 42 | else { | |
| 49 | - types.push(typeDef); | ||
| 43 | + types.push(current[1]); | ||
| 50 | 44 | } | |
| 51 | 45 | }); | |
| 52 | 46 | ||
| 53 | - enums = _.sortBy(enums, "name"); | ||
| 54 | - | ||
| 55 | 47 | var previous = ""; | |
| 56 | - enums = enums.reduce(function(enumMemo, enumerable) { | ||
| 48 | + enums = _(enums).sortBy("name").reduce(function(enumMemo, enumerable) { | ||
| 57 | 49 | if (previous == enumerable.typeName) { | |
| 58 | - console.log('WARNING: duplicate definition for enum ' + enumerable.name + | ||
| 50 | + console.log('WARNING: duplicate definition for enum ' + enumerable.typeName + | ||
| 59 | 51 | ". skipped."); | |
| 60 | 52 | } | |
| 61 | 53 | else if (!enumerable.fields) { | |
| 62 | - console.log('WARNING: incomplete definition for enum ' + enumerable.name + | ||
| 54 | + console.log('WARNING: incomplete definition for enum ' + enumerable.typeName + | ||
| 63 | 55 | ". skipped."); | |
| 64 | 56 | } | |
| 65 | 57 | else { | |
| 66 | - enumMemo.push({ | ||
| 58 | + enumMemo[enumerable.typeName] = { | ||
| 67 | 59 | name: enumerable.typeName.replace(/^git_/, "").replace(/_t$/, ""), | |
| 68 | 60 | cType: enumerable.typeName, | |
| 69 | 61 | isMask: (/_t$/).test(enumerable.typeName), | |
@@ -73,33 +65,28 @@ enums = enums.reduce(function(enumMemo, enumerable) { | |||
| 73 | 65 | value: field.value | |
| 74 | 66 | } | |
| 75 | 67 | }) | |
| 76 | - }); | ||
| 68 | + }; | ||
| 77 | 69 | } | |
| 78 | 70 | ||
| 79 | - previous = enumerable.name; | ||
| 71 | + previous = enumerable.typeName; | ||
| 80 | 72 | return enumMemo; | |
| 81 | - }, []); | ||
| 73 | + }, []).valueOf(); | ||
| 82 | 74 | ||
| 75 | + // decorate the definitions with required data to build the C++ files | ||
| 83 | 76 | types.forEach(function(typeDef) { | |
| 84 | 77 | var typeName = typeDef.typeName; | |
| 85 | 78 | typeDef.cType = typeName; | |
| 86 | 79 | typeName = typeName.replace("git_", ""); | |
| 87 | 80 | typeDef.typeName = typeName; | |
| 88 | 81 | dependencyLookup[typeName] = typeName; | |
| 89 | 82 | ||
| 90 | - typeDef.isClass = utils.isClass(typeName, groupNames); | ||
| 83 | + typeDef.isClass = !!groups[typeName]; | ||
| 91 | 84 | typeDef.isStruct = !typeDef.isClass; | |
| 92 | 85 | ||
| 93 | - utils.decoratePrimaryType(typeDef); | ||
| 86 | + typeDef.functions = groups[typeName] || []; | ||
| 87 | + utils.decoratePrimaryType(typeDef, enums); | ||
| 94 | 88 | ||
| 95 | - if (typeDef.isClass) { | ||
| 96 | - typeDef.functions = groups[typeName]; | ||
| 97 | - utils.decorateClass(typeDef); | ||
| 98 | - groups[typeName] = false; | ||
| 99 | - } | ||
| 100 | - else { | ||
| 101 | - utils.decorateStruct(typeDef); | ||
| 102 | - } | ||
| 89 | + groups[typeName] = false; | ||
| 103 | 90 | ||
| 104 | 91 | output.push(typeDef); | |
| 105 | 92 | }); | |
@@ -115,14 +102,12 @@ for (var groupName in groups) { | |||
| 115 | 102 | functions: groupDef | |
| 116 | 103 | }; | |
| 117 | 104 | ||
| 118 | - var classDefOverrides = descriptor.types[groupName] || {}; | ||
| 119 | 105 | groupDef.isClass = true; | |
| 120 | 106 | groupDef.isStruct = false; | |
| 121 | 107 | ||
| 122 | 108 | groupDef.typeName = groupName; | |
| 123 | 109 | dependencyLookup[groupName] = groupName; | |
| 124 | - utils.decoratePrimaryType(groupDef); | ||
| 125 | - utils.decorateClass(groupDef, classDefOverrides); | ||
| 110 | + utils.decoratePrimaryType(groupDef, enums); | ||
| 126 | 111 | ||
| 127 | 112 | output.push(groupDef); | |
| 128 | 113 | } | |
@@ -164,19 +149,19 @@ output.forEach(function (def) { | |||
| 164 | 149 | // Process enums | |
| 165 | 150 | enums.forEach(function(enumerable) { | |
| 166 | 151 | output.some(function(obj) { | |
| 167 | - if (enumerable.name.indexOf(obj.typeName) == 0) { | ||
| 152 | + if (enumerable.typeName.indexOf(obj.typeName) == 0) { | ||
| 168 | 153 | enumerable.owner = obj.jsClassName; | |
| 169 | 154 | } | |
| 170 | 155 | else if (enumerable.owner) { | |
| 171 | 156 | return true; | |
| 172 | 157 | } | |
| 173 | 158 | }); | |
| 174 | 159 | ||
| 175 | - var override = descriptor.enums[enumerable.name] || {}; | ||
| 160 | + var override = descriptor.enums[enumerable.typeName] || {}; | ||
| 176 | 161 | ||
| 177 | 162 | enumerable.owner = enumerable.owner || "Enums"; | |
| 178 | 163 | ||
| 179 | - enumerable.JsName = enumerable.name | ||
| 164 | + enumerable.JsName = enumerable.typeName | ||
| 180 | 165 | .replace(new RegExp("^" + enumerable.owner.toLowerCase()), "") | |
| 181 | 166 | .replace(/^_/, "") | |
| 182 | 167 | .toUpperCase(); | |
@@ -212,6 +197,9 @@ if (process.argv[2] != "--documentation") { | |||
| 212 | 197 | utils.filterDocumentation(output); | |
| 213 | 198 | } | |
| 214 | 199 | ||
| 200 | + fs.writeFileSync(path.join(__dirname, "output.json"), | ||
| 201 | + JSON.stringify(output, null, 2)); | ||
| 202 | + | ||
| 215 | 203 | output = {types: output, enums: enums}; | |
| 216 | 204 | ||
| 217 | 205 | fs.writeFileSync(path.join(__dirname, "idefs.json"), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,10 +105,6 @@ var Utils = { | |||
| 105 | 105 | && ~cbField.name.indexOf(payloadName.replace("_payload", "")); | |
| 106 | 106 | }, | |
| 107 | 107 | ||
| 108 | - isClass: function(typeName, groupNames) { | ||
| 109 | - return !!~groupNames.indexOf(typeName); | ||
| 110 | - }, | ||
| 111 | - | ||
| 112 | 108 | getLibgitType: function(normalizedType, types) { | |
| 113 | 109 | var libgitType; | |
| 114 | 110 | ||
@@ -153,7 +149,7 @@ var Utils = { | |||
| 153 | 149 | } | |
| 154 | 150 | }, | |
| 155 | 151 | ||
| 156 | - decorateLibgitType: function(type, types) { | ||
| 152 | + decorateLibgitType: function(type, types, enums) { | ||
| 157 | 153 | var normalizedType = Utils.normalizeCtype(type.cType); | |
| 158 | 154 | var libgitType = Utils.getLibgitType(normalizedType, types); | |
| 159 | 155 | ||
@@ -166,69 +162,52 @@ var Utils = { | |||
| 166 | 162 | if (type.isEnum) { | |
| 167 | 163 | type.cppClassName = "Number"; | |
| 168 | 164 | type.jsClassName = "Number"; | |
| 165 | + if (enums[type.cType]) { | ||
| 166 | + type.isMask = enums[type.cType].isMask || false | ||
| 167 | + } | ||
| 169 | 168 | } | |
| 170 | - | ||
| 171 | 169 | _.merge(type, descriptor.types[normalizedType.replace("git_", "")] || {}); | |
| 172 | 170 | } | |
| 173 | 171 | }, | |
| 174 | 172 | ||
| 175 | - decoratePrimaryType: function(typeDef) { | ||
| 173 | + decoratePrimaryType: function(typeDef, enums) { | ||
| 176 | 174 | var typeDefOverrides = descriptor.types[typeDef.typeName] || {}; | |
| 177 | 175 | var partialOverrides = _.omit(typeDefOverrides, ["fields", "functions"]); | |
| 178 | 176 | ||
| 179 | 177 | typeDef.cType = typeDef.cType || null; | |
| 180 | 178 | typeDef.cppClassName = Utils.cTypeToCppName(typeDef.cType || "git_" + typeDef.typeName); | |
| 181 | 179 | typeDef.jsClassName = Utils.titleCase(Utils.cTypeToJsName(typeDef.cType || "git_" + typeDef.typeName)); | |
| 182 | - | ||
| 183 | - typeDef.dependencies = []; | ||
| 184 | 180 | typeDef.filename = typeDef.typeName; | |
| 181 | + typeDef.isLibgitType = true; | ||
| 182 | + typeDef.dependencies = []; | ||
| 185 | 183 | ||
| 186 | 184 | typeDef.fields = typeDef.fields || []; | |
| 187 | - | ||
| 188 | 185 | typeDef.fields.forEach(function (field, index, allFields) { | |
| 189 | 186 | var fieldOverrides = typeDefOverrides.fields || {}; | |
| 190 | - Utils.decorateField(field, allFields, fieldOverrides[field.name] || {}); | ||
| 187 | + Utils.decorateField(field, allFields, fieldOverrides[field.name] || {}, enums); | ||
| 191 | 188 | }); | |
| 192 | 189 | ||
| 193 | 190 | typeDef.needsForwardDeclaration = typeDef.decl === typeDef.cType; | |
| 194 | 191 | ||
| 195 | - _.merge(typeDef, partialOverrides); | ||
| 196 | - }, | ||
| 192 | + var normalizedType = Utils.normalizeCtype(typeDef.cType); | ||
| 193 | + typeDef.hasConstructor = Utils.hasConstructor(typeDef, normalizedType); | ||
| 197 | 194 | ||
| 198 | - decorateStruct: function(structDef) { | ||
| 199 | - /* There are no enums for now, and when we get there I'm gonna argue they should have | ||
| 200 | - their own process | ||
| 201 | - if (structDef.type === "enum") { | ||
| 202 | - structDef.isEnum = true; | ||
| 203 | - structDef.cppClassName = "Number"; | ||
| 204 | - structDef.jsClassName = "Number"; | ||
| 205 | - } */ | ||
| 206 | - | ||
| 207 | - structDef.isLibgitType = true; | ||
| 208 | - | ||
| 209 | - // TODO: Structs don't *have* functions, we need to remove the code thats requiring this (if there even is any) | ||
| 210 | - structDef.functions = []; | ||
| 211 | - | ||
| 212 | - var normalizedType = Utils.normalizeCtype(structDef.cType); | ||
| 213 | - structDef.hasConstructor = Utils.hasConstructor(structDef, normalizedType); | ||
| 214 | - }, | ||
| 215 | - | ||
| 216 | - decorateClass: function(classDef) { | ||
| 217 | - var typeDefOverrides = descriptor.types[classDef.typeName] || {}; | ||
| 218 | - | ||
| 219 | - classDef.functions = (classDef.functions || []).map(function(fn) { | ||
| 195 | + typeDef.functions = (typeDef.functions).map(function(fn) { | ||
| 220 | 196 | var fnDef = libgit2.functions[fn]; | |
| 221 | 197 | fnDef.cFunctionName = fn; | |
| 222 | 198 | return fnDef; | |
| 223 | 199 | }); | |
| 224 | 200 | ||
| 201 | + var typeDefOverrides = descriptor.types[typeDef.typeName] || {}; | ||
| 225 | 202 | var functionOverrides = typeDefOverrides.functions || {}; | |
| 226 | - classDef.functions.forEach(function(fnDef) { | ||
| 227 | - Utils.decorateFunction(fnDef, classDef, functionOverrides[fnDef.cFunctionName] || {}); | ||
| 203 | + typeDef.functions.forEach(function(fnDef) { | ||
| 204 | + Utils.decorateFunction(fnDef, typeDef, functionOverrides[fnDef.cFunctionName] || {}, enums); | ||
| 228 | 205 | }); | |
| 206 | + | ||
| 207 | + _.merge(typeDef, partialOverrides); | ||
| 229 | 208 | }, | |
| 230 | 209 | ||
| 231 | - decorateField: function(field, allFields, fieldOverrides) { | ||
| 210 | + decorateField: function(field, allFields, fieldOverrides, enums) { | ||
| 232 | 211 | var normalizeType = Utils.normalizeCtype(field.type); | |
| 233 | 212 | ||
| 234 | 213 | field.cType = field.type; | |
@@ -243,7 +222,7 @@ var Utils = { | |||
| 243 | 222 | var argOverrides = fieldOverrides.args || {}; | |
| 244 | 223 | field.args = field.args || []; | |
| 245 | 224 | field.args.forEach(function (arg) { | |
| 246 | - Utils.decorateArg(arg, null, null, argOverrides[arg.name] || {}); | ||
| 225 | + Utils.decorateArg(arg, null, null, argOverrides[arg.name] || {}, enums); | ||
| 247 | 226 | }); | |
| 248 | 227 | } | |
| 249 | 228 | else { | |
@@ -254,26 +233,26 @@ var Utils = { | |||
| 254 | 233 | } | |
| 255 | 234 | } | |
| 256 | 235 | ||
| 257 | - Utils.decorateLibgitType(field, libgit2.types); | ||
| 236 | + Utils.decorateLibgitType(field, libgit2.types, enums); | ||
| 258 | 237 | _.merge(field, fieldOverrides); | |
| 259 | 238 | }, | |
| 260 | 239 | ||
| 261 | - decorateArg: function(arg, classDef, fnDef, argOverrides) { | ||
| 240 | + decorateArg: function(arg, typeDef, fnDef, argOverrides, enums) { | ||
| 262 | 241 | var type = arg.cType || arg.type; | |
| 263 | 242 | var normalizedType = Utils.normalizeCtype(type); | |
| 264 | 243 | ||
| 265 | 244 | arg.cType = type; | |
| 266 | 245 | arg.cppClassName = Utils.cTypeToCppName(arg.cType); | |
| 267 | 246 | arg.jsClassName = Utils.titleCase(Utils.cTypeToJsName(arg.cType)); | |
| 268 | 247 | ||
| 269 | - Utils.decorateLibgitType(arg, libgit2.types); | ||
| 248 | + Utils.decorateLibgitType(arg, libgit2.types, enums); | ||
| 270 | 249 | ||
| 271 | - if (classDef && fnDef) { | ||
| 250 | + if (typeDef && fnDef) { | ||
| 272 | 251 | // Mark all of the args that are either returns or are the object | |
| 273 | 252 | // itself and determine if this function goes on the prototype | |
| 274 | 253 | // or is a constructor method. | |
| 275 | - arg.isReturn = arg.name === "out" || (Utils.isDoublePointer(arg.type) && normalizedType == classDef.cType); | ||
| 276 | - arg.isSelf = Utils.isPointer(arg.type) && normalizedType == classDef.cType; | ||
| 254 | + arg.isReturn = arg.name === "out" || (Utils.isDoublePointer(arg.type) && normalizedType == typeDef.cType); | ||
| 255 | + arg.isSelf = Utils.isPointer(arg.type) && normalizedType == typeDef.cType; | ||
| 277 | 256 | ||
| 278 | 257 | if (arg.isReturn && fnDef.return && fnDef.return.type === "int") { | |
| 279 | 258 | fnDef.return.isErrorCode = true; | |
@@ -292,34 +271,34 @@ var Utils = { | |||
| 292 | 271 | _.merge(arg, argOverrides); | |
| 293 | 272 | }, | |
| 294 | 273 | ||
| 295 | - decorateFunction: function(fnDef, classDef, fnOverrides) { | ||
| 274 | + decorateFunction: function(fnDef, typeDef, fnOverrides, enums) { | ||
| 296 | 275 | var key = fnDef.cFunctionName; | |
| 297 | 276 | ||
| 298 | 277 | // if this is the free function for the class, make the ref on the class | |
| 299 | 278 | // and then return since we don't want the free functions publicly | |
| 300 | 279 | // available | |
| 301 | - if (key == classDef.cType + "_free") { | ||
| 302 | - classDef.freeFunctionName = key; | ||
| 280 | + if (key == typeDef.cType + "_free") { | ||
| 281 | + typeDef.freeFunctionName = key; | ||
| 303 | 282 | fnDef.ignore = true; | |
| 304 | 283 | return; | |
| 305 | 284 | } | |
| 306 | 285 | ||
| 307 | - fnDef.cppFunctionName = Utils.cTypeToCppName(key, "git_" + classDef.typeName); | ||
| 308 | - fnDef.jsFunctionName = Utils.cTypeToJsName(key, "git_" + classDef.typeName); | ||
| 286 | + fnDef.cppFunctionName = Utils.cTypeToCppName(key, "git_" + typeDef.typeName); | ||
| 287 | + fnDef.jsFunctionName = Utils.cTypeToJsName(key, "git_" + typeDef.typeName); | ||
| 309 | 288 | //fnDef.isAsync = false; // until proven otherwise | |
| 310 | 289 | ||
| 311 | 290 | ||
| 312 | - if (fnDef.cppFunctionName == classDef.cppClassName) { | ||
| 291 | + if (fnDef.cppFunctionName == typeDef.cppClassName) { | ||
| 313 | 292 | fnDef.cppFunctionName = fnDef.cppFunctionName.replace("Git", ""); | |
| 314 | 293 | } | |
| 315 | 294 | ||
| 316 | 295 | var argOverrides = fnOverrides.args || {}; | |
| 317 | 296 | fnDef.args.forEach(function(arg) { | |
| 318 | - Utils.decorateArg(arg, classDef, fnDef, argOverrides[arg.name] || {}); | ||
| 297 | + Utils.decorateArg(arg, typeDef, fnDef, argOverrides[arg.name] || {}, enums); | ||
| 319 | 298 | }); | |
| 320 | 299 | ||
| 321 | 300 | if (fnDef.return) { | |
| 322 | - Utils.decorateArg(fnDef.return, classDef, fnDef, fnOverrides.return || {}); | ||
| 301 | + Utils.decorateArg(fnDef.return, typeDef, fnDef, fnOverrides.return || {}, enums); | ||
| 323 | 302 | } | |
| 324 | 303 | ||
| 325 | 304 | _(collisionMappings).forEach(function(newName, collidingName) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments