From 46bfa62aadb617a737c2f6af1b62347f41a3abca Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 15 Oct 2015 10:31:08 +0200 Subject: [PATCH] Execute prepareTernaryOpForAST earlier (#7048) --- lib/tokenize.cpp | 5 +++-- test/testtokenize.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cc02cb028..9ffaa6940 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1713,8 +1713,6 @@ bool Tokenizer::tokenize(std::istream &code, if (simplifyTokenList1(FileName)) { if (!noSymbolDB_AST) { - prepareTernaryOpForAST(); - createSymbolDatabase(); // Use symbol database to identify rvalue references. Split && to & &. This is safe, since it doesn't delete any tokens (which might be referenced by symbol database) @@ -3402,6 +3400,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Remove __asm.. simplifyAsm(); + // Add parantheses to ternary operator where necessary + prepareTernaryOpForAST(); + // Change initialisation of variable to assignment simplifyInitVar(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 45e600830..607710c5c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -255,6 +255,7 @@ private: TEST_CASE(vardecl2); TEST_CASE(vardecl3); TEST_CASE(vardecl4); + TEST_CASE(vardecl5); // #7048 TEST_CASE(vardec_static); TEST_CASE(vardecl6); TEST_CASE(vardecl7); @@ -3507,6 +3508,14 @@ private: ASSERT_EQUALS(res4, tokenizeAndStringify(code4)); } + void vardecl5() { + ASSERT_EQUALS("void foo ( int nX ) {\n" + "int addI ; addI = frontPoint == 2 || frontPoint == 1 ? ( i = 0 , 1 ) : ( i = nX - 2 , -1 ) ;\n" + "}", tokenizeAndStringify("void foo(int nX) {\n" + " int addI = frontPoint == 2 || frontPoint == 1 ? i = 0, 1 : (i = nX - 2, -1);\n" + "}")); + } + void vardecl_stl_1() { // ticket #520