diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 942c3ba988e..a45f982e1fd 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -628,7 +628,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s for (const Token *typeToken = tokenList.back(); Token::Match(typeToken, "&|*|%name%"); typeToken = typeToken->previous()) { if (!typeToken->isName()) continue; - const ::Type *recordType = scope->check->findVariableType(scope, typeToken); + const ::Type *recordType = scope->symdb.findVariableType(scope, typeToken); if (recordType) { const_cast(typeToken)->type(recordType); return recordType; @@ -698,14 +698,13 @@ Scope *clangimport::AstNode::createScope(TokenList &tokenList, Scope::ScopeType auto *nestedIn = const_cast(getNestedInScope(tokenList)); - symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nestedIn); + symbolDatabase->scopeList.emplace_back(nestedIn->symdb, nullptr, nestedIn); Scope *scope = &symbolDatabase->scopeList.back(); if (scopeType == Scope::ScopeType::eEnum) scope->enumeratorList.reserve(children2.size()); nestedIn->nestedList.push_back(scope); scope->type = scopeType; - scope->classDef = def; - scope->check = nestedIn->check; + scope->classDef = def; // TODO: pass into ctor if (Token::Match(def, "if|for|while (")) { std::map replaceVar; for (const Token *vartok = def->tokAt(2); vartok; vartok = vartok->next()) { @@ -1401,11 +1400,10 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList) Scope *scope = nullptr; if (hasBody) { - symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nestedIn); + symbolDatabase->scopeList.emplace_back(*symbolDatabase, nullptr, nestedIn); scope = &symbolDatabase->scopeList.back(); - scope->check = symbolDatabase; scope->function = function; - scope->classDef = nameToken; + scope->classDef = nameToken; // TODO: pass into ctor scope->type = Scope::ScopeType::eFunction; scope->className = nameToken->str(); nestedIn->nestedList.push_back(scope); @@ -1617,9 +1615,8 @@ void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f) tokenizer.createSymbolDatabase(); auto *symbolDatabase = const_cast(tokenizer.getSymbolDatabase()); - symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nullptr); + symbolDatabase->scopeList.emplace_back(*symbolDatabase, nullptr, nullptr); symbolDatabase->scopeList.back().type = Scope::ScopeType::eGlobal; - symbolDatabase->scopeList.back().check = symbolDatabase; clangimport::Data data; data.mSettings = &tokenizer.getSettings(); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 2570c819f5e..24458584d19 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -52,15 +52,15 @@ #include //--------------------------------------------------------------------------- -SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger& errorLogger) - : mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger) +SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer) + : mTokenizer(tokenizer) { if (!mTokenizer.tokens()) return; - if (mSettings.platform.defaultSign == 's' || mSettings.platform.defaultSign == 'S') + if (mTokenizer.getSettings().platform.defaultSign == 's' || mTokenizer.getSettings().platform.defaultSign == 'S') mDefaultSignedness = ValueType::SIGNED; - else if (mSettings.platform.defaultSign == 'u' || mSettings.platform.defaultSign == 'U') + else if (mTokenizer.getSettings().platform.defaultSign == 'u' || mTokenizer.getSettings().platform.defaultSign == 'U') mDefaultSignedness = ValueType::UNSIGNED; else mDefaultSignedness = ValueType::UNKNOWN_SIGN; @@ -140,7 +140,7 @@ const Token* SymbolDatabase::isEnumDefinition(const Token* tok) void SymbolDatabase::createSymbolDatabaseFindAllScopes() { // create global scope - scopeList.emplace_back(this, nullptr, nullptr); + scopeList.emplace_back(*this, nullptr, nullptr); // pointer to current scope Scope *scope = &scopeList.back(); @@ -171,9 +171,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // find all scopes for (const Token *tok = mTokenizer.tokens(); tok; tok = tok ? tok->next() : nullptr) { // #5593 suggested to add here: - mErrorLogger.reportProgress(mTokenizer.list.getSourceFilePath(), - "SymbolDatabase", - tok->progressValue()); + mTokenizer.getErrorLogger().reportProgress(mTokenizer.list.getSourceFilePath(), + "SymbolDatabase", + tok->progressValue()); // Locate next class if ((tok->isCpp() && tok->isKeyword() && ((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") && @@ -285,7 +285,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() scope = new_scope; tok = tok2; } else { - scopeList.emplace_back(this, tok, scope); + scopeList.emplace_back(*this, tok, scope); new_scope = &scopeList.back(); if (tok->str() == "class") @@ -350,7 +350,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() Token::Match(tok, "namespace %name% %type% (") && tok->tokAt(2)->isUpperCaseName() && Token::simpleMatch(tok->linkAt(3), ") {")) { - scopeList.emplace_back(this, tok, scope); + scopeList.emplace_back(*this, tok, scope); Scope *new_scope = &scopeList.back(); access[new_scope] = AccessControl::Public; @@ -426,7 +426,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // unnamed struct and union else if (tok->isKeyword() && Token::Match(tok, "struct|union {") && Token::Match(tok->linkAt(1), "} *|&| %name% ;|[|=")) { - scopeList.emplace_back(this, tok, scope); + scopeList.emplace_back(*this, tok, scope); Scope *new_scope = &scopeList.back(); access[new_scope] = AccessControl::Public; @@ -445,7 +445,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); const Token *tok2 = tok->next(); @@ -468,7 +468,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() else if (tok->isKeyword() && ((Token::Match(tok, "struct|union {") && Token::simpleMatch(tok->linkAt(1), "} ;")) || Token::simpleMatch(tok, "namespace {"))) { - scopeList.emplace_back(this, tok, scope); + scopeList.emplace_back(*this, tok, scope); Scope *new_scope = &scopeList.back(); access[new_scope] = AccessControl::Public; @@ -706,11 +706,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() if (tok->isKeyword() && Token::Match(tok, "else|try|do {")) { const Token* tok1 = tok->next(); if (tok->str() == "else") - scopeList.emplace_back(this, tok, scope, Scope::eElse, tok1); + scopeList.emplace_back(*this, tok, scope, Scope::eElse, tok1); else if (tok->str() == "do") - scopeList.emplace_back(this, tok, scope, Scope::eDo, tok1); + scopeList.emplace_back(*this, tok, scope, Scope::eDo, tok1); else //if (tok->str() == "try") - scopeList.emplace_back(this, tok, scope, Scope::eTry, tok1); + scopeList.emplace_back(*this, tok, scope, Scope::eTry, tok1); tok = tok1; scope->nestedList.push_back(&scopeList.back()); @@ -718,22 +718,22 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } else if (tok->isKeyword() && Token::Match(tok, "if|for|while|catch|switch (") && Token::simpleMatch(tok->linkAt(1), ") {")) { const Token *scopeStartTok = tok->linkAt(1)->next(); if (tok->str() == "if") - scopeList.emplace_back(this, tok, scope, Scope::eIf, scopeStartTok); + scopeList.emplace_back(*this, tok, scope, Scope::eIf, scopeStartTok); else if (tok->str() == "for") { - scopeList.emplace_back(this, tok, scope, Scope::eFor, scopeStartTok); + scopeList.emplace_back(*this, tok, scope, Scope::eFor, scopeStartTok); } else if (tok->str() == "while") - scopeList.emplace_back(this, tok, scope, Scope::eWhile, scopeStartTok); + scopeList.emplace_back(*this, tok, scope, Scope::eWhile, scopeStartTok); else if (tok->str() == "catch") { - scopeList.emplace_back(this, tok, scope, Scope::eCatch, scopeStartTok); + scopeList.emplace_back(*this, tok, scope, Scope::eCatch, scopeStartTok); } else // if (tok->str() == "switch") - scopeList.emplace_back(this, tok, scope, Scope::eSwitch, scopeStartTok); + scopeList.emplace_back(*this, tok, scope, Scope::eSwitch, scopeStartTok); 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); // 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); // check for variable declaration and add it to new scope if found tok = tok->next(); inIfCondition.push(scopeStartTok); } else if (Token::Match(tok, "%var% {")) { @@ -747,7 +747,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } else if (!inIfCondition.empty() && tok == inIfCondition.top()) { inIfCondition.pop(); } else if (isExecutableScope(tok)) { - scopeList.emplace_back(this, tok, scope, Scope::eUnconditional, tok); + scopeList.emplace_back(*this, tok, scope, Scope::eUnconditional, tok); scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); } else { @@ -845,14 +845,14 @@ void SymbolDatabase::createSymbolDatabaseVariableInfo() // fill in variable info for (Scope& scope : scopeList) { // find variables - scope.getVariableList(mSettings); + scope.getVariableList(); } // fill in function arguments for (Scope& scope : scopeList) { for (auto func = scope.functionList.begin(); func != scope.functionList.end(); ++func) { // add arguments - func->addArguments(this, &scope); + func->addArguments(&scope); } } } @@ -1015,7 +1015,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 && mTokenizer.getSettings().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."); @@ -1364,7 +1364,7 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers() setMemberVar(membervar, membertok, tok->function()->retDef); } } - } else if (mSettings.library.detectSmartPointer(tok->function()->retDef)) { + } else if (mTokenizer.getSettings().library.detectSmartPointer(tok->function()->retDef)) { if (const Token* templateArg = Token::findsimplematch(tok->function()->retDef, "<")) { if (const Type* spType = findTypeInNested(templateArg->next(), tok->scope())) { if (spType->classScope) { @@ -1500,7 +1500,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars() fstr.insert(0, ftok->strAt(-1) + "::"); ftok = ftok->tokAt(-2); } - if (mSettings.library.functions().find(fstr) != mSettings.library.functions().end()) + if (mTokenizer.getSettings().library.functions().find(fstr) != mTokenizer.getSettings().library.functions().end()) continue; if (tok->isCpp()) { const Token* parent = tok->astParent(); @@ -1526,7 +1526,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, mTokenizer.getSettings().library, nullptr, true)); } } @@ -1800,7 +1800,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() // In template arguments, there might not be AST // Determine size by using the "raw tokens" - TokenList tokenList(&mSettings); + TokenList tokenList(&mTokenizer.getSettings()); tokenList.setLang(dimension.tok->isCpp() ? Standards::Language::CPP : Standards::Language::C); tokenList.addtoken(";", 0, 0, 0, false); bool fail = false; @@ -1851,19 +1851,19 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() std::uint8_t bits = 0; switch (dimension.tok->valueType()->type) { case ValueType::Type::CHAR: - bits = mSettings.platform.char_bit; + bits = mTokenizer.getSettings().platform.char_bit; break; case ValueType::Type::SHORT: - bits = mSettings.platform.short_bit; + bits = mTokenizer.getSettings().platform.short_bit; break; case ValueType::Type::INT: - bits = mSettings.platform.int_bit; + bits = mTokenizer.getSettings().platform.int_bit; break; case ValueType::Type::LONG: - bits = mSettings.platform.long_bit; + bits = mTokenizer.getSettings().platform.long_bit; break; case ValueType::Type::LONGLONG: - bits = mSettings.platform.long_long_bit; + bits = mTokenizer.getSettings().platform.long_long_bit; break; default: break; @@ -2105,7 +2105,7 @@ void SymbolDatabase::validateExecutableScopes() const "symbolDatabaseWarning", msg, Certainty::normal); - mErrorLogger.reportErr(errmsg); + mTokenizer.getErrorLogger().reportErr(errmsg); } } } @@ -2145,7 +2145,7 @@ void SymbolDatabase::validateVariables() const void SymbolDatabase::validate() const { - if (mSettings.debugwarnings) { + if (mTokenizer.getSettings().debugwarnings) { validateExecutableScopes(); } validateVariables(); @@ -2158,7 +2158,7 @@ void SymbolDatabase::clangSetVariables(const std::vector &vari void SymbolDatabase::debugSymbolDatabase() const { - if (!mSettings.debugnormal && !mSettings.debugwarnings) + if (!mTokenizer.getSettings().debugnormal && !mTokenizer.getSettings().debugwarnings) return; for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) { if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug()) @@ -2175,7 +2175,7 @@ void SymbolDatabase::debugSymbolDatabase() const msg += "missing"; } errorPath.emplace_back(tok, ""); - mErrorLogger.reportErr( + mTokenizer.getErrorLogger().reportErr( {errorPath, &mTokenizer.list, Severity::debug, "valueType", msg, CWE{0}, Certainty::normal}); } } @@ -2787,10 +2787,10 @@ static bool typesMatch( const Token *&new_second) { // get first type - const Type* first_type = first_scope->check->findType(first_token, first_scope, /*lookOutside*/ true); + const Type* first_type = first_scope->symdb.findType(first_token, first_scope, /*lookOutside*/ true); if (first_type) { // get second type - const Type* second_type = second_scope->check->findType(second_token, second_scope, /*lookOutside*/ true); + const Type* second_type = second_scope->symdb.findType(second_token, second_scope, /*lookOutside*/ true); // check if types match if (first_type == second_type) { const Token* tok1 = first_token; @@ -3437,7 +3437,7 @@ void SymbolDatabase::addClassFunction(Scope *&scope, const Token *&tok, const To void SymbolDatabase::addNewFunction(Scope *&scope, const Token *&tok) { const Token *tok1 = tok; - scopeList.emplace_back(this, tok1, scope); + scopeList.emplace_back(*this, tok1, scope); Scope *newScope = &scopeList.back(); // find start of function '{' @@ -3565,7 +3565,7 @@ const Token *Type::initBaseInfo(const Token *tok, const Token *tok1) } } - const Type * baseType = classScope->check->findType(base.nameTok, enclosingScope); + const Type * baseType = classScope->symdb.findType(base.nameTok, enclosingScope); if (baseType && !baseType->findDependency(this)) base.type = baseType; @@ -3604,27 +3604,27 @@ 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 && mTokenizer.getSettings().debugwarnings) { const std::list locationList(1, tok); const ErrorMessage errmsg(locationList, &mTokenizer.list, Severity::debug, type, msg, Certainty::normal); - mErrorLogger.reportErr(errmsg); + mTokenizer.getErrorLogger().reportErr(errmsg); } } void SymbolDatabase::returnImplicitIntError(const Token *tok) const { - if (tok && mSettings.severity.isEnabled(Severity::portability) && (tok->isC() && mSettings.standards.c != Standards::C89)) { + if (tok && mTokenizer.getSettings().severity.isEnabled(Severity::portability) && (tok->isC() && mTokenizer.getSettings().standards.c != Standards::C89)) { const std::list locationList(1, tok); const ErrorMessage errmsg(locationList, &mTokenizer.list, Severity::portability, "returnImplicitInt", "Omitted return type of function '" + tok->str() + "' defaults to int, this is not supported by ISO C99 and later standards.", Certainty::normal); - mErrorLogger.reportErr(errmsg); + mTokenizer.getErrorLogger().reportErr(errmsg); } } @@ -4413,9 +4413,9 @@ void SymbolDatabase::printXml(std::ostream &out) const //--------------------------------------------------------------------------- -static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase* symbolDatabase, const Scope* scope, const Token* typeTok) +static const Type* findVariableTypeIncludingUsedNamespaces(const Scope* scope, const Token* typeTok) { - const Type* argType = symbolDatabase->findVariableType(scope, typeTok); + const Type* argType = scope->symdb.findVariableType(scope, typeTok); if (argType) return argType; @@ -4423,7 +4423,7 @@ static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase* while (scope) { for (const Scope::UsingInfo &ui : scope->usingList) { if (ui.scope) { - argType = symbolDatabase->findVariableType(ui.scope, typeTok); + argType = scope->symdb.findVariableType(ui.scope, typeTok); if (argType) return argType; } @@ -4435,7 +4435,7 @@ static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase* //--------------------------------------------------------------------------- -void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope) +void Function::addArguments(const Scope *scope) { // check for non-empty argument list "( ... )" const Token * start = arg ? arg : argDef; @@ -4496,7 +4496,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); + scope->symdb.mTokenizer.syntaxError(typeTok); } if (Token::Match(typeTok, "%type% <") && Token::Match(typeTok->linkAt(1), "> :: %type%")) typeTok = typeTok->linkAt(1)->tokAt(2); @@ -4515,7 +4515,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s endTok = nameTok->previous(); if (hasBody()) - symbolDatabase->debugMessage(nameTok, "varid0", "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0."); + scope->symdb.debugMessage(nameTok, "varid0", "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0."); } else endTok = typeTok; } else @@ -4524,7 +4524,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s const ::Type *argType = nullptr; if (!typeTok->isStandardType()) { - argType = findVariableTypeIncludingUsedNamespaces(symbolDatabase, scope, typeTok); + argType = findVariableTypeIncludingUsedNamespaces(scope, typeTok); // save type const_cast(typeTok)->type(argType); @@ -4546,7 +4546,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, scope->symdb.mTokenizer.getSettings()); if (tok->str() == ")") { // check for a variadic function or a variadic template function @@ -4719,8 +4719,8 @@ const Variable* Function::getArgumentVar(nonneg int num) const //--------------------------------------------------------------------------- -Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_) : - check(check_), +Scope::Scope(const SymbolDatabase &symdb_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_) : + symdb(symdb_), classDef(classDef_), nestedIn(nestedIn_), type(type_) @@ -4728,8 +4728,8 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope * setBodyStartEnd(start_); } -Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_) : - check(check_), +Scope::Scope(const SymbolDatabase &symdb_, const Token *classDef_, const Scope *nestedIn_) : + symdb(symdb_), classDef(classDef_), nestedIn(nestedIn_) { @@ -4785,36 +4785,36 @@ AccessControl Scope::defaultAccess() const } void Scope::addVariable(const Token *token_, const Token *start_, const Token *end_, - AccessControl access_, const Type *type_, const Scope *scope_, const Settings& settings) + AccessControl access_, const Type *type_, const Scope *scope_) { // keep possible size_t -> int truncation outside emplace_back() to have a single line // C4267 VC++ warning instead of several dozens lines const int varIndex = varlist.size(); - varlist.emplace_back(token_, start_, end_, varIndex, access_, type_, scope_, settings); + varlist.emplace_back(token_, start_, end_, varIndex, access_, type_, scope_, scope_->symdb.mTokenizer.getSettings()); } // Get variable list.. -void Scope::getVariableList(const Settings& settings) +void Scope::getVariableList() { if (!bodyStartList.empty()) { for (const Token *bs: bodyStartList) - getVariableList(settings, bs->next(), bs->link()); + getVariableList(bs->next(), bs->link()); } // global scope else if (type == Scope::eGlobal) - getVariableList(settings, check->mTokenizer.tokens(), nullptr); + getVariableList(symdb.mTokenizer.tokens(), nullptr); // forward declaration else return; } -void Scope::getVariableList(const Settings& settings, const Token* start, const Token* end) +void Scope::getVariableList(const Token* start, const Token* end) { // Variable declared in condition: if (auto x = bar()) if (Token::Match(classDef, "if|while ( %type%") && Token::simpleMatch(classDef->next()->astOperand2(), "=")) { - checkVariable(classDef->tokAt(2), defaultAccess(), settings); + checkVariable(classDef->tokAt(2), defaultAccess()); } AccessControl varaccess = defaultAccess(); @@ -4911,14 +4911,14 @@ void Scope::getVariableList(const Settings& settings, const Token* start, const if (tok->str() == ";") continue; - tok = checkVariable(tok, varaccess, settings); + tok = checkVariable(tok, varaccess); if (!tok) break; } } -const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, const Settings& settings) +const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess) { // Is it a throw..? if (tok->isKeyword() && Token::Match(tok, "throw %any% (") && @@ -4948,11 +4948,11 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con const Token *typestart = tok; // C++17 structured bindings - if (tok && tok->isCpp() && (settings.standards.cpp >= Standards::CPP17) && Token::Match(tok, "auto &|&&| [")) { + if (tok && tok->isCpp() && (symdb.mTokenizer.getSettings().standards.cpp >= Standards::CPP17) && Token::Match(tok, "auto &|&&| [")) { const Token *typeend = Token::findsimplematch(typestart, "[")->previous(); for (tok = typeend->tokAt(2); Token::Match(tok, "%name%|,"); tok = tok->next()) { if (tok->varId()) - addVariable(tok, typestart, typeend, varaccess, nullptr, this, settings); + addVariable(tok, typestart, typeend, varaccess, nullptr, this); } return typeend->linkAt(1); } @@ -4973,14 +4973,14 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con if (vartok->varId() == 0) { if (!vartok->isBoolean()) - check->debugMessage(vartok, "varid0", "Scope::checkVariable found variable \'" + vartok->str() + "\' with varid 0."); + symdb.debugMessage(vartok, "varid0", "Scope::checkVariable found variable \'" + vartok->str() + "\' with varid 0."); return tok; } const Type *vType = nullptr; if (typetok) { - vType = findVariableTypeIncludingUsedNamespaces(check, this, typetok); + vType = findVariableTypeIncludingUsedNamespaces(this, typetok); const_cast(typetok)->type(vType); } @@ -4989,7 +4989,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con if (Token::Match(typestart, "enum|struct")) typestart = typestart->next(); - addVariable(vartok, typestart, vartok->previous(), varaccess, vType, this, settings); + addVariable(vartok, typestart, vartok->previous(), varaccess, vType, this); } return tok; @@ -5053,7 +5053,7 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok, if (isCPP && Token::Match(tok, "throw|new")) return false; - const bool isCPP11 = isCPP && check->mSettings.standards.cpp >= Standards::CPP11; + const bool isCPP11 = isCPP && symdb.mTokenizer.getSettings().standards.cpp >= Standards::CPP11; if (isCPP11 && tok->str() == "using") return false; @@ -6103,7 +6103,7 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const return tok1->valueType()->typeScope->findFunction(tok, tok1->valueType()->constness == 1, tok1->valueType()->reference); if (tok1 && Token::Match(tok1->previous(), "%name% (") && tok1->previous()->function() && tok1->previous()->function()->retDef) { - ValueType vt = ValueType::parseDecl(tok1->previous()->function()->retDef, mSettings); + ValueType vt = ValueType::parseDecl(tok1->previous()->function()->retDef, mTokenizer.getSettings()); if (vt.typeScope) return vt.typeScope->findFunction(tok, vt.constness == 1); } else if (Token::Match(tok1, "%var% .")) { @@ -6117,7 +6117,7 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const } else if (Token::simpleMatch(tok->previous()->astOperand1(), "(")) { const Token *castTok = tok->previous()->astOperand1(); if (castTok->isCast()) { - ValueType vt = ValueType::parseDecl(castTok->next(),mSettings); + ValueType vt = ValueType::parseDecl(castTok->next(),mTokenizer.getSettings()); if (vt.typeScope) return vt.typeScope->findFunction(tok, vt.constness == 1); } @@ -6147,7 +6147,7 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const } // Check for constructor if (Token::Match(tok, "%name% (|{")) { - ValueType vt = ValueType::parseDecl(tok, mSettings); + ValueType vt = ValueType::parseDecl(tok, mTokenizer.getSettings()); if (vt.typeScope) return vt.typeScope->findFunction(tok, false); } @@ -6543,7 +6543,7 @@ nonneg int SymbolDatabase::sizeOfType(const Token *type) const int size = mTokenizer.sizeOfType(type); if (size == 0 && type->type() && type->type()->isEnumType() && type->type()->classScope) { - size = mSettings.platform.sizeof_int; + size = mTokenizer.getSettings().platform.sizeof_int; const Token * enum_type = type->type()->classScope->enumType; if (enum_type) size = mTokenizer.sizeOfType(enum_type); @@ -6561,7 +6561,7 @@ static const Token* parsedecl(const Token* type, void SymbolDatabase::setValueType(Token* tok, const Variable& var, const SourceLocation &loc) { ValueType valuetype; - if (mSettings.debugnormal || mSettings.debugwarnings) + if (mTokenizer.getSettings().debugnormal || mTokenizer.getSettings().debugwarnings) valuetype.setDebugPath(tok, loc); if (var.nameToken()) valuetype.bits = var.nameToken()->bits(); @@ -6577,7 +6577,7 @@ void SymbolDatabase::setValueType(Token* tok, const Variable& var, const SourceL valuetype.containerTypeToken = var.valueType()->containerTypeToken; } valuetype.smartPointerType = var.smartPointerType(); - if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) { + if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mTokenizer.getSettings())) { if (tok->str() == "." && tok->astOperand1()) { const ValueType * const vt = tok->astOperand1()->valueType(); if (vt && (vt->constness & 1) != 0) { @@ -6602,7 +6602,7 @@ static ValueType::Type getEnumType(const Scope* scope, const Platform& platform) void SymbolDatabase::setValueType(Token* tok, const Enumerator& enumerator, const SourceLocation &loc) { ValueType valuetype; - if (mSettings.debugnormal || mSettings.debugwarnings) + if (mTokenizer.getSettings().debugnormal || mTokenizer.getSettings().debugwarnings) valuetype.setDebugPath(tok, loc); valuetype.typeScope = enumerator.scope; const Token * type = enumerator.scope->enumType; @@ -6611,7 +6611,7 @@ void SymbolDatabase::setValueType(Token* tok, const Enumerator& enumerator, cons if (type) { valuetype.type = ValueType::typeFromString(type->str(), type->isLong()); if (valuetype.type == ValueType::Type::UNKNOWN_TYPE) - valuetype.fromLibraryType(type->expressionString(), mSettings); + valuetype.fromLibraryType(type->expressionString(), mTokenizer.getSettings()); if (valuetype.isIntegral()) { if (type->isSigned()) @@ -6627,7 +6627,7 @@ void SymbolDatabase::setValueType(Token* tok, const Enumerator& enumerator, cons setValueType(tok, valuetype); } else { valuetype.sign = ValueType::SIGNED; - valuetype.type = getEnumType(enumerator.scope, mSettings.platform); + valuetype.type = getEnumType(enumerator.scope, mTokenizer.getSettings().platform); setValueType(tok, valuetype); } } @@ -6653,7 +6653,7 @@ static bool isContainerYieldPointer(Library::Container::Yield yield) void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const SourceLocation &loc) { auto* valuetypePtr = new ValueType(valuetype); - if (mSettings.debugnormal || mSettings.debugwarnings) + if (mTokenizer.getSettings().debugnormal || mTokenizer.getSettings().debugwarnings) valuetypePtr->setDebugPath(tok, loc); tok->setValueType(valuetypePtr); Token *parent = tok->astParent(); @@ -6686,7 +6686,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const if (vt1 && vt1->container && vt1->containerTypeToken && Token::Match(parent, ". %name% (") && isContainerYieldElement(vt1->container->getYield(parent->strAt(1)))) { ValueType item; - if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings)) { + if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mTokenizer.getSettings())) { if (item.constness == 0) item.constness = vt1->constness; if (item.volatileness == 0) @@ -6804,7 +6804,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::ITERATOR && valuetype.containerTypeToken) { ValueType vt; - if (parsedecl(valuetype.containerTypeToken, &vt, mDefaultSignedness, mSettings)) { + if (parsedecl(valuetype.containerTypeToken, &vt, mDefaultSignedness, mTokenizer.getSettings())) { if (vt.constness == 0) vt.constness = valuetype.constness; if (vt.volatileness == 0) @@ -6818,7 +6818,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::SMART_POINTER && valuetype.smartPointerTypeToken) { ValueType vt; - if (parsedecl(valuetype.smartPointerTypeToken, &vt, mDefaultSignedness, mSettings)) { + if (parsedecl(valuetype.smartPointerTypeToken, &vt, mDefaultSignedness, mTokenizer.getSettings())) { if (vt.constness == 0) vt.constness = valuetype.constness; if (vt.volatileness == 0) @@ -6940,7 +6940,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const setType = true; autovt.type = ValueType::Type::RECORD; } else if (vt2->containerTypeToken) { - if (mSettings.library.isSmartPointer(vt2->containerTypeToken)) { + if (mTokenizer.getSettings().library.isSmartPointer(vt2->containerTypeToken)) { const Token *smartPointerTypeTok = vt2->containerTypeToken; while (Token::Match(smartPointerTypeTok, "%name%|::")) smartPointerTypeTok = smartPointerTypeTok->next(); @@ -6951,7 +6951,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const autovt.type = ValueType::Type::NONSTD; } } - } else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings)) { + } else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mTokenizer.getSettings())) { setType = true; templateArgType = vt2->containerTypeToken->type(); if (Token::simpleMatch(autoToken->next(), "&")) @@ -6999,7 +6999,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const if (vt1 && vt1->containerTypeToken && parent->str() == "[") { ValueType vtParent; - if (parsedecl(vt1->containerTypeToken, &vtParent, mDefaultSignedness, mSettings)) { + if (parsedecl(vt1->containerTypeToken, &vtParent, mDefaultSignedness, mTokenizer.getSettings())) { setValueType(parent, vtParent); return; } @@ -7011,7 +7011,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const } // c++17 auto type deduction of braced init list - if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { + if (parent->isCpp() && mTokenizer.getSettings().standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { Token *autoTok = parent->tokAt(-2); setValueType(autoTok, *vt2); setAutoTokenProperties(autoTok); @@ -7274,7 +7274,7 @@ static const Token* parsedecl(const Token* type, valuetype->container = container; } else { const Scope *scope = type->scope(); - valuetype->typeScope = scope->check->findScope(typeTokens.front(), scope); + valuetype->typeScope = scope->symdb.findScope(typeTokens.front(), scope); if (valuetype->typeScope) valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD; } @@ -7484,18 +7484,18 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to pos -= 2; } else break; } - if (mSettings.platform.type != Platform::Type::Unspecified) { - if (type <= ValueType::Type::INT && mSettings.platform.isIntValue(unsignedSuffix ? (value >> 1) : value)) + if (mTokenizer.getSettings().platform.type != Platform::Type::Unspecified) { + if (type <= ValueType::Type::INT && mTokenizer.getSettings().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) && mTokenizer.getSettings().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 && mTokenizer.getSettings().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) && mTokenizer.getSettings().platform.isLongValue(value >> 2)) { type = ValueType::Type::LONG; sign = ValueType::Sign::UNSIGNED; - } else if (mSettings.platform.isLongLongValue(unsignedSuffix ? (value >> 1) : value)) + } else if (mTokenizer.getSettings().platform.isLongLongValue(unsignedSuffix ? (value >> 1) : value)) type = ValueType::Type::LONGLONG; else { type = ValueType::Type::LONGLONG; @@ -7510,7 +7510,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to const Function *function = getOperatorFunction(tok); if (function) { ValueType vt; - parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings); + parsedecl(function->retDef, &vt, mDefaultSignedness, mTokenizer.getSettings()); setValueType(tok, vt); continue; } @@ -7524,15 +7524,15 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to nonneg int const volatileness = 0; ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness, volatileness); - if (tok->isCpp() && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) { + if (tok->isCpp() && mTokenizer.getSettings().standards.cpp >= Standards::CPP20 && tok->isUtf8()) { valuetype.originalTypeName = "char8_t"; - valuetype.fromLibraryType(valuetype.originalTypeName, mSettings); + valuetype.fromLibraryType(valuetype.originalTypeName, mTokenizer.getSettings()); } else if (tok->isUtf16()) { valuetype.originalTypeName = "char16_t"; - valuetype.fromLibraryType(valuetype.originalTypeName, mSettings); + valuetype.fromLibraryType(valuetype.originalTypeName, mTokenizer.getSettings()); } else if (tok->isUtf32()) { valuetype.originalTypeName = "char32_t"; - valuetype.fromLibraryType(valuetype.originalTypeName, mSettings); + valuetype.fromLibraryType(valuetype.originalTypeName, mTokenizer.getSettings()); } else if (tok->isLong()) { valuetype.originalTypeName = "wchar_t"; valuetype.type = ValueType::Type::WCHAR_T; @@ -7546,21 +7546,21 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to // cast if (tok->isCast() && !tok->astOperand2() && Token::Match(tok, "( %name%")) { ValueType valuetype; - if (Token::simpleMatch(parsedecl(tok->next(), &valuetype, mDefaultSignedness, mSettings), ")")) + if (Token::simpleMatch(parsedecl(tok->next(), &valuetype, mDefaultSignedness, mTokenizer.getSettings()), ")")) setValueType(tok, valuetype); } // C++ cast else if (tok->astOperand2() && Token::Match(tok->astOperand1(), "static_cast|const_cast|dynamic_cast|reinterpret_cast < %name%") && tok->astOperand1()->linkAt(1)) { ValueType valuetype; - if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype, mDefaultSignedness, mSettings), ">")) + if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype, mDefaultSignedness, mTokenizer.getSettings()), ">")) setValueType(tok, valuetype); } // Construct smart pointer - else if (start && start->isCpp() && mSettings.library.isSmartPointer(start)) { + else if (start && start->isCpp() && mTokenizer.getSettings().library.isSmartPointer(start)) { ValueType valuetype; - if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings)) { + if (parsedecl(start, &valuetype, mDefaultSignedness, mTokenizer.getSettings())) { setValueType(tok, valuetype); setValueType(tok->astOperand1(), valuetype); } @@ -7570,13 +7570,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to // function or lambda else if (const Function* f = getFunction(tok->previous())) { ValueType valuetype; - if (parsedecl(f->retDef, &valuetype, mDefaultSignedness, mSettings)) + if (parsedecl(f->retDef, &valuetype, mDefaultSignedness, mTokenizer.getSettings())) setValueType(tok, valuetype); } else if (Token::simpleMatch(tok->previous(), "sizeof (")) { ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U); - if (mSettings.platform.type == Platform::Type::Win64) + if (mTokenizer.getSettings().platform.type == Platform::Type::Win64) valuetype.type = ValueType::Type::LONGLONG; valuetype.originalTypeName = "size_t"; @@ -7584,7 +7584,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to if (Token::Match(tok, "( %type% %type%| *| *| )")) { ValueType vt; - if (parsedecl(tok->next(), &vt, mDefaultSignedness, mSettings)) { + if (parsedecl(tok->next(), &vt, mDefaultSignedness, mTokenizer.getSettings())) { setValueType(tok->next(), vt); } } @@ -7593,7 +7593,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to // function style cast else if (tok->previous() && tok->previous()->isStandardType()) { ValueType valuetype; - if (tok->astOperand1() && valuetype.fromLibraryType(tok->astOperand1()->expressionString(), mSettings)) { + if (tok->astOperand1() && valuetype.fromLibraryType(tok->astOperand1()->expressionString(), mTokenizer.getSettings())) { setValueType(tok, valuetype); continue; } @@ -7626,7 +7626,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to // Aggregate constructor if (Token::Match(tok->previous(), "%name%")) { ValueType valuetype; - if (parsedecl(tok->previous(), &valuetype, mDefaultSignedness, mSettings)) { + if (parsedecl(tok->previous(), &valuetype, mDefaultSignedness, mTokenizer.getSettings())) { if (valuetype.typeScope) { setValueType(tok, valuetype); continue; @@ -7637,10 +7637,10 @@ 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 (mTokenizer.getSettings().library.detectContainerOrIterator(typeStartToken) || + mTokenizer.getSettings().library.detectSmartPointer(typeStartToken)) { ValueType vt; - if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings)) { + if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mTokenizer.getSettings())) { setValueType(tok, vt); continue; } @@ -7650,15 +7650,15 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to if ((e == "std::make_shared" || e == "std::make_unique") && Token::Match(tok->astOperand1(), ":: %name% < %name%")) { ValueType vt; - parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mSettings); + parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mTokenizer.getSettings()); if (vt.typeScope) { 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" && mTokenizer.getSettings().library.smartPointers().count("std::shared_ptr") > 0) + vt.smartPointer = &mTokenizer.getSettings().library.smartPointers().at("std::shared_ptr"); + if (e == "std::make_unique" && mTokenizer.getSettings().library.smartPointers().count("std::unique_ptr") > 0) + vt.smartPointer = &mTokenizer.getSettings().library.smartPointers().at("std::unique_ptr"); vt.type = ValueType::Type::SMART_POINTER; vt.smartPointerTypeToken = tok->astOperand1()->tokAt(3); setValueType(tok, vt); @@ -7666,20 +7666,20 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } ValueType podtype; - if (podtype.fromLibraryType(e, mSettings)) { + if (podtype.fromLibraryType(e, mTokenizer.getSettings())) { setValueType(tok, podtype); continue; } } - const std::string& typestr(mSettings.library.returnValueType(tok->previous())); + const std::string& typestr(mTokenizer.getSettings().library.returnValueType(tok->previous())); if (!typestr.empty()) { ValueType valuetype; - TokenList tokenList(&mSettings); + TokenList tokenList(&mTokenizer.getSettings()); std::istringstream istr(typestr+";"); tokenList.createTokens(istr, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C); // TODO: check result? tokenList.simplifyStdType(); - if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings)) { + if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mTokenizer.getSettings())) { valuetype.originalTypeName = typestr; setValueType(tok, valuetype); } @@ -7719,7 +7719,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to continue; } - const auto yield = astFunctionYield(tok->previous(), mSettings); + const auto yield = astFunctionYield(tok->previous(), mTokenizer.getSettings()); if (yield == Library::Container::Yield::START_ITERATOR || yield == Library::Container::Yield::END_ITERATOR || yield == Library::Container::Yield::ITERATOR) { @@ -7733,7 +7733,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 = mTokenizer.getSettings().library.getArgIteratorInfo(tok->previous(), 1); if (info && info->it) { const Token* contTok = args[0]; if (Token::simpleMatch(args[0]->astOperand1(), ".") && args[0]->astOperand1()->astOperand1()) // .begin() @@ -7765,13 +7765,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } continue; } - TokenList tokenList(&mSettings); + TokenList tokenList(&mTokenizer.getSettings()); std::istringstream istr(typestr+";"); if (tokenList.createTokens(istr, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C)) { ValueType vt; tokenList.simplifyPlatformTypes(); tokenList.simplifyStdType(); - if (parsedecl(tokenList.front(), &vt, mDefaultSignedness, mSettings)) { + if (parsedecl(tokenList.front(), &vt, mDefaultSignedness, mTokenizer.getSettings())) { vt.originalTypeName = typestr; setValueType(tok, vt); } @@ -7783,7 +7783,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to functionScope = functionScope->nestedIn; if (functionScope && functionScope->type == Scope::eFunction && functionScope->function && functionScope->function->retDef) { - ValueType vt = ValueType::parseDecl(functionScope->function->retDef, mSettings); + ValueType vt = ValueType::parseDecl(functionScope->function->retDef, mTokenizer.getSettings()); setValueType(tok, vt); if (Token::simpleMatch(tok, "return {")) setValueType(tok->next(), vt); @@ -7799,7 +7799,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 = mTokenizer.getSettings().library.detectContainerOrIterator(typeTok, &isIterator)) { ValueType vt; vt.pointer = 1; vt.container = c; @@ -7823,7 +7823,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } else { vt.type = ValueType::typeFromString(typestr, typeTok->isLong()); if (vt.type == ValueType::Type::UNKNOWN_TYPE) - vt.fromLibraryType(typestr, mSettings); + vt.fromLibraryType(typestr, mTokenizer.getSettings()); if (vt.type == ValueType::Type::UNKNOWN_TYPE) continue; if (typeTok->isUnsigned()) @@ -7844,7 +7844,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to fscope = fscope->nestedIn; if (fscope && fscope->function && fscope->function->retDef) { ValueType vt; - parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings); + parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mTokenizer.getSettings()); setValueType(tok, vt); } } else if (tok->isKeyword() && tok->str() == "this" && tok->scope()->isExecutable()) { @@ -7864,7 +7864,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } } - if (reportDebugWarnings && mSettings.debugwarnings) { + if (reportDebugWarnings && mTokenizer.getSettings().debugwarnings) { for (Token *tok = tokens; tok; tok = tok->next()) { if (tok->str() == "auto" && !tok->valueType()) { if (Token::Match(tok->next(), "%name% ; %name% = [") && isLambdaCaptureList(tok->tokAt(5))) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 24ae777c52f..f2189d6ba65 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -41,7 +41,6 @@ #include class Platform; -class ErrorLogger; class Function; class Scope; class Settings; @@ -777,7 +776,7 @@ class CPPCHECKLIB Function { nonneg int initializedArgCount() const { return initArgCount; } - void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope); + void addArguments(const Scope *scope); /** @brief check if this function is virtual in the base classes */ bool isImplicitlyVirtual(bool defaultVal = false, bool* pFoundAllBaseClasses = nullptr) const; @@ -1038,10 +1037,10 @@ class CPPCHECKLIB Scope { enum ScopeType : std::uint8_t { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch, eLambda, eEnum }; - Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_); - Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_); + Scope(const SymbolDatabase &symdb_, const Token *classDef_, const Scope *nestedIn_); + Scope(const SymbolDatabase &symdb_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_); - const SymbolDatabase* check{}; + const SymbolDatabase& symdb; std::string className; const Token* classDef{}; ///< class/struct/union/namespace token const Token* bodyStart{}; ///< '{' token @@ -1158,10 +1157,10 @@ class CPPCHECKLIB Scope { void addVariable(const Token *token_, const Token *start_, const Token *end_, AccessControl access_, const Type *type_, - const Scope *scope_, const Settings& settings); + const Scope *scope_); /** @brief initialize varlist */ - void getVariableList(const Settings& settings); + void getVariableList(); const Function *getDestructor() const; @@ -1179,10 +1178,9 @@ class CPPCHECKLIB Scope { * @brief check if statement is variable declaration and add it if it is * @param tok pointer to start of statement * @param varaccess access control of statement - * @param settings Settings * @return pointer to last token */ - const Token *checkVariable(const Token *tok, AccessControl varaccess, const Settings& settings); + const Token *checkVariable(const Token *tok, AccessControl varaccess); /** * @brief get variable from name @@ -1210,7 +1208,7 @@ class CPPCHECKLIB Scope { void findFunctionInBase(const std::string & name, nonneg int args, std::vector & matches) const; /** @brief initialize varlist */ - void getVariableList(const Settings& settings, const Token *start, const Token *end); + void getVariableList(const Token *start, const Token *end); }; /** Value type */ @@ -1328,7 +1326,7 @@ class CPPCHECKLIB ValueType { class CPPCHECKLIB SymbolDatabase { friend class TestSymbolDatabase; public: - SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger& errorLogger); + explicit SymbolDatabase(Tokenizer& tokenizer); ~SymbolDatabase(); /** @brief Information about all namespaces/classes/structures */ @@ -1478,8 +1476,6 @@ class CPPCHECKLIB SymbolDatabase { void validateVariables() const; Tokenizer& mTokenizer; - const Settings &mSettings; - ErrorLogger &mErrorLogger; /** variable symbol table */ std::vector mVariableList; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2813e357e0f..50439e01e04 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10269,7 +10269,7 @@ void Tokenizer::simplifyBorland() void Tokenizer::createSymbolDatabase() { if (!mSymbolDatabase) - mSymbolDatabase = new SymbolDatabase(*this, mSettings, mErrorLogger); + mSymbolDatabase = new SymbolDatabase(*this); mSymbolDatabase->validate(); } diff --git a/lib/tokenize.h b/lib/tokenize.h index c6a12a3cc7c..6d16b89e188 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -621,6 +621,10 @@ class CPPCHECKLIB Tokenizer { return mSettings; } + ErrorLogger &getErrorLogger() { + return mErrorLogger; + } + void calculateScopes(); /** Disable copy constructor */