30 #include "llvm/ADT/FoldingSet.h" 31 #include "llvm/Support/Casting.h" 32 #include "llvm/Support/Compiler.h" 33 #include "llvm/Support/ErrorHandling.h" 34 #include "llvm/Support/raw_ostream.h" 40 using namespace clang;
65 public llvm::FoldingSetNode {
75 ID.AddPointer(Template);
111 return (A < B ? -1 : (A > B ? 1 : 0));
122 if (!LII)
return RII ? -1 : 0;
136 return LHSSelector.getAsIdentifierInfo()->
getName().compare(
137 RHSSelector.getAsIdentifierInfo()->
getName());
140 for (
unsigned I = 0, N =
std::min(LN, RN); I != N; ++I) {
179 llvm_unreachable(
"Invalid DeclarationName Kind!");
189 OS << *ClassRec->getDecl();
194 OS << *InjTy->getDecl();
198 ClassType.
print(OS, Policy);
223 OS <<
"<deduction guide for ";
224 getCXXDeductionGuideTemplate()->getDeclName().print(OS, Policy);
228 case DeclarationName::CXXOperatorName: { 229 static const char* const OperatorNames[NUM_OVERLOADED_OPERATORS] = { 231 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 233 #include "clang/Basic/OperatorKinds.def" 235 const char *OpName = OperatorNames[N.getCXXOverloadedOperator()]; 236 assert(OpName && "not an overloaded operator"); 239 if (OpName[0] >= 'a
' && OpName[0] <= 'z
') 245 case DeclarationName::CXXLiteralOperatorName: 246 OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName(); 249 case DeclarationName::CXXConversionFunctionName: { 251 QualType Type = N.getCXXNameType(); 252 if (const RecordType *Rec = Type->getAs<RecordType>()) { 253 OS << *Rec->getDecl(); 256 // We know we're printing
C++ here, ensure we print
'bool' properly.
259 Type.print(OS, CXXPolicy);
263 OS <<
"<using-directive>";
267 llvm_unreachable(
"Unexpected declaration name kind");
281 switch (getStoredNameKind()) {
282 case StoredIdentifier:
return Identifier;
283 case StoredObjCZeroArgSelector:
return ObjCZeroArgSelector;
284 case StoredObjCOneArgSelector:
return ObjCOneArgSelector;
286 case StoredDeclarationNameExtra:
289 return CXXConstructorName;
292 return CXXDestructorName;
295 return CXXDeductionGuideName;
298 return CXXConversionFunctionName;
301 return CXXLiteralOperatorName;
310 return CXXOperatorName;
312 return ObjCMultiArgSelector;
317 llvm_unreachable(
"This should be unreachable!");
326 auto *TD = getCXXDeductionGuideTemplate();
327 if (TD && TD->getDeclContext()->isDependentContext())
335 llvm::raw_string_ostream OS(Result);
342 return CXXName->
Type;
348 if (
auto *Guide = getAsCXXDeductionGuideNameExtra())
349 return Guide->Template;
370 void *DeclarationName::getFETokenInfoAsVoidSlow()
const {
371 switch (getNameKind()) {
373 llvm_unreachable(
"Handled by getFETokenInfo()");
375 case CXXConstructorName:
376 case CXXDestructorName:
377 case CXXConversionFunctionName:
378 return getAsCXXSpecialName()->FETokenInfo;
380 case CXXDeductionGuideName:
381 return getAsCXXDeductionGuideNameExtra()->FETokenInfo;
383 case CXXOperatorName:
384 return getAsCXXOperatorIdName()->FETokenInfo;
386 case CXXLiteralOperatorName:
387 return getAsCXXLiteralOperatorIdName()->FETokenInfo;
390 llvm_unreachable(
"Declaration name has no FETokenInfo");
395 switch (getNameKind()) {
397 getAsIdentifierInfo()->setFETokenInfo(T);
400 case CXXConstructorName:
401 case CXXDestructorName:
402 case CXXConversionFunctionName:
403 getAsCXXSpecialName()->FETokenInfo =
T;
406 case CXXDeductionGuideName:
407 getAsCXXDeductionGuideNameExtra()->FETokenInfo =
T;
410 case CXXOperatorName:
411 getAsCXXOperatorIdName()->FETokenInfo =
T;
414 case CXXLiteralOperatorName:
415 getAsCXXLiteralOperatorIdName()->FETokenInfo =
T;
419 llvm_unreachable(
"Declaration name has no FETokenInfo");
429 Ptr |= StoredDeclarationNameExtra;
435 llvm::errs() << *
this <<
'\n';
439 CXXSpecialNamesImpl =
new llvm::FoldingSet<CXXSpecialName>;
440 CXXLiteralOperatorNames =
new llvm::FoldingSet<CXXLiteralOperatorIdName>;
441 CXXDeductionGuideNames =
new llvm::FoldingSet<CXXDeductionGuideNameExtra>;
454 static_cast<llvm::FoldingSet<CXXSpecialName> *
>(CXXSpecialNamesImpl);
456 static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName> *
>(
457 CXXLiteralOperatorNames);
458 auto *DeductionGuideNames =
459 static_cast<llvm::FoldingSet<CXXDeductionGuideNameExtra> *
>(
460 CXXDeductionGuideNames);
464 delete DeductionGuideNames;
481 auto *DeductionGuideNames =
482 static_cast<llvm::FoldingSet<CXXDeductionGuideNameExtra> *
>(
483 CXXDeductionGuideNames);
485 llvm::FoldingSetNodeID
ID;
486 ID.AddPointer(Template);
488 void *InsertPos =
nullptr;
489 if (
auto *Name = DeductionGuideNames->FindNodeOrInsertPos(ID, InsertPos))
494 Name->Template = Template;
495 Name->FETokenInfo =
nullptr;
497 DeductionGuideNames->InsertNode(Name, InsertPos);
511 "Kind must be a C++ special name kind");
512 llvm::FoldingSet<CXXSpecialName> *SpecialNames
513 =
static_cast<llvm::FoldingSet<CXXSpecialName>*
>(CXXSpecialNamesImpl);
519 assert(!Ty.
hasQualifiers() &&
"Constructor type must be unqualified");
523 assert(!Ty.
hasQualifiers() &&
"Destructor type must be unqualified");
533 llvm::FoldingSetNodeID
ID;
534 ID.AddInteger(EKind);
537 void *InsertPos =
nullptr;
538 if (
CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos))
543 SpecialName->
Type = Ty;
546 SpecialNames->InsertNode(SpecialName, InsertPos);
557 llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
558 =
static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*
> 559 (CXXLiteralOperatorNames);
561 llvm::FoldingSetNodeID
ID;
564 void *InsertPos =
nullptr;
566 LiteralNames->FindNodeOrInsertPos(ID, InsertPos))
571 LiteralName->
ID = II;
574 LiteralNames->InsertNode(LiteralName, InsertPos);
586 NamedType.TInfo =
nullptr;
606 switch (Name.getNameKind()) {
621 return TInfo->getType()->containsUnexpandedParameterPack();
623 return Name.getCXXNameType()->containsUnexpandedParameterPack();
625 llvm_unreachable(
"All name kinds handled.");
629 switch (Name.getNameKind()) {
644 return TInfo->getType()->isInstantiationDependentType();
646 return Name.getCXXNameType()->isInstantiationDependentType();
648 llvm_unreachable(
"All name kinds handled.");
653 llvm::raw_string_ostream OS(Result);
659 switch (Name.getNameKind()) {
684 OS << TInfo->getType().getAsString(PP);
689 llvm_unreachable(
"Unexpected declaration name kind");
693 switch (Name.getNameKind()) {
699 unsigned raw = LocInfo.CXXOperatorName.EndOpNameLoc;
704 unsigned raw = LocInfo.CXXLiteralOperatorName.OpNameLoc;
712 return TInfo->getTypeLoc().getEndLoc();
723 llvm_unreachable(
"Unexpected declaration name kind");
Defines the clang::ASTContext interface.
Smart pointer class that efficiently represents Objective-C method names.
CXXSpecialName - Records the type associated with one of the "special" kinds of declaration names in ...
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
NameKind
NameKind - The kind of name this object contains.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
QualType Type
Type - The type associated with this declaration name.
C Language Family Type Representation.
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
Defines the C++ template declaration subclasses.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
A container of type source information.
bool isInstantiationDependent() const
Determine whether this name involves a template parameter.
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
const T * getAs() const
Member-template getAs<specific type>'.
Describes how types, statements, expressions, and declarations should be printed. ...
CXXOperatorIdName - Contains extra information for the name of an overloaded operator in C++...
void Profile(llvm::FoldingSetNodeID &ID)
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
static int compareInt(unsigned A, unsigned B)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
bool isDependentName() const
Determines whether the name itself is dependent, e.g., because it involves a C++ type that is itself ...
Type(TypeClass tc, QualType canon, bool Dependent, bool InstantiationDependent, bool VariablyModified, bool ContainsUnexpandedParameterPack)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getEndLoc() const
getEndLoc - Retrieve the location of the last token.
bool SuppressScope
Suppresses printing of scope specifiers.
void * getAsOpaquePtr() const
bool containsUnexpandedParameterPack() const
Determine whether this name contains an unexpanded parameter pack.
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
unsigned SuppressTemplateArgsInCXXConstructors
When true, suppresses printing template arguments in names of C++ constructors.
Function object that provides a total ordering on QualType values.
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
Allows QualTypes to be sorted and hence used in maps and sets.
Defines the clang::LangOptions interface.
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y)
void Profile(llvm::FoldingSetNodeID &FSID)
const FunctionProtoType * T
bool hasQualifiers() const
Determines whether this type has any qualifiers.
static void printCXXConstructorDestructorName(QualType ClassType, raw_ostream &OS, PrintingPolicy Policy)
std::string getAsString() const
getNameAsString - Retrieve the human-readable string for this name.
Defines an enumeration for C++ overloaded operators.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
Defines the clang::TypeLoc interface and its subclasses.
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
unsigned getNumArgs() const
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
void * FETokenInfo
FETokenInfo - Extra information associated with this operator name that can be used by the front end...
IdentifierInfo * getCXXLiteralIdentifier() const
getCXXLiteralIdentifier - If this name is the name of a literal operator, retrieve the identifier ass...
Encodes a location in the source.
void * FETokenInfo
FETokenInfo - Extra information associated with this operator name that can be used by the front end...
void printName(raw_ostream &OS) const
printName - Print the human-readable name to a stream.
The injected class name of a C++ class template or class template partial specialization.
StringRef getName() const
Return the actual identifier string.
Dataflow Directional Tag Classes.
std::string getAsString() const
getAsString - Retrieve the human-readable string for this name.
The base class of all kinds of template declarations (e.g., class, function, etc.).
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
DeclarationName - The name of a declaration.
void adjustForCPlusPlus()
Adjust this printing policy for cases where it's known that we're printing C++ code (for instance...
Not an overloaded operator.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
CXXLiteralOperatorName - Contains the actual identifier that makes up the name.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
void setFETokenInfo(void *T)
static int compare(DeclarationName LHS, DeclarationName RHS)
void print(raw_ostream &OS, const PrintingPolicy &Policy)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
void * FETokenInfo
FETokenInfo - Extra information associated with this declaration name that can be used by the front e...
static DeclarationName getUsingDirectiveName()
getUsingDirectiveName - Return name for all using-directives.