From 080374dc04f8cf64cde1d736ac6fedcbf1626833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 1 May 2010 10:09:53 +0200 Subject: [PATCH] Fixed #1638 (Tokenizer::simplifyKnownVariables: removing variable declaration) --- lib/tokenize.cpp | 10 ++++++++++ test/testtokenize.cpp | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8afc490d2..8586bf10c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2280,6 +2280,16 @@ void Tokenizer::setVarId() if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%")) continue; + // If pattern is "( %type% * %var% )" then check if it's a + // variable declaration or a multiplication + if (Token::Match(tok, "( %type% * %var% )") && !tok->next()->isStandardType()) + { + if (!Token::Match(tok->previous(), "%type%")) + continue; + if (!Token::Match(tok->tokAt(5), "const|{|;")) + continue; + } + if (Token::Match(tok, "[,;{}(] %type%")) tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index efc78ea3b..bf88ec3b9 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -122,6 +122,7 @@ private: TEST_CASE(varid13); TEST_CASE(varid14); TEST_CASE(varid15); + TEST_CASE(varid16); TEST_CASE(varidStl); TEST_CASE(varid_delete); TEST_CASE(varid_functions); @@ -1619,6 +1620,25 @@ private: } } + void varid16() + { + const std::string code("void foo()\n" + "{\n" + " int x = 1;\n" + " y = (z * x);\n" + "}\n"); + + const std::string expected("\n\n##file 0\n" + "1: void foo ( )\n" + "2: {\n" + "3: int x@1 ; x@1 = 1 ;\n" + "4: y = ( z * x@1 ) ;\n" + "5: }\n"); + + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); + } + + void varidStl() { const std::string actual = tokenizeDebugListing(