clang API Documentation

Classes | Public Types | Public Member Functions | Static Public Member Functions
clang::LookupResult Class Reference

Represents the results of name lookup. More...

#include <Lookup.h>

List of all members.

Classes

class  Filter

Public Types

enum  LookupResultKind {
  NotFound = 0, NotFoundInCurrentInstantiation, Found, FoundOverloaded,
  FoundUnresolvedValue, Ambiguous
}
enum  AmbiguityKind { AmbiguousBaseSubobjectTypes, AmbiguousBaseSubobjects, AmbiguousReference, AmbiguousTagHiding }
enum  TemporaryToken { Temporary }
 A little identifier for flagging temporary lookup results. More...
typedef UnresolvedSetImpl::iterator iterator

Public Member Functions

 LookupResult (Sema &SemaRef, const DeclarationNameInfo &NameInfo, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl=Sema::NotForRedeclaration)
 LookupResult (Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl=Sema::NotForRedeclaration)
 LookupResult (TemporaryToken _, const LookupResult &Other)
 ~LookupResult ()
const DeclarationNameInfogetLookupNameInfo () const
 Gets the name info to look up.
void setLookupNameInfo (const DeclarationNameInfo &NameInfo)
 Sets the name info to look up.
DeclarationName getLookupName () const
 Gets the name to look up.
void setLookupName (DeclarationName Name)
 Sets the name to look up.
Sema::LookupNameKind getLookupKind () const
 Gets the kind of lookup to perform.
bool isForRedeclaration () const
 True if this lookup is just looking for an existing declaration.
void setAllowHidden (bool AH)
 Specify whether hidden declarations are visible, e.g., for recovery reasons.
bool isHiddenDeclarationVisible () const
 Determine whether this lookup is permitted to see hidden declarations, such as those in modules that have not yet been imported.
void setHideTags (bool Hide)
bool isAmbiguous () const
bool isSingleResult () const
bool isOverloadedResult () const
 Determines if the results are overloaded.
bool isUnresolvableResult () const
LookupResultKind getResultKind () const
AmbiguityKind getAmbiguityKind () const
const UnresolvedSetImplasUnresolvedSet () const
iterator begin () const
iterator end () const
bool empty () const
 Return true if no decls were found.
CXXBasePathsgetBasePaths () const
 Return the base paths structure that's associated with these results, or null if none is.
NamedDeclgetAcceptableDecl (NamedDecl *D) const
 Retrieve the accepted (re)declaration of the given declaration, if there is one.
unsigned getIdentifierNamespace () const
 Returns the identifier namespace mask for this lookup.
bool isClassLookup () const
 Returns whether these results arose from performing a lookup into a class.
CXXRecordDeclgetNamingClass () const
 Returns the 'naming class' for this lookup, i.e. the class which was looked into to find these results.
void setNamingClass (CXXRecordDecl *Record)
 Sets the 'naming class' for this lookup.
QualType getBaseObjectType () const
 Returns the base object type associated with this lookup; important for [class.protected]. Most lookups do not have an associated base object.
void setBaseObjectType (QualType T)
 Sets the base object type for this lookup.
void addDecl (NamedDecl *D)
 Add a declaration to these results with its natural access. Does not test the acceptance criteria.
void addDecl (NamedDecl *D, AccessSpecifier AS)
 Add a declaration to these results with the given access. Does not test the acceptance criteria.
void addAllDecls (const LookupResult &Other)
 Add all the declarations from another set of lookup results.
bool wasNotFoundInCurrentInstantiation () const
 Determine whether no result was found because we could not search into dependent base classes of the current instantiation.
void setNotFoundInCurrentInstantiation ()
 Note that while no result was found in the current instantiation, there were dependent base classes that could not be searched.
bool isShadowed () const
 Determine whether the lookup result was shadowed by some other declaration that lookup ignored.
void setShadowed ()
 Note that we found and ignored a declaration while performing lookup.
void resolveKind ()
 Resolves the result kind of the lookup, possibly hiding decls.
void resolveKindAfterFilter ()
 Re-resolves the result kind of the lookup after a set of removals has been performed.
template<class DeclClass >
DeclClass * getAsSingle () const
NamedDeclgetFoundDecl () const
 Fetch the unique decl found by this lookup. Asserts that one was found.
NamedDeclgetRepresentativeDecl () const
 Fetches a representative decl. Useful for lazy diagnostics.
bool isSingleTagDecl () const
 Asks if the result is a single tag decl.
