From c8c5f95721c981182d527c817f98d55c714936a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 6 May 2010 18:40:52 +0200 Subject: [PATCH] Fixed #1651 (Tokenizer::setVarId wrong handling of return statement) --- lib/tokenize.cpp | 8 +++++--- test/testtokenize.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b45927123..bd5b76573 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2282,12 +2282,14 @@ 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 pattern is "( %type% *|& %var% )" then check if it's a + // variable declaration or a multiplication / mask + if (Token::Match(tok, "( %type% *|& %var% )") && !tok->next()->isStandardType()) { if (!Token::Match(tok->previous(), "%type%")) continue; + if (tok->strAt(-1) == "return") + continue; if (!Token::Match(tok->tokAt(5), "const|{|;")) continue; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 945901699..c35a2c40a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -115,7 +115,8 @@ private: TEST_CASE(varid5); TEST_CASE(varid6); TEST_CASE(varid7); - TEST_CASE(varidReturn); + TEST_CASE(varidReturn1); + TEST_CASE(varidReturn2); TEST_CASE(varid8); TEST_CASE(varid9); TEST_CASE(varid10); @@ -1524,8 +1525,7 @@ private: ASSERT_EQUALS(expected, actual); } - - void varidReturn() + void varidReturn1() { const std::string actual = tokenizeDebugListing( "int f()\n" @@ -1544,6 +1544,25 @@ private: ASSERT_EQUALS(expected, actual); } + void varidReturn2() + { + const std::string actual = tokenizeDebugListing( + "void foo()\n" + "{\n" + " unsigned long mask = (1UL << size_) - 1;\n" + " return (abits_val_ & mask);\n" + "}\n"); + + const std::string expected("\n\n##file 0\n" + "1: void foo ( )\n" + "2: {\n" + "3: long mask@1 ; mask@1 = ( 1UL << size_ ) - 1 ;\n" + "4: return ( abits_val_ & mask@1 ) ;\n" + "5: }\n"); + + ASSERT_EQUALS(expected, actual); + } + void varid8() { const std::string actual = tokenizeDebugListing(