Remove some redundant semicolons - part 2
This commit is contained in:
parent
ff1cb241a8
commit
c2ddb67316
|
@ -5286,6 +5286,9 @@ bool Tokenizer::simplifyQuestionMark()
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
for (const Token *endTok = semicolon; endTok; endTok = endTok->next()) {
|
for (const Token *endTok = semicolon; endTok; endTok = endTok->next()) {
|
||||||
if (endTok->str() == ";") {
|
if (endTok->str() == ";") {
|
||||||
|
//we can remove the semicolon if after it there's at least another token
|
||||||
|
if (endTok->next())
|
||||||
|
endTok = endTok->next();
|
||||||
Token::eraseTokens(semicolon->previous(), endTok);
|
Token::eraseTokens(semicolon->previous(), endTok);
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
|
@ -6708,7 +6711,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
if (Token::Match((*tok2)->tokAt(-7), "%type% * %var% ; %var% = & %var% ;") &&
|
if (Token::Match((*tok2)->tokAt(-7), "%type% * %var% ; %var% = & %var% ;") &&
|
||||||
(*tok2)->strAt(-5) == (*tok2)->strAt(-3)) {
|
(*tok2)->strAt(-5) == (*tok2)->strAt(-3)) {
|
||||||
(*tok2) = (*tok2)->tokAt(-4);
|
(*tok2) = (*tok2)->tokAt(-4);
|
||||||
Token::eraseTokens((*tok2), (*tok2)->tokAt(5));
|
Token::eraseTokens((*tok2), (*tok2)->tokAt(6));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -7039,7 +7042,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
if (indentlevel == indentlevel3 && Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value)) {
|
if (indentlevel == indentlevel3 && Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value)) {
|
||||||
const std::string op(tok3->strAt(2));
|
const std::string op(tok3->strAt(2));
|
||||||
if (Token::Match(tok3, "[{};] %any% %any% ;")) {
|
if (Token::Match(tok3, "[{};] %any% %any% ;")) {
|
||||||
Token::eraseTokens(tok3, tok3->tokAt(3));
|
Token::eraseTokens(tok3, tok3->tokAt(4));
|
||||||
} else {
|
} else {
|
||||||
tok3 = tok3->next();
|
tok3 = tok3->next();
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
|
@ -7060,7 +7063,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
(*tok2)->tokAt(2)->str(value);
|
(*tok2)->tokAt(2)->str(value);
|
||||||
(*tok2)->tokAt(2)->varId(valueVarId);
|
(*tok2)->tokAt(2)->varId(valueVarId);
|
||||||
if (Token::Match(tok3, "[;{}] %any% %any% ;")) {
|
if (Token::Match(tok3, "[;{}] %any% %any% ;")) {
|
||||||
Token::eraseTokens(tok3, tok3->tokAt(3));
|
Token::eraseTokens(tok3, tok3->tokAt(4));
|
||||||
} else {
|
} else {
|
||||||
tok3->deleteNext();
|
tok3->deleteNext();
|
||||||
tok3->next()->str(value);
|
tok3->next()->str(value);
|
||||||
|
|
|
@ -1174,7 +1174,7 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"void foo ( ) { int i ; i = 23 ; ; abc [ 23 ] = 0 ; }",
|
"void foo ( ) { int i ; i = 23 ; abc [ 23 ] = 0 ; }",
|
||||||
simplifyKnownVariables(code));
|
simplifyKnownVariables(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4155,7 +4155,7 @@ private:
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||||
ostr << " " << tok->str();
|
ostr << " " << tok->str();
|
||||||
ASSERT_EQUALS(" void f ( ) { } void g ( ) { }", ostr.str());
|
ASSERT_EQUALS(" void f ( ) { ; } void g ( ) { ; }", ostr.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplify_constants2() {
|
void simplify_constants2() {
|
||||||
|
|
Loading…
Reference in New Issue