void setAmbiguousBaseSubobjectTypes (CXXBasePaths &P)
 Make these results show that the name was found in base classes of different types.
void setAmbiguousBaseSubobjects (CXXBasePaths &P)
 Make these results show that the name was found in distinct base classes of the same type.
void setAmbiguousQualifiedTagHiding ()
 Make these results show that the name was found in different contexts and a tag decl was hidden by an ordinary decl in a different context.
void clear ()
 Clears out any current state.
void clear (Sema::LookupNameKind Kind)
 Clears out any current state and re-initializes for a different kind of lookup.
void setRedeclarationKind (Sema::RedeclarationKind RK)
 Change this lookup's redeclaration kind.
void print (raw_ostream &)
void suppressDiagnostics ()
bool isSuppressingDiagnostics () const
 Determines whether this lookup is suppressing diagnostics.
void setContextRange (SourceRange SR)
 Sets a 'context' source range.
SourceRange getContextRange () const
SourceLocation getNameLoc () const
SemagetSema () const
 Get the Sema object that this lookup result is searching with.
Filter makeFilter ()
 Create a filter for this result set.
void setFindLocalExtern (bool FindLocalExtern)

Static Public Member Functions

static bool isVisible (Sema &SemaRef, NamedDecl *D)
 Determine whether the given declaration is visible to the program.

Detailed Description

Represents the results of name lookup.

An instance of the LookupResult class captures the results of a single name lookup, which can return no result (nothing found), a single declaration, a set of overloaded functions, or an ambiguity. Use the getKind() method to determine which of these results occurred for a given lookup.

Definition at line 30 of file Lookup.h.


Member Typedef Documentation

Definition at line 127 of file Lookup.h.


Member Enumeration Documentation

Enumerator:
AmbiguousBaseSubobjectTypes 

Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were found in subobjects of different types. For example:

 struct A { void f(int); }
 struct B { void f(double); }
 struct C : A, B { };
 void test(C c) {
   c.f(0); // error: A::f and B::f come from subobjects of different
           // types. overload resolution is not performed.
 }
AmbiguousBaseSubobjects 

Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria were found in different subobjects of the same type. For example:

 struct A { int x; };
 struct B : A { };
 struct C : A { };
 struct D : B, C { };
 int test(D d) {
   return d.x; // error: 'x' is found in two A subobjects (of B and C)
 }
AmbiguousReference 

Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup criteria were found in different declaration contexts.

 namespace A {
   int i;
   namespace B { int i; }
   int test() {
     using namespace B;
     return i; // error 'i' is found in namespace A and A::B
    }
 }
AmbiguousTagHiding 

Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an ordinary name from a different context.

 namespace A { struct Foo {}; }
 namespace B { void Foo(); }
 namespace C {
   using namespace A;
   using namespace B;
 }
 void test() {
   C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
             // different namespace
 }

Definition at line 60 of file Lookup.h.

Enumerator:
NotFound 

No entity found met the criteria.

NotFoundInCurrentInstantiation 

No entity found met the criteria within the current instantiation,, but there were dependent base classes of the current instantiation that could not be searched.

Found 

Name lookup found a single declaration that met the criteria. getFoundDecl() will return this declaration.

FoundOverloaded 

Name lookup found a set of overloaded functions that met the criteria.

FoundUnresolvedValue 

Name lookup found an unresolvable value declaration and cannot yet complete. This only happens in C++ dependent contexts with dependent using declarations.

Ambiguous 

Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we have.

Definition at line 32 of file Lookup.h.

A little identifier for flagging temporary lookup results.

Enumerator:
Temporary 

Definition at line 123 of file Lookup.h.


Constructor & Destructor Documentation

Definition at line 129 of file Lookup.h.

Definition at line 151 of file Lookup.h.

clang::LookupResult::LookupResult ( TemporaryToken  _,
const LookupResult Other 
) [inline]

Creates a temporary lookup result, initializing its core data using the information from another result. Diagnostics are always disabled.

Definition at line 173 of file Lookup.h.

Definition at line 188 of file Lookup.h.


Member Function Documentation

void clang::LookupResult::addAllDecls ( const LookupResult Other) [inline]

Add all the declarations from another set of lookup results.

Definition at line 382 of file Lookup.h.

References clang::UnresolvedSetImpl::append(), clang::UnresolvedSetImpl::begin(), clang::UnresolvedSetImpl::end(), and Found.

Referenced by LookupQualifiedNameInUsingDirectives().

void clang::LookupResult::addDecl ( NamedDecl D) [inline]
void clang::LookupResult::addDecl ( NamedDecl D,
AccessSpecifier  AS 
) [inline]

