23 #include "llvm/ADT/SmallString.h" 24 #include "llvm/ADT/StringExtras.h" 25 #include "llvm/Support/SaveAndRestore.h" 26 #include "llvm/Support/raw_ostream.h" 27 using namespace clang;
32 class IncludeStrongLifetimeRAII {
38 : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
43 ~IncludeStrongLifetimeRAII() {
48 class ParamPolicyRAII {
54 : Policy(Policy), Old(Policy.SuppressSpecifiers) {
63 class ElaboratedTypePolicyRAII {
65 bool SuppressTagKeyword;
69 explicit ElaboratedTypePolicyRAII(
PrintingPolicy &Policy) : Policy(Policy) {
76 ~ElaboratedTypePolicyRAII() {
85 bool HasEmptyPlaceHolder;
86 bool InsideCCAttribute;
89 explicit TypePrinter(
const PrintingPolicy &Policy,
unsigned Indentation = 0)
90 : Policy(Policy), Indentation(Indentation),
91 HasEmptyPlaceHolder(
false), InsideCCAttribute(
false) { }
94 StringRef PlaceHolder);
95 void print(
QualType T, raw_ostream &OS, StringRef PlaceHolder);
97 static bool canPrefixQualifiers(
const Type *
T,
bool &NeedARCStrongQualifier);
98 void spaceBeforePlaceHolder(raw_ostream &OS);
99 void printTypeSpec(
NamedDecl *D, raw_ostream &OS);
102 void printBefore(
QualType T, raw_ostream &OS);
104 void printAfter(
QualType T, raw_ostream &OS);
105 void AppendScope(
DeclContext *DC, raw_ostream &OS);
106 void printTag(
TagDecl *
T, raw_ostream &OS);
108 #define ABSTRACT_TYPE(CLASS, PARENT) 109 #define TYPE(CLASS, PARENT) \ 110 void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \ 111 void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS); 112 #include "clang/AST/TypeNodes.def" 117 bool HasRestrictKeyword) {
118 bool appendSpace =
false;
124 if (appendSpace) OS <<
' ';
129 if (appendSpace) OS <<
' ';
130 if (HasRestrictKeyword) {
138 void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
139 if (!HasEmptyPlaceHolder)
143 void TypePrinter::print(
QualType t, raw_ostream &OS, StringRef PlaceHolder) {
145 print(split.
Ty, split.
Quals, OS, PlaceHolder);
148 void TypePrinter::print(
const Type *
T,
Qualifiers Quals, raw_ostream &OS,
149 StringRef PlaceHolder) {
157 printBefore(T, Quals, OS);
159 printAfter(T, Quals, OS);
162 bool TypePrinter::canPrefixQualifiers(
const Type *T,
163 bool &NeedARCStrongQualifier) {
169 bool CanPrefixQualifiers =
false;
170 NeedARCStrongQualifier =
false;
172 if (
const AutoType *AT = dyn_cast<AutoType>(T))
173 TC = AT->desugar()->getTypeClass();
175 = dyn_cast<SubstTemplateTypeParmType>(T))
176 TC = Subst->getReplacementType()->getTypeClass();
182 case Type::UnresolvedUsing:
184 case Type::TypeOfExpr:
187 case Type::UnaryTransform:
190 case Type::Elaborated:
191 case Type::TemplateTypeParm:
192 case Type::SubstTemplateTypeParmPack:
193 case Type::DeducedTemplateSpecialization:
194 case Type::TemplateSpecialization:
195 case Type::InjectedClassName:
196 case Type::DependentName:
197 case Type::DependentTemplateSpecialization:
198 case Type::ObjCObject:
199 case Type::ObjCTypeParam:
200 case Type::ObjCInterface:
203 CanPrefixQualifiers =
true;
206 case Type::ObjCObjectPointer:
211 case Type::ConstantArray:
212 case Type::IncompleteArray:
213 case Type::VariableArray:
214 case Type::DependentSizedArray:
215 NeedARCStrongQualifier =
true;
221 case Type::BlockPointer:
222 case Type::LValueReference:
223 case Type::RValueReference:
224 case Type::MemberPointer:
225 case Type::DependentAddressSpace:
226 case Type::DependentSizedExtVector:
228 case Type::ExtVector:
229 case Type::FunctionProto:
230 case Type::FunctionNoProto:
232 case Type::Attributed:
233 case Type::PackExpansion:
234 case Type::SubstTemplateTypeParm:
235 CanPrefixQualifiers =
false;
239 return CanPrefixQualifiers;
242 void TypePrinter::printBefore(
QualType T, raw_ostream &OS) {
249 dyn_cast<SubstTemplateTypeParmType>(Split.
Ty))
252 printBefore(Split.
Ty, Quals, OS);
257 void TypePrinter::printBefore(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
265 bool CanPrefixQualifiers =
false;
266 bool NeedARCStrongQualifier =
false;
267 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
269 if (CanPrefixQualifiers && !Quals.
empty()) {
270 if (NeedARCStrongQualifier) {
271 IncludeStrongLifetimeRAII Strong(Policy);
272 Quals.
print(OS, Policy,
true);
274 Quals.
print(OS, Policy,
true);
278 bool hasAfterQuals =
false;
279 if (!CanPrefixQualifiers && !Quals.
empty()) {
282 HasEmptyPlaceHolder =
false;
286 #define ABSTRACT_TYPE(CLASS, PARENT) 287 #define TYPE(CLASS, PARENT) case Type::CLASS: \ 288 print##CLASS##Before(cast<CLASS##Type>(T), OS); \ 290 #include "clang/AST/TypeNodes.def" 294 if (NeedARCStrongQualifier) {
295 IncludeStrongLifetimeRAII Strong(Policy);
296 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
298 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
303 void TypePrinter::printAfter(
QualType t, raw_ostream &OS) {
305 printAfter(split.
Ty, split.
Quals, OS);
310 void TypePrinter::printAfter(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
312 #define ABSTRACT_TYPE(CLASS, PARENT) 313 #define TYPE(CLASS, PARENT) case Type::CLASS: \ 314 print##CLASS##After(cast<CLASS##Type>(T), OS); \ 316 #include "clang/AST/TypeNodes.def" 320 void TypePrinter::printBuiltinBefore(
const BuiltinType *T, raw_ostream &OS) {
322 spaceBeforePlaceHolder(OS);
324 void TypePrinter::printBuiltinAfter(
const BuiltinType *T, raw_ostream &OS) { }
326 void TypePrinter::printComplexBefore(
const ComplexType *T, raw_ostream &OS) {
330 void TypePrinter::printComplexAfter(
const ComplexType *T, raw_ostream &OS) {
334 void TypePrinter::printPointerBefore(
const PointerType *T, raw_ostream &OS) {
335 IncludeStrongLifetimeRAII Strong(Policy);
344 void TypePrinter::printPointerAfter(
const PointerType *T, raw_ostream &OS) {
345 IncludeStrongLifetimeRAII Strong(Policy);
368 IncludeStrongLifetimeRAII Strong(Policy);
379 IncludeStrongLifetimeRAII Strong(Policy);
390 IncludeStrongLifetimeRAII Strong(Policy);
401 IncludeStrongLifetimeRAII Strong(Policy);
412 IncludeStrongLifetimeRAII Strong(Policy);
422 TypePrinter(InnerPolicy).print(
QualType(T->
getClass(), 0), OS, StringRef());
428 IncludeStrongLifetimeRAII Strong(Policy);
439 IncludeStrongLifetimeRAII Strong(Policy);
455 OS << T->
getSize().getZExtValue() <<
']';
461 IncludeStrongLifetimeRAII Strong(Policy);
473 IncludeStrongLifetimeRAII Strong(Policy);
497 void TypePrinter::printAdjustedBefore(
const AdjustedType *T, raw_ostream &OS) {
502 void TypePrinter::printAdjustedAfter(
const AdjustedType *T, raw_ostream &OS) {
506 void TypePrinter::printDecayedBefore(
const DecayedType *T, raw_ostream &OS) {
508 printAdjustedBefore(T, OS);
510 void TypePrinter::printDecayedAfter(
const DecayedType *T, raw_ostream &OS) {
511 printAdjustedAfter(T, OS);
514 void TypePrinter::printDependentSizedArrayBefore(
517 IncludeStrongLifetimeRAII Strong(Policy);
521 void TypePrinter::printDependentSizedArrayAfter(
531 void TypePrinter::printDependentAddressSpaceBefore(
535 void TypePrinter::printDependentAddressSpaceAfter(
537 OS <<
" __attribute__((address_space(";
544 void TypePrinter::printDependentSizedExtVectorBefore(
549 void TypePrinter::printDependentSizedExtVectorAfter(
552 OS <<
" __attribute__((ext_vector_type(";
559 void TypePrinter::printVectorBefore(
const VectorType *T, raw_ostream &OS) {
562 OS <<
"__vector __pixel ";
565 OS <<
"__vector __bool ";
573 OS <<
"__attribute__((neon_vector_type(" 578 OS <<
"__attribute__((neon_polyvector_type(" <<
585 OS <<
"__attribute__((__vector_size__(" 595 void TypePrinter::printVectorAfter(
const VectorType *T, raw_ostream &OS) {
599 void TypePrinter::printExtVectorBefore(
const ExtVectorType *T,
603 void TypePrinter::printExtVectorAfter(
const ExtVectorType *T, raw_ostream &OS) {
605 OS <<
" __attribute__((ext_vector_type(";
615 if (hasDynamicExceptionSpec()) {
620 for (
unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
624 OS << getExceptionType(I).stream(Policy);
631 if (getNoexceptExpr())
632 getNoexceptExpr()->printPretty(OS,
nullptr, Policy);
642 if (!HasEmptyPlaceHolder)
648 if (!PrevPHIsEmpty.get())
656 llvm_unreachable(
"asking for spelling of ordinary parameter ABI");
658 return "swift_context";
660 return "swift_error_result";
662 return "swift_indirect_result";
664 llvm_unreachable(
"bad parameter ABI kind");
670 if (!HasEmptyPlaceHolder)
676 ParamPolicyRAII ParamPolicy(Policy);
677 for (
unsigned i = 0, e = T->
getNumParams(); i != e; ++i) {
681 if (EPI.isConsumed()) OS <<
"__attribute__((ns_consumed)) ";
682 if (EPI.isNoEscape())
683 OS <<
"__attribute__((noescape)) ";
696 }
else if (T->
getNumParams() == 0 && Policy.UseVoidForZeroParams) {
705 printFunctionAfter(Info, OS);
735 if (!InsideCCAttribute) {
736 switch (Info.
getCC()) {
747 OS <<
" __attribute__((stdcall))";
750 OS <<
" __attribute__((fastcall))";
753 OS <<
" __attribute__((thiscall))";
756 OS <<
" __attribute__((vectorcall))";
759 OS <<
" __attribute__((pascal))";
762 OS <<
" __attribute__((pcs(\"aapcs\")))";
765 OS <<
" __attribute__((pcs(\"aapcs-vfp\")))";
768 OS <<
" __attribute__((intel_ocl_bicc))";
771 OS <<
" __attribute__((ms_abi))";
774 OS <<
" __attribute__((sysv_abi))";
777 OS <<
" __attribute__((regcall))";
784 OS <<
" __attribute__((swiftcall))";
787 OS <<
" __attribute__((preserve_most))";
790 OS <<
" __attribute__((preserve_all))";
796 OS <<
" __attribute__((noreturn))";
798 OS <<
" __attribute__((ns_returns_retained))";
800 OS <<
" __attribute__((regparm (" 803 OS <<
" __attribute__((no_caller_saved_registers))";
811 if (!PrevPHIsEmpty.get())
817 if (!HasEmptyPlaceHolder)
826 void TypePrinter::printTypeSpec(
NamedDecl *D, raw_ostream &OS) {
831 if (!Policy.SuppressScope)
836 spaceBeforePlaceHolder(OS);
841 printTypeSpec(T->
getDecl(), OS);
846 void TypePrinter::printTypedefBefore(
const TypedefType *T, raw_ostream &OS) {
847 printTypeSpec(T->
getDecl(), OS);
849 void TypePrinter::printTypedefAfter(
const TypedefType *T, raw_ostream &OS) { }
856 spaceBeforePlaceHolder(OS);
861 void TypePrinter::printTypeOfBefore(
const TypeOfType *T, raw_ostream &OS) {
865 spaceBeforePlaceHolder(OS);
867 void TypePrinter::printTypeOfAfter(
const TypeOfType *T, raw_ostream &OS) { }
869 void TypePrinter::printDecltypeBefore(
const DecltypeType *T, raw_ostream &OS) {
874 spaceBeforePlaceHolder(OS);
876 void TypePrinter::printDecltypeAfter(
const DecltypeType *T, raw_ostream &OS) { }
880 IncludeStrongLifetimeRAII Strong(Policy);
884 OS <<
"__underlying_type(";
887 spaceBeforePlaceHolder(OS);
895 IncludeStrongLifetimeRAII Strong(Policy);
905 void TypePrinter::printAutoBefore(
const AutoType *T, raw_ostream &OS) {
915 spaceBeforePlaceHolder(OS);
918 void TypePrinter::printAutoAfter(
const AutoType *T, raw_ostream &OS) {
924 void TypePrinter::printDeducedTemplateSpecializationBefore(
930 IncludeStrongLifetimeRAII Strong(Policy);
932 spaceBeforePlaceHolder(OS);
935 void TypePrinter::printDeducedTemplateSpecializationAfter(
942 void TypePrinter::printAtomicBefore(
const AtomicType *T, raw_ostream &OS) {
943 IncludeStrongLifetimeRAII Strong(Policy);
948 spaceBeforePlaceHolder(OS);
950 void TypePrinter::printAtomicAfter(
const AtomicType *T, raw_ostream &OS) { }
952 void TypePrinter::printPipeBefore(
const PipeType *T, raw_ostream &OS) {
953 IncludeStrongLifetimeRAII Strong(Policy);
961 spaceBeforePlaceHolder(OS);
964 void TypePrinter::printPipeAfter(
const PipeType *T, raw_ostream &OS) {
967 void TypePrinter::AppendScope(
DeclContext *DC, raw_ostream &OS) {
973 if (Policy.SuppressUnwrittenScope &&
974 (NS->isAnonymousNamespace() || NS->isInline()))
976 if (NS->getIdentifier())
977 OS << NS->getName() <<
"::";
979 OS <<
"(anonymous namespace)::";
981 = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
982 IncludeStrongLifetimeRAII Strong(Policy);
983 OS << Spec->getIdentifier()->getName();
987 }
else if (
TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
989 OS << Typedef->getIdentifier()->getName() <<
"::";
990 else if (Tag->getIdentifier())
991 OS << Tag->getIdentifier()->getName() <<
"::";
997 void TypePrinter::printTag(
TagDecl *D, raw_ostream &OS) {
998 if (Policy.IncludeTagDefinition) {
1001 D->
print(OS, SubPolicy, Indentation);
1002 spaceBeforePlaceHolder(OS);
1006 bool HasKindDecoration =
false;
1011 HasKindDecoration =
true;
1019 if (!Policy.SuppressScope)
1023 OS << II->getName();
1025 assert(Typedef->getIdentifier() &&
"Typedef without identifier?");
1026 OS << Typedef->getIdentifier()->getName();
1030 OS << (Policy.MSVCFormatting ?
'`' :
'(');
1032 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
1034 HasKindDecoration =
true;
1039 if (Policy.AnonymousTagLocations) {
1043 if (!HasKindDecoration)
1055 OS << (Policy.MSVCFormatting ?
'\'' :
')');
1061 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1065 cast<TemplateSpecializationType>(TAW->getType());
1069 Args = TemplateArgs.
asArray();
1071 IncludeStrongLifetimeRAII Strong(Policy);
1075 spaceBeforePlaceHolder(OS);
1078 void TypePrinter::printRecordBefore(
const RecordType *T, raw_ostream &OS) {
1081 void TypePrinter::printRecordAfter(
const RecordType *T, raw_ostream &OS) { }
1083 void TypePrinter::printEnumBefore(
const EnumType *T, raw_ostream &OS) {
1086 void TypePrinter::printEnumAfter(
const EnumType *T, raw_ostream &OS) { }
1091 OS <<
Id->getName();
1094 spaceBeforePlaceHolder(OS);
1097 raw_ostream &OS) { }
1099 void TypePrinter::printSubstTemplateTypeParmBefore(
1102 IncludeStrongLifetimeRAII Strong(Policy);
1105 void TypePrinter::printSubstTemplateTypeParmAfter(
1108 IncludeStrongLifetimeRAII Strong(Policy);
1112 void TypePrinter::printSubstTemplateTypeParmPackBefore(
1115 IncludeStrongLifetimeRAII Strong(Policy);
1118 void TypePrinter::printSubstTemplateTypeParmPackAfter(
1121 IncludeStrongLifetimeRAII Strong(Policy);
1125 void TypePrinter::printTemplateSpecializationBefore(
1128 IncludeStrongLifetimeRAII Strong(Policy);
1132 spaceBeforePlaceHolder(OS);
1134 void TypePrinter::printTemplateSpecializationAfter(
1136 raw_ostream &OS) { }
1143 raw_ostream &OS) { }
1148 if (!Policy.IncludeTagDefinition)
1155 Qualifier->
print(OS, Policy);
1158 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1163 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1167 void TypePrinter::printParenBefore(
const ParenType *T, raw_ostream &OS) {
1168 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1174 void TypePrinter::printParenAfter(
const ParenType *T, raw_ostream &OS) {
1175 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1191 spaceBeforePlaceHolder(OS);
1194 raw_ostream &OS) { }
1196 void TypePrinter::printDependentTemplateSpecializationBefore(
1198 IncludeStrongLifetimeRAII Strong(Policy);
1208 spaceBeforePlaceHolder(OS);
1211 void TypePrinter::printDependentTemplateSpecializationAfter(
1244 spaceBeforePlaceHolder(OS);
1256 OS <<
" _Null_unspecified";
1258 llvm_unreachable(
"unhandled nullability");
1259 spaceBeforePlaceHolder(OS);
1296 ->getExtInfo().getProducesResult())
1308 OS <<
" _Null_unspecified";
1310 llvm_unreachable(
"unhandled nullability");
1315 OS <<
" __attribute__((";
1317 default: llvm_unreachable(
"This attribute should have been handled already");
1319 OS <<
"address_space(";
1327 OS <<
"__vector_size__(";
1329 OS << vector->getNumElements();
1331 print(vector->getElementType(), OS, StringRef());
1341 OS <<
"neon_vector_type(";
1343 OS <<
"neon_polyvector_type(";
1368 if (next == tmp)
break;
1381 OS <<
"objc_ownership(";
1393 OS <<
"ns_returns_retained";
1417 "\"aapcs\"" :
"\"aapcs-vfp\"");
1423 OS <<
"preserve_most";
1426 OS <<
"preserve_all";
1435 spaceBeforePlaceHolder(OS);
1438 raw_ostream &OS) { }
1444 bool isFirst =
true;
1446 for (
const auto *I : T->
quals()) {
1456 spaceBeforePlaceHolder(OS); 1459 void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T, 1460 raw_ostream &OS) { } 1462 void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T, 1464 if (T->qual_empty() && T->isUnspecializedAsWritten() && 1465 !T->isKindOfTypeAsWritten()) 1466 return printBefore(T->getBaseType(), OS); 1468 if (T->isKindOfTypeAsWritten()) 1471 print(T->getBaseType(), OS, StringRef()); 1473 if (T->isSpecializedAsWritten()) { 1474 bool isFirst = true; 1476 for (auto typeArg : T->getTypeArgsAsWritten()) { 1482 print(typeArg, OS, StringRef()); 1487 if (!T->qual_empty()) { 1488 bool isFirst = true; 1490 for (const auto *I : T->quals()) { 1500 spaceBeforePlaceHolder(OS); 1502 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T, 1504 if (T->qual_empty() && T->isUnspecializedAsWritten() && 1505 !T->isKindOfTypeAsWritten()) 1506 return printAfter(T->getBaseType(), OS); 1509 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T, 1511 printBefore(T->getPointeeType(), OS); 1513 // If we need to print the pointer, print it now. 1514 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() && 1515 !T->isObjCClassType() && !T->isObjCQualifiedClassType()) { 1516 if (HasEmptyPlaceHolder) 1522 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T, 1523 raw_ostream &OS) { } 1526 const TemplateArgument &getArgument(const TemplateArgument &A) { return A; } 1528 static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) { 1529 return A.getArgument(); 1532 template<typename TA> 1533 static void printTo(raw_ostream &OS, ArrayRef<TA> Args, 1534 const PrintingPolicy &Policy, bool SkipBrackets) { 1535 const char *Comma = Policy.MSVCFormatting ? "," : ", "; 1539 bool NeedSpace = false; 1540 bool FirstArg = true; 1541 for (const auto &Arg : Args) { 1542 // Print the argument into a string. 1543 SmallString<128> Buf; 1544 llvm::raw_svector_ostream ArgOS(Buf); 1545 const TemplateArgument &Argument = getArgument(Arg); 1546 if (Argument.getKind() == TemplateArgument::Pack) { 1547 if (Argument.pack_size() && !FirstArg) 1549 printTo(ArgOS, Argument.getPackAsArray(), Policy, true); 1553 Argument.print(Policy, ArgOS); 1555 StringRef ArgString = ArgOS.str(); 1557 // If this is the first argument and its string representation 1558 // begins with the global scope specifier ('::foo
'), add a space 1559 // to avoid printing the diagraph '<:
'. 1560 if (FirstArg && !ArgString.empty() && ArgString[0] == ':
') 1565 NeedSpace = (!ArgString.empty() && ArgString.back() == '>
'); 1569 // If the last character of our string is '>
', add another space to 1570 // keep the two '>
''s separate tokens. We don
't *have* to do this in 1571 // C++0x, but it's still good hygiene.
1579 void clang::printTemplateArgumentList(raw_ostream &OS, 1580 const TemplateArgumentListInfo &Args, 1581 const PrintingPolicy &Policy) { 1582 return printTo(OS, Args.arguments(), Policy, false); 1585 void clang::printTemplateArgumentList(raw_ostream &OS, 1586 ArrayRef<TemplateArgument> Args, 1587 const PrintingPolicy &Policy) { 1588 printTo(OS, Args, Policy, false); 1591 void clang::printTemplateArgumentList(raw_ostream &OS, 1592 ArrayRef<TemplateArgumentLoc> Args, 1593 const PrintingPolicy &Policy) { 1594 printTo(OS, Args, Policy, false); 1597 std::string Qualifiers::getAsString() const { 1599 return getAsString(PrintingPolicy(LO)); 1602 // Appends qualifiers to the given string, separated by spaces. Will 1603 // prefix a space if the string is non-empty. Will not append a final 1605 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const { 1606 SmallString<64> Buf; 1607 llvm::raw_svector_ostream StrOS(Buf); 1608 print(StrOS, Policy); 1612 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const { 1613 if (getCVRQualifiers()) 1616 if (getAddressSpace() != LangAS::Default) 1619 if (getObjCGCAttr()) 1622 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) 1623 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)) 1629 // Appends qualifiers to the given string, separated by spaces. Will 1630 // prefix a space if the string is non-empty. Will not append a final 1632 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy, 1633 bool appendSpaceIfNonEmpty) const { 1634 bool addSpace = false; 1636 unsigned quals = getCVRQualifiers(); 1638 AppendTypeQualList(OS, quals, Policy.Restrict); 1641 if (hasUnaligned()) { 1644 OS << "__unaligned"; 1647 LangAS addrspace = getAddressSpace(); 1648 if (addrspace != LangAS::Default) { 1649 if (addrspace != LangAS::opencl_private) { 1653 switch (addrspace) { 1654 case LangAS::opencl_global: 1657 case LangAS::opencl_local: 1660 case LangAS::opencl_private: 1662 case LangAS::opencl_constant: 1663 case LangAS::cuda_constant: 1666 case LangAS::opencl_generic: 1669 case LangAS::cuda_device: 1672 case LangAS::cuda_shared: 1676 OS << "__attribute__((address_space("; 1677 OS << toTargetAddressSpace(addrspace); 1682 if (Qualifiers::GC gc = getObjCGCAttr()) { 1686 if (gc == Qualifiers::Weak) 1691 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) { 1692 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){ 1699 case Qualifiers::OCL_None: llvm_unreachable("none but true"); 1700 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break; 1701 case Qualifiers::OCL_Strong: 1702 if (!Policy.SuppressStrongLifetime) 1706 case Qualifiers::OCL_Weak: OS << "__weak"; break; 1707 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break; 1711 if (appendSpaceIfNonEmpty && addSpace) 1715 std::string QualType::getAsString() const { 1716 return getAsString(split(), LangOptions()); 1719 std::string QualType::getAsString(const PrintingPolicy &Policy) const { 1721 getAsStringInternal(S, Policy); 1725 std::string QualType::getAsString(const Type *ty, Qualifiers qs, 1726 const PrintingPolicy &Policy) { 1728 getAsStringInternal(ty, qs, buffer, Policy); 1732 void QualType::print(const Type *ty, Qualifiers qs, 1733 raw_ostream &OS, const PrintingPolicy &policy, 1734 const Twine &PlaceHolder, unsigned Indentation) { 1735 SmallString<128> PHBuf; 1736 StringRef PH = PlaceHolder.toStringRef(PHBuf); 1738 TypePrinter(policy, Indentation).print(ty, qs, OS, PH); 1741 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs, 1742 std::string &buffer, 1743 const PrintingPolicy &policy) { 1744 SmallString<256> Buf; 1745 llvm::raw_svector_ostream StrOS(Buf); 1746 TypePrinter(policy).print(ty, qs, StrOS, buffer); 1747 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.
__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.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
The base class of the type hierarchy.
NamespaceDecl - Represent a C++ namespace.
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
getIdentifier - Get the identifier that names this declaration, if there is one.
Represents a class template specialization, which refers to a class template with a given set of temp...
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.
Represents the result of substituting a set of types for a template type parameter pack...
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.
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
is ARM Neon polynomial vector
Expr * getSizeExpr() const
bool getNoCallerSavedRegs() const
QualType getPointeeTypeAsWritten() 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.
This object can be modified without requiring retains or releases.
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Expr * getAddrSpaceExpr() const
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
const FunctionProtoType * T
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.
Qualifiers::GC getObjCGCAttr() const
Returns gc attribute of this type.
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...
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.
There is no lifetime qualification on this type.
is AltiVec 'vector Pixel'
Assigning into this object requires the old value to be released and the new value to be retained...
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...
TagDecl - Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
CallingConv getCC() const
QualType getElementType() const
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 (&&).
Assigning into this object requires a lifetime extension.
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.
StringRef getName() const
Return the actual identifier string.
bool isObjCGCWeak() const
true when Type is objc's weak.
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.
llvm::StringRef getParameterABISpelling(ParameterABI kind)
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
QualType getUnderlyingType() const
SourceManager & getSourceManager()
A template argument list.
TypedefNameDecl * getDecl() const
Reading or writing from this object requires a barrier call.
unsigned getDepth() const
An attributed type is a type to which a type attribute has been applied.
QualType getParamType(unsigned i) const
Represents a type parameter type in Objective C.
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'.
StringRef getName() const
getName - 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...
NamedDecl - This represents a decl with 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.
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
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.