AST: Fixed tree for 'a.b[5]'

This commit is contained in:
Daniel Marjamäki 2014-04-29 06:09:26 +02:00
parent 36895674ce
commit 648479d909
2 changed files with 10 additions and 15 deletions

View File

@ -469,6 +469,9 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op, unsigned int depth
} else if (!Token::Match(tok->next(), "(|[") && !templatefunc) {
op.push(tok);
tok = tok->next();
} else if (Token::Match(tok->previous(), ".|:: %var% [")) {
op.push(tok);
tok = tok->next();
} else {
Token *name = tok;
Token *par = templatefunc ? tok->linkAt(1)->next() : tok->next();
@ -577,25 +580,17 @@ static void compileScope(Token *&tok, std::stack<Token*> &op, unsigned int depth
}
}
static void compileParAndBrackets(Token *&tok, std::stack<Token*> &op, unsigned int depth)
static void compileDot(Token *&tok, std::stack<Token*> &op, unsigned int depth)
{
compileScope(tok,op, depth);
while (tok) {
if (tok->str() == "[") {
compileBinOp(tok, compileScope, op, depth);
tok = tok->next();
} else break;
}
}
static void compileDot(Token *&tok, std::stack<Token*> &op, unsigned int depth)
{
compileParAndBrackets(tok,op, depth);
while (tok) {
if (tok->str() == ".") {
compileBinOp(tok, compileParAndBrackets, op, depth);
compileBinOp(tok, compileScope, op, depth);
if (depth==1U && Token::Match(tok,"++|--"))
compileTerm(tok,op,depth);
} else if (tok->str() == "[") {
compileBinOp(tok, compileScope, op, depth);
tok = tok->next();
} else break;
}
}

View File

@ -10384,7 +10384,7 @@ private:
" | `-i\n"
" `-f\n",
testAst("x = ((a[i]).f)();", true));
ASSERT_EQUALS("abcde.++[.=", testAst("a = b.c[++(d.e)];"));
ASSERT_EQUALS("abc.de.++[=", testAst("a = b.c[++(d.e)];"));
ASSERT_EQUALS("abc(1+=", testAst("a = b(c**)+1;"));
ASSERT_EQUALS("abc.=", testAst("a = (b).c;"));
@ -10411,7 +10411,7 @@ private:
ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4"));
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("abc.0[=", testAst("a=b.c[0];"));
ASSERT_EQUALS("ab0[1[=", testAst("a=b[0][1];"));
}