Add a declaration to these results with the given access. Does not test the acceptance criteria.

Definition at line 375 of file Lookup.h.

References clang::UnresolvedSetImpl::addDecl(), and Found.

Definition at line 275 of file Lookup.h.

References clang::UnresolvedSetImpl::begin().

Referenced by clang::Sema::ActOnExplicitInstantiation(), clang::Sema::ActOnIdExpression(), clang::Sema::ActOnTag(), clang::Sema::AddMemberOperatorCandidates(), clang::Sema::BuildCallToObjectOfClassType(), clang::Sema::BuildDeclarationNameExpr(), clang::Sema::BuildMemberReferenceExpr(), clang::Sema::BuildOverloadedArrowExpr(), clang::Sema::BuildQualifiedDeclarationNameExpr(), buildSingleCopyAssignRecursively(), clang::Sema::BuildTemplateIdExpr(), clang::Sema::BuildUsingDeclaration(), clang::Sema::CheckClassTemplate(), clang::Sema::CheckFunctionTemplateSpecialization(), checkGlobalOrExternCConflict(), clang::Sema::CheckLookupAccess(), clang::Sema::CheckMemberSpecialization(), clang::Sema::CheckOverload(), clang::Sema::CheckQualifiedMemberReference(), clang::Sema::CheckTypenameType(), clang::Sema::CheckUsingDeclRedeclaration(), clang::Sema::CheckUsingShadowDecl(), ClassifyImplicitMemberAccess(), clang::Sema::ClassifyName(), clang::Sema::DiagnoseEmptyLookup(), DiagnoseInvalidRedeclaration(), DiagnoseTwoPhaseLookup(), clang::Sema::FindAllocationFunctions(), clang::Sema::FindAllocationOverload(), clang::Sema::FindDeallocationFunction(), clang::Sema::FindUsualDeallocationFunction(), getFoundDecl(), getRepresentativeDecl(), clang::Sema::getTypeName(), clang::Sema::hasAnyAcceptableTemplateNames(), HasNoThrowOperator(), isResultTypeOrTemplate(), isTagTypeWithMissingTag(), clang::Sema::LookupLiteralOperator(), clang::Sema::LookupOverloadedOperatorName(), clang::LookupResult::Filter::restart(), and clang::Sema::UseArgumentDependentLookup().

void clang::LookupResult::clear ( ) [inline]

Clears out any current state and re-initializes for a different kind of lookup.

Definition at line 508 of file Lookup.h.

References clear().

bool clang::LookupResult::empty ( ) const [inline]

Return true if no decls were found.

Definition at line 279 of file Lookup.h.

References clang::UnresolvedSetImpl::empty().

Referenced by clang::Sema::ActOnAliasDeclaration(), clang::Sema::ActOnFriendFunctionDecl(), clang::Sema::ActOnFunctionDeclarator(), clang::Sema::ActOnIdExpression(), clang::Sema::ActOnNamespaceAliasDef(), clang::Sema::ActOnOpenMPIdExpression(), clang::Sema::ActOnStartOfLambdaDefinition(), clang::Sema::ActOnTag(), clang::Sema::ActOnTypedefNameDecl(), clang::Sema::ActOnUsingDirective(), clang::Sema::ActOnVariableDeclarator(), clang::Sema::BuildCXXNestedNameSpecifier(), clang::Sema::BuildForRangeBeginEndCall(), clang::Sema::BuildImplicitMemberExpr(), clang::Sema::BuildMemberReferenceExpr(), clang::Sema::BuildMemInitializer(), BuildNonArrayForRange(), clang::Sema::BuildQualifiedDeclarationNameExpr(), clang::Sema::BuildQualifiedTemplateIdExpr(), clang::Sema::BuildTemplateIdExpr(), clang::Sema::BuildUsingDeclaration(), clang::Sema::CheckDependentFunctionTemplateSpecialization(), clang::Sema::CheckFunctionDeclaration(), clang::Sema::CheckMemberSpecialization(), clang::Sema::CheckUsingShadowDecl(), clang::Sema::CheckVariableDeclaration(), ClassifyImplicitMemberAccess(), clang::Sema::ClassifyName(), clang::Sema::DiagnoseEmptyLookup(), DiagnoseTwoPhaseLookup(), doesUsualArrayDeleteWantSize(), filterNonConflictingPreviousDecls(), filterNonConflictingPreviousTypedefDecls(), clang::Sema::FindAllocationFunctions(), clang::Sema::FindAllocationOverload(), clang::Sema::FindDeallocationFunction(), clang::Sema::getTypeName(), clang::Sema::LookupInObjCMethod(), clang::Sema::LookupInSuper(), LookupMemberExprInRecord(), LookupPotentialTypoResult(), LookupQualifiedNameInUsingDirectives(), clang::Sema::LookupTemplateName(), clang::MultiplexExternalSemaSource::LookupUnqualified(), and clang::TemplateDeclInstantiator::VisitCXXMethodDecl().

