From 0d2d0c864af7385829ceedb31cbb67e15510ae58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 Feb 2011 22:24:45 +0100 Subject: [PATCH] Tokenizer::simplifyKnownVariables: Fixed TODO testcases (better handling of comparisons) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 107 +++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 64 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index aa800124d..2797909b8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6527,7 +6527,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign // Using the variable in condition.. if (Token::Match(tok3->previous(), ("if ( " + structname + " %varid% ==|!=|<|<=|>|>=|)").c_str(), varid) || Token::Match(tok3, ("( " + structname + " %varid% ==|!=|<|<=|>|>=").c_str(), varid) || - Token::Match(tok3, ("!|==|!=|<|<=|>|>= " + structname + " %varid% ==|!=|<|<=|>|>=|)").c_str(), varid) || + Token::Match(tok3, ("!|==|!=|<|<=|>|>= " + structname + " %varid% ==|!=|<|<=|>|>=|)|;").c_str(), varid) || Token::Match(tok3->previous(), "strlen|free ( %varid% )", varid)) { if (!structname.empty()) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 11ccaa34d..76b3b7a40 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1722,22 +1722,14 @@ private: " int i = v;\n" " return h == i;\n" "}\n"; - const char wanted[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: ;\n" - "5: return u@1 == v@2 ;\n" - "6: }\n"; - const char current[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: int i@4 ; i@4 = v@2 ;\n" - "5: return u@1 == i@4 ;\n" - "6: }\n"; - - TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true)); + const char expected[] = "\n\n##file 0\n" + "1: bool foo ( int u@1 , int v@2 )\n" + "2: {\n" + "3: ;\n" + "4:\n" + "5: return u@1 == v@2 ;\n" + "6: }\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); } { @@ -1747,21 +1739,14 @@ private: " int i = v;\n" " return h != i;\n" "}\n"; - const char wanted[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: ;\n" - "5: return u@1 != v@2 ;\n" - "6: }\n"; - const char current[] = "\n\n##file 0\n" + const char expected[] = "\n\n##file 0\n" "1: bool foo ( int u@1 , int v@2 )\n" "2: {\n" "3: ;\n" - "4: int i@4 ; i@4 = v@2 ;\n" - "5: return u@1 != i@4 ;\n" + "4:\n" + "5: return u@1 != v@2 ;\n" "6: }\n"; - TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true)); + ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); } { @@ -1771,15 +1756,14 @@ private: " int i = v;\n" " return h > i;\n" "}\n"; - const char wanted[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: ;\n" - "5: return u@1 > v@2 ;\n" - "6: }\n"; - const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 > i@4 ;\n6: }\n"; - TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true)); + const char expected[] = "\n\n##file 0\n" + "1: bool foo ( int u@1 , int v@2 )\n" + "2: {\n" + "3: ;\n" + "4:\n" + "5: return u@1 > v@2 ;\n" + "6: }\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); } { @@ -1789,15 +1773,14 @@ private: " int i = v;\n" " return h >= i;\n" "}\n"; - const char wanted[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: ;\n" - "5: return u@1 >= v@2 ;\n" - "6: }\n"; - const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 >= i@4 ;\n6: }\n"; - TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true)); + const char expected[] = "\n\n##file 0\n" + "1: bool foo ( int u@1 , int v@2 )\n" + "2: {\n" + "3: ;\n" + "4:\n" + "5: return u@1 >= v@2 ;\n" + "6: }\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); } { @@ -1807,15 +1790,14 @@ private: " int i = v;\n" " return h < i;\n" "}\n"; - const char wanted[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: ;\n" - "5: return u@1 < v@2 ;\n" - "6: }\n"; - const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 < i@4 ;\n6: }\n"; - TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true)); + const char expected[] = "\n\n##file 0\n" + "1: bool foo ( int u@1 , int v@2 )\n" + "2: {\n" + "3: ;\n" + "4:\n" + "5: return u@1 < v@2 ;\n" + "6: }\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); } { @@ -1825,15 +1807,14 @@ private: " int i = v;\n" " return h <= i;\n" "}\n"; - const char wanted[] = "\n\n##file 0\n" - "1: bool foo ( int u@1 , int v@2 )\n" - "2: {\n" - "3: ;\n" - "4: ;\n" - "5: return u@1 <= v@2 ;\n" - "6: }\n"; - const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 <= i@4 ;\n6: }\n"; - TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true)); + const char expected[] = "\n\n##file 0\n" + "1: bool foo ( int u@1 , int v@2 )\n" + "2: {\n" + "3: ;\n" + "4:\n" + "5: return u@1 <= v@2 ;\n" + "6: }\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); } {