diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/intertyper.js | 40 | ||||
-rw-r--r-- | src/jsifier.js | 3 | ||||
-rw-r--r-- | src/parseTools.js | 9 |
3 files changed, 25 insertions, 27 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index 1db3cf88..ed8d5099 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -461,22 +461,18 @@ function intertyper(data, parseFunctions, baseLineNum) { item.tokens = item.tokens.filter(function(token) { return !(token.text in LLVM.LINKAGES || token.text in LLVM.PARAM_ATTR || token.text in set('hidden', 'nounwind', 'define', 'inlinehint', '{') || token.text in LLVM.CALLING_CONVENTIONS); }); - var ret = { + var params = parseParamTokens(item.tokens[2].item.tokens); + return [{ intertype: 'function', ident: toNiceIdent(item.tokens[1].text), returnType: item.tokens[0].text, - params: parseParamTokens(item.tokens[2].item.tokens), - lineNum: item.lineNum - }; - ret.hasVarArgs = false; - ret.paramIdents = ret.params.map(function(param) { - if (param.intertype == 'varargs') { - ret.hasVarArgs = true; - return null; - } - return toNiceIdent(param.ident); - }).filter(function(param) { return param != null });; - return [ret]; + params: params, + hasVarArgs: hasVarArgs(params), + lineNum: item.lineNum, + paramIdents: params.map(function(param) { + return (param.intertype == 'varargs') ? null : toNiceIdent(param.ident); + }).filter(function(param) { return param != null; }) + }]; } }); // label @@ -799,23 +795,15 @@ function intertyper(data, parseFunctions, baseLineNum) { item.tokens.splice(1, 1); } - var ret = { + var params = parseParamTokens(item.tokens[3].item.tokens); + return [{ intertype: 'functionStub', ident: toNiceIdent(item.tokens[2].text), returnType: item.tokens[1], - params: parseParamTokens(item.tokens[3].item.tokens), - hasVarArgs: false, + params: params, + hasVarArgs: hasVarArgs(params), lineNum: item.lineNum - }; - - for (var i = 0; i < ret.params.length; i++) { - if (ret.params[i].intertype == 'varargs') { - ret.hasVarArgs = true; - break; - } - } - - return [ret]; + }]; } }); // 'unreachable' diff --git a/src/jsifier.js b/src/jsifier.js index 1bbd4d20..94f78134 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -199,7 +199,8 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { return ret; } else { if (item.external && BUILD_AS_SHARED_LIB) { - // External variables in shared libraries should not be declared. + // External variables in shared libraries should not be declared as + // they would shadow similarly-named globals in the parent. item.JS = ''; } else { item.JS = 'var ' + item.ident + ';'; diff --git a/src/parseTools.js b/src/parseTools.js index 5473ff37..4b3e63e1 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -333,6 +333,15 @@ function parseParamTokens(params) { return ret; } +function hasVarArgs(params) { + for (var i = 0; i < params.length; i++) { + if (params[i].intertype == 'varargs') { + return true; + } + } + return false; +} + function finalizeParam(param) { if (param.intertype in PARSABLE_LLVM_FUNCTIONS) { return finalizeLLVMFunctionCall(param); |