diff options
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index c06d0a0d..470c246f 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -118,7 +118,14 @@ function isJSVar(ident) { } function isLocalVar(ident) { - return ident[0] == '$'; + return ident[0] === '$'; +} + +// Simple variables or numbers, or things already quoted, do not need to be quoted +function needsQuoting(ident) { + if (/^[-+]?[$_]?[\w$_\d]*$/.test(ident)) return false; // number or variable + if (ident[0] === '(' && ident[ident.length-1] === ')' && ident.indexOf('(', 1) < 0) return false; // already fully quoted + return true; } function isStructPointerType(type) { @@ -2000,7 +2007,7 @@ function makeSignOp(value, type, op, force, ignore) { value = '1'; } else if (value === 'false') { value = '0'; - } else if (!isJSVar(value)) value = '(' + value + ')'; + } else if (needsQuoting(value)) value = '(' + value + ')'; if (bits === 32) { if (op === 're') { return '(' + value + '|0)'; @@ -2101,7 +2108,7 @@ function processMathop(item) { if (item.params[i]) { paramTypes[i] = item.params[i].type || type; idents[i] = finalizeLLVMParameter(item.params[i]); - if (!isNumber(idents[i]) && !isNiceIdent(idents[i])) { + if (needsQuoting(idents[i])) { idents[i] = '(' + idents[i] + ')'; // we may have nested expressions. So enforce the order of operations we want } } else { @@ -2540,3 +2547,8 @@ function makePrintChars(s, sep) { return ret; } +function parseAlign(text) { // parse ", align \d+" + if (!text) return QUANTUM_SIZE; + return parseInt(text.substr(8)); +} + |