diff --git a/src/tokenize.cpp b/src/tokenize.cpp index edcf684b4..fca453c91 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -464,6 +464,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[]) return false; } + simplifyDoWhileAddBraces(); + simplifyIfAddBraces(); + // Combine "- %num%" .. for (Token *tok = _tokens; tok; tok = tok->next()) { @@ -1602,6 +1605,12 @@ void Tokenizer::simplifyTokenList() simplifyGoto(); + // TODO, simplifyDoWhileAddBraces and simplifyIfAddBraces calls + // should be removed from here, but currently simplifyGoto + // removes braces which causes some tests to fail. + simplifyDoWhileAddBraces(); + simplifyIfAddBraces(); + // Combine wide strings for (Token *tok = _tokens; tok; tok = tok->next()) { @@ -1809,8 +1818,6 @@ void Tokenizer::simplifyTokenList() } } - simplifyDoWhileAddBraces(); - simplifyIfAddBraces(); simplifyFunctionParameters(); elseif(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index abc73318e..efed5b4f1 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -389,8 +389,8 @@ private: ASSERT_EQUALS(";;if{exit;}", getcode("char *s; if (a) { exit(0); }", "s")); // open/close - ASSERT_EQUALS(";;alloc;if(var)dealloc;", getcode("int f; f=open(); if(f>=0)close(f);", "f")); - ASSERT_EQUALS(";;alloc;ifv;", getcode("int f; f=open(); if(f!=-1 || x);", "f")); + ASSERT_EQUALS(";;alloc;if(var){dealloc;}", getcode("int f; f=open(); if(f>=0)close(f);", "f")); + ASSERT_EQUALS(";;alloc;ifv{;}", getcode("int f; f=open(); if(f!=-1 || x);", "f")); } diff --git a/test/testother.cpp b/test/testother.cpp index 8b67a3ee3..d37e530b7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -816,7 +816,7 @@ private: " else\n" " p = p->next();\n" "}\n"); - TODO_ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("", errout.str()); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index fcb8ffdb2..bc18372c8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -130,10 +130,10 @@ private: std::istringstream istr(code); Tokenizer tokenizer; tokenizer.tokenize(istr, "test.cpp"); - if (simplify) tokenizer.simplifyTokenList(); + tokenizer.validate(); std::string ret; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { @@ -1169,10 +1169,10 @@ private: void ifassign1() { - ASSERT_EQUALS("; a = b ; if ( a ) ;", simplifyIfAssign(";if(a=b);")); - ASSERT_EQUALS("; a = b ( ) ; if ( ( a ) ) ;", simplifyIfAssign(";if((a=b()));")); - ASSERT_EQUALS("; a = b ( ) ; if ( ! ( a ) ) ;", simplifyIfAssign(";if(!(a=b()));")); - ASSERT_EQUALS("; a . x = b ( ) ; if ( ! ( a . x ) ) ;", simplifyIfAssign(";if(!(a->x=b()));")); + ASSERT_EQUALS("; a = b ; if ( a ) { ; }", simplifyIfAssign(";if(a=b);")); + ASSERT_EQUALS("; a = b ( ) ; if ( ( a ) ) { ; }", simplifyIfAssign(";if((a=b()));")); + ASSERT_EQUALS("; a = b ( ) ; if ( ! ( a ) ) { ; }", simplifyIfAssign(";if(!(a=b()));")); + ASSERT_EQUALS("; a . x = b ( ) ; if ( ! ( a . x ) ) { ; }", simplifyIfAssign(";if(!(a->x=b()));")); } @@ -1241,16 +1241,16 @@ private: void and1() { - ASSERT_EQUALS("if ( p && q ) ;", + ASSERT_EQUALS("if ( p && q ) { ; }", simplifyLogicalOperators("if (p and q) ;")); - ASSERT_EQUALS("if ( foo ( ) && q ) ;", + ASSERT_EQUALS("if ( foo ( ) && q ) { ; }", simplifyLogicalOperators("if (foo() and q) ;")); - ASSERT_EQUALS("if ( foo ( ) && bar ( ) ) ;", + ASSERT_EQUALS("if ( foo ( ) && bar ( ) ) { ; }", simplifyLogicalOperators("if (foo() and bar()) ;")); - ASSERT_EQUALS("if ( p && bar ( ) ) ;", + ASSERT_EQUALS("if ( p && bar ( ) ) { ; }", simplifyLogicalOperators("if (p and bar()) ;")); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9bb5a07bc..74dd7e354 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -578,7 +578,7 @@ private: "}\n"; ASSERT_EQUALS( - "void f ( ) { int a ; a = 10 ; if ( 10 ) ; }", + "void f ( ) { int a ; a = 10 ; if ( 10 ) { ; } }", simplifyKnownVariables(code)); } @@ -590,7 +590,7 @@ private: "}\n"; ASSERT_EQUALS( - "void f ( ) { int a ; a = 10 ; if ( ! 10 ) ; }", + "void f ( ) { int a ; a = 10 ; if ( ! 10 ) { ; } }", simplifyKnownVariables(code)); } } @@ -605,7 +605,7 @@ private: "}\n"; ASSERT_EQUALS( - "void f ( ) { int a ; a = 10 ; a = g ( ) ; if ( a ) ; }", + "void f ( ) { int a ; a = 10 ; a = g ( ) ; if ( a ) { ; } }", simplifyKnownVariables(code)); } @@ -622,7 +622,7 @@ private: "}\n"; ASSERT_EQUALS( - "void f ( ) { int a ; a = 4 ; while ( true ) { break ; a = 10 ; } if ( a ) ; }", + "void f ( ) { int a ; a = 4 ; while ( true ) { break ; a = 10 ; } if ( a ) { ; } }", simplifyKnownVariables(code)); } @@ -635,7 +635,7 @@ private: "}\n"; ASSERT_EQUALS( - "void f ( ) { int a ; a = 4 ; if ( g ( 4 ) ) ; }", + "void f ( ) { int a ; a = 4 ; if ( g ( 4 ) ) { ; } }", simplifyKnownVariables(code)); } @@ -648,7 +648,7 @@ private: "}\n"; ASSERT_EQUALS( - "void f ( ) { int a ; a = 4 ; if ( a = 5 ) ; }", + "void f ( ) { int a ; a = 4 ; if ( a = 5 ) { ; } }", simplifyKnownVariables(code)); } @@ -704,7 +704,7 @@ private: "}\n"; ASSERT_EQUALS( - "void foo ( ) { int a ; a = 1 ; int b ; b = 2 ; if ( 1 < 2 ) ; }", + "void foo ( ) { int a ; a = 1 ; int b ; b = 2 ; if ( 1 < 2 ) { ; } }", simplifyKnownVariables(code)); } @@ -953,8 +953,8 @@ private: "2: void f ( )\n" "3: {\n" "4: int i@2 ; i@2 = 2 ;\n" - "5: for ( int i@3 = 0 ; i@3 < 10 ; ++ i@3 )\n" - "6: i@3 = 3 ;\n" + "5: for ( int i@3 = 0 ; i@3 < 10 ; ++ i@3 ) {\n" + "6: i@3 = 3 ; }\n" "7: i@2 = 4 ;\n" "8: }\n");