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"
160 : SemaPtr(&SemaRef), NameInfo(NameInfo), LookupKind(LookupKind),
175 : SemaPtr(&SemaRef), NameInfo(Name, NameLoc), LookupKind(LookupKind),
187 : SemaPtr(
Other.SemaPtr), NameInfo(
Other.NameInfo),
189 ExternalRedecl(
Other.ExternalRedecl), HideTags(
Other.HideTags),
190 AllowHidden(
Other.AllowHidden),
191 TemplateNameLookup(
Other.TemplateNameLookup) {}
199 : ResultKind(
std::move(
Other.ResultKind)),
202 NamingClass(
std::move(
Other.NamingClass)),
203 BaseObjectType(
std::move(
Other.BaseObjectType)),
205 NameContextRange(
std::move(
Other.NameContextRange)),
208 ExternalRedecl(
std::move(
Other.ExternalRedecl)),
209 HideTags(
std::move(
Other.HideTags)),
210 DiagnoseAccess(
std::move(
Other.DiagnoseAccess)),
211 DiagnoseAmbiguous(
std::move(
Other.DiagnoseAmbiguous)),
212 AllowHidden(
std::move(
Other.AllowHidden)),
213 Shadowed(
std::move(
Other.Shadowed)),
214 TemplateNameLookup(
std::move(
Other.TemplateNameLookup)) {
215 Other.Paths =
nullptr;
216 Other.DiagnoseAccess =
false;
217 Other.DiagnoseAmbiguous =
false;
221 ResultKind = std::move(
Other.ResultKind);
222 Ambiguity = std::move(
Other.Ambiguity);
223 Decls = std::move(
Other.Decls);
224 Paths = std::move(
Other.Paths);
225 NamingClass = std::move(
Other.NamingClass);
226 BaseObjectType = std::move(
Other.BaseObjectType);
227 SemaPtr = std::move(
Other.SemaPtr);
228 NameInfo = std::move(
Other.NameInfo);
229 NameContextRange = std::move(
Other.NameContextRange);
230 LookupKind = std::move(
Other.LookupKind);
231 IDNS = std::move(
Other.IDNS);
232 Redecl = std::move(
Other.Redecl);
233 ExternalRedecl = std::move(
Other.ExternalRedecl);
234 HideTags = std::move(
Other.HideTags);
235 DiagnoseAccess = std::move(
Other.DiagnoseAccess);
236 DiagnoseAmbiguous = std::move(
Other.DiagnoseAmbiguous);
237 AllowHidden = std::move(
Other.AllowHidden);
238 Shadowed = std::move(
Other.Shadowed);
239 TemplateNameLookup = std::move(
Other.TemplateNameLookup);
240 Other.Paths =
nullptr;
241 Other.DiagnoseAccess =
false;
242 Other.DiagnoseAmbiguous =
false;
249 if (DiagnoseAmbiguous)
251 if (Paths) deletePaths(Paths);
261 this->NameInfo = NameInfo;
287 return ExternalRedecl;
291 return ExternalRedecl ? RedeclarationKind::ForExternalRedeclaration
292 : Redecl ? RedeclarationKind::ForVisibleRedeclaration
293 : RedeclarationKind::NotForRedeclaration;
305 return AllowHidden ||
345 assert(checkDebugAssumptions());
409 if (!
D->isInIdentifierNamespace(IDNS))
415 return getAcceptableDeclSlow(
D);
433 return NamingClass !=
nullptr;
465 return BaseObjectType;
535 std::optional<AmbiguityKind> SavedAK;
536 bool WasAmbiguous =
false;
548 assert(WasAmbiguous);
549 Ambiguity = *SavedAK;
557 template <
class DeclClass>
570 &&
"getFoundDecl called on non-unique result");
571 return (*
begin())->getUnderlyingDecl();
576 assert(!Decls.
empty() &&
"cannot get representative of empty set");
605 LLVM_ATTRIBUTE_REINITIALIZES
void clear() {
608 if (Paths) deletePaths(Paths);
610 NamingClass =
nullptr;
624 Redecl = (RK != RedeclarationKind::NotForRedeclaration);
625 ExternalRedecl = (RK == RedeclarationKind::ForExternalRedeclaration);
630 void print(raw_ostream &);
635 DiagnoseAccess =
false;
636 DiagnoseAmbiguous =
false;
652 NameContextRange = SR;
659 return NameContextRange;
680 bool Changed =
false;
681 bool CalledDone =
false;
687 : Results(F.Results), I(F.I), Changed(F.Changed),
688 CalledDone(F.CalledDone) {
703 "LookupResult::Filter destroyed without done() call");
707 return I != Results.end();
711 assert(I != Results.end() &&
"next() called on empty filter");
722 Results.Decls.erase(--I);
729 Results.Decls.replace(I-1,
D);
735 Results.Decls.replace(I-1,
D, AS);
740 assert(!CalledDone &&
"done() called twice");
744 Results.resolveKindAfterFilter();
757 IDNS &=
~Decl::IDNS_LocalExtern;
761 void diagnoseAccess() {
763 getSema().getLangOpts().AccessControl)
767 void diagnoseAmbiguous() {
777 void addDeclsFromBasePaths(
const CXXBasePaths &
P);
780 bool checkDebugAssumptions()
const;
782 bool checkUnresolved()
const {
784 if (isa<UnresolvedUsingValueDecl>((*I)->getUnderlyingDecl()))
789 static void deletePaths(CXXBasePaths *);
796 UnresolvedSet<8> Decls;
797 CXXBasePaths *Paths =
nullptr;
798 CXXRecordDecl *NamingClass =
nullptr;
799 QualType BaseObjectType;
803 DeclarationNameInfo NameInfo;
804 SourceRange NameContextRange;
813 bool HideTags =
true;
815 bool DiagnoseAccess =
false;
816 bool DiagnoseAmbiguous =
false;
819 bool AllowHidden =
false;
824 bool Shadowed =
false;
827 bool TemplateNameLookup =
false;
859 bool InBaseClass) = 0;
872 llvm::MapVector<NamedDecl*, NamedDecl*> Decls;
874 struct select_second {
875 NamedDecl *operator()(std::pair<NamedDecl*, NamedDecl*>
P)
const {
886 Decls.erase(cast<NamedDecl>(
D->getCanonicalDecl()));
890 llvm::mapped_iterator<
decltype(Decls)
::iterator, select_second>;
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
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.
llvm::MachO::Record Record
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.
@ ForExternalRedeclaration
The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...
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.
@ IDNS_LocalExtern
This declaration is a function-local extern declaration of a variable or function.
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.
Filter & operator=(const Filter &)=delete
Filter & operator=(Filter &&)=delete
void erase()
Erase the last element returned from this iterator.
void replace(NamedDecl *D, AccessSpecifier AS)
Replaces the current entry with the given one.
Filter(const Filter &)=delete
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.
RedeclarationKind redeclarationKind() const
@ 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.
bool isSuppressingAccessDiagnostics() const
Determines whether this lookup is suppressing access control diagnostics.
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
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.
void setRedeclarationKind(RedeclarationKind RK)
Change this lookup's redeclaration kind.
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 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
void suppressAccessDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup due to access control violat...
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc, Sema::LookupNameKind LookupKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
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.
bool isSuppressingAmbiguousDiagnostics() const
Determines whether this lookup is suppressing ambiguous lookup diagnostics.
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo, Sema::LookupNameKind LookupKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
LookupResultKind getResultKind() const
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 ...
@ 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...
@ AmbiguousReferenceToPlaceholderVariable
Name lookup results in an ambiguity because multiple placeholder variables were found in the same sco...
@ 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.
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.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ Other
Other implicit parameter.
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 correspon...
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.