AST: Handle function calls
This commit is contained in:
parent
1ad9c933ec
commit
aad3a041ad
|
@ -1080,9 +1080,21 @@ void Token::astOperand2(Token *tok)
|
|||
tok->_astParent = this;
|
||||
}
|
||||
|
||||
void Token::astFunctionCall()
|
||||
{
|
||||
_astOperand1 = _next;
|
||||
_next->_astParent = this;
|
||||
}
|
||||
|
||||
void Token::astHandleParenthesis()
|
||||
{
|
||||
Token *innerTop = (_str == "(") ? _next : _previous;
|
||||
Token *innerTop;
|
||||
if (_str != "(")
|
||||
innerTop = _previous;
|
||||
else if (_next && _next->_str == ")")
|
||||
return;
|
||||
else
|
||||
innerTop = _next;
|
||||
while (innerTop->_astParent)
|
||||
innerTop = innerTop->_astParent;
|
||||
|
||||
|
|
|
@ -550,8 +550,8 @@ private:
|
|||
public:
|
||||
void astOperand1(Token *tok);
|
||||
void astOperand2(Token *tok);
|
||||
void astFunctionCall();
|
||||
void astHandleParenthesis();
|
||||
void astHandleBrackets();
|
||||
|
||||
const Token * astOperand1() const {
|
||||
return _astOperand1;
|
||||
|
|
|
@ -343,6 +343,7 @@ void TokenList::createAst()
|
|||
{
|
||||
// operators that must be ordered according to C-precedence
|
||||
const char * const operators[] = {
|
||||
" , "
|
||||
" :: ",
|
||||
" [ . ++ -- ",
|
||||
"> ++ -- + - ! ~ * & ", // prefix unary operators, from right to left
|
||||
|
@ -386,6 +387,12 @@ void TokenList::createAst()
|
|||
}
|
||||
}
|
||||
|
||||
// function calls..
|
||||
for (Token *tok = _front; tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%var% ("))
|
||||
tok->astFunctionCall();
|
||||
}
|
||||
|
||||
// parentheses..
|
||||
for (Token *tok = _front; tok; tok = tok->next()) {
|
||||
if (tok->str() == "(" || tok->str() == ")" || tok->str() == "]") {
|
||||
|
|
|
@ -7668,7 +7668,9 @@ private:
|
|||
}
|
||||
|
||||
void astfunction() { // function calls
|
||||
TODO_ASSERT_EQUALS("1f+2+", "1f+", testAst("1+f()+2"));
|
||||
ASSERT_EQUALS("1(f+2+", testAst("1+f()+2"));
|
||||
ASSERT_EQUALS("12f+3+", testAst("1+f(2)+3"));
|
||||
ASSERT_EQUALS("123,f+4+", testAst("1+f(2,3)+4"));
|
||||
}
|
||||
|
||||
void asttemplate() { // uninstantiated templates will have <,>,etc.. how do we handle them?
|
||||
|
|
Loading…
Reference in New Issue