34 #include "llvm/ADT/ArrayRef.h" 35 #include "llvm/ADT/SmallString.h" 36 #include "llvm/ADT/StringRef.h" 37 #include "llvm/ADT/Twine.h" 38 #include "llvm/Support/Casting.h" 39 #include "llvm/Support/Compiler.h" 40 #include "llvm/Support/ErrorHandling.h" 41 #include "llvm/Support/SaveAndRestore.h" 42 #include "llvm/Support/raw_ostream.h" 46 using namespace clang;
52 class IncludeStrongLifetimeRAII {
58 : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
63 ~IncludeStrongLifetimeRAII() {
68 class ParamPolicyRAII {
74 : Policy(Policy), Old(Policy.SuppressSpecifiers) {
83 class ElaboratedTypePolicyRAII {
85 bool SuppressTagKeyword;
89 explicit ElaboratedTypePolicyRAII(
PrintingPolicy &Policy) : Policy(Policy) {
96 ~ElaboratedTypePolicyRAII() {
104 unsigned Indentation;
105 bool HasEmptyPlaceHolder =
false;
106 bool InsideCCAttribute =
false;
109 explicit TypePrinter(
const PrintingPolicy &Policy,
unsigned Indentation = 0)
110 : Policy(Policy), Indentation(Indentation) {}
113 StringRef PlaceHolder);
114 void print(
QualType T, raw_ostream &OS, StringRef PlaceHolder);
116 static bool canPrefixQualifiers(
const Type *T,
bool &NeedARCStrongQualifier);
117 void spaceBeforePlaceHolder(raw_ostream &OS);
118 void printTypeSpec(
NamedDecl *D, raw_ostream &OS);
120 void printBefore(
QualType T, raw_ostream &OS);
121 void printAfter(
QualType T, raw_ostream &OS);
122 void AppendScope(
DeclContext *DC, raw_ostream &OS);
123 void printTag(
TagDecl *T, raw_ostream &OS);
125 #define ABSTRACT_TYPE(CLASS, PARENT) 126 #define TYPE(CLASS, PARENT) \ 127 void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \ 128 void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS); 129 #include "clang/AST/TypeNodes.def" 139 bool HasRestrictKeyword) {
140 bool appendSpace =
false;
146 if (appendSpace) OS <<
' ';
151 if (appendSpace) OS <<
' ';
152 if (HasRestrictKeyword) {
160 void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
161 if (!HasEmptyPlaceHolder)
172 void TypePrinter::print(
QualType t, raw_ostream &OS, StringRef PlaceHolder) {
174 print(split.
Ty, split.
Quals, OS, PlaceHolder);
177 void TypePrinter::print(
const Type *T,
Qualifiers Quals, raw_ostream &OS,
178 StringRef PlaceHolder) {
186 printBefore(T, Quals, OS);
188 printAfter(T, Quals, OS);
191 bool TypePrinter::canPrefixQualifiers(
const Type *T,
192 bool &NeedARCStrongQualifier) {
198 bool CanPrefixQualifiers =
false;
199 NeedARCStrongQualifier =
false;
201 if (
const auto *AT = dyn_cast<AutoType>(T))
202 TC = AT->desugar()->getTypeClass();
203 if (
const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))
204 TC = Subst->getReplacementType()->getTypeClass();
210 case Type::UnresolvedUsing:
212 case Type::TypeOfExpr:
215 case Type::UnaryTransform:
218 case Type::Elaborated:
219 case Type::TemplateTypeParm:
220 case Type::SubstTemplateTypeParmPack:
221 case Type::DeducedTemplateSpecialization:
222 case Type::TemplateSpecialization:
223 case Type::InjectedClassName:
224 case Type::DependentName:
225 case Type::DependentTemplateSpecialization:
226 case Type::ObjCObject:
227 case Type::ObjCTypeParam:
228 case Type::ObjCInterface:
231 CanPrefixQualifiers =
true;
234 case Type::ObjCObjectPointer:
239 case Type::ConstantArray:
240 case Type::IncompleteArray:
241 case Type::VariableArray:
242 case Type::DependentSizedArray:
243 NeedARCStrongQualifier =
true;
249 case Type::BlockPointer:
250 case Type::LValueReference:
251 case Type::RValueReference:
252 case Type::MemberPointer:
253 case Type::DependentAddressSpace:
254 case Type::DependentVector:
255 case Type::DependentSizedExtVector:
257 case Type::ExtVector:
258 case Type::FunctionProto:
259 case Type::FunctionNoProto:
261 case Type::Attributed:
262 case Type::PackExpansion:
263 case Type::SubstTemplateTypeParm:
264 CanPrefixQualifiers =
false;
268 return CanPrefixQualifiers;
271 void TypePrinter::printBefore(
QualType T, raw_ostream &OS) {
277 if (
const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(Split.
Ty))
280 printBefore(Split.
Ty, Quals, OS);
285 void TypePrinter::printBefore(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
293 bool CanPrefixQualifiers =
false;
294 bool NeedARCStrongQualifier =
false;
295 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
297 if (CanPrefixQualifiers && !Quals.
empty()) {
298 if (NeedARCStrongQualifier) {
299 IncludeStrongLifetimeRAII Strong(Policy);
300 Quals.
print(OS, Policy,
true);
302 Quals.
print(OS, Policy,
true);
306 bool hasAfterQuals =
false;
307 if (!CanPrefixQualifiers && !Quals.
empty()) {
310 HasEmptyPlaceHolder =
false;
314 #define ABSTRACT_TYPE(CLASS, PARENT) 315 #define TYPE(CLASS, PARENT) case Type::CLASS: \ 316 print##CLASS##Before(cast<CLASS##Type>(T), OS); \ 318 #include "clang/AST/TypeNodes.def" 322 if (NeedARCStrongQualifier) {
323 IncludeStrongLifetimeRAII Strong(Policy);
324 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
326 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
331 void TypePrinter::printAfter(
QualType t, raw_ostream &OS) {
333 printAfter(split.
Ty, split.
Quals, OS);
338 void TypePrinter::printAfter(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
340 #define ABSTRACT_TYPE(CLASS, PARENT) 341 #define TYPE(CLASS, PARENT) case Type::CLASS: \ 342 print##CLASS##After(cast<CLASS##Type>(T), OS); \ 344 #include "clang/AST/TypeNodes.def" 348 void TypePrinter::printBuiltinBefore(
const BuiltinType *T, raw_ostream &OS) {
350 spaceBeforePlaceHolder(OS);
353 void TypePrinter::printBuiltinAfter(
const BuiltinType *T, raw_ostream &OS) {}
355 void TypePrinter::printComplexBefore(
const ComplexType *T, raw_ostream &OS) {
360 void TypePrinter::printComplexAfter(
const ComplexType *T, raw_ostream &OS) {
364 void TypePrinter::printPointerBefore(
const PointerType *T, raw_ostream &OS) {
365 IncludeStrongLifetimeRAII Strong(Policy);
375 void TypePrinter::printPointerAfter(
const PointerType *T, raw_ostream &OS) {
376 IncludeStrongLifetimeRAII Strong(Policy);
408 IncludeStrongLifetimeRAII Strong(Policy);
411 printBefore(Inner, OS);
414 if (isa<ArrayType>(Inner))
421 IncludeStrongLifetimeRAII Strong(Policy);
426 if (isa<ArrayType>(Inner))
428 printAfter(Inner, OS);
433 IncludeStrongLifetimeRAII Strong(Policy);
436 printBefore(Inner, OS);
439 if (isa<ArrayType>(Inner))
446 IncludeStrongLifetimeRAII Strong(Policy);
451 if (isa<ArrayType>(Inner))
453 printAfter(Inner, OS);
458 IncludeStrongLifetimeRAII Strong(Policy);
468 TypePrinter(InnerPolicy).print(
QualType(T->
getClass(), 0), OS, StringRef());
475 IncludeStrongLifetimeRAII Strong(Policy);
486 IncludeStrongLifetimeRAII Strong(Policy);
503 OS << T->
getSize().getZExtValue() <<
']';
509 IncludeStrongLifetimeRAII Strong(Policy);
522 IncludeStrongLifetimeRAII Strong(Policy);
547 void TypePrinter::printAdjustedBefore(
const AdjustedType *T, raw_ostream &OS) {
553 void TypePrinter::printAdjustedAfter(
const AdjustedType *T, raw_ostream &OS) {
557 void TypePrinter::printDecayedBefore(
const DecayedType *T, raw_ostream &OS) {
559 printAdjustedBefore(T, OS);
562 void TypePrinter::printDecayedAfter(
const DecayedType *T, raw_ostream &OS) {
563 printAdjustedAfter(T, OS);
566 void TypePrinter::printDependentSizedArrayBefore(
569 IncludeStrongLifetimeRAII Strong(Policy);
574 void TypePrinter::printDependentSizedArrayAfter(
584 void TypePrinter::printDependentAddressSpaceBefore(
589 void TypePrinter::printDependentAddressSpaceAfter(
591 OS <<
" __attribute__((address_space(";
598 void TypePrinter::printDependentSizedExtVectorBefore(
604 void TypePrinter::printDependentSizedExtVectorAfter(
607 OS <<
" __attribute__((ext_vector_type(";
614 void TypePrinter::printVectorBefore(
const VectorType *T, raw_ostream &OS) {
617 OS <<
"__vector __pixel ";
620 OS <<
"__vector __bool ";
628 OS <<
"__attribute__((neon_vector_type(" 633 OS <<
"__attribute__((neon_polyvector_type(" <<
640 OS <<
"__attribute__((__vector_size__(" 651 void TypePrinter::printVectorAfter(
const VectorType *T, raw_ostream &OS) {
655 void TypePrinter::printDependentVectorBefore(
659 OS <<
"__vector __pixel ";
662 OS <<
"__vector __bool ";
670 OS <<
"__attribute__((neon_vector_type(";
677 OS <<
"__attribute__((neon_polyvector_type(";
686 OS <<
"__attribute__((__vector_size__(";
698 void TypePrinter::printDependentVectorAfter(
703 void TypePrinter::printExtVectorBefore(
const ExtVectorType *T,
708 void TypePrinter::printExtVectorAfter(
const ExtVectorType *T, raw_ostream &OS) {
710 OS <<
" __attribute__((ext_vector_type(";
719 if (hasDynamicExceptionSpec()) {
724 for (
unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
728 OS << getExceptionType(I).stream(Policy);
737 if (getNoexceptExpr())
738 getNoexceptExpr()->printPretty(OS,
nullptr, Policy);
748 if (!HasEmptyPlaceHolder)
754 if (!PrevPHIsEmpty.get())
762 llvm_unreachable(
"asking for spelling of ordinary parameter ABI");
764 return "swift_context";
766 return "swift_error_result";
768 return "swift_indirect_result";
770 llvm_unreachable(
"bad parameter ABI kind");
776 if (!HasEmptyPlaceHolder)
782 ParamPolicyRAII ParamPolicy(Policy);
783 for (
unsigned i = 0, e = T->
getNumParams(); i != e; ++i) {
787 if (EPI.isConsumed()) OS <<
"__attribute__((ns_consumed)) ";
788 if (EPI.isNoEscape())
789 OS <<
"__attribute__((noescape)) ";
802 }
else if (T->
getNumParams() == 0 && Policy.UseVoidForZeroParams) {
811 printFunctionAfter(Info, OS);
839 if (!InsideCCAttribute) {
840 switch (Info.
getCC()) {
851 OS <<
" __attribute__((stdcall))";
854 OS <<
" __attribute__((fastcall))";
857 OS <<
" __attribute__((thiscall))";
860 OS <<
" __attribute__((vectorcall))";
863 OS <<
" __attribute__((pascal))";
866 OS <<
" __attribute__((pcs(\"aapcs\")))";
869 OS <<
" __attribute__((pcs(\"aapcs-vfp\")))";
872 OS <<
"__attribute__((aarch64_vector_pcs))";
875 OS <<
" __attribute__((intel_ocl_bicc))";
878 OS <<
" __attribute__((ms_abi))";
881 OS <<
" __attribute__((sysv_abi))";
884 OS <<
" __attribute__((regcall))";
891 OS <<
" __attribute__((swiftcall))";
894 OS <<
" __attribute__((preserve_most))";
897 OS <<
" __attribute__((preserve_all))";
903 OS <<
" __attribute__((noreturn))";
905 OS <<
" __attribute__((ns_returns_retained))";
907 OS <<
" __attribute__((regparm (" 910 OS <<
" __attribute__((no_caller_saved_registers))";
912 OS <<
" __attribute__((nocf_check))";
920 if (!PrevPHIsEmpty.get())
927 if (!HasEmptyPlaceHolder)
936 void TypePrinter::printTypeSpec(
NamedDecl *D, raw_ostream &OS) {
941 if (!Policy.SuppressScope)
946 spaceBeforePlaceHolder(OS);
951 printTypeSpec(T->
getDecl(), OS);
957 void TypePrinter::printTypedefBefore(
const TypedefType *T, raw_ostream &OS) {
958 printTypeSpec(T->
getDecl(), OS);
961 void TypePrinter::printTypedefAfter(
const TypedefType *T, raw_ostream &OS) {}
968 spaceBeforePlaceHolder(OS);
974 void TypePrinter::printTypeOfBefore(
const TypeOfType *T, raw_ostream &OS) {
978 spaceBeforePlaceHolder(OS);
981 void TypePrinter::printTypeOfAfter(
const TypeOfType *T, raw_ostream &OS) {}
983 void TypePrinter::printDecltypeBefore(
const DecltypeType *T, raw_ostream &OS) {
988 spaceBeforePlaceHolder(OS);
991 void TypePrinter::printDecltypeAfter(
const DecltypeType *T, raw_ostream &OS) {}
995 IncludeStrongLifetimeRAII Strong(Policy);
999 OS <<
"__underlying_type(";
1002 spaceBeforePlaceHolder(OS);
1011 IncludeStrongLifetimeRAII Strong(Policy);
1021 void TypePrinter::printAutoBefore(
const AutoType *T, raw_ostream &OS) {
1031 spaceBeforePlaceHolder(OS);
1035 void TypePrinter::printAutoAfter(
const AutoType *T, raw_ostream &OS) {
1041 void TypePrinter::printDeducedTemplateSpecializationBefore(
1047 IncludeStrongLifetimeRAII Strong(Policy);
1049 spaceBeforePlaceHolder(OS);
1053 void TypePrinter::printDeducedTemplateSpecializationAfter(
1060 void TypePrinter::printAtomicBefore(
const AtomicType *T, raw_ostream &OS) {
1061 IncludeStrongLifetimeRAII Strong(Policy);
1066 spaceBeforePlaceHolder(OS);
1069 void TypePrinter::printAtomicAfter(
const AtomicType *T, raw_ostream &OS) {}
1071 void TypePrinter::printPipeBefore(
const PipeType *T, raw_ostream &OS) {
1072 IncludeStrongLifetimeRAII Strong(Policy);
1077 OS <<
"write_only ";
1080 spaceBeforePlaceHolder(OS);
1083 void TypePrinter::printPipeAfter(
const PipeType *T, raw_ostream &OS) {}
1086 void TypePrinter::AppendScope(
DeclContext *DC, raw_ostream &OS) {
1091 if (
const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1092 if (Policy.SuppressUnwrittenScope &&
1093 (NS->isAnonymousNamespace() || NS->isInline()))
1095 if (NS->getIdentifier())
1096 OS << NS->getName() <<
"::";
1098 OS <<
"(anonymous namespace)::";
1099 }
else if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1100 IncludeStrongLifetimeRAII Strong(Policy);
1101 OS << Spec->getIdentifier()->getName();
1105 }
else if (
const auto *Tag = dyn_cast<TagDecl>(DC)) {
1107 OS << Typedef->getIdentifier()->getName() <<
"::";
1108 else if (Tag->getIdentifier())
1109 OS << Tag->getIdentifier()->getName() <<
"::";
1115 void TypePrinter::printTag(
TagDecl *D, raw_ostream &OS) {
1116 if (Policy.IncludeTagDefinition) {
1119 D->
print(OS, SubPolicy, Indentation);
1120 spaceBeforePlaceHolder(OS);
1124 bool HasKindDecoration =
false;
1129 HasKindDecoration =
true;
1137 if (!Policy.SuppressScope)
1141 OS << II->getName();
1143 assert(Typedef->getIdentifier() &&
"Typedef without identifier?");
1144 OS << Typedef->getIdentifier()->getName();
1148 OS << (Policy.MSVCFormatting ?
'`' :
'(');
1150 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
1152 HasKindDecoration =
true;
1157 if (Policy.AnonymousTagLocations) {
1161 if (!HasKindDecoration)
1169 if (Policy.RemapFilePaths)
1170 OS << Policy.remapPath(File);
1177 OS << (Policy.MSVCFormatting ?
'\'' :
')');
1182 if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1186 cast<TemplateSpecializationType>(TAW->getType());
1190 Args = TemplateArgs.
asArray();
1192 IncludeStrongLifetimeRAII Strong(Policy);
1196 spaceBeforePlaceHolder(OS);
1199 void TypePrinter::printRecordBefore(
const RecordType *T, raw_ostream &OS) {
1203 void TypePrinter::printRecordAfter(
const RecordType *T, raw_ostream &OS) {}
1205 void TypePrinter::printEnumBefore(
const EnumType *T, raw_ostream &OS) {
1209 void TypePrinter::printEnumAfter(
const EnumType *T, raw_ostream &OS) {}
1214 OS <<
Id->getName();
1217 spaceBeforePlaceHolder(OS);
1223 void TypePrinter::printSubstTemplateTypeParmBefore(
1226 IncludeStrongLifetimeRAII Strong(Policy);
1230 void TypePrinter::printSubstTemplateTypeParmAfter(
1233 IncludeStrongLifetimeRAII Strong(Policy);
1237 void TypePrinter::printSubstTemplateTypeParmPackBefore(
1240 IncludeStrongLifetimeRAII Strong(Policy);
1244 void TypePrinter::printSubstTemplateTypeParmPackAfter(
1247 IncludeStrongLifetimeRAII Strong(Policy);
1251 void TypePrinter::printTemplateSpecializationBefore(
1254 IncludeStrongLifetimeRAII Strong(Policy);
1258 spaceBeforePlaceHolder(OS);
1261 void TypePrinter::printTemplateSpecializationAfter(
1278 "OwnedTagDecl expected to be a declaration for the type");
1281 OwnedTagDecl->
print(OS, SubPolicy, Indentation);
1282 spaceBeforePlaceHolder(OS);
1287 if (!Policy.IncludeTagDefinition)
1294 Qualifier->
print(OS, Policy);
1297 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1305 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1309 void TypePrinter::printParenBefore(
const ParenType *T, raw_ostream &OS) {
1310 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1317 void TypePrinter::printParenAfter(
const ParenType *T, raw_ostream &OS) {
1318 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1334 spaceBeforePlaceHolder(OS);
1340 void TypePrinter::printDependentTemplateSpecializationBefore(
1342 IncludeStrongLifetimeRAII Strong(Policy);
1352 spaceBeforePlaceHolder(OS);
1355 void TypePrinter::printDependentTemplateSpecializationAfter(
1386 case attr::Ptr32: OS <<
" __ptr32";
break;
1387 case attr::Ptr64: OS <<
" __ptr64";
break;
1388 case attr::SPtr: OS <<
" __sptr";
break;
1389 case attr::UPtr: OS <<
" __uptr";
break;
1391 spaceBeforePlaceHolder(OS);
1400 else if (T->
getAttrKind() == attr::TypeNullUnspecified)
1401 OS <<
" _Null_unspecified";
1403 llvm_unreachable(
"unhandled nullability");
1404 spaceBeforePlaceHolder(OS);
1430 if (T->
getAttrKind() == attr::ObjCInertUnsafeUnretained)
1434 if (T->
getAttrKind() == attr::NSReturnsRetained &&
1436 ->getExtInfo().getProducesResult())
1440 OS <<
" [[clang::lifetimebound]]";
1450 OS <<
" __attribute__((";
1452 #define TYPE_ATTR(NAME) 1453 #define DECL_OR_TYPE_ATTR(NAME) 1454 #define ATTR(NAME) case attr::NAME: 1455 #include "clang/Basic/AttrList.inc" 1456 llvm_unreachable(
"non-type attribute attached to type");
1458 case attr::OpenCLPrivateAddressSpace:
1459 case attr::OpenCLGlobalAddressSpace:
1460 case attr::OpenCLLocalAddressSpace:
1461 case attr::OpenCLConstantAddressSpace:
1462 case attr::OpenCLGenericAddressSpace:
1467 case attr::LifetimeBound:
1468 case attr::TypeNonNull:
1469 case attr::TypeNullable:
1470 case attr::TypeNullUnspecified:
1472 case attr::ObjCInertUnsafeUnretained:
1473 case attr::ObjCKindOf:
1474 case attr::ObjCOwnership:
1479 case attr::AddressSpace:
1480 llvm_unreachable(
"This attribute should have been handled already");
1482 case attr::NSReturnsRetained:
1483 OS <<
"ns_returns_retained";
1488 case attr::AnyX86NoCfCheck: OS <<
"nocf_check";
break;
1489 case attr::CDecl: OS <<
"cdecl";
break;
1490 case attr::FastCall: OS <<
"fastcall";
break;
1491 case attr::StdCall: OS <<
"stdcall";
break;
1492 case attr::ThisCall: OS <<
"thiscall";
break;
1493 case attr::SwiftCall: OS <<
"swiftcall";
break;
1494 case attr::VectorCall: OS <<
"vectorcall";
break;
1495 case attr::Pascal: OS <<
"pascal";
break;
1496 case attr::MSABI: OS <<
"ms_abi";
break;
1497 case attr::SysVABI: OS <<
"sysv_abi";
break;
1498 case attr::RegCall: OS <<
"regcall";
break;
1505 "\"aapcs\"" :
"\"aapcs-vfp\"");
1509 case attr::AArch64VectorPcs: OS <<
"aarch64_vector_pcs";
break;
1510 case attr::IntelOclBicc: OS <<
"inteloclbicc";
break;
1511 case attr::PreserveMost:
1512 OS <<
"preserve_most";
1515 case attr::PreserveAll:
1516 OS <<
"preserve_all";
1528 spaceBeforePlaceHolder(OS);
1538 bool isFirst =
true;
1540 for (
const auto *I : T->
quals()) {
1550 spaceBeforePlaceHolder(OS); 1553 void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T, 1556 void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T, 1558 if (T->qual_empty() && T->isUnspecializedAsWritten() && 1559 !T->isKindOfTypeAsWritten()) 1560 return printBefore(T->getBaseType(), OS); 1562 if (T->isKindOfTypeAsWritten()) 1565 print(T->getBaseType(), OS, StringRef()); 1567 if (T->isSpecializedAsWritten()) { 1568 bool isFirst = true; 1570 for (auto typeArg : T->getTypeArgsAsWritten()) { 1576 print(typeArg, OS, StringRef()); 1581 if (!T->qual_empty()) { 1582 bool isFirst = true; 1584 for (const auto *I : T->quals()) { 1594 spaceBeforePlaceHolder(OS); 1597 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T, 1599 if (T->qual_empty() && T->isUnspecializedAsWritten() && 1600 !T->isKindOfTypeAsWritten()) 1601 return printAfter(T->getBaseType(), OS); 1604 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T, 1606 printBefore(T->getPointeeType(), OS); 1608 // If we need to print the pointer, print it now. 1609 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() && 1610 !T->isObjCClassType() && !T->isObjCQualifiedClassType()) { 1611 if (HasEmptyPlaceHolder) 1617 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T, 1621 const TemplateArgument &getArgument(const TemplateArgument &A) { return A; } 1623 static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) { 1624 return A.getArgument(); 1627 template<typename TA> 1628 static void printTo(raw_ostream &OS, ArrayRef<TA> Args, 1629 const PrintingPolicy &Policy, bool SkipBrackets) { 1630 const char *Comma = Policy.MSVCFormatting ? "," : ", "; 1634 bool NeedSpace = false; 1635 bool FirstArg = true; 1636 for (const auto &Arg : Args) { 1637 // Print the argument into a string. 1638 SmallString<128> Buf; 1639 llvm::raw_svector_ostream ArgOS(Buf); 1640 const TemplateArgument &Argument = getArgument(Arg); 1641 if (Argument.getKind() == TemplateArgument::Pack) { 1642 if (Argument.pack_size() && !FirstArg) 1644 printTo(ArgOS, Argument.getPackAsArray(), Policy, true); 1648 Argument.print(Policy, ArgOS); 1650 StringRef ArgString = ArgOS.str(); 1652 // If this is the first argument and its string representation 1653 // begins with the global scope specifier ('::foo
'), add a space 1654 // to avoid printing the diagraph '<:
'. 1655 if (FirstArg && !ArgString.empty() && ArgString[0] == ':
') 1660 NeedSpace = (!ArgString.empty() && ArgString.back() == '>
'); 1664 // If the last character of our string is '>
', add another space to 1665 // keep the two '>
''s separate tokens. We don
't *have* to do this in 1666 // C++0x, but it's still good hygiene.
1674 void clang::printTemplateArgumentList(raw_ostream &OS, 1675 const TemplateArgumentListInfo &Args, 1676 const PrintingPolicy &Policy) { 1677 return printTo(OS, Args.arguments(), Policy, false); 1680 void clang::printTemplateArgumentList(raw_ostream &OS, 1681 ArrayRef<TemplateArgument> Args, 1682 const PrintingPolicy &Policy) { 1683 printTo(OS, Args, Policy, false); 1686 void clang::printTemplateArgumentList(raw_ostream &OS, 1687 ArrayRef<TemplateArgumentLoc> Args, 1688 const PrintingPolicy &Policy) { 1689 printTo(OS, Args, Policy, false); 1692 std::string Qualifiers::getAsString() const { 1694 return getAsString(PrintingPolicy(LO)); 1697 // Appends qualifiers to the given string, separated by spaces. Will 1698 // prefix a space if the string is non-empty. Will not append a final 1700 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const { 1701 SmallString<64> Buf; 1702 llvm::raw_svector_ostream StrOS(Buf); 1703 print(StrOS, Policy); 1707 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const { 1708 if (getCVRQualifiers()) 1711 if (getAddressSpace() != LangAS::Default) 1714 if (getObjCGCAttr()) 1717 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) 1718 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)) 1724 // Appends qualifiers to the given string, separated by spaces. Will 1725 // prefix a space if the string is non-empty. Will not append a final 1727 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy, 1728 bool appendSpaceIfNonEmpty) const { 1729 bool addSpace = false; 1731 unsigned quals = getCVRQualifiers(); 1733 AppendTypeQualList(OS, quals, Policy.Restrict); 1736 if (hasUnaligned()) { 1739 OS << "__unaligned"; 1742 LangAS addrspace = getAddressSpace(); 1743 if (addrspace != LangAS::Default) { 1744 if (addrspace != LangAS::opencl_private) { 1748 switch (addrspace) { 1749 case LangAS::opencl_global: 1752 case LangAS::opencl_local: 1755 case LangAS::opencl_private: 1757 case LangAS::opencl_constant: 1758 case LangAS::cuda_constant: 1761 case LangAS::opencl_generic: 1764 case LangAS::cuda_device: 1767 case LangAS::cuda_shared: 1771 OS << "__attribute__((address_space("; 1772 OS << toTargetAddressSpace(addrspace); 1777 if (Qualifiers::GC gc = getObjCGCAttr()) { 1781 if (gc == Qualifiers::Weak) 1786 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) { 1787 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){ 1794 case Qualifiers::OCL_None: llvm_unreachable("none but true"); 1795 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break; 1796 case Qualifiers::OCL_Strong: 1797 if (!Policy.SuppressStrongLifetime) 1801 case Qualifiers::OCL_Weak: OS << "__weak"; break; 1802 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break; 1806 if (appendSpaceIfNonEmpty && addSpace) 1810 std::string QualType::getAsString() const { 1811 return getAsString(split(), LangOptions()); 1814 std::string QualType::getAsString(const PrintingPolicy &Policy) const { 1816 getAsStringInternal(S, Policy); 1820 std::string QualType::getAsString(const Type *ty, Qualifiers qs, 1821 const PrintingPolicy &Policy) { 1823 getAsStringInternal(ty, qs, buffer, Policy); 1827 void QualType::print(raw_ostream &OS, const PrintingPolicy &Policy, 1828 const Twine &PlaceHolder, unsigned Indentation) const { 1829 print(splitAccordingToPolicy(*this, Policy), OS, Policy, PlaceHolder, 1833 void QualType::print(const Type *ty, Qualifiers qs, 1834 raw_ostream &OS, const PrintingPolicy &policy, 1835 const Twine &PlaceHolder, unsigned Indentation) { 1836 SmallString<128> PHBuf; 1837 StringRef PH = PlaceHolder.toStringRef(PHBuf); 1839 TypePrinter(policy, Indentation).print(ty, qs, OS, PH); 1842 void QualType::getAsStringInternal(std::string &Str, 1843 const PrintingPolicy &Policy) const { 1844 return getAsStringInternal(splitAccordingToPolicy(*this, Policy), Str, 1848 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs, 1849 std::string &buffer, 1850 const PrintingPolicy &policy) { 1851 SmallString<256> Buf; 1852 llvm::raw_svector_ostream StrOS(Buf); 1853 TypePrinter(policy).print(ty, qs, StrOS, buffer); 1854 std::string str = StrOS.str();
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Defines the clang::ASTContext interface.
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
const Type * Ty
The locally-unqualified type.
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool HasRestrictKeyword)
const TemplateSpecializationType * getInjectedTST() const
StringRef getName(const PrintingPolicy &Policy) const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getElementType() const
QualType getPointeeType() const
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
A (possibly-)qualified type.
bool getNoCfCheck() const
__auto_type (GNU extension)
Expr * getUnderlyingExpr() const
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
C Language Family Type Representation.
Defines the SourceManager interface.
Represents a qualified type name for which the type name is dependent.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
const Type * getTypeForDecl() const
bool isVariadic() const
Whether this function prototype is variadic.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
The base class of the type hierarchy.
A container of type source information.
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
QualType getElementType() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
unsigned getNumParams() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents a C++17 deduced template specialization type.
bool isCallingConv() const
Describes how types, statements, expressions, and declarations should be printed. ...
Represents the result of substituting a type for a template type parameter.
The collection of all-type qualifiers we support.
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
One of these records is kept for each identifier that is lexed.
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS=false) const
Print the template name.
unsigned getRegParm() const
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
QualType getPointeeType() const
bool isObjCIdType() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
Represents the result of substituting a set of types for a template type parameter pack...
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
bool isObjCQualifiedClassType() const
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
bool getProducesResult() const
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
An rvalue reference type, per C++11 [dcl.ref].
UnresolvedUsingTypenameDecl * getDecl() const
bool isMSTypeSpec() const
An lvalue ref-qualifier was provided (&).
Microsoft throw(...) extension.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Represents a typeof (or typeof) expression (a GCC extension).
const Type * getClass() const
Expr * getSizeExpr() const
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
is ARM Neon polynomial vector
Qualifiers getTypeQuals() const
Expr * getSizeExpr() const
bool getNoCallerSavedRegs() const
QualType getPointeeTypeAsWritten() const
Expr * getSizeExpr() const
QualType getElementType() const
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
unsigned PrintCanonicalTypes
Whether to print types as written or canonically.
Represents an extended vector type where either the type or size is dependent.
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Expr * getAddrSpaceExpr() const
Provides definitions for the various language-specific address spaces.
llvm::StringRef getParameterABISpelling(ParameterABI kind)
Represents a prototype with parameter type info, e.g.
static SplitQualType splitAccordingToPolicy(QualType QT, const PrintingPolicy &Policy)
ObjCTypeParamDecl * getDecl() const
Represents an array type in C++ whose size is a value-dependent expression.
QualType getElementType() const
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
IdentifierInfo * getIdentifier() const
Defines the clang::LangOptions interface.
StringRef getKindName() const
unsigned getIndex() const
const T * castAs() const
Member-template castAs<specific type>.
unsigned getLine() const
Return the presumed line number of this location.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
bool isObjCClassType() const
DeclContext * getDeclContext()
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Represents the type decltype(expr) (C++11).
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isFunctionOrMethod() const
Qualifiers Quals
The local qualifiers.
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Represents an unpacked "presumed" location which can be presented to the user.
Represents a GCC generic vector type.
ArraySizeModifier getSizeModifier() const
An lvalue reference type, per C++11 [dcl.ref].
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Expr * getUnderlyingExpr() const
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
bool hasQualifiers() const
Return true if the set contains any qualifiers.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
RecordDecl * getDecl() const
const char * getFilename() const
Return the presumed filename of this location.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
is AltiVec 'vector Pixel'
QualType getCanonicalType() const
not a target-specific vector type
ExtParameterInfo getExtParameterInfo(unsigned I) const
ElaboratedTypeKeyword getKeyword() const
unsigned getColumn() const
Return the presumed column number of this location.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Sugar for parentheses used when specifying types.
QualType getAdjustedType() const
QualType getReturnType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Represents typeof(type), a GCC extension.
Interfaces are the core concept in Objective-C for object oriented design.
unsigned SuppressScope
Suppresses printing of scope specifiers.
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
CallingConv getCC() const
QualType getElementType() const
Represents a vector type where either the type or size is dependent.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
No ref-qualifier was provided.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
QualType getEquivalentType() const
QualType getInnerType() const
is AltiVec 'vector bool ...'
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
AutoTypeKeyword getKeyword() const
Qualifiers getIndexTypeQualifiers() const
TypeClass getTypeClass() const
ArrayRef< TemplateArgument > template_arguments() const
EnumDecl * getDecl() const
An rvalue ref-qualifier was provided (&&).
ParameterABI
Kinds of parameter ABI.
std::string getAsString() const
Represents a pointer type decayed from an array or function type.
The injected class name of a C++ class template or class template partial specialization.
QualType getPointeeType() const
Represents a pack expansion of types.
Defines various enumerations that describe declaration and type specifiers.
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Dataflow Directional Tag Classes.
ExtInfo getExtInfo() const
NestedNameSpecifier * getQualifier() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
VectorKind getVectorKind() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A pointer to member type per C++ 8.3.3 - Pointers to members.
QualType getModifiedType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
unsigned getIndexTypeCVRQualifiers() const
const llvm::APInt & getSize() const
bool isFunctionType() const
bool isObjCQualifiedIdType() const
ExtVectorType - Extended vector type.
Base for LValueReferenceType and RValueReferenceType.
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
QualType getUnderlyingType() const
SourceManager & getSourceManager()
A template argument list.
VectorType::VectorKind getVectorKind() const
TypedefNameDecl * getDecl() const
unsigned getDepth() const
An attributed type is a type to which a type attribute has been applied.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getParamType(unsigned i) const
Represents a type parameter type in Objective C.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
Defines the clang::SourceLocation class and associated facilities.
TypedefNameDecl * getTypedefNameForAnonDecl() const
Represents a template specialization type whose template cannot be resolved, e.g. ...
ArrayRef< TemplateArgument > template_arguments() const
Represents a C array with an unspecified size.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getNamedType() const
Retrieve the type named by the qualified-id.
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
This class is used for builtin types like 'int'.
static QualType skipTopLevelReferences(QualType T)
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
unsigned getNumElements() const
Represents an extended address space qualifier where the input address space value is dependent...
Represents a type template specialization; the template must be a class template, a type alias templa...
This represents a decl that may have a name.
bool isTranslationUnit() const
Represents a C array with a specified size that is not an integer-constant-expression.
No keyword precedes the qualified type name.
QualType getElementType() const
llvm::Optional< NullabilityKind > getImmediateNullability() const
Represents the canonical version of C arrays with a specified constant size.
A class which abstracts out some details necessary for making a call.
SourceLocation getLocation() const
QualType getPointeeType() const
This parameter (which must have pointer type) is a Swift indirect result parameter.
const IdentifierInfo * getIdentifier() const
Expr * getSizeExpr() const