Fixed #4254 (Tokenizer::simplifyIfAssign: varids not preserved)
This commit is contained in:
parent
47ca73c00a
commit
c2b61030a8
|
@ -5491,6 +5491,7 @@ void Tokenizer::simplifyIfAssign()
|
||||||
|
|
||||||
for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous()) {
|
for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous()) {
|
||||||
tok3->insertToken(tok2->str());
|
tok3->insertToken(tok2->str());
|
||||||
|
tok3->next()->varId(tok2->varId());
|
||||||
|
|
||||||
Token *newTok = tok3->next();
|
Token *newTok = tok3->next();
|
||||||
newTok->fileIndex(tok2->fileIndex());
|
newTok->fileIndex(tok2->fileIndex());
|
||||||
|
|
|
@ -144,6 +144,7 @@ private:
|
||||||
TEST_CASE(ifAssignWithCast);
|
TEST_CASE(ifAssignWithCast);
|
||||||
TEST_CASE(whileAssign1);
|
TEST_CASE(whileAssign1);
|
||||||
TEST_CASE(whileAssign2);
|
TEST_CASE(whileAssign2);
|
||||||
|
TEST_CASE(whileAssign3); // varid
|
||||||
|
|
||||||
// "if(0==x)" => "if(!x)"
|
// "if(0==x)" => "if(!x)"
|
||||||
TEST_CASE(ifnot);
|
TEST_CASE(ifnot);
|
||||||
|
@ -2507,6 +2508,19 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void ifnot() {
|
||||||
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false));
|
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false));
|
||||||
|
|
Loading…
Reference in New Issue