aboutsummaryrefslogtreecommitdiff
path: root/src/preamble.js
diff options
context:
space:
mode:
authorBruce Mitchener <bruce.mitchener@gmail.com>2014-02-20 18:03:33 +0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-02-21 07:42:28 +0700
commitd4edc4c8614d43d3b46c6d01bbc00bd00835587e (patch)
tree589cb32e668f556eb5a7855fc4a09744c8e09129 /src/preamble.js
parent686d2e6a68f02da35a4fc4d71c5d152c7ed2d177 (diff)
strict fix: Don't define functions within conditionals or try blocks.
Diffstat (limited to 'src/preamble.js')
-rw-r--r--src/preamble.js248
1 files changed, 124 insertions, 124 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 1c9de066..27a98422 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -683,6 +683,130 @@ function stringToUTF32(str, outPtr) {
Module['stringToUTF32'] = stringToUTF32;
function demangle(func) {
+ var i = 3;
+ // params, etc.
+ var basicTypes = {
+ 'v': 'void',
+ 'b': 'bool',
+ 'c': 'char',
+ 's': 'short',
+ 'i': 'int',
+ 'l': 'long',
+ 'f': 'float',
+ 'd': 'double',
+ 'w': 'wchar_t',
+ 'a': 'signed char',
+ 'h': 'unsigned char',
+ 't': 'unsigned short',
+ 'j': 'unsigned int',
+ 'm': 'unsigned long',
+ 'x': 'long long',
+ 'y': 'unsigned long long',
+ 'z': '...'
+ };
+ var subs = [];
+ var first = true;
+ function dump(x) {
+ //return;
+ if (x) Module.print(x);
+ Module.print(func);
+ var pre = '';
+ for (var a = 0; a < i; a++) pre += ' ';
+ Module.print (pre + '^');
+ }
+ function parseNested() {
+ i++;
+ if (func[i] === 'K') i++; // ignore const
+ var parts = [];
+ while (func[i] !== 'E') {
+ if (func[i] === 'S') { // substitution
+ i++;
+ var next = func.indexOf('_', i);
+ var num = func.substring(i, next) || 0;
+ parts.push(subs[num] || '?');
+ i = next+1;
+ continue;
+ }
+ if (func[i] === 'C') { // constructor
+ parts.push(parts[parts.length-1]);
+ i += 2;
+ continue;
+ }
+ var size = parseInt(func.substr(i));
+ var pre = size.toString().length;
+ if (!size || !pre) { i--; break; } // counter i++ below us
+ var curr = func.substr(i + pre, size);
+ parts.push(curr);
+ subs.push(curr);
+ i += pre + size;
+ }
+ i++; // skip E
+ return parts;
+ }
+ function parse(rawList, limit, allowVoid) { // main parser
+ limit = limit || Infinity;
+ var ret = '', list = [];
+ function flushList() {
+ return '(' + list.join(', ') + ')';
+ }
+ var name;
+ if (func[i] === 'N') {
+ // namespaced N-E
+ name = parseNested().join('::');
+ limit--;
+ if (limit === 0) return rawList ? [name] : name;
+ } else {
+ // not namespaced
+ if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L'
+ var size = parseInt(func.substr(i));
+ if (size) {
+ var pre = size.toString().length;
+ name = func.substr(i + pre, size);
+ i += pre + size;
+ }
+ }
+ first = false;
+ if (func[i] === 'I') {
+ i++;
+ var iList = parse(true);
+ var iRet = parse(true, 1, true);
+ ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>';
+ } else {
+ ret = name;
+ }
+ paramLoop: while (i < func.length && limit-- > 0) {
+ //dump('paramLoop');
+ var c = func[i++];
+ if (c in basicTypes) {
+ list.push(basicTypes[c]);
+ } else {
+ switch (c) {
+ case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer
+ case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference
+ case 'L': { // literal
+ i++; // skip basic type
+ var end = func.indexOf('E', i);
+ var size = end - i;
+ list.push(func.substr(i, size));
+ i += size + 2; // size + 'EE'
+ break;
+ }
+ case 'A': { // array
+ var size = parseInt(func.substr(i));
+ i += size.toString().length;
+ if (func[i] !== '_') throw '?';
+ i++; // skip _
+ list.push(parse(true, 1, true)[0] + ' [' + size + ']');
+ break;
+ }
+ case 'E': break paramLoop;
+ default: ret += '?' + c; break paramLoop;
+ }
+ }
+ }
+ if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void)
+ return rawList ? list : ret + flushList();
+ }
try {
// Special-case the entry point, since its name differs from other name mangling.
if (func == 'Object._main' || func == '_main') {
@@ -696,130 +820,6 @@ function demangle(func) {
case 'n': return 'operator new()';
case 'd': return 'operator delete()';
}
- var i = 3;
- // params, etc.
- var basicTypes = {
- 'v': 'void',
- 'b': 'bool',
- 'c': 'char',
- 's': 'short',
- 'i': 'int',
- 'l': 'long',
- 'f': 'float',
- 'd': 'double',
- 'w': 'wchar_t',
- 'a': 'signed char',
- 'h': 'unsigned char',
- 't': 'unsigned short',
- 'j': 'unsigned int',
- 'm': 'unsigned long',
- 'x': 'long long',
- 'y': 'unsigned long long',
- 'z': '...'
- };
- function dump(x) {
- //return;
- if (x) Module.print(x);
- Module.print(func);
- var pre = '';
- for (var a = 0; a < i; a++) pre += ' ';
- Module.print (pre + '^');
- }
- var subs = [];
- function parseNested() {
- i++;
- if (func[i] === 'K') i++; // ignore const
- var parts = [];
- while (func[i] !== 'E') {
- if (func[i] === 'S') { // substitution
- i++;
- var next = func.indexOf('_', i);
- var num = func.substring(i, next) || 0;
- parts.push(subs[num] || '?');
- i = next+1;
- continue;
- }
- if (func[i] === 'C') { // constructor
- parts.push(parts[parts.length-1]);
- i += 2;
- continue;
- }
- var size = parseInt(func.substr(i));
- var pre = size.toString().length;
- if (!size || !pre) { i--; break; } // counter i++ below us
- var curr = func.substr(i + pre, size);
- parts.push(curr);
- subs.push(curr);
- i += pre + size;
- }
- i++; // skip E
- return parts;
- }
- var first = true;
- function parse(rawList, limit, allowVoid) { // main parser
- limit = limit || Infinity;
- var ret = '', list = [];
- function flushList() {
- return '(' + list.join(', ') + ')';
- }
- var name;
- if (func[i] === 'N') {
- // namespaced N-E
- name = parseNested().join('::');
- limit--;
- if (limit === 0) return rawList ? [name] : name;
- } else {
- // not namespaced
- if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L'
- var size = parseInt(func.substr(i));
- if (size) {
- var pre = size.toString().length;
- name = func.substr(i + pre, size);
- i += pre + size;
- }
- }
- first = false;
- if (func[i] === 'I') {
- i++;
- var iList = parse(true);
- var iRet = parse(true, 1, true);
- ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>';
- } else {
- ret = name;
- }
- paramLoop: while (i < func.length && limit-- > 0) {
- //dump('paramLoop');
- var c = func[i++];
- if (c in basicTypes) {
- list.push(basicTypes[c]);
- } else {
- switch (c) {
- case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer
- case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference
- case 'L': { // literal
- i++; // skip basic type
- var end = func.indexOf('E', i);
- var size = end - i;
- list.push(func.substr(i, size));
- i += size + 2; // size + 'EE'
- break;
- }
- case 'A': { // array
- var size = parseInt(func.substr(i));
- i += size.toString().length;
- if (func[i] !== '_') throw '?';
- i++; // skip _
- list.push(parse(true, 1, true)[0] + ' [' + size + ']');
- break;
- }
- case 'E': break paramLoop;
- default: ret += '?' + c; break paramLoop;
- }
- }
- }
- if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void)
- return rawList ? list : ret + flushList();
- }
return parse();
} catch(e) {
return func;