Skip to content

Commit c7d6290

Browse files
committed
SymbolDatabase: removed mIsCpp and isCPP() [skip ci]
1 parent e183e34 commit c7d6290

2 files changed

Lines changed: 38 additions & 48 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
//---------------------------------------------------------------------------
5454

5555
SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger* errorLogger)
56-
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger), mIsCpp(mTokenizer.isCPP())
56+
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger)
5757
{
5858
if (!mTokenizer.tokens())
5959
return;
@@ -160,7 +160,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
160160
"SymbolDatabase",
161161
tok->progressValue());
162162
// Locate next class
163-
if ((mIsCpp && tok->isKeyword() &&
163+
if ((tok->isCpp() && tok->isKeyword() &&
164164
((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
165165
!Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) ||
166166
(Token::Match(tok, "enum class| %name% {") ||
@@ -170,7 +170,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
170170

171171
if (tok->strAt(1) == "::")
172172
tok2 = tok2->next();
173-
else if (mIsCpp && tok->strAt(1) == "class")
173+
else if (tok->isCpp() && tok->strAt(1) == "class")
174174
tok2 = tok2->next();
175175

176176
while (Token::Match(tok2, ":: %name%"))
@@ -186,7 +186,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
186186
}
187187

188188
// skip over final
189-
if (mIsCpp && Token::simpleMatch(tok2, "final"))
189+
if (tok2 && tok2->isCpp() && Token::simpleMatch(tok2, "final"))
190190
tok2 = tok2->next();
191191

192192
// make sure we have valid code
@@ -254,7 +254,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
254254
}
255255

256256
// definition may be different than declaration
257-
if (mIsCpp && tok->str() == "class") {
257+
if (tok->isCpp() && tok->str() == "class") {
258258
access[new_scope] = AccessControl::Private;
259259
new_scope->type = Scope::eClass;
260260
} else if (tok->str() == "struct") {
@@ -313,7 +313,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
313313
}
314314

315315
if (new_scope->type == Scope::eEnum) {
316-
tok2 = new_scope->addEnum(tok, mIsCpp);
316+
tok2 = new_scope->addEnum(tok);
317317
scope->nestedList.push_back(new_scope);
318318

319319
if (!tok2)
@@ -329,7 +329,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
329329
}
330330

331331
// Namespace and unknown macro (#3854)
332-
else if (mIsCpp && tok->isKeyword() &&
332+
else if (tok->isCpp() && tok->isKeyword() &&
333333
Token::Match(tok, "namespace %name% %type% (") &&
334334
tok->tokAt(2)->isUpperCaseName() &&
335335
Token::simpleMatch(tok->linkAt(3), ") {")) {
@@ -368,7 +368,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
368368
}
369369

370370
// using namespace
371-
else if (mIsCpp && tok->isKeyword() && Token::Match(tok, "using namespace ::| %type% ;|::")) {
371+
else if (tok->isCpp() && tok->isKeyword() && Token::Match(tok, "using namespace ::| %type% ;|::")) {
372372
Scope::UsingInfo using_info;
373373

374374
using_info.start = tok; // save location
@@ -388,7 +388,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
388388
}
389389

390390
// using type alias
391-
else if (mIsCpp && tok->isKeyword() && Token::Match(tok, "using %name% =")) {
391+
else if (tok->isCpp() && tok->isKeyword() && Token::Match(tok, "using %name% =")) {
392392
if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) {
393393
// fill typeList..
394394
typeList.emplace_back(tok, nullptr, scope);
@@ -601,7 +601,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
601601
}
602602

603603
// friend class declaration?
604-
else if (mIsCpp && tok->isKeyword() && Token::Match(tok, "friend class|struct| ::| %any% ;|::")) {
604+
else if (tok->isCpp() && tok->isKeyword() && Token::Match(tok, "friend class|struct| ::| %any% ;|::")) {
605605
Type::FriendInfo friendInfo;
606606

607607
// save the name start
@@ -1139,7 +1139,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
11391139
inTemplateArg = tok->link();
11401140
if (inTemplateArg == tok)
11411141
inTemplateArg = nullptr;
1142-
if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{(,)>;]")) && !isReservedName(tok->str())) {
1142+
if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{(,)>;]")) && !isReservedName(tok)) {
11431143
if (tok->next()->str() == ">" && !tok->next()->link())
11441144
continue;
11451145

@@ -1548,7 +1548,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
15481548
}
15491549
if (mSettings.library.functions.find(fstr) != mSettings.library.functions.end())
15501550
continue;
1551-
if (mIsCpp) {
1551+
if (tok->isCpp()) {
15521552
const Token* parent = tok->astParent();
15531553
while (Token::Match(parent, "::|[|{"))
15541554
parent = parent->astParent();
@@ -1976,7 +1976,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
19761976
return false;
19771977

19781978
// regular function?
1979-
else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) && tok->previous() &&
1979+
else if (Token::Match(tok, "%name% (") && !isReservedName(tok) && tok->previous() &&
19801980
(Token::Match(tok->previous(), "%name%|>|&|&&|*|::|~") || // Either a return type or scope qualifier in front of tok
19811981
outerScope->isClassOrStructOrUnion())) { // or a ctor/dtor
19821982
const Token* tok1 = tok->previous();
@@ -2018,7 +2018,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
20182018
// done if constructor or destructor
20192019
if (!Token::Match(tok1, "{|}|;|public:|protected:|private:") && tok1) {
20202020
// skip over pointers and references
2021-
while (Token::Match(tok1, "%type%|*|&|&&") && !endsWith(tok1->str(), ':') && (!isReservedName(tok1->str()) || tok1->str() == "const"))
2021+
while (Token::Match(tok1, "%type%|*|&|&&") && !endsWith(tok1->str(), ':') && (!isReservedName(tok1) || tok1->str() == "const"))
20222022
tok1 = tok1->previous();
20232023

20242024
// skip over decltype
@@ -2061,7 +2061,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
20612061
// skip over modifiers and other stuff
20622062
while (Token::Match(tok1, "const|static|extern|template|virtual|struct|class|enum|%name%")) {
20632063
// friend type func(); is not a function
2064-
if (mIsCpp && tok1->str() == "friend" && tok2->str() == ";")
2064+
if (tok1->isCpp() && tok1->str() == "friend" && tok2->str() == ";")
20652065
return false;
20662066
tok1 = tok1->previous();
20672067
}
@@ -2111,7 +2111,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
21112111
}
21122112

21132113
// regular C function with missing return or invalid C++ ?
2114-
else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) &&
2114+
else if (Token::Match(tok, "%name% (") && !isReservedName(tok) &&
21152115
Token::simpleMatch(tok->linkAt(1), ") {") &&
21162116
(!tok->previous() || Token::Match(tok->previous(), ";|}"))) {
21172117
if (mTokenizer.isC()) {
@@ -2841,8 +2841,7 @@ static bool typesMatch(
28412841

28422842
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, nonneg int path_length) const
28432843
{
2844-
const bool isCPP = scope->check->isCPP();
2845-
if (!isCPP) // C does not support overloads
2844+
if (!first->isCpp()) // C does not support overloads
28462845
return true;
28472846

28482847
int arg_path_length = path_length;
@@ -4757,7 +4756,7 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *
47574756
const Token *nameTok = classDef;
47584757
if (!classDef) {
47594758
type = Scope::eGlobal;
4760-
} else if (classDef->str() == "class" && check && check->isCPP()) {
4759+
} else if (classDef->str() == "class" && classDef->isCpp()) {
47614760
type = Scope::eClass;
47624761
nameTok = nameTok->next();
47634762
} else if (classDef->str() == "struct") {
@@ -5136,12 +5135,12 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok,
51365135
return nullptr != vartok;
51375136
}
51385137

5139-
const Token * Scope::addEnum(const Token * tok, bool isCpp)
5138+
const Token * Scope::addEnum(const Token * tok)
51405139
{
51415140
const Token * tok2 = tok->next();
51425141

51435142
// skip over class if present
5144-
if (isCpp && tok2->str() == "class")
5143+
if (tok2->isCpp() && tok2->str() == "class")
51455144
tok2 = tok2->next();
51465145

51475146
// skip over name
@@ -5202,7 +5201,7 @@ const Token * Scope::addEnum(const Token * tok, bool isCpp)
52025201
if (tok2 == end) {
52035202
tok2 = tok2->next();
52045203

5205-
if (tok2 && tok2->str() != ";" && (isCpp || tok2->str() != ")"))
5204+
if (tok2 && tok2->str() != ";" && (tok2->isCpp() || tok2->str() != ")"))
52065205
tok2 = nullptr;
52075206
} else
52085207
tok2 = nullptr;
@@ -5828,7 +5827,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
58285827
fallback2++;
58295828

58305829
// Try to evaluate the apparently more complex expression
5831-
else if (check->isCPP()) {
5830+
else if (arguments[j]->isCpp()) {
58325831
const Token *vartok = arguments[j];
58335832
if (vartok->str() == ".") {
58345833
const Token* rml = nextAfterAstRightmostLeaf(vartok);
@@ -6204,13 +6203,6 @@ const Function *Scope::getDestructor() const
62046203

62056204
//---------------------------------------------------------------------------
62066205

6207-
bool SymbolDatabase::isCPP() const
6208-
{
6209-
return mIsCpp;
6210-
}
6211-
6212-
//---------------------------------------------------------------------------
6213-
62146206
const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const
62156207
{
62166208
const Scope *scope = nullptr;
@@ -6459,9 +6451,10 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
64596451

64606452
//---------------------------------------------------------------------------
64616453

6462-
bool SymbolDatabase::isReservedName(const std::string& iName) const
6454+
bool SymbolDatabase::isReservedName(const Token* tok) const
64636455
{
6464-
if (mIsCpp) {
6456+
const std::string& iName = tok->str();
6457+
if (tok->isCpp()) {
64656458
static const auto& cpp_keywords = Keywords::getAll(Standards::cppstd_t::CPPLatest);
64666459
return cpp_keywords.find(iName) != cpp_keywords.cend();
64676460
}
@@ -6587,7 +6580,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
65876580
const ValueType *vt2 = parent->astOperand2() ? parent->astOperand2()->valueType() : nullptr;
65886581

65896582
if (vt1 && Token::Match(parent, "<<|>>")) {
6590-
if (!mIsCpp || (vt2 && vt2->isIntegral())) {
6583+
if (!parent->isCpp() || (vt2 && vt2->isIntegral())) {
65916584
if (vt1->type < ValueType::Type::BOOL || vt1->type >= ValueType::Type::INT) {
65926585
ValueType vt(*vt1);
65936586
vt.reference = Reference::None;
@@ -6632,7 +6625,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
66326625
auto vt = *vt1;
66336626
vt.reference = Reference::None;
66346627
setValueType(parent, vt);
6635-
} else if (mIsCpp && ((Token::Match(parent->tokAt(-3), "%var% ; %var% =") && parent->strAt(-3) == parent->strAt(-1)) ||
6628+
} else if (parent->isCpp() && ((Token::Match(parent->tokAt(-3), "%var% ; %var% =") && parent->strAt(-3) == parent->strAt(-1)) ||
66366629
Token::Match(parent->tokAt(-1), "%var% ="))) {
66376630
Token *var1Tok = parent->strAt(-2) == ";" ? parent->tokAt(-3) : parent->tokAt(-1);
66386631
Token *autoTok = nullptr;
@@ -6690,7 +6683,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
66906683
return;
66916684
}
66926685

6693-
if (parent->str() == "[" && (!mIsCpp || parent->astOperand1() == tok) && valuetype.pointer > 0U && !Token::Match(parent->previous(), "[{,]")) {
6686+
if (parent->str() == "[" && (!parent->isCpp() || parent->astOperand1() == tok) && valuetype.pointer > 0U && !Token::Match(parent->previous(), "[{,]")) {
66946687
const Token *op1 = parent->astOperand1();
66956688
while (op1 && op1->str() == "[")
66966689
op1 = op1->astOperand1();
@@ -6926,13 +6919,13 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
69266919
}
69276920
}
69286921

6929-
if (mIsCpp && vt2 && Token::simpleMatch(parent->previous(), "decltype (")) {
6922+
if (parent->isCpp() && vt2 && Token::simpleMatch(parent->previous(), "decltype (")) {
69306923
setValueType(parent, *vt2);
69316924
return;
69326925
}
69336926

69346927
// c++17 auto type deduction of braced init list
6935-
if (mIsCpp && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) {
6928+
if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) {
69366929
Token *autoTok = parent->tokAt(-2);
69376930
setValueType(autoTok, *vt2);
69386931
setAutoTokenProperties(autoTok);
@@ -7421,7 +7414,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
74217414
setValueType(tok, ValueType(sign, type, 0U));
74227415
}
74237416
} else if (tok->isComparisonOp() || tok->tokType() == Token::eLogicalOp) {
7424-
if (mIsCpp && tok->isComparisonOp() && (getClassScope(tok->astOperand1()) || getClassScope(tok->astOperand2()))) {
7417+
if (tok->isCpp() && tok->isComparisonOp() && (getClassScope(tok->astOperand1()) || getClassScope(tok->astOperand2()))) {
74257418
const Function *function = getOperatorFunction(tok);
74267419
if (function) {
74277420
ValueType vt;
@@ -7439,7 +7432,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
74397432
nonneg int const volatileness = 0U;
74407433
ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness, volatileness);
74417434

7442-
if (mIsCpp && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) {
7435+
if (tok->isCpp() && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) {
74437436
valuetype.originalTypeName = "char8_t";
74447437
valuetype.fromLibraryType(valuetype.originalTypeName, mSettings);
74457438
} else if (tok->isUtf16()) {
@@ -7451,7 +7444,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
74517444
} else if (tok->isLong()) {
74527445
valuetype.originalTypeName = "wchar_t";
74537446
valuetype.type = ValueType::Type::WCHAR_T;
7454-
} else if ((tok->tokType() == Token::eChar) && ((tok->isCChar() && !mIsCpp) || (tok->isCMultiChar()))) {
7447+
} else if ((tok->tokType() == Token::eChar) && ((!tok->isCpp() && tok->isCChar()) || (tok->isCMultiChar()))) {
74557448
valuetype.type = ValueType::Type::INT;
74567449
valuetype.sign = ValueType::Sign::SIGNED;
74577450
}
@@ -7473,7 +7466,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
74737466
}
74747467

74757468
// Construct smart pointer
7476-
else if (mIsCpp && mSettings.library.isSmartPointer(start)) {
7469+
else if (start && start->isCpp() && mSettings.library.isSmartPointer(start)) {
74777470
ValueType valuetype;
74787471
if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings)) {
74797472
setValueType(tok, valuetype);
@@ -7548,7 +7541,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
75487541
}
75497542
}
75507543
}
7551-
if (mIsCpp && tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) {
7544+
if (tok->isCpp() && tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) {
75527545
const Token *typeStartToken = tok->astOperand1();
75537546
while (typeStartToken && typeStartToken->str() == "::")
75547547
typeStartToken = typeStartToken->astOperand1();

lib/symboldatabase.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ class CPPCHECKLIB Scope {
11761176
*/
11771177
const Variable *getVariable(const std::string &varname) const;
11781178

1179-
const Token * addEnum(const Token * tok, bool isCpp);
1179+
const Token * addEnum(const Token * tok);
11801180

11811181
const Scope *findRecordInBase(const std::string &name) const;
11821182

@@ -1387,8 +1387,6 @@ class CPPCHECKLIB SymbolDatabase {
13871387
void printVariable(const Variable *var, const char *indent) const;
13881388
void printXml(std::ostream &out) const;
13891389

1390-
bool isCPP() const;
1391-
13921390
/*
13931391
* @brief Do a sanity check
13941392
*/
@@ -1458,8 +1456,8 @@ class CPPCHECKLIB SymbolDatabase {
14581456

14591457
void fixVarId(VarIdMap & varIds, const Token * vartok, Token * membertok, const Variable * membervar);
14601458

1461-
/** Whether iName is a keyword as defined in http://en.cppreference.com/w/c/keyword and http://en.cppreference.com/w/cpp/keyword*/
1462-
bool isReservedName(const std::string& iName) const;
1459+
/** Whether the token is a keyword as defined in http://en.cppreference.com/w/c/keyword and http://en.cppreference.com/w/cpp/keyword*/
1460+
bool isReservedName(const Token* tok) const;
14631461

14641462
const Enumerator * findEnumerator(const Token * tok, std::set<std::string>& tokensThatAreNotEnumeratorValues) const;
14651463

@@ -1477,7 +1475,6 @@ class CPPCHECKLIB SymbolDatabase {
14771475
/** list for missing types */
14781476
std::list<Type> mBlankTypes;
14791477

1480-
bool mIsCpp;
14811478
ValueType::Sign mDefaultSignedness;
14821479
};
14831480

0 commit comments

Comments
 (0)