Doxygen
Loading...
Searching...
No Matches
SymbolResolver::Private Struct Reference
Collaboration diagram for SymbolResolver::Private:

Public Member Functions

 Private (const FileDef *f)
void reset ()
void setFileScope (const FileDef *fileScope)
const FileDef * fileScope () const
const ClassDef * getResolvedTypeRec (LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const DString &n, const MemberDef **pTypeDef, DString *pTemplSpec, DString *pResolvedType)
const Definition * getResolvedSymbolRec (LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const DString &n, const DString &args, bool checkCV, bool insideCode, bool onlyLinkable, const MemberDef **pTypeDef, DString *pTemplSpec, DString *pResolvedType)
int isAccessibleFrom (VisitedKeys &visitedKeys, AccessStack &accessStack, const Definition *scope, const Definition *item)
int isAccessibleFromWithExpScope (VisitedKeys &visitedKeys, VisitedNamespaces &visitedNamespaces, AccessStack &accessStack, const Definition *scope, const Definition *item, const DString &explicitScopePart)

Public Attributes

DString resolvedType
const MemberDef * typeDef = nullptr
DString templateSpec

Private Member Functions

void getResolvedType (LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const Definition *d, const DString &explicitScopePart, const ArgumentList *actTemplParams, int &minDistance, const ClassDef *&bestMatch, const MemberDef *&bestTypedef, DString &bestTemplSpec, DString &bestResolvedType)
void getResolvedSymbol (VisitedKeys &visitedKeys, const Definition *scope, const Definition *d, const DString &args, bool checkCV, bool insideCode, const DString &explicitScopePart, const DString &strippedTemplateParams, bool forceCallable, int &minDistance, const Definition *&bestMatch, const MemberDef *&bestTypedef, DString &bestTemplSpec, DString &bestResolvedType)
const ClassDef * newResolveTypedef (LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const MemberDef *md, const MemberDef **pMemType, DString *pTemplSpec, DString *pResolvedType, const ArgumentList *actTemplParams=nullptr)
const Definition * followPath (VisitedKeys &visitedKeys, const Definition *start, const DString &path)
const Definition * endOfPathIsUsedClass (const LinkedRefMap< const Definition > &dl, const DString &localName)
bool accessibleViaUsingNamespace (VisitedKeys &visitedKeys, VisitedNamespaceKeys &visitedNamespaces, const LinkedRefMap< NamespaceDef > &nl, const Definition *item, const DString &explicitScopePart="", int level=0)
bool accessibleViaUsingDefinition (VisitedKeys &visitedKeys, const LinkedRefMap< const Definition > &dl, const Definition *item, const DString &explicitScopePart="")
DString substTypedef (VisitedKeys &visitedKeys, const Definition *scope, const DString &name, const MemberDef **pTypeDef=nullptr)

Private Attributes

const FileDef * m_fileScope
std::unordered_map< std::string, const MemberDef * > m_resolvedTypedefs

Detailed Description

Definition at line 194 of file symbolresolver.cpp.

Constructor & Destructor Documentation

◆ Private()

SymbolResolver::Private::Private ( const FileDef * f)
inline

Definition at line 197 of file symbolresolver.cpp.

197: m_fileScope(f) {}

References m_fileScope.

Member Function Documentation

◆ accessibleViaUsingDefinition()

bool SymbolResolver::Private::accessibleViaUsingDefinition ( VisitedKeys & visitedKeys,
const LinkedRefMap< const Definition > & dl,
const Definition * item,
const DString & explicitScopePart = "" )
private

Definition at line 1446 of file symbolresolver.cpp.

1450{
1451 AUTO_TRACE("item={} explicitScopePart={}",item?item->name():DString(), explicitScopePart);
1452 for (const auto &ud : dl)
1453 {
1454 AUTO_TRACE_ADD("trying via used definition '{}'",ud->name());
1455 const Definition *sc = explicitScopePart.empty() ? ud : followPath(visitedKeys,ud,explicitScopePart);
1456 if (sc && sc==item)
1457 {
1458 AUTO_TRACE_EXIT("true");
1459 return true;
1460 }
1461 }
1462 AUTO_TRACE_EXIT("false");
1463 return false;
1464}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
virtual const DString & name() const =0
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
const Definition * followPath(VisitedKeys &visitedKeys, const Definition *start, const DString &path)

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, DString::empty(), followPath(), and Definition::name().

Referenced by isAccessibleFrom().

◆ accessibleViaUsingNamespace()

bool SymbolResolver::Private::accessibleViaUsingNamespace ( VisitedKeys & visitedKeys,
VisitedNamespaceKeys & visitedNamespaces,
const LinkedRefMap< NamespaceDef > & nl,
const Definition * item,
const DString & explicitScopePart = "",
int level = 0 )
private

Definition at line 1408 of file symbolresolver.cpp.

1415{
1416 AUTO_TRACE("item={} explicitScopePart={} level={}",item?item->name():DString(), explicitScopePart, level);
1417 for (const auto &und : nl) // check used namespaces for the class
1418 {
1419 AUTO_TRACE_ADD("trying via used namespace '{}'",und->name());
1420 const Definition *sc = explicitScopePart.empty() ? und : followPath(visitedKeys,und,explicitScopePart);
1421 if (sc && item->getOuterScope()==sc)
1422 {
1423 AUTO_TRACE_EXIT("true");
1424 return true;
1425 }
1426 if (item->getLanguage()==SrcLangExt::Cpp)
1427 {
1428 DString key=und->qualifiedName();
1429 if (!und->getUsedNamespaces().empty() && std::find(visitedNamespaces.begin(),visitedNamespaces.end(),key.str())==std::end(visitedNamespaces))
1430 {
1431 visitedNamespaces.push_back(key.str());
1432 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaces,und->getUsedNamespaces(),item,explicitScopePart,level+1))
1433 {
1434 AUTO_TRACE_EXIT("true");
1435 return true;
1436 }
1437
1438 }
1439 }
1440 }
1441 AUTO_TRACE_EXIT("false");
1442 return false;
1443}
const std::string & str() const
Definition dstring.h:645
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual Definition * getOuterScope() const =0
bool accessibleViaUsingNamespace(VisitedKeys &visitedKeys, VisitedNamespaceKeys &visitedNamespaces, const LinkedRefMap< NamespaceDef > &nl, const Definition *item, const DString &explicitScopePart="", int level=0)

