SymbolDatabase: made `mTokenizer` and `mSettings` references (#4857)

This commit is contained in:
Oliver Stöneberg 2023-03-07 12:22:06 +01:00 committed by GitHub
parent a3cacf1ba1
commit 20db3ff368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 161 deletions

View File

@ -717,7 +717,7 @@ std::vector<ValueType> getParentValueTypes(const Token* tok, const Settings* set
const ValueType* vtCont = contTok->valueType(); const ValueType* vtCont = contTok->valueType();
if (!vtCont->containerTypeToken) if (!vtCont->containerTypeToken)
return {}; 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)}; return {std::move(vtParent)};
} }
if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) { if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) {

View File

@ -2980,7 +2980,7 @@ void CheckClass::checkThisUseAfterFree()
for (const Variable &var : classScope->varlist) { for (const Variable &var : classScope->varlist) {
// Find possible "self pointer".. pointer/smartpointer member variable of "self" type. // Find possible "self pointer".. pointer/smartpointer member variable of "self" type.
if (var.valueType() && var.valueType()->smartPointerType != classScope->definedType && var.valueType()->typeScope != classScope) { 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) if (valueType.smartPointerType != classScope->definedType)
continue; continue;
} }

View File

@ -407,7 +407,7 @@ void CheckType::checkFloatToIntegerOverflow()
while (scope && scope->type != Scope::ScopeType::eLambda && scope->type != Scope::ScopeType::eFunction) while (scope && scope->type != Scope::ScopeType::eLambda && scope->type != Scope::ScopeType::eFunction)
scope = scope->nestedIn; scope = scope->nestedIn;
if (scope && scope->type == Scope::ScopeType::eFunction && scope->function && scope->function->retDef) { 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(); vtfloat = tok->astOperand1()->valueType();
checkFloatToIntegerOverflow(tok, &valueType, vtfloat, tok->astOperand1()->values()); checkFloatToIntegerOverflow(tok, &valueType, vtfloat, tok->astOperand1()->values());
} }

View File

