Fixed ticket #3227 (Improve tokenizer: labels are not handled correctly after a case or another label instruction)
Moved the labels simplification after combining the tokens and moved the case/default simplification inside the labels.
This commit is contained in:
parent
f4cdf57955
commit
73f0e2c5b9
|
@ -1968,9 +1968,6 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
// specify array size..
|
||||
arraySize();
|
||||
|
||||
// simplify labels..
|
||||
labels();
|
||||
|
||||
simplifyDoWhileAddBraces();
|
||||
|
||||
if (!simplifyIfAddBraces())
|
||||
|
@ -2031,6 +2028,9 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
}
|
||||
}
|
||||
|
||||
// simplify labels..
|
||||
labels();
|
||||
|
||||
// ";a+=b;" => ";a=a+b;"
|
||||
simplifyCompoundAssignment();
|
||||
|
||||
|
@ -2456,9 +2456,9 @@ void Tokenizer::labels()
|
|||
if (tok->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok->str() == "}") {
|
||||
if (indentlevel <= 1)
|
||||
break;
|
||||
--indentlevel;
|
||||
if (!indentlevel)
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok->str() == "(")
|
||||
|
@ -2468,6 +2468,17 @@ void Tokenizer::labels()
|
|||
break;
|
||||
--indentroundbraces;
|
||||
}
|
||||
if (!indentroundbraces && tok->str() == "case")
|
||||
{
|
||||
while (0 != (tok = tok->next())) {
|
||||
if (Token::Match(tok->previous(), "%any% :"))
|
||||
break;
|
||||
}
|
||||
if (!(tok->next()) || tok->next()->str() != ";"){
|
||||
tok->insertToken(";");
|
||||
tok = tok->next();
|
||||
}
|
||||
}
|
||||
// simplify label.. except for unhandled macro
|
||||
if (!indentroundbraces && Token::Match(tok, "[;{}] %var% :")
|
||||
&& !Token::Match(tok->next(), "public|protected|private")
|
||||
|
@ -4143,13 +4154,6 @@ bool Tokenizer::simplifyTokenList()
|
|||
|
||||
simplifyIfAssign(); // could be affected by simplifyIfNot
|
||||
|
||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "case %any% : %var%"))
|
||||
tok->tokAt(2)->insertToken(";");
|
||||
if (Token::Match(tok, "default : %var%"))
|
||||
tok->next()->insertToken(";");
|
||||
}
|
||||
|
||||
// In case variable declarations have been updated...
|
||||
setVarId();
|
||||
|
||||
|
|
|
@ -4666,8 +4666,11 @@ private:
|
|||
}
|
||||
|
||||
void switchCase() {
|
||||
ASSERT_EQUALS("void foo ( int i ) { switch ( i ) { case -1 : break ; } }",
|
||||
ASSERT_EQUALS("void foo ( int i ) { switch ( i ) { case -1 : ; break ; } }",
|
||||
tokenizeAndStringify("void foo (int i) { switch(i) { case -1: break; } }"));
|
||||
//ticket #3227
|
||||
ASSERT_EQUALS("void foo ( ) { switch ( n ) { label : ; case 1 : ; label1 : ; label2 : ; break ; } }",
|
||||
tokenizeAndStringify("void foo(){ switch (n){ label: case 1: label1: label2: break; }}"));
|
||||
}
|
||||
|
||||
void simplifyPointerToStandardType() {
|
||||
|
|
Loading…
Reference in New Issue