| 5516 | } |
| 5517 | |
| 5518 | const 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); |