Doxygen
Loading...
Searching...
No Matches
SymbolResolver Class Reference

#include <src/symbolresolver.h>

Classes

struct  Private

Public Types

enum class  ClearScope { All , Classes , Unresolved }
 Clear the type lookup cache for the current thread. More...

Public Member Functions

 SymbolResolver (const FileDef *fileScope=nullptr)
 ~SymbolResolver ()
const ClassDef * resolveClass (const Definition *scope, const DString &name, bool maybeUnlinkable=false, bool mayBeHidden=false)
 Find the class definition matching name within the scope set.
ClassDefMutable * resolveClassMutable (const Definition *scope, const DString &name, bool mayBeUnlinkable=false, bool mayBeHidden=false)
 Wrapper around resolveClass that returns a mutable interface to the class object or a nullptr if the symbol is immutable.
const Definition * resolveSymbol (const Definition *scope, const DString &name, const DString &args=DString(), bool checkCV=false, bool insideCode=false, bool onlyLinkable=false)
 Find the symbool definition matching name within the scope set.
int isAccessibleFrom (const Definition *scope, const Definition *item)
 Checks if symbol item is accessible from within scope.
int isAccessibleFromWithExpScope (const Definition *scope, const Definition *item, const DString &explicitScopePart)
 Check if symbol item is accessible from within scope, where it has to match the explicitScopePart.
void setFileScope (const FileDef *fd)
 Sets or updates the file scope using when resolving symbols.
const MemberDef * getTypedef () const
 In case a call to resolveClass() resolves to a type member (e.g. an enum) this method will return it.
DString getTemplateSpec () const
 In case a call to resolveClass() points to a template specialization, the template part is return via this method.
DString getResolvedType () const
 In case a call to resolveClass() points to a typedef or using declaration.

Static Public Member Functions

static void clearTypeLookupCache (ClearScope scope)
static void showCacheUsage ()
 Show usage of the type lookup cache.

Private Attributes

std::unique_ptr< Private > p

Detailed Description

Helper class to find a class definition or check if A symbol is accessible in a given scope.

Definition at line 31 of file symbolresolver.h.

Member Enumeration Documentation

◆ ClearScope

enum class SymbolResolver::ClearScope
strong

Clear the type lookup cache for the current thread.

Enumerator
All 
Classes 
Unresolved 

Definition at line 102 of file symbolresolver.h.

102{ All, Classes, Unresolved };

Constructor & Destructor Documentation

◆ SymbolResolver()

SymbolResolver::SymbolResolver ( const FileDef * fileScope = nullptr)
explicit

Definition at line 1721 of file symbolresolver.cpp.

1722 : p(std::make_unique<Private>(fileScope))
1723{
1724}
std::unique_ptr< Private > p

References p.

◆ ~SymbolResolver()

SymbolResolver::~SymbolResolver ( )

Definition at line 1726 of file symbolresolver.cpp.

1727{
1728}

Member Function Documentation

◆ clearTypeLookupCache()

void SymbolResolver::clearTypeLookupCache ( SymbolResolver::ClearScope scope)
static

Definition at line 1848 of file symbolresolver.cpp.

1849{
1850 auto &cache = getTypeLookupCache();
1851 switch (scope)
1852 {
1853 case ClearScope::All:
1854 cache.clear();
1855 break;
1857 {
1858 StringVector elementsToRemove;
1859 for (const auto &ci : cache)
1860 {
1861 const LookupInfo &li = ci.second;
1862 if (li.definition==nullptr && li.typeDef==nullptr)
1863 {
1864 elementsToRemove.push_back(ci.first);
1865 }
1866 }
1867 for (const auto &k : elementsToRemove)
1868 {
1869 cache.remove(k);
1870 }
1871 }
1872 break;
1874 {
1875 StringVector elementsToRemove;
1876 for (const auto &ci : cache)
1877 {
1878 const LookupInfo &li = ci.second;
1879 if (li.definition)
1880 {
1881 elementsToRemove.push_back(ci.first);
1882 }
1883 }
1884 for (const auto &k : elementsToRemove)
1885 {
1886 cache.remove(k);
1887 }
1888 }
1889 break;
1890 }
1891}
std::vector< std::string > StringVector
Definition containers.h:33
const Definition * definition
Definition doxygen.h:52
const MemberDef * typeDef
Definition doxygen.h:53
static LookupCache & getTypeLookupCache()

