From 648479d9096a91a7c249c0d45ed494e2643ab599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Apr 2014 06:09:26 +0200 Subject: [PATCH] AST: Fixed tree for 'a.b[5]' --- lib/tokenlist.cpp | 21 ++++++++------------- test/testtokenize.cpp | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 88dc33eb9..e47e33d3f 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -469,6 +469,9 @@ static void compileTerm(Token *& tok, std::stack &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 &op, unsigned int depth } } -static void compileParAndBrackets(Token *&tok, std::stack &op, unsigned int depth) +static void compileDot(Token *&tok, std::stack &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 &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; } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2e1ae3e31..3aaf9d9da 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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];")); }