13#ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
14#define LLVM_CLANG_AST_DECLARATIONNAME_H
22#include "llvm/ADT/DenseMapInfo.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/Support/Compiler.h"
26#include "llvm/Support/type_traits.h"
35template <
typename>
class CanQual;
37class DeclarationNameTable;
53 :
public llvm::FoldingSetNode {
68 void Profile(llvm::FoldingSetNodeID &ID) {
69 ID.AddPointer(
Type.getAsOpaquePtr());
76 public llvm::FoldingSetNode {
90 FETokenInfo(nullptr) {}
93 void Profile(llvm::FoldingSetNodeID &ID) { ID.AddPointer(Template); }
110 void *FETokenInfo =
nullptr;
117 public llvm::FoldingSetNode {
130 FETokenInfo(nullptr) {}
133 void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); }
174 enum StoredNameKind {
175 StoredIdentifier = 0,
176 StoredObjCZeroArgSelector = Selector::ZeroArg,
177 StoredObjCOneArgSelector = Selector::OneArg,
178 StoredCXXConstructorName = 3,
179 StoredCXXDestructorName = 4,
180 StoredCXXConversionFunctionName = 5,
181 StoredCXXOperatorName = 6,
182 StoredDeclarationNameExtra = Selector::MultiArg,
184 UncommonNameKindOffset = 8
193 "The various classes that DeclarationName::Ptr can point to"
194 " must be at least aligned to 8 bytes!");
197 std::is_same<std::underlying_type_t<StoredNameKind>,
198 std::underlying_type_t<
200 "The various enums used to compute values for NameKind should "
201 "all have the same underlying type");
210 ObjCZeroArgSelector = StoredObjCZeroArgSelector,
211 ObjCOneArgSelector = StoredObjCOneArgSelector,
212 CXXConstructorName = StoredCXXConstructorName,
213 CXXDestructorName = StoredCXXDestructorName,
214 CXXConversionFunctionName = StoredCXXConversionFunctionName,
215 CXXOperatorName = StoredCXXOperatorName,
216 CXXDeductionGuideName = llvm::addEnumValues(
217 UncommonNameKindOffset,
218 detail::DeclarationNameExtra::CXXDeductionGuideName),
219 CXXLiteralOperatorName = llvm::addEnumValues(
220 UncommonNameKindOffset,
221 detail::DeclarationNameExtra::CXXLiteralOperatorName),
223 llvm::addEnumValues(UncommonNameKindOffset,
224 detail::DeclarationNameExtra::CXXUsingDirective),
225 ObjCMultiArgSelector =
226 llvm::addEnumValues(UncommonNameKindOffset,
227 detail::DeclarationNameExtra::ObjCMultiArgSelector),
265 StoredNameKind getStoredNameKind()
const {
266 return static_cast<StoredNameKind
>(Ptr & PtrMask);
269 void *getPtr()
const {
return reinterpret_cast<void *
>(Ptr & ~PtrMask); }
271 void setPtrAndKind(
const void *
P, StoredNameKind Kind) {
273 assert((Kind & ~PtrMask) == 0 &&
274 "Invalid StoredNameKind in setPtrAndKind!");
275 assert((PAsInteger & PtrMask) == 0 &&
276 "Improperly aligned pointer in setPtrAndKind!");
277 Ptr = PAsInteger |
Kind;
281 DeclarationName(detail::DeclarationNameExtra *Name) {
282 setPtrAndKind(Name, StoredDeclarationNameExtra);
286 DeclarationName(detail::CXXSpecialNameExtra *Name,
287 StoredNameKind StoredKind) {
288 assert((StoredKind == StoredCXXConstructorName ||
289 StoredKind == StoredCXXDestructorName ||
290 StoredKind == StoredCXXConversionFunctionName) &&
291 "Invalid StoredNameKind when constructing a DeclarationName"
292 " from a CXXSpecialNameExtra!");
293 setPtrAndKind(Name, StoredKind);
297 DeclarationName(detail::CXXOperatorIdName *Name) {
298 setPtrAndKind(Name, StoredCXXOperatorName);
302 IdentifierInfo *castAsIdentifierInfo()
const {
303 assert((getStoredNameKind() == StoredIdentifier) &&
304 "DeclarationName does not store an IdentifierInfo!");
305 return static_cast<IdentifierInfo *
>(getPtr());
310 detail::DeclarationNameExtra *castAsExtra()
const {
311 assert((getStoredNameKind() == StoredDeclarationNameExtra) &&
312 "DeclarationName does not store an Extra structure!");
313 return static_cast<detail::DeclarationNameExtra *
>(getPtr());
318 detail::CXXSpecialNameExtra *castAsCXXSpecialNameExtra()
const {
319 assert((getStoredNameKind() == StoredCXXConstructorName ||
320 getStoredNameKind() == StoredCXXDestructorName ||
321 getStoredNameKind() == StoredCXXConversionFunctionName) &&
322 "DeclarationName does not store a CXXSpecialNameExtra!");
323 return static_cast<detail::CXXSpecialNameExtra *
>(getPtr());
328 detail::CXXOperatorIdName *castAsCXXOperatorIdName()
const {
329 assert((getStoredNameKind() == StoredCXXOperatorName) &&
330 "DeclarationName does not store a CXXOperatorIdName!");
331 return static_cast<detail::CXXOperatorIdName *
>(getPtr());
336 detail::CXXDeductionGuideNameExtra *castAsCXXDeductionGuideNameExtra()
const {
337 assert(getNameKind() == CXXDeductionGuideName &&
338 "DeclarationName does not store a CXXDeductionGuideNameExtra!");
339 return static_cast<detail::CXXDeductionGuideNameExtra *
>(getPtr());
344 detail::CXXLiteralOperatorIdName *castAsCXXLiteralOperatorIdName()
const {
345 assert(getNameKind() == CXXLiteralOperatorName &&
346 "DeclarationName does not store a CXXLiteralOperatorIdName!");
347 return static_cast<detail::CXXLiteralOperatorIdName *
>(getPtr());
352 void *getFETokenInfoSlow()
const;
353 void setFETokenInfoSlow(
void *T);
361 setPtrAndKind(II, StoredIdentifier);
371 detail::DeclarationNameExtra::CXXUsingDirective);
376 explicit operator bool()
const {
377 return getPtr() || (getStoredNameKind() != StoredIdentifier);
384 bool isIdentifier()
const {
return getStoredNameKind() == StoredIdentifier; }
386 return getStoredNameKind() == StoredObjCZeroArgSelector;
389 return getStoredNameKind() == StoredObjCOneArgSelector;
396 StoredNameKind StoredKind = getStoredNameKind();
397 if (StoredKind != StoredDeclarationNameExtra)
398 return static_cast<NameKind>(StoredKind);
402 unsigned ExtraKind = castAsExtra()->getKind();
403 return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind);
412 bool isDependentName()
const;
421 return castAsIdentifierInfo();
449 if (getStoredNameKind() == StoredCXXConstructorName ||
450 getStoredNameKind() == StoredCXXDestructorName ||
451 getStoredNameKind() == StoredCXXConversionFunctionName) {
452 assert(getPtr() &&
"getCXXNameType on a null DeclarationName!");
453 return castAsCXXSpecialNameExtra()->Type;
461 if (getNameKind() == CXXDeductionGuideName) {
463 "getCXXDeductionGuideTemplate on a null DeclarationName!");
464 return castAsCXXDeductionGuideNameExtra()->Template;
472 if (getStoredNameKind() == StoredCXXOperatorName) {
473 assert(getPtr() &&
"getCXXOverloadedOperator on a null DeclarationName!");
474 return castAsCXXOperatorIdName()->Kind;
482 if (getNameKind() == CXXLiteralOperatorName) {
483 assert(getPtr() &&
"getCXXLiteralIdentifier on a null DeclarationName!");
484 return castAsCXXLiteralOperatorIdName()->ID;
491 assert((getNameKind() == ObjCZeroArgSelector ||
492 getNameKind() == ObjCOneArgSelector ||
493 getNameKind() == ObjCMultiArgSelector || !getPtr()) &&
502 assert(getPtr() &&
"getFETokenInfo on an empty DeclarationName!");
503 if (getStoredNameKind() == StoredIdentifier)
504 return castAsIdentifierInfo()->getFETokenInfo();
505 return getFETokenInfoSlow();
509 assert(getPtr() &&
"setFETokenInfo on an empty DeclarationName!");
510 if (getStoredNameKind() == StoredIdentifier)
511 castAsIdentifierInfo()->setFETokenInfo(T);
513 setFETokenInfoSlow(T);
518 return LHS.Ptr == RHS.Ptr;
523 return LHS.Ptr != RHS.Ptr;
545raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
550 return DeclarationName::compare(LHS, RHS) < 0;
556 return DeclarationName::compare(LHS, RHS) > 0;
562 return DeclarationName::compare(LHS, RHS) <= 0;
568 return DeclarationName::compare(LHS, RHS) >= 0;
583 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames;
588 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames;
594 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames;
605 llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames;
611 llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames;
677 struct CXXLitOpName {
687 struct CXXOpName CXXOperatorName;
688 struct CXXLitOpName CXXLiteralOperatorName;
691 void setNamedTypeLoc(
TypeSourceInfo *TInfo) { NamedType.TInfo = TInfo; }
693 void setCXXOperatorNameRange(SourceRange Range) {
694 CXXOperatorName.BeginOpNameLoc = Range.getBegin().getRawEncoding();
695 CXXOperatorName.EndOpNameLoc = Range.getEnd().getRawEncoding();
698 void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
699 CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
703 DeclarationNameLoc(DeclarationName Name);
713 return SourceLocation::getFromRawEncoding(CXXOperatorName.BeginOpNameLoc);
718 return SourceLocation::getFromRawEncoding(CXXOperatorName.EndOpNameLoc);
726 getCXXOperatorNameEndLoc());
733 return SourceLocation::getFromRawEncoding(CXXLiteralOperatorName.OpNameLoc);
740 DNL.setNamedTypeLoc(TInfo);
747 return makeCXXOperatorNameLoc(
SourceRange(BeginLoc, EndLoc));
753 DNL.setCXXOperatorNameRange(Range);
760 DNL.setCXXLiteralOperatorNameLoc(Loc);
783 : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
787 : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
807 if (Name.getNameKind() != DeclarationName::CXXConstructorName &&
808 Name.getNameKind() != DeclarationName::CXXDestructorName &&
809 Name.getNameKind() != DeclarationName::CXXConversionFunctionName)
817 assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
818 Name.getNameKind() == DeclarationName::CXXDestructorName ||
819 Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
820 LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
826 if (Name.getNameKind() != DeclarationName::CXXOperatorName)
834 assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
835 LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
842 if (Name.getNameKind() != DeclarationName::CXXLiteralOperatorName)
851 assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
852 LocInfo = DeclarationNameLoc::makeCXXLiteralOperatorNameLoc(Loc);
856 bool isInstantiationDependent()
const;
860 bool containsUnexpandedParameterPack()
const;
878 return EndLoc.
isValid() ? EndLoc : getBeginLoc();
890 DiagnosticsEngine::ak_declarationname);
894raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo);
903struct DenseMapInfo<
clang::DeclarationName> {
913 return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
924 return P.getAsOpaquePtr();
929 static constexpr int NumLowBitsAvailable = 0;
Defines the Diagnostic-related interfaces.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
Defines an enumeration for C++ overloaded operators.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y)
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
__DEVICE__ void * memset(void *__a, int __b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
DeclarationNameLoc - Additional source/type location info for a declaration name.
static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo)
Construct location information for a constructor, destructor or conversion operator.
static DeclarationNameLoc makeCXXLiteralOperatorNameLoc(SourceLocation Loc)
Construct location information for a literal C++ operator.
SourceLocation getCXXLiteralOperatorNameLoc() const
Return the location of the literal operator name (without the operator keyword).
SourceLocation getCXXOperatorNameBeginLoc() const
Return the beginning location of the getCXXOperatorNameRange() range.
TypeSourceInfo * getNamedTypeInfo() const
Returns the source type info.
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc, SourceLocation EndLoc)
Construct location information for a non-literal C++ operator.
SourceLocation getCXXOperatorNameEndLoc() const
Return the end location of the getCXXOperatorNameRange() range.
SourceRange getCXXOperatorNameRange() const
Return the range of the operator name (without the operator keyword).
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceRange Range)
Construct location information for a non-literal C++ operator.
The name of a declaration.
static DeclarationName getFromOpaqueInteger(uintptr_t P)
Get a declaration name from an opaque integer returned by getAsOpaqueInteger.
uintptr_t getAsOpaqueInteger() const
Get the representation of this declaration name as an opaque integer.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
static DeclarationName getEmptyMarker()
static DeclarationName getFromOpaquePtr(void *P)
Get a declaration name from an opaque pointer returned by getAsOpaquePtr.
static DeclarationName getTombstoneMarker()
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
DeclarationName(Selector Sel)
Construct a declaration name from an Objective-C selector.
void * getAsOpaquePtr() const
Get the representation of this declaration name as an opaque pointer.
friend bool operator==(DeclarationName LHS, DeclarationName RHS)
Determine whether the specified names are identical.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
friend bool operator!=(DeclarationName LHS, DeclarationName RHS)
Determine whether the specified names are different.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isObjCZeroArgSelector() const
NameKind
The kind of the name stored in this DeclarationName.
void * getFETokenInfo() const
Get and set FETokenInfo.
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
bool isObjCOneArgSelector() const
DeclarationName()
Construct an empty declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
DeclarationName(const IdentifierInfo *II)
Construct a declaration name from an IdentifierInfo *.
void setFETokenInfo(void *T)
bool isIdentifier() const
Predicate functions for querying what type of name this is.
One of these records is kept for each identifier that is lexed.
This represents a decl that may have a name.
A (possibly-)qualified type.
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
The base class of all kinds of template declarations (e.g., class, function, etc.).
A container of type source information.
The base class of the type hierarchy.
Implementation class used to describe either a set of overloaded template names or an already-substit...
Contains the actual identifier that makes up the name of a C++ literal operator.
void Profile(llvm::FoldingSetNodeID &FSID)
Contains extra information for the name of an overloaded operator in C++, such as "operator+.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
llvm::StringRef getAsString(SyncScope S)
YAML serialization mapping.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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 setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setInfo(const DeclarationNameLoc &Info)
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
const DeclarationNameLoc & getInfo() const
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc, DeclarationNameLoc LocInfo)
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
SourceLocation getEndLoc() const LLVM_READONLY
DeclarationNameInfo()=default
Describes how types, statements, expressions, and declarations should be printed.
static clang::DeclarationName getEmptyKey()
static clang::DeclarationName getTombstoneKey()
static bool isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS)
static unsigned getHashValue(clang::DeclarationName Name)
static void * getAsVoidPointer(clang::DeclarationName P)
static clang::DeclarationName getFromVoidPointer(void *P)