References accessibleViaUsingNamespace(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, DString::empty(), followPath(), Definition::getLanguage(), Definition::getOuterScope(), Definition::name(), and DString::str().

Referenced by accessibleViaUsingNamespace(), isAccessibleFrom(), and isAccessibleFromWithExpScope().

◆ endOfPathIsUsedClass()

const Definition * SymbolResolver::Private::endOfPathIsUsedClass ( const LinkedRefMap< const Definition > & dl,
const DString & localName )
private

Definition at line 1396 of file symbolresolver.cpp.

1397{
1398 for (const auto &d : dl)
1399 {
1400 if (d->localName()==localName)
1401 {
1402 return d;
1403 }
1404 }
1405 return nullptr;
1406}

Referenced by followPath().

◆ fileScope()

const FileDef * SymbolResolver::Private::fileScope ( ) const
inline

Definition at line 209 of file symbolresolver.cpp.

209{ return m_fileScope; }

References m_fileScope.

Referenced by setFileScope().

◆ followPath()

const Definition * SymbolResolver::Private::followPath ( VisitedKeys & visitedKeys,
const Definition * start,
const DString & path )
private

Definition at line 1291 of file symbolresolver.cpp.

1293{
1294 AUTO_TRACE("start={},path={}",start?start->name():DString(), path);
1295 int is=0,ps=0,l=0;
1296
1297 const Definition *current=start;
1298 // for each part of the explicit scope
1299 while ((is=getScopeFragment(path,ps,&l))!=-1)
1300 {
1301 // try to resolve the part if it is a typedef
1302 const MemberDef *memTypeDef=nullptr;
1303 DString qualScopePart = substTypedef(visitedKeys,current,path.mid(is,l),&memTypeDef);
1304 AUTO_TRACE_ADD("qualScopePart={} memTypeDef={}",qualScopePart,memTypeDef?memTypeDef->name():"");
1305 const Definition *next = nullptr;
1306 if (memTypeDef)
1307 {
1308 const ClassDef *type = newResolveTypedef(getTypeLookupCache(),visitedKeys,m_fileScope,memTypeDef,nullptr,nullptr,nullptr);
1309 if (type)
1310 {
1311 AUTO_TRACE_EXIT("type={}",type->name());
1312 return type;
1313 }
1314 }
1315 else if (m_fileScope)
1316 {
1317 next = endOfPathIsUsedClass(m_fileScope->getUsedDefinitions(),qualScopePart);
1318 }
1319 if (next==nullptr)
1320 {
1321 next = current->findInnerCompound(qualScopePart);
1322 }
1323 AUTO_TRACE_ADD("Looking for {} inside {} result={}",
1324 qualScopePart, current->name(), next?next->name():DString());
1325 if (next==nullptr)
1326 {
1327 next = current->findInnerCompound(qualScopePart+"-p");
1328 }
1329 if (current->definitionType()==Definition::TypeClass)
1330 {
1331 const MemberDef *classMember = toClassDef(current)->getMemberByName(qualScopePart);
1332 if (classMember && classMember->isEnumerate())
1333 {
1334 next = classMember;
1335 }
1336 }
1337 else if (current!=Doxygen::globalScope && current->definitionType()==Definition::TypeNamespace)
1338 {
1339 const MemberDef *namespaceMember = toNamespaceDef(current)->getMemberByName(qualScopePart);
1340 if (namespaceMember && namespaceMember->isEnumerate())
1341 {
1342 next = namespaceMember;
1343 }
1344 }
1345 else if (current==Doxygen::globalScope || current->definitionType()==Definition::TypeFile)
1346 {
1347 auto &range = Doxygen::symbolMap->find(qualScopePart);
1348 for (Definition *def : range)
1349 {
1350 const Definition *outerScope = def->getOuterScope();
1351 if (
1352 (outerScope==Doxygen::globalScope || // global scope or
1353 (outerScope && // anonymous namespace in the global scope
1354 outerScope->name().startsWith("anonymous_namespace{") &&
1355 outerScope->getOuterScope()==Doxygen::globalScope
1356 )
1357 ) &&
1358 (def->definitionType()==Definition::TypeClass ||
1359 def->definitionType()==Definition::TypeMember ||
1360 def->definitionType()==Definition::TypeNamespace
1361 )
1362 )
1363 {
1364 next=def;
1365 break;
1366 }
1367 }
1368 }
1369 if (next==nullptr) // failed to follow the path
1370 {
1372 {
1373 next = endOfPathIsUsedClass(
1374 (toNamespaceDef(current))->getUsedDefinitions(),qualScopePart);
1375 }
1376 else if (current->definitionType()==Definition::TypeFile)
1377 {
1378 next = endOfPathIsUsedClass(
1379 (toFileDef(current))->getUsedDefinitions(),qualScopePart);
1380 }
1381 current = next;
1382 if (current==nullptr) break;
1383 }
1384 else // continue to follow scope
1385 {
1386 current = next;
1387 AUTO_TRACE_ADD("current={}",current->name());
1388 }
1389 ps=is+l;
1390 }
1391
1392 AUTO_TRACE_EXIT("result={}",current?current->name():DString());
1393 return current; // path could be followed
1394}
virtual const MemberDef * getMemberByName(const DString &) const =0
Returns the member with the given name.
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
bool startsWith(const char *s) const
Definition dstring.h:600
virtual DefType definitionType() const =0
virtual const Definition * findInnerCompound(const DString &name) const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
static SymbolMap< Definition > * symbolMap
Definition doxygen.h:118
virtual const LinkedRefMap< const Definition > & getUsedDefinitions() const =0
virtual bool isEnumerate() const =0
virtual const MemberDef * getMemberByName(const DString &) const =0
const VectorPtr & find(const DString &name)
Definition symbolmap.h:74
ClassDef * toClassDef(Definition *d)
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:2054
NamespaceDef * toNamespaceDef(Definition *d)
const ClassDef * newResolveTypedef(LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const MemberDef *md, const MemberDef **pMemType, DString *pTemplSpec, DString *pResolvedType, const ArgumentList *actTemplParams=nullptr)
const Definition * endOfPathIsUsedClass(const LinkedRefMap< const Definition > &dl, const DString &localName)
DString substTypedef(VisitedKeys &visitedKeys, const Definition *scope, const DString &name, const MemberDef **pTypeDef=nullptr)
static LookupCache & getTypeLookupCache()
int getScopeFragment(const DString &s, int p, int *l)
Definition util.cpp:3930

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, Definition::definitionType(), endOfPathIsUsedClass(), SymbolMap< T >::find(), Definition::findInnerCompound(), ClassDef::getMemberByName(), NamespaceDef::getMemberByName(), Definition::getOuterScope(), getScopeFragment(), getTypeLookupCache(), Doxygen::globalScope, MemberDef::isEnumerate(), m_fileScope, DString::mid(), Definition::name(), newResolveTypedef(), DString::startsWith(), substTypedef(), Doxygen::symbolMap, toClassDef(), toFileDef(), toNamespaceDef(), Definition::TypeClass, Definition::TypeFile, Definition::TypeMember, and Definition::TypeNamespace.

Referenced by accessibleViaUsingDefinition(), accessibleViaUsingNamespace(), and isAccessibleFromWithExpScope().

◆ getResolvedSymbol()

void SymbolResolver::Private::getResolvedSymbol ( VisitedKeys & visitedKeys,
const Definition * scope,
const Definition * d,
const DString & args,
bool checkCV,
bool insideCode,
const DString & explicitScopePart,
const DString & strippedTemplateParams,
bool forceCallable,
int & minDistance,
const Definition *& bestMatch,
const MemberDef *& bestTypedef,
DString & bestTemplSpec,
DString & bestResolvedType )
private

Definition at line 858 of file symbolresolver.cpp.

874{
875 AUTO_TRACE("scope={} sym={}",scope->name(),d->qualifiedName());
876 // only look at classes and members that are enums or typedefs
877 VisitedNamespaces visitedNamespaces;
878 AccessStack accessStack;
879 // test accessibility of definition within scope.
880 int distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,d,explicitScopePart+strippedTemplateParams);
881 if (distance==-1 && !strippedTemplateParams.empty())
882 {
883 distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,d,explicitScopePart);
884 }
885 AUTO_TRACE_ADD("distance={}",distance);
886 if (distance!=-1) // definition is accessible
887 {
888 // see if we are dealing with a class or a typedef
889 if (args.empty() && !forceCallable && d->definitionType()==Definition::TypeClass) // d is a class
890 {
891 const ClassDef *cd = toClassDef(d);
892 if (!cd->isTemplateArgument()) // skip classes that
893 // are only there to
894 // represent a template
895 // argument
896 {
897 if (distance<minDistance) // found a definition that is "closer"
898 {
899 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",d->name(),distance,minDistance);
900 minDistance=distance;
901 bestMatch = d;
902 bestTypedef = nullptr;
903 bestTemplSpec.clear();
904 bestResolvedType = cd->qualifiedName();
905 }
906 else if (distance==minDistance &&
907 m_fileScope && bestMatch &&
911 )
912 {
913 // in case the distance is equal it could be that a class X
914 // is defined in a namespace and in the global scope. When searched
915 // in the global scope the distance is 0 in both cases. We have
916 // to choose one of the definitions: we choose the one in the
917 // namespace if the fileScope imports namespaces and the definition
918 // found was in a namespace while the best match so far isn't.
919 // Just a non-perfect heuristic but it could help in some situations
920 // (kdecore code is an example).
921 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",d->name(),distance,minDistance);
922 minDistance=distance;
923 bestMatch = d;
924 bestTypedef = nullptr;
925 bestTemplSpec.clear();
926 bestResolvedType = cd->qualifiedName();
927 }
928 }
929 else
930 {
931 AUTO_TRACE_ADD("class with template arguments");
932 }
933 }
935 {
936 const MemberDef *md = toMemberDef(d);
937
938 bool match = true;
939 AUTO_TRACE_ADD("member={} args={} isCallable()={}",md->name(),argListToString(md->argumentList()),md->isCallable());
940 if (md->isCallable() && !args.empty())
941 {
942 DString actArgs;
943 if (md->isArtificial() && md->formalTemplateArguments()) // for members of an instantiated template we need to replace
944 // the formal arguments by the actual ones before matching
945 // See issue #10640
946 {
948 }
949 else
950 {
951 actArgs = args;
952 }
953 std::unique_ptr<ArgumentList> argList = stringToArgumentList(md->getLanguage(),actArgs);
954 const ArgumentList &mdAl = md->argumentList();
955 match = matchArguments2(md->getOuterScope(),md->getFileDef(),md->typeString(),&mdAl,
956 scope, md->getFileDef(),md->typeString(),argList.get(),
957 checkCV,md->getLanguage());
958 AUTO_TRACE_ADD("match={}",match);
959 }
960
961 if (match && distance<minDistance)
962 {
963 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",md->name(),distance,minDistance);
964 minDistance=distance;
965 bestMatch = md;
966 bestTypedef = md;
967 bestTemplSpec = "";
968 bestResolvedType = md->qualifiedName();
969 }
970 }
974 {
975 if (distance<minDistance) // found a definition that is "closer"
976 {
977 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",d->name(),distance,minDistance);
978 minDistance=distance;
979 bestMatch = d;
980 bestTypedef = nullptr;
981 bestTemplSpec.clear();
982 bestResolvedType.clear();
983 }
984 }
985 } // if definition accessible
986 else
987 {
988 AUTO_TRACE_ADD("not accessible");
989 }
990 AUTO_TRACE_EXIT("bestMatch sym={} distance={}",
991 bestMatch?bestMatch->name():DString("<none>"),bestResolvedType);
992}
virtual bool isTemplateArgument() const =0
void clear()
Definition dstring.h:214
virtual DString qualifiedName() const =0
virtual bool isArtificial() const =0
virtual const LinkedRefMap< NamespaceDef > & getUsedNamespaces() const =0
bool empty() const
Definition linkedmap.h:374
virtual const FileDef * getFileDef() const =0
virtual const ArgumentList & argumentList() const =0
virtual std::optional< ArgumentList > formalTemplateArguments() const =0
virtual DString typeString() const =0
virtual bool isCallable() const =0
std::unique_ptr< ArgumentList > stringToArgumentList(SrcLangExt lang, const DString &argsString, DString *extraTypeChars=nullptr)
Definition defargs.l:822
MemberDef * toMemberDef(Definition *d)
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:861
int isAccessibleFromWithExpScope(VisitedKeys &visitedKeys, VisitedNamespaces &visitedNamespaces, AccessStack &accessStack, const Definition *scope, const Definition *item, const DString &explicitScopePart)
std::unordered_map< std::string, const Definition * > VisitedNamespaces
DString substituteTemplateArgumentsInString(const DString &nm, const ArgumentList &formalArgs, const ArgumentList *actualArgs)
Definition util.cpp:3656
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:864
bool matchArguments2(const Definition *srcScope, const FileDef *srcFileScope, const DString &srcReturnType, const ArgumentList *srcAl, const Definition *dstScope, const FileDef *dstFileScope, const DString &dstReturnType, const ArgumentList *dstAl, bool checkCV, SrcLangExt lang, bool allowUnresolved)
Definition util.cpp:1649

