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:
parent
bc69881607
commit
9270b84d64
|
@ -2821,9 +2821,9 @@ void Tokenizer::labels()
|
|||
{
|
||||
// Simplify labels in the executable scope..
|
||||
unsigned int indentlevel = 0;
|
||||
unsigned int indentroundbraces = 0;
|
||||
while (0 != (tok = tok->next()))
|
||||
{
|
||||
// indentations..
|
||||
if (tok->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok->str() == "}")
|
||||
|
@ -2833,11 +2833,29 @@ void Tokenizer::labels()
|
|||
--indentlevel;
|
||||
}
|
||||
|
||||
// simplify label..
|
||||
if (Token::Match(tok, "[;{}] %var% : (| *|&| %var%"))
|
||||
if (tok->str() == "(")
|
||||
++indentroundbraces;
|
||||
else if (tok->str() == ")")
|
||||
{
|
||||
if (!Token::Match(tok->next(), "public|protected|private"))
|
||||
tok->tokAt(2)->insertToken(";");
|
||||
if (!indentroundbraces)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5085,9 +5085,26 @@ private:
|
|||
void labels()
|
||||
{
|
||||
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; }"));
|
||||
ASSERT_EQUALS(" void f(){ ab:;& b=0;}", labels_("void f() { ab: &b=0; }"));
|
||||
//ticket #3176
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue