@@ -1187,21 +1187,23 @@ void Tokenizer::simplifyTypedef()
11871187 simplifyTypedefCpp ();
11881188}
11891189
1190- static Token* simplifyTypedefCopyTokens (Token* to, const Token* fromStart, const Token* toEnd, const Token* location) {
1190+ static Token* simplifyTypedefCopyTokens (Token* to, const Token* fromStart, const Token* toEnd, const Token* location, const std::string &originalName ) {
11911191 Token* ret = TokenList::copyTokens (to, fromStart, toEnd);
11921192 for (Token* tok = to->next (); tok != ret->next (); tok = tok->next ()) {
11931193 tok->linenr (location->linenr ());
11941194 tok->column (location->column ());
11951195 tok->isSimplifiedTypedef (true );
1196+ tok->originalName (originalName);
11961197 }
11971198 return ret;
11981199}
11991200
1200- static Token* simplifyTypedefInsertToken (Token* tok, const std::string& str, const Token* location) {
1201+ static Token* simplifyTypedefInsertToken (Token* tok, const std::string& str, const Token* location, const std::string &originalName ) {
12011202 tok = tok->insertToken (str);
12021203 tok->linenr (location->linenr ());
12031204 tok->column (location->column ());
12041205 tok->isSimplifiedTypedef (true );
1206+ tok->originalName (originalName);
12051207 return tok;
12061208}
12071209
@@ -2037,12 +2039,13 @@ void Tokenizer::simplifyTypedefCpp()
20372039
20382040 // start substituting at the typedef name by replacing it with the type
20392041 const Token* location = tok2;
2042+ const std::string originalName = tok2->str ();
20402043 for (Token* tok3 = typeStart; tok3 && (tok3->str () != " ;" ); tok3 = tok3->next ())
20412044 tok3->isSimplifiedTypedef (true );
20422045 if (isPointerTypeCall) {
20432046 tok2->deleteThis ();
2044- tok2 = simplifyTypedefInsertToken (tok2, " 0" , location);
2045- simplifyTypedefInsertToken (tok2->next (), " 0" , location);
2047+ tok2 = simplifyTypedefInsertToken (tok2, " 0" , location, originalName );
2048+ simplifyTypedefInsertToken (tok2->next (), " 0" , location, originalName );
20462049 }
20472050 if (Token::Match (tok2->tokAt (-1 ), " class|struct|union" ) && tok2->strAt (-1 ) == typeStart->str ())
20482051 tok2->deletePrevious ();
@@ -2051,7 +2054,7 @@ void Tokenizer::simplifyTypedefCpp()
20512054 tok2->previous ()->str (" typedef" );
20522055 tok2->insertToken (tok2->str ());
20532056 }
2054- tok2->originalName (tok2-> str () );
2057+ tok2->originalName (originalName );
20552058 tok2->str (typeStart->str ());
20562059
20572060 // restore qualification if it was removed
@@ -2060,12 +2063,12 @@ void Tokenizer::simplifyTypedefCpp()
20602063 tok2 = tok2->previous ();
20612064
20622065 if (globalScope) {
2063- tok2 = simplifyTypedefInsertToken (tok2, " ::" , location);
2066+ tok2 = simplifyTypedefInsertToken (tok2, " ::" , location, originalName );
20642067 }
20652068
20662069 for (std::size_t i = classLevel; i < spaceInfo.size (); ++i) {
2067- tok2 = simplifyTypedefInsertToken (tok2, spaceInfo[i].className , location);
2068- tok2 = simplifyTypedefInsertToken (tok2, " ::" , location);
2070+ tok2 = simplifyTypedefInsertToken (tok2, spaceInfo[i].className , location, originalName );
2071+ tok2 = simplifyTypedefInsertToken (tok2, " ::" , location, originalName );
20692072 }
20702073 }
20712074
@@ -2082,11 +2085,11 @@ void Tokenizer::simplifyTypedefCpp()
20822085 std::string::size_type spaceIdx = 0 ;
20832086 std::string::size_type startIdx = 0 ;
20842087 while ((spaceIdx = removed1.find (' ' , startIdx)) != std::string::npos) {
2085- simplifyTypedefInsertToken (tok2->previous (), removed1.substr (startIdx, spaceIdx - startIdx), location);
2088+ simplifyTypedefInsertToken (tok2->previous (), removed1.substr (startIdx, spaceIdx - startIdx), location, originalName );
20862089 startIdx = spaceIdx + 1 ;
20872090 }
2088- simplifyTypedefInsertToken (tok2->previous (), removed1.substr (startIdx), location);
2089- simplifyTypedefInsertToken (tok2->previous (), " ::" , location);
2091+ simplifyTypedefInsertToken (tok2->previous (), removed1.substr (startIdx), location, originalName );
2092+ simplifyTypedefInsertToken (tok2->previous (), " ::" , location, originalName );
20902093 break ;
20912094 }
20922095 idx = removed1.rfind (" ::" );
@@ -2098,23 +2101,23 @@ void Tokenizer::simplifyTypedefCpp()
20982101 }
20992102 Token* constTok = Token::simpleMatch (tok2->previous (), " const" ) ? tok2->previous () : nullptr ;
21002103 // add remainder of type
2101- tok2 = simplifyTypedefCopyTokens (tok2, typeStart->next (), typeEnd, location);
2104+ tok2 = simplifyTypedefCopyTokens (tok2, typeStart->next (), typeEnd, location, originalName );
21022105
21032106 if (!pointers.empty ()) {
21042107 for (const std::string &p : pointers)
21052108 // cppcheck-suppress useStlAlgorithm
2106- tok2 = simplifyTypedefInsertToken (tok2, p, location);
2109+ tok2 = simplifyTypedefInsertToken (tok2, p, location, originalName );
21072110 if (constTok && !functionPtr) {
2108- tok2 = simplifyTypedefInsertToken (tok2, " const" , location);
2111+ tok2 = simplifyTypedefInsertToken (tok2, " const" , location, originalName );
21092112 constTok->deleteThis ();
21102113 location = constTok;
21112114 }
21122115 }
21132116
21142117 if (funcStart && funcEnd) {
2115- tok2 = simplifyTypedefInsertToken (tok2, " (" , location);
2118+ tok2 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
21162119 Token *paren = tok2;
2117- tok2 = simplifyTypedefCopyTokens (tok2, funcStart, funcEnd, location);
2120+ tok2 = simplifyTypedefCopyTokens (tok2, funcStart, funcEnd, location, originalName );
21182121
21192122 if (!inCast)
21202123 tok2 = processFunc (tok2, inOperator);
@@ -2125,17 +2128,17 @@ void Tokenizer::simplifyTypedefCpp()
21252128 while (Token::Match (tok2, " %name%|] [" ))
21262129 tok2 = tok2->linkAt (1 );
21272130
2128- tok2 = simplifyTypedefInsertToken (tok2, " )" , location);
2131+ tok2 = simplifyTypedefInsertToken (tok2, " )" , location, originalName );
21292132 Token::createMutualLinks (tok2, paren);
21302133
2131- tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location);
2134+ tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location, originalName );
21322135
21332136 if (specStart) {
21342137 Token *spec = specStart;
2135- tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location);
2138+ tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location, originalName );
21362139 while (spec != specEnd) {
21372140 spec = spec->next ();
2138- tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location);
2141+ tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location, originalName );
21392142 }
21402143 }
21412144 }
@@ -2147,20 +2150,20 @@ void Tokenizer::simplifyTypedefCpp()
21472150 if (!inTemplate && function && tok2->next () && tok2->strAt (1 ) != " *" )
21482151 needParen = false ;
21492152 if (needParen) {
2150- tok2 = simplifyTypedefInsertToken (tok2, " (" , location);
2153+ tok2 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
21512154 }
21522155 Token *tok3 = tok2;
21532156 if (namespaceStart) {
21542157 const Token *tok4 = namespaceStart;
21552158
21562159 while (tok4 != namespaceEnd) {
2157- tok2 = simplifyTypedefInsertToken (tok2, tok4->str (), location);
2160+ tok2 = simplifyTypedefInsertToken (tok2, tok4->str (), location, originalName );
21582161 tok4 = tok4->next ();
21592162 }
2160- tok2 = simplifyTypedefInsertToken (tok2, namespaceEnd->str (), location);
2163+ tok2 = simplifyTypedefInsertToken (tok2, namespaceEnd->str (), location, originalName );
21612164 }
21622165 if (functionPtr) {
2163- tok2 = simplifyTypedefInsertToken (tok2, " *" , location);
2166+ tok2 = simplifyTypedefInsertToken (tok2, " *" , location, originalName );
21642167 }
21652168
21662169 if (!inCast)
@@ -2170,35 +2173,35 @@ void Tokenizer::simplifyTypedefCpp()
21702173 if (!tok2)
21712174 syntaxError (nullptr );
21722175
2173- tok2 = simplifyTypedefInsertToken (tok2, " )" , location);
2176+ tok2 = simplifyTypedefInsertToken (tok2, " )" , location, originalName );
21742177 Token::createMutualLinks (tok2, tok3);
21752178 }
21762179 if (!tok2)
21772180 syntaxError (nullptr );
21782181
2179- tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location);
2182+ tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location, originalName );
21802183 if (inTemplate) {
21812184 tok2 = tok2->next ();
21822185 }
21832186
21842187 if (specStart) {
21852188 Token *spec = specStart;
2186- tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location);
2189+ tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location, originalName );
21872190 while (spec != specEnd) {
21882191 spec = spec->next ();
2189- tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location);
2192+ tok2 = simplifyTypedefInsertToken (tok2, spec->str (), location, originalName );
21902193 }
21912194 }
21922195 } else if (functionRetFuncPtr || functionPtrRetFuncPtr) {
2193- tok2 = simplifyTypedefInsertToken (tok2, " (" , location);
2196+ tok2 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
21942197 Token *tok3 = tok2;
2195- tok2 = simplifyTypedefInsertToken (tok2, " *" , location);
2198+ tok2 = simplifyTypedefInsertToken (tok2, " *" , location, originalName );
21962199
21972200 Token * tok4 = nullptr ;
21982201 if (functionPtrRetFuncPtr) {
2199- tok2 = simplifyTypedefInsertToken (tok2, " (" , location);
2202+ tok2 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
22002203 tok4 = tok2;
2201- tok2 = simplifyTypedefInsertToken (tok2, " *" , location);
2204+ tok2 = simplifyTypedefInsertToken (tok2, " *" , location, originalName );
22022205 }
22032206
22042207 // skip over variable name if there
@@ -2211,24 +2214,24 @@ void Tokenizer::simplifyTypedefCpp()
22112214 }
22122215
22132216 if (tok4 && functionPtrRetFuncPtr) {
2214- tok2 = simplifyTypedefInsertToken (tok2," )" , location);
2217+ tok2 = simplifyTypedefInsertToken (tok2," )" , location, originalName );
22152218 Token::createMutualLinks (tok2, tok4);
22162219 }
22172220
2218- tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location);
2221+ tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location, originalName );
22192222
2220- tok2 = simplifyTypedefInsertToken (tok2, " )" , location);
2223+ tok2 = simplifyTypedefInsertToken (tok2, " )" , location, originalName );
22212224 Token::createMutualLinks (tok2, tok3);
22222225
2223- tok2 = simplifyTypedefCopyTokens (tok2, argFuncRetStart, argFuncRetEnd, location);
2226+ tok2 = simplifyTypedefCopyTokens (tok2, argFuncRetStart, argFuncRetEnd, location, originalName );
22242227 } else if (ptrToArray || refToArray) {
2225- tok2 = simplifyTypedefInsertToken (tok2, " (" , location);
2228+ tok2 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
22262229 Token *tok3 = tok2;
22272230
22282231 if (ptrToArray)
2229- tok2 = simplifyTypedefInsertToken (tok2, " *" , location);
2232+ tok2 = simplifyTypedefInsertToken (tok2, " *" , location, originalName );
22302233 else
2231- tok2 = simplifyTypedefInsertToken (tok2, " &" , location);
2234+ tok2 = simplifyTypedefInsertToken (tok2, " &" , location, originalName );
22322235
22332236 bool hasName = false ;
22342237 // skip over name
@@ -2247,14 +2250,14 @@ void Tokenizer::simplifyTypedefCpp()
22472250 tok2 = tok2->linkAt (1 );
22482251 }
22492252
2250- simplifyTypedefInsertToken (tok2, " )" , location);
2253+ simplifyTypedefInsertToken (tok2, " )" , location, originalName );
22512254 Token::createMutualLinks (tok2->next (), tok3);
22522255
22532256 if (!hasName)
22542257 tok2 = tok2->next ();
22552258 } else if (ptrMember) {
22562259 if (Token::simpleMatch (tok2, " * (" )) {
2257- tok2 = simplifyTypedefInsertToken (tok2, " *" , location);
2260+ tok2 = simplifyTypedefInsertToken (tok2, " *" , location, originalName );
22582261 } else {
22592262 // This is the case of casting operator.
22602263 // Name is not available, and () should not be
@@ -2263,33 +2266,33 @@ void Tokenizer::simplifyTypedefCpp()
22632266 Token *openParenthesis = nullptr ;
22642267
22652268 if (!castOperator) {
2266- tok2 = simplifyTypedefInsertToken (tok2, " (" , location);
2269+ tok2 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
22672270
22682271 openParenthesis = tok2;
22692272 }
22702273
22712274 const Token *tok4 = namespaceStart;
22722275
22732276 while (tok4 != namespaceEnd) {
2274- tok2 = simplifyTypedefInsertToken (tok2, tok4->str (), location);
2277+ tok2 = simplifyTypedefInsertToken (tok2, tok4->str (), location, originalName );
22752278 tok4 = tok4->next ();
22762279 }
2277- tok2 = simplifyTypedefInsertToken (tok2, namespaceEnd->str (), location);
2280+ tok2 = simplifyTypedefInsertToken (tok2, namespaceEnd->str (), location, originalName );
22782281
2279- tok2 = simplifyTypedefInsertToken (tok2, " *" , location);
2282+ tok2 = simplifyTypedefInsertToken (tok2, " *" , location, originalName );
22802283
22812284 if (openParenthesis) {
22822285 // Skip over name, if any
22832286 if (Token::Match (tok2->next (), " %name%" ))
22842287 tok2 = tok2->next ();
22852288
2286- tok2 = simplifyTypedefInsertToken (tok2, " )" , location);
2289+ tok2 = simplifyTypedefInsertToken (tok2, " )" , location, originalName );
22872290
22882291 Token::createMutualLinks (tok2, openParenthesis);
22892292 }
22902293 }
22912294 } else if (typeOf) {
2292- tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location);
2295+ tok2 = simplifyTypedefCopyTokens (tok2, argStart, argEnd, location, originalName );
22932296 } else if (Token::Match (tok2, " %name% [" )) {
22942297 while (Token::Match (tok2, " %name%|] [" )) {
22952298 tok2 = tok2->linkAt (1 );
@@ -2311,7 +2314,7 @@ void Tokenizer::simplifyTypedefCpp()
23112314 // reference or pointer to array?
23122315 if (Token::Match (tok2, " &|*|&&" )) {
23132316 tok2 = tok2->previous ();
2314- Token *tok3 = simplifyTypedefInsertToken (tok2, " (" , location);
2317+ Token *tok3 = simplifyTypedefInsertToken (tok2, " (" , location, originalName );
23152318
23162319 // handle missing variable name
23172320 if (Token::Match (tok3, " ( *|&|&& *|&|&& %name%" ))
@@ -2349,7 +2352,7 @@ void Tokenizer::simplifyTypedefCpp()
23492352 tok2 = tok2->tokAt (3 );
23502353 }
23512354
2352- tok2 = simplifyTypedefInsertToken (tok2, " )" , location);
2355+ tok2 = simplifyTypedefInsertToken (tok2, " )" , location, originalName );
23532356 Token::createMutualLinks (tok2, tok3);
23542357 }
23552358
@@ -2360,7 +2363,7 @@ void Tokenizer::simplifyTypedefCpp()
23602363 while (tok2->strAt (1 ) == " [" )
23612364 tok2 = tok2->linkAt (1 );
23622365
2363- tok2 = simplifyTypedefCopyTokens (tok2, arrayStart, arrayEnd, location);
2366+ tok2 = simplifyTypedefCopyTokens (tok2, arrayStart, arrayEnd, location, originalName );
23642367 if (!tok2->next ())
23652368 syntaxError (tok2);
23662369
0 commit comments