ast: fixed handling of templates

This commit is contained in:
Daniel Marjamäki 2014-01-09 17:14:16 +01:00
parent f9dd9676be
commit 1be30bf022
2 changed files with 14 additions and 5 deletions

View File

@ -427,19 +427,25 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
} else if (tok->str() == "return") {
compileUnaryOp(tok, compileExpression, op);
} else if (tok->isName()) {
const bool templatefunc = Token::Match(tok, "%var% <") && Token::simpleMatch(tok->linkAt(1), "> (");
if (Token::Match(tok->next(), "++|--")) { // post increment / decrement
tok = tok->next();
tok->astOperand1(tok->previous());
op.push(tok);
tok = tok->next();
} else if (!Token::Match(tok->next(), "(|[")) {
} else if (tok->next() && tok->next()->str() == "<" && tok->next()->link() && !templatefunc) {
op.push(tok);
tok = tok->next()->link()->next();
compileTerm(tok,op);
} else if (!Token::Match(tok->next(), "(|[") && !templatefunc) {
op.push(tok);
tok = tok->next();
} else {
Token *name = tok;
tok = tok->tokAt(2);
Token *par = templatefunc ? tok->linkAt(1)->next() : tok->next();
tok = par->next();
if (Token::Match(tok, ")|]")) {
name->next()->astOperand1(name);
par->astOperand1(name);
tok = tok->next();
} else {
Token *prev = name;
@ -458,7 +464,7 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
tok = tok->next();
}
}
op.push(name->next());
op.push(par);
}
} else if (Token::Match(tok, "++|--")) {
bool pre = false;

View File

@ -10037,6 +10037,8 @@ private:
else if (!links.empty() && Token::Match(tok,")|]")) {
Token::createMutualLinks(links.top(), tok);
links.pop();
} else if (Token::Match(tok, "< %type% >")) {
Token::createMutualLinks(tok, tok->tokAt(2));
}
}
@ -10130,7 +10132,8 @@ private:
}
void asttemplate() const { // uninstantiated templates will have <,>,etc..
ASSERT_EQUALS("aint<>3==", testAst("a<int>()==3"));
ASSERT_EQUALS("a(3==", testAst("a<int>()==3"));
ASSERT_EQUALS("ab(==", testAst("a == b<c>(); f();"));
}
};