MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / createSymbolDatabaseFindAllScopes

Method createSymbolDatabaseFindAllScopes

lib/symboldatabase.cpp:146–838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146void SymbolDatabase::createSymbolDatabaseFindAllScopes()
147{
148 // create global scope
149 scopeList.emplace_back(*this, nullptr, nullptr);
150
151 // pointer to current scope
152 Scope *scope = &scopeList.back();
153
154 // Store the ending of init lists
155 std::stack<std::pair<const Token*, const Scope*>> endInitList;
156 auto inInitList = [&] {
157 if (endInitList.empty())
158 return false;
159 return endInitList.top().second == scope;
160 };
161
162 std::stack<const Token*> inIfCondition;
163 std::stack<Scope*> pendingIfScopes;
164
165 auto addLambda = [this, &scope](const Token* tok, const Token* lambdaEndToken) -> const Token* {
166 const Token* lambdaStartToken = lambdaEndToken->link();
167 const Token* argStart = lambdaStartToken->astParent();
168 const Token* funcStart = Token::simpleMatch(argStart, "[") ? argStart : argStart->astParent();
169 const Function* function = addGlobalFunction(scope, tok, argStart, funcStart);
170 if (!function)
171 mTokenizer.syntaxError(tok);
172 return lambdaStartToken;
173 };
174
175 // Store current access in each scope (depends on evaluation progress)
176 std::map<const Scope*, AccessControl> access;
177
178 std::map<Scope *, std::set<std::string>> forwardDecls;
179
180 const std::function<Scope *(const Token *, Scope *)> findForwardDeclScope = [&](const Token *tok, Scope *startScope) {
181 if (tok->str() == "::")
182 return findForwardDeclScope(tok->next(), &scopeList.front());
183
184 if (Token::Match(tok, "%name% :: %name%")) {
185 auto it = std::find_if(startScope->nestedList.cbegin(), startScope->nestedList.cend(), [&](const Scope *scope) {
186 return scope->className == tok->str();
187 });
188
189 if (it == startScope->nestedList.cend())
190 return static_cast<Scope *>(nullptr);
191
192 return findForwardDeclScope(tok->tokAt(2), *it);
193 }
194
195 auto it = forwardDecls.find(startScope);
196 if (it == forwardDecls.cend())
197 return static_cast<Scope *>(nullptr);
198
199 return it->second.count(tok->str()) > 0 ? startScope : nullptr;
200 };
201
202 ProgressReporter progressReporter(mErrorLogger, mSettings.reportProgress, mTokenizer.list.getSourceFilePath(), "SymbolDatabase (find all scopes)");
203

Callers

nothing calls this directly

Calls 15

findScopeFunction · 0.85
findTypeFunction · 0.85
succeedsFunction · 0.85
findLambdaEndTokenFunction · 0.85
isExecutableScopeFunction · 0.85
astParentMethod · 0.80
nextMethod · 0.80
frontMethod · 0.80
isCMethod · 0.80
linkAtMethod · 0.80
initBaseInfoMethod · 0.80
addEnumMethod · 0.80

Tested by

no test coverage detected