Fixed template bracket linkage in while loop simplification

Ran AStyle
This commit is contained in:
PKEuS 2014-08-23 12:28:54 +02:00
parent 976966fe81
commit 7f2be2f57c
5 changed files with 53 additions and 33 deletions

View File

@ -5968,16 +5968,17 @@ void Tokenizer::simplifyIfAndWhileAssign()
for (tok2 = tok2->next(); tok2 && tok2 != tok; tok2 = tok2->previous()) {
tok3->insertToken(tok2->str());
tok3->next()->varId(tok2->varId());
Token *newTok = tok3->next();
newTok->varId(tok2->varId());
newTok->fileIndex(tok2->fileIndex());
newTok->linenr(tok2->linenr());
// link() newly tokens manually
if (Token::Match(newTok, "}|)|]")) {
// link() new tokens manually
if (tok2->link()) {
if (Token::Match(newTok, "}|)|]|>")) {
braces2.push(newTok);
} else if (Token::Match(newTok, "{|(|[")) {
} else {
Token::createMutualLinks(newTok, braces2.top());
braces2.pop();
}
@ -5986,6 +5987,7 @@ void Tokenizer::simplifyIfAndWhileAssign()
}
}
}
}
void Tokenizer::simplifyVariableMultipleAssign()
{

View File

@ -157,6 +157,7 @@ private:
TEST_CASE(whileAssign1);
TEST_CASE(whileAssign2);
TEST_CASE(whileAssign3); // varid
TEST_CASE(whileAssign4); // links
TEST_CASE(doWhileAssign); // varid
TEST_CASE(test_4881); // similar to doWhileAssign (#4911), taken from #4881 with full code
@ -2727,6 +2728,23 @@ private:
"4: }\n", tokenizeDebugListing(code, true, "test.c"));
}
void whileAssign4() {
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr("; while (!(m = q->push<Message>(x))) {}");
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList2();
ASSERT_EQUALS("; m = q . push < Message > ( x ) ; while ( ! m ) { m = q . push < Message > ( x ) ; }", tokenizer.tokens()->stringifyList(0, false));
ASSERT(tokenizer.tokens()->tokAt(26) != nullptr);
if (tokenizer.tokens()->tokAt(26)) {
ASSERT(tokenizer.tokens()->tokAt(6)->link() == tokenizer.tokens()->tokAt(8));
ASSERT(tokenizer.tokens()->tokAt(24)->link() == tokenizer.tokens()->tokAt(26));
}
}
void doWhileAssign() {
ASSERT_EQUALS("; do { a = b ; } while ( a ) ;", simplifyIfAndWhileAssign(";do { } while(a=b);"));
ASSERT_EQUALS("; do { a . a = 0 ; a . b = c ; } while ( a . b ) ;", simplifyIfAndWhileAssign(";do { a.a = 0; } while(a.b=c);"));