diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d866d42c2..d4fd65559 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; + } } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index af842c37f..754de6c50 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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