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);
121 void printBefore(
QualType T, raw_ostream &OS);
123 void printAfter(
QualType T, raw_ostream &OS);
124 void AppendScope(
DeclContext *DC, raw_ostream &OS);
125 void printTag(
TagDecl *T, raw_ostream &OS);
127 #define ABSTRACT_TYPE(CLASS, PARENT) 128 #define TYPE(CLASS, PARENT) \ 129 void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \ 130 void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS); 131 #include "clang/AST/TypeNodes.def" 137 bool HasRestrictKeyword) {
138 bool appendSpace =
false;
144 if (appendSpace) OS <<
' ';
149 if (appendSpace) OS <<
' ';
150 if (HasRestrictKeyword) {
158 void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
159 if (!HasEmptyPlaceHolder)
163 void TypePrinter::print(
QualType t, raw_ostream &OS, StringRef PlaceHolder) {
165 print(split.
Ty, split.
Quals, OS, PlaceHolder);
168 void TypePrinter::print(
const Type *T,
Qualifiers Quals, raw_ostream &OS,
169 StringRef PlaceHolder) {
177 printBefore(T, Quals, OS);
179 printAfter(T, Quals, OS);
182 bool TypePrinter::canPrefixQualifiers(
const Type *T,
183 bool &NeedARCStrongQualifier) {
189 bool CanPrefixQualifiers =
false;
190 NeedARCStrongQualifier =
false;
192 if (
const auto *AT = dyn_cast<AutoType>(T))
193 TC = AT->desugar()->getTypeClass();
194 if (
const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))
195 TC = Subst->getReplacementType()->getTypeClass();
201 case Type::UnresolvedUsing:
203 case Type::TypeOfExpr:
206 case Type::UnaryTransform:
209 case Type::Elaborated:
210 case Type::TemplateTypeParm:
211 case Type::SubstTemplateTypeParmPack:
212 case Type::DeducedTemplateSpecialization:
213 case Type::TemplateSpecialization:
214 case Type::InjectedClassName:
215 case Type::DependentName:
216 case Type::DependentTemplateSpecialization:
217 case Type::ObjCObject:
218 case Type::ObjCTypeParam:
219 case Type::ObjCInterface:
222 CanPrefixQualifiers =
true;
225 case Type::ObjCObjectPointer:
230 case Type::ConstantArray:
231 case Type::IncompleteArray:
232 case Type::VariableArray:
233 case Type::DependentSizedArray:
234 NeedARCStrongQualifier =
true;
240 case Type::BlockPointer:
241 case Type::LValueReference:
242 case Type::RValueReference:
243 case Type::MemberPointer:
244 case Type::DependentAddressSpace:
245 case Type::DependentVector:
246 case Type::DependentSizedExtVector:
248 case Type::ExtVector:
249 case Type::FunctionProto:
250 case Type::FunctionNoProto:
252 case Type::Attributed:
253 case Type::PackExpansion:
254 case Type::SubstTemplateTypeParm:
255 CanPrefixQualifiers =
false;
259 return CanPrefixQualifiers;
262 void TypePrinter::printBefore(
QualType T, raw_ostream &OS) {
268 if (
const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(Split.
Ty))
271 printBefore(Split.
Ty, Quals, OS);
276 void TypePrinter::printBefore(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
284 bool CanPrefixQualifiers =
false;
285 bool NeedARCStrongQualifier =
false;
286 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
288 if (CanPrefixQualifiers && !Quals.
empty()) {
289 if (NeedARCStrongQualifier) {
290 IncludeStrongLifetimeRAII Strong(Policy);
291 Quals.
print(OS, Policy,
true);
293 Quals.
print(OS, Policy,
true);
297 bool hasAfterQuals =
false;
298 if (!CanPrefixQualifiers && !Quals.
empty()) {
301 HasEmptyPlaceHolder =
false;
305 #define ABSTRACT_TYPE(CLASS, PARENT) 306 #define TYPE(CLASS, PARENT) case Type::CLASS: \ 307 print##CLASS##Before(cast<CLASS##Type>(T), OS); \ 309 #include "clang/AST/TypeNodes.def" 313 if (NeedARCStrongQualifier) {
314 IncludeStrongLifetimeRAII Strong(Policy);
315 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
317 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
322 void TypePrinter::printAfter(
QualType t, raw_ostream &OS) {
324 printAfter(split.
Ty, split.
Quals, OS);
329 void TypePrinter::printAfter(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
331 #define ABSTRACT_TYPE(CLASS, PARENT) 332 #define TYPE(CLASS, PARENT) case Type::CLASS: \ 333 print##CLASS##After(cast<CLASS##Type>(T), OS); \ 335 #include "clang/AST/TypeNodes.def" 339 void TypePrinter::printBuiltinBefore(
const BuiltinType *T, raw_ostream &OS) {
341 spaceBeforePlaceHolder(OS);
344 void TypePrinter::printBuiltinAfter(
const BuiltinType *T, raw_ostream &OS) {}
346 void TypePrinter::printComplexBefore(
const ComplexType *T, raw_ostream &OS) {
351 void TypePrinter::printComplexAfter(
const ComplexType *T, raw_ostream &OS) {
355 void TypePrinter::printPointerBefore(
const PointerType *T, raw_ostream &OS) {
356 IncludeStrongLifetimeRAII Strong(Policy);
366 void TypePrinter::printPointerAfter(
const PointerType *T, raw_ostream &OS) {
367 IncludeStrongLifetimeRAII Strong(Policy);
399 IncludeStrongLifetimeRAII Strong(Policy);
402 printBefore(Inner, OS);
405 if (isa<ArrayType>(Inner))
412 IncludeStrongLifetimeRAII Strong(Policy);
417 if (isa<ArrayType>(Inner))
419 printAfter(Inner, OS);
424 IncludeStrongLifetimeRAII Strong(Policy);
427 printBefore(Inner, OS);
430 if (isa<ArrayType>(Inner))
437 IncludeStrongLifetimeRAII Strong(Policy);
442 if (isa<ArrayType>(Inner))
444 printAfter(Inner, OS);
449 IncludeStrongLifetimeRAII Strong(Policy);
459 TypePrinter(InnerPolicy).print(
QualType(T->
getClass(), 0), OS, StringRef());
466 IncludeStrongLifetimeRAII Strong(Policy);
477 IncludeStrongLifetimeRAII Strong(Policy);
494 OS << T->
getSize().getZExtValue() <<
']';
500 IncludeStrongLifetimeRAII Strong(Policy);
513 IncludeStrongLifetimeRAII Strong(Policy);
538 void TypePrinter::printAdjustedBefore(
const AdjustedType *T, raw_ostream &OS) {
544 void TypePrinter::printAdjustedAfter(
const AdjustedType *T, raw_ostream &OS) {
548 void TypePrinter::printDecayedBefore(
const DecayedType *T, raw_ostream &OS) {
550 printAdjustedBefore(T, OS);
553 void TypePrinter::printDecayedAfter(
const DecayedType *T, raw_ostream &OS) {
554 printAdjustedAfter(T, OS);
557 void TypePrinter::printDependentSizedArrayBefore(
560 IncludeStrongLifetimeRAII Strong(Policy);
565 void TypePrinter::printDependentSizedArrayAfter(
575 void TypePrinter::printDependentAddressSpaceBefore(
580 void TypePrinter::printDependentAddressSpaceAfter(
582 OS <<
" __attribute__((address_space(";
589 void TypePrinter::printDependentSizedExtVectorBefore(
595 void TypePrinter::printDependentSizedExtVectorAfter(
598 OS <<
" __attribute__((ext_vector_type(";
605 void TypePrinter::printVectorBefore(
const VectorType *T, raw_ostream &OS) {
608 OS <<
"__vector __pixel ";
611 OS <<
"__vector __bool ";
619 OS <<
"__attribute__((neon_vector_type(" 624 OS <<
"__attribute__((neon_polyvector_type(" <<
631 OS <<
"__attribute__((__vector_size__(" 642 void TypePrinter::printVectorAfter(
const VectorType *T, raw_ostream &OS) {
646 void TypePrinter::printDependentVectorBefore(
650 OS <<
"__vector __pixel ";
653 OS <<
"__vector __bool ";
661 OS <<
"__attribute__((neon_vector_type(";
668 OS <<
"__attribute__((neon_polyvector_type(";
677 OS <<
"__attribute__((__vector_size__(";
689 void TypePrinter::printDependentVectorAfter(
694 void TypePrinter::printExtVectorBefore(
const ExtVectorType *T,
699 void TypePrinter::printExtVectorAfter(
const ExtVectorType *T, raw_ostream &OS) {
701 OS <<
" __attribute__((ext_vector_type(";
710 if (hasDynamicExceptionSpec()) {
715 for (
unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
719 OS << getExceptionType(I).stream(Policy);
728 if (getNoexceptExpr())
729 getNoexceptExpr()->printPretty(OS,
nullptr, Policy);
739 if (!HasEmptyPlaceHolder)
745 if (!PrevPHIsEmpty.get())
753 llvm_unreachable(
"asking for spelling of ordinary parameter ABI");
755 return "swift_context";
757 return "swift_error_result";
759 return "swift_indirect_result";
761 llvm_unreachable(
"bad parameter ABI kind");
767 if (!HasEmptyPlaceHolder)
773 ParamPolicyRAII ParamPolicy(Policy);
774 for (
unsigned i = 0, e = T->
getNumParams(); i != e; ++i) {
778 if (EPI.isConsumed()) OS <<
"__attribute__((ns_consumed)) ";
779 if (EPI.isNoEscape())
780 OS <<
"__attribute__((noescape)) ";
793 }
else if (T->
getNumParams() == 0 && Policy.UseVoidForZeroParams) {
802 printFunctionAfter(Info, OS);
832 if (!InsideCCAttribute) {
833 switch (Info.
getCC()) {
844 OS <<
" __attribute__((stdcall))";
847 OS <<
" __attribute__((fastcall))";
850 OS <<
" __attribute__((thiscall))";
853 OS <<
" __attribute__((vectorcall))";
856 OS <<
" __attribute__((pascal))";
859 OS <<
" __attribute__((pcs(\"aapcs\")))";
862 OS <<
" __attribute__((pcs(\"aapcs-vfp\")))";
865 OS <<
" __attribute__((intel_ocl_bicc))";
868 OS <<
" __attribute__((ms_abi))";
871 OS <<
" __attribute__((sysv_abi))";
874 OS <<
" __attribute__((regcall))";
881 OS <<
" __attribute__((swiftcall))";
884 OS <<
" __attribute__((preserve_most))";
887 OS <<
" __attribute__((preserve_all))";
893 OS <<
" __attribute__((noreturn))";
895 OS <<
" __attribute__((ns_returns_retained))";
897 OS <<
" __attribute__((regparm (" 900 OS <<
" __attribute__((no_caller_saved_registers))";
902 OS <<
" __attribute__((nocf_check))";
910 if (!PrevPHIsEmpty.get())
917 if (!HasEmptyPlaceHolder)
926 void TypePrinter::printTypeSpec(
NamedDecl *D, raw_ostream &OS) {
931 if (!Policy.SuppressScope)
936 spaceBeforePlaceHolder(OS);
941 printTypeSpec(T->
getDecl(), OS);
947 void TypePrinter::printTypedefBefore(
const TypedefType *T, raw_ostream &OS) {
948 printTypeSpec(T->
getDecl(), OS);
951 void TypePrinter::printTypedefAfter(
const TypedefType *T, raw_ostream &OS) {}
958 spaceBeforePlaceHolder(OS);
964 void TypePrinter::printTypeOfBefore(
const TypeOfType *T, raw_ostream &OS) {
968 spaceBeforePlaceHolder(OS);
971 void TypePrinter::printTypeOfAfter(
const TypeOfType *T, raw_ostream &OS) {}
973 void TypePrinter::printDecltypeBefore(
const DecltypeType *T, raw_ostream &OS) {
978 spaceBeforePlaceHolder(OS);
981 void TypePrinter::printDecltypeAfter(
const DecltypeType *T, raw_ostream &OS) {}
985 IncludeStrongLifetimeRAII Strong(Policy);
989 OS <<
"__underlying_type(";
992 spaceBeforePlaceHolder(OS);
1001 IncludeStrongLifetimeRAII Strong(Policy);
1011 void TypePrinter::printAutoBefore(
const AutoType *T, raw_ostream &OS) {
1021 spaceBeforePlaceHolder(OS);
1025 void TypePrinter::printAutoAfter(
const AutoType *T, raw_ostream &OS) {
1031 void TypePrinter::printDeducedTemplateSpecializationBefore(
1037 IncludeStrongLifetimeRAII Strong(Policy);
1039 spaceBeforePlaceHolder(OS);
1043 void TypePrinter::printDeducedTemplateSpecializationAfter(
1050 void TypePrinter::printAtomicBefore(
const AtomicType *T, raw_ostream &OS) {
1051 IncludeStrongLifetimeRAII Strong(Policy);
1056 spaceBeforePlaceHolder(OS);
1059 void TypePrinter::printAtomicAfter(
const AtomicType *T, raw_ostream &OS) {}
1061 void TypePrinter::printPipeBefore(
const PipeType *T, raw_ostream &OS) {
1062 IncludeStrongLifetimeRAII Strong(Policy);
1067 OS <<
"write_only ";
1070 spaceBeforePlaceHolder(OS);
1073 void TypePrinter::printPipeAfter(
const PipeType *T, raw_ostream &OS) {}
1076 void TypePrinter::AppendScope(
DeclContext *DC, raw_ostream &OS) {
1081 if (
const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1082 if (Policy.SuppressUnwrittenScope &&
1083 (NS->isAnonymousNamespace() || NS->isInline()))
1085 if (NS->getIdentifier())
1086 OS << NS->getName() <<
"::";
1088 OS <<
"(anonymous namespace)::";
1089 }
else if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1090 IncludeStrongLifetimeRAII Strong(Policy);
1091 OS << Spec->getIdentifier()->getName();
1095 }
else if (
const auto *Tag = dyn_cast<TagDecl>(DC)) {
1097 OS << Typedef->getIdentifier()->getName() <<
"::";
1098 else if (Tag->getIdentifier())
1099 OS << Tag->getIdentifier()->getName() <<
"::";
1105 void TypePrinter::printTag(
TagDecl *D, raw_ostream &OS) {
1106 if (Policy.IncludeTagDefinition) {
1109 D->
print(OS, SubPolicy, Indentation);
1110 spaceBeforePlaceHolder(OS);
1114 bool HasKindDecoration =
false;
1119 HasKindDecoration =
true;
1127 if (!Policy.SuppressScope)
1131 OS << II->getName();
1133 assert(Typedef->getIdentifier() &&
"Typedef without identifier?");
1134 OS << Typedef->getIdentifier()->getName();
1138 OS << (Policy.MSVCFormatting ?
'`' :
'(');
1140 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
1142 HasKindDecoration =
true;
1147 if (Policy.AnonymousTagLocations) {
1151 if (!HasKindDecoration)
1163 OS << (Policy.MSVCFormatting ?
'\'' :
')');
1168 if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1172 cast<TemplateSpecializationType>(TAW->getType());
1176 Args = TemplateArgs.
asArray();
1178 IncludeStrongLifetimeRAII Strong(Policy);
1182 spaceBeforePlaceHolder(OS);
1185 void TypePrinter::printRecordBefore(
const RecordType *T, raw_ostream &OS) {
1189 void TypePrinter::printRecordAfter(
const RecordType *T, raw_ostream &OS) {}
1191 void TypePrinter::printEnumBefore(
const EnumType *T, raw_ostream &OS) {
1195 void TypePrinter::printEnumAfter(
const EnumType *T, raw_ostream &OS) {}
1200 OS <<
Id->getName();
1203 spaceBeforePlaceHolder(OS);
1209 void TypePrinter::printSubstTemplateTypeParmBefore(
1212 IncludeStrongLifetimeRAII Strong(Policy);
1216 void TypePrinter::printSubstTemplateTypeParmAfter(
1219 IncludeStrongLifetimeRAII Strong(Policy);
1223 void TypePrinter::printSubstTemplateTypeParmPackBefore(
1226 IncludeStrongLifetimeRAII Strong(Policy);
1230 void TypePrinter::printSubstTemplateTypeParmPackAfter(
1233 IncludeStrongLifetimeRAII Strong(Policy);
1237 void TypePrinter::printTemplateSpecializationBefore(
1240 IncludeStrongLifetimeRAII Strong(Policy);
1244 spaceBeforePlaceHolder(OS);
1247 void TypePrinter::printTemplateSpecializationAfter(
1264 "OwnedTagDecl expected to be a declaration for the type");
1267 OwnedTagDecl->
print(OS, SubPolicy, Indentation);
1268 spaceBeforePlaceHolder(OS);
1273 if (!Policy.IncludeTagDefinition)
1280 Qualifier->
print(OS, Policy);
1283 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1291 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1295 void TypePrinter::printParenBefore(
const ParenType *T, raw_ostream &OS) {
1296 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1303 void TypePrinter::printParenAfter(
const ParenType *T, raw_ostream &OS) {
1304 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1320 spaceBeforePlaceHolder(OS);
1326 void TypePrinter::printDependentTemplateSpecializationBefore(
1328 IncludeStrongLifetimeRAII Strong(Policy);
1338 spaceBeforePlaceHolder(OS);
1341 void TypePrinter::printDependentTemplateSpecializationAfter(
1375 spaceBeforePlaceHolder(OS);
1387 OS <<
" _Null_unspecified";
1389 llvm_unreachable(
"unhandled nullability");
1390 spaceBeforePlaceHolder(OS);
1427 ->getExtInfo().getProducesResult())
1439 OS <<
" _Null_unspecified";
1441 llvm_unreachable(
"unhandled nullability");
1447 OS <<
" [[clang::lifetimebound]]";
1451 OS <<
" __attribute__((";
1465 llvm_unreachable(
"This attribute should have been handled already");
1468 OS <<
"address_space(";
1476 OS <<
"__vector_size__(";
1478 OS << vector->getNumElements();
1480 print(vector->getElementType(), OS, StringRef());
1489 OS <<
"neon_vector_type(";
1491 OS <<
"neon_polyvector_type(";
1511 OS <<
"ns_returns_retained";
1535 "\"aapcs\"" :
"\"aapcs-vfp\"");
1542 OS <<
"preserve_most";
1546 OS <<
"preserve_all";
1555 spaceBeforePlaceHolder(OS);
1565 bool isFirst =
true;
1567 for (
const auto *I : T->
quals()) {
1577 spaceBeforePlaceHolder(OS); 1580 void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T, 1583 void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T, 1585 if (T->qual_empty() && T->isUnspecializedAsWritten() && 1586 !T->isKindOfTypeAsWritten()) 1587 return printBefore(T->getBaseType(), OS); 1589 if (T->isKindOfTypeAsWritten()) 1592 print(T->getBaseType(), OS, StringRef()); 1594 if (T->isSpecializedAsWritten()) { 1595 bool isFirst = true; 1597 for (auto typeArg : T->getTypeArgsAsWritten()) { 1603 print(typeArg, OS, StringRef()); 1608 if (!T->qual_empty()) { 1609 bool isFirst = true; 1611 for (const auto *I : T->quals()) { 1621 spaceBeforePlaceHolder(OS); 1624 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T, 1626 if (T->qual_empty() && T->isUnspecializedAsWritten() && 1627 !T->isKindOfTypeAsWritten()) 1628 return printAfter(T->getBaseType(), OS); 1631 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T, 1633 printBefore(T->getPointeeType(), OS); 1635 // If we need to print the pointer, print it now. 1636 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() && 1637 !T->isObjCClassType() && !T->isObjCQualifiedClassType()) { 1638 if (HasEmptyPlaceHolder) 1644 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T, 1648 const TemplateArgument &getArgument(const TemplateArgument &A) { return A; } 1650 static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) { 1651 return A.getArgument(); 1654 template<typename TA> 1655 static void printTo(raw_ostream &OS, ArrayRef<TA> Args, 1656 const PrintingPolicy &Policy, bool SkipBrackets) { 1657 const char *Comma = Policy.MSVCFormatting ? "," : ", "; 1661 bool NeedSpace = false; 1662 bool FirstArg = true; 1663 for (const auto &Arg : Args) { 1664 // Print the argument into a string. 1665 SmallString<128> Buf; 1666 llvm::raw_svector_ostream ArgOS(Buf); 1667 const TemplateArgument &Argument = getArgument(Arg); 1668 if (Argument.getKind() == TemplateArgument::Pack) { 1669 if (Argument.pack_size() && !FirstArg) 1671 printTo(ArgOS, Argument.getPackAsArray(), Policy, true); 1675 Argument.print(Policy, ArgOS); 1677 StringRef ArgString = ArgOS.str(); 1679 // If this is the first argument and its string representation 1680 // begins with the global scope specifier ('::foo
'), add a space 1681 // to avoid printing the diagraph '<:
'. 1682 if (FirstArg && !ArgString.empty() && ArgString[0] == ':
') 1687 NeedSpace = (!ArgString.empty() && ArgString.back() == '>
'); 1691 // If the last character of our string is '>
', add another space to 1692 // keep the two '>
''s separate tokens. We don
't *have* to do this in 1693 // C++0x, but it's still good hygiene.
1701 void clang::printTemplateArgumentList(raw_ostream &OS, 1702 const TemplateArgumentListInfo &Args, 1703 const PrintingPolicy &Policy) { 1704 return printTo(OS, Args.arguments(), Policy, false); 1707 void clang::printTemplateArgumentList(raw_ostream &OS, 1708 ArrayRef<TemplateArgument> Args, 1709 const PrintingPolicy &Policy) { 1710 printTo(OS, Args, Policy, false); 1713 void clang::printTemplateArgumentList(raw_ostream &OS, 1714 ArrayRef<TemplateArgumentLoc> Args, 1715 const PrintingPolicy &Policy) { 1716 printTo(OS, Args, Policy, false); 1719 std::string Qualifiers::getAsString() const { 1721 return getAsString(PrintingPolicy(LO)); 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 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const { 1728 SmallString<64> Buf; 1729 llvm::raw_svector_ostream StrOS(Buf); 1730 print(StrOS, Policy); 1734 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const { 1735 if (getCVRQualifiers()) 1738 if (getAddressSpace() != LangAS::Default) 1741 if (getObjCGCAttr()) 1744 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) 1745 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)) 1751 // Appends qualifiers to the given string, separated by spaces. Will 1752 // prefix a space if the string is non-empty. Will not append a final 1754 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy, 1755 bool appendSpaceIfNonEmpty) const { 1756 bool addSpace = false; 1758 unsigned quals = getCVRQualifiers(); 1760 AppendTypeQualList(OS, quals, Policy.Restrict); 1763 if (hasUnaligned()) { 1766 OS << "__unaligned"; 1769 LangAS addrspace = getAddressSpace(); 1770 if (addrspace != LangAS::Default) { 1771 if (addrspace != LangAS::opencl_private) { 1775 switch (addrspace) { 1776 case LangAS::opencl_global: 1779 case LangAS::opencl_local: 1782 case LangAS::opencl_private: 1784 case LangAS::opencl_constant: 1785 case LangAS::cuda_constant: 1788 case LangAS::opencl_generic: 1791 case LangAS::cuda_device: 1794 case LangAS::cuda_shared: 1798 OS << "__attribute__((address_space("; 1799 OS << toTargetAddressSpace(addrspace); 1804 if (Qualifiers::GC gc = getObjCGCAttr()) { 1808 if (gc == Qualifiers::Weak) 1813 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) { 1814 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){ 1821 case Qualifiers::OCL_None: llvm_unreachable("none but true"); 1822 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break; 1823 case Qualifiers::OCL_Strong: 1824 if (!Policy.SuppressStrongLifetime) 1828 case Qualifiers::OCL_Weak: OS << "__weak"; break; 1829 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break; 1833 if (appendSpaceIfNonEmpty && addSpace) 1837 std::string QualType::getAsString() const { 1838 return getAsString(split(), LangOptions()); 1841 std::string QualType::getAsString(const PrintingPolicy &Policy) const { 1843 getAsStringInternal(S, Policy); 1847 std::string QualType::getAsString(const Type *ty, Qualifiers qs, 1848 const PrintingPolicy &Policy) { 1850 getAsStringInternal(ty, qs, buffer, Policy); 1854 void QualType::print(const Type *ty, Qualifiers qs, 1855 raw_ostream &OS, const PrintingPolicy &policy, 1856 const Twine &PlaceHolder, unsigned Indentation) { 1857 SmallString<128> PHBuf; 1858 StringRef PH = PlaceHolder.toStringRef(PHBuf); 1860 TypePrinter(policy, Indentation).print(ty, qs, OS, PH); 1863 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs, 1864 std::string &buffer, 1865 const PrintingPolicy &policy) { 1866 SmallString<256> Buf; 1867 llvm::raw_svector_ostream StrOS(Buf); 1868 TypePrinter(policy).print(ty, qs, StrOS, buffer); 1869 std::string str = StrOS.str();
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
ParameterABI getABI() const
Return the ABI treatment of this parameter.
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
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 none...
bool isObjCQualifiedClassType() const
unsigned getTypeQuals() 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).
bool SuppressScope
Suppresses printing of scope specifiers.
const Type * getClass() const
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, const ASTContext *Context=nullptr) const
Expr * getSizeExpr() const
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
is ARM Neon polynomial vector
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...
Represents an extended vector type where either the type or size is dependent.
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.
ObjCTypeParamDecl * getDecl() const
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
Represents an array type in C++ whose size is a value-dependent expression.
QualType getElementType() const
IdentifierInfo * getIdentifier() const
Defines the clang::LangOptions interface.
StringRef getKindName() const
unsigned getIndex() const
bool IncludeTagDefinition
When true, include the body of a tag definition.
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].
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Expr * getUnderlyingExpr() const
bool hasTrailingReturn() const
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'
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...
LangAS getAddressSpace() const
Return the address space of this type.
Represents typeof(type), a GCC extension.
Interfaces are the core concept in Objective-C for object oriented design.
bool SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
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 ...'
bool SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
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.
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.
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
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