diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-05-16 14:01:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-05-16 14:01:06 -0700 |
commit | 67fd8548d4cd14ec829d8bac929e8c59863b53eb (patch) | |
tree | 3e879ebea38999eaffeb211eb98bcf364353c5c2 | |
parent | df3638c87ae2c9c617bf04adbc7140a7155cc844 (diff) |
compiler code is now js strict mode compliant
-rw-r--r-- | src/analyzer.js | 4 | ||||
-rw-r--r-- | src/framework.js | 1 | ||||
-rw-r--r-- | src/intertyper.js | 17 | ||||
-rw-r--r-- | src/jsifier.js | 16 | ||||
-rw-r--r-- | src/library.js | 3 | ||||
-rw-r--r-- | src/parseTools.js | 14 | ||||
-rw-r--r-- | src/utility.js | 1 |
7 files changed, 31 insertions, 25 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 1b438db4..e6ff4a24 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -391,7 +391,7 @@ function analyzer(data) { function get() { if (param.intertype === 'value' && !isNumber(param.ident)) { if (func.variables[param.ident]) { - return func.variables[param.ident].originalType; + return func.variables[param.ident].originalType || null; } else { return item.globalVariables[param.ident].originalType; } @@ -1034,7 +1034,7 @@ function analyzer(data) { } return true; } - assert(false); + return assert(false); } // TODO: Parallelize diff --git a/src/framework.js b/src/framework.js index 9e0d163d..e682d547 100644 --- a/src/framework.js +++ b/src/framework.js @@ -134,6 +134,7 @@ Substrate.prototype = { } midComment(); } + return null; } }; diff --git a/src/intertyper.js b/src/intertyper.js index a3c572a6..c76c3637 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -221,16 +221,17 @@ function intertyper(data, parseFunctions, baseLineNum) { } } } - var item = { + var newItem = { tokens: tokens, indent: lineText.search(/[^ ]/), lineNum: item.lineNum }; if (inner) { - return item; + return newItem; } else { - this.forwardItem(item, 'Triager'); + this.forwardItem(newItem, 'Triager'); } + return null; } }); @@ -329,11 +330,11 @@ function intertyper(data, parseFunctions, baseLineNum) { return { intertype: 'emptystruct', type: segment[0].text }; } else if (segment[1].text in PARSABLE_LLVM_FUNCTIONS) { return parseLLVMFunctionCall(segment); - } else if (segment[1].type == '{') { + } else if (segment[1].type && segment[1].type == '{') { return { intertype: 'struct', type: segment[0].text, contents: handleSegments(segment[1].tokens) }; - } else if (segment[1].type == '<') { + } else if (segment[1].type && segment[1].type == '<') { return { intertype: 'struct', type: segment[0].text, contents: handleSegments(segment[1].item.tokens[0].tokens) }; - } else if (segment[1].type == '[') { + } else if (segment[1].type && segment[1].type == '[') { return { intertype: 'list', type: segment[0].text, contents: handleSegments(segment[1].item.tokens) }; } else if (segment.length == 2) { return { intertype: 'value', value: toNiceIdent(segment[1].text) }; @@ -368,7 +369,7 @@ function intertyper(data, parseFunctions, baseLineNum) { } if (item.tokens[2].text == 'alias') { - return; // TODO: handle this. See raytrace.cpp + return null; // TODO: handle this. See raytrace.cpp } if (item.tokens[2].text == 'type') { var fields = []; @@ -614,6 +615,7 @@ function intertyper(data, parseFunctions, baseLineNum) { return [item]; } this.forwardItem(item, 'Reintegrator'); + return null; } }); // 'invoke' @@ -639,6 +641,7 @@ function intertyper(data, parseFunctions, baseLineNum) { return [item]; } this.forwardItem(item, 'Reintegrator'); + return null; } }); diff --git a/src/jsifier.js b/src/jsifier.js index 0a590163..6c27f653 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -288,16 +288,16 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { funcs: {}, seen: {}, processItem: function(item) { - if (this.seen[item.__uid__]) return; + if (this.seen[item.__uid__]) return null; if (item.intertype == 'function') { this.funcs[item.ident] = item; item.relines = {}; this.seen[item.__uid__] = true; - return; + return null; } var line = item; var func = this.funcs[line.func]; - if (!func) return; + if (!func) return null; // Re-insert our line this.seen[item.__uid__] = true; @@ -307,7 +307,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { }); func.splitItems --; // OLD delete line.funcData; // clean up - if (func.splitItems > 0) return; + if (func.splitItems > 0) return null; // We have this function all reconstructed, go and finalize it's JS! @@ -376,7 +376,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { var intendedTrueLabel = stolen.labelTrue; assert(block.entryLabels.length <= 2); [stolen.labelTrue, stolen.labelFalse].forEach(function(entry) { - var branch = makeBranch(entry, stolen.currLabelId); + var branch = makeBranch(entry, stolen.currLabelId || null); entryLabel = block.entryLabels.filter(function(possible) { return possible.ident === getActualLabelId(entry) })[0]; if (branch.length < 5 && !entryLabel) return; //ret += indent + multipleIdent + (first ? '' : 'else ') + @@ -426,7 +426,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { }); function getVarData(funcData, ident) { - return funcData.variables[ident] || GLOBAL_VARIABLES[ident]; + return funcData.variables[ident] || GLOBAL_VARIABLES[ident] || null; } function getVarImpl(funcData, ident) { @@ -521,6 +521,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { default: throw 'unknown [store] impl: ' + impl; } + return null; }); makeFuncLineActor('deleted', function(item) { return ';' }); @@ -595,7 +596,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { first = false; } ret += 'if (' + item.ident + ' == ' + switchLabel.value + ') {\n'; - ret += ' ' + makeBranch(switchLabel.label, item.currLabelId) + '\n'; + ret += ' ' + makeBranch(switchLabel.label, item.currLabelId || null) + '\n'; ret += '}\n'; }); ret += 'else {\n'; @@ -778,6 +779,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { itemsDict.GlobalVariablePostSet.forEach(function(item) { print(indentify(item.JS, 4)); }); print(postParts[1]); print(shellParts[1]); + return null; } // Data diff --git a/src/library.js b/src/library.js index eaa2332d..d5e22ade 100644 --- a/src/library.js +++ b/src/library.js @@ -416,8 +416,7 @@ var Library = { _STDIO.write(stream, ptr, String_len(ptr)); }, - vfprintf__deps: ['STDIO'], - vfprintf__deps: ['_formatString'], + vfprintf__deps: ['STDIO', '_formatString'], vfprintf: function(stream, format, args) { var ptr = __formatString(-format, args); _STDIO.write(stream, ptr, String_len(ptr)); diff --git a/src/parseTools.js b/src/parseTools.js index 19aaa63d..af85d569 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -21,17 +21,17 @@ function preprocess(text, constants) { var showStack = []; for (var i = 0; i < lines.length; i++) { var line = lines[i]; - if (line[0] != '#') { + if (!line[0] || line[0] != '#') { if (showStack.indexOf(false) == -1) { ret += line + '\n'; } } else { - if (line[1] == 'i') { // if + if (line[1] && line[1] == 'i') { // if var ident = line.substr(4); showStack.push(!!this[ident] && this[ident] > 0); - } else if (line[2] == 'l') { // else + } else if (line[2] && line[2] == 'l') { // else showStack.push(!showStack.pop()); - } else if (line[2] == 'n') { // endif + } else if (line[2] && line[2] == 'n') { // endif showStack.pop(); } else { throw "Unclear preprocessor command: " + line; @@ -52,7 +52,7 @@ function pointingLevels(type) { if (!type) return 0; var ret = 0; var len1 = type.length - 1; - while (type[len1-ret] === '*') { + while (type[len1-ret] && type[len1-ret] === '*') { ret ++; } return ret; @@ -335,7 +335,7 @@ function parseLLVMSegment(segment) { ident: toNiceIdent(segment[0].text), type: type }; - } else if (segment[1].type == '{') { + } else if (segment[1].type && segment[1].type == '{') { type = segment[0].text; Types.needAnalysis[type] = 0; return { @@ -638,7 +638,7 @@ function indexizeFunctions(value) { // TODO: Also check for externals if (value in Functions.currFunctions) { return Functions.getIndex(value); } - if (value && value[0] == '_') { + if (value && value[0] && value[0] == '_') { var rootIdent = LibraryManager.getRootIdent(value.slice(1)); if (rootIdent && typeof Library[rootIdent] === 'function') { return Functions.getIndex('_' + rootIdent); diff --git a/src/utility.js b/src/utility.js index 64d9011a..2fb18e0d 100644 --- a/src/utility.js +++ b/src/utility.js @@ -50,6 +50,7 @@ function assertEq(a, b) { print('Stack: ' + new Error().stack); throw 'Should have been equal: ' + a + ' : ' + b; } + return false; } function assertTrue(a, msg) { |