Fixed #5722 (AST: wrong handling of 'x = ((a[i])->getx)();' - the 'x' is an operand of the =)

This commit is contained in:
Daniel Marjamäki 2014-04-25 06:06:54 +02:00
parent 290f0ef022
commit 8602d13dc9
2 changed files with 25 additions and 3 deletions

View File

@ -533,8 +533,18 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op, unsigned int depth
tok = tok->next(); tok = tok->next();
compileExpression(tok,op, depth); compileExpression(tok,op, depth);
tok = nextpar; tok = nextpar;
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); compileBinOp(tok, compileExpression, op, depth);
tok = tok->next(); tok = tok->next();
}
} else { } else {
// Parenthesized sub-expression // Parenthesized sub-expression
tok = tok->next(); tok = tok->next();

View File

@ -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.. // tokenize given code..
const Settings settings; const Settings settings;
TokenList tokenList(&settings); TokenList tokenList(&settings);
@ -10250,6 +10250,9 @@ private:
tokenList.createAst(); tokenList.createAst();
// Return stringified AST // Return stringified AST
if (verbose)
return tokenList.front()->astTop()->astStringVerbose(0,0);
std::string ret; std::string ret;
std::set<const Token *> astTop; std::set<const Token *> astTop;
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) { for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
@ -10329,6 +10332,15 @@ 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("=\n"
"|-x\n"
"`-(\n"
" `-.\n"
" |-[\n"
" | |-a\n"
" | `-i\n"
" `-f\n",
testAst("x = ((a[i]).f)();", true));
// casts // casts
ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;")); ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;"));