@@ -204,20 +204,6 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last,
204204
205205// ---------------------------------------------------------------------------
206206
207- void Tokenizer::duplicateTypedefError (const Token *tok1, const Token *tok2, const std::string &type) const
208- {
209- if (tok1 && !(_settings->isEnabled (" style" ) && _settings->inconclusive ))
210- return ;
211-
212- std::list<const Token*> locationList;
213- locationList.push_back (tok1);
214- locationList.push_back (tok2);
215- const std::string tok2_str = tok2 ? tok2->str () : std::string (" name" );
216-
217- reportError (locationList, Severity::style, " variableHidingTypedef" ,
218- std::string (" The " + type + " '" + tok2_str + " ' hides a typedef with the same name." ), true );
219- }
220-
221207// check if this statement is a duplicate definition
222208bool Tokenizer::duplicateTypedef (Token **tokPtr, const Token *name, const Token *typeDef, const std::set<std::string>& structs) const
223209{
@@ -260,7 +246,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
260246 if (!Token::Match (tok->tokAt (-3 ), " ,|<" ))
261247 return false ;
262248
263- duplicateTypedefError (*tokPtr, name, " template instantiation" );
264249 *tokPtr = end->link ();
265250 return true ;
266251 }
@@ -271,7 +256,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
271256 // look backwards
272257 if (Token::Match (tok->previous (), " %type%" ) &&
273258 !Token::Match (tok->previous (), " return|new|const|struct" )) {
274- duplicateTypedefError (*tokPtr, name, " function parameter" );
275259 // duplicate definition so skip entire function
276260 *tokPtr = end->next ()->link ();
277261 return true ;
@@ -284,7 +268,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
284268 while (end && end->str () != " {" )
285269 end = end->next ();
286270 if (end) {
287- duplicateTypedefError (*tokPtr, name, " template parameter" );
288271 *tokPtr = end->link ();
289272 return true ;
290273 }
@@ -302,10 +285,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
302285 if (tok->previous ()->str () == " }" ) {
303286 tok = tok->previous ()->link ();
304287 } else if (tok->previous ()->str () == " typedef" ) {
305- duplicateTypedefError (*tokPtr, name, " typedef" );
306288 return true ;
307289 } else if (tok->previous ()->str () == " enum" ) {
308- duplicateTypedefError (*tokPtr, name, " enum" );
309290 return true ;
310291 } else if (tok->previous ()->str () == " struct" ) {
311292 if (tok->strAt (-2 ) == " typedef" &&
@@ -315,28 +296,24 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
315296 return true ;
316297 } else if (tok->next ()->str () == " {" ) {
317298 if (structs.find (name->strAt (-1 )) == structs.end ())
318- duplicateTypedefError (*tokPtr, name, " struct" );
319299 return true ;
320300 } else if (Token::Match (tok->next (), " )|*" )) {
321301 return true ;
322302 } else if (tok->next ()->str () == name->str ()) {
323303 return true ;
324304 } else if (tok->next ()->str () != " ;" ) {
325- duplicateTypedefError (*tokPtr, name, " struct" );
326305 return true ;
327306 } else {
328307 return false ;
329308 }
330309 } else if (tok->previous ()->str () == " union" ) {
331310 if (tok->next ()->str () != " ;" ) {
332- duplicateTypedefError (*tokPtr, name, " union" );
333311 return true ;
334312 } else {
335313 return false ;
336314 }
337315 } else if (isCPP () && tok->previous ()->str () == " class" ) {
338316 if (tok->next ()->str () != " ;" ) {
339- duplicateTypedefError (*tokPtr, name, " class" );
340317 return true ;
341318 } else {
342319 return false ;
@@ -347,7 +324,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
347324 }
348325
349326 if ((*tokPtr)->strAt (1 ) != " (" || !Token::Match ((*tokPtr)->linkAt (1 ), " ) .|(|[" )) {
350- duplicateTypedefError (*tokPtr, name, " variable" );
351327 return true ;
352328 }
353329 }
@@ -7224,24 +7200,10 @@ void Tokenizer::simplifyNestedStrcat()
72247200 }
72257201}
72267202
7227- void Tokenizer::duplicateEnumError (const Token * tok1, const Token * tok2, const std::string & type) const
7228- {
7229- if (tok1 && !(_settings->isEnabled (" style" )))
7230- return ;
7231-
7232- std::list<const Token*> locationList;
7233- locationList.push_back (tok1);
7234- locationList.push_back (tok2);
7235- const std::string tok2_str = tok2 ? tok2->str () : std::string (" name" );
7236-
7237- reportError (locationList, Severity::style, " variableHidingEnum" ,
7238- std::string (type + " '" + tok2_str + " ' hides enumerator with same name" ));
7239- }
7240-
72417203// Check if this statement is a duplicate definition. A duplicate
72427204// definition will hide the enumerator within it's scope so just
72437205// skip the entire scope of the duplicate.
7244- bool Tokenizer::duplicateDefinition (Token ** tokPtr, const Token * name ) const
7206+ bool Tokenizer::duplicateDefinition (Token ** tokPtr) const
72457207{
72467208 // check for an end of definition
72477209 const Token * tok = *tokPtr;
@@ -7283,7 +7245,6 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const
72837245 (Token::Match (tok->previous (), " %type%" ) &&
72847246 tok->previous ()->str () != " return" ) ||
72857247 Token::Match (tok->tokAt (-2 ), " %type% &|*" )) {
7286- duplicateEnumError (*tokPtr, name, " Function parameter" );
72877248 // duplicate definition so skip entire function
72887249 *tokPtr = end->next ()->link ();
72897250 return true ;
@@ -7297,22 +7258,19 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const
72977258 while (end && end->str () != " {" )
72987259 end = end->next ();
72997260 if (end) {
7300- duplicateEnumError (*tokPtr, name, " Template parameter" );
73017261 *tokPtr = end->link ();
73027262 return true ;
73037263 }
73047264 }
73057265 } else {
73067266 if (Token::Match (tok->previous (), " enum|," )) {
7307- duplicateEnumError (*tokPtr, name, " Variable" );
73087267 return true ;
73097268 } else if (Token::Match (tok->previous (), " %type%" )) {
73107269 // look backwards
73117270 const Token *back = tok;
73127271 while (back && back->isName ())
73137272 back = back->previous ();
73147273 if (!back || (Token::Match (back, " [(,;{}]" ) && !Token::Match (back->next ()," return|throw" ))) {
7315- duplicateEnumError (*tokPtr, name, " Variable" );
73167274 return true ;
73177275 }
73187276 }
@@ -7371,7 +7329,8 @@ class EnumValue {
73717329 }
73727330
73737331 // Simplify calculations..
7374- while (start && start->previous () && TemplateSimplifier::simplifyNumericCalculations (start->previous ())) { }
7332+ while (start && start->previous () && TemplateSimplifier::simplifyNumericCalculations (start->previous ()))
7333+ { }
73757334
73767335 if (Token::Match (start, " %num% [,}]" )) {
73777336 value = start;
@@ -7390,7 +7349,6 @@ void Tokenizer::simplifyEnum()
73907349 std::string className;
73917350 int classLevel = 0 ;
73927351 bool goback = false ;
7393- const bool printStyle = _settings->isEnabled (" style" );
73947352 for (Token *tok = list.front (); tok; tok = tok->next ()) {
73957353
73967354 if (goback) {
@@ -7646,10 +7604,6 @@ void Tokenizer::simplifyEnum()
76467604 if (prev->str () == " (" && (!Token::Match (prev->tokAt (-2 ), " %type%|::|*|& %type% (" ) || prev->strAt (-2 ) == " else" ))
76477605 continue ;
76487606 shadowVars.insert (arg->str ());
7649- if (inScope && printStyle) {
7650- const EnumValue& enumValue = enumValues.find (arg->str ())->second ;
7651- duplicateEnumError (arg, enumValue.name , " Function argument" );
7652- }
76537607 }
76547608 }
76557609 }
@@ -7666,10 +7620,6 @@ void Tokenizer::simplifyEnum()
76667620 (Token::Match (prev->previous (), " %type% *|&" ) && (prev->previous ()->isStandardType () || prev->strAt (-1 ) == " const" || Token::Match (prev->tokAt (-2 ), " ;|{|}" )))) {
76677621 // variable declaration?
76687622 shadowVars.insert (tok3->str ());
7669- if (inScope && printStyle) {
7670- const EnumValue& enumValue = enumValues.find (tok3->str ())->second ;
7671- duplicateEnumError (tok3, enumValue.name , " Variable" );
7672- }
76737623 }
76747624 }
76757625 }
@@ -7702,7 +7652,7 @@ void Tokenizer::simplifyEnum()
77027652 (shadowId.empty () || shadowId.top ().find (tok2->str ()) == shadowId.top ().end ()) && // no shadow enum/var/etc of enum
77037653 enumValues.find (tok2->str ()) != enumValues.end ()) { // tok2 is a enum id with a known value
77047654 ev = &(enumValues.find (tok2->str ())->second );
7705- if (!duplicateDefinition (&tok2, ev-> name )) {
7655+ if (!duplicateDefinition (&tok2)) {
77067656 if (tok2->strAt (-1 ) == " ::" ||
77077657 Token::Match (tok2->next (), " ::|[|=" )) {
77087658 // Don't replace this enum if:
@@ -8734,14 +8684,7 @@ std::string Tokenizer::simplifyString(const std::string &source)
87348684
87358685 return str;
87368686}
8737-
8738- void Tokenizer::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings)
8739- {
8740- Tokenizer t (settings, errorLogger);
8741- t.duplicateTypedefError (0 , 0 , " variable" );
8742- t.duplicateEnumError (0 , 0 , " variable" );
8743- }
8744-
8687+
87458688void Tokenizer::simplifyWhile0 ()
87468689{
87478690 for (Token *tok = list.front (); tok; tok = tok->next ()) {
0 commit comments