ast: clarify the code somewhat

This commit is contained in:
Daniel Marjamäki 2013-02-23 07:43:12 +01:00
parent bce99a9e2f
commit d5af34331b
2 changed files with 7 additions and 3 deletions

View File

@ -1066,12 +1066,16 @@ void Token::astFunctionCall()
void Token::astHandleParentheses() void Token::astHandleParentheses()
{ {
// Assumptions:
// * code is valid
// * _str is one of: ( ) ]
Token *innerTop; Token *innerTop;
if (_str != "(") if (Token::Match(this, ")|]"))
innerTop = _previous; innerTop = _previous;
else if (_next && _next->_str == ")") else if (_next && _next->_str == ")")
return; return;
else else // _str = "("
innerTop = _next; innerTop = _next;
while (innerTop->_astParent) while (innerTop->_astParent)
innerTop = innerTop->_astParent; innerTop = innerTop->_astParent;

View File

@ -412,7 +412,7 @@ void TokenList::createAst()
// parentheses.. // parentheses..
for (Token *tok = _front; tok; tok = tok->next()) { for (Token *tok = _front; tok; tok = tok->next()) {
if (tok->str() == "(" || tok->str() == ")" || tok->str() == "]") { if (Token::Match(tok, "(|)|]")) {
tok->astHandleParentheses(); tok->astHandleParentheses();
} }
} }