iterator clang::LookupResult::end ( ) const [inline]

Retrieve the accepted (re)declaration of the given declaration, if there is one.

Definition at line 304 of file Lookup.h.

References getSema(), isHiddenDeclarationVisible(), clang::Decl::isInIdentifierNamespace(), and isVisible().

Referenced by LookupDirect(), clang::Sema::LookupName(), and LookupVisibleDecls().

Definition at line 266 of file Lookup.h.

References isAmbiguous().

Referenced by clang::Sema::DiagnoseAmbiguousLookup(), and clang::Sema::getTypeName().

template<class DeclClass >
DeclClass* clang::LookupResult::getAsSingle ( ) const [inline]

Returns the base object type associated with this lookup; important for [class.protected]. Most lookups do not have an associated base object.

Definition at line 358 of file Lookup.h.

Referenced by clang::Sema::CheckLookupAccess().

Return the base paths structure that's associated with these results, or null if none is.

Definition at line 283 of file Lookup.h.

Referenced by clang::Sema::DiagnoseAmbiguousLookup().

Gets the source range of the context of this name; for C++ qualified lookups, this is the source range of the scope specifier.

Definition at line 542 of file Lookup.h.

Referenced by clang::Sema::DiagnoseAmbiguousLookup().

Returns the identifier namespace mask for this lookup.

Definition at line 320 of file Lookup.h.

Returns the 'naming class' for this lookup, i.e. the class which was looked into to find these results.

C++0x [class.access.base]p5: The access to a member is affected by the class in which the member is named. This naming class is the class in which the member name was looked up and found. [Note: this class can be explicit, e.g., when a qualified-id is used, or implicit, e.g., when a class member access operator (5.2.5) is used (including cases where an implicit "this->" is added). If both a class member access operator and a qualified-id are used to name the member (as in p->T::m), the class naming the member is the class named by the nested-name-specifier of the qualified-id (that is, T). -- end note ]

This is set by the lookup routines when they find results in a class.

Definition at line 346 of file Lookup.h.

Referenced by clang::Sema::BuildDeclarationNameExpr(), clang::Sema::BuildTemplateIdExpr(), clang::Sema::CheckLookupAccess(), ClassifyImplicitMemberAccess(), clang::Sema::FindAllocationFunctions(), clang::Sema::FindAllocationOverload(), and clang::Sema::FindDeallocationFunction().

Sema& clang::LookupResult::getSema ( ) const [inline]

Get the Sema object that this lookup result is searching with.

Definition at line 554 of file Lookup.h.

Referenced by getAcceptableDecl(), isResultTypeOrTemplate(), LookupDirect(), and LookupVisibleDecls().

Returns whether these results arose from performing a lookup into a class.

Definition at line 326 of file Lookup.h.

True if this lookup is just looking for an existing declaration.

Definition at line 219 of file Lookup.h.

Referenced by clang::Sema::ActOnTag(), LookupBuiltin(), LookupDirect(), clang::Sema::LookupInObjCMethod(), and clang::Sema::LookupQualifiedName().

Determine whether this lookup is permitted to see hidden declarations, such as those in modules that have not yet been imported.

Definition at line 231 of file Lookup.h.

References clang::Sema::LookupTagName.

Referenced by getAcceptableDecl().

Determines if the results are overloaded.

Definition at line 253 of file Lookup.h.

References FoundOverloaded, and getResultKind().

Referenced by clang::Sema::ActOnIdExpression(), clang::Sema::BuildDeclarationNameExpr(), and clang::Sema::BuildMemberReferenceExpr().

Determine whether the lookup result was shadowed by some other declaration that lookup ignored.

Definition at line 402 of file Lookup.h.

Referenced by clang::Sema::ActOnVariableDeclarator(), clang::Sema::CheckFunctionDeclaration(), and mergeTypeWithPrevious().

Asks if the result is a single tag decl.

Definition at line 473 of file Lookup.h.

References Found, getFoundDecl(), and getResultKind().

