@@ -669,7 +669,7 @@ namespace {
669669 return mNameToken ? mNameToken ->str () : " " ;
670670 }
671671
672- void replace (Token* tok) {
672+ void replace (Token* tok, const std::string &originalname ) {
673673 if (tok == mNameToken )
674674 return ;
675675
@@ -701,7 +701,7 @@ namespace {
701701 insertTokens (tok2, mRangeTypeQualifiers );
702702 }
703703 else { // functional-style cast
704- tok->originalName (tok-> str () );
704+ tok->originalName (originalname );
705705 tok->isSimplifiedTypedef (true );
706706 tok->str (" (" );
707707 Token* tok2 = insertTokens (tok, mRangeType );
@@ -721,22 +721,22 @@ namespace {
721721 if (isFunctionPointer && isCast (tok->previous ())) {
722722 tok->insertToken (" *" );
723723 Token* const tok_1 = insertTokens (tok, std::pair<Token*, Token*>(mRangeType .first , mNameToken ->linkAt (1 )));
724- tok_1->originalName (tok-> str () );
724+ tok_1->originalName (originalname );
725725 tok->deleteThis ();
726726 return ;
727727 }
728728
729729 // Inherited type => skip "struct" / "class"
730730 if (Token::Match (mRangeType .first , " const| struct|class %name% {" ) && Token::Match (tok->previous (), " public|protected|private|<" )) {
731- tok->originalName (tok-> str () );
731+ tok->originalName (originalname );
732732 tok->str (mRangeType .second ->strAt (-1 ));
733733 return ;
734734 }
735735
736736 if (Token::Match (tok, " %name% ::" )) {
737737 if (Token::Match (mRangeType .first , " const| struct|class|union|enum %name% %name%|{" ) ||
738738 Token::Match (mRangeType .first , " %name% %name% ;" )) {
739- tok->originalName (tok-> str () );
739+ tok->originalName (originalname );
740740 tok->str (mRangeType .second ->strAt (-1 ));
741741 } else {
742742 mReplaceFailed = true ;
@@ -790,8 +790,8 @@ namespace {
790790 Token* const tok2 = insertTokens (tok, rangeType);
791791 Token* const tok3 = insertTokens (tok2, mRangeTypeQualifiers );
792792
793- tok2->originalName (tok-> str () );
794- tok3->originalName (tok-> str () );
793+ tok2->originalName (originalname );
794+ tok3->originalName (originalname );
795795 Token *after = tok3;
796796 while (Token::Match (after, " %name%|*|&|&&|::" ))
797797 after = after->next ();
@@ -1023,12 +1023,20 @@ void Tokenizer::simplifyTypedef()
10231023{
10241024 // Simplify global typedefs that are not redefined with the fast 1-pass simplification.
10251025 // Then use the slower old typedef simplification.
1026- std::map<std::string, int > numberOfTypedefs;
1026+ std::map<std::string, std::set<std::string> > numberOfTypedefs;
10271027 for (Token* tok = list.front (); tok; tok = tok->next ()) {
10281028 if (tok->str () == " typedef" ) {
10291029 TypedefSimplifier ts (tok);
1030+ if (ts.name ().empty ())
1031+ continue ;
1032+ const Token* t = tok->next ();
1033+ std::string existing_data_type;
1034+ while (t && t->str () != ts.name ()) {
1035+ existing_data_type += t->str () + " " ;
1036+ t = t->next ();
1037+ }
10301038 if (!ts.fail ())
1031- numberOfTypedefs[ts.name ()]++ ;
1039+ numberOfTypedefs[ts.name ()]. insert (existing_data_type) ;
10321040 continue ;
10331041 }
10341042 }
@@ -1046,8 +1054,7 @@ void Tokenizer::simplifyTypedef()
10461054
10471055 if (indentlevel == 0 && tok->str () == " typedef" ) {
10481056 TypedefSimplifier ts (tok);
1049- if (!ts.fail () && numberOfTypedefs[ts.name ()] == 1 &&
1050- (numberOfTypedefs.find (ts.getTypedefToken ()->strAt (1 )) == numberOfTypedefs.end () || ts.getTypedefToken ()->strAt (2 ) == " (" )) {
1057+ if (!ts.fail () && numberOfTypedefs[ts.name ()].size () == 1 ) {
10511058 if (mSettings .severity .isEnabled (Severity::portability) && ts.isInvalidConstFunctionType (typedefs))
10521059 invalidConstFunctionTypeError (tok->next ());
10531060 typedefs.emplace (ts.name (), ts);
@@ -1060,8 +1067,11 @@ void Tokenizer::simplifyTypedef()
10601067 auto it = typedefs.find (tok->str ());
10611068 if (it != typedefs.end () && it->second .canReplace (tok)) {
10621069 std::set<std::string> r;
1070+ std::string originalname;
10631071 while (it != typedefs.end () && r.insert (tok->str ()).second ) {
1064- it->second .replace (tok);
1072+ if (originalname.empty ())
1073+ originalname = tok->str ();
1074+ it->second .replace (tok, originalname);
10651075 it = typedefs.find (tok->str ());
10661076 }
10671077 } else if (tok->str () == " enum" ) {
0 commit comments