@@ -1147,6 +1147,7 @@ void Tokenizer::simplifyTypedef()
1147
1147
1148
1148
void Tokenizer::simplifyTypedefCpp ()
1149
1149
{
1150
+ const bool cpp = isCPP ();
1150
1151
bool isNamespace = false ;
1151
1152
std::string className, fullClassName;
1152
1153
bool hasClass = false ;
@@ -1714,7 +1715,7 @@ void Tokenizer::simplifyTypedefCpp()
1714
1715
}
1715
1716
1716
1717
// check for member functions
1717
- else if (tok2-> isCpp () && tok2->str () == " (" && isFunctionHead (tok2, " {:" )) {
1718
+ else if (cpp && tok2->str () == " (" && isFunctionHead (tok2, " {:" )) {
1718
1719
const Token *func = tok2->previous ();
1719
1720
1720
1721
/* * @todo add support for multi-token operators */
@@ -1741,7 +1742,7 @@ void Tokenizer::simplifyTypedefCpp()
1741
1742
// check for entering a new scope
1742
1743
else if (tok2->str () == " {" ) {
1743
1744
// check for entering a new namespace
1744
- if (tok2-> isCpp () ) {
1745
+ if (cpp ) {
1745
1746
if (tok2->strAt (-2 ) == " namespace" ) {
1746
1747
if (classLevel < spaceInfo.size () &&
1747
1748
spaceInfo[classLevel].isNamespace &&
@@ -1770,7 +1771,7 @@ void Tokenizer::simplifyTypedefCpp()
1770
1771
1771
1772
// check for operator typedef
1772
1773
/* * @todo add support for multi-token operators */
1773
- else if (tok2-> isCpp () &&
1774
+ else if (cpp &&
1774
1775
tok2->str () == " operator" &&
1775
1776
tok2->next () &&
1776
1777
tok2->next ()->str () == typeName->str () &&
@@ -4526,6 +4527,7 @@ static const std::unordered_set<std::string> notstart_cpp = { NOTSTART_C,
4526
4527
4527
4528
void Tokenizer::setVarIdPass1 ()
4528
4529
{
4530
+ const bool cpp = isCPP ();
4529
4531
// Variable declarations can't start with "return" etc.
4530
4532
const std::unordered_set<std::string>& notstart = (isC ()) ? notstart_c : notstart_cpp;
4531
4533
@@ -4542,7 +4544,7 @@ void Tokenizer::setVarIdPass1()
4542
4544
for (Token *tok = list.front (); tok; tok = tok->next ()) {
4543
4545
if (tok->isOp ())
4544
4546
continue ;
4545
- if (tok-> isCpp () && Token::simpleMatch (tok, " template <" )) {
4547
+ if (cpp && Token::simpleMatch (tok, " template <" )) {
4546
4548
Token* closingBracket = tok->next ()->findClosingBracket ();
4547
4549
if (closingBracket)
4548
4550
tok = closingBracket;
@@ -4697,7 +4699,7 @@ void Tokenizer::setVarIdPass1()
4697
4699
continue ;
4698
4700
4699
4701
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 &|&&| [" )) {
4701
4703
// Structured bindings
4702
4704
tok2 = Token::findsimplematch (tok, " [" );
4703
4705
if ((Token::simpleMatch (tok->previous (), " for (" ) && Token::simpleMatch (tok2->link (), " ] :" )) ||
@@ -4721,7 +4723,7 @@ void Tokenizer::setVarIdPass1()
4721
4723
inlineFunction = true ;
4722
4724
4723
4725
if (decl) {
4724
- if (isCPP () ) {
4726
+ if (cpp ) {
4725
4727
if (Token *declTypeTok = Token::findsimplematch (tok, " decltype (" , tok2)) {
4726
4728
for (Token *declTok = declTypeTok->linkAt (1 ); declTok != declTypeTok; declTok = declTok->previous ()) {
4727
4729
if (declTok->isName () && !Token::Match (declTok->previous (), " ::|." ) && variableMap.hasVariable (declTok->str ()))
@@ -4737,7 +4739,7 @@ void Tokenizer::setVarIdPass1()
4737
4739
;
4738
4740
else if (Token::Match (prev2, " %type% ( !!)" ) && Token::simpleMatch (tok2->link (), " ) ;" )) {
4739
4741
// In C++ , a variable can't be called operator+ or something like that.
4740
- if (prev2-> isCpp () &&
4742
+ if (cpp &&
4741
4743
prev2->isOperatorKeyword ())
4742
4744
continue ;
4743
4745
@@ -4774,7 +4776,7 @@ void Tokenizer::setVarIdPass1()
4774
4776
}
4775
4777
} else
4776
4778
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
4778
4780
if (tok2->link () != tok2->next () && // add value-initialized variable T x{};
4779
4781
(Token::Match (prev2, " do|try|else" ) || Token::Match (prev2->tokAt (-2 ), " struct|class|:" )))
4780
4782
continue ;
@@ -4819,7 +4821,7 @@ void Tokenizer::setVarIdPass1()
4819
4821
4820
4822
if (tok->isName () && !tok->isKeyword () && !tok->isStandardType ()) {
4821
4823
// 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" ))
4823
4825
continue ;
4824
4826
4825
4827
bool globalNamespace = false ;
@@ -7056,7 +7058,8 @@ void Tokenizer::simplifyVarDecl(const bool only_k_r_fpar)
7056
7058
7057
7059
void Tokenizer::simplifyVarDecl (Token * tokBegin, const Token * const tokEnd, const bool only_k_r_fpar)
7058
7060
{
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);
7060
7063
7061
7064
// Split up variable declarations..
7062
7065
// "int a=4;" => "int a; a=4;"
@@ -7065,7 +7068,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
7065
7068
for (Token *tok = tokBegin; tok != tokEnd; tok = tok->next ()) {
7066
7069
if (Token::Match (tok, " {|;" ))
7067
7070
scopeDecl = false ;
7068
- if (isCPP () ) {
7071
+ if (cpp ) {
7069
7072
if (Token::Match (tok, " class|struct|namespace|union" ))
7070
7073
scopeDecl = true ;
7071
7074
if (Token::Match (tok, " decltype|noexcept (" )) {
@@ -7114,7 +7117,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
7114
7117
} else
7115
7118
continue ;
7116
7119
} else if (tok->str () == " (" ) {
7117
- if (isCPP () ) {
7120
+ if (cpp ) {
7118
7121
for (Token * tok2 = tok; tok2 && tok2 != tok->link (); tok2 = tok2->next ()) {
7119
7122
if (Token::Match (tok2, " [(,] [" )) {
7120
7123
// lambda function at tok2->next()
@@ -7144,7 +7147,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
7144
7147
continue ;
7145
7148
if (isCPP11 && type0->str () == " using" )
7146
7149
continue ;
7147
- if (type0-> isCpp () && Token::Match (type0, " namespace|delete" ))
7150
+ if (cpp && Token::Match (type0, " namespace|delete" ))
7148
7151
continue ;
7149
7152
7150
7153
bool isconst = false ;
@@ -7264,7 +7267,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
7264
7267
varName = varName->next ();
7265
7268
else
7266
7269
--typelen;
7267
- if (isCPP () && Token::Match (varName, " public:|private:|protected:|using" ))
7270
+ if (cpp && Token::Match (varName, " public:|private:|protected:|using" ))
7268
7271
continue ;
7269
7272
// skip all the pointer part
7270
7273
bool isPointerOrRef = false ;
@@ -8345,6 +8348,8 @@ void Tokenizer::reportUnknownMacros() const
8345
8348
}
8346
8349
}
8347
8350
8351
+ const bool cpp = isCPP ();
8352
+
8348
8353
// Report unknown macros in non-executable scopes..
8349
8354
std::set<std::string> possible;
8350
8355
for (const Token *tok = tokens (); tok; tok = tok->next ()) {
@@ -8378,7 +8383,7 @@ void Tokenizer::reportUnknownMacros() const
8378
8383
else
8379
8384
unknownMacroError (tok);
8380
8385
}
8381
- } else if (isCPP () && Token::Match (tok, " public|private|protected %name% :" )) {
8386
+ } else if (cpp && Token::Match (tok, " public|private|protected %name% :" )) {
8382
8387
unknownMacroError (tok->next ());
8383
8388
}
8384
8389
}
@@ -8428,7 +8433,8 @@ void Tokenizer::reportUnknownMacros() const
8428
8433
8429
8434
void Tokenizer::findGarbageCode () const
8430
8435
{
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;
8432
8438
8433
8439
static const std::unordered_set<std::string> nonConsecutiveKeywords{ " break" ,
8434
8440
" continue" ,
@@ -8476,7 +8482,7 @@ void Tokenizer::findGarbageCode() const
8476
8482
8477
8483
// Assign/increment/decrement literal
8478
8484
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% =" ))
8480
8486
syntaxError (tok, tok->next ()->str () + " " + tok->strAt (2 ));
8481
8487
}
8482
8488
else if (Token::simpleMatch (tok, " ) return" ) && !Token::Match (tok->link ()->previous (), " if|while|for (" )) {
@@ -8504,7 +8510,7 @@ void Tokenizer::findGarbageCode() const
8504
8510
if (!Token::Match (tok->next (), " ( !!)" ))
8505
8511
syntaxError (tok);
8506
8512
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)))
8508
8514
syntaxError (tok);
8509
8515
}
8510
8516
}
@@ -8613,7 +8619,7 @@ void Tokenizer::findGarbageCode() const
8613
8619
// if we have an invalid number of semicolons inside for( ), assume syntax error
8614
8620
if (semicolons > 2 )
8615
8621
syntaxError (tok);
8616
- if (semicolons == 1 && !(isCPP () && mSettings .standards .cpp >= Standards::CPP20))
8622
+ if (semicolons == 1 && !(cpp && mSettings .standards .cpp >= Standards::CPP20))
8617
8623
syntaxError (tok);
8618
8624
if (semicolons == 0 && colons == 0 )
8619
8625
syntaxError (tok);
@@ -8623,7 +8629,7 @@ void Tokenizer::findGarbageCode() const
8623
8629
const Token *templateEndToken = nullptr ;
8624
8630
for (const Token *tok = tokens (); tok; tok = tok->next ()) {
8625
8631
if (!templateEndToken) {
8626
- if (tok->str () == " <" && isCPP () )
8632
+ if (tok->str () == " <" && cpp )
8627
8633
templateEndToken = tok->findClosingBracket ();
8628
8634
} else {
8629
8635
if (templateEndToken == tok)
@@ -8639,7 +8645,7 @@ void Tokenizer::findGarbageCode() const
8639
8645
{
8640
8646
bool match1 = Token::Match (tok, " %or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|++|--|::|sizeof" );
8641
8647
bool match2 = Token::Match (tok->next (), " {|if|else|while|do|for|return|switch|break" );
8642
- if (isCPP () ) {
8648
+ if (cpp ) {
8643
8649
match1 = match1 || Token::Match (tok, " throw|decltype|typeof" );
8644
8650
match2 = match2 || Token::Match (tok->next (), " try|catch|namespace" );
8645
8651
}
@@ -8664,21 +8670,21 @@ void Tokenizer::findGarbageCode() const
8664
8670
syntaxError (tok);
8665
8671
if (Token::Match (tok, " %assign% typename|class %assign%" ))
8666
8672
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" )))
8668
8674
syntaxError (tok);
8669
8675
if (Token::Match (tok, " %cop%|=|,|[ %or%|%oror%|/|%" ))
8670
8676
syntaxError (tok);
8671
8677
if (Token::Match (tok, " [;([{] %comp%|%oror%|%or%|%|/" ))
8672
8678
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% &|=|> ]" )))
8674
8680
syntaxError (tok);
8675
- if (Token::Match (tok, " [+-] [;,)]}]" ) && !(isCPP () && Token::simpleMatch (tok->previous (), " operator" )))
8681
+ if (Token::Match (tok, " [+-] [;,)]}]" ) && !(cpp && Token::simpleMatch (tok->previous (), " operator" )))
8676
8682
syntaxError (tok);
8677
8683
if (Token::simpleMatch (tok, " ," ) &&
8678
8684
!Token::Match (tok->tokAt (-2 ), " [ = , &|%name%" )) {
8679
8685
if (Token::Match (tok->previous (), " (|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof" ))
8680
8686
syntaxError (tok);
8681
- if (isCPP () && Token::Match (tok->previous (), " throw|decltype|typeof" ))
8687
+ if (cpp && Token::Match (tok->previous (), " throw|decltype|typeof" ))
8682
8688
syntaxError (tok);
8683
8689
if (Token::Match (tok->next (), " )|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&" ))
8684
8690
syntaxError (tok);
@@ -8709,9 +8715,9 @@ void Tokenizer::findGarbageCode() const
8709
8715
if (Token::Match (tok, " typedef [,;:]" ))
8710
8716
syntaxError (tok);
8711
8717
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" )))
8713
8719
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 [" )))) {
8715
8721
if (tok->next ()->isUpperCaseName ())
8716
8722
unknownMacroError (tok->next ());
8717
8723
else
@@ -8723,7 +8729,7 @@ void Tokenizer::findGarbageCode() const
8723
8729
for (const Token* inner = tok->next (); inner != end; inner = inner->next ()) {
8724
8730
if (inner->str () == " {" )
8725
8731
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" )))) {
8727
8733
if (tok->tokAt (-1 ) && tok->tokAt (-1 )->isUpperCaseName ())
8728
8734
unknownMacroError (tok->tokAt (-1 ));
8729
8735
else
@@ -8732,7 +8738,7 @@ void Tokenizer::findGarbageCode() const
8732
8738
}
8733
8739
}
8734
8740
8735
- if ((!isCPP () || !Token::simpleMatch (tok->previous (), " operator" )) && Token::Match (tok, " [,;] ," ))
8741
+ if ((!cpp || !Token::simpleMatch (tok->previous (), " operator" )) && Token::Match (tok, " [,;] ," ))
8736
8742
syntaxError (tok);
8737
8743
if (tok->str () == " typedef" ) {
8738
8744
for (const Token* tok2 = tok->next (); tok2 && tok2->str () != " ;" ; tok2 = tok2->next ()) {
@@ -8748,7 +8754,7 @@ void Tokenizer::findGarbageCode() const
8748
8754
syntaxError (tok);
8749
8755
}
8750
8756
}
8751
- if (isCPP () && tok->str () == " namespace" && tok->tokAt (-1 )) {
8757
+ if (cpp && tok->str () == " namespace" && tok->tokAt (-1 )) {
8752
8758
if (!Token::Match (tok->tokAt (-1 ), " ;|{|}|using|inline" )) {
8753
8759
if (tok->tokAt (-1 )->isUpperCaseName ())
8754
8760
unknownMacroError (tok->tokAt (-1 ));
@@ -8781,7 +8787,7 @@ void Tokenizer::findGarbageCode() const
8781
8787
syntaxError (list.back ()->previous ());
8782
8788
8783
8789
// Garbage templates..
8784
- if (isCPP () ) {
8790
+ if (cpp ) {
8785
8791
for (const Token *tok = tokens (); tok; tok = tok->next ()) {
8786
8792
if (Token::simpleMatch (tok, " < >" ) && !(Token::Match (tok->tokAt (-1 ), " %name%" ) || (tok->tokAt (-1 ) && Token::Match (tok->tokAt (-2 ), " operator %op%" ))))
8787
8793
syntaxError (tok);
0 commit comments