References All, Classes, LookupInfo::definition, getTypeLookupCache(), LookupInfo::typeDef, and Unresolved.

Referenced by flushCachedTemplateRelations(), flushUnresolvedRelations(), and parseInput().

◆ getResolvedType()

DString SymbolResolver::getResolvedType ( ) const

In case a call to resolveClass() points to a typedef or using declaration.

The type name it resolved to is returned via this method.

Definition at line 1843 of file symbolresolver.cpp.

1844{
1845 return p->resolvedType;
1846}

References p.

Referenced by getCanonicalTypeForIdentifier(), and SymbolResolver::Private::getResolvedTypeRec().

◆ getTemplateSpec()

DString SymbolResolver::getTemplateSpec ( ) const

In case a call to resolveClass() points to a template specialization, the template part is return via this method.

Definition at line 1838 of file symbolresolver.cpp.

1839{
1840 return p->templateSpec;
1841}

References p.

Referenced by findClassRelation(), and getCanonicalTypeForIdentifier().

◆ getTypedef()

const MemberDef * SymbolResolver::getTypedef ( ) const

In case a call to resolveClass() resolves to a type member (e.g. an enum) this method will return it.

Definition at line 1833 of file symbolresolver.cpp.

1834{
1835 return p->typeDef;
1836}

References p.

Referenced by findClassRelation(), getCanonicalTypeForIdentifier(), linkifyText(), and matchUnresolvedTypes().

◆ isAccessibleFrom()

int SymbolResolver::isAccessibleFrom ( const Definition * scope,
const Definition * item )

Checks if symbol item is accessible from within scope.

Returns
-1 if item is not accessible or a number indicating how many scope levels up the nearest match was found.

Definition at line 1802 of file symbolresolver.cpp.

1803{
1804 AUTO_TRACE("scope={} item={}",
1805 scope?scope->name():DString(), item?item->name():DString());
1806 p->reset();
1807 VisitedKeys visitedKeys;
1808 AccessStack accessStack;
1809 int result = p->isAccessibleFrom(visitedKeys,accessStack,scope,item);
1810 AUTO_TRACE_EXIT("result={}",result);
1811 return result;
1812}
virtual const DString & name() const =0
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
StringVector VisitedKeys

References AUTO_TRACE, AUTO_TRACE_EXIT, Definition::name(), and p.

Referenced by SymbolResolver::Private::isAccessibleFrom(), SymbolResolver::Private::isAccessibleFromWithExpScope(), and resolveTypeDef().

◆ isAccessibleFromWithExpScope()

int SymbolResolver::isAccessibleFromWithExpScope ( const Definition * scope,
const Definition * item,
const DString & explicitScopePart )

Check if symbol item is accessible from within scope, where it has to match the explicitScopePart.

Returns
-1 if item is not accessible or a number indicating how many scope levels up the nearest match was found.

Definition at line 1814 of file symbolresolver.cpp.

1816{
1817 AUTO_TRACE("scope={} item={} explicitScopePart={}",
1818 scope?scope->name():DString(), item?item->name():DString(), explicitScopePart);
1819 p->reset();
1820 VisitedKeys visitedKeys;
1821 VisitedNamespaces visitedNamespaces;
1822 AccessStack accessStack;
1823 int result = p->isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,item,explicitScopePart);
1824 AUTO_TRACE_EXIT("result={}",result);
1825 return result;
1826}
std::unordered_map< std::string, const Definition * > VisitedNamespaces

References AUTO_TRACE, AUTO_TRACE_EXIT, Definition::name(), and p.

Referenced by getMemberFromSymbol(), SymbolResolver::Private::getResolvedSymbol(), SymbolResolver::Private::getResolvedType(), SymbolResolver::Private::isAccessibleFromWithExpScope(), and SymbolResolver::Private::substTypedef().

◆ resolveClass()

const ClassDef * SymbolResolver::resolveClass ( const Definition * scope,
const DString & name,
bool maybeUnlinkable = false,
bool mayBeHidden = false )

Find the class definition matching name within the scope set.