References argListToString(), MemberDef::argumentList(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, DString::clear(), Definition::definitionType(), DString::empty(), MemberDef::formalTemplateArguments(), MemberDef::getFileDef(), Definition::getLanguage(), Definition::getOuterScope(), Doxygen::globalScope, SymbolResolver::isAccessibleFromWithExpScope(), Definition::isArtificial(), MemberDef::isCallable(), ClassDef::isTemplateArgument(), m_fileScope, matchArguments2(), Definition::name(), Definition::qualifiedName(), stringToArgumentList(), substituteTemplateArgumentsInString(), toClassDef(), toMemberDef(), Definition::TypeClass, Definition::TypeFile, Definition::TypeMember, Definition::TypeModule, Definition::TypeNamespace, and MemberDef::typeString().

Referenced by getResolvedSymbolRec().

◆ getResolvedSymbolRec()

const Definition * SymbolResolver::Private::getResolvedSymbolRec ( LookupCache & cache,
VisitedKeys & visitedKeys,
const Definition * scope,
const DString & n,
const DString & args,
bool checkCV,
bool insideCode,
bool onlyLinkable,
const MemberDef ** pTypeDef,
DString * pTemplSpec,
DString * pResolvedType )

Definition at line 470 of file symbolresolver.cpp.

482{
483 AUTO_TRACE("scope={} name={} args={} checkCV={} insideCode={}",
484 scope->name(),n,args,checkCV,insideCode);
485 if (n.empty()) return nullptr;
486 DString explicitScopePart;
487 DString strippedTemplateParams;
488 DString scopeName=scope!=Doxygen::globalScope ? scope->name() : DString();
489 DString name=stripTemplateSpecifiersFromScope(n,true,&strippedTemplateParams,scopeName);
490 std::unique_ptr<ArgumentList> actTemplParams;
491 if (!strippedTemplateParams.empty()) // template part that was stripped
492 {
493 actTemplParams = stringToArgumentList(scope->getLanguage(),strippedTemplateParams);
494 }
495
496 int qualifierIndex = computeQualifiedIndex(name);
497 //printf("name=%s qualifierIndex=%d\n",qPrint(name),qualifierIndex);
498 if (qualifierIndex!=-1) // qualified name
499 {
500 // split off the explicit scope part
501 explicitScopePart=name.left(qualifierIndex);
502 // todo: improve namespace alias substitution
503 replaceNamespaceAliases(explicitScopePart);
504 name=name.mid(qualifierIndex+2);
505 }
506 AUTO_TRACE_ADD("qualifierIndex={} name={} explicitScopePart={} strippedTemplateParams={}",
507 qualifierIndex,name,explicitScopePart,strippedTemplateParams);
508
509 if (name.empty())
510 {
511 AUTO_TRACE_EXIT("empty name qualifierIndex={}",qualifierIndex);
512 return nullptr; // empty name
513 }
514
515 size_t i=0;
516 const auto &range1 = Doxygen::symbolMap->find(name);
517 const auto &range = (range1.empty() && (i=name.find('<'))!=DString::npos) ?
518 Doxygen::symbolMap->find(name.left(i)) : range1;
519 if (range.empty())
520 {
521 AUTO_TRACE_ADD("no symbols with name '{}' (including unspecialized)",name);
522 return nullptr;
523 }
524 AUTO_TRACE_ADD("{} -> {} candidates",name,range.size());
525
526 bool hasUsingStatements =
527 (m_fileScope && (!m_fileScope->getUsedNamespaces().empty() ||
529 );
530 // Since it is often the case that the same name is searched in the same
531 // scope over an over again (especially for the linked source code generation)
532 // we use a cache to collect previous results. This is possible since the
533 // result of a lookup is deterministic. As the key we use the concatenated
534 // scope, the name to search for and the explicit scope prefix. The speedup
535 // achieved by this simple cache can be enormous.
536 size_t scopeNameLen = scope!=Doxygen::globalScope ? scope->name().length()+1 : 0;
537 size_t nameLen = name.length()+1;
538 size_t explicitPartLen = explicitScopePart.length();
539 size_t strippedTemplateParamsLen = strippedTemplateParams.length();
540 bool resultDependsOnFileScope = hasUsingStatements ||
541 (m_fileScope && std::any_of(range.begin(),range.end(),isFileLocalStatic));
542 size_t fileScopeLen = resultDependsOnFileScope ? 1+m_fileScope->absFilePath().length() : 0;
543 size_t argsLen = args.length()+1;
544
545 // below is a more efficient coding of
546 // DString key=scope->name()+"+"+name+"+"+explicitScopePart+args+typesOnly?'T':'F';
547 std::string key;
548 key.reserve(scopeNameLen+nameLen+explicitPartLen+strippedTemplateParamsLen+fileScopeLen+argsLen);
549 if (scope!=Doxygen::globalScope)
550 {
551 key+=scope->name().str();
552 key+='+';
553 }
554 key+=name.str();
555 key+='+';
556 key+=explicitScopePart.str();
557 key+=strippedTemplateParams.str();
558
559 // if a file scope is given and the result can depend on it we should
560 // also use the file part in the key:
561 // - a class name can be in two different namespaces and a using
562 // statement in a file can select one of them.
563 // - skipDefinition() only accepts a file-local static from the file scope.
564 if (resultDependsOnFileScope)
565 {
566 // below is a more efficient coding of
567 // key+="+"+m_fileScope->name();
568 key+='+';
569 key+=m_fileScope->absFilePath().str();
570 }
571 if (argsLen>0)
572 {
573 key+='+';
574 key+=args.str();
575 }
576
577 const Definition *bestMatch=nullptr;
578 {
579 if (std::find(visitedKeys.begin(),visitedKeys.end(),key)!=std::end(visitedKeys))
580 {
581 // we are already in the middle of find the definition for this key.
582 // avoid recursion
583 return nullptr;
584 }
585 // remember the key
586 visitedKeys.push_back(key);
587 LookupInfo *pval = cache.find(key);
588 AUTO_TRACE_ADD("key={} found={}",key,pval!=nullptr);
589 if (pval)
590 {
591 if (pTemplSpec) *pTemplSpec=pval->templSpec;
592 if (pTypeDef) *pTypeDef=pval->typeDef;
593 if (pResolvedType) *pResolvedType=pval->resolvedType;
594 AUTO_TRACE_EXIT("found cached name={} templSpec={} typeDef={} resolvedTypedef={}",
595 pval->definition?pval->definition->name():DString(),
596 pval->templSpec,
597 pval->typeDef?pval->typeDef->name():DString(),
598 pval->resolvedType);
599 return pval->definition;
600 }
601
602 const MemberDef *bestTypedef=nullptr;
603 DString bestTemplSpec;
604 DString bestResolvedType;
605 int minDistance=10000; // init at "infinite"
606
607 // helper to skip symbol definitions that should not be considered for lookup
608 auto skipDefinition = [this,&explicitScopePart](const Definition *d) -> bool {
609 if (d->definitionType()==Definition::TypeMember)
610 {
611 const MemberDef *emd = dynamic_cast<const MemberDef *>(d);
612 if (emd &&
613 emd->isEnumValue() &&
614 emd->getEnumScope() &&
615 emd->getEnumScope()->isStrong() &&
616 explicitScopePart.empty())
617 {
618 // skip lookup for strong enum values without explicit scope, see issue #11799
619 return true;
620 }
621 if (emd &&
622 isFileLocalStatic(emd) &&
623 emd->getFileDef()!=m_fileScope) // defined in a different file
624 {
625 // skip lookup for static members that are not in the current file scope
626 return true;
627 }
628 }
629 return false;
630 };
631
632 for (Definition *d : range)
633 {
634 if (isCodeSymbol(d->definitionType()) &&
635 (!onlyLinkable ||
636 d->isLinkable() ||
637 d->isLinkableInProject() ||
638 (d->definitionType()==Definition::TypeFile &&
639 (toFileDef(d))->generateSourceFile()
640 ) // undocumented file that has source code we can link to
641 )
642 )
643 {
644 if (skipDefinition(d)) continue;
645 getResolvedSymbol(visitedKeys,scope,d,args,checkCV,insideCode,explicitScopePart,strippedTemplateParams,false,
646 minDistance,bestMatch,bestTypedef,bestTemplSpec,bestResolvedType);
647 }
648 if (minDistance==0) break; // we can stop reaching if we already reached distance 0
649 }
650
651 // in case we are looking for e.g. func() and the real function is func(int x) we also
652 // accept func(), see example 036 in the test set.
653 if (bestMatch==nullptr && args=="()")
654 {
655 for (Definition *d : range)
656 {
657 if (isCodeSymbol(d->definitionType()))
658 {
659 if (skipDefinition(d)) continue;
660 getResolvedSymbol(visitedKeys,scope,d,DString(),false,insideCode,explicitScopePart,strippedTemplateParams,true,
661 minDistance,bestMatch,bestTypedef,bestTemplSpec,bestResolvedType);
662 }
663 if (minDistance==0) break; // we can stop reaching if we already reached distance 0
664 }
665 }
666
667 if (pTypeDef)
668 {
669 *pTypeDef = bestTypedef;
670 }
671 if (pTemplSpec)
672 {
673 *pTemplSpec = bestTemplSpec;
674 }
675 if (pResolvedType)
676 {
677 *pResolvedType = bestResolvedType;
678 }
679
680 cache.insert(key,LookupInfo(bestMatch,bestTypedef,bestTemplSpec,bestResolvedType));
681 visitedKeys.erase(std::remove(visitedKeys.begin(),visitedKeys.end(),key),visitedKeys.end());
682
683 AUTO_TRACE_EXIT("found name={} templSpec={} typeDef={} resolvedTypedef={}",
684 bestMatch?bestMatch->name():DString(),
685 bestTemplSpec,
686 bestTypedef?bestTypedef->name():DString(),
687 bestResolvedType);
688 }
689 return bestMatch;
690}
V * insert(const K &key, V &&value)
Inserts value under key in the cache.
Definition cache.h:44
V * find(const K &key)
Definition cache.h:105
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
virtual DString absFilePath() const =0
virtual bool isStrong() const =0
virtual const MemberDef * getEnumScope() const =0
virtual bool isEnumValue() const =0
const char * name(int level)
Definition latexgen.h:368
void replaceNamespaceAliases(DString &name)
DString resolvedType
Definition doxygen.h:55
const Definition * definition
Definition doxygen.h:52
const MemberDef * typeDef
Definition doxygen.h:53
DString templSpec
Definition doxygen.h:54
void getResolvedSymbol(VisitedKeys &visitedKeys, const Definition *scope, const Definition *d, const DString &args, bool checkCV, bool insideCode, const DString &explicitScopePart, const DString &strippedTemplateParams, bool forceCallable, int &minDistance, const Definition *&bestMatch, const MemberDef *&bestTypedef, DString &bestTemplSpec, DString &bestResolvedType)
static bool isCodeSymbol(Definition::DefType defType)
static bool isFileLocalStatic(const Definition *d)
Returns true for a static function or variable that is not a class member, so it is only visible with...
int computeQualifiedIndex(const DString &name)
Return the index of the last :: in the string name that is still before the first <.
Definition util.cpp:5435
DString stripTemplateSpecifiersFromScope(const DString &fullName, bool parentOnly, DString *pLastScopeStripped, DString scopeName, bool allowArtificial)
Definition util.cpp:3818

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, computeQualifiedIndex(), LookupInfo::definition, DString::empty(), Cache< K, V >::find(), SymbolMap< T >::find(), MemberDef::getEnumScope(), MemberDef::getFileDef(), Definition::getLanguage(), getResolvedSymbol(), Doxygen::globalScope, Cache< K, V >::insert(), isCodeSymbol(), MemberDef::isEnumValue(), isFileLocalStatic(), MemberDef::isStrong(), DString::length(), m_fileScope, Definition::name(), DString::npos, replaceNamespaceAliases(), LookupInfo::resolvedType, DString::str(), stringToArgumentList(), stripTemplateSpecifiersFromScope(), Doxygen::symbolMap, LookupInfo::templSpec, toFileDef(), LookupInfo::typeDef, Definition::TypeFile, and Definition::TypeMember.

◆ getResolvedType()

void SymbolResolver::Private::getResolvedType ( LookupCache & cache,
VisitedKeys & visitedKeys,
const Definition * scope,
const Definition * d,
const DString & explicitScopePart,
const ArgumentList * actTemplParams,
int & minDistance,
const ClassDef *& bestMatch,
const MemberDef *& bestTypedef,
DString & bestTemplSpec,
DString & bestResolvedType )
private

Definition at line 692 of file symbolresolver.cpp.

705{
706 AUTO_TRACE("scope={} sym={} explicitScope={}",scope->name(),d->qualifiedName(),explicitScopePart);
707 // only look at classes and members that are enums or typedefs
710 ((toMemberDef(d))->isTypedef() ||
711 (toMemberDef(d))->isEnumerate())
712 )
713 )
714 {
715 VisitedNamespaces visitedNamespaces;
716 AccessStack accessStack;
717 // test accessibility of definition within scope.
718 int distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,
719 accessStack,scope,d,explicitScopePart);
720 AUTO_TRACE_ADD("distance={}",distance);
721 if (distance!=-1) // definition is accessible
722 {
723 // see if we are dealing with a class or a typedef
724 if (d->definitionType()==Definition::TypeClass) // d is a class
725 {
726 const ClassDef *cd = toClassDef(d);
727 //printf("cd=%s\n",qPrint(cd->name()));
728 if (!cd->isTemplateArgument()) // skip classes that
729 // are only there to
730 // represent a template
731 // argument
732 {
733 //printf("is not a templ arg\n");
734 if (distance<minDistance) // found a definition that is "closer"
735 {
736 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",cd->name(),distance,minDistance);
737 minDistance=distance;
738 bestMatch = cd;
739 bestTypedef = nullptr;
740 bestTemplSpec.clear();
741 bestResolvedType = cd->qualifiedName();
742 }
743 else if (distance==minDistance &&
744 m_fileScope && bestMatch &&
748 )
749 {
750 // in case the distance is equal it could be that a class X
751 // is defined in a namespace and in the global scope. When searched
752 // in the global scope the distance is 0 in both cases. We have
753 // to choose one of the definitions: we choose the one in the
754 // namespace if the fileScope imports namespaces and the definition
755 // found was in a namespace while the best match so far isn't.
756 // Just a non-perfect heuristic but it could help in some situations
757 // (kdecore code is an example).
758 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",cd->name(),distance,minDistance);
759 minDistance=distance;
760 bestMatch = cd;
761 bestTypedef = nullptr;
762 bestTemplSpec.clear();
763 bestResolvedType = cd->qualifiedName();
764 }
765 }
766 else
767 {
768 //printf(" is a template argument!\n");
769 }
770 }
772 {
773 const MemberDef *md = toMemberDef(d);
774 AUTO_TRACE_ADD("member={} isTypeDef={}",md->name(),md->isTypedef());
775 if (md->isTypedef()) // d is a typedef
776 {
777 DString args=md->argsString();
778 if (args.empty()) // do not expand "typedef t a[4];"
779 {
780 // we found a symbol at this distance, but if it didn't
781 // resolve to a class, we still have to make sure that
782 // something at a greater distance does not match, since
783 // that symbol is hidden by this one.
784 if (distance<minDistance)
785 {
786 DString spec;
787 DString type;
788 minDistance=distance;
789 const MemberDef *enumType = nullptr;
790 const ClassDef *cd = newResolveTypedef(cache,visitedKeys,scope,md,&enumType,&spec,&type,actTemplParams);
791 if (cd) // type resolves to a class
792 {
793 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",cd->name(),distance,minDistance);
794 bestMatch = cd;
795 bestTypedef = md;
796 bestTemplSpec = spec;
797 bestResolvedType = type;
798 }
799 else if (enumType) // type resolves to a member type
800 {
801 AUTO_TRACE_ADD("found enum");
802 bestMatch = nullptr;
803 bestTypedef = enumType;
804 bestTemplSpec = "";
805 bestResolvedType = enumType->qualifiedName();
806 }
807 else if (md->isReference()) // external reference
808 {
809 AUTO_TRACE_ADD("found external reference");
810 bestMatch = nullptr;
811 bestTypedef = md;
812 bestTemplSpec = spec;
813 bestResolvedType = type;
814 }
815 else
816 {
817 AUTO_TRACE_ADD("no match");
818 bestMatch = nullptr;
819 bestTypedef = md;
820 bestTemplSpec.clear();
821 bestResolvedType.clear();
822 }
823 }
824 else
825 {
826 //printf(" not the best match %d min=%d\n",distance,minDistance);
827 }
828 }
829 else
830 {
831 AUTO_TRACE_ADD("skipping complex typedef");
832 }
833 }
834 else if (md->isEnumerate())
835 {
836 if (distance<minDistance)
837 {
838 AUTO_TRACE_ADD("found enum={} at distance={} minDistance={}",md->name(),distance,minDistance);
839 minDistance=distance;
840 bestMatch = nullptr;
841 bestTypedef = md;
842 bestTemplSpec = "";
843 bestResolvedType = md->qualifiedName();
844 }
845 }
846 }
847 } // if definition accessible
848 else
849 {
850 AUTO_TRACE_ADD("not accessible");
851 }
852 } // if definition is a class or member
853 AUTO_TRACE_EXIT("bestMatch sym={} type={}",
854 bestMatch?bestMatch->name():DString("<none>"),bestResolvedType);
855}
virtual bool isReference() const =0
virtual DString argsString() const =0
virtual bool isTypedef() const =0

