ast: fixed handling of templates
This commit is contained in:
parent
f9dd9676be
commit
1be30bf022
|
@ -427,19 +427,25 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
|
||||||
} else if (tok->str() == "return") {
|
} else if (tok->str() == "return") {
|
||||||
compileUnaryOp(tok, compileExpression, op);
|
compileUnaryOp(tok, compileExpression, op);
|
||||||
} else if (tok->isName()) {
|
} else if (tok->isName()) {
|
||||||
|
const bool templatefunc = Token::Match(tok, "%var% <") && Token::simpleMatch(tok->linkAt(1), "> (");
|
||||||
if (Token::Match(tok->next(), "++|--")) { // post increment / decrement
|
if (Token::Match(tok->next(), "++|--")) { // post increment / decrement
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
tok->astOperand1(tok->previous());
|
tok->astOperand1(tok->previous());
|
||||||
op.push(tok);
|
op.push(tok);
|
||||||
tok = tok->next();
|
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);
|
op.push(tok);
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
} else {
|
} else {
|
||||||
Token *name = tok;
|
Token *name = tok;
|
||||||
tok = tok->tokAt(2);
|
Token *par = templatefunc ? tok->linkAt(1)->next() : tok->next();
|
||||||
|
tok = par->next();
|
||||||
if (Token::Match(tok, ")|]")) {
|
if (Token::Match(tok, ")|]")) {
|
||||||
name->next()->astOperand1(name);
|
par->astOperand1(name);
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
} else {
|
} else {
|
||||||
Token *prev = name;
|
Token *prev = name;
|
||||||
|
@ -458,7 +464,7 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op.push(name->next());
|
op.push(par);
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "++|--")) {
|
} else if (Token::Match(tok, "++|--")) {
|
||||||
bool pre = false;
|
bool pre = false;
|
||||||
|
|
|
@ -10037,6 +10037,8 @@ private:
|
||||||
else if (!links.empty() && Token::Match(tok,")|]")) {
|
else if (!links.empty() && Token::Match(tok,")|]")) {
|
||||||
Token::createMutualLinks(links.top(), tok);
|
Token::createMutualLinks(links.top(), tok);
|
||||||
links.pop();
|
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..
|
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();"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue