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

Method findTypeInNested

lib/symboldatabase.cpp:6707–6758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6705//---------------------------------------------------------------------------
6706
6707const Type* SymbolDatabase::findTypeInNested(const Token *startTok, const Scope *startScope) const
6708{
6709 // skip over struct or union
6710 if (Token::Match(startTok, "struct|union|enum"))
6711 startTok = startTok->next();
6712
6713 // type same as scope
6714 if (startScope->isClassOrStruct() && startTok->str() == startScope->className && !Token::simpleMatch(startTok->next(), "::"))
6715 return startScope->definedType;
6716
6717 bool hasPath = false;
6718
6719 // absolute path - directly start in global scope
6720 if (startTok->str() == "::") {
6721 hasPath = true;
6722 startTok = startTok->next();
6723 startScope = &scopeList.front();
6724 }
6725
6726 const Token* tok = startTok;
6727 const Scope* scope = startScope;
6728
6729 while (scope && tok && tok->isName()) {
6730 if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && Token::simpleMatch(tok->linkAt(1), "> ::"))) {
6731 hasPath = true;
6732 scope = scope->findRecordInNestedList(tok->str());
6733 if (scope) {
6734 if (tok->strAt(1) == "::")
6735 tok = tok->tokAt(2);
6736 else
6737 tok = tok->linkAt(1)->tokAt(2);
6738 } else {
6739 startScope = startScope->nestedIn;
6740 if (!startScope)
6741 break;
6742 scope = startScope;
6743 tok = startTok;
6744 }
6745 } else {
6746 const Type * type = scope->findType(tok->str());
6747 if (hasPath || type)
6748 return type;
6749
6750 scope = scope->nestedIn;
6751 if (!scope)
6752 break;
6753 }
6754 }
6755
6756 // not a valid path
6757 return nullptr;
6758}
6759
6760//---------------------------------------------------------------------------
6761

Callers

nothing calls this directly

Calls 8

nextMethod · 0.80
frontMethod · 0.80
linkAtMethod · 0.80
findTypeMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45
tokAtMethod · 0.45

Tested by

no test coverage detected