References MemberDef::argsString(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, DString::clear(), Definition::definitionType(), DString::empty(), Definition::getOuterScope(), Doxygen::globalScope, SymbolResolver::isAccessibleFromWithExpScope(), MemberDef::isEnumerate(), Definition::isReference(), ClassDef::isTemplateArgument(), MemberDef::isTypedef(), m_fileScope, Definition::name(), newResolveTypedef(), Definition::qualifiedName(), toClassDef(), toMemberDef(), Definition::TypeClass, Definition::TypeMember, and Definition::TypeNamespace.

◆ getResolvedTypeRec()

const ClassDef * SymbolResolver::Private::getResolvedTypeRec ( LookupCache & cache,
VisitedKeys & visitedKeys,
const Definition * scope,
const DString & n,
const MemberDef ** pTypeDef,
DString * pTemplSpec,
DString * pResolvedType )

Definition at line 317 of file symbolresolver.cpp.

325{
326 AUTO_TRACE("scope={} name={}",scope->name(),n);
327 if (n.empty()) return nullptr;
328 DString explicitScopePart;
329 DString strippedTemplateParams;
330 DString scopeName=scope!=Doxygen::globalScope ? scope->name() : DString();
331 DString name=stripTemplateSpecifiersFromScope(n,true,&strippedTemplateParams,scopeName);
332 std::unique_ptr<ArgumentList> actTemplParams;
333 if (!strippedTemplateParams.empty()) // template part that was stripped
334 {
335 actTemplParams = stringToArgumentList(scope->getLanguage(),strippedTemplateParams);
336 }
337
338 int qualifierIndex = computeQualifiedIndex(name);
339 //printf("name=%s qualifierIndex=%d\n",qPrint(name),qualifierIndex);
340 if (qualifierIndex!=-1) // qualified name
341 {
342 // split off the explicit scope part
343 explicitScopePart=name.left(qualifierIndex);
344 // todo: improve namespace alias substitution
345 replaceNamespaceAliases(explicitScopePart);
346 name=name.mid(qualifierIndex+2);
347 }
348
349 if (name.empty())
350 {
351 AUTO_TRACE_EXIT("empty name");
352 return nullptr; // empty name
353 }
354
355 auto &range = Doxygen::symbolMap->find(name);
356 if (range.empty())
357 {
358 AUTO_TRACE_EXIT("no symbol with this name");
359 return nullptr;
360 }
361
362 bool hasUsingStatements =
363 (m_fileScope && (!m_fileScope->getUsedNamespaces().empty() ||
365 );
366 // Since it is often the case that the same name is searched in the same
367 // scope over an over again (especially for the linked source code generation)
368 // we use a cache to collect previous results. This is possible since the
369 // result of a lookup is deterministic. As the key we use the concatenated
370 // scope, the name to search for and the explicit scope prefix. The speedup
371 // achieved by this simple cache can be enormous.
372 size_t scopeNameLen = scope->name().length()+1;
373 size_t nameLen = name.length()+1;
374 size_t explicitPartLen = explicitScopePart.length();
375 size_t fileScopeLen = hasUsingStatements ? 1+m_fileScope->absFilePath().length() : 0;
376
377 // below is a more efficient coding of
378 // DString key=scope->name()+"+"+name+"+"+explicitScopePart+args+typesOnly?'T':'F';
379 DString key(scopeNameLen+nameLen+explicitPartLen+fileScopeLen, DString::ExplicitSize);
380 char *pk=key.rawData();
381 dstrcpy(pk,scope->name().data()); *(pk+scopeNameLen-1)='+';
382 pk+=scopeNameLen;
383 dstrcpy(pk,name.data()); *(pk+nameLen-1)='+';
384 pk+=nameLen;
385 dstrcpy(pk,explicitScopePart.data());
386 pk+=explicitPartLen;
387
388 // if a file scope is given and it contains using statements we should
389 // also use the file part in the key (as a class name can be in
390 // two different namespaces and a using statement in a file can select
391 // one of them).
392 if (hasUsingStatements)
393 {
394 // below is a more efficient coding of
395 // key+="+"+m_fileScope->name();
396 *pk++='+';
398 pk+=fileScopeLen-1;
399 }
400 *pk='\0';
401
402 const ClassDef *bestMatch=nullptr;
403 {
404 if (std::find(visitedKeys.begin(),visitedKeys.end(),key.str())!=std::end(visitedKeys))
405 {
406 // we are already in the middle of find the definition for this key.
407 // avoid recursion
408 AUTO_TRACE_EXIT("recursion detected");
409 return nullptr;
410 }
411 // remember the key
412 visitedKeys.push_back(key.str());
413
414 LookupInfo *pval = cache.find(key.str());
415 AUTO_TRACE_ADD("key={} found={}",key,pval!=nullptr);
416 if (pval)
417 {
418 if (pTemplSpec) *pTemplSpec=pval->templSpec;
419 if (pTypeDef) *pTypeDef=pval->typeDef;
420 if (pResolvedType) *pResolvedType=pval->resolvedType;
421 AUTO_TRACE_EXIT("found cached name={} templSpec={} typeDef={} resolvedTypedef={}",
422 pval->definition?pval->definition->name():DString(),
423 pval->templSpec,
424 pval->typeDef?pval->typeDef->name():DString(),
425 pval->resolvedType);
426
427 return toClassDef(pval->definition);
428 }
429
430 const MemberDef *bestTypedef=nullptr;
431 DString bestTemplSpec;
432 DString bestResolvedType;
433 int minDistance=10000; // init at "infinite"
434
435 for (Definition *d : range)
436 {
437 if (isCodeSymbol(d->definitionType()))
438 {
439 getResolvedType(cache,visitedKeys,scope,d,explicitScopePart,actTemplParams.get(),
440 minDistance,bestMatch,bestTypedef,bestTemplSpec,bestResolvedType);
441 }
442 if (minDistance==0) break; // we can stop reaching if we already reached distance 0
443 }
444
445 if (pTypeDef)
446 {
447 *pTypeDef = bestTypedef;
448 }
449 if (pTemplSpec)
450 {
451 *pTemplSpec = bestTemplSpec;
452 }
453 if (pResolvedType)
454 {
455 *pResolvedType = bestResolvedType;
456 }
457
458 cache.insert(key.str(),LookupInfo(bestMatch,bestTypedef,bestTemplSpec,bestResolvedType));
459 visitedKeys.erase(std::remove(visitedKeys.begin(), visitedKeys.end(), key.str()), visitedKeys.end());
460
461 AUTO_TRACE_EXIT("found name={} templSpec={} typeDef={} resolvedTypedef={}",
462 bestMatch?bestMatch->name():DString(),
463 bestTemplSpec,
464 bestTypedef?bestTypedef->name():DString(),
465 bestResolvedType);
466 }
467 return bestMatch;
468}
@ ExplicitSize
Definition dstring.h:131
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
DString getResolvedType() const
In case a call to resolveClass() points to a typedef or using declaration.
char * dstrcpy(char *dst, const char *src)
Definition dstring.h:42

References FileDef::absFilePath(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, computeQualifiedIndex(), DString::data(), LookupInfo::definition, dstrcpy(), DString::empty(), LinkedRefMap< T, Hash, KeyEqual, Map >::empty(), DString::ExplicitSize, Cache< K, V >::find(), SymbolMap< T >::find(), Definition::getLanguage(), SymbolResolver::getResolvedType(), FileDef::getUsedDefinitions(), FileDef::getUsedNamespaces(), Doxygen::globalScope, Cache< K, V >::insert(), isCodeSymbol(), DString::length(), m_fileScope, Definition::name(), DString::rawData(), replaceNamespaceAliases(), LookupInfo::resolvedType, DString::str(), stringToArgumentList(), stripTemplateSpecifiersFromScope(), Doxygen::symbolMap, LookupInfo::templSpec, toClassDef(), and LookupInfo::typeDef.

Referenced by newResolveTypedef().

◆ isAccessibleFrom()

int SymbolResolver::Private::isAccessibleFrom ( VisitedKeys & visitedKeys,
AccessStack & accessStack,
const Definition * scope,
const Definition * item )

Definition at line 1466 of file symbolresolver.cpp.

1470{
1471 AUTO_TRACE("scope={} item={} item.definitionType={}",
1472 scope?scope->name():DString(), item?item->name():DString(),
1473 item?(int)item->definitionType():-1);
1474
1475 if (accessStack.find(scope,m_fileScope,item))
1476 {
1477 AUTO_TRACE_EXIT("already processed!");
1478 return -1;
1479 }
1480 accessStack.push(scope,m_fileScope,item);
1481
1482 int result=0; // assume we found it
1483 int i=0;
1484
1485 const Definition *itemScope=item->getOuterScope();
1486 bool itemIsMember = item->definitionType()==Definition::TypeMember;
1487 bool itemIsClass = item->definitionType()==Definition::TypeClass;
1488
1489 // if item is a global member and scope points to a specific file
1490 // we adjust the scope so the file gets preference over members with the same name in
1491 // other files.
1492 if ((itemIsMember || itemIsClass) &&
1493 (itemScope==Doxygen::globalScope || // global
1494 (itemScope && itemScope->name().startsWith("anonymous_namespace{")) // member of an anonymous namespace
1495 ) &&
1497 {
1498 if (itemIsMember)
1499 {
1500 itemScope = toMemberDef(item)->getFileDef();
1501 }
1502 else if (itemIsClass)
1503 {
1504 itemScope = toClassDef(item)->getFileDef();
1505 }
1506 AUTO_TRACE_ADD("adjusting scope to {}",itemScope?itemScope->name():DString());
1507 }
1508
1509 const ClassDef *classScope = scope->definitionType()==Definition::TypeClass ? toClassDef(scope) : nullptr;
1510
1511 bool memberAccessibleFromScope =
1512 (itemIsMember && // a member
1513 itemScope && itemScope->definitionType()==Definition::TypeClass && // of a class
1514 classScope && classScope->isAccessibleMember(toMemberDef(item)) // accessible from scope
1515 );
1516 bool nestedClassInsideBaseClass =
1517 (itemIsClass && // a nested class
1518 itemScope && itemScope->definitionType()==Definition::TypeClass && // inside a base
1519 classScope && classScope->isBaseClass(toClassDef(itemScope),true) // class of scope
1520 );
1521 int distanceToBaseClass=0;
1522 bool baseClassOfScope =
1523 (itemIsClass && item!=scope && // a base class of scope
1524 item->getLanguage()==SrcLangExt::Cpp && // can be named in C++
1525 classScope && // without its own scope,
1526 bareName(item)!=bareName(classScope) && // unless scope has the same name
1527 (distanceToBaseClass=classScope->isBaseClass(toClassDef(item),true))>0
1528 );
1529 bool enumValueOfStrongEnum =
1530 (itemIsMember &&
1531 toMemberDef(item)->isStrongEnumValue() &&
1533 toMemberDef(scope)->isEnumerate() &&
1534 scope==toMemberDef(item)->getEnumScope()
1535 );
1536
1537 if (itemScope==scope || memberAccessibleFromScope || nestedClassInsideBaseClass || baseClassOfScope || enumValueOfStrongEnum)
1538 {
1539 AUTO_TRACE_ADD("memberAccessibleFromScope={} nestedClassInsideBaseClass={} baseClassOfScope={} enumValueOfStrongEnum={}",
1540 memberAccessibleFromScope, nestedClassInsideBaseClass, baseClassOfScope, enumValueOfStrongEnum);
1541 int distanceToBase=0;
1542 if (nestedClassInsideBaseClass)
1543 {
1544 result++; // penalty for base class to prevent
1545 // this is preferred over nested class in this class
1546 // see bug 686956
1547 }
1548 else if (memberAccessibleFromScope &&
1549 itemScope &&
1550 itemScope->definitionType()==Definition::TypeClass &&
1552 (distanceToBase=toClassDef(scope)->isBaseClass(toClassDef(itemScope),true))>0
1553 )
1554 {
1555 result+=distanceToBase; // penalty if member is accessible via a base class
1556 }
1557 else if (baseClassOfScope)
1558 {
1559 result+=distanceToBaseClass; // penalty if class is accessible as a base class of scope
1560 }
1561 }
1562 else if (scope==Doxygen::globalScope)
1563 {
1564 if (itemScope &&
1566 toNamespaceDef(itemScope)->isAnonymous() &&
1567 itemScope->getOuterScope()==Doxygen::globalScope)
1568 { // item is in an anonymous namespace in the global scope and we are
1569 // looking in the global scope
1570 AUTO_TRACE_ADD("found in anonymous namespace");
1571 result++;
1572 goto done;
1573 }
1574 if (m_fileScope)
1575 {
1577 {
1578 AUTO_TRACE_ADD("found via used class");
1579 goto done;
1580 }
1581 VisitedNamespaceKeys visitedNamespaceKeys;
1582 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaceKeys,m_fileScope->getUsedNamespaces(),item))
1583 {
1584 AUTO_TRACE_ADD("found via used namespace");
1585 goto done;
1586 }
1587 }
1588 AUTO_TRACE_ADD("reached global scope");
1589 result=-1; // not found in path to globalScope
1590 }
1591 else // keep searching
1592 {
1593 // check if scope is a namespace, which is using other classes and namespaces
1595 {
1596 const NamespaceDef *nscope = toNamespaceDef(scope);
1597 if (accessibleViaUsingDefinition(visitedKeys,nscope->getUsedDefinitions(),item))
1598 {
1599 AUTO_TRACE_ADD("found via used class");
1600 goto done;
1601 }
1602 VisitedNamespaceKeys visitedNamespaceKeys;
1603 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaceKeys,nscope->getUsedNamespaces(),item,DString()))
1604 {
1605 AUTO_TRACE_ADD("found via used namespace");
1606 goto done;
1607 }
1608 }
1609 else if (scope->definitionType()==Definition::TypeFile)
1610 {
1611 const FileDef *nfile = toFileDef(scope);
1612 if (accessibleViaUsingDefinition(visitedKeys,nfile->getUsedDefinitions(),item))
1613 {
1614 AUTO_TRACE_ADD("found via used class");
1615 goto done;
1616 }
1617 VisitedNamespaceKeys visitedNamespaceKeys;
1618 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaceKeys,nfile->getUsedNamespaces(),item,DString()))
1619 {
1620 AUTO_TRACE_ADD("found via used namespace");
1621 goto done;
1622 }
1623 }
1624 // repeat for the parent scope
1625 const Definition *parentScope = scope->getOuterScope();
1626 if (parentScope==Doxygen::globalScope)
1627 {
1629 {
1630 const FileDef *fd = toClassDef(scope)->getFileDef();
1631 if (fd)
1632 {
1633 parentScope = fd;
1634 }
1635 }
1636 }
1637 i=isAccessibleFrom(visitedKeys,accessStack,parentScope,item);
1638 result= (i==-1) ? -1 : i+2;
1639 }
1640done:
1641 AUTO_TRACE_EXIT("result={}",result);
1642 accessStack.pop();
1643 return result;
1644}
bool find(const Definition *scope, const FileDef *fileScope, const Definition *item)
void push(const Definition *scope, const FileDef *fileScope, const Definition *item)
virtual int isBaseClass(const ClassDef *bcd, bool followInstances, const DString &templSpec=DString()) const =0
Returns true iff bcd is a direct or indirect base class of this class.
virtual bool isAccessibleMember(const MemberDef *md) const =0
returns true iff md is a member of this class or of the the public/protected members of a base class
virtual FileDef * getFileDef() const =0
Returns the file in which this compound's definition can be found.
virtual bool isStrongEnumValue() const =0
virtual const LinkedRefMap< NamespaceDef > & getUsedNamespaces() const =0
virtual const LinkedRefMap< const Definition > & getUsedDefinitions() const =0
int isAccessibleFrom(VisitedKeys &visitedKeys, AccessStack &accessStack, const Definition *scope, const Definition *item)
bool accessibleViaUsingDefinition(VisitedKeys &visitedKeys, const LinkedRefMap< const Definition > &dl, const Definition *item, const DString &explicitScopePart="")
StringVector VisitedNamespaceKeys
static DString bareName(const Definition *d)
Returns the name of a class as it is used inside the class itself, so Widget for Widget<int>.