Referenced by clang::Sema::HandleDeclarator(), LookupQualifiedNameInUsingDirectives(), and clang::TemplateDeclInstantiator::VisitCXXMethodDecl().

Determines whether this lookup is suppressing diagnostics.

Definition at line 530 of file Lookup.h.

Referenced by clang::Sema::LookupTemplateName().

static bool clang::LookupResult::isVisible ( Sema SemaRef,
NamedDecl D 
) [inline, static]

Determine whether the given declaration is visible to the program.

Definition at line 289 of file Lookup.h.

References clang::Sema::ActiveTemplateInstantiations, and clang::NamedDecl::isHidden().

Referenced by checkCorrectionVisibility(), findAcceptableDecl(), clang::TypoCorrectionConsumer::FoundDecl(), getAcceptableDecl(), and hasVisibleDefinition().

void LookupResult::print ( raw_ostream &  Out)

Definition at line 499 of file SemaLookup.cpp.

Re-resolves the result kind of the lookup after a set of removals has been performed.

Definition at line 417 of file Lookup.h.

References Ambiguous, clang::UnresolvedSetImpl::empty(), Found, NotFound, NotFoundInCurrentInstantiation, and resolveKind().

Referenced by clang::LookupResult::Filter::done().

Specify whether hidden declarations are visible, e.g., for recovery reasons.

Definition at line 225 of file Lookup.h.

Referenced by LookupPotentialTypoResult(), and clang::Sema::LookupVisibleDecls().

Make these results show that the name was found in distinct base classes of the same type.

The given paths object is copied and invalidated.

Definition at line 483 of file SemaLookup.cpp.

References clang::CXXBasePaths::swap().

Referenced by clang::Sema::LookupQualifiedName().

Make these results show that the name was found in base classes of different types.

The given paths object is copied and invalidated.

Definition at line 491 of file SemaLookup.cpp.

References clang::CXXBasePaths::swap().

Referenced by clang::Sema::LookupQualifiedName().

Make these results show that the name was found in different contexts and a tag decl was hidden by an ordinary decl in a different context.

Definition at line 492 of file Lookup.h.

References AmbiguousTagHiding.

Referenced by LookupQualifiedNameInUsingDirectives().

Sets the base object type for this lookup.

Definition at line 363 of file Lookup.h.

Referenced by clang::Sema::BuildMemberReferenceExpr(), clang::Sema::BuildUsingDeclaration(), and clang::Sema::LookupInSuper().

Sets a 'context' source range.

Definition at line 535 of file Lookup.h.

Referenced by clang::Sema::BuildCXXNestedNameSpecifier(), clang::Sema::isNonTypeNestedNameSpecifier(), and clang::Sema::LookupParsedName().

void clang::LookupResult::setFindLocalExtern ( bool  FindLocalExtern) [inline]

Definition at line 623 of file Lookup.h.

References clang::Decl::IDNS_LocalExtern.

void clang::LookupResult::setHideTags ( bool  Hide) [inline]

Sets whether tag declarations should be hidden by non-tag declarations during resolution. The default is true.

Definition at line 237 of file Lookup.h.

Referenced by clang::Sema::BuildUsingDeclaration(), and clang::Sema::CheckUsingDeclQualifier().

void clang::LookupResult::setLookupNameInfo ( const DeclarationNameInfo NameInfo) [inline]

Sets the name info to look up.

Definition at line 199 of file Lookup.h.

Sets the 'naming class' for this lookup.

Definition at line 351 of file Lookup.h.

References Record.

Referenced by clang::Sema::DiagnoseEmptyLookup(), and clang::Sema::LookupQualifiedName().

Note that while no result was found in the current instantiation, there were dependent base classes that could not be searched.

Definition at line 395 of file Lookup.h.

References clang::UnresolvedSetImpl::empty(), NotFound, and NotFoundInCurrentInstantiation.

Referenced by clang::Sema::LookupParsedName(), and clang::Sema::LookupQualifiedName().

Change this lookup's redeclaration kind.

Definition at line 515 of file Lookup.h.

References clang::Sema::ForRedeclaration.

Referenced by clang::Sema::ActOnTag().

Note that we found and ignored a declaration while performing lookup.

Definition at line 406 of file Lookup.h.

Referenced by clang::Sema::CheckVariableDeclaration(), and clang::Sema::LookupName().

Determine whether no result was found because we could not search into dependent base classes of the current instantiation.

Definition at line 389 of file Lookup.h.

References NotFoundInCurrentInstantiation.

Referenced by clang::Sema::ActOnTag().


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