@@ -1147,6 +1147,7 @@ void Tokenizer::simplifyTypedef()
11471147
11481148void Tokenizer::simplifyTypedefCpp ()
11491149{
1150+ const bool cpp = isCPP ();
11501151 bool isNamespace = false ;
11511152 std::string className, fullClassName;
11521153 bool hasClass = false ;
@@ -1714,7 +1715,7 @@ void Tokenizer::simplifyTypedefCpp()
17141715 }
17151716
17161717 // check for member functions
1717- else if (tok2-> isCpp () && tok2->str () == " (" && isFunctionHead (tok2, " {:" )) {
1718+ else if (cpp && tok2->str () == " (" && isFunctionHead (tok2, " {:" )) {
17181719 const Token *func = tok2->previous ();
17191720
17201721 /* * @todo add support for multi-token operators */
@@ -1741,7 +1742,7 @@ void Tokenizer::simplifyTypedefCpp()
17411742 // check for entering a new scope
17421743 else if (tok2->str () == " {" ) {
17431744 // check for entering a new namespace
1744- if (tok2-> isCpp () ) {
1745+ if (cpp ) {
17451746 if (tok2->strAt (-2 ) == " namespace" ) {
17461747 if (classLevel < spaceInfo.size () &&
17471748 spaceInfo[classLevel].isNamespace &&
@@ -1770,7 +1771,7 @@ void Tokenizer::simplifyTypedefCpp()
17701771
17711772 // check for operator typedef
17721773 /* * @todo add support for multi-token operators */
1773- else if (tok2-> isCpp () &&
1774+ else if (cpp &&
17741775 tok2->str () == " operator" &&
17751776 tok2->next () &&
17761777 tok2->next ()->str () == typeName->str () &&
@@ -4526,6 +4527,7 @@ static const std::unordered_set<std::string> notstart_cpp = { NOTSTART_C,
45264527
45274528void Tokenizer::setVarIdPass1 ()
45284529{
4530+ const bool cpp = isCPP ();
45294531 // Variable declarations can't start with "return" etc.
45304532 const std::unordered_set<std::string>& notstart = (isC ()) ? notstart_c : notstart_cpp;
45314533
@@ -4542,7 +4544,7 @@ void Tokenizer::setVarIdPass1()
45424544 for (Token *tok = list.front (); tok; tok = tok->next ()) {
45434545 if (tok->isOp ())
45444546 continue ;
4545- if (tok-> isCpp () && Token::simpleMatch (tok, " template <" )) {
4547+ if (cpp && Token::simpleMatch (tok, " template <" )) {
45464548 Token* closingBracket = tok->next ()->findClosingBracket ();
45474549 if (closingBracket)
45484550 tok = closingBracket;
@@ -4697,7 +4699,7 @@ void Tokenizer::setVarIdPass1()
46974699 continue ;
46984700
46994701 bool decl;
4700- if (isCPP () && mSettings .standards .cpp >= Standards::CPP17 && Token::Match (tok, " [(;{}] const| auto &|&&| [" )) {
4702+ if (cpp && mSettings .standards .cpp >= Standards::CPP17 && Token::Match (tok, " [(;{}] const| auto &|&&| [" )) {
47014703 // Structured bindings
47024704 tok2 = Token::findsimplematch (tok, " [" );
47034705 if ((Token::simpleMatch (tok->previous (), " for (" ) && Token::simpleMatch (tok2->link (), " ] :" )) ||
@@ -4721,7 +4723,7 @@ void Tokenizer::setVarIdPass1()
47214723 inlineFunction = true ;
47224724
47234725 if (decl) {
4724- if (isCPP () ) {
4726+ if (cpp ) {
47254727 if (Token *declTypeTok = Token::findsimplematch (tok, " decltype (" , tok2)) {
47264728 for (Token *declTok = declTypeTok->linkAt (1 ); declTok != declTypeTok; declTok = declTok->previous ()) {
47274729 if (declTok->isName () && !Token::Match (declTok->previous (), " ::|." ) && variableMap.hasVariable (declTok->str ()))
@@ -4737,7 +4739,7 @@ void Tokenizer::setVarIdPass1()
47374739 ;
47384740 else if (Token::Match (prev2, " %type% ( !!)" ) && Token::simpleMatch (tok2->link (), " ) ;" )) {
47394741 // In C++ , a variable can't be called operator+ or something like that.
4740- if (prev2-> isCpp () &&
4742+ if (cpp &&
47414743 prev2->isOperatorKeyword ())
47424744 continue ;
47434745
@@ -4774,7 +4776,7 @@ void Tokenizer::setVarIdPass1()
47744776 }
47754777 } else
47764778 decl = false ;
4777- } else if (isCPP () && Token::Match (prev2, " %type% {" ) && Token::simpleMatch (tok2->link (), " } ;" )) { // C++11 initialization style
4779+ } else if (cpp && Token::Match (prev2, " %type% {" ) && Token::simpleMatch (tok2->link (), " } ;" )) { // C++11 initialization style
47784780 if (tok2->link () != tok2->next () && // add value-initialized variable T x{};
47794781 (Token::Match (prev2, " do|try|else" ) || Token::Match (prev2->tokAt (-2 ), " struct|class|:" )))
47804782 continue ;
@@ -4819,7 +4821,7 @@ void Tokenizer::setVarIdPass1()
48194821
48204822 if (tok->isName () && !tok->isKeyword () && !tok->isStandardType ()) {
48214823 // don't set variable id after a struct|enum|union
4822- if (Token::Match (tok->previous (), " struct|enum|union" ) || (tok-> isCpp () && tok->strAt (-1 ) == " class" ))
4824+ if (Token::Match (tok->previous (), " struct|enum|union" ) || (cpp && tok->strAt (-1 ) == " class" ))
48234825 continue ;
48244826
48254827 bool globalNamespace = false ;
@@ -7056,7 +7058,8 @@ void Tokenizer::simplifyVarDecl(const bool only_k_r_fpar)
70567058
70577059void Tokenizer::simplifyVarDecl (Token * tokBegin, const Token * const tokEnd, const bool only_k_r_fpar)
70587060{
7059- const bool isCPP11 = isCPP () && (mSettings .standards .cpp >= Standards::CPP11);
7061+ const bool cpp = isCPP ();
7062+ const bool isCPP11 = cpp && (mSettings .standards .cpp >= Standards::CPP11);
70607063
70617064 // Split up variable declarations..
70627065 // "int a=4;" => "int a; a=4;"
@@ -7065,7 +7068,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
70657068 for (Token *tok = tokBegin; tok != tokEnd; tok = tok->next ()) {
70667069 if (Token::Match (tok, " {|;" ))
70677070 scopeDecl = false ;
7068- if (isCPP () ) {
7071+ if (cpp ) {
70697072 if (Token::Match (tok, " class|struct|namespace|union" ))
70707073 scopeDecl = true ;
70717074 if (Token::Match (tok, " decltype|noexcept (" )) {
@@ -7114,7 +7117,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
71147117 } else
71157118 continue ;
71167119 } else if (tok->str () == " (" ) {
7117- if (isCPP () ) {
7120+ if (cpp ) {
71187121 for (Token * tok2 = tok; tok2 && tok2 != tok->link (); tok2 = tok2->next ()) {
71197122 if (Token::Match (tok2, " [(,] [" )) {
71207123 // lambda function at tok2->next()
@@ -7144,7 +7147,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
71447147 continue ;
71457148 if (isCPP11 && type0->str () == " using" )
71467149 continue ;
7147- if (type0-> isCpp () && Token::Match (type0, " namespace|delete" ))
7150+ if (cpp && Token::Match (type0, " namespace|delete" ))
71487151 continue ;
71497152
71507153 bool isconst = false ;
@@ -7264,7 +7267,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
72647267 varName = varName->next ();
72657268 else
72667269 --typelen;
7267- if (isCPP () && Token::Match (varName, " public:|private:|protected:|using" ))
7270+ if (cpp && Token::Match (varName, " public:|private:|protected:|using" ))
72687271 continue ;
72697272 // skip all the pointer part
72707273 bool isPointerOrRef = false ;
@@ -8345,6 +8348,8 @@ void Tokenizer::reportUnknownMacros() const
83458348 }
83468349 }
83478350
8351+ const bool cpp = isCPP ();
8352+
83488353 // Report unknown macros in non-executable scopes..
83498354 std::set<std::string> possible;
83508355 for (const Token *tok = tokens (); tok; tok = tok->next ()) {
@@ -8378,7 +8383,7 @@ void Tokenizer::reportUnknownMacros() const
83788383 else
83798384 unknownMacroError (tok);
83808385 }
8381- } else if (isCPP () && Token::Match (tok, " public|private|protected %name% :" )) {
8386+ } else if (cpp && Token::Match (tok, " public|private|protected %name% :" )) {
83828387 unknownMacroError (tok->next ());
83838388 }
83848389 }
@@ -8428,7 +8433,8 @@ void Tokenizer::reportUnknownMacros() const
84288433
84298434void Tokenizer::findGarbageCode () const
84308435{
8431- const bool isCPP11 = isCPP () && mSettings .standards .cpp >= Standards::CPP11;
8436+ const bool cpp = isCPP ();
8437+ const bool isCPP11 = cpp && mSettings .standards .cpp >= Standards::CPP11;
84328438
84338439 static const std::unordered_set<std::string> nonConsecutiveKeywords{ " break" ,
84348440 " continue" ,
@@ -8476,7 +8482,7 @@ void Tokenizer::findGarbageCode() const
84768482
84778483 // Assign/increment/decrement literal
84788484 else if (Token::Match (tok, " !!) %num%|%str%|%char% %assign%|++|--" )) {
8479- if (!isCPP () || mSettings .standards .cpp < Standards::CPP20 || !Token::Match (tok->previous (), " %name% : %num% =" ))
8485+ if (!cpp || mSettings .standards .cpp < Standards::CPP20 || !Token::Match (tok->previous (), " %name% : %num% =" ))
84808486 syntaxError (tok, tok->next ()->str () + " " + tok->strAt (2 ));
84818487 }
84828488 else if (Token::simpleMatch (tok, " ) return" ) && !Token::Match (tok->link ()->previous (), " if|while|for (" )) {
@@ -8504,7 +8510,7 @@ void Tokenizer::findGarbageCode() const
85048510 if (!Token::Match (tok->next (), " ( !!)" ))
85058511 syntaxError (tok);
85068512 if (tok->str () != " for" ) {
8507- if (isGarbageExpr (tok->next (), tok->linkAt (1 ), isCPP () && (mSettings .standards .cpp >=Standards::cppstd_t ::CPP17)))
8513+ if (isGarbageExpr (tok->next (), tok->linkAt (1 ), cpp && (mSettings .standards .cpp >=Standards::cppstd_t ::CPP17)))
85088514 syntaxError (tok);
85098515 }
85108516 }
@@ -8613,7 +8619,7 @@ void Tokenizer::findGarbageCode() const
86138619 // if we have an invalid number of semicolons inside for( ), assume syntax error
86148620 if (semicolons > 2 )
86158621 syntaxError (tok);
8616- if (semicolons == 1 && !(isCPP () && mSettings .standards .cpp >= Standards::CPP20))
8622+ if (semicolons == 1 && !(cpp && mSettings .standards .cpp >= Standards::CPP20))
86178623 syntaxError (tok);
86188624 if (semicolons == 0 && colons == 0 )
86198625 syntaxError (tok);
@@ -8623,7 +8629,7 @@ void Tokenizer::findGarbageCode() const
86238629 const Token *templateEndToken = nullptr ;
86248630 for (const Token *tok = tokens (); tok; tok = tok->next ()) {
86258631 if (!templateEndToken) {
8626- if (tok->str () == " <" && isCPP () )
8632+ if (tok->str () == " <" && cpp )
86278633 templateEndToken = tok->findClosingBracket ();
86288634 } else {
86298635 if (templateEndToken == tok)
@@ -8639,7 +8645,7 @@ void Tokenizer::findGarbageCode() const
86398645 {
86408646 bool match1 = Token::Match (tok, " %or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|++|--|::|sizeof" );
86418647 bool match2 = Token::Match (tok->next (), " {|if|else|while|do|for|return|switch|break" );
8642- if (isCPP () ) {
8648+ if (cpp ) {
86438649 match1 = match1 || Token::Match (tok, " throw|decltype|typeof" );
86448650 match2 = match2 || Token::Match (tok->next (), " try|catch|namespace" );
86458651 }
@@ -8664,21 +8670,21 @@ void Tokenizer::findGarbageCode() const
86648670 syntaxError (tok);
86658671 if (Token::Match (tok, " %assign% typename|class %assign%" ))
86668672 syntaxError (tok);
8667- if (Token::Match (tok, " %assign% [;)}]" ) && (!isCPP () || !Token::simpleMatch (tok->previous (), " operator" )))
8673+ if (Token::Match (tok, " %assign% [;)}]" ) && (!cpp || !Token::simpleMatch (tok->previous (), " operator" )))
86688674 syntaxError (tok);
86698675 if (Token::Match (tok, " %cop%|=|,|[ %or%|%oror%|/|%" ))
86708676 syntaxError (tok);
86718677 if (Token::Match (tok, " [;([{] %comp%|%oror%|%or%|%|/" ))
86728678 syntaxError (tok);
8673- if (Token::Match (tok, " %cop%|= ]" ) && !(isCPP () && Token::Match (tok->previous (), " %type%|[|,|%num% &|=|> ]" )))
8679+ if (Token::Match (tok, " %cop%|= ]" ) && !(cpp && Token::Match (tok->previous (), " %type%|[|,|%num% &|=|> ]" )))
86748680 syntaxError (tok);
8675- if (Token::Match (tok, " [+-] [;,)]}]" ) && !(isCPP () && Token::simpleMatch (tok->previous (), " operator" )))
8681+ if (Token::Match (tok, " [+-] [;,)]}]" ) && !(cpp && Token::simpleMatch (tok->previous (), " operator" )))
86768682 syntaxError (tok);
86778683 if (Token::simpleMatch (tok, " ," ) &&
86788684 !Token::Match (tok->tokAt (-2 ), " [ = , &|%name%" )) {
86798685 if (Token::Match (tok->previous (), " (|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof" ))
86808686 syntaxError (tok);
8681- if (isCPP () && Token::Match (tok->previous (), " throw|decltype|typeof" ))
8687+ if (cpp && Token::Match (tok->previous (), " throw|decltype|typeof" ))
86828688 syntaxError (tok);
86838689 if (Token::Match (tok->next (), " )|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&" ))
86848690 syntaxError (tok);
@@ -8709,9 +8715,9 @@ void Tokenizer::findGarbageCode() const
87098715 if (Token::Match (tok, " typedef [,;:]" ))
87108716 syntaxError (tok);
87118717 if (Token::Match (tok, " !|~ %comp%" ) &&
8712- !(isCPP () && tok->strAt (1 ) == " >" && Token::simpleMatch (tok->tokAt (-1 ), " operator" )))
8718+ !(cpp && tok->strAt (1 ) == " >" && Token::simpleMatch (tok->tokAt (-1 ), " operator" )))
87138719 syntaxError (tok);
8714- if (Token::Match (tok, " ] %name%" ) && (!isCPP () || !(tok->tokAt (-1 ) && Token::simpleMatch (tok->tokAt (-2 ), " delete [" )))) {
8720+ if (Token::Match (tok, " ] %name%" ) && (!cpp || !(tok->tokAt (-1 ) && Token::simpleMatch (tok->tokAt (-2 ), " delete [" )))) {
87158721 if (tok->next ()->isUpperCaseName ())
87168722 unknownMacroError (tok->next ());
87178723 else
@@ -8723,7 +8729,7 @@ void Tokenizer::findGarbageCode() const
87238729 for (const Token* inner = tok->next (); inner != end; inner = inner->next ()) {
87248730 if (inner->str () == " {" )
87258731 inner = inner->link ();
8726- else if (inner->str () == " ;" || (Token::simpleMatch (inner, " , ," ) && (!isCPP () || !Token::simpleMatch (inner->previous (), " operator" )))) {
8732+ else if (inner->str () == " ;" || (Token::simpleMatch (inner, " , ," ) && (!cpp || !Token::simpleMatch (inner->previous (), " operator" )))) {
87278733 if (tok->tokAt (-1 ) && tok->tokAt (-1 )->isUpperCaseName ())
87288734 unknownMacroError (tok->tokAt (-1 ));
87298735 else
@@ -8732,7 +8738,7 @@ void Tokenizer::findGarbageCode() const
87328738 }
87338739 }
87348740
8735- if ((!isCPP () || !Token::simpleMatch (tok->previous (), " operator" )) && Token::Match (tok, " [,;] ," ))
8741+ if ((!cpp || !Token::simpleMatch (tok->previous (), " operator" )) && Token::Match (tok, " [,;] ," ))
87368742 syntaxError (tok);
87378743 if (tok->str () == " typedef" ) {
87388744 for (const Token* tok2 = tok->next (); tok2 && tok2->str () != " ;" ; tok2 = tok2->next ()) {
@@ -8748,7 +8754,7 @@ void Tokenizer::findGarbageCode() const
87488754 syntaxError (tok);
87498755 }
87508756 }
8751- if (isCPP () && tok->str () == " namespace" && tok->tokAt (-1 )) {
8757+ if (cpp && tok->str () == " namespace" && tok->tokAt (-1 )) {
87528758 if (!Token::Match (tok->tokAt (-1 ), " ;|{|}|using|inline" )) {
87538759 if (tok->tokAt (-1 )->isUpperCaseName ())
87548760 unknownMacroError (tok->tokAt (-1 ));
@@ -8781,7 +8787,7 @@ void Tokenizer::findGarbageCode() const
87818787 syntaxError (list.back ()->previous ());
87828788
87838789 // Garbage templates..
8784- if (isCPP () ) {
8790+ if (cpp ) {
87858791 for (const Token *tok = tokens (); tok; tok = tok->next ()) {
87868792 if (Token::simpleMatch (tok, " < >" ) && !(Token::Match (tok->tokAt (-1 ), " %name%" ) || (tok->tokAt (-1 ) && Token::Match (tok->tokAt (-2 ), " operator %op%" ))))
87878793 syntaxError (tok);
0 commit comments