References accessibleViaUsingDefinition(), accessibleViaUsingNamespace(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, bareName(), Definition::definitionType(), AccessStack::find(), MemberDef::getEnumScope(), ClassDef::getFileDef(), MemberDef::getFileDef(), Definition::getLanguage(), Definition::getOuterScope(), FileDef::getUsedDefinitions(), NamespaceDef::getUsedDefinitions(), FileDef::getUsedNamespaces(), NamespaceDef::getUsedNamespaces(), Doxygen::globalScope, SymbolResolver::isAccessibleFrom(), ClassDef::isAccessibleMember(), ClassDef::isBaseClass(), MemberDef::isEnumerate(), MemberDef::isStrongEnumValue(), m_fileScope, Definition::name(), AccessStack::pop(), AccessStack::push(), DString::startsWith(), toClassDef(), toFileDef(), toMemberDef(), toNamespaceDef(), Definition::TypeClass, Definition::TypeFile, Definition::TypeMember, and Definition::TypeNamespace.

◆ isAccessibleFromWithExpScope()

int SymbolResolver::Private::isAccessibleFromWithExpScope ( VisitedKeys & visitedKeys,
VisitedNamespaces & visitedNamespaces,
AccessStack & accessStack,
const Definition * scope,
const Definition * item,
const DString & explicitScopePart )

Definition at line 1135 of file symbolresolver.cpp.

1142{
1143 int result=0; // assume we found it
1144 AUTO_TRACE("scope={} item={} explictScopePart={}",
1145 scope?scope->name():DString(), item?item->name():DString(), explicitScopePart);
1146 if (explicitScopePart.empty())
1147 {
1148 // handle degenerate case where there is no explicit scope.
1149 result = isAccessibleFrom(visitedKeys,accessStack,scope,item);
1150 AUTO_TRACE_EXIT("result={}",result);
1151 return result;
1152 }
1153
1154 if (accessStack.find(scope,m_fileScope,item,explicitScopePart))
1155 {
1156 AUTO_TRACE_EXIT("already found");
1157 return -1;
1158 }
1159 accessStack.push(scope,m_fileScope,item,explicitScopePart);
1160
1161 const Definition *newScope = followPath(visitedKeys,scope,explicitScopePart);
1162 if (newScope) // explicitScope is inside scope => newScope is the result
1163 {
1164 Definition *itemScope = item->getOuterScope();
1165
1166 AUTO_TRACE_ADD("scope traversal successful newScope={}",newScope->name());
1167
1168 bool nestedClassInsideBaseClass =
1169 itemScope &&
1170 itemScope->definitionType()==Definition::TypeClass &&
1172 (toClassDef(newScope))->isBaseClass(toClassDef(itemScope),true);
1173
1174 bool enumValueWithinEnum =
1176 toMemberDef(item)->isEnumValue() &&
1177 toMemberDef(item)->getEnumScope()==newScope;
1178
1179 if (itemScope==newScope) // exact match of scopes => distance==0
1180 {
1181 AUTO_TRACE_ADD("found scope match");
1182 }
1183 else if (nestedClassInsideBaseClass)
1184 {
1185 // inheritance is also ok. Example: looking for B::I, where
1186 // class A { public: class I {} };
1187 // class B : public A {}
1188 // but looking for B::I, where
1189 // class A { public: class I {} };
1190 // class B { public: class I {} };
1191 // will find A::I, so we still prefer a direct match and give this one a distance of 1
1192 result=1;
1193
1194 AUTO_TRACE_ADD("{} is a bass class of {}",scope->name(),newScope->name());
1195 }
1196 else if (enumValueWithinEnum)
1197 {
1198 AUTO_TRACE_ADD("found enum value inside enum");
1199 result=1;
1200 }
1201 else
1202 {
1203 int i=-1;
1205 {
1206 visitedNamespaces.emplace(newScope->name().str(),newScope);
1207 // this part deals with the case where item is a class
1208 // A::B::C but is explicit referenced as A::C, where B is imported
1209 // in A via a using directive.
1210 //printf("newScope is a namespace: %s!\n",qPrint(newScope->name()));
1211 const NamespaceDef *nscope = toNamespaceDef(newScope);
1212 for (const auto &ud : nscope->getUsedDefinitions())
1213 {
1214 if (ud==item)
1215 {
1216 AUTO_TRACE_ADD("found in used definition {}",ud->name());
1217 goto done;
1218 }
1219 }
1220 for (const auto &nd : nscope->getUsedNamespaces())
1221 {
1222 if (visitedNamespaces.find(nd->name().str())==visitedNamespaces.end())
1223 {
1224 i = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,item,nd->name());
1225 if (i!=-1)
1226 {
1227 AUTO_TRACE_ADD("found in used namespace {}",nd->name());
1228 goto done;
1229 }
1230 }
1231 }
1232 }
1233#if 0 // this caused problems resolving A::f() in the docs when there was a A::f(int) but also a
1234 // global function f() that exactly matched the argument list.
1235 else if (isParentScope(scope,newScope) && newScope->definitionType()==Definition::TypeClass)
1236 {
1237 // if we a look for a type B and have explicit scope A, then it is also fine if B
1238 // is found at the global scope.
1239 result = 1;
1240 goto done;
1241 }
1242#endif
1243 // repeat for the parent scope
1244 if (scope!=Doxygen::globalScope)
1245 {
1246 i = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope->getOuterScope(),item,explicitScopePart);
1247 }
1248 result = (i==-1) ? -1 : i+2;
1249 }
1250 }
1251 else // failed to resolve explicitScope
1252 {
1253 AUTO_TRACE_ADD("failed to resolve explicitScope");
1255 {
1256 const NamespaceDef *nscope = toNamespaceDef(scope);
1257 VisitedNamespaceKeys locVisitedNamespaceKeys;
1258 if (accessibleViaUsingNamespace(visitedKeys,locVisitedNamespaceKeys,nscope->getUsedNamespaces(),item,explicitScopePart))
1259 {
1260 AUTO_TRACE_ADD("found in used class");
1261 goto done;
1262 }
1263 }
1264 if (scope==Doxygen::globalScope)
1265 {
1266 if (m_fileScope)
1267 {
1268 VisitedNamespaceKeys locVisitedNamespaceKeys;
1269 if (accessibleViaUsingNamespace(visitedKeys,locVisitedNamespaceKeys,m_fileScope->getUsedNamespaces(),item,explicitScopePart))
1270 {
1271 AUTO_TRACE_ADD("found in used namespace");
1272 goto done;
1273 }
1274 }
1275 AUTO_TRACE_ADD("not found in this scope");
1276 result=-1;
1277 }
1278 else // continue by looking into the parent scope
1279 {
1280 int i=isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope->getOuterScope(),item,explicitScopePart);
1281 result= (i==-1) ? -1 : i+2;
1282 }
1283 }
1284
1285done:
1286 AUTO_TRACE_EXIT("result={}",result);
1287 accessStack.pop();
1288 return result;
1289}