Parameters
scopeThe scope to search from.
nameThe name of the symbol.
maybeUnlinkableinclude unlinkable symbols in the search.
mayBeHiddeninclude hidden symbols in the search.
Note
As a result of this call the getters getTypedef(), getTemplateSpec(), and getResolvedType() are set as well.

Definition at line 1731 of file symbolresolver.cpp.

1735{
1736 AUTO_TRACE("scope={} name={} mayBeUnlinkable={} mayBeHidden={}",
1737 scope?scope->name():DString(), name, mayBeUnlinkable, mayBeHidden);
1738 p->reset();
1739
1740 auto lang = scope ? scope->getLanguage() :
1741 p->fileScope() ? p->fileScope()->getLanguage() :
1742 SrcLangExt::Cpp; // fallback to C++
1743
1744 if (scope==nullptr ||
1747 ) ||
1748 (name.stripWhiteSpace().startsWith("::")) ||
1749 ((lang==SrcLangExt::Java || lang==SrcLangExt::CSharp) && DString(name).find("::")!=DString::npos)
1750 )
1751 {
1753 }
1754 const ClassDef *result=nullptr;
1755 if (Config_getBool(OPTIMIZE_OUTPUT_VHDL))
1756 {
1757 result = getClass(name);
1758 }
1759 else
1760 {
1761 VisitedKeys visitedKeys;
1762 DString lookupName = lang==SrcLangExt::CSharp ? mangleCSharpGenericName(name) : name;
1763 AUTO_TRACE_ADD("lookup={}",lookupName);
1764 result = p->getResolvedTypeRec(getTypeLookupCache(),visitedKeys,scope,lookupName,&p->typeDef,&p->templateSpec,&p->resolvedType);
1765 if (result==nullptr) // for nested classes imported via tag files, the scope may not
1766 // present, so we check the class name directly as well.
1767 // See also bug701314
1768 {
1769 result = getClass(lookupName);
1770 }
1771 }
1772 if (!mayBeUnlinkable && result && !result->isLinkable())
1773 {
1774 if (!mayBeHidden || !result->isHidden())
1775 {
1776 AUTO_TRACE_ADD("hiding symbol {}",result->name());
1777 result=nullptr; // don't link to artificial/hidden classes unless explicitly allowed
1778 }
1779 }
1780 AUTO_TRACE_EXIT("result={}",result?result->name():DString());
1781 return result;
1782}
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
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual bool isLinkable() const =0
virtual DefType definitionType() const =0
virtual bool isHidden() const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
ClassDef * getClass(const DString &n)
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
const char * name(int level)
Definition latexgen.h:368
DString mangleCSharpGenericName(const DString &name)
Definition util.cpp:5477

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, Config_getBool, Definition::definitionType(), getClass(), Definition::getLanguage(), getTypeLookupCache(), Doxygen::globalScope, Definition::isHidden(), Definition::isLinkable(), mangleCSharpGenericName(), Definition::name(), DString::npos, p, Definition::TypeClass, and Definition::TypeNamespace.

Referenced by findClassDefinition(), findClassWithinClassContext(), findFieldDocumentation(), findUsingDeclImports(), getCanonicalTypeForIdentifier(), isVarWithConstructor(), linkifyText(), matchUnresolvedTypes(), normalizeNonTemplateArgumentsInString(), and resolveClassMutable().

◆ resolveClassMutable()

ClassDefMutable * SymbolResolver::resolveClassMutable ( const Definition * scope,
const DString & name,
bool mayBeUnlinkable = false,
bool mayBeHidden = false )
inline

Wrapper around resolveClass that returns a mutable interface to the class object or a nullptr if the symbol is immutable.

Definition at line 57 of file symbolresolver.h.

61 {
62 return toClassDefMutable(const_cast<ClassDef*>(resolveClass(scope,name,mayBeUnlinkable,mayBeHidden)));
63 }
const ClassDef * resolveClass(const Definition *scope, const DString &name, bool maybeUnlinkable=false, bool mayBeHidden=false)
Find the class definition matching name within the scope set.
ClassDefMutable * toClassDefMutable(Definition *d)

References resolveClass(), and toClassDefMutable().

Referenced by ClassDefImpl::addTypeConstraint(), findClassRelation(), findUsedClassesForClass(), and resolveTemplateInstanceInType().

◆ resolveSymbol()

