From ac1ceb85b6ab6164150d553cb799ab481fa3699e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 22 May 2020 09:35:55 +0200 Subject: [PATCH] AST: improved AST when expression starts with %char% or %str% --- lib/tokenlist.cpp | 7 ++++++- test/testtokenize.cpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 58d747e49..6e595f1c2 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1483,7 +1483,12 @@ static Token * createAstAtToken(Token *tok, bool cpp) tok = typetok; } - if (Token::Match(tok, "return|case") || (cpp && tok->str() == "throw") || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{") || Token::Match(tok->previous(), "[;{}] %num%")) { + if (Token::Match(tok, "return|case") || + (cpp && tok->str() == "throw") || + !tok->previous() || + Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || + Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{") || + Token::Match(tok->previous(), "[;{}] %num%|%str%|%char%")) { if (cpp && (Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%") || Token::Match(tok->tokAt(-3), "[;{}] :: new|delete %name%"))) tok = tok->previous(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 115511b80..33c489582 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7720,6 +7720,8 @@ private: ASSERT_EQUALS("xab,c,{=", testAst("x={a,b,(c)};")); ASSERT_EQUALS("x0fSa.1=b.2=,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = 1, .b = 2, .c = \"\" });")); ASSERT_EQUALS("x0fSa.1{=b.2{,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = { 1 }, .b { 2 }, .c = \"\" });")); + ASSERT_EQUALS("a0{,( \"\"abc12:?,", testAst("a(0, {{\"\", (abc) ? 1 : 2}});")); + ASSERT_EQUALS("a0{,( \'\'abc12:?,", testAst("a(0, {{\'\', (abc) ? 1 : 2}});")); // struct initialization hang ASSERT_EQUALS("sbar.1{,{(={= fcmd( forfieldfield++;;(",