diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 6132276e9..87ea72ea1 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -717,7 +717,7 @@ std::vector getParentValueTypes(const Token* tok, const Settings* set const ValueType* vtCont = contTok->valueType(); if (!vtCont->containerTypeToken) return {}; - ValueType vtParent = ValueType::parseDecl(vtCont->containerTypeToken, settings, true); // TODO: set isCpp + ValueType vtParent = ValueType::parseDecl(vtCont->containerTypeToken, *settings, true); // TODO: set isCpp return {std::move(vtParent)}; } if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) { diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 80d9e110d..e90207eef 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2980,7 +2980,7 @@ void CheckClass::checkThisUseAfterFree() for (const Variable &var : classScope->varlist) { // Find possible "self pointer".. pointer/smartpointer member variable of "self" type. if (var.valueType() && var.valueType()->smartPointerType != classScope->definedType && var.valueType()->typeScope != classScope) { - const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), mSettings, true); // this is only called for C++ + const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), *mSettings, true); // this is only called for C++ if (valueType.smartPointerType != classScope->definedType) continue; } diff --git a/lib/checktype.cpp b/lib/checktype.cpp index d29251726..e5ae9d88b 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -407,7 +407,7 @@ void CheckType::checkFloatToIntegerOverflow() while (scope && scope->type != Scope::ScopeType::eLambda && scope->type != Scope::ScopeType::eFunction) scope = scope->nestedIn; if (scope && scope->type == Scope::ScopeType::eFunction && scope->function && scope->function->retDef) { - const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, mSettings, mTokenizer->isCPP()); + const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, *mSettings, mTokenizer->isCPP()); vtfloat = tok->astOperand1()->valueType(); checkFloatToIntegerOverflow(tok, &valueType, vtfloat, tok->astOperand1()->values()); } diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 9f5499c9d..4855fd50a 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -630,7 +630,7 @@ void clangimport::AstNode::setValueType(Token *tok) if (!decl.front()) break; - const ValueType valueType = ValueType::parseDecl(decl.front(), mData->mSettings, true); // TODO: set isCpp + const ValueType valueType = ValueType::parseDecl(decl.front(), *mData->mSettings, true); // TODO: set isCpp if (valueType.type != ValueType::Type::UNKNOWN_TYPE) { tok->setValueType(new ValueType(valueType)); break; @@ -1543,7 +1543,7 @@ static void setValues(Tokenizer *tokenizer, SymbolDatabase *symbolDatabase) for (Token *tok = const_cast(tokenizer->tokens()); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "sizeof (")) { - ValueType vt = ValueType::parseDecl(tok->tokAt(2), settings, tokenizer->isCPP()); + ValueType vt = ValueType::parseDecl(tok->tokAt(2), *settings, tokenizer->isCPP()); const int sz = vt.typeSize(settings->platform, true); if (sz <= 0) continue; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4b3dc3199..2dc897704 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -52,17 +52,17 @@ #include //--------------------------------------------------------------------------- -SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) +SymbolDatabase::SymbolDatabase(const Tokenizer &tokenizer, const Settings &settings, ErrorLogger *errorLogger) : mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger) { - if (!tokenizer || !tokenizer->tokens()) + if (!mTokenizer.tokens()) return; mIsCpp = isCPP(); - if (mSettings->platform.defaultSign == 's' || mSettings->platform.defaultSign == 'S') + if (mSettings.platform.defaultSign == 's' || mSettings.platform.defaultSign == 'S') mDefaultSignedness = ValueType::SIGNED; - else if (mSettings->platform.defaultSign == 'u' || mSettings->platform.defaultSign == 'U') + else if (mSettings.platform.defaultSign == 'u' || mSettings.platform.defaultSign == 'U') mDefaultSignedness = ValueType::UNSIGNED; else mDefaultSignedness = ValueType::UNKNOWN_SIGN; @@ -145,24 +145,24 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() std::map access; // find all scopes - for (const Token *tok = mTokenizer->tokens(); tok; tok = tok ? tok->next() : nullptr) { + for (const Token *tok = mTokenizer.tokens(); tok; tok = tok ? tok->next() : nullptr) { // #5593 suggested to add here: if (mErrorLogger) - mErrorLogger->reportProgress(mTokenizer->list.getSourceFilePath(), + mErrorLogger->reportProgress(mTokenizer.list.getSourceFilePath(), "SymbolDatabase", tok->progressValue()); // Locate next class - if ((mTokenizer->isCPP() && tok->isKeyword() && + if ((mTokenizer.isCPP() && tok->isKeyword() && ((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") && !Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) || (Token::Match(tok, "enum class| %name% {") || Token::Match(tok, "enum class| %name% : %name% {")))) - || (mTokenizer->isC() && tok->isKeyword() && Token::Match(tok, "struct|union|enum %name% {"))) { + || (mTokenizer.isC() && tok->isKeyword() && Token::Match(tok, "struct|union|enum %name% {"))) { const Token *tok2 = tok->tokAt(2); if (tok->strAt(1) == "::") tok2 = tok2->next(); - else if (mTokenizer->isCPP() && tok->strAt(1) == "class") + else if (mTokenizer.isCPP() && tok->strAt(1) == "class") tok2 = tok2->next(); while (Token::Match(tok2, ":: %name%")) @@ -178,7 +178,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // skip over final - if (mTokenizer->isCPP() && Token::simpleMatch(tok2, "final")) + if (mTokenizer.isCPP() && Token::simpleMatch(tok2, "final")) tok2 = tok2->next(); // make sure we have valid code @@ -196,7 +196,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // skip variable declaration else if (Token::Match(tok2, "*|&|>")) continue; - else if (Token::Match(tok2, "%name% (") && mTokenizer->isFunctionHead(tok2->next(), "{;")) + else if (Token::Match(tok2, "%name% (") && mTokenizer.isFunctionHead(tok2->next(), "{;")) continue; else if (Token::Match(tok2, "%name% [|=")) continue; @@ -237,7 +237,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() if (new_scope->isClassOrStruct()) { // goto initial '{' if (!new_scope->definedType) - mTokenizer->syntaxError(nullptr); // #6808 + mTokenizer.syntaxError(nullptr); // #6808 tok2 = new_scope->definedType->initBaseInfo(tok, tok2); // make sure we have valid code if (!tok2) { @@ -246,7 +246,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // definition may be different than declaration - if (mTokenizer->isCPP() && tok->str() == "class") { + if (mTokenizer.isCPP() && tok->str() == "class") { access[new_scope] = AccessControl::Private; new_scope->type = Scope::eClass; } else if (tok->str() == "struct") { @@ -258,7 +258,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() new_scope->setBodyStartEnd(tok2); // make sure we have valid code if (!new_scope->bodyEnd) { - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } scope = new_scope; tok = tok2; @@ -290,7 +290,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // make sure we have valid code if (!tok2) { - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } } else if (new_scope->type == Scope::eEnum) { if (tok2->str() == ":") @@ -301,15 +301,15 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // make sure we have valid code if (!new_scope->bodyEnd) { - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } if (new_scope->type == Scope::eEnum) { - tok2 = new_scope->addEnum(tok, mTokenizer->isCPP()); + tok2 = new_scope->addEnum(tok, mTokenizer.isCPP()); scope->nestedList.push_back(new_scope); if (!tok2) - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } else { // make the new scope the current scope scope->nestedList.push_back(new_scope); @@ -321,7 +321,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // Namespace and unknown macro (#3854) - else if (mTokenizer->isCPP() && tok->isKeyword() && + else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "namespace %name% %type% (") && tok->tokAt(2)->isUpperCaseName() && Token::simpleMatch(tok->linkAt(3), ") {")) { @@ -360,7 +360,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // using namespace - else if (mTokenizer->isCPP() && tok->isKeyword() && Token::Match(tok, "using namespace ::| %type% ;|::")) { + else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "using namespace ::| %type% ;|::")) { Scope::UsingInfo using_info; using_info.start = tok; // save location @@ -380,7 +380,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // using type alias - else if (mTokenizer->isCPP() && tok->isKeyword() && Token::Match(tok, "using %name% =")) { + else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "using %name% =")) { if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) { // fill typeList.. typeList.emplace_back(tok, nullptr, scope); @@ -420,7 +420,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() scope->definedTypesMap[new_type->name()] = new_type; } - scope->addVariable(varNameTok, tok, tok, access[scope], new_scope->definedType, scope, mSettings); + scope->addVariable(varNameTok, tok, tok, access[scope], new_scope->definedType, scope, &mSettings); const Token *tok2 = tok->next(); @@ -521,7 +521,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // class function? else if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) { if (tok->previous()->str() != "::" || tok->strAt(-2) == scope->className) { - Function function(mTokenizer, tok, scope, funcStart, argStart); + Function function(&mTokenizer, tok, scope, funcStart, argStart); // save the access type function.access = access[scope]; @@ -537,7 +537,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() function.arg = function.argDef; // out of line function - if (const Token *endTok = mTokenizer->isFunctionHead(end, ";")) { + if (const Token *endTok = mTokenizer.isFunctionHead(end, ";")) { tok = endTok; scope->addFunction(function); } @@ -593,7 +593,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // friend class declaration? - else if (mTokenizer->isCPP() && tok->isKeyword() && Token::Match(tok, "friend class|struct| ::| %any% ;|::")) { + else if (mTokenizer.isCPP() && tok->isKeyword() && Token::Match(tok, "friend class|struct| ::| %any% ;|::")) { Type::FriendInfo friendInfo; // save the name start @@ -612,7 +612,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() friendInfo.type = nullptr; if (!scope->definedType) - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); scope->definedType->friendList.push_back(friendInfo); } @@ -642,12 +642,12 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Function* const function = addGlobalFunction(scope, tok, argStart, funcStart); if (!function) - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } // syntax error? if (!scope) - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } // function prototype? else if (declEnd && declEnd->str() == ";") { @@ -704,9 +704,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); if (scope->type == Scope::eFor) - scope->checkVariable(tok->tokAt(2), AccessControl::Local, mSettings); // check for variable declaration and add it to new scope if found + scope->checkVariable(tok->tokAt(2), AccessControl::Local, &mSettings); // check for variable declaration and add it to new scope if found else if (scope->type == Scope::eCatch) - scope->checkVariable(tok->tokAt(2), AccessControl::Throw, mSettings); // check for variable declaration and add it to new scope if found + scope->checkVariable(tok->tokAt(2), AccessControl::Throw, &mSettings); // check for variable declaration and add it to new scope if found tok = scopeStartTok; } else if (Token::Match(tok, "%var% {")) { endInitList.emplace(tok->next()->link(), scope); @@ -717,7 +717,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Token * funcStart = Token::simpleMatch(argStart, "[") ? argStart : argStart->astParent(); const Function * function = addGlobalFunction(scope, tok, argStart, funcStart); if (!function) - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); tok = lambdaStartToken; } else if (tok->str() == "{") { if (inInitList()) { @@ -734,17 +734,17 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // syntax error? if (!scope) - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); // End of scope or list should be handled above if (tok->str() == "}") - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } } } void SymbolDatabase::createSymbolDatabaseClassInfo() { - if (mTokenizer->isC()) + if (mTokenizer.isC()) return; // fill in using info @@ -770,7 +770,7 @@ void SymbolDatabase::createSymbolDatabaseClassInfo() const Type* found = findType(i.nameTok, type.enclosingScope, /*lookOutside*/ true); if (found && found->findDependency(&type)) { // circular dependency - //mTokenizer->syntaxError(nullptr); + //mTokenizer.syntaxError(nullptr); } else { i.type = found; } @@ -791,7 +791,7 @@ void SymbolDatabase::createSymbolDatabaseVariableInfo() // fill in variable info for (Scope& scope : scopeList) { // find variables - scope.getVariableList(mSettings); + scope.getVariableList(&mSettings); } // fill in function arguments @@ -874,7 +874,7 @@ void SymbolDatabase::createSymbolDatabaseFunctionReturnTypes() void SymbolDatabase::createSymbolDatabaseNeedInitialization() { - if (mTokenizer->isC()) { + if (mTokenizer.isC()) { // For C code it is easy, as there are no constructors and no default values for (const Scope& scope : scopeList) { if (scope.definedType) @@ -962,7 +962,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization() } while (unknowns && retry < 100); // this shouldn't happen so output a debug warning - if (retry == 100 && mSettings->debugwarnings) { + if (retry == 100 && mSettings.debugwarnings) { for (const Scope& scope : scopeList) { if (scope.isClassOrStruct() && scope.definedType->needInitialization == Type::NeedInitialization::Unknown) debugMessage(scope.classDef, "debug", "SymbolDatabase couldn't resolve all user defined types."); @@ -974,7 +974,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization() void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() { // create variable symbol table - mVariableList.resize(mTokenizer->varIdCount() + 1); + mVariableList.resize(mTokenizer.varIdCount() + 1); std::fill_n(mVariableList.begin(), mVariableList.size(), nullptr); // check all scopes for variables @@ -1069,7 +1069,7 @@ void SymbolDatabase::createSymbolDatabaseSetScopePointers() // Set scope pointers for (const Scope& scope: scopeList) { if (scope.type == Scope::eGlobal) - setScopePointers(scope, mTokenizer->list.front(), mTokenizer->list.back()); + setScopePointers(scope, mTokenizer.list.front(), mTokenizer.list.back()); else { for (const Token *bodyStart: scope.bodyStartList) setScopePointers(scope, bodyStart, bodyStart->link()); @@ -1093,7 +1093,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass) } // Set function call pointers - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { if (tok->isName() && !tok->function() && tok->varId() == 0 && Token::Match(tok, "%name% [(,)>;]") && !isReservedName(tok->str())) { if (tok->next()->str() == ">" && !tok->next()->link()) continue; @@ -1159,7 +1159,7 @@ void SymbolDatabase::createSymbolDatabaseSetTypePointers() } // Set type pointers - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { if (!tok->isName() || tok->varId() || tok->function() || tok->type() || tok->enumerator()) continue; @@ -1191,7 +1191,7 @@ void SymbolDatabase::fixVarId(VarIdMap & varIds, const Token * vartok, Token * m if (varId == varIds.end()) { MemberIdMap memberId; if (membertok->varId() == 0) { - memberId[membervar->nameToken()->varId()] = const_cast(mTokenizer)->newVarId(); + memberId[membervar->nameToken()->varId()] = const_cast(mTokenizer).newVarId(); mVariableList.push_back(membervar); } else mVariableList[membertok->varId()] = membervar; @@ -1201,7 +1201,7 @@ void SymbolDatabase::fixVarId(VarIdMap & varIds, const Token * vartok, Token * m MemberIdMap::iterator memberId = varId->second.find(membervar->nameToken()->varId()); if (memberId == varId->second.end()) { if (membertok->varId() == 0) { - varId->second.insert(std::make_pair(membervar->nameToken()->varId(), const_cast(mTokenizer)->newVarId())); + varId->second.insert(std::make_pair(membervar->nameToken()->varId(), const_cast(mTokenizer).newVarId())); mVariableList.push_back(membervar); memberId = varId->second.find(membervar->nameToken()->varId()); } else @@ -1226,7 +1226,7 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers() }; // Set variable pointers - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { if (!tok->isName() || tok->isKeyword() || tok->isStandardType()) continue; if (tok->varId()) @@ -1362,7 +1362,7 @@ void SymbolDatabase::createSymbolDatabaseEnums() // look for initialization tokens that can be converted to enumerators and convert them if (enumerator.start) { if (!enumerator.end) - mTokenizer->syntaxError(enumerator.start); + mTokenizer.syntaxError(enumerator.start); for (const Token * tok3 = enumerator.start; tok3 && tok3 != enumerator.end->next(); tok3 = tok3->next()) { if (tok3->tokType() == Token::eName) { const Enumerator * e = findEnumerator(tok3, tokensThatAreNotEnumeratorValues); @@ -1375,7 +1375,7 @@ void SymbolDatabase::createSymbolDatabaseEnums() } // find enumerators - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { const bool isVariable = (tok->tokType() == Token::eVariable && !tok->variable()); if (tok->tokType() != Token::eName && !isVariable) continue; @@ -1451,7 +1451,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars() "volatile", "NULL", }; - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { const Scope * scope = tok->scope(); if (!scope) continue; @@ -1483,7 +1483,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars() // TODO: handle all C/C++ standards if (cppkeywords.count(tok->str()) > 0) continue; - if (mSettings->standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0) + if (mSettings.standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0) continue; const_cast(tok)->isIncompleteVar(true); // TODO: avoid const_cast } @@ -1499,7 +1499,7 @@ void SymbolDatabase::createSymbolDatabaseEscapeFunctions() continue; if (Token::findsimplematch(scope.bodyStart, "return", scope.bodyEnd)) continue; - function->isEscapeFunction(isReturnScope(scope.bodyEnd, &mSettings->library, nullptr, true)); + function->isEscapeFunction(isReturnScope(scope.bodyEnd, &mSettings.library, nullptr, true)); } } @@ -1546,7 +1546,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() // Find incomplete vars that are used in constant context std::unordered_map unknownConstantIds; const Token* inConstExpr = nullptr; - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { if (Token::Match(tok, "decltype|sizeof|typeof (") && tok->next()->link()) { tok = tok->next()->link()->previous(); } else if (tok == inConstExpr) { @@ -1620,7 +1620,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() continue; if (tok1->exprId() == tok2->exprId()) continue; - if (!isSameExpression(isCPP(), true, tok1, tok2, mSettings->library, false, false)) + if (!isSameExpression(isCPP(), true, tok1, tok2, mSettings.library, false, false)) continue; nonneg int const cid = std::min(tok1->exprId(), tok2->exprId()); tok1->exprId(cid); @@ -1652,7 +1652,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() // In template arguments, there might not be AST // Determine size by using the "raw tokens" - TokenList tokenList(mSettings); + TokenList tokenList(&mSettings); tokenList.addtoken(";", 0, 0, 0, false); bool fail = false; for (const Token *tok = dimension.tok; tok && !Token::Match(tok, "[,>]"); tok = tok->next()) { @@ -1702,19 +1702,19 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() int bits = 0; switch (dimension.tok->valueType()->type) { case ValueType::Type::CHAR: - bits = mSettings->platform.char_bit; + bits = mSettings.platform.char_bit; break; case ValueType::Type::SHORT: - bits = mSettings->platform.short_bit; + bits = mSettings.platform.short_bit; break; case ValueType::Type::INT: - bits = mSettings->platform.int_bit; + bits = mSettings.platform.int_bit; break; case ValueType::Type::LONG: - bits = mSettings->platform.long_bit; + bits = mSettings.platform.long_bit; break; case ValueType::Type::LONGLONG: - bits = mSettings->platform.long_long_bit; + bits = mSettings.platform.long_long_bit; break; default: break; @@ -1734,7 +1734,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() SymbolDatabase::~SymbolDatabase() { // Clear scope, type, function and variable pointers - for (const Token* tok = mTokenizer->list.front(); tok; tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok; tok = tok->next()) { const_cast(tok)->scope(nullptr); const_cast(tok)->type(nullptr); const_cast(tok)->function(nullptr); @@ -1792,7 +1792,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const const Token* tok1 = tok->previous(); const Token* tok2 = tok->next()->link()->next(); - if (!mTokenizer->isFunctionHead(tok->next(), ";:{")) + if (!mTokenizer.isFunctionHead(tok->next(), ";:{")) return false; // skip over destructor "~" @@ -1924,14 +1924,14 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) && Token::simpleMatch(tok->linkAt(1), ") {") && (!tok->previous() || Token::Match(tok->previous(), ";|}"))) { - if (mTokenizer->isC()) { + if (mTokenizer.isC()) { debugMessage(tok, "debug", "SymbolDatabase::isFunction found C function '" + tok->str() + "' without a return type."); *funcStart = tok; *argStart = tok->next(); *declEnd = tok->linkAt(1)->next(); return true; } - mTokenizer->syntaxError(tok); + mTokenizer.syntaxError(tok); } return false; @@ -1946,7 +1946,7 @@ void SymbolDatabase::validateExecutableScopes() const if (scope->isExecutable() && !function) { const std::list callstack(1, scope->classDef); const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function."; - const ErrorMessage errmsg(callstack, &mTokenizer->list, Severity::debug, + const ErrorMessage errmsg(callstack, &mTokenizer.list, Severity::debug, "symbolDatabaseWarning", msg, Certainty::normal); @@ -1991,7 +1991,7 @@ void SymbolDatabase::validateVariables() const void SymbolDatabase::validate() const { - if (mSettings->debugwarnings) { + if (mSettings.debugwarnings) { validateExecutableScopes(); } // TODO @@ -2005,9 +2005,9 @@ void SymbolDatabase::clangSetVariables(const std::vector &vari void SymbolDatabase::debugSymbolDatabase() const { - if (!mSettings->debugnormal && !mSettings->debugwarnings) + if (!mSettings.debugnormal && !mSettings.debugwarnings) return; - for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) { + for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug()) continue; if (tok->getTokenDebug() == TokenDebug::ValueType) { @@ -2023,7 +2023,7 @@ void SymbolDatabase::debugSymbolDatabase() const } errorPath.emplace_back(tok, ""); mErrorLogger->reportErr( - {errorPath, &mTokenizer->list, Severity::debug, "valueType", msg, CWE{0}, Certainty::normal}); + {errorPath, &mTokenizer.list, Severity::debug, "valueType", msg, CWE{0}, Certainty::normal}); } } } @@ -2171,7 +2171,7 @@ void Variable::evaluate(const Settings* settings) setFlag(fIsArray, arrayDimensions(settings, isContainer)); if (mTypeStartToken) - setValueType(ValueType::parseDecl(mTypeStartToken,settings, true)); // TODO: set isCpp + setValueType(ValueType::parseDecl(mTypeStartToken,*settings, true)); // TODO: set isCpp const Token* tok = mTypeStartToken; while (tok && tok->previous() && tok->previous()->isName()) @@ -3099,7 +3099,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok, const Token *argStart, const Token* funcStart) { - Function function(mTokenizer, tok, scope, funcStart, argStart); + Function function(&mTokenizer, tok, scope, funcStart, argStart); scope->addFunction(std::move(function)); return &scope->functionList.back(); } @@ -3165,7 +3165,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To if (!func->hasBody()) { const Token *closeParen = (*tok)->next()->link(); if (closeParen) { - const Token *eq = mTokenizer->isFunctionHead(closeParen, ";"); + const Token *eq = mTokenizer.isFunctionHead(closeParen, ";"); if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) { func->isDefault(true); return; @@ -3235,7 +3235,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To if (func->argsMatch(scope1, func->argDef, (*tok)->next(), path, path_length)) { const Token *closeParen = (*tok)->next()->link(); if (closeParen) { - const Token *eq = mTokenizer->isFunctionHead(closeParen, ";"); + const Token *eq = mTokenizer.isFunctionHead(closeParen, ";"); if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) { func->isDefault(true); return; @@ -3299,7 +3299,7 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) // syntax error? if (!newScope->bodyEnd) { - mTokenizer->unmatchedToken(tok1); + mTokenizer.unmatchedToken(tok1); } else { (*scope)->nestedList.push_back(newScope); *scope = newScope; @@ -3432,9 +3432,9 @@ const std::string& Type::name() const void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, const std::string &msg) const { - if (tok && mSettings->debugwarnings) { + if (tok && mSettings.debugwarnings) { const std::list locationList(1, tok); - const ErrorMessage errmsg(locationList, &mTokenizer->list, + const ErrorMessage errmsg(locationList, &mTokenizer.list, Severity::debug, type, msg, @@ -3608,18 +3608,18 @@ static std::string accessControlToString(const AccessControl& access) return "Unknown"; } -static std::string tokenToString(const Token* tok, const Tokenizer* tokenizer) +static std::string tokenToString(const Token* tok, const Tokenizer& tokenizer) { std::ostringstream oss; if (tok) { oss << tok->str() << " "; - oss << tokenizer->list.fileLine(tok) << " "; + oss << tokenizer.list.fileLine(tok) << " "; } oss << tok; return oss.str(); } -static std::string scopeToString(const Scope* scope, const Tokenizer* tokenizer) +static std::string scopeToString(const Scope* scope, const Tokenizer& tokenizer) { std::ostringstream oss; if (scope) { @@ -3627,7 +3627,7 @@ static std::string scopeToString(const Scope* scope, const Tokenizer* tokenizer) if (!scope->className.empty()) oss << scope->className << " "; if (scope->classDef) - oss << tokenizer->list.fileLine(scope->classDef) << " "; + oss << tokenizer.list.fileLine(scope->classDef) << " "; } oss << scope; return oss.str(); @@ -3696,7 +3696,7 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons std::cout << indent << "mType: "; if (var->type()) { std::cout << var->type()->type() << " " << var->type()->name(); - std::cout << " " << mTokenizer->list.fileLine(var->type()->classDef); + std::cout << " " << mTokenizer.list.fileLine(var->type()->classDef); std::cout << " " << var->type() << std::endl; } else std::cout << "none" << std::endl; @@ -3880,7 +3880,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << "::" << tok1->strAt(1); tok1 = tok1->tokAt(2); } - std::cout << " " << mTokenizer->list.fileLine(use->start) << std::endl; + std::cout << " " << mTokenizer.list.fileLine(use->start) << std::endl; } std::cout << " functionOf: " << scopeToString(scope->functionOf, mTokenizer) << std::endl; @@ -3951,7 +3951,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << "mVariableList[" << i << "]: " << mVariableList[i]; if (mVariableList[i]) { std::cout << " " << mVariableList[i]->name() << " " - << mTokenizer->list.fileLine(mVariableList[i]->nameToken()); + << mTokenizer.list.fileLine(mVariableList[i]->nameToken()); } std::cout << std::endl; } @@ -4189,7 +4189,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s while (Token::Match(typeTok, "const|volatile|enum|struct|::")) typeTok = typeTok->next(); if (Token::Match(typeTok, ",|)")) { // #8333 - symbolDatabase->mTokenizer->syntaxError(typeTok); + symbolDatabase->mTokenizer.syntaxError(typeTok); } // skip over qualification while (Token::Match(typeTok, "%type% ::")) @@ -4234,7 +4234,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s if (startTok == nameTok) break; - argumentList.emplace_back(nameTok, startTok, endTok, count++, AccessControl::Argument, argType, functionScope, symbolDatabase->mSettings); + argumentList.emplace_back(nameTok, startTok, endTok, count++, AccessControl::Argument, argType, functionScope, &symbolDatabase->mSettings); if (tok->str() == ")") { // check for a variadic function or a variadic template function @@ -4487,7 +4487,7 @@ void Scope::getVariableList(const Settings* settings) // global scope else if (type == Scope::eGlobal) - getVariableList(settings, check->mTokenizer->tokens(), nullptr); + getVariableList(settings, check->mTokenizer.tokens(), nullptr); // forward declaration else @@ -4730,12 +4730,12 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok, if (!tok) return false; - const bool isCPP = check && check->mTokenizer->isCPP(); + const bool isCPP = check && check->mTokenizer.isCPP(); if (isCPP && Token::Match(tok, "throw|new")) return false; - const bool isCPP11 = isCPP && check->mSettings->standards.cpp >= Standards::CPP11; + const bool isCPP11 = isCPP && check->mSettings.standards.cpp >= Standards::CPP11; if (isCPP11 && tok->str() == "using") return false; @@ -5751,7 +5751,7 @@ const Function *Scope::getDestructor() const bool SymbolDatabase::isCPP() const { - return mTokenizer->isCPP(); + return mTokenizer.isCPP(); } //--------------------------------------------------------------------------- @@ -5796,7 +5796,7 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc if (startTok->str() == startScope->className && startScope->isClassOrStruct() && startTok->strAt(1) != "::") return startScope->definedType; - if (mTokenizer->isC()) { + if (mTokenizer.isC()) { const Scope* scope = startScope; while (scope) { if (startTok->str() == scope->className && scope->isClassOrStruct()) @@ -6018,13 +6018,13 @@ bool SymbolDatabase::isReservedName(const std::string& iName) const nonneg int SymbolDatabase::sizeOfType(const Token *type) const { - int size = mTokenizer->sizeOfType(type); + int size = mTokenizer.sizeOfType(type); if (size == 0 && type->type() && type->type()->isEnumType() && type->type()->classScope) { - size = mSettings->platform.sizeof_int; + size = mSettings.platform.sizeof_int; const Token * enum_type = type->type()->classScope->enumType; if (enum_type) - size = mTokenizer->sizeOfType(enum_type); + size = mTokenizer.sizeOfType(enum_type); } return size; @@ -6033,14 +6033,14 @@ nonneg int SymbolDatabase::sizeOfType(const Token *type) const static const Token* parsedecl(const Token* type, ValueType* const valuetype, ValueType::Sign defaultSignedness, - const Settings* settings, + const Settings& settings, bool isCpp, SourceLocation loc = SourceLocation::current()); void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocation loc) { ValueType valuetype; - if (mSettings->debugnormal || mSettings->debugwarnings) + if (mSettings.debugnormal || mSettings.debugwarnings) valuetype.setDebugPath(tok, loc); if (var.nameToken()) valuetype.bits = var.nameToken()->bits(); @@ -6069,7 +6069,7 @@ void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocatio void SymbolDatabase::setValueType(Token* tok, const Enumerator& enumerator, SourceLocation loc) { ValueType valuetype; - if (mSettings->debugnormal || mSettings->debugwarnings) + if (mSettings.debugnormal || mSettings.debugwarnings) valuetype.setDebugPath(tok, loc); valuetype.typeScope = enumerator.scope; const Token * type = enumerator.scope->enumType; @@ -6118,7 +6118,7 @@ static bool isContainerYieldPointer(Library::Container::Yield yield) void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, SourceLocation loc) { ValueType* valuetypePtr = new ValueType(valuetype); - if (mSettings->debugnormal || mSettings->debugwarnings) + if (mSettings.debugnormal || mSettings.debugwarnings) valuetypePtr->setDebugPath(tok, loc); tok->setValueType(valuetypePtr); Token *parent = tok->astParent(); @@ -6373,7 +6373,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source setType = true; autovt.type = ValueType::Type::RECORD; } else if (vt2->containerTypeToken) { - if (mSettings->library.isSmartPointer(vt2->containerTypeToken)) { + if (mSettings.library.isSmartPointer(vt2->containerTypeToken)) { const Token *smartPointerTypeTok = vt2->containerTypeToken; while (Token::Match(smartPointerTypeTok, "%name%|::")) smartPointerTypeTok = smartPointerTypeTok->next(); @@ -6425,7 +6425,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source } // c++17 auto type deduction of braced init list - if (mIsCpp && mSettings->standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { + if (mIsCpp && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { Token *autoTok = parent->tokAt(-2); setValueType(autoTok, *vt2); setAutoTokenProperties(autoTok); @@ -6560,11 +6560,11 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source static const Token* parsedecl(const Token* type, ValueType* const valuetype, ValueType::Sign defaultSignedness, - const Settings* settings, + const Settings& settings, bool isCpp, SourceLocation loc) { - if (settings->debugnormal || settings->debugwarnings) + if (settings.debugnormal || settings.debugwarnings) valuetype->setDebugPath(type, loc); const Token * const previousType = type; const unsigned int pointer0 = valuetype->pointer; @@ -6625,8 +6625,8 @@ static const Token* parsedecl(const Token* type, parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp); else if (Token::Match(type, "const|constexpr")) valuetype->constness |= (1 << (valuetype->pointer - pointer0)); - else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find('<')) { - TokenList typeTokens(settings); + else if (settings.clang && type->str().size() > 2 && type->str().find("::") < type->str().find('<')) { + TokenList typeTokens(&settings); std::string::size_type pos1 = 0; do { const std::string::size_type pos2 = type->str().find("::", pos1); @@ -6639,7 +6639,7 @@ static const Token* parsedecl(const Token* type, pos1 = pos2 + 2; } while (pos1 < type->str().size()); const Library::Container* container = - settings->library.detectContainerOrIterator(typeTokens.front(), &isIterator); + settings.library.detectContainerOrIterator(typeTokens.front(), &isIterator); if (container) { if (isIterator) valuetype->type = ValueType::Type::ITERATOR; @@ -6652,7 +6652,7 @@ static const Token* parsedecl(const Token* type, if (valuetype->typeScope) valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD; } - } else if (const Library::Container* container = (isCpp ? settings->library.detectContainerOrIterator(type, &isIterator) : nullptr)) { + } else if (const Library::Container* container = (isCpp ? settings.library.detectContainerOrIterator(type, &isIterator) : nullptr)) { if (isIterator) valuetype->type = ValueType::Type::ITERATOR; else @@ -6674,7 +6674,7 @@ static const Token* parsedecl(const Token* type, // we are past the end of the type type = type->previous(); continue; - } else if (const Library::SmartPointer* smartPointer = (isCpp ? settings->library.detectSmartPointer(type) : nullptr)) { + } else if (const Library::SmartPointer* smartPointer = (isCpp ? settings.library.detectSmartPointer(type) : nullptr)) { const Token* argTok = Token::findsimplematch(type, "<"); if (!argTok) break; @@ -6797,7 +6797,7 @@ static const Function *getOperatorFunction(const Token * const tok) void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *tokens) { if (!tokens) - tokens = const_cast(mTokenizer)->list.front(); + tokens = const_cast(mTokenizer).list.front(); for (Token *tok = tokens; tok; tok = tok->next()) tok->setValueType(nullptr); @@ -6829,18 +6829,18 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to pos -= 2; } else break; } - if (mSettings->platform.type != cppcheck::Platform::Type::Unspecified) { - if (type <= ValueType::Type::INT && mSettings->platform.isIntValue(unsignedSuffix ? (value >> 1) : value)) + if (mSettings.platform.type != cppcheck::Platform::Type::Unspecified) { + if (type <= ValueType::Type::INT && mSettings.platform.isIntValue(unsignedSuffix ? (value >> 1) : value)) type = ValueType::Type::INT; - else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings->platform.isIntValue(value >> 2)) { + else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings.platform.isIntValue(value >> 2)) { type = ValueType::Type::INT; sign = ValueType::Sign::UNSIGNED; - } else if (type <= ValueType::Type::LONG && mSettings->platform.isLongValue(unsignedSuffix ? (value >> 1) : value)) + } else if (type <= ValueType::Type::LONG && mSettings.platform.isLongValue(unsignedSuffix ? (value >> 1) : value)) type = ValueType::Type::LONG; - else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings->platform.isLongValue(value >> 2)) { + else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings.platform.isLongValue(value >> 2)) { type = ValueType::Type::LONG; sign = ValueType::Sign::UNSIGNED; - } else if (mSettings->platform.isLongLongValue(unsignedSuffix ? (value >> 1) : value)) + } else if (mSettings.platform.isLongLongValue(unsignedSuffix ? (value >> 1) : value)) type = ValueType::Type::LONGLONG; else { type = ValueType::Type::LONGLONG; @@ -6868,7 +6868,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to nonneg int const constness = tok->tokType() == Token::eChar ? 0U : 1U; ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness); - if (mIsCpp && mSettings->standards.cpp >= Standards::CPP20 && tok->isUtf8()) { + if (mIsCpp && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) { valuetype.originalTypeName = "char8_t"; valuetype.fromLibraryType(valuetype.originalTypeName, mSettings); } else if (tok->isUtf16()) { @@ -6902,7 +6902,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } // Construct smart pointer - else if (mSettings->library.isSmartPointer(start)) { + else if (mSettings.library.isSmartPointer(start)) { ValueType valuetype; if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings, mIsCpp)) { setValueType(tok, valuetype); @@ -6920,7 +6920,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to else if (Token::simpleMatch(tok->previous(), "sizeof (")) { ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U); - if (mSettings->platform.type == cppcheck::Platform::Type::Win64) + if (mSettings.platform.type == cppcheck::Platform::Type::Win64) valuetype.type = ValueType::Type::LONGLONG; valuetype.originalTypeName = "size_t"; @@ -6981,8 +6981,8 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to const Token *typeStartToken = tok->astOperand1(); while (typeStartToken && typeStartToken->str() == "::") typeStartToken = typeStartToken->astOperand1(); - if (mSettings->library.detectContainerOrIterator(typeStartToken) || - mSettings->library.detectSmartPointer(typeStartToken)) { + if (mSettings.library.detectContainerOrIterator(typeStartToken) || + mSettings.library.detectSmartPointer(typeStartToken)) { ValueType vt; if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) { setValueType(tok, vt); @@ -6999,10 +6999,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to vt.smartPointerType = vt.typeScope->definedType; vt.typeScope = nullptr; } - if (e == "std::make_shared" && mSettings->library.smartPointers.count("std::shared_ptr") > 0) - vt.smartPointer = &mSettings->library.smartPointers.at("std::shared_ptr"); - if (e == "std::make_unique" && mSettings->library.smartPointers.count("std::unique_ptr") > 0) - vt.smartPointer = &mSettings->library.smartPointers.at("std::unique_ptr"); + if (e == "std::make_shared" && mSettings.library.smartPointers.count("std::shared_ptr") > 0) + vt.smartPointer = &mSettings.library.smartPointers.at("std::shared_ptr"); + if (e == "std::make_unique" && mSettings.library.smartPointers.count("std::unique_ptr") > 0) + vt.smartPointer = &mSettings.library.smartPointers.at("std::unique_ptr"); vt.type = ValueType::Type::SMART_POINTER; vt.smartPointerTypeToken = tok->astOperand1()->tokAt(3); setValueType(tok, vt); @@ -7016,10 +7016,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } } - const std::string& typestr(mSettings->library.returnValueType(tok->previous())); + const std::string& typestr(mSettings.library.returnValueType(tok->previous())); if (!typestr.empty()) { ValueType valuetype; - TokenList tokenList(mSettings); + TokenList tokenList(&mSettings); std::istringstream istr(typestr+";"); tokenList.createTokens(istr); tokenList.simplifyStdType(); @@ -7055,7 +7055,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to if (isReturnIter) { const std::vector args = getArguments(tok); if (!args.empty()) { - const Library::ArgumentChecks::IteratorInfo* info = mSettings->library.getArgIteratorInfo(tok->previous(), 1); + const Library::ArgumentChecks::IteratorInfo* info = mSettings.library.getArgIteratorInfo(tok->previous(), 1); if (info && info->it) { const Token* contTok = args[0]; if (Token::simpleMatch(args[0]->astOperand1(), ".") && args[0]->astOperand1()->astOperand1()) @@ -7072,7 +7072,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } continue; } - TokenList tokenList(mSettings); + TokenList tokenList(&mSettings); std::istringstream istr(typestr+";"); if (tokenList.createTokens(istr)) { ValueType vt; @@ -7106,7 +7106,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to if (Token::Match(typeTok, "( std| ::| nothrow )")) typeTok = typeTok->link()->next(); bool isIterator = false; - if (const Library::Container* c = mSettings->library.detectContainerOrIterator(typeTok, &isIterator)) { + if (const Library::Container* c = mSettings.library.detectContainerOrIterator(typeTok, &isIterator)) { ValueType vt; vt.pointer = 1; vt.container = c; @@ -7169,7 +7169,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } } - if (reportDebugWarnings && mSettings->debugwarnings) { + if (reportDebugWarnings && mSettings.debugwarnings) { for (Token *tok = tokens; tok; tok = tok->next()) { if (tok->str() == "auto" && !tok->valueType()) debugMessage(tok, "autoNoType", "auto token with no type."); @@ -7183,10 +7183,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to createSymbolDatabaseSetVariablePointers(); } -ValueType ValueType::parseDecl(const Token *type, const Settings *settings, bool isCpp) +ValueType ValueType::parseDecl(const Token *type, const Settings &settings, bool isCpp) { ValueType vt; - parsedecl(type, &vt, settings->platform.defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings, isCpp); + parsedecl(type, &vt, settings.platform.defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings, isCpp); return vt; } @@ -7213,19 +7213,19 @@ ValueType::Type ValueType::typeFromString(const std::string &typestr, bool longT return ValueType::Type::UNKNOWN_TYPE; } -bool ValueType::fromLibraryType(const std::string &typestr, const Settings *settings) +bool ValueType::fromLibraryType(const std::string &typestr, const Settings &settings) { - const Library::PodType* podtype = settings->library.podtype(typestr); + const Library::PodType* podtype = settings.library.podtype(typestr); if (podtype && (podtype->sign == 's' || podtype->sign == 'u')) { if (podtype->size == 1) type = ValueType::Type::CHAR; - else if (podtype->size == settings->platform.sizeof_int) + else if (podtype->size == settings.platform.sizeof_int) type = ValueType::Type::INT; - else if (podtype->size == settings->platform.sizeof_short) + else if (podtype->size == settings.platform.sizeof_short) type = ValueType::Type::SHORT; - else if (podtype->size == settings->platform.sizeof_long) + else if (podtype->size == settings.platform.sizeof_long) type = ValueType::Type::LONG; - else if (podtype->size == settings->platform.sizeof_long_long) + else if (podtype->size == settings.platform.sizeof_long_long) type = ValueType::Type::LONGLONG; else if (podtype->stdtype == Library::PodType::Type::BOOL) type = ValueType::Type::BOOL; @@ -7249,7 +7249,7 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett return true; } - const Library::PlatformType *platformType = settings->library.platform_type(typestr, settings->platform.toString()); + const Library::PlatformType *platformType = settings.library.platform_type(typestr, settings.platform.toString()); if (platformType) { if (platformType->mType == "char") type = ValueType::Type::CHAR; @@ -7275,11 +7275,11 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett } else if (!podtype && (typestr == "size_t" || typestr == "std::size_t")) { originalTypeName = "size_t"; sign = ValueType::UNSIGNED; - if (settings->platform.sizeof_size_t == settings->platform.sizeof_long) + if (settings.platform.sizeof_size_t == settings.platform.sizeof_long) type = ValueType::Type::LONG; - else if (settings->platform.sizeof_size_t == settings->platform.sizeof_long_long) + else if (settings.platform.sizeof_size_t == settings.platform.sizeof_long_long) type = ValueType::Type::LONGLONG; - else if (settings->platform.sizeof_size_t == settings->platform.sizeof_int) + else if (settings.platform.sizeof_size_t == settings.platform.sizeof_int) type = ValueType::Type::INT; else type = ValueType::Type::UNKNOWN_INT; diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index b3c71c4fa..a28a44efc 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1325,7 +1325,7 @@ public: debugPath() {} - static ValueType parseDecl(const Token *type, const Settings *settings, bool isCpp); + static ValueType parseDecl(const Token *type, const Settings &settings, bool isCpp); static Type typeFromString(const std::string &typestr, bool longType); @@ -1345,7 +1345,7 @@ public: return (type >= ValueType::Type::FLOAT && type <= ValueType::Type::LONGDOUBLE); } - bool fromLibraryType(const std::string &typestr, const Settings *settings); + bool fromLibraryType(const std::string &typestr, const Settings &settings); bool isEnum() const { return typeScope && typeScope->type == Scope::eEnum; @@ -1366,7 +1366,7 @@ public: class CPPCHECKLIB SymbolDatabase { friend class TestSymbolDatabase; public: - SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); + SymbolDatabase(const Tokenizer &tokenizer, const Settings &settings, ErrorLogger *errorLogger); ~SymbolDatabase(); /** @brief Information about all namespaces/classes/structures */ @@ -1510,8 +1510,8 @@ private: void setValueType(Token* tok, const Variable& var, SourceLocation loc = SourceLocation::current()); void setValueType(Token* tok, const Enumerator& enumerator, SourceLocation loc = SourceLocation::current()); - const Tokenizer *mTokenizer; - const Settings *mSettings; + const Tokenizer &mTokenizer; + const Settings &mSettings; ErrorLogger *mErrorLogger; /** variable symbol table */ diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 356481b19..190df1825 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9141,7 +9141,7 @@ void Tokenizer::simplifyBorland() void Tokenizer::createSymbolDatabase() { if (!mSymbolDatabase) - mSymbolDatabase = new SymbolDatabase(this, mSettings, mErrorLogger); + mSymbolDatabase = new SymbolDatabase(*this, *mSettings, mErrorLogger); mSymbolDatabase->validate(); } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 276f898df..30373f53c 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -748,7 +748,7 @@ static void setTokenValue(Token* tok, if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) && Token::simpleMatch(parent->astOperand1(), "dynamic_cast")) return; - const ValueType &valueType = ValueType::parseDecl(castType, settings, true); // TODO: set isCpp + const ValueType &valueType = ValueType::parseDecl(castType, *settings, true); // TODO: set isCpp if (value.isImpossible() && value.isIntValue() && value.intvalue < 0 && astIsUnsigned(tok) && valueType.sign == ValueType::SIGNED && tok->valueType() && ValueFlow::getSizeOf(*tok->valueType(), settings) >= ValueFlow::getSizeOf(valueType, settings)) @@ -1051,7 +1051,7 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V static nonneg int getSizeOfType(const Token *typeTok, const Settings *settings) { - const ValueType &valueType = ValueType::parseDecl(typeTok, settings, true); // TODO: set isCpp + const ValueType &valueType = ValueType::parseDecl(typeTok, *settings, true); // TODO: set isCpp if (valueType.pointer > 0) return settings->platform.sizeof_pointer; if (valueType.type == ValueType::Type::BOOL || valueType.type == ValueType::Type::CHAR) @@ -1268,7 +1268,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b setTokenValue(tok->next(), std::move(value), settings); } } else if (!tok2->type()) { - const ValueType& vt = ValueType::parseDecl(tok2, settings, true); // TODO: set isCpp + const ValueType& vt = ValueType::parseDecl(tok2, *settings, true); // TODO: set isCpp size_t sz = ValueFlow::getSizeOf(vt, settings); const Token* brac = tok2->astParent(); while (Token::simpleMatch(brac, "[")) { @@ -4652,7 +4652,7 @@ static bool isContainerOfPointers(const Token* tok, const Settings* settings) return true; } - ValueType vt = ValueType::parseDecl(tok, settings, true); // TODO: set isCpp + ValueType vt = ValueType::parseDecl(tok, *settings, true); // TODO: set isCpp return vt.pointer > 0; } @@ -8275,7 +8275,7 @@ static bool valueFlowIsSameContainerType(const ValueType& contType, const Token* if (!tok || !tok->valueType() || !tok->valueType()->containerTypeToken) return false; - const ValueType tokType = ValueType::parseDecl(tok->valueType()->containerTypeToken, settings, true); + const ValueType tokType = ValueType::parseDecl(tok->valueType()->containerTypeToken, *settings, true); return contType.isTypeEqual(&tokType); } @@ -8295,7 +8295,7 @@ static std::vector getInitListSize(const Token* tok, if (valueType->container->stdStringLike) { initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]); } else if (containerTypeToken && settings) { - ValueType vt = ValueType::parseDecl(containerTypeToken, settings, true); // TODO: set isCpp + ValueType vt = ValueType::parseDecl(containerTypeToken, *settings, true); // TODO: set isCpp if (vt.pointer > 0 && astIsPointer(args[0])) initList = true; else if (vt.type == ValueType::ITERATOR && astIsIterator(args[0])) @@ -8704,7 +8704,7 @@ static bool getMinMaxValues(const std::string &typestr, const Settings *settings return false; typeTokens.simplifyPlatformTypes(); typeTokens.simplifyStdType(); - const ValueType &vt = ValueType::parseDecl(typeTokens.front(), settings, true); // TODO: set isCpp + const ValueType &vt = ValueType::parseDecl(typeTokens.front(), *settings, true); // TODO: set isCpp return getMinMaxValues(&vt, settings->platform, minvalue, maxvalue); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 587f08522..59a294e2d 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -7907,11 +7907,11 @@ private: settingsWin64.library.mPodTypes["xyz::x"] = u32; settingsWin64.library.mPodTypes["podtype2"] = podtype2; ValueType vt; - ASSERT_EQUALS(true, vt.fromLibraryType("u32", &settingsWin64)); - ASSERT_EQUALS(true, vt.fromLibraryType("xyz::x", &settingsWin64)); + ASSERT_EQUALS(true, vt.fromLibraryType("u32", settingsWin64)); + ASSERT_EQUALS(true, vt.fromLibraryType("xyz::x", settingsWin64)); ASSERT_EQUALS(ValueType::Type::INT, vt.type); ValueType vt2; - ASSERT_EQUALS(true, vt2.fromLibraryType("podtype2", &settingsWin64)); + ASSERT_EQUALS(true, vt2.fromLibraryType("podtype2", settingsWin64)); ASSERT_EQUALS(ValueType::Type::INT, vt2.type); ASSERT_EQUALS("unsigned int *", typeOf(";void *data = new u32[10];", "new", "test.cpp", &settingsWin64)); ASSERT_EQUALS("unsigned int *", typeOf(";void *data = new xyz::x[10];", "new", "test.cpp", &settingsWin64)); @@ -7927,7 +7927,7 @@ private: s32.mType = "int"; settingsUnix32.library.mPlatforms[settingsUnix32.platform.toString()].mPlatformTypes["s32"] = s32; ValueType vt; - ASSERT_EQUALS(true, vt.fromLibraryType("s32", &settingsUnix32)); + ASSERT_EQUALS(true, vt.fromLibraryType("s32", settingsUnix32)); ASSERT_EQUALS(ValueType::Type::INT, vt.type); } { @@ -7938,7 +7938,7 @@ private: lpctstr.mType = "wchar_t"; settingsWin64.library.mPlatforms[settingsWin64.platform.toString()].mPlatformTypes["LPCTSTR"] = lpctstr; ValueType vt; - ASSERT_EQUALS(true, vt.fromLibraryType("LPCTSTR", &settingsWin64)); + ASSERT_EQUALS(true, vt.fromLibraryType("LPCTSTR", settingsWin64)); ASSERT_EQUALS(ValueType::Type::WCHAR_T, vt.type); } {