@@ -103,14 +103,14 @@ static void skipEnumBody(T *&tok)
103103/* *
104104 * is tok the start brace { of a class, struct, union, or enum
105105 */
106- static bool isClassStructUnionEnumStart (const Token * tok)
106+ static const Token* isClassStructUnionEnumStart (const Token* tok)
107107{
108108 if (!Token::Match (tok->previous (), " class|struct|union|enum|%name%|>|>> {" ))
109- return false ;
109+ return nullptr ;
110110 const Token * tok2 = tok->previous ();
111111 while (tok2 && !Token::Match (tok2, " class|struct|union|enum|{|}|)|;" ))
112112 tok2 = tok2->previous ();
113- return Token::Match (tok2, " class|struct|union|enum" ) && !Token::simpleMatch (tok2->tokAt (-1 ), " ->" );
113+ return ( Token::Match (tok2, " class|struct|union|enum" ) && !Token::simpleMatch (tok2->tokAt (-1 ), " ->" )) ? tok2 : nullptr ;
114114}
115115
116116// ---------------------------------------------------------------------------
@@ -1028,6 +1028,13 @@ bool Tokenizer::isFunctionPointer(const Token* tok) {
10281028 return Token::Match (tok, " %name% ) (" );
10291029}
10301030
1031+ static bool matchCurrentType (const std::string& typeStr, const std::map<int , std::string>& types)
1032+ {
1033+ return std::any_of (types.begin (), types.end (), [&](const std::pair<int , std::string>& element) {
1034+ return typeStr == element.second ;
1035+ });
1036+ }
1037+
10311038void Tokenizer::simplifyTypedef ()
10321039{
10331040 // Simplify global typedefs that are not redefined with the fast 1-pass simplification.
@@ -1050,12 +1057,19 @@ void Tokenizer::simplifyTypedef()
10501057
10511058 int indentlevel = 0 ;
10521059 std::map<std::string, TypedefSimplifier> typedefs;
1060+ std::map<int , std::string> inType;
10531061 for (Token* tok = list.front (); tok; tok = tok->next ()) {
10541062 if (!tok->isName ()) {
1055- if (tok->str ()[0 ] == ' {' )
1063+ if (tok->str ()[0 ] == ' {' ) {
10561064 ++indentlevel;
1057- else if (tok->str ()[0 ] == ' }' )
1065+ if (const Token* typeStart = isClassStructUnionEnumStart (tok)) {
1066+ inType.emplace (indentlevel, typeStart->strAt (1 ));
1067+ }
1068+ }
1069+ else if (tok->str ()[0 ] == ' }' ) {
1070+ inType.erase (indentlevel);
10581071 --indentlevel;
1072+ }
10591073 continue ;
10601074 }
10611075
@@ -1072,7 +1086,7 @@ void Tokenizer::simplifyTypedef()
10721086 }
10731087
10741088 auto it = typedefs.find (tok->str ());
1075- if (it != typedefs.end () && it->second .canReplace (tok)) {
1089+ if (it != typedefs.end () && it->second .canReplace (tok) && ! matchCurrentType (tok-> str (), inType) ) {
10761090 std::set<std::string> r;
10771091 std::string originalname;
10781092 while (it != typedefs.end () && r.insert (tok->str ()).second ) {
0 commit comments