29 #include "llvm/ADT/FoldingSet.h" 30 #include "llvm/Support/Casting.h" 31 #include "llvm/Support/Compiler.h" 32 #include "llvm/Support/ErrorHandling.h" 33 #include "llvm/Support/raw_ostream.h" 39 using namespace clang;
42 return (A < B ? -1 : (A > B ? 1 : 0));
69 return LHSSelector.getAsIdentifierInfo()->
getName().compare(
70 RHSSelector.getAsIdentifierInfo()->
getName());
73 for (
unsigned I = 0, N =
std::min(LN, RN); I != N; ++I) {
115 llvm_unreachable(
"Invalid DeclarationName Kind!");
125 OS << *ClassRec->getDecl();
130 OS << *InjTy->getDecl();
134 ClassType.
print(OS, Policy);
159 OS <<
"<deduction guide for ";
164 case DeclarationName::CXXOperatorName: { 165 const char *OpName = getOperatorSpelling(getCXXOverloadedOperator()); 166 assert(OpName && "not an overloaded operator"); 169 if (OpName[0] >= 'a
' && OpName[0] <= 'z
') 175 case DeclarationName::CXXLiteralOperatorName: 176 OS << "operator\"\"" << getCXXLiteralIdentifier()->getName(); 179 case DeclarationName::CXXConversionFunctionName: { 181 QualType Type = getCXXNameType(); 182 if (const RecordType *Rec = Type->getAs<RecordType>()) { 183 OS << *Rec->getDecl(); 186 // We know we're printing
C++ here, ensure we
print 'bool' properly.
189 Type.print(OS, CXXPolicy);
193 OS <<
"<using-directive>";
197 llvm_unreachable(
"Unexpected declaration name kind");
217 if (TD && TD->getDeclContext()->isDependentContext())
225 llvm::raw_string_ostream OS(Result);
230 void *DeclarationName::getFETokenInfoSlow()
const {
233 llvm_unreachable(
"case Identifier already handled by getFETokenInfo!");
237 return castAsCXXSpecialNameExtra()->FETokenInfo;
239 return castAsCXXOperatorIdName()->FETokenInfo;
241 return castAsCXXDeductionGuideNameExtra()->FETokenInfo;
243 return castAsCXXLiteralOperatorIdName()->FETokenInfo;
245 llvm_unreachable(
"DeclarationName has no FETokenInfo!");
249 void DeclarationName::setFETokenInfoSlow(
void *T) {
252 llvm_unreachable(
"case Identifier already handled by setFETokenInfo!");
256 castAsCXXSpecialNameExtra()->FETokenInfo = T;
259 castAsCXXOperatorIdName()->FETokenInfo = T;
262 castAsCXXDeductionGuideNameExtra()->FETokenInfo = T;
265 castAsCXXLiteralOperatorIdName()->FETokenInfo = T;
268 llvm_unreachable(
"DeclarationName has no FETokenInfo!");
273 llvm::errs() << *
this <<
'\n';
279 CXXOperatorNames[Op].
Kind = static_cast<OverloadedOperatorKind>(Op);
286 llvm::FoldingSetNodeID
ID;
287 ID.AddPointer(Template);
289 void *InsertPos =
nullptr;
290 if (
auto *Name = CXXDeductionGuideNames.FindNodeOrInsertPos(ID, InsertPos))
294 CXXDeductionGuideNames.InsertNode(Name, InsertPos);
302 llvm::FoldingSetNodeID
ID;
304 void *InsertPos =
nullptr;
305 if (
auto *Name = CXXConstructorNames.FindNodeOrInsertPos(ID, InsertPos))
306 return {Name, DeclarationName::StoredCXXConstructorName};
310 CXXConstructorNames.InsertNode(SpecialName, InsertPos);
311 return {SpecialName, DeclarationName::StoredCXXConstructorName};
318 llvm::FoldingSetNodeID
ID;
320 void *InsertPos =
nullptr;
321 if (
auto *Name = CXXDestructorNames.FindNodeOrInsertPos(ID, InsertPos))
322 return {Name, DeclarationName::StoredCXXDestructorName};
326 CXXDestructorNames.InsertNode(SpecialName, InsertPos);
327 return {SpecialName, DeclarationName::StoredCXXDestructorName};
333 llvm::FoldingSetNodeID
ID;
335 void *InsertPos =
nullptr;
337 CXXConversionFunctionNames.FindNodeOrInsertPos(ID, InsertPos))
338 return {Name, DeclarationName::StoredCXXConversionFunctionName};
342 CXXConversionFunctionNames.InsertNode(SpecialName, InsertPos);
343 return {SpecialName, DeclarationName::StoredCXXConversionFunctionName};
357 llvm_unreachable(
"Invalid kind in getCXXSpecialName!");
363 llvm::FoldingSetNodeID
ID;
366 void *InsertPos =
nullptr;
367 if (
auto *Name = CXXLiteralOperatorNames.FindNodeOrInsertPos(ID, InsertPos))
371 CXXLiteralOperatorNames.InsertNode(LiteralName, InsertPos);
383 NamedType.TInfo =
nullptr;
403 switch (Name.getNameKind()) {
418 return TInfo->getType()->containsUnexpandedParameterPack();
420 return Name.getCXXNameType()->containsUnexpandedParameterPack();
422 llvm_unreachable(
"All name kinds handled.");
426 switch (Name.getNameKind()) {
441 return TInfo->getType()->isInstantiationDependentType();
443 return Name.getCXXNameType()->isInstantiationDependentType();
445 llvm_unreachable(
"All name kinds handled.");
450 llvm::raw_string_ostream OS(Result);
462 switch (Name.getNameKind()) {
471 Name.print(OS, Policy);
485 OS << TInfo->getType().getAsString(Policy);
487 Name.print(OS, Policy);
490 llvm_unreachable(
"Unexpected declaration name kind");
494 switch (Name.getNameKind()) {
500 unsigned raw = LocInfo.CXXOperatorName.EndOpNameLoc;
505 unsigned raw = LocInfo.CXXLiteralOperatorName.OpNameLoc;
513 return TInfo->getTypeLoc().getEndLoc();
524 llvm_unreachable(
"Unexpected declaration name kind");
Defines the clang::ASTContext interface.
Smart pointer class that efficiently represents Objective-C method names.
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
The kind of the name stored in this DeclarationName.
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
C Language Family Type Representation.
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
Defines the C++ template declaration subclasses.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
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.
const T * getAs() const
Member-template getAs<specific type>'.
Describes how types, statements, expressions, and declarations should be printed. ...
DeclarationName getDeclName() const
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.
NameKind getNameKind() const
Determine what kind of name this is.
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...
bool isDependentName() const
Determines whether the name itself is dependent, e.g., because it involves a C++ type that is itself ...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
bool containsUnexpandedParameterPack() const
Determine whether this name contains an unexpanded parameter pack.
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.
Allows QualTypes to be sorted and hence used in maps and sets.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
Defines the clang::LangOptions interface.
static void printCXXConstructorDestructorName(QualType ClassType, raw_ostream &OS, PrintingPolicy Policy)
std::string getAsString() const
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.
Defines the clang::TypeLoc interface and its subclasses.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
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.
Encodes a location in the source.
unsigned SuppressScope
Suppresses printing of scope specifiers.
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.).
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...
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
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.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
Defines the clang::SourceLocation class and associated facilities.
static int compare(DeclarationName LHS, DeclarationName RHS)
Contains the actual identifier that makes up the name of a C++ literal operator.
__DEVICE__ int min(int __a, int __b)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it...