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

Method calculateScopes

lib/tokenize.cpp:4162–4251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4160}
4161
4162void Tokenizer::calculateScopes()
4163{
4164 for (auto *tok = list.front(); tok; tok = tok->next())
4165 tok->scopeInfo(nullptr);
4166
4167 std::string nextScopeNameAddition;
4168 std::shared_ptr<ScopeInfo2> primaryScope = std::make_shared<ScopeInfo2>("", nullptr);
4169 list.front()->scopeInfo(std::move(primaryScope));
4170
4171 for (Token* tok = list.front(); tok; tok = tok->next()) {
4172 if (tok == list.front() || !tok->scopeInfo()) {
4173 if (tok != list.front())
4174 tok->scopeInfo(tok->previous()->scopeInfo());
4175
4176 if (Token::Match(tok, "using namespace %name% ::|<|;")) {
4177 std::string usingNamespaceName;
4178 for (const Token* namespaceNameToken = tok->tokAt(2);
4179 namespaceNameToken && namespaceNameToken->str() != ";";
4180 namespaceNameToken = namespaceNameToken->next()) {
4181 usingNamespaceName += namespaceNameToken->str();
4182 usingNamespaceName += " ";
4183 }
4184 if (!usingNamespaceName.empty())
4185 usingNamespaceName.pop_back();
4186 tok->scopeInfo()->usingNamespaces.insert(std::move(usingNamespaceName));
4187 } else if (Token::Match(tok, "namespace|class|struct|union %name% {|::|:|<")) {
4188 for (Token* nameTok = tok->next(); nameTok && !Token::Match(nameTok, "{|:"); nameTok = nameTok->next()) {
4189 if (Token::Match(nameTok, ";|<")) {
4190 nextScopeNameAddition = "";
4191 break;
4192 }
4193 nextScopeNameAddition.append(nameTok->str());
4194 nextScopeNameAddition.append(" ");
4195 }
4196 if (!nextScopeNameAddition.empty())
4197 nextScopeNameAddition.pop_back();
4198 }
4199
4200 if (Token::simpleMatch(tok, "{")) {
4201 // This might be the opening of a member function
4202 Token *tok1 = tok;
4203 while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
4204 tok1 = tok1->previous();
4205 if (tok1->previous() && tok1->strAt(-1) == ")") {
4206 bool member = true;
4207 tok1 = tok1->linkAt(-1);
4208 if (Token::Match(tok1->previous(), "throw|noexcept")) {
4209 tok1 = tok1->previous();
4210 while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
4211 tok1 = tok1->previous();
4212 if (tok1->strAt(-1) != ")")
4213 member = false;
4214 } else if (Token::Match(tok->tokAt(-2), ":|, %name%")) {
4215 tok1 = tok1->tokAt(-2);
4216 if (tok1->strAt(-1) != ")")
4217 member = false;
4218 }
4219 if (member) {

Callers 1

simplifyTemplatesMethod · 0.80

Calls 9

frontMethod · 0.80
nextMethod · 0.80
scopeInfoMethod · 0.80
linkAtMethod · 0.80
findOpeningBracketMethod · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45
strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected