AST: Fixed bad syntax tree for 'if (x()[0]==1);'

This commit is contained in:
Daniel Marjamäki 2014-04-05 08:03:24 +02:00
parent 173a2e9ea2
commit 049d68ae7d
3 changed files with 21 additions and 18 deletions

View File

@ -460,13 +460,16 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
} else {
Token *name = tok;
Token *par = templatefunc ? tok->linkAt(1)->next() : tok->next();
Token *prev;
tok = par->next();
if (Token::Match(tok, ")|]")) {
prev = name;
par->astOperand1(name);
tok = tok->next();
} else {
Token *prev = name;
prev = name;
tok = tok->previous();
}
while (Token::Match(tok, "(|[")) {
Token *tok1 = tok;
tok = tok->next();
@ -482,7 +485,6 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
if (Token::Match(tok, "]|)"))
tok = tok->next();
}
}
op.push(par);
}
} else if (Token::Match(tok, "++|--")) {

View File

@ -10324,6 +10324,7 @@ private:
ASSERT_EQUALS("QT_WA{{,( QT_WA{{,( x1=",
testAst("QT_WA({},{x=0;});" // don't hang
"QT_WA({x=1;},{x=2;});"));
ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}"));
}
void astbrackets() const { // []