References accessibleViaUsingNamespace(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, Definition::definitionType(), DString::empty(), AccessStack::find(), followPath(), MemberDef::getEnumScope(), Definition::getOuterScope(), NamespaceDef::getUsedDefinitions(), NamespaceDef::getUsedNamespaces(), Doxygen::globalScope, SymbolResolver::isAccessibleFrom(), SymbolResolver::isAccessibleFromWithExpScope(), MemberDef::isEnumValue(), m_fileScope, Definition::name(), AccessStack::pop(), AccessStack::push(), DString::str(), toClassDef(), toMemberDef(), toNamespaceDef(), Definition::TypeClass, Definition::TypeMember, and Definition::TypeNamespace.

◆ newResolveTypedef()

const ClassDef * SymbolResolver::Private::newResolveTypedef ( LookupCache & cache,
VisitedKeys & visitedKeys,
const Definition * scope,
const MemberDef * md,
const MemberDef ** pMemType,
DString * pTemplSpec,
DString * pResolvedType,
const ArgumentList * actTemplParams = nullptr )
private

Definition at line 995 of file symbolresolver.cpp.

1004{
1005 AUTO_TRACE("md={}",md->qualifiedName());
1006 std::lock_guard lock(g_cacheTypedefMutex);
1007 bool isCached = md->isTypedefValCached(); // value already cached
1008 if (isCached)
1009 {
1010 AUTO_TRACE_EXIT("cached typedef={} resolvedTypedef={} templSpec={}",
1011 md->getCachedTypedefVal() ? md->getCachedTypedefVal()->name() : DString(),
1014
1015 if (pTemplSpec) *pTemplSpec = md->getCachedTypedefTemplSpec();
1016 if (pResolvedType) *pResolvedType = md->getCachedResolvedTypedef();
1017 return md->getCachedTypedefVal();
1018 }
1019
1020 DString qname = md->qualifiedName();
1021 if (m_resolvedTypedefs.find(qname.str())!=m_resolvedTypedefs.end())
1022 {
1023 AUTO_TRACE_EXIT("already being processed");
1024 return nullptr; // typedef already done
1025 }
1026
1027 auto typedef_it = m_resolvedTypedefs.emplace(qname.str(),md).first; // put on the trace list
1028
1029 const ClassDef *typeClass = md->getClassDef();
1030 DString type = md->typeString(); // get the "value" of the typedef
1031 if (typeClass && typeClass->isTemplate() &&
1032 actTemplParams && !actTemplParams->empty())
1033 {
1035 typeClass->templateArguments(),actTemplParams);
1036 }
1037 DString typedefValue = type;
1038 int tl=static_cast<int>(type.length());
1039 int ip=tl-1; // remove * and & at the end
1040 while (ip>=0 && (type.at(ip)=='*' || type.at(ip)=='&' || type.at(ip)==' '))
1041 {
1042 ip--;
1043 }
1044 type=type.left(ip+1);
1045 type.stripPrefix("const "); // strip leading "const"
1046 type.stripPrefix("volatile "); // strip leading "volatile"
1047 type.stripPrefix("struct "); // strip leading "struct"
1048 type.stripPrefix("record "); // strip leading "record"
1049 type.stripPrefix("union "); // strip leading "union"
1050 int sp=0;
1051 tl=static_cast<int>(type.length()); // length may have been changed
1052 while (sp<tl && type.at(sp)==' ') sp++;
1053 const MemberDef *memTypeDef = nullptr;
1054 const ClassDef *result = getResolvedTypeRec(cache,visitedKeys,md->getOuterScope(),type,
1055 &memTypeDef,nullptr,pResolvedType);
1056 // if type is a typedef then return what it resolves to.
1057 if (memTypeDef && memTypeDef->isTypedef())
1058 {
1059 AUTO_TRACE_ADD("resolving typedef");
1060 result=newResolveTypedef(cache,visitedKeys,m_fileScope,memTypeDef,pMemType,pTemplSpec,nullptr);
1061 goto done;
1062 }
1063 else if (memTypeDef && memTypeDef->isEnumerate() && pMemType)
1064 {
1065 *pMemType = memTypeDef;
1066 }
1067
1068 if (result==nullptr)
1069 {
1070 // try unspecialized version if type is template
1071 size_t si = type.rfind("::");
1072 size_t i = type.find('<');
1073 if (si==DString::npos && i!=DString::npos) // typedef of a template => try the unspecialized version
1074 {
1075 if (pTemplSpec) *pTemplSpec = type.mid(i);
1076 result = getResolvedTypeRec(cache,visitedKeys,md->getOuterScope(),type.left(i),nullptr,nullptr,pResolvedType);
1077 }
1078 else if (si!=DString::npos) // A::B
1079 {
1080 i=type.find('<',si);
1081 if (i==DString::npos) // Something like A<T>::B => lookup A::B
1082 {
1083 i=type.length();
1084 }
1085 else // Something like A<T>::B<S> => lookup A::B, spec=<S>
1086 {
1087 if (pTemplSpec) *pTemplSpec = type.mid(i);
1088 }
1089 result = getResolvedTypeRec(cache,visitedKeys,md->getOuterScope(),
1090 stripTemplateSpecifiersFromScope(type.left(i),false),nullptr,nullptr,pResolvedType);
1091 }
1092 }
1093
1094done:
1095 if (pResolvedType)
1096 {
1097 if (result && result->definitionType()==Definition::TypeClass)
1098 {
1099 *pResolvedType = result->qualifiedName();
1100 if (sp>0) pResolvedType->prepend(typedefValue.left(sp));
1101 if (ip<tl-1) pResolvedType->append(typedefValue.right(tl-ip-1));
1102 }
1103 else
1104 {
1105 *pResolvedType = typedefValue;
1106 }
1107 }
1108
1109 // remember computed value for next time
1110 if (result && result->getDefFileName()!="<code>")
1111 // this check is needed to prevent that temporary classes that are
1112 // introduced while parsing code fragments are being cached here.
1113 {
1114 AUTO_TRACE_ADD("caching typedef relation {}->{}",md->name(),result->name());
1115 MemberDefMutable *mdm = toMemberDefMutable(const_cast<MemberDef*>(md));
1116 if (mdm)
1117 {
1118 mdm->cacheTypedefVal(result,
1119 pTemplSpec ? *pTemplSpec : DString(),
1120 pResolvedType ? *pResolvedType : DString()
1121 );
1122 }
1123 }
1124
1125 m_resolvedTypedefs.erase(typedef_it); // remove from the trace list
1126
1127 AUTO_TRACE_EXIT("result={} pTemplSpec={} pResolvedType={}",
1128 result ? result->name() : DString(),
1129 pTemplSpec ? *pTemplSpec : "<nullptr>",
1130 pResolvedType ? *pResolvedType : "<nullptr>"
1131 );
1132 return result;
1133}
bool empty() const
Definition arguments.h:100
virtual const ArgumentList & templateArguments() const =0
Returns the template arguments of this class.
virtual bool isTemplate() const =0
Returns true if this class is a template.
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
DString & append(char c)
Definition dstring.h:489
DString right(size_t len) const
Definition dstring.h:311
DString & prepend(const char *s)
Definition dstring.h:515
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString left(size_t len) const
Definition dstring.h:306
bool stripPrefix(const DString &prefix)
Definition dstring.h:290
virtual DString getDefFileName() const =0
virtual const ClassDef * getCachedTypedefVal() const =0
virtual const ClassDef * getClassDef() const =0
virtual DString getCachedResolvedTypedef() const =0
virtual bool isTypedefValCached() const =0
virtual DString getCachedTypedefTemplSpec() const =0
virtual void cacheTypedefVal(const ClassDef *val, const DString &templSpec, const DString &resolvedType)=0
MemberDefMutable * toMemberDefMutable(Definition *d)
const ClassDef * getResolvedTypeRec(LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const DString &n, const MemberDef **pTypeDef, DString *pTemplSpec, DString *pResolvedType)
std::unordered_map< std::string, const MemberDef * > m_resolvedTypedefs
static std::recursive_mutex g_cacheTypedefMutex

References DString::append(), DString::at(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, MemberDefMutable::cacheTypedefVal(), Definition::definitionType(), ArgumentList::empty(), DString::find(), g_cacheTypedefMutex, MemberDef::getCachedResolvedTypedef(), MemberDef::getCachedTypedefTemplSpec(), MemberDef::getCachedTypedefVal(), MemberDef::getClassDef(), Definition::getDefFileName(), Definition::getOuterScope(), getResolvedTypeRec(), MemberDef::isEnumerate(), ClassDef::isTemplate(), MemberDef::isTypedef(), MemberDef::isTypedefValCached(), DString::left(), DString::length(), m_fileScope, m_resolvedTypedefs, DString::mid(), Definition::name(), newResolveTypedef(), DString::npos, DString::prepend(), Definition::qualifiedName(), DString::rfind(), DString::right(), DString::str(), DString::stripPrefix(), stripTemplateSpecifiersFromScope(), substituteTemplateArgumentsInString(), ClassDef::templateArguments(), toMemberDefMutable(), Definition::TypeClass, and MemberDef::typeString().

Referenced by followPath(), getResolvedType(), and newResolveTypedef().

◆ reset()

void SymbolResolver::Private::reset ( )
inline

Definition at line 198 of file symbolresolver.cpp.

199 {
200 m_resolvedTypedefs.clear();
202 typeDef = nullptr;
204 }
const MemberDef * typeDef

References DString::clear(), m_resolvedTypedefs, resolvedType, templateSpec, and typeDef.

◆ setFileScope()

void SymbolResolver::Private::setFileScope ( const FileDef * fileScope)
inline

Definition at line 205 of file symbolresolver.cpp.

206 {
208 }
const FileDef * fileScope() const

References fileScope(), and m_fileScope.

◆ substTypedef()

DString SymbolResolver::Private::substTypedef ( VisitedKeys & visitedKeys,
const Definition * scope,
const DString & name,
const MemberDef ** pTypeDef = nullptr )
private

Definition at line 1646 of file symbolresolver.cpp.

1650{
1651 AUTO_TRACE("scope={} name={}",scope?scope->name():DString(), name);
1652 DString result=name;
1653 if (name.empty()) return result;
1654
1655 auto &range = Doxygen::symbolMap->find(name);
1656 if (range.empty())
1657 return result; // no matches
1658
1659 MemberDef *bestMatch=nullptr;
1660 int minDistance=10000; // init at "infinite"
1661
1662 std::string key;
1663 const int maxAddrSize = 20;
1664 char ptr_str[maxAddrSize];
1665 int num = snprintf(ptr_str,maxAddrSize,"%p:",(void *)scope);
1666 ASSERT(num>0);
1667 key.reserve(num+name.length()+1);
1668 key+=ptr_str;
1669 key+=name.str();
1670 {
1671 auto it = g_substMap.find(key);
1672 if (it!=g_substMap.end())
1673 {
1674 if (pTypeDef) *pTypeDef = it->second.second;
1675 return it->second.first;
1676 }
1677 }
1678
1679 for (Definition *d : range)
1680 {
1681 // only look at members
1682 if (d->definitionType()==Definition::TypeMember)
1683 {
1684 // that are also typedefs
1685 MemberDef *md = toMemberDef(d);
1686 if (md->isTypedef()) // d is a typedef
1687 {
1688 VisitedNamespaces visitedNamespaces;
1689 AccessStack accessStack;
1690 // test accessibility of typedef within scope.
1691 int distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,d,"");
1692 if (distance!=-1 && distance<minDistance)
1693 // definition is accessible and a better match
1694 {
1695 minDistance=distance;
1696 bestMatch = md;
1697 }
1698 }
1699 }
1700 }
1701
1702 if (bestMatch)
1703 {
1704 result = bestMatch->typeString();
1705 if (pTypeDef) *pTypeDef=bestMatch;
1706 }
1707
1708 // cache the result of the computation to give a faster answers next time, especially relevant
1709 // if `range` has many arguments (i.e. there are many symbols with the same name in different contexts)
1710 {
1711 g_substMap.emplace(key,std::make_pair(result,bestMatch));
1712 }
1713
1714 AUTO_TRACE_EXIT("result={}",result);
1715 return result;
1716}
#define ASSERT(x)
Definition message.h:142
THREAD_LOCAL std::unordered_map< std::string, std::pair< DString, const MemberDef * > > g_substMap

References ASSERT, AUTO_TRACE, AUTO_TRACE_EXIT, SymbolMap< T >::find(), g_substMap, SymbolResolver::isAccessibleFromWithExpScope(), MemberDef::isTypedef(), Definition::name(), Doxygen::symbolMap, toMemberDef(), Definition::TypeMember, and MemberDef::typeString().

Referenced by followPath().

Member Data Documentation

◆ m_fileScope

◆ m_resolvedTypedefs

std::unordered_map<std::string,const MemberDef*> SymbolResolver::Private::m_resolvedTypedefs
private

Definition at line 312 of file symbolresolver.cpp.

Referenced by newResolveTypedef(), and reset().

◆ resolvedType

DString SymbolResolver::Private::resolvedType

Definition at line 211 of file symbolresolver.cpp.

Referenced by reset().

◆ templateSpec

DString SymbolResolver::Private::templateSpec

Definition at line 213 of file symbolresolver.cpp.

Referenced by reset().

◆ typeDef

const MemberDef* SymbolResolver::Private::typeDef = nullptr

Definition at line 212 of file symbolresolver.cpp.

Referenced by reset().


The documentation for this struct was generated from the following file: