Execute prepareTernaryOpForAST earlier (#7048)

This commit is contained in:
PKEuS 2015-10-15 10:31:08 +02:00
parent 600641c4c5
commit 46bfa62aad
2 changed files with 12 additions and 2 deletions

View File

@ -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();

View File

@ -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