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

#include <src/symbolresolver.h>

Classes

struct  Private

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.
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.

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.

Constructor & Destructor Documentation

◆ SymbolResolver()

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

Definition at line 1624 of file symbolresolver.cpp.

1625 : p(std::make_unique<Private>(fileScope))
1626{
1627}
std::unique_ptr< Private > p

References p.

◆ ~SymbolResolver()

SymbolResolver::~SymbolResolver ( )

Definition at line 1629 of file symbolresolver.cpp.

1630{
1631}

Member Function Documentation

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

1747{
1748 return p->resolvedType;
1749}

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

1742{
1743 return p->templateSpec;
1744}

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

1737{
1738 return p->typeDef;
1739}

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

1706{
1707 AUTO_TRACE("scope={} item={}",
1708 scope?scope->name():QCString(), item?item->name():QCString());
1709 p->reset();
1710 VisitedKeys visitedKeys;
1711 AccessStack accessStack;
1712 int result = p->isAccessibleFrom(visitedKeys,accessStack,scope,item);
1713 AUTO_TRACE_EXIT("result={}",result);
1714 return result;
1715}
virtual const QCString & name() const =0
#define AUTO_TRACE(...)
Definition docnode.cpp:46
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:48
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 1717 of file symbolresolver.cpp.

1719{
1720 AUTO_TRACE("scope={} item={} explicitScopePart={}",
1721 scope?scope->name():QCString(), item?item->name():QCString(), explicitScopePart);
1722 p->reset();
1723 VisitedKeys visitedKeys;
1724 VisitedNamespaces visitedNamespaces;
1725 AccessStack accessStack;
1726 int result = p->isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,item,explicitScopePart);
1727 AUTO_TRACE_EXIT("result={}",result);
1728 return result;
1729}
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 1634 of file symbolresolver.cpp.

1638{
1639 AUTO_TRACE("scope={} name={} mayBeUnlinkable={} mayBeHidden={}",
1640 scope?scope->name():QCString(), name, mayBeUnlinkable, mayBeHidden);
1641 p->reset();
1642
1643 auto lang = scope ? scope->getLanguage() :
1644 p->fileScope() ? p->fileScope()->getLanguage() :
1645 SrcLangExt::Cpp; // fallback to C++
1646
1647 if (scope==nullptr ||
1650 ) ||
1651 (name.stripWhiteSpace().startsWith("::")) ||
1652 ((lang==SrcLangExt::Java || lang==SrcLangExt::CSharp) && QCString(name).find("::")!=-1)
1653 )
1654 {
1656 }
1657 const ClassDef *result=nullptr;
1658 if (Config_getBool(OPTIMIZE_OUTPUT_VHDL))
1659 {
1660 result = getClass(name);
1661 }
1662 else
1663 {
1664 VisitedKeys visitedKeys;
1665 QCString lookupName = lang==SrcLangExt::CSharp ? mangleCSharpGenericName(name) : name;
1666 AUTO_TRACE_ADD("lookup={}",lookupName);
1667 result = p->getResolvedTypeRec(visitedKeys,scope,lookupName,&p->typeDef,&p->templateSpec,&p->resolvedType);
1668 if (result==nullptr) // for nested classes imported via tag files, the scope may not
1669 // present, so we check the class name directly as well.
1670 // See also bug701314
1671 {
1672 result = getClass(lookupName);
1673 }
1674 }
1675 if (!mayBeUnlinkable && result && !result->isLinkable())
1676 {
1677 if (!mayBeHidden || !result->isHidden())
1678 {
1679 AUTO_TRACE_ADD("hiding symbol {}",result->name());
1680 result=nullptr; // don't link to artificial/hidden classes unless explicitly allowed
1681 }
1682 }
1683 AUTO_TRACE_EXIT("result={}",result?result->name():QCString());
1684 return result;
1685}
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:507
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
ClassDef * getClass(const QCString &n)
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:47
QCString mangleCSharpGenericName(const QCString &name)
Definition util.cpp:6850

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, Config_getBool, Definition::definitionType(), getClass(), Definition::getLanguage(), 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 1687 of file symbolresolver.cpp.

1693{
1694 AUTO_TRACE("scope={} name={} args={} checkCV={} insideCode={}",
1695 scope?scope->name():QCString(), name, args, checkCV, insideCode);
1696 p->reset();
1697 if (scope==nullptr) scope=Doxygen::globalScope;
1698 VisitedKeys visitedKeys;
1699 const Definition *result = p->getResolvedSymbolRec(visitedKeys,scope,name,args,checkCV,insideCode,onlyLinkable,&p->typeDef,&p->templateSpec,&p->resolvedType);
1700 AUTO_TRACE_EXIT("result={}{}", qPrint(result?result->qualifiedName():QCString()),
1701 qPrint(result && result->definitionType()==Definition::TypeMember ? toMemberDef(result)->argsString() : QCString()));
1702 return result;
1703}
virtual QCString qualifiedName() const =0
MemberDef * toMemberDef(Definition *d)
const char * qPrint(const char *s)
Definition qcstring.h:687

References AUTO_TRACE, AUTO_TRACE_EXIT, Definition::definitionType(), 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 1731 of file symbolresolver.cpp.

1732{
1733 p->setFileScope(fileScope);
1734}

References p.

Referenced by getDefs().

Member Data Documentation

◆ p


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