AST: Improved handling of brackets

This commit is contained in:
Daniel Marjamäki 2013-11-25 20:58:40 +01:00
parent d8b25da73c
commit 3b11ee9e0e
2 changed files with 20 additions and 9 deletions

View File

@ -363,10 +363,8 @@ static bool iscast(const Token *tok)
return false; return false;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == ")")
return (tok2->next() && !tok2->next()->isOp());
if (!Token::Match(tok2, "%var%|*")) if (!Token::Match(tok2, "%var%|*"))
return false; return Token::Match(tok2, ") %any%") && (!tok2->next()->isOp() && tok2->next()->str() != "[");
} }
return false; return false;
@ -500,16 +498,26 @@ static void compileScope(Token *&tok, std::stack<Token*> &op)
} }
} }
static void compileDot(Token *&tok, std::stack<Token*> &op) static void compileParAndBrackets(Token *&tok, std::stack<Token*> &op)
{ {
compileScope(tok,op); compileScope(tok,op);
while (tok) { while (tok) {
if (tok->str() == ".") { if (tok->str() == "[") {
compileBinOp(tok, compileScope, op); compileBinOp(tok, compileScope, op);
} else break; } else break;
} }
} }
static void compileDot(Token *&tok, std::stack<Token*> &op)
{
compileParAndBrackets(tok,op);
while (tok) {
if (tok->str() == ".") {
compileBinOp(tok, compileParAndBrackets, op);
} else break;
}
}
static void compileMulDiv(Token *&tok, std::stack<Token*> &op) static void compileMulDiv(Token *&tok, std::stack<Token*> &op)
{ {
compileDot(tok,op); compileDot(tok,op);

View File

@ -10008,10 +10008,6 @@ private:
ASSERT_EQUALS("'X''a'>", testAst("('X' > 'a')")); ASSERT_EQUALS("'X''a'>", testAst("('X' > 'a')"));
ASSERT_EQUALS("'X''a'>", testAst("(L'X' > L'a')")); ASSERT_EQUALS("'X''a'>", testAst("(L'X' > L'a')"));
// ({..})
ASSERT_EQUALS("a{+d+", testAst("a+({b+c;})+d"));
ASSERT_EQUALS("a{d*+", testAst("a+({b+c;})*d"));
} }
void astpar() const { // parentheses void astpar() const { // parentheses
@ -10023,11 +10019,18 @@ private:
// casts // casts
ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;")); ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;"));
ASSERT_EQUALS("a1(2+=",testAst("a=(t)1+2;")); ASSERT_EQUALS("a1(2+=",testAst("a=(t)1+2;"));
// ({..})
ASSERT_EQUALS("a{+d+", testAst("a+({b+c;})+d"));
ASSERT_EQUALS("a{d*+", testAst("a+({b+c;})*d"));
} }
void astbrackets() const { // [] void astbrackets() const { // []
ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4")); ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4"));
ASSERT_EQUALS("a1[0[", testAst("a[1][0]")); ASSERT_EQUALS("a1[0[", testAst("a[1][0]"));
ASSERT_EQUALS("ab0[=", testAst("a=(b)[0];"));
ASSERT_EQUALS("abc0[.=", testAst("a=b.c[0];"));
ASSERT_EQUALS("ab0[1[=", testAst("a=b[0][1];"));
} }
void astunaryop() const { // unary operators void astunaryop() const { // unary operators