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/Compiler.h"
41#include "llvm/Support/ErrorHandling.h"
42#include "llvm/Support/SaveAndRestore.h"
43#include "llvm/Support/raw_ostream.h"
53class IncludeStrongLifetimeRAII {
59 : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
67class ParamPolicyRAII {
73 : Policy(Policy), Old(Policy.SuppressSpecifiers) {
80class DefaultTemplateArgsPolicyRAII {
86 : Policy(Policy), Old(Policy.SuppressDefaultTemplateArgs) {
93class ElaboratedTypePolicyRAII {
95 bool SuppressTagKeyword;
99 explicit ElaboratedTypePolicyRAII(
PrintingPolicy &Policy) : Policy(Policy) {
106 ~ElaboratedTypePolicyRAII() {
114 unsigned Indentation;
115 bool HasEmptyPlaceHolder =
false;
116 bool InsideCCAttribute =
false;
119 explicit TypePrinter(
const PrintingPolicy &Policy,
unsigned Indentation = 0)
120 : Policy(Policy), Indentation(Indentation) {}
123 StringRef PlaceHolder);
126 static bool canPrefixQualifiers(
const Type *
T,
bool &NeedARCStrongQualifier);
127 void spaceBeforePlaceHolder(raw_ostream &OS);
128 void printTypeSpec(
NamedDecl *
D, raw_ostream &OS);
132 void printBefore(
QualType T, raw_ostream &OS);
133 void printAfter(
QualType T, raw_ostream &OS);
136 void printTag(
TagDecl *
T, raw_ostream &OS);
138#define ABSTRACT_TYPE(CLASS, PARENT)
139#define TYPE(CLASS, PARENT) \
140 void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
141 void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
142#include "clang/AST/TypeNodes.inc"
152 bool HasRestrictKeyword) {
153 bool appendSpace =
false;
159 if (appendSpace) OS <<
' ';
164 if (appendSpace) OS <<
' ';
165 if (HasRestrictKeyword) {
173void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
174 if (!HasEmptyPlaceHolder)
185void TypePrinter::print(
QualType t, raw_ostream &OS, StringRef PlaceHolder) {
190void TypePrinter::print(
const Type *
T,
Qualifiers Quals, raw_ostream &OS,
191 StringRef PlaceHolder) {
199 printBefore(
T, Quals, OS);
201 printAfter(
T, Quals, OS);
204bool TypePrinter::canPrefixQualifiers(
const Type *
T,
205 bool &NeedARCStrongQualifier) {
211 bool CanPrefixQualifiers =
false;
212 NeedARCStrongQualifier =
false;
213 const Type *UnderlyingType =
T;
214 if (
const auto *AT = dyn_cast<AutoType>(
T))
215 UnderlyingType = AT->desugar().getTypePtr();
216 if (
const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(
T))
217 UnderlyingType = Subst->getReplacementType().getTypePtr();
224 case Type::UnresolvedUsing:
227 case Type::TypeOfExpr:
230 case Type::UnaryTransform:
233 case Type::Elaborated:
234 case Type::TemplateTypeParm:
235 case Type::SubstTemplateTypeParmPack:
236 case Type::DeducedTemplateSpecialization:
237 case Type::TemplateSpecialization:
238 case Type::InjectedClassName:
239 case Type::DependentName:
240 case Type::DependentTemplateSpecialization:
241 case Type::ObjCObject:
242 case Type::ObjCTypeParam:
243 case Type::ObjCInterface:
247 case Type::DependentBitInt:
248 case Type::BTFTagAttributed:
249 case Type::HLSLAttributedResource:
250 CanPrefixQualifiers =
true;
253 case Type::ObjCObjectPointer:
258 case Type::VariableArray:
259 case Type::DependentSizedArray:
260 NeedARCStrongQualifier =
true;
263 case Type::ConstantArray:
264 case Type::IncompleteArray:
265 return canPrefixQualifiers(
266 cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(),
267 NeedARCStrongQualifier);
271 case Type::ArrayParameter:
273 case Type::BlockPointer:
274 case Type::LValueReference:
275 case Type::RValueReference:
276 case Type::MemberPointer:
277 case Type::DependentAddressSpace:
278 case Type::DependentVector:
279 case Type::DependentSizedExtVector:
281 case Type::ExtVector:
282 case Type::ConstantMatrix:
283 case Type::DependentSizedMatrix:
284 case Type::FunctionProto:
285 case Type::FunctionNoProto:
287 case Type::PackExpansion:
288 case Type::SubstTemplateTypeParm:
289 case Type::MacroQualified:
290 case Type::CountAttributed:
291 CanPrefixQualifiers =
false;
294 case Type::Attributed: {
297 const auto *AttrTy = cast<AttributedType>(UnderlyingType);
298 CanPrefixQualifiers = AttrTy->getAttrKind() == attr::AddressSpace;
301 case Type::PackIndexing: {
302 return canPrefixQualifiers(
303 cast<PackIndexingType>(UnderlyingType)->getPattern().getTypePtr(),
304 NeedARCStrongQualifier);
308 return CanPrefixQualifiers;
311void TypePrinter::printBefore(
QualType T, raw_ostream &OS) {
317 if (
const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(
Split.Ty))
320 printBefore(
Split.Ty, Quals, OS);
325void TypePrinter::printBefore(
const Type *
T,
Qualifiers Quals, raw_ostream &OS) {
333 bool CanPrefixQualifiers =
false;
334 bool NeedARCStrongQualifier =
false;
335 CanPrefixQualifiers = canPrefixQualifiers(
T, NeedARCStrongQualifier);
337 if (CanPrefixQualifiers && !Quals.
empty()) {
338 if (NeedARCStrongQualifier) {
339 IncludeStrongLifetimeRAII Strong(Policy);
340 Quals.
print(OS, Policy,
true);
342 Quals.
print(OS, Policy,
true);
346 bool hasAfterQuals =
false;
347 if (!CanPrefixQualifiers && !Quals.
empty()) {
350 HasEmptyPlaceHolder =
false;
354#define ABSTRACT_TYPE(CLASS, PARENT)
355#define TYPE(CLASS, PARENT) case Type::CLASS: \
356 print##CLASS##Before(cast<CLASS##Type>(T), OS); \
358#include "clang/AST/TypeNodes.inc"
362 if (NeedARCStrongQualifier) {
363 IncludeStrongLifetimeRAII Strong(Policy);
364 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
366 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
371void TypePrinter::printAfter(
QualType t, raw_ostream &OS) {
373 printAfter(split.
Ty, split.
Quals, OS);
378void TypePrinter::printAfter(
const Type *
T,
Qualifiers Quals, raw_ostream &OS) {
380#define ABSTRACT_TYPE(CLASS, PARENT)
381#define TYPE(CLASS, PARENT) case Type::CLASS: \
382 print##CLASS##After(cast<CLASS##Type>(T), OS); \
384#include "clang/AST/TypeNodes.inc"
388void TypePrinter::printBuiltinBefore(
const BuiltinType *
T, raw_ostream &OS) {
389 OS <<
T->getName(Policy);
390 spaceBeforePlaceHolder(OS);
393void TypePrinter::printBuiltinAfter(
const BuiltinType *
T, raw_ostream &OS) {}
395void TypePrinter::printComplexBefore(
const ComplexType *
T, raw_ostream &OS) {
397 printBefore(
T->getElementType(), OS);
400void TypePrinter::printComplexAfter(
const ComplexType *
T, raw_ostream &OS) {
401 printAfter(
T->getElementType(), OS);
404void TypePrinter::printPointerBefore(
const PointerType *
T, raw_ostream &OS) {
405 IncludeStrongLifetimeRAII Strong(Policy);
415void TypePrinter::printPointerAfter(
const PointerType *
T, raw_ostream &OS) {
416 IncludeStrongLifetimeRAII Strong(Policy);
448 IncludeStrongLifetimeRAII Strong(Policy);
451 printBefore(Inner, OS);
454 if (isa<ArrayType>(Inner))
461 IncludeStrongLifetimeRAII Strong(Policy);
466 if (isa<ArrayType>(Inner))
468 printAfter(Inner, OS);
473 IncludeStrongLifetimeRAII Strong(Policy);
476 printBefore(Inner, OS);
479 if (isa<ArrayType>(Inner))
486 IncludeStrongLifetimeRAII Strong(Policy);
491 if (isa<ArrayType>(Inner))
493 printAfter(Inner, OS);
498 IncludeStrongLifetimeRAII Strong(Policy);
507 InnerPolicy.IncludeTagDefinition =
false;
508 TypePrinter(InnerPolicy).print(
QualType(
T->getClass(), 0), OS, StringRef());
515 IncludeStrongLifetimeRAII Strong(Policy);
526 IncludeStrongLifetimeRAII Strong(Policy);
527 printBefore(
T->getElementType(), OS);
533 if (
T->getIndexTypeQualifiers().hasQualifiers()) {
539 if (
T->getSizeModifier() == ArraySizeModifier::Static)
542 OS <<
T->getZExtSize() <<
']';
543 printAfter(
T->getElementType(), OS);
548 IncludeStrongLifetimeRAII Strong(Policy);
549 printBefore(
T->getElementType(), OS);
555 printAfter(
T->getElementType(), OS);
560 IncludeStrongLifetimeRAII Strong(Policy);
561 printBefore(
T->getElementType(), OS);
567 if (
T->getIndexTypeQualifiers().hasQualifiers()) {
572 if (
T->getSizeModifier() == ArraySizeModifier::Static)
574 else if (
T->getSizeModifier() == ArraySizeModifier::Star)
577 if (
T->getSizeExpr())
578 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
581 printAfter(
T->getElementType(), OS);
584void TypePrinter::printAdjustedBefore(
const AdjustedType *
T, raw_ostream &OS) {
587 printBefore(
T->getAdjustedType(), OS);
590void TypePrinter::printAdjustedAfter(
const AdjustedType *
T, raw_ostream &OS) {
591 printAfter(
T->getAdjustedType(), OS);
594void TypePrinter::printDecayedBefore(
const DecayedType *
T, raw_ostream &OS) {
596 printAdjustedBefore(
T, OS);
601 printConstantArrayAfter(
T, OS);
606 printConstantArrayBefore(
T, OS);
609void TypePrinter::printDecayedAfter(
const DecayedType *
T, raw_ostream &OS) {
610 printAdjustedAfter(
T, OS);
613void TypePrinter::printDependentSizedArrayBefore(
616 IncludeStrongLifetimeRAII Strong(Policy);
617 printBefore(
T->getElementType(), OS);
620void TypePrinter::printDependentSizedArrayAfter(
624 if (
T->getSizeExpr())
625 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
627 printAfter(
T->getElementType(), OS);
630void TypePrinter::printDependentAddressSpaceBefore(
635void TypePrinter::printDependentAddressSpaceAfter(
637 OS <<
" __attribute__((address_space(";
638 if (
T->getAddrSpaceExpr())
639 T->getAddrSpaceExpr()->printPretty(OS,
nullptr, Policy);
644void TypePrinter::printDependentSizedExtVectorBefore(
647 if (Policy.UseHLSLTypes)
649 printBefore(
T->getElementType(), OS);
652void TypePrinter::printDependentSizedExtVectorAfter(
655 if (Policy.UseHLSLTypes) {
657 if (
T->getSizeExpr())
658 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
661 OS <<
" __attribute__((ext_vector_type(";
662 if (
T->getSizeExpr())
663 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
666 printAfter(
T->getElementType(), OS);
669void TypePrinter::printVectorBefore(
const VectorType *
T, raw_ostream &OS) {
670 switch (
T->getVectorKind()) {
671 case VectorKind::AltiVecPixel:
672 OS <<
"__vector __pixel ";
674 case VectorKind::AltiVecBool:
675 OS <<
"__vector __bool ";
676 printBefore(
T->getElementType(), OS);
678 case VectorKind::AltiVecVector:
680 printBefore(
T->getElementType(), OS);
682 case VectorKind::Neon:
683 OS <<
"__attribute__((neon_vector_type("
684 <<
T->getNumElements() <<
"))) ";
685 printBefore(
T->getElementType(), OS);
687 case VectorKind::NeonPoly:
688 OS <<
"__attribute__((neon_polyvector_type(" <<
689 T->getNumElements() <<
"))) ";
690 printBefore(
T->getElementType(), OS);
692 case VectorKind::Generic: {
695 OS <<
"__attribute__((__vector_size__("
696 <<
T->getNumElements()
698 print(
T->getElementType(), OS, StringRef());
700 printBefore(
T->getElementType(), OS);
703 case VectorKind::SveFixedLengthData:
704 case VectorKind::SveFixedLengthPredicate:
707 OS <<
"__attribute__((__arm_sve_vector_bits__(";
709 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
712 OS <<
T->getNumElements() * 8;
714 OS <<
T->getNumElements();
717 print(
T->getElementType(), OS, StringRef());
720 printBefore(
T->getElementType(), OS);
722 case VectorKind::RVVFixedLengthData:
723 case VectorKind::RVVFixedLengthMask:
724 case VectorKind::RVVFixedLengthMask_1:
725 case VectorKind::RVVFixedLengthMask_2:
726 case VectorKind::RVVFixedLengthMask_4:
729 OS <<
"__attribute__((__riscv_rvv_vector_bits__(";
731 OS <<
T->getNumElements();
734 print(
T->getElementType(), OS, StringRef());
737 printBefore(
T->getElementType(), OS);
742void TypePrinter::printVectorAfter(
const VectorType *
T, raw_ostream &OS) {
743 printAfter(
T->getElementType(), OS);
746void TypePrinter::printDependentVectorBefore(
748 switch (
T->getVectorKind()) {
749 case VectorKind::AltiVecPixel:
750 OS <<
"__vector __pixel ";
752 case VectorKind::AltiVecBool:
753 OS <<
"__vector __bool ";
754 printBefore(
T->getElementType(), OS);
756 case VectorKind::AltiVecVector:
758 printBefore(
T->getElementType(), OS);
760 case VectorKind::Neon:
761 OS <<
"__attribute__((neon_vector_type(";
762 if (
T->getSizeExpr())
763 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
765 printBefore(
T->getElementType(), OS);
767 case VectorKind::NeonPoly:
768 OS <<
"__attribute__((neon_polyvector_type(";
769 if (
T->getSizeExpr())
770 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
772 printBefore(
T->getElementType(), OS);
774 case VectorKind::Generic: {
777 OS <<
"__attribute__((__vector_size__(";
778 if (
T->getSizeExpr())
779 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
781 print(
T->getElementType(), OS, StringRef());
783 printBefore(
T->getElementType(), OS);
786 case VectorKind::SveFixedLengthData:
787 case VectorKind::SveFixedLengthPredicate:
790 OS <<
"__attribute__((__arm_sve_vector_bits__(";
791 if (
T->getSizeExpr()) {
792 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
793 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
798 print(
T->getElementType(), OS, StringRef());
803 printBefore(
T->getElementType(), OS);
805 case VectorKind::RVVFixedLengthData:
806 case VectorKind::RVVFixedLengthMask:
807 case VectorKind::RVVFixedLengthMask_1:
808 case VectorKind::RVVFixedLengthMask_2:
809 case VectorKind::RVVFixedLengthMask_4:
812 OS <<
"__attribute__((__riscv_rvv_vector_bits__(";
813 if (
T->getSizeExpr()) {
814 T->getSizeExpr()->printPretty(OS,
nullptr, Policy);
816 print(
T->getElementType(), OS, StringRef());
821 printBefore(
T->getElementType(), OS);
826void TypePrinter::printDependentVectorAfter(
828 printAfter(
T->getElementType(), OS);
833 if (Policy.UseHLSLTypes)
835 printBefore(
T->getElementType(), OS);
838void TypePrinter::printExtVectorAfter(
const ExtVectorType *
T, raw_ostream &OS) {
839 printAfter(
T->getElementType(), OS);
841 if (Policy.UseHLSLTypes) {
843 OS <<
T->getNumElements();
846 OS <<
" __attribute__((ext_vector_type(";
847 OS <<
T->getNumElements();
854 printBefore(
T->getElementType(), OS);
855 OS <<
" __attribute__((matrix_type(";
856 OS <<
T->getNumRows() <<
", " <<
T->getNumColumns();
862 printAfter(
T->getElementType(), OS);
865void TypePrinter::printDependentSizedMatrixBefore(
867 printBefore(
T->getElementType(), OS);
868 OS <<
" __attribute__((matrix_type(";
869 if (
T->getRowExpr()) {
870 T->getRowExpr()->printPretty(OS,
nullptr, Policy);
873 if (
T->getColumnExpr()) {
874 T->getColumnExpr()->printPretty(OS,
nullptr, Policy);
879void TypePrinter::printDependentSizedMatrixAfter(
881 printAfter(
T->getElementType(), OS);
901 OS <<
" __attribute__((nothrow))";
919 if (!HasEmptyPlaceHolder)
925 if (!PrevPHIsEmpty.get())
933 llvm_unreachable(
"asking for spelling of ordinary parameter ABI");
935 return "swift_context";
937 return "swift_async_context";
939 return "swift_error_result";
941 return "swift_indirect_result";
947 llvm_unreachable(
"bad parameter ABI kind");
953 if (!HasEmptyPlaceHolder)
959 ParamPolicyRAII ParamPolicy(Policy);
964 if (EPI.isConsumed()) OS <<
"__attribute__((ns_consumed)) ";
965 if (EPI.isNoEscape())
966 OS <<
"__attribute__((noescape)) ";
967 auto ABI = EPI.getABI();
970 if (Policy.UseHLSLTypes) {
989 }
else if (
T->
getNumParams() == 0 && Policy.UseVoidForZeroParams) {
1000 OS <<
" __arm_streaming_compatible";
1002 OS <<
" __arm_streaming";
1004 OS <<
"__arm_agnostic(\"sme_za_state\")";
1006 OS <<
" __arm_preserves(\"za\")";
1008 OS <<
" __arm_in(\"za\")";
1010 OS <<
" __arm_out(\"za\")";
1012 OS <<
" __arm_inout(\"za\")";
1014 OS <<
" __arm_preserves(\"zt0\")";
1016 OS <<
" __arm_in(\"zt0\")";
1018 OS <<
" __arm_out(\"zt0\")";
1020 OS <<
" __arm_inout(\"zt0\")";
1022 printFunctionAfter(Info, OS);
1042 for (
const auto &CFE : FX) {
1043 OS <<
" __attribute__((" << CFE.Effect.name();
1044 if (
const Expr *
E = CFE.Cond.getCondition()) {
1061 if (!InsideCCAttribute) {
1062 switch (Info.
getCC()) {
1073 OS <<
" __attribute__((stdcall))";
1076 OS <<
" __attribute__((fastcall))";
1079 OS <<
" __attribute__((thiscall))";
1082 OS <<
" __attribute__((vectorcall))";
1085 OS <<
" __attribute__((pascal))";
1088 OS <<
" __attribute__((pcs(\"aapcs\")))";
1091 OS <<
" __attribute__((pcs(\"aapcs-vfp\")))";
1094 OS <<
"__attribute__((aarch64_vector_pcs))";
1097 OS <<
"__attribute__((aarch64_sve_pcs))";
1100 OS <<
"__attribute__((amdgpu_kernel))";
1103 OS <<
" __attribute__((intel_ocl_bicc))";
1106 OS <<
" __attribute__((ms_abi))";
1109 OS <<
" __attribute__((sysv_abi))";
1112 OS <<
" __attribute__((regcall))";
1119 OS <<
" __attribute__((swiftcall))";
1122 OS <<
"__attribute__((swiftasynccall))";
1125 OS <<
" __attribute__((preserve_most))";
1128 OS <<
" __attribute__((preserve_all))";
1131 OS <<
" __attribute__((m68k_rtd))";
1134 OS <<
" __attribute__((preserve_none))";
1137 OS <<
"__attribute__((riscv_vector_cc))";
1143 OS <<
" __attribute__((noreturn))";
1145 OS <<
" __attribute__((cmse_nonsecure_call))";
1147 OS <<
" __attribute__((ns_returns_retained))";
1149 OS <<
" __attribute__((regparm ("
1152 OS <<
" __attribute__((no_caller_saved_registers))";
1154 OS <<
" __attribute__((nocf_check))";
1162 if (!PrevPHIsEmpty.get())
1169 if (!HasEmptyPlaceHolder)
1178void TypePrinter::printTypeSpec(
NamedDecl *
D, raw_ostream &OS) {
1183 if (!Policy.SuppressScope)
1188 spaceBeforePlaceHolder(OS);
1193 printTypeSpec(
T->getDecl(), OS);
1199void TypePrinter::printUsingBefore(
const UsingType *
T, raw_ostream &OS) {
1209 printTypeSpec(
T->getFoundDecl()->getUnderlyingDecl(), OS);
1212void TypePrinter::printUsingAfter(
const UsingType *
T, raw_ostream &OS) {}
1214void TypePrinter::printTypedefBefore(
const TypedefType *
T, raw_ostream &OS) {
1215 printTypeSpec(
T->getDecl(), OS);
1220 StringRef MacroName =
T->getMacroIdentifier()->getName();
1221 OS << MacroName <<
" ";
1225 printBefore(
T->getModifiedType(), OS);
1230 printAfter(
T->getModifiedType(), OS);
1233void TypePrinter::printTypedefAfter(
const TypedefType *
T, raw_ostream &OS) {}
1239 if (
T->getUnderlyingExpr())
1240 T->getUnderlyingExpr()->printPretty(OS,
nullptr, Policy);
1241 spaceBeforePlaceHolder(OS);
1247void TypePrinter::printTypeOfBefore(
const TypeOfType *
T, raw_ostream &OS) {
1250 print(
T->getUnmodifiedType(), OS, StringRef());
1252 spaceBeforePlaceHolder(OS);
1255void TypePrinter::printTypeOfAfter(
const TypeOfType *
T, raw_ostream &OS) {}
1257void TypePrinter::printDecltypeBefore(
const DecltypeType *
T, raw_ostream &OS) {
1259 if (
T->getUnderlyingExpr())
1260 T->getUnderlyingExpr()->printPretty(OS,
nullptr, Policy);
1262 spaceBeforePlaceHolder(OS);
1267 if (
T->hasSelectedType()) {
1268 OS <<
T->getSelectedType();
1270 OS <<
T->getPattern() <<
"...[";
1271 T->getIndexExpr()->printPretty(OS,
nullptr, Policy);
1274 spaceBeforePlaceHolder(OS);
1280void TypePrinter::printDecltypeAfter(
const DecltypeType *
T, raw_ostream &OS) {}
1284 IncludeStrongLifetimeRAII Strong(Policy);
1286 static llvm::DenseMap<int, const char *> Transformation = {{
1287#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
1288 {UnaryTransformType::Enum, "__" #Trait},
1289#include "clang/Basic/TransformTypeTraits.def"
1291 OS << Transformation[
T->getUTTKind()] <<
'(';
1292 print(
T->getBaseType(), OS, StringRef());
1294 spaceBeforePlaceHolder(OS);
1300void TypePrinter::printAutoBefore(
const AutoType *
T, raw_ostream &OS) {
1302 if (!
T->getDeducedType().isNull()) {
1303 printBefore(
T->getDeducedType(), OS);
1305 if (
T->isConstrained()) {
1308 T->getTypeConstraintConcept()->getDeclName().print(OS, Policy);
1309 auto Args =
T->getTypeConstraintArguments();
1313 T->getTypeConstraintConcept()->getTemplateParameters());
1316 switch (
T->getKeyword()) {
1321 spaceBeforePlaceHolder(OS);
1325void TypePrinter::printAutoAfter(
const AutoType *
T, raw_ostream &OS) {
1327 if (!
T->getDeducedType().isNull())
1328 printAfter(
T->getDeducedType(), OS);
1331void TypePrinter::printDeducedTemplateSpecializationBefore(
1334 if (!
T->getDeducedType().isNull()) {
1335 printBefore(
T->getDeducedType(), OS);
1337 IncludeStrongLifetimeRAII Strong(Policy);
1338 T->getTemplateName().print(OS, Policy);
1339 spaceBeforePlaceHolder(OS);
1343void TypePrinter::printDeducedTemplateSpecializationAfter(
1346 if (!
T->getDeducedType().isNull())
1347 printAfter(
T->getDeducedType(), OS);
1350void TypePrinter::printAtomicBefore(
const AtomicType *
T, raw_ostream &OS) {
1351 IncludeStrongLifetimeRAII Strong(Policy);
1354 print(
T->getValueType(), OS, StringRef());
1356 spaceBeforePlaceHolder(OS);
1359void TypePrinter::printAtomicAfter(
const AtomicType *
T, raw_ostream &OS) {}
1361void TypePrinter::printPipeBefore(
const PipeType *
T, raw_ostream &OS) {
1362 IncludeStrongLifetimeRAII Strong(Policy);
1364 if (
T->isReadOnly())
1367 OS <<
"write_only ";
1369 print(
T->getElementType(), OS, StringRef());
1370 spaceBeforePlaceHolder(OS);
1373void TypePrinter::printPipeAfter(
const PipeType *
T, raw_ostream &OS) {}
1375void TypePrinter::printBitIntBefore(
const BitIntType *
T, raw_ostream &OS) {
1376 if (
T->isUnsigned())
1378 OS <<
"_BitInt(" <<
T->getNumBits() <<
")";
1379 spaceBeforePlaceHolder(OS);
1382void TypePrinter::printBitIntAfter(
const BitIntType *
T, raw_ostream &OS) {}
1386 if (
T->isUnsigned())
1389 T->getNumBitsExpr()->printPretty(OS,
nullptr, Policy);
1391 spaceBeforePlaceHolder(OS);
1398void TypePrinter::AppendScope(
DeclContext *DC, raw_ostream &OS,
1408 if (Policy.Callbacks && Policy.Callbacks->isScopeVisible(DC))
1411 if (
const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1412 if (Policy.SuppressUnwrittenScope && NS->isAnonymousNamespace())
1413 return AppendScope(DC->
getParent(), OS, NameInScope);
1417 if (Policy.SuppressInlineNamespace !=
1419 NS->isInline() && NameInScope &&
1420 NS->isRedundantInlineQualifierFor(NameInScope))
1421 return AppendScope(DC->
getParent(), OS, NameInScope);
1423 AppendScope(DC->
getParent(), OS, NS->getDeclName());
1424 if (NS->getIdentifier())
1425 OS << NS->getName() <<
"::";
1427 OS <<
"(anonymous namespace)::";
1428 }
else if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1429 AppendScope(DC->
getParent(), OS, Spec->getDeclName());
1430 IncludeStrongLifetimeRAII Strong(Policy);
1431 OS << Spec->getIdentifier()->getName();
1434 OS, TemplateArgs.
asArray(), Policy,
1435 Spec->getSpecializedTemplate()->getTemplateParameters());
1437 }
else if (
const auto *Tag = dyn_cast<TagDecl>(DC)) {
1440 OS << Typedef->getIdentifier()->getName() <<
"::";
1441 else if (
Tag->getIdentifier())
1442 OS <<
Tag->getIdentifier()->getName() <<
"::";
1446 AppendScope(DC->
getParent(), OS, NameInScope);
1450void TypePrinter::printTag(
TagDecl *
D, raw_ostream &OS) {
1451 if (Policy.IncludeTagDefinition) {
1454 D->
print(OS, SubPolicy, Indentation);
1455 spaceBeforePlaceHolder(OS);
1459 bool HasKindDecoration =
false;
1463 if (!Policy.SuppressTagKeyword && !
D->getTypedefNameForAnonDecl()) {
1464 HasKindDecoration =
true;
1465 OS <<
D->getKindName();
1472 if (!Policy.SuppressScope)
1478 assert(Typedef->getIdentifier() &&
"Typedef without identifier?");
1479 OS << Typedef->getIdentifier()->getName();
1483 OS << (Policy.MSVCFormatting ?
'`' :
'(');
1485 if (isa<CXXRecordDecl>(
D) && cast<CXXRecordDecl>(
D)->isLambda()) {
1487 HasKindDecoration =
true;
1488 }
else if ((isa<RecordDecl>(
D) && cast<RecordDecl>(
D)->isAnonymousStructOrUnion())) {
1494 if (Policy.AnonymousTagLocations) {
1498 if (!HasKindDecoration)
1499 OS <<
" " <<
D->getKindName();
1507 if (
auto *Callbacks = Policy.Callbacks)
1508 WrittenFile = Callbacks->remapPath(
File);
1512 llvm::sys::path::Style Style =
1513 llvm::sys::path::is_absolute(WrittenFile)
1514 ? llvm::sys::path::Style::native
1515 : (Policy.MSVCFormatting
1516 ? llvm::sys::path::Style::windows_backslash
1517 : llvm::sys::path::Style::posix);
1518 llvm::sys::path::native(WrittenFile, Style);
1523 OS << (Policy.MSVCFormatting ?
'\'' :
')');
1528 if (
auto *S = dyn_cast<ClassTemplateSpecializationDecl>(
D)) {
1530 S->getSpecializedTemplate()->getTemplateParameters();
1532 S->getTemplateArgsAsWritten();
1533 IncludeStrongLifetimeRAII Strong(Policy);
1534 if (TArgAsWritten && !Policy.PrintCanonicalTypes)
1542 spaceBeforePlaceHolder(OS);
1545void TypePrinter::printRecordBefore(
const RecordType *
T, raw_ostream &OS) {
1547 if (Policy.UsePreferredNames) {
1548 for (
const auto *PNA :
T->getDecl()->specific_attrs<PreferredNameAttr>()) {
1555 if (
auto *TT = dyn_cast<TypedefType>(
T))
1556 return printTypeSpec(TT->getDecl(), OS);
1557 if (
auto *TST = dyn_cast<TemplateSpecializationType>(
T))
1558 return printTemplateId(TST, OS,
true);
1564 printTag(
T->getDecl(), OS);
1567void TypePrinter::printRecordAfter(
const RecordType *
T, raw_ostream &OS) {}
1569void TypePrinter::printEnumBefore(
const EnumType *
T, raw_ostream &OS) {
1570 printTag(
T->getDecl(), OS);
1573void TypePrinter::printEnumAfter(
const EnumType *
T, raw_ostream &OS) {}
1579 if (
auto *TC =
D->getTypeConstraint()) {
1580 TC->print(OS, Policy);
1585 OS << (Policy.CleanUglifiedParameters ?
Id->deuglifiedName()
1588 OS <<
"type-parameter-" <<
T->getDepth() <<
'-' <<
T->getIndex();
1590 spaceBeforePlaceHolder(OS);
1596void TypePrinter::printSubstTemplateTypeParmBefore(
1599 IncludeStrongLifetimeRAII Strong(Policy);
1600 printBefore(
T->getReplacementType(), OS);
1603void TypePrinter::printSubstTemplateTypeParmAfter(
1606 IncludeStrongLifetimeRAII Strong(Policy);
1607 printAfter(
T->getReplacementType(), OS);
1610void TypePrinter::printSubstTemplateTypeParmPackBefore(
1613 IncludeStrongLifetimeRAII Strong(Policy);
1616 if (
auto *TC =
D->getTypeConstraint()) {
1617 TC->print(OS, Policy);
1622 OS << (Policy.CleanUglifiedParameters ?
Id->deuglifiedName()
1625 OS <<
"type-parameter-" <<
D->getDepth() <<
'-' <<
D->getIndex();
1627 spaceBeforePlaceHolder(OS);
1631void TypePrinter::printSubstTemplateTypeParmPackAfter(
1634 IncludeStrongLifetimeRAII Strong(Policy);
1638 raw_ostream &OS,
bool FullyQualify) {
1639 IncludeStrongLifetimeRAII Strong(Policy);
1642 T->getTemplateName().getAsTemplateDecl(
true);
1644 if (FullyQualify && TD) {
1645 if (!Policy.SuppressScope)
1653 DefaultTemplateArgsPolicyRAII TemplateArgs(Policy);
1656 spaceBeforePlaceHolder(OS);
1659void TypePrinter::printTemplateSpecializationBefore(
1662 printTemplateId(
T, OS, Policy.FullyQualifiedName);
1665void TypePrinter::printTemplateSpecializationAfter(
1671 if (Policy.PrintInjectedClassNameWithArguments)
1672 return printTemplateSpecializationBefore(
T->getInjectedTST(), OS);
1674 IncludeStrongLifetimeRAII Strong(Policy);
1675 T->getTemplateName().print(OS, Policy);
1676 spaceBeforePlaceHolder(OS);
1684 if (Policy.IncludeTagDefinition &&
T->getOwnedTagDecl()) {
1685 TagDecl *OwnedTagDecl =
T->getOwnedTagDecl();
1686 assert(OwnedTagDecl->
getTypeForDecl() ==
T->getNamedType().getTypePtr() &&
1687 "OwnedTagDecl expected to be a declaration for the type");
1690 OwnedTagDecl->
print(OS, SubPolicy, Indentation);
1691 spaceBeforePlaceHolder(OS);
1695 if (Policy.SuppressElaboration) {
1696 printBefore(
T->getNamedType(), OS);
1701 if (!Policy.IncludeTagDefinition)
1707 if (!Policy.SuppressTagKeyword && Policy.SuppressScope &&
1708 !Policy.SuppressUnwrittenScope) {
1709 bool OldTagKeyword = Policy.SuppressTagKeyword;
1710 bool OldSupressScope = Policy.SuppressScope;
1711 Policy.SuppressTagKeyword =
true;
1712 Policy.SuppressScope =
false;
1713 printBefore(
T->getNamedType(), OS);
1714 Policy.SuppressTagKeyword = OldTagKeyword;
1715 Policy.SuppressScope = OldSupressScope;
1722 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1723 printBefore(
T->getNamedType(), OS);
1728 if (Policy.IncludeTagDefinition &&
T->getOwnedTagDecl())
1731 if (Policy.SuppressElaboration) {
1732 printAfter(
T->getNamedType(), OS);
1736 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1737 printAfter(
T->getNamedType(), OS);
1740void TypePrinter::printParenBefore(
const ParenType *
T, raw_ostream &OS) {
1741 if (!HasEmptyPlaceHolder && !isa<FunctionType>(
T->getInnerType())) {
1742 printBefore(
T->getInnerType(), OS);
1745 printBefore(
T->getInnerType(), OS);
1748void TypePrinter::printParenAfter(
const ParenType *
T, raw_ostream &OS) {
1749 if (!HasEmptyPlaceHolder && !isa<FunctionType>(
T->getInnerType())) {
1751 printAfter(
T->getInnerType(), OS);
1753 printAfter(
T->getInnerType(), OS);
1762 T->getQualifier()->print(OS, Policy);
1764 OS <<
T->getIdentifier()->getName();
1765 spaceBeforePlaceHolder(OS);
1771void TypePrinter::printDependentTemplateSpecializationBefore(
1773 IncludeStrongLifetimeRAII Strong(Policy);
1779 if (
T->getQualifier())
1780 T->getQualifier()->print(OS, Policy);
1781 OS <<
"template " <<
T->getIdentifier()->getName();
1783 spaceBeforePlaceHolder(OS);
1786void TypePrinter::printDependentTemplateSpecializationAfter(
1791 printBefore(
T->getPattern(), OS);
1796 printAfter(
T->getPattern(), OS);
1804 if (
T->isCountInBytes() &&
T->isOrNull())
1805 OS <<
"__sized_by_or_null(";
1806 else if (
T->isCountInBytes())
1807 OS <<
"__sized_by(";
1808 else if (
T->isOrNull())
1809 OS <<
"__counted_by_or_null(";
1811 OS <<
"__counted_by(";
1812 if (
T->getCountExpr())
1813 T->getCountExpr()->printPretty(OS,
nullptr, Policy);
1836 if (
T->getAttrKind() == attr::ObjCGC ||
1837 T->getAttrKind() == attr::ObjCOwnership)
1838 return printBefore(
T->getEquivalentType(), OS);
1840 if (
T->getAttrKind() == attr::ObjCKindOf)
1843 if (
T->getAttrKind() == attr::AddressSpace)
1844 printBefore(
T->getEquivalentType(), OS);
1846 printBefore(
T->getModifiedType(), OS);
1848 if (
T->isMSTypeSpec()) {
1849 switch (
T->getAttrKind()) {
1851 case attr::Ptr32: OS <<
" __ptr32";
break;
1852 case attr::Ptr64: OS <<
" __ptr64";
break;
1853 case attr::SPtr: OS <<
" __sptr";
break;
1854 case attr::UPtr: OS <<
" __uptr";
break;
1856 spaceBeforePlaceHolder(OS);
1859 if (
T->isWebAssemblyFuncrefSpec())
1863 if (
T->getImmediateNullability()) {
1864 if (
T->getAttrKind() == attr::TypeNonNull)
1866 else if (
T->getAttrKind() == attr::TypeNullable)
1868 else if (
T->getAttrKind() == attr::TypeNullUnspecified)
1869 OS <<
" _Null_unspecified";
1870 else if (
T->getAttrKind() == attr::TypeNullableResult)
1871 OS <<
" _Nullable_result";
1873 llvm_unreachable(
"unhandled nullability");
1874 spaceBeforePlaceHolder(OS);
1883 if (
T->getAttrKind() == attr::ObjCGC ||
1884 T->getAttrKind() == attr::ObjCOwnership)
1885 return printAfter(
T->getEquivalentType(), OS);
1889 SaveAndRestore MaybeSuppressCC(InsideCCAttribute,
T->isCallingConv());
1891 printAfter(
T->getModifiedType(), OS);
1895 if (
T->getAttrKind() == attr::ObjCKindOf ||
T->isMSTypeSpec() ||
1896 T->getImmediateNullability() ||
T->isWebAssemblyFuncrefSpec())
1900 if (
T->getAttrKind() == attr::ObjCInertUnsafeUnretained)
1904 if (
T->getAttrKind() == attr::NSReturnsRetained &&
1909 if (
T->getAttrKind() == attr::LifetimeBound) {
1910 OS <<
" [[clang::lifetimebound]]";
1913 if (
T->getAttrKind() == attr::LifetimeCaptureBy) {
1914 OS <<
" [[clang::lifetime_capture_by(";
1915 if (
auto *attr = dyn_cast_or_null<LifetimeCaptureByAttr>(
T->getAttr()))
1916 llvm::interleaveComma(
attr->getArgIdents(), OS,
1917 [&](
auto it) { OS << it->getName(); });
1925 if (
T->getAttrKind() == attr::AddressSpace)
1928 if (
T->getAttrKind() == attr::AnnotateType) {
1933 OS <<
" [[clang::annotate_type(...)]]";
1937 if (
T->getAttrKind() == attr::ArmStreaming) {
1938 OS <<
"__arm_streaming";
1941 if (
T->getAttrKind() == attr::ArmStreamingCompatible) {
1942 OS <<
"__arm_streaming_compatible";
1946 if (
T->getAttrKind() == attr::SwiftAttr) {
1947 if (
auto *swiftAttr = dyn_cast_or_null<SwiftAttrAttr>(
T->getAttr())) {
1948 OS <<
" __attribute__((swift_attr(\"" << swiftAttr->getAttribute()
1954 OS <<
" __attribute__((";
1955 switch (
T->getAttrKind()) {
1956#define TYPE_ATTR(NAME)
1957#define DECL_OR_TYPE_ATTR(NAME)
1958#define ATTR(NAME) case attr::NAME:
1959#include "clang/Basic/AttrList.inc"
1960 llvm_unreachable(
"non-type attribute attached to type");
1962 case attr::BTFTypeTag:
1963 llvm_unreachable(
"BTFTypeTag attribute handled separately");
1965 case attr::HLSLResourceClass:
1967 case attr::HLSLRawBuffer:
1968 case attr::HLSLContainedType:
1969 llvm_unreachable(
"HLSL resource type attributes handled separately");
1971 case attr::OpenCLPrivateAddressSpace:
1972 case attr::OpenCLGlobalAddressSpace:
1973 case attr::OpenCLGlobalDeviceAddressSpace:
1974 case attr::OpenCLGlobalHostAddressSpace:
1975 case attr::OpenCLLocalAddressSpace:
1976 case attr::OpenCLConstantAddressSpace:
1977 case attr::OpenCLGenericAddressSpace:
1978 case attr::HLSLGroupSharedAddressSpace:
1983 case attr::CountedBy:
1984 case attr::CountedByOrNull:
1986 case attr::SizedByOrNull:
1987 case attr::LifetimeBound:
1988 case attr::LifetimeCaptureBy:
1989 case attr::TypeNonNull:
1990 case attr::TypeNullable:
1991 case attr::TypeNullableResult:
1992 case attr::TypeNullUnspecified:
1994 case attr::ObjCInertUnsafeUnretained:
1995 case attr::ObjCKindOf:
1996 case attr::ObjCOwnership:
2001 case attr::AddressSpace:
2002 case attr::CmseNSCall:
2003 case attr::AnnotateType:
2004 case attr::WebAssemblyFuncref:
2005 case attr::ArmAgnostic:
2006 case attr::ArmStreaming:
2007 case attr::ArmStreamingCompatible:
2010 case attr::ArmInOut:
2011 case attr::ArmPreserves:
2012 case attr::NonBlocking:
2013 case attr::NonAllocating:
2014 case attr::Blocking:
2015 case attr::Allocating:
2016 case attr::SwiftAttr:
2017 llvm_unreachable(
"This attribute should have been handled already");
2019 case attr::NSReturnsRetained:
2020 OS <<
"ns_returns_retained";
2025 case attr::AnyX86NoCfCheck: OS <<
"nocf_check";
break;
2026 case attr::CDecl: OS <<
"cdecl";
break;
2027 case attr::FastCall: OS <<
"fastcall";
break;
2028 case attr::StdCall: OS <<
"stdcall";
break;
2029 case attr::ThisCall: OS <<
"thiscall";
break;
2030 case attr::SwiftCall: OS <<
"swiftcall";
break;
2031 case attr::SwiftAsyncCall: OS <<
"swiftasynccall";
break;
2032 case attr::VectorCall: OS <<
"vectorcall";
break;
2033 case attr::Pascal: OS <<
"pascal";
break;
2034 case attr::MSABI: OS <<
"ms_abi";
break;
2035 case attr::SysVABI: OS <<
"sysv_abi";
break;
2036 case attr::RegCall: OS <<
"regcall";
break;
2043 "\"aapcs\"" :
"\"aapcs-vfp\"");
2047 case attr::AArch64VectorPcs: OS <<
"aarch64_vector_pcs";
break;
2048 case attr::AArch64SVEPcs: OS <<
"aarch64_sve_pcs";
break;
2049 case attr::AMDGPUKernelCall: OS <<
"amdgpu_kernel";
break;
2050 case attr::IntelOclBicc: OS <<
"inteloclbicc";
break;
2051 case attr::PreserveMost:
2052 OS <<
"preserve_most";
2055 case attr::PreserveAll:
2056 OS <<
"preserve_all";
2061 case attr::PreserveNone:
2062 OS <<
"preserve_none";
2064 case attr::RISCVVectorCC:
2065 OS <<
"riscv_vector_cc";
2070 case attr::AcquireHandle:
2071 OS <<
"acquire_handle";
2073 case attr::ArmMveStrictPolymorphism:
2074 OS <<
"__clang_arm_mve_strict_polymorphism";
2082 printBefore(
T->getWrappedType(), OS);
2083 OS <<
" __attribute__((btf_type_tag(\"" <<
T->getAttr()->getBTFTypeTag() <<
"\")))";
2088 printAfter(
T->getWrappedType(), OS);
2091void TypePrinter::printHLSLAttributedResourceBefore(
2093 printBefore(
T->getWrappedType(), OS);
2096void TypePrinter::printHLSLAttributedResourceAfter(
2098 printAfter(
T->getWrappedType(), OS);
2100 OS <<
" [[hlsl::resource_class("
2101 << HLSLResourceClassAttr::ConvertResourceClassToStr(Attrs.
ResourceClass)
2104 OS <<
" [[hlsl::is_rov]]";
2106 OS <<
" [[hlsl::raw_buffer]]";
2108 QualType ContainedTy =
T->getContainedType();
2109 if (!ContainedTy.
isNull()) {
2110 OS <<
" [[hlsl::contained_type(";
2111 printBefore(ContainedTy, OS);
2112 printAfter(ContainedTy, OS);
2119 OS <<
T->getDecl()->getName();
2120 spaceBeforePlaceHolder(OS);
2128 OS <<
T->getDecl()->getName();
2129 if (!
T->qual_empty()) {
2130 bool isFirst =
true;
2132 for (
const auto *I :
T->quals()) {
2142 spaceBeforePlaceHolder(OS);
2150 if (
T->qual_empty() &&
T->isUnspecializedAsWritten() &&
2151 !
T->isKindOfTypeAsWritten())
2152 return printBefore(
T->getBaseType(), OS);
2154 if (
T->isKindOfTypeAsWritten())
2157 print(
T->getBaseType(), OS, StringRef());
2159 if (
T->isSpecializedAsWritten()) {
2160 bool isFirst =
true;
2162 for (
auto typeArg :
T->getTypeArgsAsWritten()) {
2168 print(typeArg, OS, StringRef());
2173 if (!
T->qual_empty()) {
2174 bool isFirst =
true;
2176 for (
const auto *I :
T->quals()) {
2186 spaceBeforePlaceHolder(OS);
2191 if (
T->qual_empty() &&
T->isUnspecializedAsWritten() &&
2192 !
T->isKindOfTypeAsWritten())
2193 return printAfter(
T->getBaseType(), OS);
2203 if (HasEmptyPlaceHolder)
2220 llvm::raw_ostream &OS,
bool IncludeType) {
2221 A.
print(PP, OS, IncludeType);
2245 if (TTPT->getDepth() == Depth && TTPT->getIndex() < Args.size() &&
2248 Args[TTPT->getIndex()].getAsType(), Pattern.
getQualifiers());
2260 if (TQual != PatQual)
2278 Template = TTST->getTemplateName();
2279 TemplateArgs = TTST->template_arguments();
2280 }
else if (
auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
2282 Template =
TemplateName(CTSD->getSpecializedTemplate());
2283 TemplateArgs = CTSD->getTemplateArgs().asArray();
2291 if (TemplateArgs.size() != PTST->template_arguments().size())
2293 for (
unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
2295 Ctx, TemplateArgs[I], PTST->template_arguments()[I], Args, Depth))
2346 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
2347 return NTTP->getDepth() == Depth && Args.size() > NTTP->getIndex() &&
2348 Args[NTTP->getIndex()].structurallyEquals(Arg);
2364 if (
auto *TTPD = dyn_cast_or_null<TemplateTemplateParmDecl>(PatTD))
2365 return TTPD->getDepth() == Depth && Args.size() > TTPD->getIndex() &&
2382 if (
auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Param)) {
2383 return TTPD->hasDefaultArgument() &&
2385 Ctx, Arg, TTPD->getDefaultArgument().getArgument(), Args, Depth);
2386 }
else if (
auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2387 return TTPD->hasDefaultArgument() &&
2389 Ctx, Arg, TTPD->getDefaultArgument().getArgument(), Args, Depth);
2390 }
else if (
auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2391 return NTTPD->hasDefaultArgument() &&
2393 Ctx, Arg, NTTPD->getDefaultArgument().getArgument(), Args,
2399template <
typename TA>
2406 Args.size() <= TPL->
size()) {
2408 for (
const TA &A : Args)
2411 Args = Args.drop_back();
2418 bool NeedSpace =
false;
2419 bool FirstArg =
true;
2420 for (
const auto &Arg : Args) {
2423 llvm::raw_svector_ostream ArgOS(Buf);
2436 Policy, TPL, ParmIndex));
2438 StringRef ArgString = ArgOS.str();
2443 if (FirstArg && ArgString.starts_with(
":"))
2450 if (!ArgString.empty()) {
2478 printTo(OS, Args, Policy, TPL,
false, 0);
2485 printTo(OS, Args, Policy, TPL,
false, 0);
2498 llvm::raw_svector_ostream StrOS(Buf);
2499 print(StrOS, Policy);
2500 return std::string(StrOS.str());
2534 return "__constant";
2539 return "__global_device";
2542 return "__global_host";
2544 return "__device__";
2546 return "__constant__";
2548 return "__shared__";
2550 return "__sptr __ptr32";
2552 return "__uptr __ptr32";
2558 return "groupshared";
2568 bool appendSpaceIfNonEmpty)
const {
2569 bool addSpace =
false;
2579 OS <<
"__unaligned";
2583 if (!ASStr.empty()) {
2589 OS <<
"__attribute__((address_space(" << ASStr <<
")))";
2623 if (appendSpaceIfNonEmpty && addSpace)
2645 const Twine &PlaceHolder,
unsigned Indentation)
const {
2652 const Twine &PlaceHolder,
unsigned Indentation) {
2654 StringRef PH = PlaceHolder.toStringRef(PHBuf);
2656 TypePrinter(policy, Indentation).print(ty, qs, OS, PH);
2666 std::string &buffer,
2669 llvm::raw_svector_ostream StrOS(Buf);
2670 TypePrinter(policy).print(ty, qs, StrOS, buffer);
2671 std::string str = std::string(StrOS.str());
2677 TypePrinter(
LangOptions()).print(S.Ty, S.Quals, OS,
"");
Defines the clang::ASTContext interface.
Provides definitions for the various language-specific address spaces.
Defines the clang::attr::Kind enum.
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 &ASTCtx, QualType Ty)
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 void printCountAttributedImpl(const CountAttributedType *T, raw_ostream &OS, const PrintingPolicy &Policy)
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 ...
SourceManager & getSourceManager()
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.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals) const
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.
Represents a constant array type that does not decay to a pointer when used as a function parameter.
An attributed type is a type to which a type attribute has been applied.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
A fixed int type of a specified bitwidth.
This class is used for builtin types like 'int'.
Complex values, per C99 6.2.5p11.
Represents the canonical version of C arrays with a specified constant size.
Represents a concrete matrix type with constant number of rows and columns.
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Represents a pointer type decayed from an array or function type.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isTranslationUnit() const
bool isFunctionOrMethod() const
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
SourceLocation getLocation() const
DeclContext * getDeclContext()
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
The name of a declaration.
Represents the type decltype(expr) (C++11).
Represents a C++17 deduced template specialization type.
Represents an extended address space qualifier where the input address space value is dependent.
Represents a qualified type name for which the type name is dependent.
Represents an array type in C++ whose size is a value-dependent expression.
Represents an extended vector type where either the type or size is dependent.
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Represents a template specialization type whose template cannot be resolved, e.g.
Represents a vector type where either the type or size is dependent.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
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...
bool isIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
ExtVectorType - Extended vector type.
An immutable set of FunctionEffects and possibly conditions attached to them.
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Represents a prototype with parameter type info, e.g.
ExtParameterInfo getExtParameterInfo(unsigned I) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Qualifiers getMethodQuals() const
QualType getParamType(unsigned i) const
FunctionEffectsRef getFunctionEffects() const
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
unsigned getNumExceptions() const
Return the number of types in the exception specification.
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
A class which abstracts out some details necessary for making a call.
CallingConv getCC() const
bool getCmseNSCall() const
bool getNoCfCheck() const
unsigned getRegParm() const
bool getNoCallerSavedRegs() const
bool getProducesResult() const
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
QualType getReturnType() const
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
@ SME_AgnosticZAStateMask
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.
The injected class name of a C++ class template or class template partial specialization.
An lvalue reference type, per C++11 [dcl.ref].
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Interfaces are the core concept in Objective-C for object oriented design.
Represents a pointer to an Objective C object.
Represents a class type in Objective C.
Represents a type parameter type in Objective C.
Represents a pack expansion of types.
Sugar for parentheses used when specifying types.
PointerType - C99 6.7.5.1 - Pointer Declarators.
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.
unsigned getLine() const
Return the presumed line number of this location.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
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 getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
std::string getAsString() const
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
bool hasUnaligned() const
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
ObjCLifetime getObjCLifetime() const
std::string getAsString() const
LangAS getAddressSpace() const
static std::string getAddrSpaceAsString(LangAS AS)
An rvalue reference type, per C++11 [dcl.ref].
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Base for LValueReferenceType and RValueReferenceType.
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.
Represents the result of substituting a type for a template type parameter.
Represents the declaration of a struct/union/class/enum.
A convenient class for passing around template argument information.
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
TypeSourceInfo * getTypeSourceInfo() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
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.
ArgKind
The kind of template argument we're storing.
@ Template
The template argument is a template name that was provided for a template template parameter.
@ Pack
The template argument is actually a parameter pack.
@ Type
The template argument is a type.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
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...
Declaration of a template type parameter.
const Type * getTypeForDecl() const
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
QualType getType() const
Return the type wrapped by this type source info.
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
const T * castAs() const
Member-template castAs<specific type>.
bool isObjCQualifiedIdType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isObjCIdType() const
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
bool isFunctionType() const
bool isObjCQualifiedClassType() const
bool isObjCClassType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
Base class for declarations which introduce a typedef-name.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
The JSON file list parser is used to communicate input to InstallAPI.
@ GNUAutoType
__auto_type (GNU extension)
@ DecltypeAuto
decltype(auto)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
bool isTargetAddressSpace(LangAS AS)
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
unsigned toTargetAddressSpace(LangAS AS)
ParameterABI
Kinds of parameter ABI.
@ 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.
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 ...
const FunctionProtoType * T
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.
@ None
No keyword precedes the qualified type name.
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_MSAny
Microsoft throw(...) extension.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
llvm::dxil::ResourceClass ResourceClass
Describes how types, statements, expressions, and declarations should be printed.
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...
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.