Fixed #5722 (AST: wrong handling of 'x = ((a[i])->getx)();' - the 'x' is an operand of the =)
This commit is contained in:
parent
290f0ef022
commit
8602d13dc9
|
@ -533,8 +533,18 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op, unsigned int depth
|
|||
tok = tok->next();
|
||||
compileExpression(tok,op, depth);
|
||||
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);
|
||||
tok = tok->next();
|
||||
}
|
||||
} else {
|
||||
// Parenthesized sub-expression
|
||||
tok = tok->next();
|
||||
|
|
|
@ -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<const Token *> 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;"));
|
||||
|
|
Loading…
Reference in New Issue