aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-22 21:03:03 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-22 21:03:03 -0800
commit0eadc1bad8baecfdedbc60c600ee802489a58a9d (patch)
treec5ae44068671f95ae0d22e5f399e1520f58a6d3e /src/parseTools.js
parent146f803547b1dad73b5564b04b0d2203151831a0 (diff)
optimize function type detection and detect returning of pointers more carefully
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 97864602..f5eba4c4 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -205,26 +205,25 @@ function isFunctionDef(token, out) {
function isPossiblyFunctionType(type) {
// A quick but unreliable way to see if something is a function type. Yes is just 'maybe', no is definite.
var len = type.length;
- return type[len-2] == ')' && type[len-1] == '*';
+ return type[len-2] == ')' && type[len-1] == '*' && type.indexOf('(') > 0;
}
function isFunctionType(type, out) {
if (!isPossiblyFunctionType(type)) return false;
+ type = type.substr(0, type.length-1); // remove final '*'
type = type.replace(/"[^"]+"/g, '".."');
- var parts;
- // hackish, but quick splitting of function def parts. this must be fast as it happens a lot
- if (type[0] != '[') {
- parts = type.split(' ');
+ var lastOpen = type.lastIndexOf('(');
+ var firstOpen = type.indexOf('(');
+ var returnType;
+ if (firstOpen == lastOpen) {
+ returnType = type.substr(0, type.indexOf(' '));
+ if (!isType(returnType)) return false;
} else {
- var index = type.search(']');
- index += type.substr(index).search(' ');
- parts = [type.substr(0, index), type.substr(index+1)];
- }
- if (pointingLevels(type) !== 1) return false;
- var text = removeAllPointing(parts.slice(1).join(' '));
- if (!text) return false;
- if (out) out.returnType = parts[0];
- return isType(parts[0]) && isFunctionDef({ text: text, item: tokenize(text.substr(1, text.length-2), true) }, out);
+ returnType = 'i8*'; // some pointer type, no point in analyzing further
+ }
+ if (out) out.returnType = returnType;
+ var argText = type.substr(lastOpen);
+ return isFunctionDef({ text: argText, item: tokenize(argText.substr(1, argText.length-2), true) }, out);
}
var isTypeCache = {}; // quite hot, optimize as much as possible