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 ClassDefresolveClass (const Definition *scope, const QCString &name, bool maybeUnlinkable=false, bool mayBeHidden=false)
 Find the class definition matching name within the scope set.
ClassDefMutableresolveClassMutable (const Definition *scope, const QCString &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 DefinitionresolveSymbol (const Definition *scope, const QCString &name, const QCString &args=QCString(), 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 QCString &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 MemberDefgetTypedef () const
 In case a call to resolveClass() resolves to a type member (e.g. an enum) this method will return it.
QCString getTemplateSpec () const
 In case a call to resolveClass() points to a template specialization, the template part is return via this method.
QCString 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< Privatep

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 1680 of file symbolresolver.cpp.

1681 : p(std::make_unique<Private>(fileScope))
1682{
1683}
std::unique_ptr< Private > p

References p.

◆ ~SymbolResolver()

SymbolResolver::~SymbolResolver ( )

Definition at line 1685 of file symbolresolver.cpp.

1686{
1687}

Member Function Documentation

◆ clearTypeLookupCache()

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

Definition at line 1807 of file symbolresolver.cpp.

1808{
1809 auto &cache = getTypeLookupCache();
1810 switch (scope)
1811 {
1812 case ClearScope::All:
1813 cache.clear();
1814 break;
1816 {
1817 StringVector elementsToRemove;
1818 for (const auto &ci : cache)
1819 {
1820 const LookupInfo &li = ci.second;
1821 if (li.definition==nullptr && li.typeDef==nullptr)
1822 {
1823 elementsToRemove.push_back(ci.first);
1824 }
1825 }
1826 for (const auto &k : elementsToRemove)
1827 {
1828 cache.remove(k);
1829 }
1830 }
1831 break;
1833 {
1834 StringVector elementsToRemove;
1835 for (const auto &ci : cache)
1836 {
1837 const LookupInfo &li = ci.second;
1838 if (li.definition)
1839 {
1840 elementsToRemove.push_back(ci.first);
1841 }
1842 }
1843 for (const auto &k : elementsToRemove)
1844 {
1845 cache.remove(k);
1846 }
1847 }
1848 break;
1849 }
1850}
std::vector< std::string > StringVector
Definition containers.h:33
const Definition * definition
Definition doxygen.h:59
const MemberDef * typeDef
Definition doxygen.h:60
static LookupCache & getTypeLookupCache()

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

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

◆ getResolvedType()

QCString 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 1802 of file symbolresolver.cpp.

1803{
1804 return p->resolvedType;
1805}

References p.

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

◆ getTemplateSpec()

QCString 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 1797 of file symbolresolver.cpp.

1798{
1799 return p->templateSpec;
1800}

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 1792 of file symbolresolver.cpp.

1793{
1794 return p->typeDef;
1795}

References p.

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

◆ 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 1761 of file symbolresolver.cpp.

1762{
1763 AUTO_TRACE("scope={} item={}",
1764 scope?scope->name():QCString(), item?item->name():QCString());
1765 p->reset();
1766 VisitedKeys visitedKeys;
1767 AccessStack accessStack;
1768 int result = p->isAccessibleFrom(visitedKeys,accessStack,scope,item);
1769 AUTO_TRACE_EXIT("result={}",result);
1770 return result;
1771}
virtual const QCString & name() const =0
#define AUTO_TRACE(...)
Definition docnode.cpp:48
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:50
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 QCString & 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 1773 of file symbolresolver.cpp.

1775{
1776 AUTO_TRACE("scope={} item={} explicitScopePart={}",
1777 scope?scope->name():QCString(), item?item->name():QCString(), explicitScopePart);
1778 p->reset();
1779 VisitedKeys visitedKeys;
1780 VisitedNamespaces visitedNamespaces;
1781 AccessStack accessStack;
1782 int result = p->isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,item,explicitScopePart);
1783 AUTO_TRACE_EXIT("result={}",result);
1784 return result;
1785}
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 QCString & 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 1690 of file symbolresolver.cpp.

1694{
1695 AUTO_TRACE("scope={} name={} mayBeUnlinkable={} mayBeHidden={}",
1696 scope?scope->name():QCString(), name, mayBeUnlinkable, mayBeHidden);
1697 p->reset();
1698
1699 auto lang = scope ? scope->getLanguage() :
1700 p->fileScope() ? p->fileScope()->getLanguage() :
1701 SrcLangExt::Cpp; // fallback to C++
1702
1703 if (scope==nullptr ||
1706 ) ||
1707 (name.stripWhiteSpace().startsWith("::")) ||
1708 ((lang==SrcLangExt::Java || lang==SrcLangExt::CSharp) && QCString(name).find("::")!=-1)
1709 )
1710 {
1712 }
1713 const ClassDef *result=nullptr;
1714 if (Config_getBool(OPTIMIZE_OUTPUT_VHDL))
1715 {
1716 result = getClass(name);
1717 }
1718 else
1719 {
1720 VisitedKeys visitedKeys;
1721 QCString lookupName = lang==SrcLangExt::CSharp ? mangleCSharpGenericName(name) : name;
1722 AUTO_TRACE_ADD("lookup={}",lookupName);
1723 result = p->getResolvedTypeRec(getTypeLookupCache(),visitedKeys,scope,lookupName,&p->typeDef,&p->templateSpec,&p->resolvedType);
1724 if (result==nullptr) // for nested classes imported via tag files, the scope may not
1725 // present, so we check the class name directly as well.
1726 // See also bug701314
1727 {
1728 result = getClass(lookupName);
1729 }
1730 }
1731 if (!mayBeUnlinkable && result && !result->isLinkable())
1732 {
1733 if (!mayBeHidden || !result->isHidden())
1734 {
1735 AUTO_TRACE_ADD("hiding symbol {}",result->name());
1736 result=nullptr; // don't link to artificial/hidden classes unless explicitly allowed
1737 }
1738 }
1739 AUTO_TRACE_EXIT("result={}",result?result->name():QCString());
1740 return result;
1741}
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:121
bool startsWith(const char *s) const
Definition qcstring.h:505
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:258
ClassDef * getClass(const QCString &n)
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:49
QCString mangleCSharpGenericName(const QCString &name)
Definition util.cpp:6953

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(), p, QCString::startsWith(), QCString::stripWhiteSpace(), Definition::TypeClass, and Definition::TypeNamespace.

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

