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

Method findEnumerator

lib/symboldatabase.cpp:5518–5669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5516}
5517
5518const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<std::string>& tokensThatAreNotEnumeratorValues) const
5519{
5520 if (tok->isKeyword())
5521 return nullptr;
5522
5523 const std::string& tokStr = tok->str();
5524 const Scope* scope = tok->scope();
5525
5526 // check for qualified name
5527 if (tok->strAt(-1) == "::") {
5528 // find first scope
5529 const Token *tok1 = tok;
5530 while (Token::Match(tok1->tokAt(-2), "%name% ::"))
5531 tok1 = tok1->tokAt(-2);
5532
5533 if (tok1->strAt(-1) == "::")
5534 scope = &scopeList.front();
5535 else {
5536 const Scope* temp = nullptr;
5537 if (scope)
5538 temp = scope->findRecordInNestedList(tok1->str());
5539 // find first scope
5540 while (scope && scope->nestedIn) {
5541 if (!temp)
5542 temp = scope->nestedIn->findRecordInNestedList(tok1->str());
5543 if (!temp && scope->functionOf) {
5544 temp = scope->functionOf->findRecordInNestedList(tok1->str());
5545 const Scope* nested = scope->functionOf->nestedIn;
5546 while (!temp && nested) {
5547 temp = nested->findRecordInNestedList(tok1->str());
5548 nested = nested->nestedIn;
5549 }
5550 }
5551 if (!temp)
5552 temp = findEnumScopeInBase(scope, tok1->str());
5553 if (temp) {
5554 scope = temp;
5555 break;
5556 }
5557 scope = scope->nestedIn;
5558 }
5559 }
5560
5561 if (scope) {
5562 tok1 = tok1->tokAt(2);
5563 while (scope && Token::Match(tok1, "%name% ::")) {
5564 scope = scope->findRecordInNestedList(tok1->str());
5565 tok1 = tok1->tokAt(2);
5566 }
5567
5568 if (scope) {
5569 const Enumerator * enumerator = scope->findEnumerator(tokStr);
5570
5571 if (enumerator) // enum class
5572 return enumerator;
5573 // enum
5574 for (auto it = scope->nestedList.cbegin(), end = scope->nestedList.cend(); it != end; ++it) {
5575 enumerator = (*it)->findEnumerator(tokStr);

Callers 12

enum3Method · 0.80
enum8Method · 0.80
enum9Method · 0.80
enum10Method · 0.80
enum12Method · 0.80
enum13Method · 0.80
enum14Method · 0.80
enum15Method · 0.80
enum16Method · 0.80
enum17Method · 0.80
enum18Method · 0.80

Calls 15

findEnumScopeInBaseFunction · 0.85
scopeMethod · 0.80
frontMethod · 0.80
astTopMethod · 0.80
astOperand1Method · 0.80
astParentMethod · 0.80
variableMethod · 0.80
typeMethod · 0.80
simpleMatchFunction · 0.70
isKeywordMethod · 0.45

Tested by 11

enum3Method · 0.64
enum8Method · 0.64
enum9Method · 0.64
enum10Method · 0.64
enum12Method · 0.64
enum13Method · 0.64
enum14Method · 0.64
enum15Method · 0.64
enum16Method · 0.64
enum17Method · 0.64
enum18Method · 0.64