AST: Fixed handling of 'a = b.c[++(d.e)];'

This commit is contained in:
Daniel Marjamäki 2014-04-26 13:16:34 +02:00
parent ffa55bbaa0
commit c34616a6ba
2 changed files with 6 additions and 3 deletions

View File

@ -499,9 +499,9 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op, unsigned int depth
} }
} else if (Token::Match(tok, "++|--")) { } else if (Token::Match(tok, "++|--")) {
bool pre = false; bool pre = false;
if (tok->next() && tok->next()->isName()) if (Token::Match(tok->next(), "%var%|("))
pre = true; pre = true;
else if (!op.empty() && !op.top()->isOp()) else if (!op.empty() && !Token::Match(tok->previous(), "(|[") && !op.top()->isOp())
pre = false; pre = false;
else else
pre = true; pre = true;

View File

@ -10332,6 +10332,9 @@ private:
// problems with: if (x[y]==z) // problems with: if (x[y]==z)
ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}")); ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}"));
ASSERT_EQUALS("ifbuff0[&(*1==(", testAst("if (*((DWORD*)&buff[0])==1){}")); ASSERT_EQUALS("ifbuff0[&(*1==(", testAst("if (*((DWORD*)&buff[0])==1){}"));
ASSERT_EQUALS("ifp*0[1==(", testAst("if((*p)[0]==1)"));
// problems with: x=expr
ASSERT_EQUALS("=\n" ASSERT_EQUALS("=\n"
"|-x\n" "|-x\n"
"`-(\n" "`-(\n"
@ -10341,7 +10344,7 @@ private:
" | `-i\n" " | `-i\n"
" `-f\n", " `-f\n",
testAst("x = ((a[i]).f)();", true)); testAst("x = ((a[i]).f)();", true));
ASSERT_EQUALS("ifp*0[1==(", testAst("if((*p)[0]==1)")); ASSERT_EQUALS("abcde.++[.=", testAst("a = b.c[++(d.e)];"));
// casts // casts
ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;")); ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;"));