@ -630,7 +630,7 @@ void clangimport::AstNode::setValueType(Token *tok)
if (!decl.front()) if (!decl.front())
break; 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) { if (valueType.type != ValueType::Type::UNKNOWN_TYPE) {
tok->setValueType(new ValueType(valueType)); tok->setValueType(new ValueType(valueType));
break; break;
@ -1543,7 +1543,7 @@ static void setValues(Tokenizer *tokenizer, SymbolDatabase *symbolDatabase)
for (Token *tok = const_cast<Token*>(tokenizer->tokens()); tok; tok = tok->next()) { for (Token *tok = const_cast<Token*>(tokenizer->tokens()); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "sizeof (")) { 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); const int sz = vt.typeSize(settings->platform, true);
if (sz <= 0) if (sz <= 0)
continue; continue;

View File

@ -52,17 +52,17 @@
#include <unordered_set> #include <unordered_set>
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
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) : mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger)
{ {
if (!tokenizer || !tokenizer->tokens()) if (!mTokenizer.tokens())
return; return;
mIsCpp = isCPP(); mIsCpp = isCPP();
if (mSettings->platform.defaultSign == 's' || mSettings->platform.defaultSign == 'S') if (mSettings.platform.defaultSign == 's' || mSettings.platform.defaultSign == 'S')
mDefaultSignedness = ValueType::SIGNED; 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; mDefaultSignedness = ValueType::UNSIGNED;
else else
mDefaultSignedness = ValueType::UNKNOWN_SIGN; mDefaultSignedness = ValueType::UNKNOWN_SIGN;
@ -145,24 +145,24 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
std::map<const Scope*, AccessControl> access; std::map<const Scope*, AccessControl> access;
// find all scopes // 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: // #5593 suggested to add here:
if (mErrorLogger) if (mErrorLogger)
mErrorLogger->reportProgress(mTokenizer->list.getSourceFilePath(), mErrorLogger->reportProgress(mTokenizer.list.getSourceFilePath(),
"SymbolDatabase", "SymbolDatabase",
tok->progressValue()); tok->progressValue());
// Locate next class // 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, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
!Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) || !Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) ||
(Token::Match(tok, "enum class| %name% {") || (Token::Match(tok, "enum class| %name% {") ||
Token::Match(tok, "enum class| %name% : %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); const Token *tok2 = tok->tokAt(2);
if (tok->strAt(1) == "::") if (tok->strAt(1) == "::")
tok2 = tok2->next(); tok2 = tok2->next();
else if (mTokenizer->isCPP() && tok->strAt(1) == "class") else if (mTokenizer.isCPP() && tok->strAt(1) == "class")
tok2 = tok2->next(); tok2 = tok2->next();
while (Token::Match(tok2, ":: %name%")) while (Token::Match(tok2, ":: %name%"))
@ -178,7 +178,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// skip over final // skip over final
if (mTokenizer->isCPP() && Token::simpleMatch(tok2, "final")) if (mTokenizer.isCPP() && Token::simpleMatch(tok2, "final"))
tok2 = tok2->next(); tok2 = tok2->next();
// make sure we have valid code // make sure we have valid code
@ -196,7 +196,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// skip variable declaration // skip variable declaration
else if (Token::Match(tok2, "*|&|>")) else if (Token::Match(tok2, "*|&|>"))
continue; continue;
else if (Token::Match(tok2, "%name% (") && mTokenizer->isFunctionHead(tok2->next(), "{;")) else if (Token::Match(tok2, "%name% (") && mTokenizer.isFunctionHead(tok2->next(), "{;"))
continue; continue;
else if (Token::Match(tok2, "%name% [|=")) else if (Token::Match(tok2, "%name% [|="))
continue; continue;
@ -237,7 +237,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
if (new_scope->isClassOrStruct()) { if (new_scope->isClassOrStruct()) {
// goto initial '{' // goto initial '{'
if (!new_scope->definedType) if (!new_scope->definedType)
mTokenizer->syntaxError(nullptr); // #6808 mTokenizer.syntaxError(nullptr); // #6808
tok2 = new_scope->definedType->initBaseInfo(tok, tok2); tok2 = new_scope->definedType->initBaseInfo(tok, tok2);
// make sure we have valid code // make sure we have valid code
if (!tok2) { if (!tok2) {
@ -246,7 +246,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// definition may be different than declaration // definition may be different than declaration
if (mTokenizer->isCPP() && tok->str() == "class") { if (mTokenizer.isCPP() && tok->str() == "class") {
access[new_scope] = AccessControl::Private; access[new_scope] = AccessControl::Private;
new_scope->type = Scope::eClass; new_scope->type = Scope::eClass;
} else if (tok->str() == "struct") { } else if (tok->str() == "struct") {
@ -258,7 +258,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
new_scope->setBodyStartEnd(tok2); new_scope->setBodyStartEnd(tok2);
// make sure we have valid code // make sure we have valid code
if (!new_scope->bodyEnd) { if (!new_scope->bodyEnd) {
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
scope = new_scope; scope = new_scope;
tok = tok2; tok = tok2;
@ -290,7 +290,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// make sure we have valid code // make sure we have valid code
if (!tok2) { if (!tok2) {
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
} else if (new_scope->type == Scope::eEnum) { } else if (new_scope->type == Scope::eEnum) {
if (tok2->str() == ":") if (tok2->str() == ":")
@ -301,15 +301,15 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// make sure we have valid code // make sure we have valid code
if (!new_scope->bodyEnd) { if (!new_scope->bodyEnd) {
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
if (new_scope->type == Scope::eEnum) { 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); scope->nestedList.push_back(new_scope);
if (!tok2) if (!tok2)
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} else { } else {
// make the new scope the current scope // make the new scope the current scope
scope->nestedList.push_back(new_scope); scope->nestedList.push_back(new_scope);
@ -321,7 +321,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// Namespace and unknown macro (#3854) // Namespace and unknown macro (#3854)
else if (mTokenizer->isCPP() && tok->isKeyword() && else if (mTokenizer.isCPP() && tok->isKeyword() &&
Token::Match(tok, "namespace %name% %type% (") && Token::Match(tok, "namespace %name% %type% (") &&
tok->tokAt(2)->isUpperCaseName() && tok->tokAt(2)->isUpperCaseName() &&
Token::simpleMatch(tok->linkAt(3), ") {")) { Token::simpleMatch(tok->linkAt(3), ") {")) {
@ -360,7 +360,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// using namespace // 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; Scope::UsingInfo using_info;
using_info.start = tok; // save location using_info.start = tok; // save location
@ -380,7 +380,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// using type alias // 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)) { if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) {
// fill typeList.. // fill typeList..
typeList.emplace_back(tok, nullptr, scope); typeList.emplace_back(tok, nullptr, scope);
@ -420,7 +420,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
scope->definedTypesMap[new_type->name()] = new_type; 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(); const Token *tok2 = tok->next();
@ -521,7 +521,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// class function? // class function?
else if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) { else if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) {
if (tok->previous()->str() != "::" || tok->strAt(-2) == scope->className) { 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 // save the access type
function.access = access[scope]; function.access = access[scope];
@ -537,7 +537,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
function.arg = function.argDef; function.arg = function.argDef;
// out of line function // out of line function
if (const Token *endTok = mTokenizer->isFunctionHead(end, ";")) { if (const Token *endTok = mTokenizer.isFunctionHead(end, ";")) {
tok = endTok; tok = endTok;
scope->addFunction(function); scope->addFunction(function);
} }
@ -593,7 +593,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// friend class declaration? // 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; Type::FriendInfo friendInfo;
// save the name start // save the name start
@ -612,7 +612,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
friendInfo.type = nullptr; friendInfo.type = nullptr;
if (!scope->definedType) if (!scope->definedType)
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
scope->definedType->friendList.push_back(friendInfo); scope->definedType->friendList.push_back(friendInfo);
} }
@ -642,12 +642,12 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
const Function* const function = addGlobalFunction(scope, tok, argStart, funcStart); const Function* const function = addGlobalFunction(scope, tok, argStart, funcStart);
if (!function) if (!function)
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
// syntax error? // syntax error?
if (!scope) if (!scope)
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
// function prototype? // function prototype?
else if (declEnd && declEnd->str() == ";") { else if (declEnd && declEnd->str() == ";") {
@ -704,9 +704,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
scope->nestedList.push_back(&scopeList.back()); scope->nestedList.push_back(&scopeList.back());
scope = &scopeList.back(); scope = &scopeList.back();
if (scope->type == Scope::eFor) 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) 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; tok = scopeStartTok;
} else if (Token::Match(tok, "%var% {")) { } else if (Token::Match(tok, "%var% {")) {
endInitList.emplace(tok->next()->link(), scope); endInitList.emplace(tok->next()->link(), scope);
@ -717,7 +717,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
const Token * funcStart = Token::simpleMatch(argStart, "[") ? argStart : argStart->astParent(); const Token * funcStart = Token::simpleMatch(argStart, "[") ? argStart : argStart->astParent();
const Function * function = addGlobalFunction(scope, tok, argStart, funcStart); const Function * function = addGlobalFunction(scope, tok, argStart, funcStart);
if (!function) if (!function)
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
tok = lambdaStartToken; tok = lambdaStartToken;
} else if (tok->str() == "{") { } else if (tok->str() == "{") {
if (inInitList()) { if (inInitList()) {
@ -734,17 +734,17 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} }
// syntax error? // syntax error?
if (!scope) if (!scope)
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
// End of scope or list should be handled above // End of scope or list should be handled above
if (tok->str() == "}") if (tok->str() == "}")
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
} }
} }
void SymbolDatabase::createSymbolDatabaseClassInfo() void SymbolDatabase::createSymbolDatabaseClassInfo()
{ {
if (mTokenizer->isC()) if (mTokenizer.isC())
return; return;
// fill in using info // fill in using info
@ -770,7 +770,7 @@ void SymbolDatabase::createSymbolDatabaseClassInfo()
const Type* found = findType(i.nameTok, type.enclosingScope, /*lookOutside*/ true); const Type* found = findType(i.nameTok, type.enclosingScope, /*lookOutside*/ true);
if (found && found->findDependency(&type)) { if (found && found->findDependency(&type)) {
// circular dependency // circular dependency
//mTokenizer->syntaxError(nullptr); //mTokenizer.syntaxError(nullptr);
} else { } else {
i.type = found; i.type = found;
} }
@ -791,7 +791,7 @@ void SymbolDatabase::createSymbolDatabaseVariableInfo()
// fill in variable info // fill in variable info
for (Scope& scope : scopeList) { for (Scope& scope : scopeList) {
// find variables // find variables
scope.getVariableList(mSettings); scope.getVariableList(&mSettings);
} }
// fill in function arguments // fill in function arguments
@ -874,7 +874,7 @@ void SymbolDatabase::createSymbolDatabaseFunctionReturnTypes()
void SymbolDatabase::createSymbolDatabaseNeedInitialization() 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 C code it is easy, as there are no constructors and no default values
for (const Scope& scope : scopeList) { for (const Scope& scope : scopeList) {
if (scope.definedType) if (scope.definedType)
@ -962,7 +962,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
} while (unknowns && retry < 100); } while (unknowns && retry < 100);
// this shouldn't happen so output a debug warning // this shouldn't happen so output a debug warning
if (retry == 100 && mSettings->debugwarnings) { if (retry == 100 && mSettings.debugwarnings) {
for (const Scope& scope : scopeList) { for (const Scope& scope : scopeList) {
if (scope.isClassOrStruct() && scope.definedType->needInitialization == Type::NeedInitialization::Unknown) if (scope.isClassOrStruct() && scope.definedType->needInitialization == Type::NeedInitialization::Unknown)
debugMessage(scope.classDef, "debug", "SymbolDatabase couldn't resolve all user defined types."); debugMessage(scope.classDef, "debug", "SymbolDatabase couldn't resolve all user defined types.");
@ -974,7 +974,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() void SymbolDatabase::createSymbolDatabaseVariableSymbolTable()
{ {
// create variable symbol table // create variable symbol table
mVariableList.resize(mTokenizer->varIdCount() + 1); mVariableList.resize(mTokenizer.varIdCount() + 1);
std::fill_n(mVariableList.begin(), mVariableList.size(), nullptr); std::fill_n(mVariableList.begin(), mVariableList.size(), nullptr);
// check all scopes for variables // check all scopes for variables
@ -1069,7 +1069,7 @@ void SymbolDatabase::createSymbolDatabaseSetScopePointers()
// Set scope pointers // Set scope pointers
for (const Scope& scope: scopeList) { for (const Scope& scope: scopeList) {
if (scope.type == Scope::eGlobal) if (scope.type == Scope::eGlobal)
setScopePointers(scope, mTokenizer->list.front(), mTokenizer->list.back()); setScopePointers(scope, mTokenizer.list.front(), mTokenizer.list.back());
else { else {
for (const Token *bodyStart: scope.bodyStartList) for (const Token *bodyStart: scope.bodyStartList)
setScopePointers(scope, bodyStart, bodyStart->link()); setScopePointers(scope, bodyStart, bodyStart->link());
@ -1093,7 +1093,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
} }
// Set function call pointers // 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->isName() && !tok->function() && tok->varId() == 0 && Token::Match(tok, "%name% [(,)>;]") && !isReservedName(tok->str())) {
if (tok->next()->str() == ">" && !tok->next()->link()) if (tok->next()->str() == ">" && !tok->next()->link())
continue; continue;
@ -1159,7 +1159,7 @@ void SymbolDatabase::createSymbolDatabaseSetTypePointers()
} }
// Set type pointers // 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()) if (!tok->isName() || tok->varId() || tok->function() || tok->type() || tok->enumerator())
continue; continue;
@ -1191,7 +1191,7 @@ void SymbolDatabase::fixVarId(VarIdMap & varIds, const Token * vartok, Token * m
if (varId == varIds.end()) { if (varId == varIds.end()) {
MemberIdMap memberId; MemberIdMap memberId;
if (membertok->varId() == 0) { if (membertok->varId() == 0) {
memberId[membervar->nameToken()->varId()] = const_cast<Tokenizer *>(mTokenizer)->newVarId(); memberId[membervar->nameToken()->varId()] = const_cast<Tokenizer &>(mTokenizer).newVarId();
mVariableList.push_back(membervar); mVariableList.push_back(membervar);
} else } else
mVariableList[membertok->varId()] = membervar; 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()); MemberIdMap::iterator memberId = varId->second.find(membervar->nameToken()->varId());
if (memberId == varId->second.end()) { if (memberId == varId->second.end()) {
if (membertok->varId() == 0) { if (membertok->varId() == 0) {
varId->second.insert(std::make_pair(membervar->nameToken()->varId(), const_cast<Tokenizer *>(mTokenizer)->newVarId())); varId->second.insert(std::make_pair(membervar->nameToken()->varId(), const_cast<Tokenizer &>(mTokenizer).newVarId()));
mVariableList.push_back(membervar); mVariableList.push_back(membervar);
memberId = varId->second.find(membervar->nameToken()->varId()); memberId = varId->second.find(membervar->nameToken()->varId());
} else } else
@ -1226,7 +1226,7 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers()
}; };
// Set variable pointers // 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()) if (!tok->isName() || tok->isKeyword() || tok->isStandardType())
continue; continue;
if (tok->varId()) if (tok->varId())
@ -1362,7 +1362,7 @@ void SymbolDatabase::createSymbolDatabaseEnums()
// look for initialization tokens that can be converted to enumerators and convert them // look for initialization tokens that can be converted to enumerators and convert them
if (enumerator.start) { if (enumerator.start) {
if (!enumerator.end) 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()) { for (const Token * tok3 = enumerator.start; tok3 && tok3 != enumerator.end->next(); tok3 = tok3->next()) {
if (tok3->tokType() == Token::eName) { if (tok3->tokType() == Token::eName) {
const Enumerator * e = findEnumerator(tok3, tokensThatAreNotEnumeratorValues); const Enumerator * e = findEnumerator(tok3, tokensThatAreNotEnumeratorValues);
@ -1375,7 +1375,7 @@ void SymbolDatabase::createSymbolDatabaseEnums()
} }
// find enumerators // 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()); const bool isVariable = (tok->tokType() == Token::eVariable && !tok->variable());
if (tok->tokType() != Token::eName && !isVariable) if (tok->tokType() != Token::eName && !isVariable)
continue; continue;
@ -1451,7 +1451,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
"volatile", "volatile",
"NULL", "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(); const Scope * scope = tok->scope();
if (!scope) if (!scope)
continue; continue;
@ -1483,7 +1483,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
// TODO: handle all C/C++ standards // TODO: handle all C/C++ standards
if (cppkeywords.count(tok->str()) > 0) if (cppkeywords.count(tok->str()) > 0)
continue; continue;
if (mSettings->standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0) if (mSettings.standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0)
continue; continue;
const_cast<Token *>(tok)->isIncompleteVar(true); // TODO: avoid const_cast const_cast<Token *>(tok)->isIncompleteVar(true); // TODO: avoid const_cast
} }
@ -1499,7 +1499,7 @@ void SymbolDatabase::createSymbolDatabaseEscapeFunctions()
continue; continue;
if (Token::findsimplematch(scope.bodyStart, "return", scope.bodyEnd)) if (Token::findsimplematch(scope.bodyStart, "return", scope.bodyEnd))
continue; 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 // Find incomplete vars that are used in constant context
std::unordered_map<std::string, nonneg int> unknownConstantIds; std::unordered_map<std::string, nonneg int> unknownConstantIds;
const Token* inConstExpr = nullptr; 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()) { if (Token::Match(tok, "decltype|sizeof|typeof (") && tok->next()->link()) {
tok = tok->next()->link()->previous(); tok = tok->next()->link()->previous();
} else if (tok == inConstExpr) { } else if (tok == inConstExpr) {
@ -1620,7 +1620,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
continue; continue;
if (tok1->exprId() == tok2->exprId()) if (tok1->exprId() == tok2->exprId())
continue; continue;
if (!isSameExpression(isCPP(), true, tok1, tok2, mSettings->library, false, false)) if (!isSameExpression(isCPP(), true, tok1, tok2, mSettings.library, false, false))
continue; continue;
nonneg int const cid = std::min(tok1->exprId(), tok2->exprId()); nonneg int const cid = std::min(tok1->exprId(), tok2->exprId());
tok1->exprId(cid); tok1->exprId(cid);
@ -1652,7 +1652,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
// In template arguments, there might not be AST // In template arguments, there might not be AST
// Determine size by using the "raw tokens" // Determine size by using the "raw tokens"
TokenList tokenList(mSettings); TokenList tokenList(&mSettings);
tokenList.addtoken(";", 0, 0, 0, false); tokenList.addtoken(";", 0, 0, 0, false);
bool fail = false; bool fail = false;
for (const Token *tok = dimension.tok; tok && !Token::Match(tok, "[,>]"); tok = tok->next()) { for (const Token *tok = dimension.tok; tok && !Token::Match(tok, "[,>]"); tok = tok->next()) {
@ -1702,19 +1702,19 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
int bits = 0; int bits = 0;
switch (dimension.tok->valueType()->type) { switch (dimension.tok->valueType()->type) {
case ValueType::Type::CHAR: case ValueType::Type::CHAR:
bits = mSettings->platform.char_bit; bits = mSettings.platform.char_bit;
break; break;
case ValueType::Type::SHORT: case ValueType::Type::SHORT:
bits = mSettings->platform.short_bit; bits = mSettings.platform.short_bit;
break; break;
case ValueType::Type::INT: case ValueType::Type::INT:
bits = mSettings->platform.int_bit; bits = mSettings.platform.int_bit;
break; break;
case ValueType::Type::LONG: case ValueType::Type::LONG:
bits = mSettings->platform.long_bit; bits = mSettings.platform.long_bit;
break; break;
case ValueType::Type::LONGLONG: case ValueType::Type::LONGLONG:
bits = mSettings->platform.long_long_bit; bits = mSettings.platform.long_long_bit;
break; break;
default: default:
break; break;
@ -1734,7 +1734,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
SymbolDatabase::~SymbolDatabase() SymbolDatabase::~SymbolDatabase()
{ {
// Clear scope, type, function and variable pointers // 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<Token *>(tok)->scope(nullptr); const_cast<Token *>(tok)->scope(nullptr);
const_cast<Token *>(tok)->type(nullptr); const_cast<Token *>(tok)->type(nullptr);
const_cast<Token *>(tok)->function(nullptr); const_cast<Token *>(tok)->function(nullptr);
@ -1792,7 +1792,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
const Token* tok1 = tok->previous(); const Token* tok1 = tok->previous();
const Token* tok2 = tok->next()->link()->next(); const Token* tok2 = tok->next()->link()->next();
if (!mTokenizer->isFunctionHead(tok->next(), ";:{")) if (!mTokenizer.isFunctionHead(tok->next(), ";:{"))
return false; return false;
// skip over destructor "~" // 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()) && else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) &&
Token::simpleMatch(tok->linkAt(1), ") {") && Token::simpleMatch(tok->linkAt(1), ") {") &&
(!tok->previous() || Token::Match(tok->previous(), ";|}"))) { (!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."); debugMessage(tok, "debug", "SymbolDatabase::isFunction found C function '" + tok->str() + "' without a return type.");
*funcStart = tok; *funcStart = tok;
*argStart = tok->next(); *argStart = tok->next();
*declEnd = tok->linkAt(1)->next(); *declEnd = tok->linkAt(1)->next();
return true; return true;
} }
mTokenizer->syntaxError(tok); mTokenizer.syntaxError(tok);
} }
return false; return false;
@ -1946,7 +1946,7 @@ void SymbolDatabase::validateExecutableScopes() const
if (scope->isExecutable() && !function) { if (scope->isExecutable() && !function) {
const std::list<const Token*> callstack(1, scope->classDef); const std::list<const Token*> callstack(1, scope->classDef);
const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function."; 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", "symbolDatabaseWarning",
msg, msg,
Certainty::normal); Certainty::normal);
@ -1991,7 +1991,7 @@ void SymbolDatabase::validateVariables() const
void SymbolDatabase::validate() const void SymbolDatabase::validate() const
{ {
if (mSettings->debugwarnings) { if (mSettings.debugwarnings) {
validateExecutableScopes(); validateExecutableScopes();
} }
// TODO // TODO
@ -2005,9 +2005,9 @@ void SymbolDatabase::clangSetVariables(const std::vector<const Variable *> &vari
void SymbolDatabase::debugSymbolDatabase() const void SymbolDatabase::debugSymbolDatabase() const
{ {
if (!mSettings->debugnormal && !mSettings->debugwarnings) if (!mSettings.debugnormal && !mSettings.debugwarnings)
return; 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()) if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug())
continue; continue;
if (tok->getTokenDebug() == TokenDebug::ValueType) { if (tok->getTokenDebug() == TokenDebug::ValueType) {
@ -2023,7 +2023,7 @@ void SymbolDatabase::debugSymbolDatabase() const
} }
errorPath.emplace_back(tok, ""); errorPath.emplace_back(tok, "");
mErrorLogger->reportErr( 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)); setFlag(fIsArray, arrayDimensions(settings, isContainer));
if (mTypeStartToken) if (mTypeStartToken)
setValueType(ValueType::parseDecl(mTypeStartToken,settings, true)); // TODO: set isCpp setValueType(ValueType::parseDecl(mTypeStartToken,*settings, true)); // TODO: set isCpp
const Token* tok = mTypeStartToken; const Token* tok = mTypeStartToken;
while (tok && tok->previous() && tok->previous()->isName()) 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* 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)); scope->addFunction(std::move(function));
return &scope->functionList.back(); return &scope->functionList.back();
} }
@ -3165,7 +3165,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
if (!func->hasBody()) { if (!func->hasBody()) {
const Token *closeParen = (*tok)->next()->link(); const Token *closeParen = (*tok)->next()->link();
if (closeParen) { if (closeParen) {
const Token *eq = mTokenizer->isFunctionHead(closeParen, ";"); const Token *eq = mTokenizer.isFunctionHead(closeParen, ";");
if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) { if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) {
func->isDefault(true); func->isDefault(true);
return; 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)) { if (func->argsMatch(scope1, func->argDef, (*tok)->next(), path, path_length)) {
const Token *closeParen = (*tok)->next()->link(); const Token *closeParen = (*tok)->next()->link();
if (closeParen) { if (closeParen) {
const Token *eq = mTokenizer->isFunctionHead(closeParen, ";"); const Token *eq = mTokenizer.isFunctionHead(closeParen, ";");
if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) { if (eq && Token::simpleMatch(eq->tokAt(-2), "= default ;")) {
func->isDefault(true); func->isDefault(true);
return; return;
@ -3299,7 +3299,7 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
// syntax error? // syntax error?
if (!newScope->bodyEnd) { if (!newScope->bodyEnd) {
mTokenizer->unmatchedToken(tok1); mTokenizer.unmatchedToken(tok1);
} else { } else {
(*scope)->nestedList.push_back(newScope); (*scope)->nestedList.push_back(newScope);
*scope = 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 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<const Token*> locationList(1, tok); const std::list<const Token*> locationList(1, tok);
const ErrorMessage errmsg(locationList, &mTokenizer->list, const ErrorMessage errmsg(locationList, &mTokenizer.list,
Severity::debug, Severity::debug,
type, type,
msg, msg,
@ -3608,18 +3608,18 @@ static std::string accessControlToString(const AccessControl& access)
return "Unknown"; 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; std::ostringstream oss;
if (tok) { if (tok) {
oss << tok->str() << " "; oss << tok->str() << " ";
oss << tokenizer->list.fileLine(tok) << " "; oss << tokenizer.list.fileLine(tok) << " ";
} }
oss << tok; oss << tok;
return oss.str(); 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; std::ostringstream oss;
if (scope) { if (scope) {
@ -3627,7 +3627,7 @@ static std::string scopeToString(const Scope* scope, const Tokenizer* tokenizer)
if (!scope->className.empty()) if (!scope->className.empty())
oss << scope->className << " "; oss << scope->className << " ";
if (scope->classDef) if (scope->classDef)
oss << tokenizer->list.fileLine(scope->classDef) << " "; oss << tokenizer.list.fileLine(scope->classDef) << " ";
} }
oss << scope; oss << scope;
return oss.str(); return oss.str();
@ -3696,7 +3696,7 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons
std::cout << indent << "mType: "; std::cout << indent << "mType: ";
if (var->type()) { if (var->type()) {
std::cout << var->type()->type() << " " << var->type()->name(); 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; std::cout << " " << var->type() << std::endl;
} else } else
std::cout << "none" << std::endl; std::cout << "none" << std::endl;
@ -3880,7 +3880,7 @@ void SymbolDatabase::printOut(const char *title) const
std::cout << "::" << tok1->strAt(1); std::cout << "::" << tok1->strAt(1);
tok1 = tok1->tokAt(2); 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; 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]; std::cout << "mVariableList[" << i << "]: " << mVariableList[i];
if (mVariableList[i]) { if (mVariableList[i]) {
std::cout << " " << mVariableList[i]->name() << " " std::cout << " " << mVariableList[i]->name() << " "
<< mTokenizer->list.fileLine(mVariableList[i]->nameToken()); << mTokenizer.list.fileLine(mVariableList[i]->nameToken());
} }
std::cout << std::endl; 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|::")) while (Token::Match(typeTok, "const|volatile|enum|struct|::"))
typeTok = typeTok->next(); typeTok = typeTok->next();
if (Token::Match(typeTok, ",|)")) { // #8333 if (Token::Match(typeTok, ",|)")) { // #8333
symbolDatabase->mTokenizer->syntaxError(typeTok); symbolDatabase->mTokenizer.syntaxError(typeTok);
} }
// skip over qualification // skip over qualification
while (Token::Match(typeTok, "%type% ::")) while (Token::Match(typeTok, "%type% ::"))
@ -4234,7 +4234,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
if (startTok == nameTok) if (startTok == nameTok)
break; 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() == ")") { if (tok->str() == ")") {
// check for a variadic function or a variadic template function // check for a variadic function or a variadic template function
@ -4487,7 +4487,7 @@ void Scope::getVariableList(const Settings* settings)
// global scope // global scope
else if (type == Scope::eGlobal) else if (type == Scope::eGlobal)
getVariableList(settings, check->mTokenizer->tokens(), nullptr); getVariableList(settings, check->mTokenizer.tokens(), nullptr);
// forward declaration // forward declaration
else else
@ -4730,12 +4730,12 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok,
if (!tok) if (!tok)
return false; return false;
const bool isCPP = check && check->mTokenizer->isCPP(); const bool isCPP = check && check->mTokenizer.isCPP();
if (isCPP && Token::Match(tok, "throw|new")) if (isCPP && Token::Match(tok, "throw|new"))
return false; 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") if (isCPP11 && tok->str() == "using")
return false; return false;
@ -5751,7 +5751,7 @@ const Function *Scope::getDestructor() const
bool SymbolDatabase::isCPP() 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) != "::") if (startTok->str() == startScope->className && startScope->isClassOrStruct() && startTok->strAt(1) != "::")
return startScope->definedType; return startScope->definedType;
if (mTokenizer->isC()) { if (mTokenizer.isC()) {
const Scope* scope = startScope; const Scope* scope = startScope;
while (scope) { while (scope) {
if (startTok->str() == scope->className && scope->isClassOrStruct()) 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 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) { 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; const Token * enum_type = type->type()->classScope->enumType;
if (enum_type) if (enum_type)
size = mTokenizer->sizeOfType(enum_type); size = mTokenizer.sizeOfType(enum_type);
} }
return size; return size;
@ -6033,14 +6033,14 @@ nonneg int SymbolDatabase::sizeOfType(const Token *type) const
static const Token* parsedecl(const Token* type, static const Token* parsedecl(const Token* type,
ValueType* const valuetype, ValueType* const valuetype,
ValueType::Sign defaultSignedness, ValueType::Sign defaultSignedness,
const Settings* settings, const Settings& settings,
bool isCpp, bool isCpp,
SourceLocation loc = SourceLocation::current()); SourceLocation loc = SourceLocation::current());
void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocation loc) void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocation loc)
{ {
ValueType valuetype; ValueType valuetype;
if (mSettings->debugnormal || mSettings->debugwarnings) if (mSettings.debugnormal || mSettings.debugwarnings)
valuetype.setDebugPath(tok, loc); valuetype.setDebugPath(tok, loc);
if (var.nameToken()) if (var.nameToken())
valuetype.bits = var.nameToken()->bits(); 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) void SymbolDatabase::setValueType(Token* tok, const Enumerator& enumerator, SourceLocation loc)
{ {
ValueType valuetype; ValueType valuetype;
if (mSettings->debugnormal || mSettings->debugwarnings) if (mSettings.debugnormal || mSettings.debugwarnings)
valuetype.setDebugPath(tok, loc); valuetype.setDebugPath(tok, loc);
valuetype.typeScope = enumerator.scope; valuetype.typeScope = enumerator.scope;
const Token * type = enumerator.scope->enumType; 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) void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, SourceLocation loc)
{ {
ValueType* valuetypePtr = new ValueType(valuetype); ValueType* valuetypePtr = new ValueType(valuetype);
if (mSettings->debugnormal || mSettings->debugwarnings) if (mSettings.debugnormal || mSettings.debugwarnings)
valuetypePtr->setDebugPath(tok, loc); valuetypePtr->setDebugPath(tok, loc);
tok->setValueType(valuetypePtr); tok->setValueType(valuetypePtr);
Token *parent = tok->astParent(); Token *parent = tok->astParent();
@ -6373,7 +6373,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
setType = true; setType = true;
autovt.type = ValueType::Type::RECORD; autovt.type = ValueType::Type::RECORD;
} else if (vt2->containerTypeToken) { } else if (vt2->containerTypeToken) {
if (mSettings->library.isSmartPointer(vt2->containerTypeToken)) { if (mSettings.library.isSmartPointer(vt2->containerTypeToken)) {
const Token *smartPointerTypeTok = vt2->containerTypeToken; const Token *smartPointerTypeTok = vt2->containerTypeToken;
while (Token::Match(smartPointerTypeTok, "%name%|::")) while (Token::Match(smartPointerTypeTok, "%name%|::"))
smartPointerTypeTok = smartPointerTypeTok->next(); 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 // 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); Token *autoTok = parent->tokAt(-2);
setValueType(autoTok, *vt2); setValueType(autoTok, *vt2);
setAutoTokenProperties(autoTok); setAutoTokenProperties(autoTok);
@ -6560,11 +6560,11 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
static const Token* parsedecl(const Token* type, static const Token* parsedecl(const Token* type,
ValueType* const valuetype, ValueType* const valuetype,
ValueType::Sign defaultSignedness, ValueType::Sign defaultSignedness,
const Settings* settings, const Settings& settings,
bool isCpp, bool isCpp,
SourceLocation loc) SourceLocation loc)
{ {
if (settings->debugnormal || settings->debugwarnings) if (settings.debugnormal || settings.debugwarnings)
valuetype->setDebugPath(type, loc); valuetype->setDebugPath(type, loc);
const Token * const previousType = type; const Token * const previousType = type;
const unsigned int pointer0 = valuetype->pointer; 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); parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp);
else if (Token::Match(type, "const|constexpr")) else if (Token::Match(type, "const|constexpr"))
valuetype->constness |= (1 << (valuetype->pointer - pointer0)); valuetype->constness |= (1 << (valuetype->pointer - pointer0));
else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find('<')) { else if (settings.clang && type->str().size() > 2 && type->str().find("::") < type->str().find('<')) {
TokenList typeTokens(settings); TokenList typeTokens(&settings);
std::string::size_type pos1 = 0; std::string::size_type pos1 = 0;
do { do {
const std::string::size_type pos2 = type->str().find("::", pos1); const std::string::size_type pos2 = type->str().find("::", pos1);
@ -6639,7 +6639,7 @@ static const Token* parsedecl(const Token* type,
pos1 = pos2 + 2; pos1 = pos2 + 2;
} while (pos1 < type->str().size()); } while (pos1 < type->str().size());
const Library::Container* container = const Library::Container* container =
settings->library.detectContainerOrIterator(typeTokens.front(), &isIterator); settings.library.detectContainerOrIterator(typeTokens.front(), &isIterator);
if (container) { if (container) {
if (isIterator) if (isIterator)
valuetype->type = ValueType::Type::ITERATOR; valuetype->type = ValueType::Type::ITERATOR;
@ -6652,7 +6652,7 @@ static const Token* parsedecl(const Token* type,
if (valuetype->typeScope) if (valuetype->typeScope)
valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD; 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) if (isIterator)
valuetype->type = ValueType::Type::ITERATOR; valuetype->type = ValueType::Type::ITERATOR;
else else
@ -6674,7 +6674,7 @@ static const Token* parsedecl(const Token* type,
// we are past the end of the type // we are past the end of the type
type = type->previous(); type = type->previous();
continue; 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, "<"); const Token* argTok = Token::findsimplematch(type, "<");
if (!argTok) if (!argTok)
break; break;
@ -6797,7 +6797,7 @@ static const Function *getOperatorFunction(const Token * const tok)
void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *tokens) void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *tokens)
{ {
if (!tokens) if (!tokens)
tokens = const_cast<Tokenizer *>(mTokenizer)->list.front(); tokens = const_cast<Tokenizer &>(mTokenizer).list.front();
for (Token *tok = tokens; tok; tok = tok->next()) for (Token *tok = tokens; tok; tok = tok->next())
tok->setValueType(nullptr); tok->setValueType(nullptr);
@ -6829,18 +6829,18 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
pos -= 2; pos -= 2;
} else break; } else break;
} }
if (mSettings->platform.type != cppcheck::Platform::Type::Unspecified) { if (mSettings.platform.type != cppcheck::Platform::Type::Unspecified) {
if (type <= ValueType::Type::INT && mSettings->platform.isIntValue(unsignedSuffix ? (value >> 1) : value)) if (type <= ValueType::Type::INT && mSettings.platform.isIntValue(unsignedSuffix ? (value >> 1) : value))
type = ValueType::Type::INT; 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; type = ValueType::Type::INT;
sign = ValueType::Sign::UNSIGNED; 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; 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; type = ValueType::Type::LONG;
sign = ValueType::Sign::UNSIGNED; 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; type = ValueType::Type::LONGLONG;
else { else {
type = ValueType::Type::LONGLONG; 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; nonneg int const constness = tok->tokType() == Token::eChar ? 0U : 1U;
ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness); 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.originalTypeName = "char8_t";
valuetype.fromLibraryType(valuetype.originalTypeName, mSettings); valuetype.fromLibraryType(valuetype.originalTypeName, mSettings);
} else if (tok->isUtf16()) { } else if (tok->isUtf16()) {
@ -6902,7 +6902,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
} }
// Construct smart pointer // Construct smart pointer
else if (mSettings->library.isSmartPointer(start)) { else if (mSettings.library.isSmartPointer(start)) {
ValueType valuetype; ValueType valuetype;
if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings, mIsCpp)) { if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
setValueType(tok, valuetype); setValueType(tok, valuetype);
@ -6920,7 +6920,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
else if (Token::simpleMatch(tok->previous(), "sizeof (")) { else if (Token::simpleMatch(tok->previous(), "sizeof (")) {
ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U); 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.type = ValueType::Type::LONGLONG;
valuetype.originalTypeName = "size_t"; valuetype.originalTypeName = "size_t";
@ -6981,8 +6981,8 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
const Token *typeStartToken = tok->astOperand1(); const Token *typeStartToken = tok->astOperand1();
while (typeStartToken && typeStartToken->str() == "::") while (typeStartToken && typeStartToken->str() == "::")
typeStartToken = typeStartToken->astOperand1(); typeStartToken = typeStartToken->astOperand1();
if (mSettings->library.detectContainerOrIterator(typeStartToken) || if (mSettings.library.detectContainerOrIterator(typeStartToken) ||
mSettings->library.detectSmartPointer(typeStartToken)) { mSettings.library.detectSmartPointer(typeStartToken)) {
ValueType vt; ValueType vt;
if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) { if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
setValueType(tok, vt); setValueType(tok, vt);
@ -6999,10 +6999,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
vt.smartPointerType = vt.typeScope->definedType; vt.smartPointerType = vt.typeScope->definedType;
vt.typeScope = nullptr; vt.typeScope = nullptr;
} }
if (e == "std::make_shared" && mSettings->library.smartPointers.count("std::shared_ptr") > 0) if (e == "std::make_shared" && mSettings.library.smartPointers.count("std::shared_ptr") > 0)
vt.smartPointer = &mSettings->library.smartPointers.at("std::shared_ptr"); vt.smartPointer = &mSettings.library.smartPointers.at("std::shared_ptr");
if (e == "std::make_unique" && mSettings->library.smartPointers.count("std::unique_ptr") > 0) if (e == "std::make_unique" && mSettings.library.smartPointers.count("std::unique_ptr") > 0)
vt.smartPointer = &mSettings->library.smartPointers.at("std::unique_ptr"); vt.smartPointer = &mSettings.library.smartPointers.at("std::unique_ptr");
vt.type = ValueType::Type::SMART_POINTER; vt.type = ValueType::Type::SMART_POINTER;
vt.smartPointerTypeToken = tok->astOperand1()->tokAt(3); vt.smartPointerTypeToken = tok->astOperand1()->tokAt(3);
setValueType(tok, vt); 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()) { if (!typestr.empty()) {
ValueType valuetype; ValueType valuetype;
TokenList tokenList(mSettings); TokenList tokenList(&mSettings);
std::istringstream istr(typestr+";"); std::istringstream istr(typestr+";");
tokenList.createTokens(istr); tokenList.createTokens(istr);
tokenList.simplifyStdType(); tokenList.simplifyStdType();
@ -7055,7 +7055,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
if (isReturnIter) { if (isReturnIter) {
const std::vector<const Token*> args = getArguments(tok); const std::vector<const Token*> args = getArguments(tok);
if (!args.empty()) { 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) { if (info && info->it) {
const Token* contTok = args[0]; const Token* contTok = args[0];
if (Token::simpleMatch(args[0]->astOperand1(), ".") && args[0]->astOperand1()->astOperand1()) if (Token::simpleMatch(args[0]->astOperand1(), ".") && args[0]->astOperand1()->astOperand1())
@ -7072,7 +7072,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
} }
continue; continue;
} }
TokenList tokenList(mSettings); TokenList tokenList(&mSettings);
std::istringstream istr(typestr+";"); std::istringstream istr(typestr+";");
if (tokenList.createTokens(istr)) { if (tokenList.createTokens(istr)) {
ValueType vt; ValueType vt;
@ -7106,7 +7106,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
if (Token::Match(typeTok, "( std| ::| nothrow )")) if (Token::Match(typeTok, "( std| ::| nothrow )"))
typeTok = typeTok->link()->next(); typeTok = typeTok->link()->next();
bool isIterator = false; 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; ValueType vt;
vt.pointer = 1; vt.pointer = 1;
vt.container = c; 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()) { for (Token *tok = tokens; tok; tok = tok->next()) {
if (tok->str() == "auto" && !tok->valueType()) if (tok->str() == "auto" && !tok->valueType())
debugMessage(tok, "autoNoType", "auto token with no type."); debugMessage(tok, "autoNoType", "auto token with no type.");
@ -7183,10 +7183,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
createSymbolDatabaseSetVariablePointers(); 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; 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; return vt;
} }
@ -7213,19 +7213,19 @@ ValueType::Type ValueType::typeFromString(const std::string &typestr, bool longT
return ValueType::Type::UNKNOWN_TYPE; 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 && (podtype->sign == 's' || podtype->sign == 'u')) {
if (podtype->size == 1) if (podtype->size == 1)
type = ValueType::Type::CHAR; type = ValueType::Type::CHAR;
else if (podtype->size == settings->platform.sizeof_int) else if (podtype->size == settings.platform.sizeof_int)
type = ValueType::Type::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; type = ValueType::Type::SHORT;
else if (podtype->size == settings->platform.sizeof_long) else if (podtype->size == settings.platform.sizeof_long)
type = ValueType::Type::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; type = ValueType::Type::LONGLONG;
else if (podtype->stdtype == Library::PodType::Type::BOOL) else if (podtype->stdtype == Library::PodType::Type::BOOL)
type = ValueType::Type::BOOL; type = ValueType::Type::BOOL;
@ -7249,7 +7249,7 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett
return true; 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) {
if (platformType->mType == "char") if (platformType->mType == "char")
type = ValueType::Type::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")) { } else if (!podtype && (typestr == "size_t" || typestr == "std::size_t")) {
originalTypeName = "size_t"; originalTypeName = "size_t";
sign = ValueType::UNSIGNED; 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; 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; 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; type = ValueType::Type::INT;
else else
type = ValueType::Type::UNKNOWN_INT; type = ValueType::Type::UNKNOWN_INT;

View File

@ -1325,7 +1325,7 @@ public:
debugPath() 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); static Type typeFromString(const std::string &typestr, bool longType);
@ -1345,7 +1345,7 @@ public:
return (type >= ValueType::Type::FLOAT && type <= ValueType::Type::LONGDOUBLE); 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 { bool isEnum() const {
return typeScope && typeScope->type == Scope::eEnum; return typeScope && typeScope->type == Scope::eEnum;
@ -1366,7 +1366,7 @@ public:
class CPPCHECKLIB SymbolDatabase { class CPPCHECKLIB SymbolDatabase {
friend class TestSymbolDatabase; friend class TestSymbolDatabase;
public: public:
SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); SymbolDatabase(const Tokenizer &tokenizer, const Settings &settings, ErrorLogger *errorLogger);
~SymbolDatabase(); ~SymbolDatabase();
/** @brief Information about all namespaces/classes/structures */ /** @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 Variable& var, SourceLocation loc = SourceLocation::current());
void setValueType(Token* tok, const Enumerator& enumerator, SourceLocation loc = SourceLocation::current()); void setValueType(Token* tok, const Enumerator& enumerator, SourceLocation loc = SourceLocation::current());
const Tokenizer *mTokenizer; const Tokenizer &mTokenizer;
const Settings *mSettings; const Settings &mSettings;
ErrorLogger *mErrorLogger; ErrorLogger *mErrorLogger;
/** variable symbol table */ /** variable symbol table */

View File

@ -9141,7 +9141,7 @@ void Tokenizer::simplifyBorland()
void Tokenizer::createSymbolDatabase() void Tokenizer::createSymbolDatabase()
{ {
if (!mSymbolDatabase) if (!mSymbolDatabase)
mSymbolDatabase = new SymbolDatabase(this, mSettings, mErrorLogger); mSymbolDatabase = new SymbolDatabase(*this, *mSettings, mErrorLogger);
mSymbolDatabase->validate(); mSymbolDatabase->validate();
} }

View File

@ -748,7 +748,7 @@ static void setTokenValue(Token* tok,
if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) && if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) &&
Token::simpleMatch(parent->astOperand1(), "dynamic_cast")) Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
return; 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) && if (value.isImpossible() && value.isIntValue() && value.intvalue < 0 && astIsUnsigned(tok) &&
valueType.sign == ValueType::SIGNED && tok->valueType() && valueType.sign == ValueType::SIGNED && tok->valueType() &&
ValueFlow::getSizeOf(*tok->valueType(), settings) >= ValueFlow::getSizeOf(valueType, settings)) 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) 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) if (valueType.pointer > 0)
return settings->platform.sizeof_pointer; return settings->platform.sizeof_pointer;
if (valueType.type == ValueType::Type::BOOL || valueType.type == ValueType::Type::CHAR) 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); setTokenValue(tok->next(), std::move(value), settings);
} }
} else if (!tok2->type()) { } 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); size_t sz = ValueFlow::getSizeOf(vt, settings);
const Token* brac = tok2->astParent(); const Token* brac = tok2->astParent();
while (Token::simpleMatch(brac, "[")) { while (Token::simpleMatch(brac, "[")) {
@ -4652,7 +4652,7 @@ static bool isContainerOfPointers(const Token* tok, const Settings* settings)
return true; 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; return vt.pointer > 0;
} }
@ -8275,7 +8275,7 @@ static bool valueFlowIsSameContainerType(const ValueType& contType, const Token*
if (!tok || !tok->valueType() || !tok->valueType()->containerTypeToken) if (!tok || !tok->valueType() || !tok->valueType()->containerTypeToken)
return false; 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); return contType.isTypeEqual(&tokType);
} }
@ -8295,7 +8295,7 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
if (valueType->container->stdStringLike) { if (valueType->container->stdStringLike) {
initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]); initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]);
} else if (containerTypeToken && settings) { } 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])) if (vt.pointer > 0 && astIsPointer(args[0]))
initList = true; initList = true;
else if (vt.type == ValueType::ITERATOR && astIsIterator(args[0])) 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; return false;
typeTokens.simplifyPlatformTypes(); typeTokens.simplifyPlatformTypes();
typeTokens.simplifyStdType(); 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); return getMinMaxValues(&vt, settings->platform, minvalue, maxvalue);
} }

View File

@ -7907,11 +7907,11 @@ private:
settingsWin64.library.mPodTypes["xyz::x"] = u32; settingsWin64.library.mPodTypes["xyz::x"] = u32;
settingsWin64.library.mPodTypes["podtype2"] = podtype2; settingsWin64.library.mPodTypes["podtype2"] = podtype2;
ValueType vt; ValueType vt;
ASSERT_EQUALS(true, vt.fromLibraryType("u32", &settingsWin64)); ASSERT_EQUALS(true, vt.fromLibraryType("u32", settingsWin64));
ASSERT_EQUALS(true, vt.fromLibraryType("xyz::x", &settingsWin64)); ASSERT_EQUALS(true, vt.fromLibraryType("xyz::x", settingsWin64));
ASSERT_EQUALS(ValueType::Type::INT, vt.type); ASSERT_EQUALS(ValueType::Type::INT, vt.type);
ValueType vt2; 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(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 u32[10];", "new", "test.cpp", &settingsWin64));
ASSERT_EQUALS("unsigned int *", typeOf(";void *data = new xyz::x[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"; s32.mType = "int";
settingsUnix32.library.mPlatforms[settingsUnix32.platform.toString()].mPlatformTypes["s32"] = s32; settingsUnix32.library.mPlatforms[settingsUnix32.platform.toString()].mPlatformTypes["s32"] = s32;
ValueType vt; ValueType vt;
ASSERT_EQUALS(true, vt.fromLibraryType("s32", &settingsUnix32)); ASSERT_EQUALS(true, vt.fromLibraryType("s32", settingsUnix32));
ASSERT_EQUALS(ValueType::Type::INT, vt.type); ASSERT_EQUALS(ValueType::Type::INT, vt.type);
} }
{ {
@ -7938,7 +7938,7 @@ private:
lpctstr.mType = "wchar_t"; lpctstr.mType = "wchar_t";
settingsWin64.library.mPlatforms[settingsWin64.platform.toString()].mPlatformTypes["LPCTSTR"] = lpctstr; settingsWin64.library.mPlatforms[settingsWin64.platform.toString()].mPlatformTypes["LPCTSTR"] = lpctstr;
ValueType vt; ValueType vt;
ASSERT_EQUALS(true, vt.fromLibraryType("LPCTSTR", &settingsWin64)); ASSERT_EQUALS(true, vt.fromLibraryType("LPCTSTR", settingsWin64));
ASSERT_EQUALS(ValueType::Type::WCHAR_T, vt.type); ASSERT_EQUALS(ValueType::Type::WCHAR_T, vt.type);
} }
{ {