@@ -93,12 +93,7 @@ static void skipEnumBody(T **tok)
9393 *tok = defStart->link ()->next ();
9494}
9595
96- const Token * Tokenizer::isFunctionHead (const Token *tok, const std::string &endsWith) const
97- {
98- return Tokenizer::isFunctionHead (tok, endsWith, isCPP ());
99- }
100-
101- const Token * Tokenizer::isFunctionHead (const Token *tok, const std::string &endsWith, bool cpp)
96+ const Token * Tokenizer::isFunctionHead (const Token *tok, const std::string &endsWith)
10297{
10398 if (!tok)
10499 return nullptr ;
@@ -113,7 +108,7 @@ const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &end
113108 }
114109 return (tok && endsWith.find (tok->str ()) != std::string::npos) ? tok : nullptr ;
115110 }
116- if (cpp && tok->str () == " )" ) {
111+ if (tok-> isCpp () && tok->str () == " )" ) {
117112 tok = tok->next ();
118113 while (Token::Match (tok, " const|noexcept|override|final|volatile|mutable|&|&& !!(" ) ||
119114 (Token::Match (tok, " %name% !!(" ) && tok->isUpperCaseName ()))
@@ -2791,7 +2786,7 @@ namespace {
27912786 }
27922787} // namespace
27932788
2794- bool Tokenizer::isMemberFunction (const Token *openParen) const
2789+ bool Tokenizer::isMemberFunction (const Token *openParen)
27952790{
27962791 return (Token::Match (openParen->tokAt (-2 ), " :: %name% (" ) ||
27972792 Token::Match (openParen->tokAt (-3 ), " :: ~ %name% (" )) &&
@@ -3901,7 +3896,7 @@ const Token * Tokenizer::startOfExecutableScope(const Token * tok)
39013896 if (tok->str () != " )" )
39023897 return nullptr ;
39033898
3904- tok = isFunctionHead (tok, " :{" , true );
3899+ tok = Tokenizer:: isFunctionHead (tok, " :{" );
39053900
39063901 if (Token::Match (tok, " : %name% [({]" )) {
39073902 while (Token::Match (tok, " [:,] %name% [({]" ))
@@ -4088,32 +4083,31 @@ void Tokenizer::simplifyTemplates()
40884083// ---------------------------------------------------------------------------
40894084
40904085
4091- /* * Class used in Tokenizer::setVarIdPass1 */
4092- class VariableMap {
4093- private:
4094- std::unordered_map<std::string, nonneg int > mVariableId ;
4095- std::unordered_map<std::string, nonneg int > mVariableId_global ;
4096- std::stack<std::vector<std::pair<std::string, nonneg int >>> mScopeInfo ;
4097- mutable nonneg int mVarId {};
4098- public:
4099- VariableMap () = default ;
4100- void enterScope ();
4101- bool leaveScope ();
4102- void addVariable (const std::string& varname, bool globalNamespace);
4103- bool hasVariable (const std::string& varname) const {
4104- return mVariableId .find (varname) != mVariableId .end ();
4105- }
4086+ namespace {
4087+ /* * Class used in Tokenizer::setVarIdPass1 */
4088+ class VariableMap {
4089+ private:
4090+ std::unordered_map<std::string, nonneg int > mVariableId ;
4091+ std::unordered_map<std::string, nonneg int > mVariableId_global ;
4092+ std::stack<std::vector<std::pair<std::string, nonneg int >>> mScopeInfo ;
4093+ mutable nonneg int mVarId {};
4094+ public:
4095+ VariableMap () = default ;
4096+ void enterScope ();
4097+ bool leaveScope ();
4098+ void addVariable (const std::string& varname, bool globalNamespace);
4099+ bool hasVariable (const std::string& varname) const {
4100+ return mVariableId .find (varname) != mVariableId .end ();
4101+ }
41064102
4107- const std::unordered_map<std::string, nonneg int >& map (bool global) const {
4108- return global ? mVariableId_global : mVariableId ;
4109- }
4110- nonneg int getVarId () const {
4111- return mVarId ;
4112- }
4113- nonneg int & getVarId () {
4114- return mVarId ;
4115- }
4116- };
4103+ const std::unordered_map<std::string, nonneg int >& map (bool global) const {
4104+ return global ? mVariableId_global : mVariableId ;
4105+ }
4106+ nonneg int & getVarId () {
4107+ return mVarId ;
4108+ }
4109+ };
4110+ }
41174111
41184112
41194113void VariableMap::enterScope ()
@@ -4298,9 +4292,9 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap
42984292}
42994293
43004294
4301- void Tokenizer:: setVarIdStructMembers (Token **tok1,
4302- std::map<nonneg int , std::map<std::string, nonneg int >>& structMembers,
4303- nonneg int &varId) const
4295+ static void setVarIdStructMembers (Token **tok1,
4296+ std::map<nonneg int , std::map<std::string, nonneg int >>& structMembers,
4297+ nonneg int &varId)
43044298{
43054299 Token *tok = *tok1;
43064300
@@ -4334,7 +4328,7 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
43344328 while (Token::Match (tok->next (), " )| . %name% !!(" )) {
43354329 // Don't set varid for trailing return type
43364330 if (tok->strAt (1 ) == " )" && (tok->linkAt (1 )->previous ()->isName () || tok->linkAt (1 )->strAt (-1 ) == " ]" ) &&
4337- isFunctionHead (tok->linkAt (1 ), " {|;" )) {
4331+ Tokenizer:: isFunctionHead (tok->linkAt (1 ), " {|;" )) {
43384332 tok = tok->tokAt (3 );
43394333 continue ;
43404334 }
@@ -4363,10 +4357,10 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
43634357 *tok1 = tok;
43644358}
43654359
4366- void Tokenizer:: setVarIdClassDeclaration (Token* const startToken,
4367- VariableMap& variableMap,
4368- const nonneg int scopeStartVarId,
4369- std::map<nonneg int , std::map<std::string, nonneg int >>& structMembers)
4360+ static bool setVarIdClassDeclaration (Token* const startToken,
4361+ VariableMap& variableMap,
4362+ const nonneg int scopeStartVarId,
4363+ std::map<nonneg int , std::map<std::string, nonneg int >>& structMembers)
43704364{
43714365 // end of scope
43724366 const Token* const endToken = startToken->link ();
@@ -4389,7 +4383,7 @@ void Tokenizer::setVarIdClassDeclaration(Token* const startToken,
43894383 const Token *initListArgLastToken = nullptr ;
43904384 for (Token *tok = startToken->next (); tok != endToken; tok = tok->next ()) {
43914385 if (!tok)
4392- syntaxError ( nullptr ) ;
4386+ return false ;
43934387 if (initList) {
43944388 if (tok == initListArgLastToken)
43954389 initListArgLastToken = nullptr ;
@@ -4416,7 +4410,7 @@ void Tokenizer::setVarIdClassDeclaration(Token* const startToken,
44164410 if (Token::Match (tok->previous (), " ::|." ) && tok->strAt (-2 ) != " this" && !Token::simpleMatch (tok->tokAt (-5 ), " ( * this ) ." ))
44174411 continue ;
44184412 if (!tok->next ())
4419- syntaxError ( nullptr ) ;
4413+ return false ;
44204414 if (tok->next ()->str () == " ::" ) {
44214415 if (tok->str () == className)
44224416 tok = tok->tokAt (2 );
@@ -4435,6 +4429,7 @@ void Tokenizer::setVarIdClassDeclaration(Token* const startToken,
44354429 } else if (indentlevel == 0 && tok->str () == " :" && !initListArgLastToken)
44364430 initList = true ;
44374431 }
4432+ return true ;
44384433}
44394434
44404435
@@ -4602,10 +4597,12 @@ void Tokenizer::setVarIdPass1()
46024597 }
46034598 // Set variable ids in class declaration..
46044599 if (!initlist && !isC () && !scopeStack.top ().isExecutable && tok->link () && !isNamespace) {
4605- setVarIdClassDeclaration (tok->link (),
4606- variableMap,
4607- scopeStack.top ().startVarid ,
4608- structMembers);
4600+ if (!setVarIdClassDeclaration (tok->link (),
4601+ variableMap,
4602+ scopeStack.top ().startVarid ,
4603+ structMembers)) {
4604+ syntaxError (nullptr );
4605+ }
46094606 }
46104607
46114608 if (!scopeStack.top ().isStructInit ) {
@@ -9883,7 +9880,7 @@ void Tokenizer::createSymbolDatabase()
98839880 mSymbolDatabase ->validate ();
98849881}
98859882
9886- bool Tokenizer::operatorEnd (const Token * tok) const
9883+ bool Tokenizer::operatorEnd (const Token * tok)
98879884{
98889885 if (tok && tok->str () == " )" ) {
98899886 if (isFunctionHead (tok, " {|;|?|:|[" ))
0 commit comments