diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 933331957..8ac2aaca9 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -533,8 +533,18 @@ static void compileTerm(Token *& tok, std::stack &op, unsigned int depth tok = tok->next(); compileExpression(tok,op, depth); tok = nextpar; - compileBinOp(tok, compileExpression, op, depth); - tok = tok->next(); + if (Token::simpleMatch(tok,"( )")) { + if (!op.empty()) { + Token *f = op.top(); + op.pop(); + tok->astOperand1(f); + op.push(tok); + } + tok = tok->tokAt(2); + } else { + compileBinOp(tok, compileExpression, op, depth); + tok = tok->next(); + } } else { // Parenthesized sub-expression tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e7502db7e..dd0596b47 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -10216,7 +10216,7 @@ private: } - static std::string testAst(const char code[]) { + static std::string testAst(const char code[],bool verbose=false) { // tokenize given code.. const Settings settings; TokenList tokenList(&settings); @@ -10250,6 +10250,9 @@ private: tokenList.createAst(); // Return stringified AST + if (verbose) + return tokenList.front()->astTop()->astStringVerbose(0,0); + std::string ret; std::set astTop; for (const Token *tok = tokenList.front(); tok; tok = tok->next()) { @@ -10329,6 +10332,15 @@ private: // problems with: if (x[y]==z) ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}")); ASSERT_EQUALS("ifbuff0[&(*1==(", testAst("if (*((DWORD*)&buff[0])==1){}")); + ASSERT_EQUALS("=\n" + "|-x\n" + "`-(\n" + " `-.\n" + " |-[\n" + " | |-a\n" + " | `-i\n" + " `-f\n", + testAst("x = ((a[i]).f)();", true)); // casts ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;"));