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 {
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);
366 : Ptr(reinterpret_cast<
uintptr_t>(Sel.InfoPtr.getOpaqueValue())) {}
372 detail::DeclarationNameExtra::CXXUsingDirective);
377 explicit operator bool()
const {
378 return getPtr() || (getStoredNameKind() != StoredIdentifier);
385 bool isIdentifier()
const {
return getStoredNameKind() == StoredIdentifier; }
387 return getStoredNameKind() == StoredObjCZeroArgSelector;
390 return getStoredNameKind() == StoredObjCOneArgSelector;
397 StoredNameKind StoredKind = getStoredNameKind();
398 if (StoredKind != StoredDeclarationNameExtra)
399 return static_cast<NameKind>(StoredKind);
403 unsigned ExtraKind = castAsExtra()->getKind();
404 return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind);
413 bool isDependentName()
const;
422 return castAsIdentifierInfo();
450 if (getStoredNameKind() == StoredCXXConstructorName ||
451 getStoredNameKind() == StoredCXXDestructorName ||
452 getStoredNameKind() == StoredCXXConversionFunctionName) {
453 assert(getPtr() &&
"getCXXNameType on a null DeclarationName!");
454 return castAsCXXSpecialNameExtra()->Type;
462 if (getNameKind() == CXXDeductionGuideName) {
464 "getCXXDeductionGuideTemplate on a null DeclarationName!");
465 return castAsCXXDeductionGuideNameExtra()->Template;
473 if (getStoredNameKind() == StoredCXXOperatorName) {
474 assert(getPtr() &&
"getCXXOverloadedOperator on a null DeclarationName!");
475 return castAsCXXOperatorIdName()->Kind;
483 if (getNameKind() == CXXLiteralOperatorName) {
484 assert(getPtr() &&
"getCXXLiteralIdentifier on a null DeclarationName!");
485 return castAsCXXLiteralOperatorIdName()->ID;
492 assert((getNameKind() == ObjCZeroArgSelector ||
493 getNameKind() == ObjCOneArgSelector ||
494 getNameKind() == ObjCMultiArgSelector || !getPtr()) &&
503 assert(getPtr() &&
"getFETokenInfo on an empty DeclarationName!");
504 if (getStoredNameKind() == StoredIdentifier)
505 return castAsIdentifierInfo()->getFETokenInfo();
506 return getFETokenInfoSlow();
510 assert(getPtr() &&
"setFETokenInfo on an empty DeclarationName!");
511 if (getStoredNameKind() == StoredIdentifier)
512 castAsIdentifierInfo()->setFETokenInfo(
T);
514 setFETokenInfoSlow(
T);
519 return LHS.Ptr == RHS.Ptr;
524 return LHS.Ptr != RHS.Ptr;
546raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
551 return DeclarationName::compare(LHS, RHS) < 0;
557 return DeclarationName::compare(LHS, RHS) > 0;
563 return DeclarationName::compare(LHS, RHS) <= 0;
569 return DeclarationName::compare(LHS, RHS) >= 0;
584 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames;
589 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames;
595 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames;
606 llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames;
612 llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames;
678 struct CXXLitOpName {
688 struct CXXOpName CXXOperatorName;
689 struct CXXLitOpName CXXLiteralOperatorName;
692 void setNamedTypeLoc(
TypeSourceInfo *TInfo) { NamedType.TInfo = TInfo; }
694 void setCXXOperatorNameRange(SourceRange
Range) {
695 CXXOperatorName.BeginOpNameLoc =
Range.getBegin().getRawEncoding();
696 CXXOperatorName.EndOpNameLoc =
Range.getEnd().getRawEncoding();
699 void setCXXLiteralOperatorNameLoc(SourceLocation
Loc) {
700 CXXLiteralOperatorName.OpNameLoc =
Loc.getRawEncoding();
704 DeclarationNameLoc(DeclarationName Name);
714 return SourceLocation::getFromRawEncoding(CXXOperatorName.BeginOpNameLoc);
719 return SourceLocation::getFromRawEncoding(CXXOperatorName.EndOpNameLoc);
727 getCXXOperatorNameEndLoc());
734 return SourceLocation::getFromRawEncoding(CXXLiteralOperatorName.OpNameLoc);
741 DNL.setNamedTypeLoc(TInfo);
748 return makeCXXOperatorNameLoc(
SourceRange(BeginLoc, EndLoc));
754 DNL.setCXXOperatorNameRange(
Range);
761 DNL.setCXXLiteralOperatorNameLoc(
Loc);
784 : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
788 : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
808 if (Name.getNameKind() != DeclarationName::CXXConstructorName &&
809 Name.getNameKind() != DeclarationName::CXXDestructorName &&
810 Name.getNameKind() != DeclarationName::CXXConversionFunctionName)
818 assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
819 Name.getNameKind() == DeclarationName::CXXDestructorName ||
820 Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
821 LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
827 if (Name.getNameKind() != DeclarationName::CXXOperatorName)
835 assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
836 LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
843 if (Name.getNameKind() != DeclarationName::CXXLiteralOperatorName)
852 assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
853 LocInfo = DeclarationNameLoc::makeCXXLiteralOperatorNameLoc(
Loc);
857 bool isInstantiationDependent()
const;
861 bool containsUnexpandedParameterPack()
const;
879 return EndLoc.
isValid() ? EndLoc : getBeginLoc();
891 DiagnosticsEngine::ak_declarationname);
895raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo);
904struct DenseMapInfo<
clang::DeclarationName> {
914 return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
925 return P.getAsOpaquePtr();
930 static constexpr int NumLowBitsAvailable = 0;
Defines the Diagnostic-related interfaces.
enum clang::sema::@1653::IndirectLocalPathEntry::EntryKind Kind
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 &ASTCtx, QualType Ty)
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.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
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.
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+.
The JSON file list parser is used to communicate input to InstallAPI.
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.
const FunctionProtoType * T
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
llvm::StringRef getAsString(SyncScope S)
Diagnostic wrappers for TextAPI types for error reporting.
__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 correspon...
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)