More fixes to the label simplifier (related to ticket 3176):

1)Simplify the labels if there are combinations of the symbols '*','&','{' and '(' after a '%var% :' and before another '%var%';
2)but do not simplify the label if it's inside an unpreprocessed macro code.
This commit is contained in:
Edoardo Prezioso 2011-10-08 21:13:53 +02:00
parent bc69881607
commit 9270b84d64
2 changed files with 42 additions and 7 deletions

View File

@ -2821,9 +2821,9 @@ void Tokenizer::labels()
{ {
// Simplify labels in the executable scope.. // Simplify labels in the executable scope..
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
unsigned int indentroundbraces = 0;
while (0 != (tok = tok->next())) while (0 != (tok = tok->next()))
{ {
// indentations..
if (tok->str() == "{") if (tok->str() == "{")
++indentlevel; ++indentlevel;
else if (tok->str() == "}") else if (tok->str() == "}")
@ -2833,11 +2833,29 @@ void Tokenizer::labels()
--indentlevel; --indentlevel;
} }
// simplify label.. if (tok->str() == "(")
if (Token::Match(tok, "[;{}] %var% : (| *|&| %var%")) ++indentroundbraces;
else if (tok->str() == ")")
{ {
if (!Token::Match(tok->next(), "public|protected|private")) if (!indentroundbraces)
tok->tokAt(2)->insertToken(";"); break;
--indentroundbraces;
}
// simplify label.. except for unhandled macro
if (!indentroundbraces && Token::Match(tok, "[;{}] %var% :")
&& !Token::Match(tok->next(), "public|protected|private")
&& tok->tokAt(3)->str() != ";")
{
for (Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next())
{
if (Token::Match(tok2, "%var%"))
{
tok->tokAt(2)->insertToken(";");
break;
}
else if (!Token::Match(tok2, "[(*&{]"))
break;
}
} }
} }
} }

View File

@ -5085,9 +5085,26 @@ private:
void labels() void labels()
{ {
ASSERT_EQUALS(" void f(){ ab:; a=0;}", labels_("void f() { ab: a=0; }")); ASSERT_EQUALS(" void f(){ ab:; a=0;}", labels_("void f() { ab: a=0; }"));
ASSERT_EQUALS(" void f(){ ab:;* b=0;}", labels_("void f() { ab: *b=0; }")); //ticket #3176
ASSERT_EQUALS(" void f(){ ab:;& b=0;}", labels_("void f() { ab: &b=0; }"));
ASSERT_EQUALS(" void f(){ ab:;(* func)();}", labels_("void f() { ab: (*func)(); }")); ASSERT_EQUALS(" void f(){ ab:;(* func)();}", labels_("void f() { ab: (*func)(); }"));
//with '*' operator
ASSERT_EQUALS(" void f(){ ab:;* b=0;}", labels_("void f() { ab: *b=0; }"));
ASSERT_EQUALS(" void f(){ ab:;** b=0;}", labels_("void f() { ab: **b=0; }"));
//with '&' operator
ASSERT_EQUALS(" void f(){ ab:;& b=0;}", labels_("void f() { ab: &b=0; }"));
ASSERT_EQUALS(" void f(){ ab:;&( b. x)=0;}", labels_("void f() { ab: &(b->x)=0; }"));
//with '(' parenthesis
ASSERT_EQUALS(" void f(){ ab:;*(* b). x=0;}", labels_("void f() { ab: *(* b)->x=0; }"));
ASSERT_EQUALS(" void f(){ ab:;(** b). x=0;}", labels_("void f() { ab: (** b).x=0; }"));
ASSERT_EQUALS(" void f(){ ab:;&(* b. x)=0;}", labels_("void f() { ab: &(*b.x)=0; }"));
//with '{' parenthesis
ASSERT_EQUALS(" void f(){ ab:;{ b=0;}}", labels_("void f() { ab: {b=0;} }"));
ASSERT_EQUALS(" void f(){ ab:;{* b=0;}}", labels_("void f() { ab: { *b=0;} }"));
ASSERT_EQUALS(" void f(){ ab:;{& b=0;}}", labels_("void f() { ab: { &b=0;} }"));
ASSERT_EQUALS(" void f(){ ab:;{&(* b. x)=0;}}", labels_("void f() { ab: {&(*b.x)=0;} }"));
//with unhandled MACRO() code
ASSERT_EQUALS(" void f(){ MACRO( ab: b=0;, foo)}", labels_("void f() { MACRO(ab: b=0;, foo)}"));
ASSERT_EQUALS(" void f(){ MACRO( bar, ab:{&(* b. x)=0;})}", labels_("void f() { MACRO(bar, ab: {&(*b.x)=0;})}"));
} }
// Check simplifyInitVar // Check simplifyInitVar