| 5695 | //--------------------------------------------------------------------------- |
| 5696 | |
| 5697 | const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *typeTok) const |
| 5698 | { |
| 5699 | const Scope *scope = start; |
| 5700 | |
| 5701 | // check if type does not have a namespace |
| 5702 | if (typeTok->strAt(-1) != "::" && typeTok->strAt(1) != "::") { |
| 5703 | // check if type same as scope |
| 5704 | if (start->isClassOrStruct() && typeTok->str() == start->className) |
| 5705 | return start->definedType; |
| 5706 | |
| 5707 | while (scope) { |
| 5708 | // look for type in this scope |
| 5709 | const Type * type = scope->findType(typeTok->str()); |
| 5710 | |
| 5711 | if (type) |
| 5712 | return type; |
| 5713 | |
| 5714 | // look for type in base classes if possible |
| 5715 | if (scope->isClassOrStruct()) { |
| 5716 | type = findVariableTypeInBase(scope, typeTok); |
| 5717 | |
| 5718 | if (type) |
| 5719 | return type; |
| 5720 | } |
| 5721 | |
| 5722 | // check if in member function class to see if it's present in class |
| 5723 | if (scope->type == ScopeType::eFunction && scope->functionOf) { |
| 5724 | const Scope *scope1 = scope->functionOf; |
| 5725 | |
| 5726 | type = scope1->findType(typeTok->str()); |
| 5727 | |
| 5728 | if (type) |
| 5729 | return type; |
| 5730 | |
| 5731 | type = findVariableTypeInBase(scope1, typeTok); |
| 5732 | |
| 5733 | if (type) |
| 5734 | return type; |
| 5735 | } |
| 5736 | |
| 5737 | scope = scope->nestedIn; |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | // check for a qualified name and use it when given |
| 5742 | else if (typeTok->strAt(-1) == "::") { |
| 5743 | // check if type is not part of qualification |
| 5744 | if (typeTok->strAt(1) == "::") |
| 5745 | return nullptr; |
| 5746 | |
| 5747 | // find start of qualified function name |
| 5748 | const Token *tok1 = typeTok; |
| 5749 | |
| 5750 | while ((Token::Match(tok1->tokAt(-2), "%type% ::") && !tok1->tokAt(-2)->isKeyword()) || |
| 5751 | (Token::simpleMatch(tok1->tokAt(-2), "> ::") && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->tokAt(-1), "%type%"))) { |
| 5752 | if (tok1->strAt(-1) == "::") |
| 5753 | tok1 = tok1->tokAt(-2); |
| 5754 | else |
no test coverage detected