14#ifndef LLVM_CLANG_SEMA_LOOKUP_H
15#define LLVM_CLANG_SEMA_LOOKUP_H
28#include "llvm/ADT/MapVector.h"
29#include "llvm/ADT/STLExtras.h"
30#include "llvm/Support/Casting.h"
148 : SemaPtr(&SemaRef), NameInfo(NameInfo), LookupKind(LookupKind),
149 Redecl(Redecl !=
Sema::NotForRedeclaration),
150 ExternalRedecl(Redecl ==
Sema::ForExternalRedeclaration),
151 Diagnose(Redecl ==
Sema::NotForRedeclaration) {
161 : SemaPtr(&SemaRef), NameInfo(Name, NameLoc), LookupKind(LookupKind),
162 Redecl(Redecl !=
Sema::NotForRedeclaration),
163 ExternalRedecl(Redecl ==
Sema::ForExternalRedeclaration),
164 Diagnose(Redecl ==
Sema::NotForRedeclaration) {
172 : SemaPtr(Other.SemaPtr), NameInfo(Other.NameInfo),
173 LookupKind(Other.LookupKind), IDNS(Other.IDNS), Redecl(Other.Redecl),
174 ExternalRedecl(Other.ExternalRedecl), HideTags(Other.HideTags),
175 AllowHidden(Other.AllowHidden),
176 TemplateNameLookup(Other.TemplateNameLookup) {}
184 : ResultKind(
std::move(Other.ResultKind)),
185 Ambiguity(
std::move(Other.Ambiguity)), Decls(
std::move(Other.Decls)),
186 Paths(
std::move(Other.Paths)),
187 NamingClass(
std::move(Other.NamingClass)),
188 BaseObjectType(
std::move(Other.BaseObjectType)),
189 SemaPtr(
std::move(Other.SemaPtr)), NameInfo(
std::move(Other.NameInfo)),
190 NameContextRange(
std::move(Other.NameContextRange)),
191 LookupKind(
std::move(Other.LookupKind)), IDNS(
std::move(Other.IDNS)),
192 Redecl(
std::move(Other.Redecl)),
193 ExternalRedecl(
std::move(Other.ExternalRedecl)),
194 HideTags(
std::move(Other.HideTags)),
195 Diagnose(
std::move(Other.Diagnose)),
196 AllowHidden(
std::move(Other.AllowHidden)),
197 Shadowed(
std::move(Other.Shadowed)),
198 TemplateNameLookup(
std::move(Other.TemplateNameLookup)) {
199 Other.Paths =
nullptr;
200 Other.Diagnose =
false;
204 ResultKind = std::move(Other.ResultKind);
205 Ambiguity = std::move(Other.Ambiguity);
206 Decls = std::move(Other.Decls);
207 Paths = std::move(Other.Paths);
208 NamingClass = std::move(Other.NamingClass);
209 BaseObjectType = std::move(Other.BaseObjectType);
210 SemaPtr = std::move(Other.SemaPtr);
211 NameInfo = std::move(Other.NameInfo);
212 NameContextRange = std::move(Other.NameContextRange);
213 LookupKind = std::move(Other.LookupKind);
214 IDNS = std::move(Other.IDNS);
215 Redecl = std::move(Other.Redecl);
216 ExternalRedecl = std::move(Other.ExternalRedecl);
217 HideTags = std::move(Other.HideTags);
218 Diagnose = std::move(Other.Diagnose);
219 AllowHidden = std::move(Other.AllowHidden);
220 Shadowed = std::move(Other.Shadowed);
221 TemplateNameLookup = std::move(Other.TemplateNameLookup);
222 Other.Paths =
nullptr;
223 Other.Diagnose =
false;
228 if (Diagnose) diagnose();
229 if (Paths) deletePaths(Paths);
239 this->NameInfo = NameInfo;
265 return ExternalRedecl;
282 return AllowHidden ||
322 assert(checkDebugAssumptions());
392 return getAcceptableDeclSlow(D);
410 return NamingClass !=
nullptr;
435 NamingClass = Record;
442 return BaseObjectType;
466 Decls.
append(Other.Decls.begin(), Other.Decls.end());
510 std::optional<AmbiguityKind> SavedAK;
511 bool WasAmbiguous =
false;
523 assert(WasAmbiguous);
524 Ambiguity = *SavedAK;
532 template <
class DeclClass>
545 &&
"getFoundDecl called on non-unique result");
546 return (*
begin())->getUnderlyingDecl();
551 assert(!Decls.
empty() &&
"cannot get representative of empty set");
580 LLVM_ATTRIBUTE_REINITIALIZES
void clear() {
583 if (Paths) deletePaths(Paths);
585 NamingClass =
nullptr;
605 void print(raw_ostream &);
620 NameContextRange = SR;
627 return NameContextRange;
648 bool Changed =
false;
649 bool CalledDone =
false;
655 : Results(F.Results), I(F.I), Changed(F.Changed),
656 CalledDone(F.CalledDone) {
662 "LookupResult::Filter destroyed without done() call");
666 return I != Results.end();
670 assert(I != Results.end() &&
"next() called on empty filter");
681 Results.Decls.erase(--I);
688 Results.Decls.replace(I-1, D);
694 Results.Decls.replace(I-1, D, AS);
699 assert(!CalledDone &&
"done() called twice");
703 Results.resolveKindAfterFilter();
716 IDNS &=
~Decl::IDNS_LocalExtern;
732 void addDeclsFromBasePaths(
const CXXBasePaths &
P);
735 bool checkDebugAssumptions()
const;
737 bool checkUnresolved()
const {
739 if (isa<UnresolvedUsingValueDecl>((*I)->getUnderlyingDecl()))
744 static void deletePaths(CXXBasePaths *);
751 UnresolvedSet<8> Decls;
752 CXXBasePaths *Paths =
nullptr;
753 CXXRecordDecl *NamingClass =
nullptr;
754 QualType BaseObjectType;
758 DeclarationNameInfo NameInfo;
759 SourceRange NameContextRange;
768 bool HideTags =
true;
770 bool Diagnose =
false;
773 bool AllowHidden =
false;
778 bool Shadowed =
false;
781 bool TemplateNameLookup =
false;
813 bool InBaseClass) = 0;
826 llvm::MapVector<NamedDecl*, NamedDecl*> Decls;
828 struct select_second {
829 NamedDecl *operator()(std::pair<NamedDecl*, NamedDecl*>
P)
const {
844 llvm::mapped_iterator<
decltype(Decls)
::iterator, select_second>;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
A class for storing results from argument-dependent lookup.
void insert(NamedDecl *D)
Adds a new ADL candidate to this map.
void erase(NamedDecl *D)
Removes any data associated with a given decl.
llvm::mapped_iterator< decltype(Decls)::iterator, select_second > iterator
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a C++ struct/union/class.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
bool isInIdentifierNamespace(unsigned NS) const
@ IDNS_LocalExtern
This declaration is a function-local extern declaration of a variable or function.
AccessSpecifier getAccess() const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
A class for iterating through a result set and possibly filtering out results.
void replace(NamedDecl *D)
Replaces the current entry with the given one, preserving the access bits.
void restart()
Restart the iteration.
void erase()
Erase the last element returned from this iterator.
void replace(NamedDecl *D, AccessSpecifier AS)
Replaces the current entry with the given one.
Represents the results of name lookup.
void setLookupNameInfo(const DeclarationNameInfo &NameInfo)
Sets the name info to look up.
void resolveKindAfterFilter()
Re-resolves the result kind of the lookup after a set of removals has been performed.
void addAllDecls(const LookupResult &Other)
Add all the declarations from another set of lookup results.
@ 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.
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ NotFound
No entity found met the criteria.
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
@ Found
Name lookup found a single declaration that met the criteria.
bool wasNotFoundInCurrentInstantiation() const
Determine whether no result was found because we could not search into dependent base classes of the ...
void setShadowed()
Note that we found and ignored a declaration while performing lookup.
static bool isAvailableForLookup(Sema &SemaRef, NamedDecl *ND)
Determine whether this lookup is permitted to see the declaration.
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl=Sema::NotForRedeclaration)
LookupResult(TemporaryToken _, const LookupResult &Other)
Creates a temporary lookup result, initializing its core data using the information from another resu...
SourceRange getContextRange() const
Gets the source range of the context of this name; for C++ qualified lookups, this is the source rang...
void setTemplateNameLookup(bool TemplateName)
Sets whether this is a template-name lookup.
void setFindLocalExtern(bool FindLocalExtern)
bool isUnresolvableResult() const
void setBaseObjectType(QualType T)
Sets the base object type for this lookup.
void setAllowHidden(bool AH)
Specify whether hidden declarations are visible, e.g., for recovery reasons.
DeclClass * getAsSingle() const
void addDecl(NamedDecl *D, AccessSpecifier AS)
Add a declaration to these results with the given access.
void setContextRange(SourceRange SR)
Sets a 'context' source range.
static bool isAcceptable(Sema &SemaRef, NamedDecl *D, Sema::AcceptableKind Kind)
void setAmbiguousQualifiedTagHiding()
Make these results show that the name was found in different contexts and a tag decl was hidden by an...
bool isForExternalRedeclaration() const
True if this lookup is just looking for an existing declaration to link against a declaration with ex...
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
bool isTemplateNameLookup() const
void setAmbiguousBaseSubobjects(CXXBasePaths &P)
Make these results show that the name was found in distinct base classes of the same type.
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
void setLookupName(DeclarationName Name)
Sets the name to look up.
bool empty() const
Return true if no decls were found.
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
AmbiguityKind getAmbiguityKind() const
bool isOverloadedResult() const
Determines if the results are overloaded.
SourceLocation getNameLoc() const
Gets the location of the identifier.
void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P)
Make these results show that the name was found in base classes of different types.
CXXBasePaths * getBasePaths() const
Return the base paths structure that's associated with these results, or null if none is.
Filter makeFilter()
Create a filter for this result set.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
void setHideTags(bool Hide)
Sets whether tag declarations should be hidden by non-tag declarations during resolution.
LookupResult & operator=(LookupResult &&Other)
NamedDecl * getAcceptableDecl(NamedDecl *D) const
Retrieve the accepted (re)declaration of the given declaration, if there is one.
bool isSuppressingDiagnostics() const
Determines whether this lookup is suppressing diagnostics.
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
unsigned getIdentifierNamespace() const
Returns the identifier namespace mask for this lookup.
CXXRecordDecl * getNamingClass() const
Returns the 'naming class' for this lookup, i.e.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
QualType getBaseObjectType() const
Returns the base object type associated with this lookup; important for [class.protected].
LookupResult(const LookupResult &)=delete
LookupResult & operator=(const LookupResult &)=delete
const UnresolvedSetImpl & asUnresolvedSet() const
UnresolvedSetImpl::iterator iterator
void clear(Sema::LookupNameKind Kind)
Clears out any current state and re-initializes for a different kind of lookup.
LookupResult(LookupResult &&Other)
bool isClassLookup() const
Returns whether these results arose from performing a lookup into a class.
LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl=Sema::NotForRedeclaration)
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
LookupResultKind getResultKind() const
void setRedeclarationKind(Sema::RedeclarationKind RK)
Change this lookup's redeclaration kind.
void print(raw_ostream &)
static bool isReachable(Sema &SemaRef, NamedDecl *D)
TemporaryToken
A little identifier for flagging temporary lookup results.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
bool isForRedeclaration() const
True if this lookup is just looking for an existing declaration.
DeclarationName getLookupName() const
Gets the name to look up.
bool isHiddenDeclarationVisible(NamedDecl *ND) const
Determine whether this lookup is permitted to see hidden declarations, such as those in modules that ...
Sema::RedeclarationKind redeclarationKind() const
@ AmbiguousTagHiding
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
@ AmbiguousBaseSubobjectTypes
Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were foun...
@ AmbiguousReference
Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup crite...
@ AmbiguousBaseSubobjects
Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria...
void setNotFoundInCurrentInstantiation()
Note that while no result was found in the current instantiation, there were dependent base classes t...
static bool isVisible(Sema &SemaRef, NamedDecl *D)
Determine whether the given declaration is visible to the program.
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
bool isShadowed() const
Determine whether the lookup result was shadowed by some other declaration that lookup ignored.
This represents a decl that may have a name.
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
A (possibly-)qualified type.
Sema - This implements semantic analysis and AST building for C.
LookupNameKind
Describes the kind of name lookup to perform.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
@ NotForRedeclaration
The lookup is a reference to this name that is not for the purpose of redeclaring the name.
@ ForVisibleRedeclaration
The lookup results will be used for redeclaration of a name, if an entity by that name already exists...
@ ForExternalRedeclaration
The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...
void CheckLookupAccess(const LookupResult &R)
Checks access to all the declarations in the given result set.
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
Encodes a location in the source.
A trivial tuple used to represent a source range.
Represents a C++ template name within the type system.
A set of unresolved declarations.
UnresolvedSetIterator iterator
void append(iterator I, iterator E)
void addDecl(NamedDecl *D)
The iterator over UnresolvedSets.
Consumes visible declarations found when searching for all visible names within a given scope or cont...
virtual bool includeHiddenDecls() const
Determine whether hidden declarations (from unimported modules) should be given to this consumer.
virtual void EnteredContext(DeclContext *Ctx)
Callback to inform the client that Sema entered into a new context to find a visible declaration.
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass)=0
Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...
virtual ~VisibleDeclConsumer()
Destroys the visible declaration consumer.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.