Fixed #5770 (AST: better handling of 'a.b[c.d]==0')
This commit is contained in:
parent
4710c5c4f1
commit
9fc8bdcbac
|
@ -578,8 +578,20 @@ static void compileDot(Token *&tok, std::stack<Token*> &op, unsigned int depth)
|
||||||
compileBinOp(tok, compileScope, op, depth);
|
compileBinOp(tok, compileScope, op, depth);
|
||||||
if (depth==1U && Token::Match(tok,"++|--"))
|
if (depth==1U && Token::Match(tok,"++|--"))
|
||||||
compileTerm(tok,op,depth);
|
compileTerm(tok,op,depth);
|
||||||
} else if (tok->str() == "[") {
|
} else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void compileBrackets(Token *&tok, std::stack<Token*> &op, unsigned int depth)
|
||||||
|
{
|
||||||
|
compileDot(tok,op, depth);
|
||||||
|
while (tok) {
|
||||||
|
if (tok->str() == ".") { // compile dot and brackets from left to right. Example: "a.b[c]"
|
||||||
compileBinOp(tok, compileScope, op, depth);
|
compileBinOp(tok, compileScope, op, depth);
|
||||||
|
if (depth==1U && Token::Match(tok,"++|--"))
|
||||||
|
compileTerm(tok,op,depth);
|
||||||
|
} else if (tok->str() == "[") {
|
||||||
|
compileBinOp(tok, compileDot, op, depth);
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
@ -587,7 +599,7 @@ static void compileDot(Token *&tok, std::stack<Token*> &op, unsigned int depth)
|
||||||
|
|
||||||
static void compileMulDiv(Token *&tok, std::stack<Token*> &op, unsigned int depth)
|
static void compileMulDiv(Token *&tok, std::stack<Token*> &op, unsigned int depth)
|
||||||
{
|
{
|
||||||
compileDot(tok,op, depth);
|
compileBrackets(tok,op, depth);
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (Token::Match(tok, "[*/%]")) {
|
if (Token::Match(tok, "[*/%]")) {
|
||||||
if (Token::Match(tok, "* [*,)]")) {
|
if (Token::Match(tok, "* [*,)]")) {
|
||||||
|
@ -595,7 +607,7 @@ static void compileMulDiv(Token *&tok, std::stack<Token*> &op, unsigned int dept
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
compileBinOp(tok, compileDot, op, depth);
|
compileBinOp(tok, compileBrackets, op, depth);
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10389,6 +10389,7 @@ private:
|
||||||
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)"));
|
ASSERT_EQUALS("ifp*0[1==(", testAst("if((*p)[0]==1)"));
|
||||||
|
ASSERT_EQUALS("ifab.cd.[e==(", testAst("if(a.b[c.d]==e){}"));
|
||||||
|
|
||||||
// problems with: x=expr
|
// problems with: x=expr
|
||||||
ASSERT_EQUALS("=\n"
|
ASSERT_EQUALS("=\n"
|
||||||
|
|
Loading…
Reference in New Issue