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) {
59 Policy.SuppressSpecifiers = Old;
63 class ElaboratedTypePolicyRAII {
65 bool SuppressTagKeyword;
69 explicit ElaboratedTypePolicyRAII(
PrintingPolicy &Policy) : Policy(Policy) {
76 ~ElaboratedTypePolicyRAII() {
77 Policy.SuppressTagKeyword = SuppressTagKeyword;
78 Policy.SuppressScope = SuppressScope;
84 bool HasEmptyPlaceHolder;
85 bool InsideCCAttribute;
89 : Policy(Policy), HasEmptyPlaceHolder(
false), InsideCCAttribute(
false) { }
92 StringRef PlaceHolder);
93 void print(
QualType T, raw_ostream &OS, StringRef PlaceHolder);
95 static bool canPrefixQualifiers(
const Type *T,
bool &NeedARCStrongQualifier);
96 void spaceBeforePlaceHolder(raw_ostream &OS);
97 void printTypeSpec(
const NamedDecl *D, raw_ostream &OS);
100 void printBefore(
QualType T, raw_ostream &OS);
102 void printAfter(
QualType T, raw_ostream &OS);
103 void AppendScope(
DeclContext *DC, raw_ostream &OS);
104 void printTag(
TagDecl *T, raw_ostream &OS);
105 #define ABSTRACT_TYPE(CLASS, PARENT)
106 #define TYPE(CLASS, PARENT) \
107 void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
108 void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
109 #include "clang/AST/TypeNodes.def"
114 bool appendSpace =
false;
120 if (appendSpace) OS <<
' ';
125 if (appendSpace) OS <<
' ';
134 void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
135 if (!HasEmptyPlaceHolder)
139 void TypePrinter::print(
QualType t, raw_ostream &OS, StringRef PlaceHolder) {
141 print(split.
Ty, split.
Quals, OS, PlaceHolder);
144 void TypePrinter::print(
const Type *T,
Qualifiers Quals, raw_ostream &OS,
145 StringRef PlaceHolder) {
153 printBefore(T, Quals, OS);
155 printAfter(T, Quals, OS);
158 bool TypePrinter::canPrefixQualifiers(
const Type *T,
159 bool &NeedARCStrongQualifier) {
165 bool CanPrefixQualifiers =
false;
166 NeedARCStrongQualifier =
false;
168 if (
const AutoType *AT = dyn_cast<AutoType>(T))
169 TC = AT->desugar()->getTypeClass();
171 = dyn_cast<SubstTemplateTypeParmType>(T))
172 TC = Subst->getReplacementType()->getTypeClass();
178 case Type::UnresolvedUsing:
180 case Type::TypeOfExpr:
183 case Type::UnaryTransform:
186 case Type::Elaborated:
187 case Type::TemplateTypeParm:
188 case Type::SubstTemplateTypeParmPack:
189 case Type::TemplateSpecialization:
190 case Type::InjectedClassName:
191 case Type::DependentName:
192 case Type::DependentTemplateSpecialization:
193 case Type::ObjCObject:
194 case Type::ObjCInterface:
197 CanPrefixQualifiers =
true;
200 case Type::ObjCObjectPointer:
205 case Type::ConstantArray:
206 case Type::IncompleteArray:
207 case Type::VariableArray:
208 case Type::DependentSizedArray:
209 NeedARCStrongQualifier =
true;
215 case Type::BlockPointer:
216 case Type::LValueReference:
217 case Type::RValueReference:
218 case Type::MemberPointer:
219 case Type::DependentSizedExtVector:
221 case Type::ExtVector:
222 case Type::FunctionProto:
223 case Type::FunctionNoProto:
225 case Type::Attributed:
226 case Type::PackExpansion:
227 case Type::SubstTemplateTypeParm:
228 CanPrefixQualifiers =
false;
232 return CanPrefixQualifiers;
235 void TypePrinter::printBefore(
QualType T, raw_ostream &OS) {
242 dyn_cast<SubstTemplateTypeParmType>(Split.
Ty))
245 printBefore(Split.
Ty, Quals, OS);
250 void TypePrinter::printBefore(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
258 bool CanPrefixQualifiers =
false;
259 bool NeedARCStrongQualifier =
false;
260 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
262 if (CanPrefixQualifiers && !Quals.
empty()) {
263 if (NeedARCStrongQualifier) {
264 IncludeStrongLifetimeRAII Strong(Policy);
265 Quals.
print(OS, Policy,
true);
267 Quals.
print(OS, Policy,
true);
271 bool hasAfterQuals =
false;
272 if (!CanPrefixQualifiers && !Quals.
empty()) {
275 HasEmptyPlaceHolder =
false;
279 #define ABSTRACT_TYPE(CLASS, PARENT)
280 #define TYPE(CLASS, PARENT) case Type::CLASS: \
281 print##CLASS##Before(cast<CLASS##Type>(T), OS); \
283 #include "clang/AST/TypeNodes.def"
287 if (NeedARCStrongQualifier) {
288 IncludeStrongLifetimeRAII Strong(Policy);
289 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
291 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
296 void TypePrinter::printAfter(
QualType t, raw_ostream &OS) {
298 printAfter(split.
Ty, split.
Quals, OS);
303 void TypePrinter::printAfter(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
305 #define ABSTRACT_TYPE(CLASS, PARENT)
306 #define TYPE(CLASS, PARENT) case Type::CLASS: \
307 print##CLASS##After(cast<CLASS##Type>(T), OS); \
309 #include "clang/AST/TypeNodes.def"
313 void TypePrinter::printBuiltinBefore(
const BuiltinType *T, raw_ostream &OS) {
315 spaceBeforePlaceHolder(OS);
317 void TypePrinter::printBuiltinAfter(
const BuiltinType *T, raw_ostream &OS) { }
319 void TypePrinter::printComplexBefore(
const ComplexType *T, raw_ostream &OS) {
323 void TypePrinter::printComplexAfter(
const ComplexType *T, raw_ostream &OS) {
327 void TypePrinter::printPointerBefore(
const PointerType *T, raw_ostream &OS) {
328 IncludeStrongLifetimeRAII Strong(Policy);
337 void TypePrinter::printPointerAfter(
const PointerType *T, raw_ostream &OS) {
338 IncludeStrongLifetimeRAII Strong(Policy);
361 IncludeStrongLifetimeRAII Strong(Policy);
372 IncludeStrongLifetimeRAII Strong(Policy);
383 IncludeStrongLifetimeRAII Strong(Policy);
394 IncludeStrongLifetimeRAII Strong(Policy);
405 IncludeStrongLifetimeRAII Strong(Policy);
414 InnerPolicy.SuppressTag =
false;
415 TypePrinter(InnerPolicy).print(
QualType(T->
getClass(), 0), OS, StringRef());
421 IncludeStrongLifetimeRAII Strong(Policy);
432 IncludeStrongLifetimeRAII Strong(Policy);
447 OS << T->
getSize().getZExtValue() <<
']';
453 IncludeStrongLifetimeRAII Strong(Policy);
465 IncludeStrongLifetimeRAII Strong(Policy);
483 T->
getSizeExpr()->printPretty(OS,
nullptr, Policy);
489 void TypePrinter::printAdjustedBefore(
const AdjustedType *T, raw_ostream &OS) {
494 void TypePrinter::printAdjustedAfter(
const AdjustedType *T, raw_ostream &OS) {
498 void TypePrinter::printDecayedBefore(
const DecayedType *T, raw_ostream &OS) {
500 printAdjustedBefore(T, OS);
502 void TypePrinter::printDecayedAfter(
const DecayedType *T, raw_ostream &OS) {
503 printAdjustedAfter(T, OS);
506 void TypePrinter::printDependentSizedArrayBefore(
509 IncludeStrongLifetimeRAII Strong(Policy);
513 void TypePrinter::printDependentSizedArrayAfter(
518 T->
getSizeExpr()->printPretty(OS,
nullptr, Policy);
523 void TypePrinter::printDependentSizedExtVectorBefore(
528 void TypePrinter::printDependentSizedExtVectorAfter(
531 OS <<
" __attribute__((ext_vector_type(";
533 T->
getSizeExpr()->printPretty(OS,
nullptr, Policy);
538 void TypePrinter::printVectorBefore(
const VectorType *T, raw_ostream &OS) {
541 OS <<
"__vector __pixel ";
544 OS <<
"__vector __bool ";
552 OS <<
"__attribute__((neon_vector_type("
557 OS <<
"__attribute__((neon_polyvector_type(" <<
564 OS <<
"__attribute__((__vector_size__("
574 void TypePrinter::printVectorAfter(
const VectorType *T, raw_ostream &OS) {
578 void TypePrinter::printExtVectorBefore(
const ExtVectorType *T,
582 void TypePrinter::printExtVectorAfter(
const ExtVectorType *T, raw_ostream &OS) {
584 OS <<
" __attribute__((ext_vector_type(";
621 if (!HasEmptyPlaceHolder)
627 if (!PrevPHIsEmpty.get())
635 if (!HasEmptyPlaceHolder)
641 ParamPolicyRAII ParamPolicy(Policy);
642 for (
unsigned i = 0, e = T->
getNumParams(); i != e; ++i) {
652 }
else if (T->
getNumParams() == 0 && !Policy.LangOpts.CPlusPlus) {
661 if (!InsideCCAttribute) {
662 switch (Info.
getCC()) {
673 OS <<
" __attribute__((stdcall))";
676 OS <<
" __attribute__((fastcall))";
679 OS <<
" __attribute__((thiscall))";
682 OS <<
" __attribute__((vectorcall))";
685 OS <<
" __attribute__((pascal))";
688 OS <<
" __attribute__((pcs(\"aapcs\")))";
691 OS <<
" __attribute__((pcs(\"aapcs-vfp\")))";
694 OS <<
" __attribute__((intel_ocl_bicc))";
697 OS <<
" __attribute__((ms_abi))";
700 OS <<
" __attribute__((sysv_abi))";
710 OS <<
" __attribute__((noreturn))";
712 OS <<
" __attribute__((regparm ("
746 if (!PrevPHIsEmpty.get())
752 if (!HasEmptyPlaceHolder)
758 OS <<
" __attribute__((noreturn))";
762 void TypePrinter::printTypeSpec(
const NamedDecl *D, raw_ostream &OS) {
765 spaceBeforePlaceHolder(OS);
770 printTypeSpec(T->
getDecl(), OS);
775 void TypePrinter::printTypedefBefore(
const TypedefType *T, raw_ostream &OS) {
776 printTypeSpec(T->
getDecl(), OS);
778 void TypePrinter::printTypedefAfter(
const TypedefType *T, raw_ostream &OS) { }
785 spaceBeforePlaceHolder(OS);
790 void TypePrinter::printTypeOfBefore(
const TypeOfType *T, raw_ostream &OS) {
794 spaceBeforePlaceHolder(OS);
796 void TypePrinter::printTypeOfAfter(
const TypeOfType *T, raw_ostream &OS) { }
798 void TypePrinter::printDecltypeBefore(
const DecltypeType *T, raw_ostream &OS) {
803 spaceBeforePlaceHolder(OS);
805 void TypePrinter::printDecltypeAfter(
const DecltypeType *T, raw_ostream &OS) { }
809 IncludeStrongLifetimeRAII Strong(Policy);
813 OS <<
"__underlying_type(";
816 spaceBeforePlaceHolder(OS);
824 IncludeStrongLifetimeRAII Strong(Policy);
834 void TypePrinter::printAutoBefore(
const AutoType *T, raw_ostream &OS) {
844 spaceBeforePlaceHolder(OS);
847 void TypePrinter::printAutoAfter(
const AutoType *T, raw_ostream &OS) {
853 void TypePrinter::printAtomicBefore(
const AtomicType *T, raw_ostream &OS) {
854 IncludeStrongLifetimeRAII Strong(Policy);
859 spaceBeforePlaceHolder(OS);
861 void TypePrinter::printAtomicAfter(
const AtomicType *T, raw_ostream &OS) { }
863 void TypePrinter::printPipeBefore(
const PipeType *T, raw_ostream &OS) {
864 IncludeStrongLifetimeRAII Strong(Policy);
867 spaceBeforePlaceHolder(OS);
870 void TypePrinter::printPipeAfter(
const PipeType *T, raw_ostream &OS) {
873 void TypePrinter::AppendScope(
DeclContext *DC, raw_ostream &OS) {
879 if (Policy.SuppressUnwrittenScope &&
880 (NS->isAnonymousNamespace() || NS->isInline()))
882 if (NS->getIdentifier())
883 OS << NS->getName() <<
"::";
885 OS <<
"(anonymous namespace)::";
887 = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
888 IncludeStrongLifetimeRAII Strong(Policy);
889 OS << Spec->getIdentifier()->getName();
896 }
else if (
TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
898 OS << Typedef->getIdentifier()->getName() <<
"::";
899 else if (Tag->getIdentifier())
900 OS << Tag->getIdentifier()->getName() <<
"::";
906 void TypePrinter::printTag(
TagDecl *D, raw_ostream &OS) {
907 if (Policy.SuppressTag)
910 bool HasKindDecoration =
false;
917 if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword ||
919 HasKindDecoration =
true;
927 if (!Policy.SuppressScope)
933 assert(Typedef->getIdentifier() &&
"Typedef without identifier?");
934 OS << Typedef->getIdentifier()->getName();
938 OS << (Policy.MSVCFormatting ?
'`' :
'(');
940 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
942 HasKindDecoration =
true;
947 if (Policy.AnonymousTagLocations) {
951 if (!HasKindDecoration)
963 OS << (Policy.MSVCFormatting ?
'\'' :
')');
969 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
974 cast<TemplateSpecializationType>(TAW->getType());
975 Args = TST->getArgs();
976 NumArgs = TST->getNumArgs();
979 Args = TemplateArgs.
data();
980 NumArgs = TemplateArgs.
size();
982 IncludeStrongLifetimeRAII Strong(Policy);
988 spaceBeforePlaceHolder(OS);
991 void TypePrinter::printRecordBefore(
const RecordType *T, raw_ostream &OS) {
994 void TypePrinter::printRecordAfter(
const RecordType *T, raw_ostream &OS) { }
996 void TypePrinter::printEnumBefore(
const EnumType *T, raw_ostream &OS) {
999 void TypePrinter::printEnumAfter(
const EnumType *T, raw_ostream &OS) { }
1004 OS << Id->getName();
1007 spaceBeforePlaceHolder(OS);
1010 raw_ostream &OS) { }
1012 void TypePrinter::printSubstTemplateTypeParmBefore(
1015 IncludeStrongLifetimeRAII Strong(Policy);
1018 void TypePrinter::printSubstTemplateTypeParmAfter(
1021 IncludeStrongLifetimeRAII Strong(Policy);
1025 void TypePrinter::printSubstTemplateTypeParmPackBefore(
1028 IncludeStrongLifetimeRAII Strong(Policy);
1031 void TypePrinter::printSubstTemplateTypeParmPackAfter(
1034 IncludeStrongLifetimeRAII Strong(Policy);
1038 void TypePrinter::printTemplateSpecializationBefore(
1041 IncludeStrongLifetimeRAII Strong(Policy);
1042 T->getTemplateName().print(OS, Policy);
1048 spaceBeforePlaceHolder(OS);
1050 void TypePrinter::printTemplateSpecializationAfter(
1052 raw_ostream &OS) { }
1059 raw_ostream &OS) { }
1063 if (Policy.SuppressTag && isa<TagType>(T->
getNamedType()))
1070 Qualifier->
print(OS, Policy);
1072 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1077 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1081 void TypePrinter::printParenBefore(
const ParenType *T, raw_ostream &OS) {
1082 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1088 void TypePrinter::printParenAfter(
const ParenType *T, raw_ostream &OS) {
1089 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1105 spaceBeforePlaceHolder(OS);
1108 raw_ostream &OS) { }
1110 void TypePrinter::printDependentTemplateSpecializationBefore(
1112 IncludeStrongLifetimeRAII Strong(Policy);
1118 if (T->getQualifier())
1119 T->getQualifier()->print(OS, Policy);
1120 OS << T->getIdentifier()->getName();
1125 spaceBeforePlaceHolder(OS);
1127 void TypePrinter::printDependentTemplateSpecializationAfter(
1160 spaceBeforePlaceHolder(OS);
1172 OS <<
" _Null_unspecified";
1174 llvm_unreachable(
"unhandled nullability");
1175 spaceBeforePlaceHolder(OS);
1218 OS <<
" _Null_unspecified";
1220 llvm_unreachable(
"unhandled nullability");
1225 OS <<
" __attribute__((";
1227 default: llvm_unreachable(
"This attribute should have been handled already");
1229 OS <<
"address_space(";
1235 OS <<
"__vector_size__(";
1237 OS << vector->getNumElements();
1239 print(vector->getElementType(), OS, StringRef());
1249 OS <<
"neon_vector_type(";
1251 OS <<
"neon_polyvector_type(";
1276 if (next == tmp)
break;
1289 OS <<
"objc_ownership(";
1319 "\"aapcs\"" :
"\"aapcs-vfp\"");
1331 spaceBeforePlaceHolder(OS);
1334 raw_ostream &OS) { }
1348 bool isFirst =
true;
1356 print(typeArg, OS, StringRef());
1361 if (!T->qual_empty()) {
1362 bool isFirst = true;
1364 for (const auto *I : T->quals()) {
1374 spaceBeforePlaceHolder(OS);
1376 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1378 if (T->qual_empty() && T->isUnspecializedAsWritten() &&
1379 !T->isKindOfTypeAsWritten())
1380 return printAfter(T->getBaseType(), OS);
1383 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1385 printBefore(T->getPointeeType(), OS);
1387 // If we need to print the pointer, print it now.
1388 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() &&
1389 !T->isObjCClassType() && !T->isObjCQualifiedClassType()) {
1390 if (HasEmptyPlaceHolder)
1395 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
1396 raw_ostream &OS) { }
1398 void TemplateSpecializationType::
1399 PrintTemplateArgumentList(raw_ostream &OS,
1400 const TemplateArgumentListInfo &Args,
1401 const PrintingPolicy &Policy) {
1402 return PrintTemplateArgumentList(OS,
1403 Args.getArgumentArray(),
1409 TemplateSpecializationType::PrintTemplateArgumentList(
1411 const TemplateArgument *Args,
1413 const PrintingPolicy &Policy,
1414 bool SkipBrackets) {
1415 const char *Comma = Policy.MSVCFormatting ? "," : ", ";
1419 bool needSpace = false;
1420 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1421 // Print the argument into a string.
1422 SmallString<128> Buf;
1423 llvm::raw_svector_ostream ArgOS(Buf);
1424 if (Args[Arg].getKind() == TemplateArgument::Pack) {
1425 if (Args[Arg].pack_size() && Arg > 0)
1427 PrintTemplateArgumentList(ArgOS,
1428 Args[Arg].pack_begin(),
1429 Args[Arg].pack_size(),
1434 Args[Arg].print(Policy, ArgOS);
1436 StringRef ArgString = ArgOS.str();
1438 // If this is the first argument and its string representation
1439 // begins with the global scope specifier ('::foo
'), add a space
1440 // to avoid printing the diagraph '<:
'.
1441 if (!Arg && !ArgString.empty() && ArgString[0] == ':
')
1446 needSpace = (!ArgString.empty() && ArgString.back() == '>
');
1449 // If the last character of our string is '>
', add another space to
1450 // keep the two '>
''s separate tokens. We don
't *have* to do this in
1451 // C++0x, but it's still good hygiene.
1459 // Sadly, repeat all that with TemplateArgLoc.
1460 void TemplateSpecializationType::
1461 PrintTemplateArgumentList(raw_ostream &OS,
1462 const TemplateArgumentLoc *Args, unsigned NumArgs,
1463 const PrintingPolicy &Policy) {
1465 const char *Comma = Policy.MSVCFormatting ? "," : ", ";
1467 bool needSpace = false;
1468 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1472 // Print the argument into a string.
1473 SmallString<128> Buf;
1474 llvm::raw_svector_ostream ArgOS(Buf);
1475 if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) {
1476 PrintTemplateArgumentList(ArgOS,
1477 Args[Arg].getArgument().pack_begin(),
1478 Args[Arg].getArgument().pack_size(),
1481 Args[Arg].getArgument().print(Policy, ArgOS);
1483 StringRef ArgString = ArgOS.str();
1485 // If this is the first argument and its string representation
1486 // begins with the global scope specifier ('::foo
'), add a space
1487 // to avoid printing the diagraph '<:
'.
1488 if (!Arg && !ArgString.empty() && ArgString[0] == ':
')
1493 needSpace = (!ArgString.empty() && ArgString.back() == '>
');
1496 // If the last character of our string is '>
', add another space to
1497 // keep the two '>
''s separate tokens. We don
't *have* to do this in
1498 // C++0x, but it's still good hygiene.
1505 std::string Qualifiers::getAsString() const {
1507 return getAsString(PrintingPolicy(LO));
1510 // Appends qualifiers to the given string, separated by spaces. Will
1511 // prefix a space if the string is non-empty. Will not append a final
1513 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
1514 SmallString<64> Buf;
1515 llvm::raw_svector_ostream StrOS(Buf);
1516 print(StrOS, Policy);
1520 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
1521 if (getCVRQualifiers())
1524 if (getAddressSpace())
1527 if (getObjCGCAttr())
1530 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
1531 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
1537 // Appends qualifiers to the given string, separated by spaces. Will
1538 // prefix a space if the string is non-empty. Will not append a final
1540 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
1541 bool appendSpaceIfNonEmpty) const {
1542 bool addSpace = false;
1544 unsigned quals = getCVRQualifiers();
1546 AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
1549 if (unsigned addrspace = getAddressSpace()) {
1553 switch (addrspace) {
1554 case LangAS::opencl_global:
1557 case LangAS::opencl_local:
1560 case LangAS::opencl_constant:
1563 case LangAS::opencl_generic:
1567 OS << "__attribute__((address_space(";
1572 if (Qualifiers::GC gc = getObjCGCAttr()) {
1576 if (gc == Qualifiers::Weak)
1581 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
1582 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){
1589 case Qualifiers::OCL_None: llvm_unreachable("none but true");
1590 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
1591 case Qualifiers::OCL_Strong:
1592 if (!Policy.SuppressStrongLifetime)
1596 case Qualifiers::OCL_Weak: OS << "__weak"; break;
1597 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
1601 if (appendSpaceIfNonEmpty && addSpace)
1605 std::string QualType::getAsString(const PrintingPolicy &Policy) const {
1607 getAsStringInternal(S, Policy);
1611 std::string QualType::getAsString(const Type *ty, Qualifiers qs) {
1613 LangOptions options;
1614 getAsStringInternal(ty, qs, buffer, PrintingPolicy(options));
1618 void QualType::print(const Type *ty, Qualifiers qs,
1619 raw_ostream &OS, const PrintingPolicy &policy,
1620 const Twine &PlaceHolder) {
1621 SmallString<128> PHBuf;
1622 StringRef PH = PlaceHolder.toStringRef(PHBuf);
1624 TypePrinter(policy).print(ty, qs, OS, PH);
1627 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
1628 std::string &buffer,
1629 const PrintingPolicy &policy) {
1630 SmallString<256> Buf;
1631 llvm::raw_svector_ostream StrOS(Buf);
1632 TypePrinter(policy).print(ty, qs, StrOS, buffer);
1633 std::string str = StrOS.str();
unsigned getNumElements() const
unsigned getAddressSpace() const
Return the address space of this type.
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Defines the clang::ASTContext interface.
QualType getExceptionType(unsigned i) const
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Expr * getSizeExpr() const
const Type * Ty
The locally-unqualified type.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
unsigned getDepth() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
A (possibly-)qualified type.
unsigned getColumn() const
Return the presumed column number of this location.
__auto_type (GNU extension)
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
FunctionType - C99 6.7.5.3 - Function Declarators.
C Language Family Type Representation.
Defines the SourceManager interface.
Qualifiers::GC getObjCGCAttr() const
Returns gc attribute of this type.
Represents a qualified type name for which the type name is dependent.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
TemplateSpecializationType(TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon, QualType Aliased)
QualType getPointeeType() const
The base class of the type hierarchy.
bool isObjCQualifiedClassType() const
DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, unsigned NumArgs, const TemplateArgument *Args, QualType Canon)
NamespaceDecl - Represent a C++ namespace.
A container of type source information.
unsigned getIndex() const
const llvm::APInt & getSize() const
AutoTypeKeyword getKeyword() const
Describes how types, statements, expressions, and declarations should be printed. ...
Qualifiers getIndexTypeQualifiers() const
Represents the result of substituting a type for a template type parameter.
The collection of all-type qualifiers we support.
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
unsigned getNumParams() const
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
QualType getElementType() const
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 getIndexTypeCVRQualifiers() const
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
Represents a class type in Objective C.
Expr * getSizeExpr() const
IdentifierInfo * getIdentifier() const
bool isTranslationUnit() const
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Represents the result of substituting a set of types for a template type parameter pack...
unsigned getRegParm() const
QualType getUnderlyingType() const
Expr * getUnderlyingExpr() const
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
An rvalue reference type, per C++11 [dcl.ref].
An lvalue ref-qualifier was provided (&).
Microsoft throw(...) extension.
QualType getBaseType() const
Gets the base type of this object type.
QualType getReturnType() const
UnresolvedUsingTypenameDecl * getDecl() const
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool C99)
Represents a typeof (or typeof) expression (a GCC extension).
Expr * getNoexceptExpr() const
bool SuppressScope
Suppresses printing of scope specifiers.
RecordDecl * getDecl() const
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
TypeClass getTypeClass() const
unsigned getLine() const
Return the presumed line number of this location.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
const TemplateSpecializationType * getInjectedTST() const
static void PrintTemplateArgumentList(raw_ostream &OS, const TemplateArgument *Args, unsigned NumArgs, const PrintingPolicy &Policy, bool SkipBrackets=false)
Print a template argument list, including the '<' and '>' enclosing the template arguments...
detail::InMemoryDirectory::const_iterator I
is ARM Neon polynomial vector
Represents an extended vector type where either the type or size is dependent.
This object can be modified without requiring retains or releases.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
EnumDecl * getDecl() const
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
ExtInfo getExtInfo() const
QualType getParamType(unsigned i) const
Represents a prototype with parameter type info, e.g.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Represents an array type in C++ whose size is a value-dependent expression.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
QualType getPointeeType() const
Defines the clang::LangOptions interface.
StringRef getName() const
Return the actual identifier string.
bool isObjCClassType() const
bool isObjCGCWeak() const
true when Type is objc's weak.
Expr * getUnderlyingExpr() const
QualType getNamedType() const
Retrieve the type named by the qualified-id.
DeclContext * getDeclContext()
Represents the type decltype(expr) (C++11).
bool isObjCIdType() const
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
bool hasTrailingReturn() const
bool isFunctionOrMethod() const
Qualifiers Quals
The local qualifiers.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Represents an unpacked "presumed" location which can be presented to the user.
Represents a GCC generic vector type.
An lvalue reference type, per C++11 [dcl.ref].
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
QualType getElementType() const
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
TypedefNameDecl * getTypedefNameForAnonDecl() const
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
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
const char * getFilename() const
Return the presumed filename of this location.
Sugar for parentheses used when specifying types.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
QualType getElementType() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function 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
VectorKind getVectorKind() const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
No ref-qualifier was provided.
is AltiVec 'vector bool ...'
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
TypedefNameDecl * getDecl() const
bool SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
An rvalue ref-qualifier was provided (&&).
Assigning into this object requires a lifetime extension.
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.
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Expr * getSizeExpr() const
Base class for declarations which introduce a typedef-name.
Represents a template argument.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
QualType getEquivalentType() const
bool isCallingConv() const
CallingConv getCC() const
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.
const T * getAs() const
Member-template getAs<specific type>'.
unsigned getTypeQuals() const
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
bool isObjCQualifiedIdType() const
bool isFunctionType() const
ExtVectorType - Extended vector type.
QualType getInnerType() const
bool isMSTypeSpec() const
SourceManager & getSourceManager()
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
A template argument list.
const Type * getClass() const
Reading or writing from this object requires a barrier call.
An attributed type is a type to which a type attribute has been applied.
bool hasQualifiers() const
Return true if the set contains any qualifiers.
Represents a C array with an unspecified size.
ArraySizeModifier getSizeModifier() const
ElaboratedTypeKeyword getKeyword() const
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
This class is used for builtin types like 'int'.
QualType getAdjustedType() const
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
QualType getPointeeTypeAsWritten() const
QualType getElementType() const
StringRef getKindName() const
SourceLocation getLocation() const
NamedDecl - This represents a decl with a name.
StringRef getName(const PrintingPolicy &Policy) const
Represents a C array with a specified size that is not an integer-constant-expression.
No keyword precedes the qualified type name.
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Represents the canonical version of C arrays with a specified constant size.
A class which abstracts out some details necessary for making a call.
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine()) const
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
unsigned getNumExceptions() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
QualType getDeducedType() const
Get the type deduced for this auto type, or null if it's either not been deduced or was deduced to a ...