Fixed #4254 (Tokenizer::simplifyIfAssign: varids not preserved)

This commit is contained in:
Daniel Marjamäki 2012-10-06 12:49:24 +02:00
parent 47ca73c00a
commit c2b61030a8
2 changed files with 15 additions and 0 deletions

View File

@ -5491,6 +5491,7 @@ void Tokenizer::simplifyIfAssign()
for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous()) {
tok3->insertToken(tok2->str());
tok3->next()->varId(tok2->varId());
Token *newTok = tok3->next();
newTok->fileIndex(tok2->fileIndex());

View File

@ -144,6 +144,7 @@ private:
TEST_CASE(ifAssignWithCast);
TEST_CASE(whileAssign1);
TEST_CASE(whileAssign2);
TEST_CASE(whileAssign3); // varid
// "if(0==x)" => "if(!x)"
TEST_CASE(ifnot);
@ -2507,6 +2508,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void whileAssign3() {
// #4254 - Variable id
const char code[] = "void f() {\n"
" int a;\n"
" while (a = x());\n"
"}";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( ) {\n"
"2: int a@1 ;\n"
"3: a@1 = x ( ) ; while ( a@1 ) { ; a@1 = x ( ) ; }\n"
"4: }\n", tokenizeDebugListing(code, true, "test.c"));
}
void ifnot() {
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false));