◆ resolveClassMutable()

ClassDefMutable * SymbolResolver::resolveClassMutable ( const Definition * scope,
const QCString & 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 QCString &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 QCString & name,
const QCString & args = QCString(),
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 1743 of file symbolresolver.cpp.

1749{
1750 AUTO_TRACE("scope={} name={} args={} checkCV={} insideCode={}",
1751 scope?scope->name():QCString(), name, args, checkCV, insideCode);
1752 p->reset();
1753 if (scope==nullptr) scope=Doxygen::globalScope;
1754 VisitedKeys visitedKeys;
1755 const Definition *result = p->getResolvedSymbolRec(getSymbolLookupCache(),visitedKeys,scope,name,args,checkCV,insideCode,onlyLinkable,&p->typeDef,&p->templateSpec,&p->resolvedType);
1756 AUTO_TRACE_EXIT("result={}{}", qPrint(result?result->qualifiedName():QCString()),
1757 qPrint(result && result->definitionType()==Definition::TypeMember ? toMemberDef(result)->argsString() : QCString()));
1758 return result;
1759}
virtual QCString qualifiedName() const =0
MemberDef * toMemberDef(Definition *d)
const char * qPrint(const char *s)
Definition qcstring.h:685
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 1787 of file symbolresolver.cpp.

1788{
1789 p->setFileScope(fileScope);
1790}

References p.

Referenced by getDefs().

◆ showCacheUsage()

void SymbolResolver::showCacheUsage ( )
static

Show usage of the type lookup cache.

Definition at line 1868 of file symbolresolver.cpp.

1869{
1870 // merge the stats of the main thread
1873
1874 msg("type lookup cache used {}/{} hits={} misses={}\n",
1879 msg("symbol lookup cache used {}/{} hits={} misses={}\n",
1884 int typeCacheParam = computeIdealCacheParam(static_cast<size_t>(g_typeCacheStatistics.misses*2/3)); // part of the cache is flushed, hence the 2/3 correction factor
1885 int symbolCacheParam = computeIdealCacheParam(static_cast<size_t>(g_symbolCacheStatistics.misses*2/3)); // part of the cache is flushed, hence the 2/3 correction factor
1886 int cacheParam = std::max(typeCacheParam,symbolCacheParam);
1887 if (cacheParam>Config_getInt(LOOKUP_CACHE_SIZE))
1888 {
1889 msg("Note: based on cache misses the ideal setting for LOOKUP_CACHE_SIZE is {} at the cost of higher memory usage.\n",cacheParam);
1890 }
1891}
#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, and CacheStatistics::size.

Referenced by generateOutput().

Member Data Documentation

◆ p


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