clang: lib/AST/QualTypeNames.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14
16
18
19
20
21
22
23
24
25
26
27static NestedNameSpecifier
29 bool WithGlobalNsPrefix);
30
31
32
33
34
35
36
37
38
39
40
42 const TypeDecl *TD,
43 bool FullyQualify,
44 bool WithGlobalNsPrefix);
45
46static NestedNameSpecifier
48 bool FullyQualified,
49 bool WithGlobalNsPrefix);
50
52 const ASTContext &Ctx, NestedNameSpecifier NNS, bool WithGlobalNsPrefix);
53
56 bool WithGlobalNsPrefix) {
57 bool Changed = false;
59
61 if (!ArgTDecl)
62 return false;
63
65
66 if (QTName &&
71 if (QNNS != NNS) {
72 Changed = true;
73 NNS = QNNS;
74 } else {
75 NNS = std::nullopt;
76 }
77 } else {
79 Ctx, ArgTDecl, true, WithGlobalNsPrefix);
80 }
81 if (NNS) {
85 TName =
87 false, UnderlyingTN);
88 Changed = true;
89 }
90 return Changed;
91}
92
95 bool WithGlobalNsPrefix) {
96 bool Changed = false;
97
98
99
100
104 if (Changed) {
106 }
109
111 if (QTFQ != SubTy) {
113 Changed = true;
114 }
115 }
116 return Changed;
117}
118
120 const TagType *TSTRecord,
123 bool WithGlobalNsPrefix) {
124
125
126
127
128 const auto *TD = TSTRecord->getDecl();
129 const auto *TSTDecl = dyn_cast(TD);
130 if (!TSTDecl)
133
135
136 bool MightHaveChanged = false;
138 for (unsigned int I = 0, E = TemplateArgs.size(); I != E; ++I) {
139
140
142 MightHaveChanged |=
144 FQArgs.push_back(Arg);
145 }
146
147 if (!MightHaveChanged)
150
151
153 Qualifier, false,
154 TemplateName(TSTDecl->getSpecializedTemplate()));
157 {}, TSTRecord->getCanonicalTypeInternal());
158
159
160
162}
163
164static const Type *
166 const TemplateSpecializationType *TST,
167 bool WithGlobalNsPrefix) {
169 bool MightHaveChanged =
172
173
175 MightHaveChanged |=
177 FQArgs.push_back(Arg);
178 }
179
180 if (!MightHaveChanged)
181 return TST;
182
185 {}, TST->desugar());
186
187
188
190}
191
193 bool FullyQualify,
194 bool WithGlobalNsPrefix) {
196 if (const auto *NS = dyn_cast(DC)) {
197 while (NS && NS->isInline()) {
198
199 NS = dyn_cast(NS->getDeclContext());
200 }
201 if (NS && NS->getDeclName()) {
203 }
204 return std::nullopt;
205 }
206 if (const auto *TD = dyn_cast(DC))
208 if (const auto *TDD = dyn_cast(DC))
210 WithGlobalNsPrefix);
213 return std::nullopt;
214}
215
216
219 switch (Scope.getKind()) {
221 llvm_unreachable("can't fully qualify the empty nested name specifier");
224
228 Ctx, Scope.getAsNamespaceAndPrefix().Namespace->getNamespace(),
229 WithGlobalNsPrefix);
232
234 if (const TagType *TagDeclType = Type->getAs())
235 TD = TagDeclType->getDecl();
236 else if (const auto *D = dyn_cast(Type))
237 TD = D->getDecl();
238 else
241 WithGlobalNsPrefix);
242 }
243 }
244 llvm_unreachable("bad NNS kind");
245}
246
247
248
251 bool FullyQualified,
252 bool WithGlobalNsPrefix) {
253 assert(Decl);
254
255
257 return std::nullopt;
259 const auto *Outer = dyn_cast(DC);
260 const auto *OuterNS = dyn_cast(DC);
261 if (OuterNS && OuterNS->isAnonymousNamespace())
262 OuterNS = dyn_cast(OuterNS->getParent());
263 if (Outer) {
264 if (const auto *CxxDecl = dyn_cast(DC)) {
266 CxxDecl->getDescribedClassTemplate()) {
267
268
269
270
271
272
273
274
275
276
277 if (!ClassTempl->specializations().empty()) {
278 Decl = *(ClassTempl->spec_begin());
279 Outer = dyn_cast(Decl);
280 OuterNS = dyn_cast(Decl);
281 }
282 }
283 }
284
285 if (OuterNS) {
287 } else if (const auto *TD = dyn_cast(Outer)) {
289 Ctx, TD, FullyQualified, WithGlobalNsPrefix);
291
292 return std::nullopt;
293 } else {
294
295
296
297 return std::nullopt;
298 }
301 }
302 return std::nullopt;
303}
304
305
306
309 bool FullyQualified,
310 bool WithGlobalNsPrefix) {
311 if (!TypePtr)
312 return std::nullopt;
313
315
316 if (const auto *TDT = dyn_cast(TypePtr)) {
317 Decl = TDT->getDecl();
318 } else if (const auto *TagDeclType = dyn_cast(TypePtr)) {
319 Decl = TagDeclType->getDecl();
320 } else if (const auto *TST = dyn_cast(TypePtr)) {
321 Decl = TST->getTemplateName().getAsTemplateDecl();
322 } else {
324 }
325
327 return std::nullopt;
328
330 Ctx, Decl, FullyQualified, WithGlobalNsPrefix);
331}
332
335 bool WithGlobalNsPrefix) {
336 while (Namespace && Namespace->isInline()) {
337
338 Namespace = dyn_cast(Namespace->getDeclContext());
339 }
340 if (!Namespace)
341 return std::nullopt;
342
343 bool FullyQualify = true;
345 Ctx, Namespace,
346 createOuterNNS(Ctx, Namespace, FullyQualify, WithGlobalNsPrefix));
347}
348
351 bool FullyQualify,
352 bool WithGlobalNsPrefix) {
354 if (auto *RD = dyn_cast(TypePtr)) {
355
356
357
360 createOuterNNS(Ctx, TD, FullyQualify, WithGlobalNsPrefix),
361 WithGlobalNsPrefix);
362 } else if (auto *TST = dyn_cast(TypePtr)) {
364 }
366}
367
368
369
371 bool WithGlobalNsPrefix) {
372
373
375
379
381 return QT;
382 }
383
384 if (auto *MPT = dyn_cast(QT.getTypePtr())) {
385
387
390 Ctx, MPT->getQualifier(), WithGlobalNsPrefix);
392 MPT->getMostRecentCXXRecordDecl());
393
395 return QT;
396 }
397
398
399
401
405
406
407 if (IsLValueRefTy)
409 else
411
413 return QT;
414 }
415
416
417 if (auto *AT = dyn_cast(QT.getTypePtr())) {
424 Ctx.getAttributedType(AT->getAttrKind(), NewModified, NewEquivalent),
426 }
427
428
429
430
431
433
435
437
438
440 }
441
442 if (const auto *TST =
443 dyn_cast(QT.getTypePtr())) {
444
446 if (T == TST)
447 return QT;
449 }
450
451
452
453
456
457
458
462 }
463
464
466 Ctx, QT.getTypePtr(), true , WithGlobalNsPrefix);
467
468
469
470 if (const auto *TT = dyn_cast(QT.getTypePtr())) {
471
472
473
474
476 Ctx, TT, TT->getKeyword(), Prefix, WithGlobalNsPrefix);
478 } else if (const auto *TT = dyn_cast(QT.getTypePtr())) {
480 TT->getKeyword(), Prefix, TT->getDecl(),
482 } else {
483 assert(!Prefix && "Unhandled type node");
484 }
486 return QT;
487}
488
492 bool WithGlobalNsPrefix) {
495}
496
499 bool WithGlobalNsPrefix) {
501 WithGlobalNsPrefix);
502}
503
504}
505}
Defines the C++ template declaration subclasses.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T, ArrayRef< TemplateArgument > SpecifiedArgs, ArrayRef< TemplateArgument > CanonicalArgs, QualType Underlying=QualType()) const
TemplateName getQualifiedTemplateName(NestedNameSpecifier Qualifier, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getMemberPointerType(QualType T, NestedNameSpecifier Qualifier, const CXXRecordDecl *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
Declaration of a class template.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Decl - This represents one declaration (or definition), e.g.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
DeclContext * getDeclContext()
Represent a C++ namespace.
Represents a C++ nested name specifier, such as "\::std::vector::".
static constexpr NestedNameSpecifier getGlobal()
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Represents a template name as written in source code.
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
The collection of all-type qualifiers we support.
Scope - A scope is a transient data structure that is used while parsing the program.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
@ Template
The template argument is a template name that was provided for a template template parameter.
@ Type
The template argument is a type.
ArgKind getKind() const
Return the kind of stored template argument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
Represents a declaration of a type.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const T * getAs() const
Member-template getAs'.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
static bool getFullyQualifiedTemplateName(const ASTContext &Ctx, TemplateName &TName, bool WithGlobalNsPrefix)
Definition QualTypeNames.cpp:54
static const Type * getFullyQualifiedTemplateType(const ASTContext &Ctx, const TagType *TSTRecord, ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, bool WithGlobalNsPrefix)
Definition QualTypeNames.cpp:119
static bool getFullyQualifiedTemplateArgument(const ASTContext &Ctx, TemplateArgument &Arg, bool WithGlobalNsPrefix)
Definition QualTypeNames.cpp:93
static NestedNameSpecifier createNestedNameSpecifier(const ASTContext &Ctx, const NamespaceDecl *Namesp, bool WithGlobalNsPrefix)
Create a NestedNameSpecifier for Namesp and its enclosing scopes.
Definition QualTypeNames.cpp:334
static NestedNameSpecifier createOuterNNS(const ASTContext &Ctx, const Decl *D, bool FullyQualify, bool WithGlobalNsPrefix)
Definition QualTypeNames.cpp:192
std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx, const PrintingPolicy &Policy, bool WithGlobalNsPrefix=false)
Get the fully qualified name for a type.
Definition QualTypeNames.cpp:489
static NestedNameSpecifier createNestedNameSpecifierForScopeOf(const ASTContext &Ctx, const Decl *decl, bool FullyQualified, bool WithGlobalNsPrefix)
Create a nested name specifier for the declaring context of the type.
Definition QualTypeNames.cpp:250
static NestedNameSpecifier getFullyQualifiedNestedNameSpecifier(const ASTContext &Ctx, NestedNameSpecifier NNS, bool WithGlobalNsPrefix)
Return a fully qualified version of this name specifier.
Definition QualTypeNames.cpp:217
NestedNameSpecifier getFullyQualifiedDeclaredContext(const ASTContext &Ctx, const Decl *Decl, bool WithGlobalNsPrefix=false)
Get the fully qualified name for the declared context of a declaration.
Definition QualTypeNames.cpp:497
QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, bool WithGlobalNsPrefix=false)
Generates a QualType that can be used to name the same type if used at the end of the current transla...
Definition QualTypeNames.cpp:370
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
const FunctionProtoType * T
@ Keyword
The name has been typo-corrected to a keyword.
U cast(CodeGen::Address addr)
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
@ None
No keyword precedes the qualified type name.
Describes how types, statements, expressions, and declarations should be printed.