clang: lib/AST/DeclarationName.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
30#include "llvm/ADT/FoldingSet.h"
31#include "llvm/Support/Compiler.h"
32#include "llvm/Support/ErrorHandling.h"
33#include "llvm/Support/raw_ostream.h"
34#include
35#include
36#include
37
38using namespace clang;
39
40static int compareInt(unsigned A, unsigned B) {
41 return (A < B ? -1 : (A > B ? 1 : 0));
42}
43
47
52 if (!LII)
53 return RII ? -1 : 0;
54 if (!RII)
55 return 1;
56
58 }
59
65
68 return LHSSelector.getAsIdentifierInfo()->getName().compare(
69 RHSSelector.getAsIdentifierInfo()->getName());
70 }
72 for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
73 if (int Compare = LHSSelector.getNameForSlot(I).compare(
75 return Compare;
76 }
77
79 }
80
85 return -1;
87 return 1;
88 return 0;
89
91
92
95
99
103
105 return 0;
106 }
107
108 llvm_unreachable("Invalid DeclarationName Kind!");
109}
110
112 raw_ostream &OS,
114
117
118 if (const RecordType *ClassRec = ClassType->getAsCanonical()) {
119 ClassRec->getDecl()->printName(OS, Policy);
120 return;
121 }
123 if (auto *InjTy = ClassType->getAsCanonical()) {
124 InjTy->getDecl()->printName(OS, Policy);
125 return;
126 }
127 }
128 ClassType.print(OS, Policy);
129}
130
136 StringRef Name = II->getName();
137
138
139 if (II->isMangledOpenMPVariantName()) {
140 std::pair<StringRef, StringRef> NameContextPair =
142 OS << NameContextPair.first << "["
143 << OMPTraitInfo(NameContextPair.second) << "]";
144 } else {
145 OS << Name;
146 }
147 }
148 return;
149
154 return;
155
158
160 OS << '~';
162
164 OS << "<deduction guide for ";
166 OS << '>';
167 return;
168
171 assert(OpName && "not an overloaded operator");
172
173 OS << "operator";
174 if (OpName[0] >= 'a' && OpName[0] <= 'z')
175 OS << ' ';
176 OS << OpName;
177 return;
178 }
179
182 return;
183
185 OS << "operator ";
187 if (const RecordType *Rec = Type->getAs()) {
188 OS << *Rec->getDecl();
189 return;
190 }
191
194 Type.print(OS, CXXPolicy);
195 return;
196 }
198 OS << "";
199 return;
200 }
201
202 llvm_unreachable("Unexpected declaration name kind");
203}
204
206
212
213}
214
217 if (.isNull() && T->isDependentType())
218 return true;
219
220
222 if (TD && TD->getDeclContext()->isDependentContext())
223 return true;
224
225 return false;
226}
227
230 llvm::raw_string_ostream OS(Result);
231 OS << *this;
233}
234
235void *DeclarationName::getFETokenInfoSlow() const {
238 llvm_unreachable("case Identifier already handled by getFETokenInfo!");
242 return castAsCXXSpecialNameExtra()->FETokenInfo;
244 return castAsCXXOperatorIdName()->FETokenInfo;
246 return castAsCXXDeductionGuideNameExtra()->FETokenInfo;
248 return castAsCXXLiteralOperatorIdName()->FETokenInfo;
249 default:
250 llvm_unreachable("DeclarationName has no FETokenInfo!");
251 }
252}
253
254void DeclarationName::setFETokenInfoSlow(void *T) {
257 llvm_unreachable("case Identifier already handled by setFETokenInfo!");
261 castAsCXXSpecialNameExtra()->FETokenInfo = T;
262 break;
264 castAsCXXOperatorIdName()->FETokenInfo = T;
265 break;
267 castAsCXXDeductionGuideNameExtra()->FETokenInfo = T;
268 break;
270 castAsCXXLiteralOperatorIdName()->FETokenInfo = T;
271 break;
272 default:
273 llvm_unreachable("DeclarationName has no FETokenInfo!");
274 }
275}
276
278 llvm::errs() << *this << '\n';
279}
280
286
290
291 llvm::FoldingSetNodeID ID;
293
294 void *InsertPos = nullptr;
295 if (auto *Name = CXXDeductionGuideNames.FindNodeOrInsertPos(ID, InsertPos))
297
299 CXXDeductionGuideNames.InsertNode(Name, InsertPos);
301}
302
304
306
307 llvm::FoldingSetNodeID ID;
309 void *InsertPos = nullptr;
310 if (auto *Name = CXXConstructorNames.FindNodeOrInsertPos(ID, InsertPos))
311 return {Name, DeclarationName::StoredCXXConstructorName};
312
313
315 CXXConstructorNames.InsertNode(SpecialName, InsertPos);
316 return {SpecialName, DeclarationName::StoredCXXConstructorName};
317}
318
320
322
323 llvm::FoldingSetNodeID ID;
325 void *InsertPos = nullptr;
326 if (auto *Name = CXXDestructorNames.FindNodeOrInsertPos(ID, InsertPos))
327 return {Name, DeclarationName::StoredCXXDestructorName};
328
329
331 CXXDestructorNames.InsertNode(SpecialName, InsertPos);
332 return {SpecialName, DeclarationName::StoredCXXDestructorName};
333}
334
337
338 llvm::FoldingSetNodeID ID;
340 void *InsertPos = nullptr;
341 if (auto *Name =
342 CXXConversionFunctionNames.FindNodeOrInsertPos(ID, InsertPos))
343 return {Name, DeclarationName::StoredCXXConversionFunctionName};
344
345
347 CXXConversionFunctionNames.InsertNode(SpecialName, InsertPos);
348 return {SpecialName, DeclarationName::StoredCXXConversionFunctionName};
349}
350
354 switch (Kind) {
361 default:
362 llvm_unreachable("Invalid kind in getCXXSpecialName!");
363 }
364}
365
368 llvm::FoldingSetNodeID ID;
369 ID.AddPointer(II);
370
371 void *InsertPos = nullptr;
372 if (auto *Name = CXXLiteralOperatorNames.FindNodeOrInsertPos(ID, InsertPos))
374
376 CXXLiteralOperatorNames.InsertNode(LiteralName, InsertPos);
378}
379
384 break;
388 setNamedTypeLoc(nullptr);
389 break;
392 break;
395 break;
399
400 break;
402 break;
403 }
404}
405
407 switch (Name.getNameKind()) {
416 return false;
417
421 if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo())
422 return TInfo->getType()->containsUnexpandedParameterPack();
423
424 return Name.getCXXNameType()->containsUnexpandedParameterPack();
425 }
426 llvm_unreachable("All name kinds handled.");
427}
428
430 switch (Name.getNameKind()) {
439 return false;
440
444 if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo())
445 return TInfo->getType()->isInstantiationDependentType();
446
447 return Name.getCXXNameType()->isInstantiationDependentType();
448 }
449 llvm_unreachable("All name kinds handled.");
450}
451
454 llvm::raw_string_ostream OS(Result);
455 OS << *this;
457}
458
464
466 switch (Name.getNameKind()) {
475 Name.print(OS, Policy);
476 return;
477
481 if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo()) {
483 OS << '~';
485 OS << "operator ";
489 OS << TInfo->getType().getAsString(Policy);
490 } else
491 Name.print(OS, Policy);
492 return;
493 }
494 llvm_unreachable("Unexpected declaration name kind");
495}
496
497SourceLocation DeclarationNameInfo::getEndLocPrivate() const {
501 return NameLoc;
502
505
508
513 return TInfo->getTypeLoc().getEndLoc();
514 else
515 return NameLoc;
516
517
522 return NameLoc;
523 }
524 llvm_unreachable("Unexpected declaration name kind");
525}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
static void printCXXConstructorDestructorName(QualType ClassType, raw_ostream &OS, PrintingPolicy Policy)
Definition DeclarationName.cpp:111
static int compareInt(unsigned A, unsigned B)
Definition DeclarationName.cpp:40
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
This file defines OpenMP AST classes for clauses.
Defines an enumeration for C++ overloaded operators.
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TypeLoc interface and its subclasses.
Allows QualTypes to be sorted and hence used in maps and sets.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
SourceLocation getCXXLiteralOperatorNameLoc() const
Return the location of the literal operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
Returns the source type info.
SourceLocation getCXXOperatorNameEndLoc() const
Return the end location of the getCXXOperatorNameRange() range.
The name of a declaration.
static int compare(DeclarationName LHS, DeclarationName RHS)
Definition DeclarationName.cpp:44
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
bool isDependentName() const
Determines whether the name itself is dependent, e.g., because it involves a C++ type that is itself ...
Definition DeclarationName.cpp:215
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Definition DeclarationName.cpp:131
std::string getAsString() const
Retrieve the human-readable string for this name.
Definition DeclarationName.cpp:228
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
NameKind
The kind of the name stored in this DeclarationName.
@ CXXConversionFunctionName
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.
void dump() const
Definition DeclarationName.cpp:277
NameKind getNameKind() const
Determine what kind of name this is.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Helper data structure representing the traits in a match clause of an declare variant or metadirectiv...
A (possibly-)qualified type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
unsigned getNumArgs() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
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.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const T * getAs() const
Member-template getAs'.
Contains the actual identifier that makes up the name of a C++ literal operator.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ NUM_OVERLOADED_OPERATORS
static constexpr StringRef getOpenMPVariantManglingSeparatorStr()
OpenMP variants are mangled early based on their OpenMP context selector.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
U cast(CodeGen::Address addr)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
bool isInstantiationDependent() const
Determine whether this name involves a template parameter.
Definition DeclarationName.cpp:429
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
Definition DeclarationName.cpp:465
std::string getAsString() const
getAsString - Retrieve the human-readable string for this name.
Definition DeclarationName.cpp:452
bool containsUnexpandedParameterPack() const
Determine whether this name contains an unexpanded parameter pack.
Definition DeclarationName.cpp:406
Describes how types, statements, expressions, and declarations should be printed.
void adjustForCPlusPlus()
Adjust this printing policy for cases where it's known that we're printing C++ code (for instance,...
unsigned SuppressScope
Suppresses printing of scope specifiers.
unsigned SuppressTemplateArgsInCXXConstructors
When true, suppresses printing template arguments in names of C++ constructors.
Function object that provides a total ordering on QualType values.