const Definition * SymbolResolver::resolveSymbol ( const Definition * scope,
const DString & name,
const DString & args = DString(),
bool checkCV = false,
bool insideCode = false,
bool onlyLinkable = false )

Find the symbool definition matching name within the scope set.

Parameters
scopeThe scope to search from.
nameThe name of the symbol.
argsArgument list associated with the symbol (for functions)
checkCVCheck const/volatile qualifiers (for methods)
insideCodeIs the symbol found in a code fragment
onlyLinkableOnly search linkable definitions

Definition at line 1784 of file symbolresolver.cpp.

1790{
1791 AUTO_TRACE("scope={} name={} args={} checkCV={} insideCode={}",
1792 scope?scope->name():DString(), name, args, checkCV, insideCode);
1793 p->reset();
1794 if (scope==nullptr) scope=Doxygen::globalScope;
1795 VisitedKeys visitedKeys;
1796 const Definition *result = p->getResolvedSymbolRec(getSymbolLookupCache(),visitedKeys,scope,name,args,checkCV,insideCode,onlyLinkable,&p->typeDef,&p->templateSpec,&p->resolvedType);
1797 AUTO_TRACE_EXIT("result={}{}", qPrint(result?result->qualifiedName():DString()),
1798 qPrint(result && result->definitionType()==Definition::TypeMember ? toMemberDef(result)->argsString() : DString()));
1799 return result;
1800}
virtual DString qualifiedName() const =0
const char * qPrint(const char *s)
Definition dstring.h:783
MemberDef * toMemberDef(Definition *d)
static LookupCache & getSymbolLookupCache()

References AUTO_TRACE, AUTO_TRACE_EXIT, Definition::definitionType(), getSymbolLookupCache(), Doxygen::globalScope, Definition::name(), p, qPrint(), Definition::qualifiedName(), toMemberDef(), and Definition::TypeMember.

Referenced by findUsingDeclarations(), findUsingDeclImports(), getDefs(), and linkifyText().

◆ setFileScope()

void SymbolResolver::setFileScope ( const FileDef * fd)

Sets or updates the file scope using when resolving symbols.

Definition at line 1828 of file symbolresolver.cpp.

1829{
1830 p->setFileScope(fileScope);
1831}

References p.

Referenced by getDefs().

◆ showCacheUsage()

void SymbolResolver::showCacheUsage ( )
static

Show usage of the type lookup cache.

Definition at line 1909 of file symbolresolver.cpp.

1910{
1911 // merge the stats of the main thread
1914
1915 std::lock_guard lock1(g_typeCacheStatistics.mutex);
1916 std::lock_guard lock2(g_symbolCacheStatistics.mutex);
1917
1918 msg("type lookup cache used {}/{} hits={} misses={}\n",
1923 msg("symbol lookup cache used {}/{} hits={} misses={}\n",
1928 int typeCacheParam = computeIdealCacheParam(static_cast<size_t>(g_typeCacheStatistics.misses*2/3)); // part of the cache is flushed, hence the 2/3 correction factor
1929 int symbolCacheParam = computeIdealCacheParam(static_cast<size_t>(g_symbolCacheStatistics.misses*2/3)); // part of the cache is flushed, hence the 2/3 correction factor
1930 int cacheParam = std::max(typeCacheParam,symbolCacheParam);
1931 if (cacheParam>Config_getInt(LOOKUP_CACHE_SIZE))
1932 {
1933 msg("Note: based on cache misses the ideal setting for LOOKUP_CACHE_SIZE is {} at the cost of higher memory usage.\n",cacheParam);
1934 }
1935}
#define Config_getInt(name)
Definition config.h:34
#define msg(fmt,...)
Definition message.h:94
static void mergeStatistics(CacheStatistics &stats, LookupCache &cache)
static int computeIdealCacheParam(size_t v)
static CacheStatistics g_symbolCacheStatistics
static CacheStatistics g_typeCacheStatistics

References CacheStatistics::capacity, computeIdealCacheParam(), Config_getInt, g_symbolCacheStatistics, g_typeCacheStatistics, getSymbolLookupCache(), getTypeLookupCache(), CacheStatistics::hits, mergeStatistics(), CacheStatistics::misses, msg, CacheStatistics::mutex, and CacheStatistics::size.

Referenced by generateOutput().

Member Data Documentation

◆ p


The documentation for this class was generated from the following files: