clang 18.0.0git
TypePrinter.cpp
Go to the documentation of this file.
1//===- TypePrinter.cpp - Pretty-Print Clang Types -------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code to print types from Clang's type system.
10//
11//===----------------------------------------------------------------------===//
12
14#include "clang/AST/Attr.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclBase.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclObjC.h"
20#include "clang/AST/Expr.h"
26#include "clang/AST/Type.h"
30#include "clang/Basic/LLVM.h"
35#include "llvm/ADT/ArrayRef.h"
36#include "llvm/ADT/DenseMap.h"
37#include "llvm/ADT/SmallString.h"
38#include "llvm/ADT/StringRef.h"
39#include "llvm/ADT/Twine.h"
40#include "llvm/Support/Casting.h"
41#include "llvm/Support/Compiler.h"
42#include "llvm/Support/ErrorHandling.h"
43#include "llvm/Support/SaveAndRestore.h"
44#include "llvm/Support/raw_ostream.h"
45#include <cassert>
46#include <string>
47
48using namespace clang;
49
50namespace {
51
52/// RAII object that enables printing of the ARC __strong lifetime
53/// qualifier.
54class IncludeStrongLifetimeRAII {
55 PrintingPolicy &Policy;
56 bool Old;
57
58public:
59 explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy)
60 : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
62 Policy.SuppressStrongLifetime = false;
63 }
64
65 ~IncludeStrongLifetimeRAII() { Policy.SuppressStrongLifetime = Old; }
66};
67
68class ParamPolicyRAII {
69 PrintingPolicy &Policy;
70 bool Old;
71
72public:
73 explicit ParamPolicyRAII(PrintingPolicy &Policy)
74 : Policy(Policy), Old(Policy.SuppressSpecifiers) {
75 Policy.SuppressSpecifiers = false;
76 }
77
78 ~ParamPolicyRAII() { Policy.SuppressSpecifiers = Old; }
79};
80
81class DefaultTemplateArgsPolicyRAII {
82 PrintingPolicy &Policy;
83 bool Old;
84
85public:
86 explicit DefaultTemplateArgsPolicyRAII(PrintingPolicy &Policy)
87 : Policy(Policy), Old(Policy.SuppressDefaultTemplateArgs) {
88 Policy.SuppressDefaultTemplateArgs = false;
89 }
90
91 ~DefaultTemplateArgsPolicyRAII() { Policy.SuppressDefaultTemplateArgs = Old; }
92};
93
94class ElaboratedTypePolicyRAII {
95 PrintingPolicy &Policy;
96 bool SuppressTagKeyword;
97 bool SuppressScope;
98
99public:
100 explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
101 SuppressTagKeyword = Policy.SuppressTagKeyword;
102 SuppressScope = Policy.SuppressScope;
103 Policy.SuppressTagKeyword = true;
104 Policy.SuppressScope = true;
105 }
106
107 ~ElaboratedTypePolicyRAII() {
108 Policy.SuppressTagKeyword = SuppressTagKeyword;
109 Policy.SuppressScope = SuppressScope;
110 }
111};
112
113class TypePrinter {
114 PrintingPolicy Policy;
115 unsigned Indentation;
116 bool HasEmptyPlaceHolder = false;
117 bool InsideCCAttribute = false;
118
119public:
120 explicit TypePrinter(const PrintingPolicy &Policy, unsigned Indentation = 0)
121 : Policy(Policy), Indentation(Indentation) {}
122
123 void print(const Type *ty, Qualifiers qs, raw_ostream &OS,
124 StringRef PlaceHolder);
125 void print(QualType T, raw_ostream &OS, StringRef PlaceHolder);
126
127 static bool canPrefixQualifiers(const Type *T, bool &NeedARCStrongQualifier);
128 void spaceBeforePlaceHolder(raw_ostream &OS);
129 void printTypeSpec(NamedDecl *D, raw_ostream &OS);
130 void printTemplateId(const TemplateSpecializationType *T, raw_ostream &OS,
131 bool FullyQualify);
132
133 void printBefore(QualType T, raw_ostream &OS);
134 void printAfter(QualType T, raw_ostream &OS);
135 void AppendScope(DeclContext *DC, raw_ostream &OS,
136 DeclarationName NameInScope);
137 void printTag(TagDecl *T, raw_ostream &OS);
138 void printFunctionAfter(const FunctionType::ExtInfo &Info, raw_ostream &OS);
139#define ABSTRACT_TYPE(CLASS, PARENT)
140#define TYPE(CLASS, PARENT) \
141 void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
142 void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
143#include "clang/AST/TypeNodes.inc"
144
145private:
146 void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);
147 void printAfter(const Type *ty, Qualifiers qs, raw_ostream &OS);
148};
149
150} // namespace
151
152static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
153 bool HasRestrictKeyword) {
154 bool appendSpace = false;
155 if (TypeQuals & Qualifiers::Const) {
156 OS << "const";
157 appendSpace = true;
158 }
159 if (TypeQuals & Qualifiers::Volatile) {
160 if (appendSpace) OS << ' ';
161 OS << "volatile";
162 appendSpace = true;
163 }
164 if (TypeQuals & Qualifiers::Restrict) {
165 if (appendSpace) OS << ' ';
166 if (HasRestrictKeyword) {
167 OS << "restrict";
168 } else {
169 OS << "__restrict";
170 }
171 }
172}
173
174void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
175 if (!HasEmptyPlaceHolder)
176 OS << ' ';
177}
178
180 const PrintingPolicy &Policy) {
181 if (Policy.PrintCanonicalTypes)
182 QT = QT.getCanonicalType();
183 return QT.split();
184}
185
186void TypePrinter::print(QualType t, raw_ostream &OS, StringRef PlaceHolder) {
187 SplitQualType split = splitAccordingToPolicy(t, Policy);
188 print(split.Ty, split.Quals, OS, PlaceHolder);
189}
190
191void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
192 StringRef PlaceHolder) {
193 if (!T) {
194 OS << "NULL TYPE";
195 return;
196 }
197
198 SaveAndRestore PHVal(HasEmptyPlaceHolder, PlaceHolder.empty());
199
200 printBefore(T, Quals, OS);
201 OS << PlaceHolder;
202 printAfter(T, Quals, OS);
203}
204
205bool TypePrinter::canPrefixQualifiers(const Type *T,
206 bool &NeedARCStrongQualifier) {
207 // CanPrefixQualifiers - We prefer to print type qualifiers before the type,
208 // so that we get "const int" instead of "int const", but we can't do this if
209 // the type is complex. For example if the type is "int*", we *must* print
210 // "int * const", printing "const int *" is different. Only do this when the
211 // type expands to a simple string.
212 bool CanPrefixQualifiers = false;
213 NeedARCStrongQualifier = false;
214 const Type *UnderlyingType = T;
215 if (const auto *AT = dyn_cast<AutoType>(T))
216 UnderlyingType = AT->desugar().getTypePtr();
217 if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))
218 UnderlyingType = Subst->getReplacementType().getTypePtr();
219 Type::TypeClass TC = UnderlyingType->getTypeClass();
220
221 switch (TC) {
222 case Type::Auto:
223 case Type::Builtin:
224 case Type::Complex:
225 case Type::UnresolvedUsing:
226 case Type::Using:
227 case Type::Typedef:
228 case Type::TypeOfExpr:
229 case Type::TypeOf:
230 case Type::Decltype:
231 case Type::UnaryTransform:
232 case Type::Record:
233 case Type::Enum:
234 case Type::Elaborated:
235 case Type::TemplateTypeParm:
236 case Type::SubstTemplateTypeParmPack:
237 case Type::DeducedTemplateSpecialization:
238 case Type::TemplateSpecialization:
239 case Type::InjectedClassName:
240 case Type::DependentName:
241 case Type::DependentTemplateSpecialization:
242 case Type::ObjCObject:
243 case Type::ObjCTypeParam:
244 case Type::ObjCInterface:
245 case Type::Atomic:
246 case Type::Pipe:
247 case Type::BitInt:
248 case Type::DependentBitInt:
249 case Type::BTFTagAttributed:
250 CanPrefixQualifiers = true;
251 break;
252
253 case Type::ObjCObjectPointer:
254 CanPrefixQualifiers = T->isObjCIdType() || T->isObjCClassType() ||
256 break;
257
258 case Type::VariableArray:
259 case Type::DependentSizedArray:
260 NeedARCStrongQualifier = true;
261 [[fallthrough]];
262
263 case Type::ConstantArray:
264 case Type::IncompleteArray:
265 return canPrefixQualifiers(
266 cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(),
267 NeedARCStrongQualifier);
268
269 case Type::Adjusted:
270 case Type::Decayed:
271 case Type::Pointer:
272 case Type::BlockPointer:
273 case Type::LValueReference:
274 case Type::RValueReference:
275 case Type::MemberPointer:
276 case Type::DependentAddressSpace:
277 case Type::DependentVector:
278 case Type::DependentSizedExtVector:
279 case Type::Vector:
280 case Type::ExtVector:
281 case Type::ConstantMatrix:
282 case Type::DependentSizedMatrix:
283 case Type::FunctionProto:
284 case Type::FunctionNoProto:
285 case Type::Paren:
286 case Type::PackExpansion:
287 case Type::SubstTemplateTypeParm:
288 case Type::MacroQualified:
289 CanPrefixQualifiers = false;
290 break;
291
292 case Type::Attributed: {
293 // We still want to print the address_space before the type if it is an
294 // address_space attribute.
295 const auto *AttrTy = cast<AttributedType>(UnderlyingType);
296 CanPrefixQualifiers = AttrTy->getAttrKind() == attr::AddressSpace;
297 break;
298 }
299 }
300
301 return CanPrefixQualifiers;
302}
303
304void TypePrinter::printBefore(QualType T, raw_ostream &OS) {
306
307 // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2
308 // at this level.
309 Qualifiers Quals = Split.Quals;
310 if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(Split.Ty))
311 Quals -= QualType(Subst, 0).getQualifiers();
312
313 printBefore(Split.Ty, Quals, OS);
314}
315
316/// Prints the part of the type string before an identifier, e.g. for
317/// "int foo[10]" it prints "int ".
318void TypePrinter::printBefore(const Type *T,Qualifiers Quals, raw_ostream &OS) {
319 if (Policy.SuppressSpecifiers && T->isSpecifierType())
320 return;
321
322 SaveAndRestore PrevPHIsEmpty(HasEmptyPlaceHolder);
323
324 // Print qualifiers as appropriate.
325
326 bool CanPrefixQualifiers = false;
327 bool NeedARCStrongQualifier = false;
328 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
329
330 if (CanPrefixQualifiers && !Quals.empty()) {
331 if (NeedARCStrongQualifier) {
332 IncludeStrongLifetimeRAII Strong(Policy);
333 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
334 } else {
335 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
336 }
337 }
338
339 bool hasAfterQuals = false;
340 if (!CanPrefixQualifiers && !Quals.empty()) {
341 hasAfterQuals = !Quals.isEmptyWhenPrinted(Policy);
342 if (hasAfterQuals)
343 HasEmptyPlaceHolder = false;
344 }
345
346 switch (T->getTypeClass()) {
347#define ABSTRACT_TYPE(CLASS, PARENT)
348#define TYPE(CLASS, PARENT) case Type::CLASS: \
349 print##CLASS##Before(cast<CLASS##Type>(T), OS); \
350 break;
351#include "clang/AST/TypeNodes.inc"
352 }
353
354 if (hasAfterQuals) {
355 if (NeedARCStrongQualifier) {
356 IncludeStrongLifetimeRAII Strong(Policy);
357 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
358 } else {
359 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
360 }
361 }
362}
363
364void TypePrinter::printAfter(QualType t, raw_ostream &OS) {
365 SplitQualType split = splitAccordingToPolicy(t, Policy);
366 printAfter(split.Ty, split.Quals, OS);
367}
368
369/// Prints the part of the type string after an identifier, e.g. for
370/// "int foo[10]" it prints "[10]".
371void TypePrinter::printAfter(const Type *T, Qualifiers Quals, raw_ostream &OS) {
372 switch (T->getTypeClass()) {
373#define ABSTRACT_TYPE(CLASS, PARENT)
374#define TYPE(CLASS, PARENT) case Type::CLASS: \
375 print##CLASS##After(cast<CLASS##Type>(T), OS); \
376 break;
377#include "clang/AST/TypeNodes.inc"
378 }
379}
380
381void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) {
382 OS << T->getName(Policy);
383 spaceBeforePlaceHolder(OS);
384}
385
386void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) {}
387
388void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) {
389 OS << "_Complex ";
390 printBefore(T->getElementType(), OS);
391}
392
393void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) {
394 printAfter(T->getElementType(), OS);
395}
396
397void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) {
398 IncludeStrongLifetimeRAII Strong(Policy);
399 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
400 printBefore(T->getPointeeType(), OS);
401 // Handle things like 'int (*A)[4];' correctly.
402 // FIXME: this should include vectors, but vectors use attributes I guess.
403 if (isa<ArrayType>(T->getPointeeType()))
404 OS << '(';
405 OS << '*';
406}
407
408void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) {
409 IncludeStrongLifetimeRAII Strong(Policy);
410 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
411 // Handle things like 'int (*A)[4];' correctly.
412 // FIXME: this should include vectors, but vectors use attributes I guess.
413 if (isa<ArrayType>(T->getPointeeType()))
414 OS << ')';
415 printAfter(T->getPointeeType(), OS);
416}
417
418void TypePrinter::printBlockPointerBefore(const BlockPointerType *T,
419 raw_ostream &OS) {
420 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
421 printBefore(T->getPointeeType(), OS);
422 OS << '^';
423}
424
425void TypePrinter::printBlockPointerAfter(const BlockPointerType *T,
426 raw_ostream &OS) {
427 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
428 printAfter(T->getPointeeType(), OS);
429}
430
431// When printing a reference, the referenced type might also be a reference.
432// If so, we want to skip that before printing the inner type.
434 if (auto *Ref = T->getAs<ReferenceType>())
435 return skipTopLevelReferences(Ref->getPointeeTypeAsWritten());
436 return T;
437}
438
439void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
440 raw_ostream &OS) {
441 IncludeStrongLifetimeRAII Strong(Policy);
442 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
444 printBefore(Inner, OS);
445 // Handle things like 'int (&A)[4];' correctly.
446 // FIXME: this should include vectors, but vectors use attributes I guess.
447 if (isa<ArrayType>(Inner))
448 OS << '(';
449 OS << '&';
450}
451
452void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T,
453 raw_ostream &OS) {
454 IncludeStrongLifetimeRAII Strong(Policy);
455 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
457 // Handle things like 'int (&A)[4];' correctly.
458 // FIXME: this should include vectors, but vectors use attributes I guess.
459 if (isa<ArrayType>(Inner))
460 OS << ')';
461 printAfter(Inner, OS);
462}
463
464void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
465 raw_ostream &OS) {
466 IncludeStrongLifetimeRAII Strong(Policy);
467 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
469 printBefore(Inner, OS);
470 // Handle things like 'int (&&A)[4];' correctly.
471 // FIXME: this should include vectors, but vectors use attributes I guess.
472 if (isa<ArrayType>(Inner))
473 OS << '(';
474 OS << "&&";
475}
476
477void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T,
478 raw_ostream &OS) {
479 IncludeStrongLifetimeRAII Strong(Policy);
480 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
482 // Handle things like 'int (&&A)[4];' correctly.
483 // FIXME: this should include vectors, but vectors use attributes I guess.
484 if (isa<ArrayType>(Inner))
485 OS << ')';
486 printAfter(Inner, OS);
487}
488
489void TypePrinter::printMemberPointerBefore(const MemberPointerType *T,
490 raw_ostream &OS) {
491 IncludeStrongLifetimeRAII Strong(Policy);
492 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
493 printBefore(T->getPointeeType(), OS);
494 // Handle things like 'int (Cls::*A)[4];' correctly.
495 // FIXME: this should include vectors, but vectors use attributes I guess.
496 if (isa<ArrayType>(T->getPointeeType()))
497 OS << '(';
498
499 PrintingPolicy InnerPolicy(Policy);
500 InnerPolicy.IncludeTagDefinition = false;
501 TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
502
503 OS << "::*";
504}
505
506void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
507 raw_ostream &OS) {
508 IncludeStrongLifetimeRAII Strong(Policy);
509 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
510 // Handle things like 'int (Cls::*A)[4];' correctly.
511 // FIXME: this should include vectors, but vectors use attributes I guess.
512 if (isa<ArrayType>(T->getPointeeType()))
513 OS << ')';
514 printAfter(T->getPointeeType(), OS);
515}
516
517void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
518 raw_ostream &OS) {
519 IncludeStrongLifetimeRAII Strong(Policy);
520 printBefore(T->getElementType(), OS);
521}
522
523void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
524 raw_ostream &OS) {
525 OS << '[';
528 Policy.Restrict);
529 OS << ' ';
530 }
531
532 if (T->getSizeModifier() == ArraySizeModifier::Static)
533 OS << "static ";
534
535 OS << T->getSize().getZExtValue() << ']';
536 printAfter(T->getElementType(), OS);
537}
538
539void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
540 raw_ostream &OS) {
541 IncludeStrongLifetimeRAII Strong(Policy);
542 printBefore(T->getElementType(), OS);
543}
544
545void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
546 raw_ostream &OS) {
547 OS << "[]";
548 printAfter(T->getElementType(), OS);
549}
550
551void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
552 raw_ostream &OS) {
553 IncludeStrongLifetimeRAII Strong(Policy);
554 printBefore(T->getElementType(), OS);
555}
556
557void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
558 raw_ostream &OS) {
559 OS << '[';
561 AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict);
562 OS << ' ';
563 }
564
565 if (T->getSizeModifier() == ArraySizeModifier::Static)
566 OS << "static ";
567 else if (T->getSizeModifier() == ArraySizeModifier::Star)
568 OS << '*';
569
570 if (T->getSizeExpr())
571 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
572 OS << ']';
573
574 printAfter(T->getElementType(), OS);
575}
576
577void TypePrinter::printAdjustedBefore(const AdjustedType *T, raw_ostream &OS) {
578 // Print the adjusted representation, otherwise the adjustment will be
579 // invisible.
580 printBefore(T->getAdjustedType(), OS);
581}
582
583void TypePrinter::printAdjustedAfter(const AdjustedType *T, raw_ostream &OS) {
584 printAfter(T->getAdjustedType(), OS);
585}
586
587void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) {
588 // Print as though it's a pointer.
589 printAdjustedBefore(T, OS);
590}
591
592void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) {
593 printAdjustedAfter(T, OS);
594}
595
596void TypePrinter::printDependentSizedArrayBefore(
598 raw_ostream &OS) {
599 IncludeStrongLifetimeRAII Strong(Policy);
600 printBefore(T->getElementType(), OS);
601}
602
603void TypePrinter::printDependentSizedArrayAfter(
605 raw_ostream &OS) {
606 OS << '[';
607 if (T->getSizeExpr())
608 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
609 OS << ']';
610 printAfter(T->getElementType(), OS);
611}
612
613void TypePrinter::printDependentAddressSpaceBefore(
614 const DependentAddressSpaceType *T, raw_ostream &OS) {
615 printBefore(T->getPointeeType(), OS);
616}
617
618void TypePrinter::printDependentAddressSpaceAfter(
619 const DependentAddressSpaceType *T, raw_ostream &OS) {
620 OS << " __attribute__((address_space(";
621 if (T->getAddrSpaceExpr())
622 T->getAddrSpaceExpr()->printPretty(OS, nullptr, Policy);
623 OS << ")))";
624 printAfter(T->getPointeeType(), OS);
625}
626
627void TypePrinter::printDependentSizedExtVectorBefore(
629 raw_ostream &OS) {
630 printBefore(T->getElementType(), OS);
631}
632
633void TypePrinter::printDependentSizedExtVectorAfter(
635 raw_ostream &OS) {
636 OS << " __attribute__((ext_vector_type(";
637 if (T->getSizeExpr())
638 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
639 OS << ")))";
640 printAfter(T->getElementType(), OS);
641}
642
643void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) {
644 switch (T->getVectorKind()) {
645 case VectorKind::AltiVecPixel:
646 OS << "__vector __pixel ";
647 break;
648 case VectorKind::AltiVecBool:
649 OS << "__vector __bool ";
650 printBefore(T->getElementType(), OS);
651 break;
652 case VectorKind::AltiVecVector:
653 OS << "__vector ";
654 printBefore(T->getElementType(), OS);
655 break;
656 case VectorKind::Neon:
657 OS << "__attribute__((neon_vector_type("
658 << T->getNumElements() << "))) ";
659 printBefore(T->getElementType(), OS);
660 break;
661 case VectorKind::NeonPoly:
662 OS << "__attribute__((neon_polyvector_type(" <<
663 T->getNumElements() << "))) ";
664 printBefore(T->getElementType(), OS);
665 break;
666 case VectorKind::Generic: {
667 // FIXME: We prefer to print the size directly here, but have no way
668 // to get the size of the type.
669 OS << "__attribute__((__vector_size__("
670 << T->getNumElements()
671 << " * sizeof(";
672 print(T->getElementType(), OS, StringRef());
673 OS << ")))) ";
674 printBefore(T->getElementType(), OS);
675 break;
676 }
677 case VectorKind::SveFixedLengthData:
678 case VectorKind::SveFixedLengthPredicate:
679 // FIXME: We prefer to print the size directly here, but have no way
680 // to get the size of the type.
681 OS << "__attribute__((__arm_sve_vector_bits__(";
682
683 if (T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
684 // Predicates take a bit per byte of the vector size, multiply by 8 to
685 // get the number of bits passed to the attribute.
686 OS << T->getNumElements() * 8;
687 else
688 OS << T->getNumElements();
689
690 OS << " * sizeof(";
691 print(T->getElementType(), OS, StringRef());
692 // Multiply by 8 for the number of bits.
693 OS << ") * 8))) ";
694 printBefore(T->getElementType(), OS);
695 break;
696 case VectorKind::RVVFixedLengthData:
697 // FIXME: We prefer to print the size directly here, but have no way
698 // to get the size of the type.
699 OS << "__attribute__((__riscv_rvv_vector_bits__(";
700
701 OS << T->getNumElements();
702
703 OS << " * sizeof(";
704 print(T->getElementType(), OS, StringRef());
705 // Multiply by 8 for the number of bits.
706 OS << ") * 8))) ";
707 printBefore(T->getElementType(), OS);
708 break;
709 }
710}
711
712void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) {
713 printAfter(T->getElementType(), OS);
714}
715
716void TypePrinter::printDependentVectorBefore(
717 const DependentVectorType *T, raw_ostream &OS) {
718 switch (T->getVectorKind()) {
719 case VectorKind::AltiVecPixel:
720 OS << "__vector __pixel ";
721 break;
722 case VectorKind::AltiVecBool:
723 OS << "__vector __bool ";
724 printBefore(T->getElementType(), OS);
725 break;
726 case VectorKind::AltiVecVector:
727 OS << "__vector ";
728 printBefore(T->getElementType(), OS);
729 break;
730 case VectorKind::Neon:
731 OS << "__attribute__((neon_vector_type(";
732 if (T->getSizeExpr())
733 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
734 OS << "))) ";
735 printBefore(T->getElementType(), OS);
736 break;
737 case VectorKind::NeonPoly:
738 OS << "__attribute__((neon_polyvector_type(";
739 if (T->getSizeExpr())
740 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
741 OS << "))) ";
742 printBefore(T->getElementType(), OS);
743 break;
744 case VectorKind::Generic: {
745 // FIXME: We prefer to print the size directly here, but have no way
746 // to get the size of the type.
747 OS << "__attribute__((__vector_size__(";
748 if (T->getSizeExpr())
749 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
750 OS << " * sizeof(";
751 print(T->getElementType(), OS, StringRef());
752 OS << ")))) ";
753 printBefore(T->getElementType(), OS);
754 break;
755 }
756 case VectorKind::SveFixedLengthData:
757 case VectorKind::SveFixedLengthPredicate:
758 // FIXME: We prefer to print the size directly here, but have no way
759 // to get the size of the type.
760 OS << "__attribute__((__arm_sve_vector_bits__(";
761 if (T->getSizeExpr()) {
762 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
763 if (T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
764 // Predicates take a bit per byte of the vector size, multiply by 8 to
765 // get the number of bits passed to the attribute.
766 OS << " * 8";
767 OS << " * sizeof(";
768 print(T->getElementType(), OS, StringRef());
769 // Multiply by 8 for the number of bits.
770 OS << ") * 8";
771 }
772 OS << "))) ";
773 printBefore(T->getElementType(), OS);
774 break;
775 case VectorKind::RVVFixedLengthData:
776 // FIXME: We prefer to print the size directly here, but have no way
777 // to get the size of the type.
778 OS << "__attribute__((__riscv_rvv_vector_bits__(";
779 if (T->getSizeExpr()) {
780 T->getSizeExpr()->printPretty(OS, nullptr, Policy);
781 OS << " * sizeof(";
782 print(T->getElementType(), OS, StringRef());
783 // Multiply by 8 for the number of bits.
784 OS << ") * 8";
785 }
786 OS << "))) ";
787 printBefore(T->getElementType(), OS);
788 break;
789 }
790}
791
792void TypePrinter::printDependentVectorAfter(
793 const DependentVectorType *T, raw_ostream &OS) {
794 printAfter(T->getElementType(), OS);
795}
796
797void TypePrinter::printExtVectorBefore(const ExtVectorType *T,
798 raw_ostream &OS) {
799 printBefore(T->getElementType(), OS);
800}
801
802void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) {
803 printAfter(T->getElementType(), OS);
804 OS << " __attribute__((ext_vector_type(";
805 OS << T->getNumElements();
806 OS << ")))";
807}
808
809void TypePrinter::printConstantMatrixBefore(const ConstantMatrixType *T,
810 raw_ostream &OS) {
811 printBefore(T->getElementType(), OS);
812 OS << " __attribute__((matrix_type(";
813 OS << T->getNumRows() << ", " << T->getNumColumns();
814 OS << ")))";
815}
816
817void TypePrinter::printConstantMatrixAfter(const ConstantMatrixType *T,
818 raw_ostream &OS) {
819 printAfter(T->getElementType(), OS);
820}
821
822void TypePrinter::printDependentSizedMatrixBefore(
823 const DependentSizedMatrixType *T, raw_ostream &OS) {
824 printBefore(T->getElementType(), OS);
825 OS << " __attribute__((matrix_type(";
826 if (T->getRowExpr()) {
827 T->getRowExpr()->printPretty(OS, nullptr, Policy);
828 }
829 OS << ", ";
830 if (T->getColumnExpr()) {
831 T->getColumnExpr()->printPretty(OS, nullptr, Policy);
832 }
833 OS << ")))";
834}
835
836void TypePrinter::printDependentSizedMatrixAfter(
837 const DependentSizedMatrixType *T, raw_ostream &OS) {
838 printAfter(T->getElementType(), OS);
839}
840
841void
843 const PrintingPolicy &Policy)
844 const {
846 OS << " throw(";
848 OS << "...";
849 else
850 for (unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
851 if (I)
852 OS << ", ";
853
854 OS << getExceptionType(I).stream(Policy);
855 }
856 OS << ')';
857 } else if (EST_NoThrow == getExceptionSpecType()) {
858 OS << " __attribute__((nothrow))";
860 OS << " noexcept";
861 // FIXME:Is it useful to print out the expression for a non-dependent
862 // noexcept specification?
864 OS << '(';
865 if (getNoexceptExpr())
866 getNoexceptExpr()->printPretty(OS, nullptr, Policy);
867 OS << ')';
868 }
869 }
870}
871
872void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T,
873 raw_ostream &OS) {
874 if (T->hasTrailingReturn()) {
875 OS << "auto ";
876 if (!HasEmptyPlaceHolder)
877 OS << '(';
878 } else {
879 // If needed for precedence reasons, wrap the inner part in grouping parens.
880 SaveAndRestore PrevPHIsEmpty(HasEmptyPlaceHolder, false);
881 printBefore(T->getReturnType(), OS);
882 if (!PrevPHIsEmpty.get())
883 OS << '(';
884 }
885}
886
888 switch (ABI) {
890 llvm_unreachable("asking for spelling of ordinary parameter ABI");
892 return "swift_context";
894 return "swift_async_context";
896 return "swift_error_result";
898 return "swift_indirect_result";
899 }
900 llvm_unreachable("bad parameter ABI kind");
901}
902
903void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T,
904 raw_ostream &OS) {
905 // If needed for precedence reasons, wrap the inner part in grouping parens.
906 if (!HasEmptyPlaceHolder)
907 OS << ')';
908 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
909
910 OS << '(';
911 {
912 ParamPolicyRAII ParamPolicy(Policy);
913 for (unsigned i = 0, e = T->getNumParams(); i != e; ++i) {
914 if (i) OS << ", ";
915
916 auto EPI = T->getExtParameterInfo(i);
917 if (EPI.isConsumed()) OS << "__attribute__((ns_consumed)) ";
918 if (EPI.isNoEscape())
919 OS << "__attribute__((noescape)) ";
920 auto ABI = EPI.getABI();
921 if (ABI != ParameterABI::Ordinary)
922 OS << "__attribute__((" << getParameterABISpelling(ABI) << ")) ";
923
924 print(T->getParamType(i), OS, StringRef());
925 }
926 }
927
928 if (T->isVariadic()) {
929 if (T->getNumParams())
930 OS << ", ";
931 OS << "...";
932 } else if (T->getNumParams() == 0 && Policy.UseVoidForZeroParams) {
933 // Do not emit int() if we have a proto, emit 'int(void)'.
934 OS << "void";
935 }
936
937 OS << ')';
938
940
942 OS << " __arm_streaming_compatible";
944 OS << " __arm_streaming";
946 OS << " __arm_shared_za";
948 OS << " __arm_preserves_za";
949
950 printFunctionAfter(Info, OS);
951
952 if (!T->getMethodQuals().empty())
953 OS << " " << T->getMethodQuals().getAsString();
954
955 switch (T->getRefQualifier()) {
956 case RQ_None:
957 break;
958
959 case RQ_LValue:
960 OS << " &";
961 break;
962
963 case RQ_RValue:
964 OS << " &&";
965 break;
966 }
967 T->printExceptionSpecification(OS, Policy);
968
969 if (T->hasTrailingReturn()) {
970 OS << " -> ";
971 print(T->getReturnType(), OS, StringRef());
972 } else
973 printAfter(T->getReturnType(), OS);
974}
975
976void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
977 raw_ostream &OS) {
978 if (!InsideCCAttribute) {
979 switch (Info.getCC()) {
980 case CC_C:
981 // The C calling convention is the default on the vast majority of platforms
982 // we support. If the user wrote it explicitly, it will usually be printed
983 // while traversing the AttributedType. If the type has been desugared, let
984 // the canonical spelling be the implicit calling convention.
985 // FIXME: It would be better to be explicit in certain contexts, such as a
986 // cdecl function typedef used to declare a member function with the
987 // Microsoft C++ ABI.
988 break;
989 case CC_X86StdCall:
990 OS << " __attribute__((stdcall))";
991 break;
992 case CC_X86FastCall:
993 OS << " __attribute__((fastcall))";
994 break;
995 case CC_X86ThisCall:
996 OS << " __attribute__((thiscall))";
997 break;
998 case CC_X86VectorCall:
999 OS << " __attribute__((vectorcall))";
1000 break;
1001 case CC_X86Pascal:
1002 OS << " __attribute__((pascal))";
1003 break;
1004 case CC_AAPCS:
1005 OS << " __attribute__((pcs(\"aapcs\")))";
1006 break;
1007 case CC_AAPCS_VFP:
1008 OS << " __attribute__((pcs(\"aapcs-vfp\")))";
1009 break;
1011 OS << "__attribute__((aarch64_vector_pcs))";
1012 break;
1013 case CC_AArch64SVEPCS:
1014 OS << "__attribute__((aarch64_sve_pcs))";
1015 break;
1017 OS << "__attribute__((amdgpu_kernel))";
1018 break;
1019 case CC_IntelOclBicc:
1020 OS << " __attribute__((intel_ocl_bicc))";
1021 break;
1022 case CC_Win64:
1023 OS << " __attribute__((ms_abi))";
1024 break;
1025 case CC_X86_64SysV:
1026 OS << " __attribute__((sysv_abi))";
1027 break;
1028 case CC_X86RegCall:
1029 OS << " __attribute__((regcall))";
1030 break;
1031 case CC_SpirFunction:
1032 case CC_OpenCLKernel:
1033 // Do nothing. These CCs are not available as attributes.
1034 break;
1035 case CC_Swift:
1036 OS << " __attribute__((swiftcall))";
1037 break;
1038 case CC_SwiftAsync:
1039 OS << "__attribute__((swiftasynccall))";
1040 break;
1041 case CC_PreserveMost:
1042 OS << " __attribute__((preserve_most))";
1043 break;
1044 case CC_PreserveAll:
1045 OS << " __attribute__((preserve_all))";
1046 break;
1047 case CC_M68kRTD:
1048 OS << " __attribute__((m68k_rtd))";
1049 break;
1050 }
1051 }
1052
1053 if (Info.getNoReturn())
1054 OS << " __attribute__((noreturn))";
1055 if (Info.getCmseNSCall())
1056 OS << " __attribute__((cmse_nonsecure_call))";
1057 if (Info.getProducesResult())
1058 OS << " __attribute__((ns_returns_retained))";
1059 if (Info.getRegParm())
1060 OS << " __attribute__((regparm ("
1061 << Info.getRegParm() << ")))";
1062 if (Info.getNoCallerSavedRegs())
1063 OS << " __attribute__((no_caller_saved_registers))";
1064 if (Info.getNoCfCheck())
1065 OS << " __attribute__((nocf_check))";
1066}
1067
1068void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T,
1069 raw_ostream &OS) {
1070 // If needed for precedence reasons, wrap the inner part in grouping parens.
1071 SaveAndRestore PrevPHIsEmpty(HasEmptyPlaceHolder, false);
1072 printBefore(T->getReturnType(), OS);
1073 if (!PrevPHIsEmpty.get())
1074 OS << '(';
1075}
1076
1077void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T,
1078 raw_ostream &OS) {
1079 // If needed for precedence reasons, wrap the inner part in grouping parens.
1080 if (!HasEmptyPlaceHolder)
1081 OS << ')';
1082 SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false);
1083
1084 OS << "()";
1085 printFunctionAfter(T->getExtInfo(), OS);
1086 printAfter(T->getReturnType(), OS);
1087}
1088
1089void TypePrinter::printTypeSpec(NamedDecl *D, raw_ostream &OS) {
1090
1091 // Compute the full nested-name-specifier for this type.
1092 // In C, this will always be empty except when the type
1093 // being printed is anonymous within other Record.
1094 if (!Policy.SuppressScope)
1095 AppendScope(D->getDeclContext(), OS, D->getDeclName());
1096
1097 IdentifierInfo *II = D->getIdentifier();
1098 OS << II->getName();
1099 spaceBeforePlaceHolder(OS);
1100}
1101
1102void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T,
1103 raw_ostream &OS) {
1104 printTypeSpec(T->getDecl(), OS);
1105}
1106
1107void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T,
1108 raw_ostream &OS) {}
1109
1110void TypePrinter::printUsingBefore(const UsingType *T, raw_ostream &OS) {
1111 // After `namespace b { using a::X }`, is the type X within B a::X or b::X?
1112 //
1113 // - b::X is more formally correct given the UsingType model
1114 // - b::X makes sense if "re-exporting" a symbol in a new namespace
1115 // - a::X makes sense if "importing" a symbol for convenience
1116 //
1117 // The "importing" use seems much more common, so we print a::X.
1118 // This could be a policy option, but the right choice seems to rest more
1119 // with the intent of the code than the caller.
1120 printTypeSpec(T->getFoundDecl()->getUnderlyingDecl(), OS);
1121}
1122
1123void TypePrinter::printUsingAfter(const UsingType *T, raw_ostream &OS) {}
1124
1125void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) {
1126 printTypeSpec(T->getDecl(), OS);
1127}
1128
1129void TypePrinter::printMacroQualifiedBefore(const MacroQualifiedType *T,
1130 raw_ostream &OS) {
1131 StringRef MacroName = T->getMacroIdentifier()->getName();
1132 OS << MacroName << " ";
1133
1134 // Since this type is meant to print the macro instead of the whole attribute,
1135 // we trim any attributes and go directly to the original modified type.
1136 printBefore(T->getModifiedType(), OS);
1137}
1138
1139void TypePrinter::printMacroQualifiedAfter(const MacroQualifiedType *T,
1140 raw_ostream &OS) {
1141 printAfter(T->getModifiedType(), OS);
1142}
1143
1144void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {}
1145
1146void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
1147 raw_ostream &OS) {
1148 OS << (T->getKind() == TypeOfKind::Unqualified ? "typeof_unqual "
1149 : "typeof ");
1150 if (T->getUnderlyingExpr())
1151 T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
1152 spaceBeforePlaceHolder(OS);
1153}
1154
1155void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
1156 raw_ostream &OS) {}
1157
1158void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
1159 OS << (T->getKind() == TypeOfKind::Unqualified ? "typeof_unqual("
1160 : "typeof(");
1161 print(T->getUnmodifiedType(), OS, StringRef());
1162 OS << ')';
1163 spaceBeforePlaceHolder(OS);
1164}
1165
1166void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) {}
1167
1168void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
1169 OS << "decltype(";
1170 if (T->getUnderlyingExpr())
1171 T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
1172 OS << ')';
1173 spaceBeforePlaceHolder(OS);
1174}
1175
1176void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) {}
1177
1178void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T,
1179 raw_ostream &OS) {
1180 IncludeStrongLifetimeRAII Strong(Policy);
1181
1182 static llvm::DenseMap<int, const char *> Transformation = {{
1183#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
1184 {UnaryTransformType::Enum, "__" #Trait},
1185#include "clang/Basic/TransformTypeTraits.def"
1186 }};
1187 OS << Transformation[T->getUTTKind()] << '(';
1188 print(T->getBaseType(), OS, StringRef());
1189 OS << ')';
1190 spaceBeforePlaceHolder(OS);
1191}
1192
1193void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T,
1194 raw_ostream &OS) {}
1195
1196void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
1197 // If the type has been deduced, do not print 'auto'.
1198 if (!T->getDeducedType().isNull()) {
1199 printBefore(T->getDeducedType(), OS);
1200 } else {
1201 if (T->isConstrained()) {
1202 // FIXME: Track a TypeConstraint as type sugar, so that we can print the
1203 // type as it was written.
1204 T->getTypeConstraintConcept()->getDeclName().print(OS, Policy);
1205 auto Args = T->getTypeConstraintArguments();
1206 if (!Args.empty())
1208 OS, Args, Policy,
1210 OS << ' ';
1211 }
1212 switch (T->getKeyword()) {
1213 case AutoTypeKeyword::Auto: OS << "auto"; break;
1214 case AutoTypeKeyword::DecltypeAuto: OS << "decltype(auto)"; break;
1215 case AutoTypeKeyword::GNUAutoType: OS << "__auto_type"; break;
1216 }
1217 spaceBeforePlaceHolder(OS);
1218 }
1219}
1220
1221void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) {
1222 // If the type has been deduced, do not print 'auto'.
1223 if (!T->getDeducedType().isNull())
1224 printAfter(T->getDeducedType(), OS);
1225}
1226
1227void TypePrinter::printDeducedTemplateSpecializationBefore(
1228 const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1229 // If the type has been deduced, print the deduced type.
1230 if (!T->getDeducedType().isNull()) {
1231 printBefore(T->getDeducedType(), OS);
1232 } else {
1233 IncludeStrongLifetimeRAII Strong(Policy);
1234 T->getTemplateName().print(OS, Policy);
1235 spaceBeforePlaceHolder(OS);
1236 }
1237}
1238
1239void TypePrinter::printDeducedTemplateSpecializationAfter(
1240 const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1241 // If the type has been deduced, print the deduced type.
1242 if (!T->getDeducedType().isNull())
1243 printAfter(T->getDeducedType(), OS);
1244}
1245
1246void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) {
1247 IncludeStrongLifetimeRAII Strong(Policy);
1248
1249 OS << "_Atomic(";
1250 print(T->getValueType(), OS, StringRef());
1251 OS << ')';
1252 spaceBeforePlaceHolder(OS);
1253}
1254
1255void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) {}
1256
1257void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
1258 IncludeStrongLifetimeRAII Strong(Policy);
1259
1260 if (T->isReadOnly())
1261 OS << "read_only ";
1262 else
1263 OS << "write_only ";
1264 OS << "pipe ";
1265 print(T->getElementType(), OS, StringRef());
1266 spaceBeforePlaceHolder(OS);
1267}
1268
1269void TypePrinter::printPipeAfter(const PipeType *T, raw_ostream &OS) {}
1270
1271void TypePrinter::printBitIntBefore(const BitIntType *T, raw_ostream &OS) {
1272 if (T->isUnsigned())
1273 OS << "unsigned ";
1274 OS << "_BitInt(" << T->getNumBits() << ")";
1275 spaceBeforePlaceHolder(OS);
1276}
1277
1278void TypePrinter::printBitIntAfter(const BitIntType *T, raw_ostream &OS) {}
1279
1280void TypePrinter::printDependentBitIntBefore(const DependentBitIntType *T,
1281 raw_ostream &OS) {
1282 if (T->isUnsigned())
1283 OS << "unsigned ";
1284 OS << "_BitInt(";
1285 T->getNumBitsExpr()->printPretty(OS, nullptr, Policy);
1286 OS << ")";
1287 spaceBeforePlaceHolder(OS);
1288}
1289
1290void TypePrinter::printDependentBitIntAfter(const DependentBitIntType *T,
1291 raw_ostream &OS) {}
1292
1293/// Appends the given scope to the end of a string.
1294void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS,
1295 DeclarationName NameInScope) {
1296 if (DC->isTranslationUnit())
1297 return;
1298
1299 // FIXME: Consider replacing this with NamedDecl::printNestedNameSpecifier,
1300 // which can also print names for function and method scopes.
1301 if (DC->isFunctionOrMethod())
1302 return;
1303
1304 if (Policy.Callbacks && Policy.Callbacks->isScopeVisible(DC))
1305 return;
1306
1307 if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1308 if (Policy.SuppressUnwrittenScope && NS->isAnonymousNamespace())
1309 return AppendScope(DC->getParent(), OS, NameInScope);
1310
1311 // Only suppress an inline namespace if the name has the same lookup
1312 // results in the enclosing namespace.
1313 if (Policy.SuppressInlineNamespace && NS->isInline() && NameInScope &&
1314 NS->isRedundantInlineQualifierFor(NameInScope))
1315 return AppendScope(DC->getParent(), OS, NameInScope);
1316
1317 AppendScope(DC->getParent(), OS, NS->getDeclName());
1318 if (NS->getIdentifier())
1319 OS << NS->getName() << "::";
1320 else
1321 OS << "(anonymous namespace)::";
1322 } else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1323 AppendScope(DC->getParent(), OS, Spec->getDeclName());
1324 IncludeStrongLifetimeRAII Strong(Policy);
1325 OS << Spec->getIdentifier()->getName();
1326 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1328 OS, TemplateArgs.asArray(), Policy,
1329 Spec->getSpecializedTemplate()->getTemplateParameters());
1330 OS << "::";
1331 } else if (const auto *Tag = dyn_cast<TagDecl>(DC)) {
1332 AppendScope(DC->getParent(), OS, Tag->getDeclName());
1333 if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
1334 OS << Typedef->getIdentifier()->getName() << "::";
1335 else if (Tag->getIdentifier())
1336 OS << Tag->getIdentifier()->getName() << "::";
1337 else
1338 return;
1339 } else {
1340 AppendScope(DC->getParent(), OS, NameInScope);
1341 }
1342}
1343
1344void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
1345 if (Policy.IncludeTagDefinition) {
1346 PrintingPolicy SubPolicy = Policy;
1347 SubPolicy.IncludeTagDefinition = false;
1348 D->print(OS, SubPolicy, Indentation);
1349 spaceBeforePlaceHolder(OS);
1350 return;
1351 }
1352
1353 bool HasKindDecoration = false;
1354
1355 // We don't print tags unless this is an elaborated type.
1356 // In C, we just assume every RecordType is an elaborated type.
1357 if (!Policy.SuppressTagKeyword && !D->getTypedefNameForAnonDecl()) {
1358 HasKindDecoration = true;
1359 OS << D->getKindName();
1360 OS << ' ';
1361 }
1362
1363 // Compute the full nested-name-specifier for this type.
1364 // In C, this will always be empty except when the type
1365 // being printed is anonymous within other Record.
1366 if (!Policy.SuppressScope)
1367 AppendScope(D->getDeclContext(), OS, D->getDeclName());
1368
1369 if (const IdentifierInfo *II = D->getIdentifier())
1370 OS << II->getName();
1371 else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
1372 assert(Typedef->getIdentifier() && "Typedef without identifier?");
1373 OS << Typedef->getIdentifier()->getName();
1374 } else {
1375 // Make an unambiguous representation for anonymous types, e.g.
1376 // (anonymous enum at /usr/include/string.h:120:9)
1377 OS << (Policy.MSVCFormatting ? '`' : '(');
1378
1379 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
1380 OS << "lambda";
1381 HasKindDecoration = true;
1382 } else if ((isa<RecordDecl>(D) && cast<RecordDecl>(D)->isAnonymousStructOrUnion())) {
1383 OS << "anonymous";
1384 } else {
1385 OS << "unnamed";
1386 }
1387
1388 if (Policy.AnonymousTagLocations) {
1389 // Suppress the redundant tag keyword if we just printed one.
1390 // We don't have to worry about ElaboratedTypes here because you can't
1391 // refer to an anonymous type with one.
1392 if (!HasKindDecoration)
1393 OS << " " << D->getKindName();
1394
1396 D->getLocation());
1397 if (PLoc.isValid()) {
1398 OS << " at ";
1399 StringRef File = PLoc.getFilename();
1400 llvm::SmallString<1024> WrittenFile(File);
1401 if (auto *Callbacks = Policy.Callbacks)
1402 WrittenFile = Callbacks->remapPath(File);
1403 // Fix inconsistent path separator created by
1404 // clang::DirectoryLookup::LookupFile when the file path is relative
1405 // path.
1406 llvm::sys::path::Style Style =
1407 llvm::sys::path::is_absolute(WrittenFile)
1408 ? llvm::sys::path::Style::native
1409 : (Policy.MSVCFormatting
1410 ? llvm::sys::path::Style::windows_backslash
1411 : llvm::sys::path::Style::posix);
1412 llvm::sys::path::native(WrittenFile, Style);
1413 OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
1414 }
1415 }
1416
1417 OS << (Policy.MSVCFormatting ? '\'' : ')');
1418 }
1419
1420 // If this is a class template specialization, print the template
1421 // arguments.
1422 if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1424 TypeSourceInfo *TAW = Spec->getTypeAsWritten();
1425 if (!Policy.PrintCanonicalTypes && TAW) {
1426 const TemplateSpecializationType *TST =
1427 cast<TemplateSpecializationType>(TAW->getType());
1428 Args = TST->template_arguments();
1429 } else {
1430 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1431 Args = TemplateArgs.asArray();
1432 }
1433 IncludeStrongLifetimeRAII Strong(Policy);
1435 OS, Args, Policy,
1436 Spec->getSpecializedTemplate()->getTemplateParameters());
1437 }
1438
1439 spaceBeforePlaceHolder(OS);
1440}
1441
1442void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
1443 // Print the preferred name if we have one for this type.
1444 if (Policy.UsePreferredNames) {
1445 for (const auto *PNA : T->getDecl()->specific_attrs<PreferredNameAttr>()) {
1446 if (!declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(),
1447 T->getDecl()))
1448 continue;
1449 // Find the outermost typedef or alias template.
1450 QualType T = PNA->getTypedefType();
1451 while (true) {
1452 if (auto *TT = dyn_cast<TypedefType>(T))
1453 return printTypeSpec(TT->getDecl(), OS);
1454 if (auto *TST = dyn_cast<TemplateSpecializationType>(T))
1455 return printTemplateId(TST, OS, /*FullyQualify=*/true);
1457 }
1458 }
1459 }
1460
1461 printTag(T->getDecl(), OS);
1462}
1463
1464void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) {}
1465
1466void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) {
1467 printTag(T->getDecl(), OS);
1468}
1469
1470void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) {}
1471
1472void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T,
1473 raw_ostream &OS) {
1474 TemplateTypeParmDecl *D = T->getDecl();
1475 if (D && D->isImplicit()) {
1476 if (auto *TC = D->getTypeConstraint()) {
1477 TC->print(OS, Policy);
1478 OS << ' ';
1479 }
1480 OS << "auto";
1481 } else if (IdentifierInfo *Id = T->getIdentifier())
1482 OS << (Policy.CleanUglifiedParameters ? Id->deuglifiedName()
1483 : Id->getName());
1484 else
1485 OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex();
1486
1487 spaceBeforePlaceHolder(OS);
1488}
1489
1490void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T,
1491 raw_ostream &OS) {}
1492
1493void TypePrinter::printSubstTemplateTypeParmBefore(
1495 raw_ostream &OS) {
1496 IncludeStrongLifetimeRAII Strong(Policy);
1497 printBefore(T->getReplacementType(), OS);
1498}
1499
1500void TypePrinter::printSubstTemplateTypeParmAfter(
1502 raw_ostream &OS) {
1503 IncludeStrongLifetimeRAII Strong(Policy);
1504 printAfter(T->getReplacementType(), OS);
1505}
1506
1507void TypePrinter::printSubstTemplateTypeParmPackBefore(
1509 raw_ostream &OS) {
1510 IncludeStrongLifetimeRAII Strong(Policy);
1511 if (const TemplateTypeParmDecl *D = T->getReplacedParameter()) {
1512 if (D && D->isImplicit()) {
1513 if (auto *TC = D->getTypeConstraint()) {
1514 TC->print(OS, Policy);
1515 OS << ' ';
1516 }
1517 OS << "auto";
1518 } else if (IdentifierInfo *Id = D->getIdentifier())
1519 OS << (Policy.CleanUglifiedParameters ? Id->deuglifiedName()
1520 : Id->getName());
1521 else
1522 OS << "type-parameter-" << D->getDepth() << '-' << D->getIndex();
1523
1524 spaceBeforePlaceHolder(OS);
1525 }
1526}
1527
1528void TypePrinter::printSubstTemplateTypeParmPackAfter(
1530 raw_ostream &OS) {
1531 IncludeStrongLifetimeRAII Strong(Policy);
1532}
1533
1534void TypePrinter::printTemplateId(const TemplateSpecializationType *T,
1535 raw_ostream &OS, bool FullyQualify) {
1536 IncludeStrongLifetimeRAII Strong(Policy);
1537
1539 // FIXME: Null TD never excercised in test suite.
1540 if (FullyQualify && TD) {
1541 if (!Policy.SuppressScope)
1542 AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
1543
1544 OS << TD->getName();
1545 } else {
1546 T->getTemplateName().print(OS, Policy);
1547 }
1548
1549 DefaultTemplateArgsPolicyRAII TemplateArgs(Policy);
1550 const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : nullptr;
1551 printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
1552 spaceBeforePlaceHolder(OS);
1553}
1554
1555void TypePrinter::printTemplateSpecializationBefore(
1557 raw_ostream &OS) {
1558 printTemplateId(T, OS, Policy.FullyQualifiedName);
1559}
1560
1561void TypePrinter::printTemplateSpecializationAfter(
1563 raw_ostream &OS) {}
1564
1565void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T,
1566 raw_ostream &OS) {
1567 if (Policy.PrintInjectedClassNameWithArguments)
1568 return printTemplateSpecializationBefore(T->getInjectedTST(), OS);
1569
1570 IncludeStrongLifetimeRAII Strong(Policy);
1571 T->getTemplateName().print(OS, Policy);
1572 spaceBeforePlaceHolder(OS);
1573}
1574
1575void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
1576 raw_ostream &OS) {}
1577
1578void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
1579 raw_ostream &OS) {
1580 if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
1581 TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
1582 assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
1583 "OwnedTagDecl expected to be a declaration for the type");
1584 PrintingPolicy SubPolicy = Policy;
1585 SubPolicy.IncludeTagDefinition = false;
1586 OwnedTagDecl->print(OS, SubPolicy, Indentation);
1587 spaceBeforePlaceHolder(OS);
1588 return;
1589 }
1590
1591 if (Policy.SuppressElaboration) {
1592 printBefore(T->getNamedType(), OS);
1593 return;
1594 }
1595
1596 // The tag definition will take care of these.
1597 if (!Policy.IncludeTagDefinition)
1598 {
1601 OS << " ";
1603 if (Qualifier)
1604 Qualifier->print(OS, Policy);
1605 }
1606
1607 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1608 printBefore(T->getNamedType(), OS);
1609}
1610
1611void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
1612 raw_ostream &OS) {
1613 if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
1614 return;
1615
1616 if (Policy.SuppressElaboration) {
1617 printAfter(T->getNamedType(), OS);
1618 return;
1619 }
1620
1621 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1622 printAfter(T->getNamedType(), OS);
1623}
1624
1625void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) {
1626 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
1627 printBefore(T->getInnerType(), OS);
1628 OS << '(';
1629 } else
1630 printBefore(T->getInnerType(), OS);
1631}
1632
1633void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) {
1634 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
1635 OS << ')';
1636 printAfter(T->getInnerType(), OS);
1637 } else
1638 printAfter(T->getInnerType(), OS);
1639}
1640
1641void TypePrinter::printDependentNameBefore(const DependentNameType *T,
1642 raw_ostream &OS) {
1645 OS << " ";
1646
1647 T->getQualifier()->print(OS, Policy);
1648
1649 OS << T->getIdentifier()->getName();
1650 spaceBeforePlaceHolder(OS);
1651}
1652
1653void TypePrinter::printDependentNameAfter(const DependentNameType *T,
1654 raw_ostream &OS) {}
1655
1656void TypePrinter::printDependentTemplateSpecializationBefore(
1657 const DependentTemplateSpecializationType *T, raw_ostream &OS) {
1658 IncludeStrongLifetimeRAII Strong(Policy);
1659
1662 OS << " ";
1663
1664 if (T->getQualifier())
1665 T->getQualifier()->print(OS, Policy);
1666 OS << "template " << T->getIdentifier()->getName();
1668 spaceBeforePlaceHolder(OS);
1669}
1670
1671void TypePrinter::printDependentTemplateSpecializationAfter(
1672 const DependentTemplateSpecializationType *T, raw_ostream &OS) {}
1673
1674void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
1675 raw_ostream &OS) {
1676 printBefore(T->getPattern(), OS);
1677}
1678
1679void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
1680 raw_ostream &OS) {
1681 printAfter(T->getPattern(), OS);
1682 OS << "...";
1683}
1684
1685void TypePrinter::printAttributedBefore(const AttributedType *T,
1686 raw_ostream &OS) {
1687 // FIXME: Generate this with TableGen.
1688
1689 // Prefer the macro forms of the GC and ownership qualifiers.
1690 if (T->getAttrKind() == attr::ObjCGC ||
1691 T->getAttrKind() == attr::ObjCOwnership)
1692 return printBefore(T->getEquivalentType(), OS);
1693
1694 if (T->getAttrKind() == attr::ObjCKindOf)
1695 OS << "__kindof ";
1696
1697 if (T->getAttrKind() == attr::AddressSpace)
1698 printBefore(T->getEquivalentType(), OS);
1699 else
1700 printBefore(T->getModifiedType(), OS);
1701
1702 if (T->isMSTypeSpec()) {
1703 switch (T->getAttrKind()) {
1704 default: return;
1705 case attr::Ptr32: OS << " __ptr32"; break;
1706 case attr::Ptr64: OS << " __ptr64"; break;
1707 case attr::SPtr: OS << " __sptr"; break;
1708 case attr::UPtr: OS << " __uptr"; break;
1709 }
1710 spaceBeforePlaceHolder(OS);
1711 }
1712
1713 if (T->isWebAssemblyFuncrefSpec())
1714 OS << "__funcref";
1715
1716 // Print nullability type specifiers.
1717 if (T->getImmediateNullability()) {
1718 if (T->getAttrKind() == attr::TypeNonNull)
1719 OS << " _Nonnull";
1720 else if (T->getAttrKind() == attr::TypeNullable)
1721 OS << " _Nullable";
1722 else if (T->getAttrKind() == attr::TypeNullUnspecified)
1723 OS << " _Null_unspecified";
1724 else if (T->getAttrKind() == attr::TypeNullableResult)
1725 OS << " _Nullable_result";
1726 else
1727 llvm_unreachable("unhandled nullability");
1728 spaceBeforePlaceHolder(OS);
1729 }
1730}
1731
1732void TypePrinter::printAttributedAfter(const AttributedType *T,
1733 raw_ostream &OS) {
1734 // FIXME: Generate this with TableGen.
1735
1736 // Prefer the macro forms of the GC and ownership qualifiers.
1737 if (T->getAttrKind() == attr::ObjCGC ||
1738 T->getAttrKind() == attr::ObjCOwnership)
1739 return printAfter(T->getEquivalentType(), OS);
1740
1741 // If this is a calling convention attribute, don't print the implicit CC from
1742 // the modified type.
1743 SaveAndRestore MaybeSuppressCC(InsideCCAttribute, T->isCallingConv());
1744
1745 printAfter(T->getModifiedType(), OS);
1746
1747 // Some attributes are printed as qualifiers before the type, so we have
1748 // nothing left to do.
1749 if (T->getAttrKind() == attr::ObjCKindOf || T->isMSTypeSpec() ||
1751 return;
1752
1753 // Don't print the inert __unsafe_unretained attribute at all.
1754 if (T->getAttrKind() == attr::ObjCInertUnsafeUnretained)
1755 return;
1756
1757 // Don't print ns_returns_retained unless it had an effect.
1758 if (T->getAttrKind() == attr::NSReturnsRetained &&
1761 return;
1762
1763 if (T->getAttrKind() == attr::LifetimeBound) {
1764 OS << " [[clang::lifetimebound]]";
1765 return;
1766 }
1767
1768 // The printing of the address_space attribute is handled by the qualifier
1769 // since it is still stored in the qualifier. Return early to prevent printing
1770 // this twice.
1771 if (T->getAttrKind() == attr::AddressSpace)
1772 return;
1773
1774 if (T->getAttrKind() == attr::AnnotateType) {
1775 // FIXME: Print the attribute arguments once we have a way to retrieve these
1776 // here. For the meantime, we just print `[[clang::annotate_type(...)]]`
1777 // without the arguments so that we know at least that we had _some_
1778 // annotation on the type.
1779 OS << " [[clang::annotate_type(...)]]";
1780 return;
1781 }
1782
1783 if (T->getAttrKind() == attr::ArmStreaming) {
1784 OS << "__arm_streaming";
1785 return;
1786 }
1787 if (T->getAttrKind() == attr::ArmStreamingCompatible) {
1788 OS << "__arm_streaming_compatible";
1789 return;
1790 }
1791 if (T->getAttrKind() == attr::ArmSharedZA) {
1792 OS << "__arm_shared_za";
1793 return;
1794 }
1795 if (T->getAttrKind() == attr::ArmPreservesZA) {
1796 OS << "__arm_preserves_za";
1797 return;
1798 }
1799
1800 OS << " __attribute__((";
1801 switch (T->getAttrKind()) {
1802#define TYPE_ATTR(NAME)
1803#define DECL_OR_TYPE_ATTR(NAME)
1804#define ATTR(NAME) case attr::NAME:
1805#include "clang/Basic/AttrList.inc"
1806 llvm_unreachable("non-type attribute attached to type");
1807
1808 case attr::BTFTypeTag:
1809 llvm_unreachable("BTFTypeTag attribute handled separately");
1810
1811 case attr::OpenCLPrivateAddressSpace:
1812 case attr::OpenCLGlobalAddressSpace:
1813 case attr::OpenCLGlobalDeviceAddressSpace:
1814 case attr::OpenCLGlobalHostAddressSpace:
1815 case attr::OpenCLLocalAddressSpace:
1816 case attr::OpenCLConstantAddressSpace:
1817 case attr::OpenCLGenericAddressSpace:
1818 case attr::HLSLGroupSharedAddressSpace:
1819 // FIXME: Update printAttributedBefore to print these once we generate
1820 // AttributedType nodes for them.
1821 break;
1822
1823 case attr::LifetimeBound:
1824 case attr::TypeNonNull:
1825 case attr::TypeNullable:
1826 case attr::TypeNullableResult:
1827 case attr::TypeNullUnspecified:
1828 case attr::ObjCGC:
1829 case attr::ObjCInertUnsafeUnretained:
1830 case attr::ObjCKindOf:
1831 case attr::ObjCOwnership:
1832 case attr::Ptr32:
1833 case attr::Ptr64:
1834 case attr::SPtr:
1835 case attr::UPtr:
1836 case attr::AddressSpace:
1837 case attr::CmseNSCall:
1838 case attr::AnnotateType:
1839 case attr::WebAssemblyFuncref:
1840 case attr::ArmStreaming:
1841 case attr::ArmStreamingCompatible:
1842 case attr::ArmSharedZA:
1843 case attr::ArmPreservesZA:
1844 llvm_unreachable("This attribute should have been handled already");
1845
1846 case attr::NSReturnsRetained:
1847 OS << "ns_returns_retained";
1848 break;
1849
1850 // FIXME: When Sema learns to form this AttributedType, avoid printing the
1851 // attribute again in printFunctionProtoAfter.
1852 case attr::AnyX86NoCfCheck: OS << "nocf_check"; break;
1853 case attr::CDecl: OS << "cdecl"; break;
1854 case attr::FastCall: OS << "fastcall"; break;
1855 case attr::StdCall: OS << "stdcall"; break;
1856 case attr::ThisCall: OS << "thiscall"; break;
1857 case attr::SwiftCall: OS << "swiftcall"; break;
1858 case attr::SwiftAsyncCall: OS << "swiftasynccall"; break;
1859 case attr::VectorCall: OS << "vectorcall"; break;
1860 case attr::Pascal: OS << "pascal"; break;
1861 case attr::MSABI: OS << "ms_abi"; break;
1862 case attr::SysVABI: OS << "sysv_abi"; break;
1863 case attr::RegCall: OS << "regcall"; break;
1864 case attr::Pcs: {
1865 OS << "pcs(";
1866 QualType t = T->getEquivalentType();
1867 while (!t->isFunctionType())
1868 t = t->getPointeeType();
1869 OS << (t->castAs<FunctionType>()->getCallConv() == CC_AAPCS ?
1870 "\"aapcs\"" : "\"aapcs-vfp\"");
1871 OS << ')';
1872 break;
1873 }
1874 case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break;
1875 case attr::AArch64SVEPcs: OS << "aarch64_sve_pcs"; break;
1876 case attr::AMDGPUKernelCall: OS << "amdgpu_kernel"; break;
1877 case attr::IntelOclBicc: OS << "inteloclbicc"; break;
1878 case attr::PreserveMost:
1879 OS << "preserve_most";
1880 break;
1881
1882 case attr::PreserveAll:
1883 OS << "preserve_all";
1884 break;
1885 case attr::M68kRTD:
1886 OS << "m68k_rtd";
1887 break;
1888 case attr::NoDeref:
1889 OS << "noderef";
1890 break;
1891 case attr::AcquireHandle:
1892 OS << "acquire_handle";
1893 break;
1894 case attr::ArmMveStrictPolymorphism:
1895 OS << "__clang_arm_mve_strict_polymorphism";
1896 break;
1897
1898 // Nothing to print for this attribute.
1899 case attr::HLSLParamModifier:
1900 break;
1901 }
1902 OS << "))";
1903}
1904
1905void TypePrinter::printBTFTagAttributedBefore(const BTFTagAttributedType *T,
1906 raw_ostream &OS) {
1907 printBefore(T->getWrappedType(), OS);
1908 OS << " __attribute__((btf_type_tag(\"" << T->getAttr()->getBTFTypeTag() << "\")))";
1909}
1910
1911void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T,
1912 raw_ostream &OS) {
1913 printAfter(T->getWrappedType(), OS);
1914}
1915
1916void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
1917 raw_ostream &OS) {
1918 OS << T->getDecl()->getName();
1919 spaceBeforePlaceHolder(OS);
1920}
1921
1922void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T,
1923 raw_ostream &OS) {}
1924
1925void TypePrinter::printObjCTypeParamBefore(const ObjCTypeParamType *T,
1926 raw_ostream &OS) {
1927 OS << T->getDecl()->getName();
1928 if (!T->qual_empty()) {
1929 bool isFirst = true;
1930 OS << '<';
1931 for (const auto *I : T->quals()) {
1932 if (isFirst)
1933 isFirst = false;
1934 else
1935 OS << ',';
1936 OS << I->getName();
1937 }
1938 OS << '>';
1939 }
1940
1941 spaceBeforePlaceHolder(OS);
1942}
1943
1944void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T,
1945 raw_ostream &OS) {}
1946
1947void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T,
1948 raw_ostream &OS) {
1949 if (T->qual_empty() && T->isUnspecializedAsWritten() &&
1951 return printBefore(T->getBaseType(), OS);
1952
1953 if (T->isKindOfTypeAsWritten())
1954 OS << "__kindof ";
1955
1956 print(T->getBaseType(), OS, StringRef());
1957
1958 if (T->isSpecializedAsWritten()) {
1959 bool isFirst = true;
1960 OS << '<';
1961 for (auto typeArg : T->getTypeArgsAsWritten()) {
1962 if (isFirst)
1963 isFirst = false;
1964 else
1965 OS << ",";
1966
1967 print(typeArg, OS, StringRef());
1968 }
1969 OS << '>';
1970 }
1971
1972 if (!T->qual_empty()) {
1973 bool isFirst = true;
1974 OS << '<';
1975 for (const auto *I : T->quals()) {
1976 if (isFirst)
1977 isFirst = false;
1978 else
1979 OS << ',';
1980 OS << I->getName();
1981 }
1982 OS << '>';
1983 }
1984
1985 spaceBeforePlaceHolder(OS);
1986}
1987
1988void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1989 raw_ostream &OS) {
1990 if (T->qual_empty() && T->isUnspecializedAsWritten() &&
1992 return printAfter(T->getBaseType(), OS);
1993}
1994
1995void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1996 raw_ostream &OS) {
1997 printBefore(T->getPointeeType(), OS);
1998
1999 // If we need to print the pointer, print it now.
2000 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() &&
2002 if (HasEmptyPlaceHolder)
2003 OS << ' ';
2004 OS << '*';
2005 }
2006}
2007
2008void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
2009 raw_ostream &OS) {}
2010
2011static
2012const TemplateArgument &getArgument(const TemplateArgument &A) { return A; }
2013
2015 return A.getArgument();
2016}
2017
2018static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
2019 llvm::raw_ostream &OS, bool IncludeType) {
2020 A.print(PP, OS, IncludeType);
2021}
2022
2024 const PrintingPolicy &PP, llvm::raw_ostream &OS,
2025 bool IncludeType) {
2026 const TemplateArgument::ArgKind &Kind = A.getArgument().getKind();
2028 return A.getTypeSourceInfo()->getType().print(OS, PP);
2029 return A.getArgument().print(PP, OS, IncludeType);
2030}
2031
2033 TemplateArgument Pattern,
2035 unsigned Depth);
2036
2037static bool isSubstitutedType(ASTContext &Ctx, QualType T, QualType Pattern,
2038 ArrayRef<TemplateArgument> Args, unsigned Depth) {
2039 if (Ctx.hasSameType(T, Pattern))
2040 return true;
2041
2042 // A type parameter matches its argument.
2043 if (auto *TTPT = Pattern->getAs<TemplateTypeParmType>()) {
2044 if (TTPT->getDepth() == Depth && TTPT->getIndex() < Args.size() &&
2045 Args[TTPT->getIndex()].getKind() == TemplateArgument::Type) {
2046 QualType SubstArg = Ctx.getQualifiedType(
2047 Args[TTPT->getIndex()].getAsType(), Pattern.getQualifiers());
2048 return Ctx.hasSameType(SubstArg, T);
2049 }
2050 return false;
2051 }
2052
2053 // FIXME: Recurse into array types.
2054
2055 // All other cases will need the types to be identically qualified.
2056 Qualifiers TQual, PatQual;
2057 T = Ctx.getUnqualifiedArrayType(T, TQual);
2058 Pattern = Ctx.getUnqualifiedArrayType(Pattern, PatQual);
2059 if (TQual != PatQual)
2060 return false;
2061
2062 // Recurse into pointer-like types.
2063 {
2064 QualType TPointee = T->getPointeeType();
2065 QualType PPointee = Pattern->getPointeeType();
2066 if (!TPointee.isNull() && !PPointee.isNull())
2067 return T->getTypeClass() == Pattern->getTypeClass() &&
2068 isSubstitutedType(Ctx, TPointee, PPointee, Args, Depth);
2069 }
2070
2071 // Recurse into template specialization types.
2072 if (auto *PTST =
2074 TemplateName Template;
2075 ArrayRef<TemplateArgument> TemplateArgs;
2076 if (auto *TTST = T->getAs<TemplateSpecializationType>()) {
2077 Template = TTST->getTemplateName();
2078 TemplateArgs = TTST->template_arguments();
2079 } else if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
2080 T->getAsCXXRecordDecl())) {
2081 Template = TemplateName(CTSD->getSpecializedTemplate());
2082 TemplateArgs = CTSD->getTemplateArgs().asArray();
2083 } else {
2084 return false;
2085 }
2086
2087 if (!isSubstitutedTemplateArgument(Ctx, Template, PTST->getTemplateName(),
2088 Args, Depth))
2089 return false;
2090 if (TemplateArgs.size() != PTST->template_arguments().size())
2091 return false;
2092 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
2094 Ctx, TemplateArgs[I], PTST->template_arguments()[I], Args, Depth))
2095 return false;
2096 return true;
2097 }
2098
2099 // FIXME: Handle more cases.
2100 return false;
2101}
2102
2103/// Evaluates the expression template argument 'Pattern' and returns true
2104/// if 'Arg' evaluates to the same result.
2106 TemplateArgument const &Pattern,
2107 TemplateArgument const &Arg) {
2108 if (Pattern.getKind() != TemplateArgument::Expression)
2109 return false;
2110
2111 // Can't evaluate value-dependent expressions so bail early
2112 Expr const *pattern_expr = Pattern.getAsExpr();
2113 if (pattern_expr->isValueDependent() ||
2114 !pattern_expr->isIntegerConstantExpr(Ctx))
2115 return false;
2116
2118 return llvm::APSInt::isSameValue(pattern_expr->EvaluateKnownConstInt(Ctx),
2119 Arg.getAsIntegral());
2120
2122 Expr const *args_expr = Arg.getAsExpr();
2123 if (args_expr->isValueDependent() || !args_expr->isIntegerConstantExpr(Ctx))
2124 return false;
2125
2126 return llvm::APSInt::isSameValue(args_expr->EvaluateKnownConstInt(Ctx),
2127 pattern_expr->EvaluateKnownConstInt(Ctx));
2128 }
2129
2130 return false;
2131}
2132
2134 TemplateArgument Pattern,
2136 unsigned Depth) {
2137 Arg = Ctx.getCanonicalTemplateArgument(Arg);
2138 Pattern = Ctx.getCanonicalTemplateArgument(Pattern);
2139 if (Arg.structurallyEquals(Pattern))
2140 return true;
2141
2142 if (Pattern.getKind() == TemplateArgument::Expression) {
2143 if (auto *DRE =
2144 dyn_cast<DeclRefExpr>(Pattern.getAsExpr()->IgnoreParenImpCasts())) {
2145 if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
2146 return NTTP->getDepth() == Depth && Args.size() > NTTP->getIndex() &&
2147 Args[NTTP->getIndex()].structurallyEquals(Arg);
2148 }
2149 }
2150
2151 if (templateArgumentExpressionsEqual(Ctx, Pattern, Arg))
2152 return true;
2153
2154 if (Arg.getKind() != Pattern.getKind())
2155 return false;
2156
2157 if (Arg.getKind() == TemplateArgument::Type)
2158 return isSubstitutedType(Ctx, Arg.getAsType(), Pattern.getAsType(), Args,
2159 Depth);
2160
2161 if (Arg.getKind() == TemplateArgument::Template) {
2162 TemplateDecl *PatTD = Pattern.getAsTemplate().getAsTemplateDecl();
2163 if (auto *TTPD = dyn_cast_or_null<TemplateTemplateParmDecl>(PatTD))
2164 return TTPD->getDepth() == Depth && Args.size() > TTPD->getIndex() &&
2165 Ctx.getCanonicalTemplateArgument(Args[TTPD->getIndex()])
2166 .structurallyEquals(Arg);
2167 }
2168
2169 // FIXME: Handle more cases.
2170 return false;
2171}
2172
2174 const NamedDecl *Param,
2176 unsigned Depth) {
2177 // An empty pack is equivalent to not providing a pack argument.
2178 if (Arg.getKind() == TemplateArgument::Pack && Arg.pack_size() == 0)
2179 return true;
2180
2181 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Param)) {
2182 return TTPD->hasDefaultArgument() &&
2183 isSubstitutedTemplateArgument(Ctx, Arg, TTPD->getDefaultArgument(),
2184 Args, Depth);
2185 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2186 return TTPD->hasDefaultArgument() &&
2188 Ctx, Arg, TTPD->getDefaultArgument().getArgument(), Args, Depth);
2189 } else if (auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2190 return NTTPD->hasDefaultArgument() &&
2191 isSubstitutedTemplateArgument(Ctx, Arg, NTTPD->getDefaultArgument(),
2192 Args, Depth);
2193 }
2194 return false;
2195}
2196
2197template <typename TA>
2198static void
2199printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
2200 const TemplateParameterList *TPL, bool IsPack, unsigned ParmIndex) {
2201 // Drop trailing template arguments that match default arguments.
2202 if (TPL && Policy.SuppressDefaultTemplateArgs &&
2203 !Policy.PrintCanonicalTypes && !Args.empty() && !IsPack &&
2204 Args.size() <= TPL->size()) {
2206 for (const TA &A : Args)
2207 OrigArgs.push_back(getArgument(A));
2208 while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
2209 Args = Args.drop_back();
2210 }
2211
2212 const char *Comma = Policy.MSVCFormatting ? "," : ", ";
2213 if (!IsPack)
2214 OS << '<';
2215
2216 bool NeedSpace = false;
2217 bool FirstArg = true;
2218 for (const auto &Arg : Args) {
2219 // Print the argument into a string.
2220 SmallString<128> Buf;
2221 llvm::raw_svector_ostream ArgOS(Buf);
2222 const TemplateArgument &Argument = getArgument(Arg);
2223 if (Argument.getKind() == TemplateArgument::Pack) {
2224 if (Argument.pack_size() && !FirstArg)
2225 OS << Comma;
2226 printTo(ArgOS, Argument.getPackAsArray(), Policy, TPL,
2227 /*IsPack*/ true, ParmIndex);
2228 } else {
2229 if (!FirstArg)
2230 OS << Comma;
2231 // Tries to print the argument with location info if exists.
2232 printArgument(Arg, Policy, ArgOS,
2234 Policy, TPL, ParmIndex));
2235 }
2236 StringRef ArgString = ArgOS.str();
2237
2238 // If this is the first argument and its string representation
2239 // begins with the global scope specifier ('::foo'), add a space
2240 // to avoid printing the diagraph '<:'.
2241 if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
2242 OS << ' ';
2243
2244 OS << ArgString;
2245
2246 // If the last character of our string is '>', add another space to
2247 // keep the two '>''s separate tokens.
2248 if (!ArgString.empty()) {
2249 NeedSpace = Policy.SplitTemplateClosers && ArgString.back() == '>';
2250 FirstArg = false;
2251 }
2252
2253 // Use same template parameter for all elements of Pack
2254 if (!IsPack)
2255 ParmIndex++;
2256 }
2257
2258 if (!IsPack) {
2259 if (NeedSpace)
2260 OS << ' ';
2261 OS << '>';
2262 }
2263}
2264
2266 const TemplateArgumentListInfo &Args,
2267 const PrintingPolicy &Policy,
2268 const TemplateParameterList *TPL) {
2269 printTemplateArgumentList(OS, Args.arguments(), Policy, TPL);
2270}
2271
2274 const PrintingPolicy &Policy,
2275 const TemplateParameterList *TPL) {
2276 printTo(OS, Args, Policy, TPL, /*isPack*/ false, /*parmIndex*/ 0);
2277}
2278
2281 const PrintingPolicy &Policy,
2282 const TemplateParameterList *TPL) {
2283 printTo(OS, Args, Policy, TPL, /*isPack*/ false, /*parmIndex*/ 0);
2284}
2285
2286std::string Qualifiers::getAsString() const {
2287 LangOptions LO;
2288 return getAsString(PrintingPolicy(LO));
2289}
2290
2291// Appends qualifiers to the given string, separated by spaces. Will
2292// prefix a space if the string is non-empty. Will not append a final
2293// space.
2294std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
2295 SmallString<64> Buf;
2296 llvm::raw_svector_ostream StrOS(Buf);
2297 print(StrOS, Policy);
2298 return std::string(StrOS.str());
2299}
2300
2302 if (getCVRQualifiers())
2303 return false;
2304
2306 return false;
2307
2308 if (getObjCGCAttr())
2309 return false;
2310
2312 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
2313 return false;
2314
2315 return true;
2316}
2317
2319 switch (AS) {
2320 case LangAS::Default:
2321 return "";
2324 return "__global";
2326 case LangAS::sycl_local:
2327 return "__local";
2330 return "__private";
2332 return "__constant";
2334 return "__generic";
2337 return "__global_device";
2340 return "__global_host";
2342 return "__device__";
2344 return "__constant__";
2346 return "__shared__";
2347 case LangAS::ptr32_sptr:
2348 return "__sptr __ptr32";
2349 case LangAS::ptr32_uptr:
2350 return "__uptr __ptr32";
2351 case LangAS::ptr64:
2352 return "__ptr64";
2354 return "__funcref";
2356 return "groupshared";
2357 default:
2358 return std::to_string(toTargetAddressSpace(AS));
2359 }
2360}
2361
2362// Appends qualifiers to the given string, separated by spaces. Will
2363// prefix a space if the string is non-empty. Will not append a final
2364// space.
2365void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
2366 bool appendSpaceIfNonEmpty) const {
2367 bool addSpace = false;
2368
2369 unsigned quals = getCVRQualifiers();
2370 if (quals) {
2371 AppendTypeQualList(OS, quals, Policy.Restrict);
2372 addSpace = true;
2373 }
2374 if (hasUnaligned()) {
2375 if (addSpace)
2376 OS << ' ';
2377 OS << "__unaligned";
2378 addSpace = true;
2379 }
2380 auto ASStr = getAddrSpaceAsString(getAddressSpace());
2381 if (!ASStr.empty()) {
2382 if (addSpace)
2383 OS << ' ';
2384 addSpace = true;
2385 // Wrap target address space into an attribute syntax
2387 OS << "__attribute__((address_space(" << ASStr << ")))";
2388 else
2389 OS << ASStr;
2390 }
2391
2392 if (Qualifiers::GC gc = getObjCGCAttr()) {
2393 if (addSpace)
2394 OS << ' ';
2395 addSpace = true;
2396 if (gc == Qualifiers::Weak)
2397 OS << "__weak";
2398 else
2399 OS << "__strong";
2400 }
2401 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
2402 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){
2403 if (addSpace)
2404 OS << ' ';
2405 addSpace = true;
2406 }
2407
2408 switch (lifetime) {
2409 case Qualifiers::OCL_None: llvm_unreachable("none but true");
2410 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
2412 if (!Policy.SuppressStrongLifetime)
2413 OS << "__strong";
2414 break;
2415
2416 case Qualifiers::OCL_Weak: OS << "__weak"; break;
2417 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
2418 }
2419 }
2420
2421 if (appendSpaceIfNonEmpty && addSpace)
2422 OS << ' ';
2423}
2424
2425std::string QualType::getAsString() const {
2426 return getAsString(split(), LangOptions());
2427}
2428
2429std::string QualType::getAsString(const PrintingPolicy &Policy) const {
2430 std::string S;
2431 getAsStringInternal(S, Policy);
2432 return S;
2433}
2434
2435std::string QualType::getAsString(const Type *ty, Qualifiers qs,
2436 const PrintingPolicy &Policy) {
2437 std::string buffer;
2438 getAsStringInternal(ty, qs, buffer, Policy);
2439 return buffer;
2440}
2441
2442void QualType::print(raw_ostream &OS, const PrintingPolicy &Policy,
2443 const Twine &PlaceHolder, unsigned Indentation) const {
2444 print(splitAccordingToPolicy(*this, Policy), OS, Policy, PlaceHolder,
2445 Indentation);
2446}
2447
2449 raw_ostream &OS, const PrintingPolicy &policy,
2450 const Twine &PlaceHolder, unsigned Indentation) {
2451 SmallString<128> PHBuf;
2452 StringRef PH = PlaceHolder.toStringRef(PHBuf);
2453
2454 TypePrinter(policy, Indentation).print(ty, qs, OS, PH);
2455}
2456
2457void QualType::getAsStringInternal(std::string &Str,
2458 const PrintingPolicy &Policy) const {
2459 return getAsStringInternal(splitAccordingToPolicy(*this, Policy), Str,
2460 Policy);
2461}
2462
2464 std::string &buffer,
2465 const PrintingPolicy &policy) {
2466 SmallString<256> Buf;
2467 llvm::raw_svector_ostream StrOS(Buf);
2468 TypePrinter(policy).print(ty, qs, StrOS, buffer);
2469 std::string str = std::string(StrOS.str());
2470 buffer.swap(str);
2471}
2472
2473raw_ostream &clang::operator<<(raw_ostream &OS, QualType QT) {
2474 SplitQualType S = QT.split();
2475 TypePrinter(LangOptions()).print(S.Ty, S.Quals, OS, /*PlaceHolder=*/"");
2476 return OS;
2477}
Defines the clang::ASTContext interface.
int Id
Definition: ASTDiff.cpp:190
Provides definitions for the various language-specific address spaces.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
static void printTo(raw_ostream &OS, ArrayRef< TA > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL, bool IsPack, unsigned ParmIndex)
static const TemplateArgument & getArgument(const TemplateArgument &A)
static bool isSubstitutedType(ASTContext &Ctx, QualType T, QualType Pattern, ArrayRef< TemplateArgument > Args, unsigned Depth)
static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP, llvm::raw_ostream &OS, bool IncludeType)
static QualType skipTopLevelReferences(QualType T)
static SplitQualType splitAccordingToPolicy(QualType QT, const PrintingPolicy &Policy)
static bool isSubstitutedTemplateArgument(ASTContext &Ctx, TemplateArgument Arg, TemplateArgument Pattern, ArrayRef< TemplateArgument > Args, unsigned Depth)
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool HasRestrictKeyword)
static bool templateArgumentExpressionsEqual(ASTContext const &Ctx, TemplateArgument const &Pattern, TemplateArgument const &Arg)
Evaluates the expression template argument 'Pattern' and returns true if 'Arg' evaluates to the same ...
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
SourceManager & getSourceManager()
Definition: ASTContext.h:697
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2551
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2133
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2925
QualType getAdjustedType() const
Definition: Type.h:2939
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3159
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:3163
QualType getElementType() const
Definition: Type.h:3157
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3167
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:6611
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5026
QualType getModifiedType() const
Definition: Type.h:5048
bool isCallingConv() const
Definition: Type.cpp:3869
std::optional< NullabilityKind > getImmediateNullability() const
Definition: Type.cpp:4554
bool isMSTypeSpec() const
Definition: Type.cpp:3852
QualType getEquivalentType() const
Definition: Type.h:5049
Kind getAttrKind() const
Definition: Type.h:5044
bool isWebAssemblyFuncrefSpec() const
Definition: Type.cpp:3865
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5403
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5413
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5418
AutoTypeKeyword getKeyword() const
Definition: Type.h:5434
bool isConstrained() const
Definition: Type.h:5422
const BTFTypeTagAttr * getAttr() const
Definition: Type.h:5139
QualType getWrappedType() const
Definition: Type.h:5138
A fixed int type of a specified bitwidth.
Definition: Type.h:6664
bool isUnsigned() const
Definition: Type.h:6674
unsigned getNumBits() const
Definition: Type.h:6676
Pointer to a block type.
Definition: Type.h:2976
QualType getPointeeType() const
Definition: Type.h:2988
This class is used for builtin types like 'int'.
Definition: Type.h:2738
StringRef getName(const PrintingPolicy &Policy) const
Definition: Type.cpp:3189
Complex values, per C99 6.2.5p11.
Definition: Type.h:2843
QualType getElementType() const
Definition: Type.h:2853
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3184
const llvm::APInt & getSize() const
Definition: Type.h:3205
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:3705
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:3726
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:3723
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2959
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2065
bool isTranslationUnit() const
Definition: DeclBase.h:2140
bool isFunctionOrMethod() const
Definition: DeclBase.h:2117
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:597
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:563
SourceLocation getLocation() const
Definition: DeclBase.h:444
DeclContext * getDeclContext()
Definition: DeclBase.h:453
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
The name of a declaration.
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Represents the type decltype(expr) (C++11).
Definition: Type.h:4847
Expr * getUnderlyingExpr() const
Definition: Type.h:4857
Represents a C++17 deduced template specialization type.
Definition: Type.h:5451
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:5471
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5390
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3400
Expr * getAddrSpaceExpr() const
Definition: Type.h:3411
QualType getPointeeType() const
Definition: Type.h:3412
Expr * getNumBitsExpr() const
Definition: Type.cpp:377
bool isUnsigned() const
Definition: Type.cpp:373
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5874
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5892
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:5899
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3342
Expr * getSizeExpr() const
Definition: Type.h:3362
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3440
QualType getElementType() const
Definition: Type.h:3455
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:3764
Expr * getColumnExpr() const
Definition: Type.h:3777
Expr * getRowExpr() const
Definition: Type.h:3776
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:5926
const IdentifierInfo * getIdentifier() const
Definition: Type.h:5943
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5945
NestedNameSpecifier * getQualifier() const
Definition: Type.h:5942
Represents a vector type where either the type or size is dependent.
Definition: Type.h:3559
Expr * getSizeExpr() const
Definition: Type.h:3570
VectorKind getVectorKind() const
Definition: Type.h:3573
QualType getElementType() const
Definition: Type.h:3571
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5793
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
Definition: Type.h:5841
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5828
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5831
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4997
EnumDecl * getDecl() const
Definition: Type.h:5004
This represents one expression.
Definition: Expr.h:110
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:169
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition: Expr.cpp:3031
bool isIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
ExtVectorType - Extended vector type.
Definition: Type.h:3599
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4116
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4160
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:4589
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4403
unsigned getNumParams() const
Definition: Type.h:4377
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4516
Qualifiers getMethodQuals() const
Definition: Type.h:4518
QualType getParamType(unsigned i) const
Definition: Type.h:4379
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
Definition: Type.h:4582
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4454
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4446
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:4412
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4500
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:4461
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:4526
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3905
CallingConv getCC() const
Definition: Type.h:3967
bool getCmseNSCall() const
Definition: Type.h:3955
bool getNoCfCheck() const
Definition: Type.h:3957
unsigned getRegParm() const
Definition: Type.h:3960
bool getNoCallerSavedRegs() const
Definition: Type.h:3956
bool getNoReturn() const
Definition: Type.h:3953
bool getProducesResult() const
Definition: Type.h:3954
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3794
ExtInfo getExtInfo() const
Definition: Type.h:4090
QualType getReturnType() const
Definition: Type.h:4078
@ SME_PStateSMEnabledMask
Definition: Type.h:4039
@ SME_PStateSMCompatibleMask
Definition: Type.h:4040
@ SME_PStateZAPreservedMask
Definition: Type.h:4042
@ SME_PStateZASharedMask
Definition: Type.h:4041
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Represents a C array with an unspecified size.
Definition: Type.h:3244
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:5643
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:5676
TemplateName getTemplateName() const
Definition: Type.h:5680
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3051
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:83
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:4731
QualType getModifiedType() const
Return this attributed type's modified type with no qualifiers attached to it.
Definition: Type.cpp:3698
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:4746
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:3683
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3087
QualType getPointeeType() const
Definition: Type.h:3103
const Type * getClass() const
Definition: Type.h:3117
This represents a decl that may have a name.
Definition: Decl.h:248
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:460
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:314
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6374
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.cpp:849
Represents a pointer to an Objective C object.
Definition: Type.h:6430
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:6511
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:6505
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:6488
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6442
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:6494
Represents a class type in Objective C.
Definition: Type.h:6176
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:6291
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6286
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:6279
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:6238
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:6269
qual_range quals() const
Definition: Type.h:6074
bool qual_empty() const
Definition: Type.h:6078
Represents a type parameter type in Objective C.
Definition: Type.h:6102
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6144
Represents a pack expansion of types.
Definition: Type.h:5991
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6012
Sugar for parentheses used when specifying types.
Definition: Type.h:2870
QualType getInnerType() const
Definition: Type.h:2879
PipeType - OpenCL20.
Definition: Type.h:6630
QualType getElementType() const
Definition: Type.h:6641
bool isReadOnly() const
Definition: Type.h:6660
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2896
QualType getPointeeType() const
Definition: Type.h:2906
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
bool isValid() const
unsigned getLine() const
Return the presumed line number of this location.
A (possibly-)qualified type.
Definition: Type.h:736
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:803
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6781
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6821
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
QualType getCanonicalType() const
Definition: Type.h:6833
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6802
std::string getAsString() const
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1176
The collection of all-type qualifiers we support.
Definition: Type.h:146
unsigned getCVRQualifiers() const
Definition: Type.h:294
GC getObjCGCAttr() const
Definition: Type.h:325
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:174
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:167
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:163
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:177
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:180
bool hasQualifiers() const
Return true if the set contains any qualifiers.
Definition: Type.h:438
bool hasUnaligned() const
Definition: Type.h:317
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
ObjCLifetime getObjCLifetime() const
Definition: Type.h:351
bool empty() const
Definition: Type.h:439
std::string getAsString() const
LangAS getAddressSpace() const
Definition: Type.h:377
static std::string getAddrSpaceAsString(LangAS AS)
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3069
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4971
RecordDecl * getDecl() const
Definition: Type.h:4981
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3007
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3023
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5311
const TemplateTypeParmDecl * getReplacedParameter() const
Gets the template parameter declaration that was substituted for.
Definition: Type.cpp:3956
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5241
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5253
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3533
StringRef getKindName() const
Definition: Decl.h:3724
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3761
A convenient class for passing around template argument information.
Definition: TemplateBase.h:601
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:629
A template argument list.
Definition: DeclTemplate.h:243
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:295
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:495
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:544
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:552
Represents a template argument.
Definition: TemplateBase.h:60
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:415
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:379
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:298
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:342
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:322
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:409
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:372
ArgKind
The kind of template argument we're storing.
Definition: TemplateBase.h:63
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:85
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:99
@ Type
The template argument is a type.
Definition: TemplateBase.h:69
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:81
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:95
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:274
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:413
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5511
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5579
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:5577
Declaration of a template type parameter.
unsigned getIndex() const
Retrieve the index of the template parameter.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
unsigned getDepth() const
Retrieve the depth of the template parameter.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5204
unsigned getIndex() const
Definition: Type.h:5201
IdentifierInfo * getIdentifier() const
Definition: Type.cpp:3901
unsigned getDepth() const
Definition: Type.h:5200
const Type * getTypeForDecl() const
Definition: Decl.h:3365
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:4763
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:4775
Expr * getUnderlyingExpr() const
Definition: Type.h:4772
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:4811
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:4838
QualType getUnmodifiedType() const
Definition: Type.h:4826
A container of type source information.
Definition: Type.h:6752
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6763
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3109
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5751
The base class of the type hierarchy.
Definition: Type.h:1602
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
Definition: Type.cpp:444
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7625
bool isObjCQualifiedIdType() const
Definition: Type.h:7182
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:651
bool isObjCIdType() const
Definition: Type.h:7194
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:2994
bool isFunctionType() const
Definition: Type.h:7029
bool isObjCQualifiedClassType() const
Definition: Type.h:7188
bool isObjCClassType() const
Definition: Type.h:7200
TypeClass getTypeClass() const
Definition: Type.h:2070
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7558
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3383
TypedefNameDecl * getDecl() const
Definition: Type.h:4706
A unary type transform, which is a type constructed from another.
Definition: Type.h:4888
QualType getBaseType() const
Definition: Type.h:4915
UTTKind getUTTKind() const
Definition: Type.h:4917
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:4632
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:4643
UsingShadowDecl * getFoundDecl() const
Definition: Type.h:4672
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3288
Expr * getSizeExpr() const
Definition: Type.h:3307
Represents a GCC generic vector type.
Definition: Type.h:3507
unsigned getNumElements() const
Definition: Type.h:3522
VectorKind getVectorKind() const
Definition: Type.h:3527
QualType getElementType() const
Definition: Type.h:3521
@ GNUAutoType
__auto_type (GNU extension)
@ DecltypeAuto
decltype(auto)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
bool isTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:77
@ RQ_None
No ref-qualifier was provided.
Definition: Type.h:1551
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1554
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1557
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
unsigned toTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:81
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:359
@ SwiftAsyncContext
This parameter (which must have pointer type) uses the special Swift asynchronous context-pointer ABI...
@ SwiftErrorResult
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
@ Ordinary
This parameter uses ordinary ABI rules for its type.
@ SwiftIndirectResult
This parameter (which must have pointer type) is a Swift indirect result parameter.
@ SwiftContext
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg, const NamedDecl *Param, ArrayRef< TemplateArgument > Args, unsigned Depth)
Make a best-effort determination of whether the type T can be produced by substituting Args into the ...
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1274
@ CC_X86Pascal
Definition: Specifiers.h:279
@ CC_Swift
Definition: Specifiers.h:288
@ CC_IntelOclBicc
Definition: Specifiers.h:285
@ CC_OpenCLKernel
Definition: Specifiers.h:287
@ CC_PreserveMost
Definition: Specifiers.h:290
@ CC_Win64
Definition: Specifiers.h:280
@ CC_X86ThisCall
Definition: Specifiers.h:277
@ CC_AArch64VectorCall
Definition: Specifiers.h:292
@ CC_AAPCS
Definition: Specifiers.h:283
@ CC_C
Definition: Specifiers.h:274
@ CC_AMDGPUKernelCall
Definition: Specifiers.h:294
@ CC_M68kRTD
Definition: Specifiers.h:295
@ CC_SwiftAsync
Definition: Specifiers.h:289
@ CC_X86RegCall
Definition: Specifiers.h:282
@ CC_X86VectorCall
Definition: Specifiers.h:278
@ CC_SpirFunction
Definition: Specifiers.h:286
@ CC_AArch64SVEPCS
Definition: Specifiers.h:293
@ CC_X86StdCall
Definition: Specifiers.h:275
@ CC_X86_64SysV
Definition: Specifiers.h:281
@ CC_PreserveAll
Definition: Specifiers.h:291
@ CC_X86FastCall
Definition: Specifiers.h:276
@ CC_AAPCS_VFP
Definition: Specifiers.h:284
@ None
No keyword precedes the qualified type name.
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_MSAny
Microsoft throw(...) extension.
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
unsigned SuppressDefaultTemplateArgs
When true, attempt to suppress template arguments that match the default argument for the parameter.
unsigned SplitTemplateClosers
Whether nested templates must be closed like 'a<b<c> >' rather than 'a<b<c>>'.
unsigned PrintCanonicalTypes
Whether to print types as written or canonically.
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration.
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
unsigned Restrict
Whether we can use 'restrict' rather than '__restrict'.
unsigned SuppressScope
Suppresses printing of scope specifiers.
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:669
const Type * Ty
The locally-unqualified type.
Definition: Type.h:671
Qualifiers Quals
The local qualifiers.
Definition: Type.h:674