Skip to content

Commit 391411b

Browse files
committed
Scope: make sure SymbolDatabase is being provided
1 parent 29105a1 commit 391411b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/clangimport.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,13 @@ Scope *clangimport::AstNode::createScope(TokenList &tokenList, Scope::ScopeType
658658

659659
auto *nestedIn = const_cast<Scope *>(getNestedInScope(tokenList));
660660

661-
symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nestedIn);
661+
symbolDatabase->scopeList.emplace_back(nestedIn->symdb, nullptr, nestedIn);
662662
Scope *scope = &symbolDatabase->scopeList.back();
663663
if (scopeType == Scope::ScopeType::eEnum)
664664
scope->enumeratorList.reserve(children2.size());
665665
nestedIn->nestedList.push_back(scope);
666666
scope->type = scopeType;
667-
scope->classDef = def;
668-
scope->symdb = nestedIn->symdb;
667+
scope->classDef = def; // TODO: pass into ctor
669668
if (Token::Match(def, "if|for|while (")) {
670669
std::map<const Variable *, const Variable *> replaceVar;
671670
for (const Token *vartok = def->tokAt(2); vartok; vartok = vartok->next()) {
@@ -1361,11 +1360,10 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList)
13611360

13621361
Scope *scope = nullptr;
13631362
if (hasBody) {
1364-
symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nestedIn);
1363+
symbolDatabase->scopeList.emplace_back(symbolDatabase, nullptr, nestedIn);
13651364
scope = &symbolDatabase->scopeList.back();
1366-
scope->symdb = symbolDatabase;
13671365
scope->function = function;
1368-
scope->classDef = nameToken;
1366+
scope->classDef = nameToken; // TODO: pass into ctor
13691367
scope->type = Scope::ScopeType::eFunction;
13701368
scope->className = nameToken->str();
13711369
nestedIn->nestedList.push_back(scope);
@@ -1577,9 +1575,8 @@ void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f)
15771575

15781576
tokenizer.createSymbolDatabase();
15791577
auto *symbolDatabase = const_cast<SymbolDatabase *>(tokenizer.getSymbolDatabase());
1580-
symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nullptr);
1578+
symbolDatabase->scopeList.emplace_back(symbolDatabase, nullptr, nullptr);
15811579
symbolDatabase->scopeList.back().type = Scope::ScopeType::eGlobal;
1582-
symbolDatabase->scopeList.back().symdb = symbolDatabase;
15831580

15841581
clangimport::Data data;
15851582
data.mSettings = &tokenizer.getSettings();

lib/symboldatabase.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -4412,17 +4412,17 @@ void SymbolDatabase::printXml(std::ostream &out) const
44124412

44134413
//---------------------------------------------------------------------------
44144414

4415-
static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase* symbolDatabase, const Scope* scope, const Token* typeTok)
4415+
static const Type* findVariableTypeIncludingUsedNamespaces(const SymbolDatabase& symbolDatabase, const Scope* scope, const Token* typeTok)
44164416
{
4417-
const Type* argType = symbolDatabase->findVariableType(scope, typeTok);
4417+
const Type* argType = symbolDatabase.findVariableType(scope, typeTok);
44184418
if (argType)
44194419
return argType;
44204420

44214421
// look for variable type in any using namespace in this scope or above
44224422
while (scope) {
44234423
for (const Scope::UsingInfo &ui : scope->usingList) {
44244424
if (ui.scope) {
4425-
argType = symbolDatabase->findVariableType(ui.scope, typeTok);
4425+
argType = symbolDatabase.findVariableType(ui.scope, typeTok);
44264426
if (argType)
44274427
return argType;
44284428
}
@@ -4523,7 +4523,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
45234523

45244524
const ::Type *argType = nullptr;
45254525
if (!typeTok->isStandardType()) {
4526-
argType = findVariableTypeIncludingUsedNamespaces(symbolDatabase, scope, typeTok);
4526+
argType = findVariableTypeIncludingUsedNamespaces(*symbolDatabase, scope, typeTok);
45274527

45284528
// save type
45294529
const_cast<Token *>(typeTok)->type(argType);
@@ -4722,6 +4722,7 @@ Scope::Scope(const SymbolDatabase *symdb_, const Token *classDef_, const Scope *
47224722
nestedIn(nestedIn_),
47234723
type(type_)
47244724
{
4725+
assert(symdb_);
47254726
setBodyStartEnd(start_);
47264727
}
47274728

@@ -4730,6 +4731,8 @@ Scope::Scope(const SymbolDatabase *symdb_, const Token *classDef_, const Scope *
47304731
classDef(classDef_),
47314732
nestedIn(nestedIn_)
47324733
{
4734+
assert(symdb_);
4735+
47334736
const Token *nameTok = classDef;
47344737
if (!classDef) {
47354738
type = Scope::eGlobal;
@@ -4977,7 +4980,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con
49774980
const Type *vType = nullptr;
49784981

49794982
if (typetok) {
4980-
vType = findVariableTypeIncludingUsedNamespaces(symdb, this, typetok);
4983+
vType = findVariableTypeIncludingUsedNamespaces(*symdb, this, typetok);
49814984

49824985
const_cast<Token *>(typetok)->type(vType);
49834986
}

0 commit comments

Comments
 (0)