aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-25 13:45:25 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-25 13:45:25 -0800
commitebe8a3a0c9662271ccdde5c05bd59a5e98964574 (patch)
tree1c427751d3b3ca3afc99cc2e01bd88110000b993 /src/parseTools.js
parent1edc791be84e53fb46b57770c67c6c7b54d2d58a (diff)
fix varargs calls in function pointers
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index ca3c90bc..98987229 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -135,7 +135,7 @@ function isVoidType(type) {
}
// Detects a function definition, ([...|type,[type,...]])
-function isFunctionDef(token) {
+function isFunctionDef(token, out) {
var text = token.text;
var nonPointing = removeAllPointing(text);
if (nonPointing[0] != '(' || nonPointing.substr(-1) != ')')
@@ -143,26 +143,41 @@ function isFunctionDef(token) {
if (nonPointing === '()') return true;
if (!token.item) return false;
var fail = false;
- splitTokenList(token.item.tokens).forEach(function(segment) {
+ var segments = splitTokenList(token.item.tokens);
+ segments.forEach(function(segment) {
var subtext = segment[0].text;
fail = fail || segment.length > 1 || !(isType(subtext) || subtext == '...');
});
+ if (out) out.numArgs = segments.length;
return !fail;
}
-function isFunctionType(type) {
+function isFunctionType(type, out) {
type = type.replace(/"[^"]+"/g, '".."');
var parts = type.split(' ');
if (pointingLevels(type) !== 1) return false;
var text = removeAllPointing(parts.slice(1).join(' '));
if (!text) return false;
- return isType(parts[0]) && isFunctionDef({ text: text, item: tokenize(text.substr(1, text.length-2), true) });
+ return isType(parts[0]) && isFunctionDef({ text: text, item: tokenize(text.substr(1, text.length-2), true) }, out);
}
function isType(type) { // TODO!
return isVoidType(type) || Runtime.isNumberType(type) || isStructType(type) || isPointerType(type) || isFunctionType(type);
}
+function isVarArgsFunctionType(type) {
+ // assumes this is known to be a function type already
+ var varArgsSuffix = '...)*';
+ return type.substr(-varArgsSuffix.length) == varArgsSuffix;
+}
+
+function countNormalArgs(type) {
+ var out = {};
+ assert(isFunctionType(type, out));
+ if (isVarArgsFunctionType(type)) out.numArgs--;
+ return out.numArgs;
+}
+
function addIdent(token) {
token.ident = token.text;
return token;