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:
196 CanPrefixQualifiers =
true;
199 case Type::ObjCObjectPointer:
204 case Type::ConstantArray:
205 case Type::IncompleteArray:
206 case Type::VariableArray:
207 case Type::DependentSizedArray:
208 NeedARCStrongQualifier =
true;
214 case Type::BlockPointer:
215 case Type::LValueReference:
216 case Type::RValueReference:
217 case Type::MemberPointer:
218 case Type::DependentSizedExtVector:
220 case Type::ExtVector:
221 case Type::FunctionProto:
222 case Type::FunctionNoProto:
224 case Type::Attributed:
225 case Type::PackExpansion:
226 case Type::SubstTemplateTypeParm:
227 CanPrefixQualifiers =
false;
231 return CanPrefixQualifiers;
234 void TypePrinter::printBefore(
QualType T, raw_ostream &OS) {
241 dyn_cast<SubstTemplateTypeParmType>(Split.
Ty))
244 printBefore(Split.
Ty, Quals, OS);
249 void TypePrinter::printBefore(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
257 bool CanPrefixQualifiers =
false;
258 bool NeedARCStrongQualifier =
false;
259 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
261 if (CanPrefixQualifiers && !Quals.
empty()) {
262 if (NeedARCStrongQualifier) {
263 IncludeStrongLifetimeRAII Strong(Policy);
264 Quals.
print(OS, Policy,
true);
266 Quals.
print(OS, Policy,
true);
270 bool hasAfterQuals =
false;
271 if (!CanPrefixQualifiers && !Quals.
empty()) {
274 HasEmptyPlaceHolder =
false;
278 #define ABSTRACT_TYPE(CLASS, PARENT)
279 #define TYPE(CLASS, PARENT) case Type::CLASS: \
280 print##CLASS##Before(cast<CLASS##Type>(T), OS); \
282 #include "clang/AST/TypeNodes.def"
286 if (NeedARCStrongQualifier) {
287 IncludeStrongLifetimeRAII Strong(Policy);
288 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
290 Quals.
print(OS, Policy, !PrevPHIsEmpty.get());
295 void TypePrinter::printAfter(
QualType t, raw_ostream &OS) {
297 printAfter(split.
Ty, split.
Quals, OS);
302 void TypePrinter::printAfter(
const Type *T,
Qualifiers Quals, raw_ostream &OS) {
304 #define ABSTRACT_TYPE(CLASS, PARENT)
305 #define TYPE(CLASS, PARENT) case Type::CLASS: \
306 print##CLASS##After(cast<CLASS##Type>(T), OS); \
308 #include "clang/AST/TypeNodes.def"
312 void TypePrinter::printBuiltinBefore(
const BuiltinType *T, raw_ostream &OS) {
314 spaceBeforePlaceHolder(OS);
316 void TypePrinter::printBuiltinAfter(
const BuiltinType *T, raw_ostream &OS) { }
318 void TypePrinter::printComplexBefore(
const ComplexType *T, raw_ostream &OS) {
322 void TypePrinter::printComplexAfter(
const ComplexType *T, raw_ostream &OS) {
326 void TypePrinter::printPointerBefore(
const PointerType *T, raw_ostream &OS) {
327 IncludeStrongLifetimeRAII Strong(Policy);
336 void TypePrinter::printPointerAfter(
const PointerType *T, raw_ostream &OS) {
337 IncludeStrongLifetimeRAII Strong(Policy);
360 IncludeStrongLifetimeRAII Strong(Policy);
371 IncludeStrongLifetimeRAII Strong(Policy);
382 IncludeStrongLifetimeRAII Strong(Policy);
393 IncludeStrongLifetimeRAII Strong(Policy);
404 IncludeStrongLifetimeRAII Strong(Policy);
413 InnerPolicy.SuppressTag =
false;
414 TypePrinter(InnerPolicy).print(
QualType(T->
getClass(), 0), OS, StringRef());
420 IncludeStrongLifetimeRAII Strong(Policy);
431 IncludeStrongLifetimeRAII Strong(Policy);
446 OS << T->
getSize().getZExtValue() <<
']';
452 IncludeStrongLifetimeRAII Strong(Policy);
464 IncludeStrongLifetimeRAII Strong(Policy);
482 T->
getSizeExpr()->printPretty(OS,
nullptr, Policy);
488 void TypePrinter::printAdjustedBefore(
const AdjustedType *T, raw_ostream &OS) {
493 void TypePrinter::printAdjustedAfter(
const AdjustedType *T, raw_ostream &OS) {
497 void TypePrinter::printDecayedBefore(
const DecayedType *T, raw_ostream &OS) {
499 printAdjustedBefore(T, OS);
501 void TypePrinter::printDecayedAfter(
const DecayedType *T, raw_ostream &OS) {
502 printAdjustedAfter(T, OS);
505 void TypePrinter::printDependentSizedArrayBefore(
508 IncludeStrongLifetimeRAII Strong(Policy);
512 void TypePrinter::printDependentSizedArrayAfter(
517 T->
getSizeExpr()->printPretty(OS,
nullptr, Policy);
522 void TypePrinter::printDependentSizedExtVectorBefore(
527 void TypePrinter::printDependentSizedExtVectorAfter(
530 OS <<
" __attribute__((ext_vector_type(";
532 T->
getSizeExpr()->printPretty(OS,
nullptr, Policy);
537 void TypePrinter::printVectorBefore(
const VectorType *T, raw_ostream &OS) {
540 OS <<
"__vector __pixel ";
543 OS <<
"__vector __bool ";
551 OS <<
"__attribute__((neon_vector_type("
556 OS <<
"__attribute__((neon_polyvector_type(" <<
563 OS <<
"__attribute__((__vector_size__("
573 void TypePrinter::printVectorAfter(
const VectorType *T, raw_ostream &OS) {
577 void TypePrinter::printExtVectorBefore(
const ExtVectorType *T,
581 void TypePrinter::printExtVectorAfter(
const ExtVectorType *T, raw_ostream &OS) {
583 OS <<
" __attribute__((ext_vector_type(";
620 if (!HasEmptyPlaceHolder)
626 if (!PrevPHIsEmpty.get())
634 if (!HasEmptyPlaceHolder)
640 ParamPolicyRAII ParamPolicy(Policy);
641 for (
unsigned i = 0, e = T->
getNumParams(); i != e; ++i) {
651 }
else if (T->
getNumParams() == 0 && !Policy.LangOpts.CPlusPlus) {
660 if (!InsideCCAttribute) {
661 switch (Info.
getCC()) {
672 OS <<
" __attribute__((stdcall))";
675 OS <<
" __attribute__((fastcall))";
678 OS <<
" __attribute__((thiscall))";
681 OS <<
" __attribute__((vectorcall))";
684 OS <<
" __attribute__((pascal))";
687 OS <<
" __attribute__((pcs(\"aapcs\")))";
690 OS <<
" __attribute__((pcs(\"aapcs-vfp\")))";
693 OS <<
" __attribute__((intel_ocl_bicc))";
696 OS <<
" __attribute__((ms_abi))";
699 OS <<
" __attribute__((sysv_abi))";
709 OS <<
" __attribute__((noreturn))";
711 OS <<
" __attribute__((regparm ("
745 if (!PrevPHIsEmpty.get())
751 if (!HasEmptyPlaceHolder)
757 OS <<
" __attribute__((noreturn))";
761 void TypePrinter::printTypeSpec(
const NamedDecl *D, raw_ostream &OS) {
764 spaceBeforePlaceHolder(OS);
769 printTypeSpec(T->
getDecl(), OS);
774 void TypePrinter::printTypedefBefore(
const TypedefType *T, raw_ostream &OS) {
775 printTypeSpec(T->
getDecl(), OS);
777 void TypePrinter::printTypedefAfter(
const TypedefType *T, raw_ostream &OS) { }
784 spaceBeforePlaceHolder(OS);
789 void TypePrinter::printTypeOfBefore(
const TypeOfType *T, raw_ostream &OS) {
793 spaceBeforePlaceHolder(OS);
795 void TypePrinter::printTypeOfAfter(
const TypeOfType *T, raw_ostream &OS) { }
797 void TypePrinter::printDecltypeBefore(
const DecltypeType *T, raw_ostream &OS) {
802 spaceBeforePlaceHolder(OS);
804 void TypePrinter::printDecltypeAfter(
const DecltypeType *T, raw_ostream &OS) { }
808 IncludeStrongLifetimeRAII Strong(Policy);
812 OS <<
"__underlying_type(";
815 spaceBeforePlaceHolder(OS);
823 IncludeStrongLifetimeRAII Strong(Policy);
833 void TypePrinter::printAutoBefore(
const AutoType *T, raw_ostream &OS) {
839 spaceBeforePlaceHolder(OS);
842 void TypePrinter::printAutoAfter(
const AutoType *T, raw_ostream &OS) {
848 void TypePrinter::printAtomicBefore(
const AtomicType *T, raw_ostream &OS) {
849 IncludeStrongLifetimeRAII Strong(Policy);
854 spaceBeforePlaceHolder(OS);
856 void TypePrinter::printAtomicAfter(
const AtomicType *T, raw_ostream &OS) { }
859 void TypePrinter::AppendScope(
DeclContext *DC, raw_ostream &OS) {
865 if (Policy.SuppressUnwrittenScope &&
866 (NS->isAnonymousNamespace() || NS->isInline()))
868 if (NS->getIdentifier())
869 OS << NS->getName() <<
"::";
871 OS <<
"(anonymous namespace)::";
873 = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
874 IncludeStrongLifetimeRAII Strong(Policy);
875 OS << Spec->getIdentifier()->getName();
882 }
else if (
TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
884 OS << Typedef->getIdentifier()->getName() <<
"::";
885 else if (Tag->getIdentifier())
886 OS << Tag->getIdentifier()->getName() <<
"::";
892 void TypePrinter::printTag(
TagDecl *D, raw_ostream &OS) {
893 if (Policy.SuppressTag)
896 bool HasKindDecoration =
false;
903 if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword ||
905 HasKindDecoration =
true;
913 if (!Policy.SuppressScope)
919 assert(Typedef->getIdentifier() &&
"Typedef without identifier?");
920 OS << Typedef->getIdentifier()->getName();
925 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
927 HasKindDecoration =
true;
932 if (Policy.AnonymousTagLocations) {
936 if (!HasKindDecoration)
954 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
959 cast<TemplateSpecializationType>(TAW->getType());
964 Args = TemplateArgs.
data();
965 NumArgs = TemplateArgs.
size();
967 IncludeStrongLifetimeRAII Strong(Policy);
973 spaceBeforePlaceHolder(OS);
976 void TypePrinter::printRecordBefore(
const RecordType *T, raw_ostream &OS) {
979 void TypePrinter::printRecordAfter(
const RecordType *T, raw_ostream &OS) { }
981 void TypePrinter::printEnumBefore(
const EnumType *T, raw_ostream &OS) {
984 void TypePrinter::printEnumAfter(
const EnumType *T, raw_ostream &OS) { }
992 spaceBeforePlaceHolder(OS);
997 void TypePrinter::printSubstTemplateTypeParmBefore(
1000 IncludeStrongLifetimeRAII Strong(Policy);
1003 void TypePrinter::printSubstTemplateTypeParmAfter(
1006 IncludeStrongLifetimeRAII Strong(Policy);
1010 void TypePrinter::printSubstTemplateTypeParmPackBefore(
1013 IncludeStrongLifetimeRAII Strong(Policy);
1016 void TypePrinter::printSubstTemplateTypeParmPackAfter(
1019 IncludeStrongLifetimeRAII Strong(Policy);
1023 void TypePrinter::printTemplateSpecializationBefore(
1026 IncludeStrongLifetimeRAII Strong(Policy);
1033 spaceBeforePlaceHolder(OS);
1035 void TypePrinter::printTemplateSpecializationAfter(
1037 raw_ostream &OS) { }
1044 raw_ostream &OS) { }
1048 if (Policy.SuppressTag && isa<TagType>(T->
getNamedType()))
1055 Qualifier->
print(OS, Policy);
1057 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1062 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1066 void TypePrinter::printParenBefore(
const ParenType *T, raw_ostream &OS) {
1067 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1073 void TypePrinter::printParenAfter(
const ParenType *T, raw_ostream &OS) {
1074 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->
getInnerType())) {
1090 spaceBeforePlaceHolder(OS);
1093 raw_ostream &OS) { }
1095 void TypePrinter::printDependentTemplateSpecializationBefore(
1097 IncludeStrongLifetimeRAII Strong(Policy);
1110 spaceBeforePlaceHolder(OS);
1112 void TypePrinter::printDependentTemplateSpecializationAfter(
1145 spaceBeforePlaceHolder(OS);
1157 OS <<
" _Null_unspecified";
1159 llvm_unreachable(
"unhandled nullability");
1160 spaceBeforePlaceHolder(OS);
1199 OS <<
" _Null_unspecified";
1201 llvm_unreachable(
"unhandled nullability");
1206 OS <<
" __attribute__((";
1208 default: llvm_unreachable(
"This attribute should have been handled already");
1210 OS <<
"address_space(";
1216 OS <<
"__vector_size__(";
1218 OS << vector->getNumElements();
1220 print(vector->getElementType(), OS, StringRef());
1230 OS <<
"neon_vector_type(";
1232 OS <<
"neon_polyvector_type(";
1257 if (next == tmp)
break;
1270 OS <<
"objc_ownership(";
1300 "\"aapcs\"" :
"\"aapcs-vfp\"");
1312 spaceBeforePlaceHolder(OS);
1315 raw_ostream &OS) { }
1329 bool isFirst =
true;
1337 print(typeArg, OS, StringRef());
1342 if (!T->qual_empty()) {
1343 bool isFirst = true;
1345 for (const auto *I : T->quals()) {
1355 spaceBeforePlaceHolder(OS);
1357 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1359 if (T->qual_empty() && T->isUnspecializedAsWritten() &&
1360 !T->isKindOfTypeAsWritten())
1361 return printAfter(T->getBaseType(), OS);
1364 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1366 printBefore(T->getPointeeType(), OS);
1368 // If we need to print the pointer, print it now.
1369 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() &&
1370 !T->isObjCClassType() && !T->isObjCQualifiedClassType()) {
1371 if (HasEmptyPlaceHolder)
1376 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
1377 raw_ostream &OS) { }
1379 void TemplateSpecializationType::
1380 PrintTemplateArgumentList(raw_ostream &OS,
1381 const TemplateArgumentListInfo &Args,
1382 const PrintingPolicy &Policy) {
1383 return PrintTemplateArgumentList(OS,
1384 Args.getArgumentArray(),
1390 TemplateSpecializationType::PrintTemplateArgumentList(
1392 const TemplateArgument *Args,
1394 const PrintingPolicy &Policy,
1395 bool SkipBrackets) {
1399 bool needSpace = false;
1400 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1401 // Print the argument into a string.
1402 SmallString<128> Buf;
1403 llvm::raw_svector_ostream ArgOS(Buf);
1404 if (Args[Arg].getKind() == TemplateArgument::Pack) {
1405 if (Args[Arg].pack_size() && Arg > 0)
1407 PrintTemplateArgumentList(ArgOS,
1408 Args[Arg].pack_begin(),
1409 Args[Arg].pack_size(),
1414 Args[Arg].print(Policy, ArgOS);
1416 StringRef ArgString = ArgOS.str();
1418 // If this is the first argument and its string representation
1419 // begins with the global scope specifier ('::foo
'), add a space
1420 // to avoid printing the diagraph '<:
'.
1421 if (!Arg && !ArgString.empty() && ArgString[0] == ':
')
1426 needSpace = (!ArgString.empty() && ArgString.back() == '>
');
1429 // If the last character of our string is '>
', add another space to
1430 // keep the two '>
''s separate tokens. We don
't *have* to do this in
1431 // C++0x, but it's still good hygiene.
1439 // Sadly, repeat all that with TemplateArgLoc.
1440 void TemplateSpecializationType::
1441 PrintTemplateArgumentList(raw_ostream &OS,
1442 const TemplateArgumentLoc *Args, unsigned NumArgs,
1443 const PrintingPolicy &Policy) {
1446 bool needSpace = false;
1447 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1451 // Print the argument into a string.
1452 SmallString<128> Buf;
1453 llvm::raw_svector_ostream ArgOS(Buf);
1454 if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) {
1455 PrintTemplateArgumentList(ArgOS,
1456 Args[Arg].getArgument().pack_begin(),
1457 Args[Arg].getArgument().pack_size(),
1460 Args[Arg].getArgument().print(Policy, ArgOS);
1462 StringRef ArgString = ArgOS.str();
1464 // If this is the first argument and its string representation
1465 // begins with the global scope specifier ('::foo
'), add a space
1466 // to avoid printing the diagraph '<:
'.
1467 if (!Arg && !ArgString.empty() && ArgString[0] == ':
')
1472 needSpace = (!ArgString.empty() && ArgString.back() == '>
');
1475 // If the last character of our string is '>
', add another space to
1476 // keep the two '>
''s separate tokens. We don
't *have* to do this in
1477 // C++0x, but it's still good hygiene.
1484 std::string Qualifiers::getAsString() const {
1486 return getAsString(PrintingPolicy(LO));
1489 // Appends qualifiers to the given string, separated by spaces. Will
1490 // prefix a space if the string is non-empty. Will not append a final
1492 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
1493 SmallString<64> Buf;
1494 llvm::raw_svector_ostream StrOS(Buf);
1495 print(StrOS, Policy);
1499 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
1500 if (getCVRQualifiers())
1503 if (getAddressSpace())
1506 if (getObjCGCAttr())
1509 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
1510 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
1516 // Appends qualifiers to the given string, separated by spaces. Will
1517 // prefix a space if the string is non-empty. Will not append a final
1519 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
1520 bool appendSpaceIfNonEmpty) const {
1521 bool addSpace = false;
1523 unsigned quals = getCVRQualifiers();
1525 AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
1528 if (unsigned addrspace = getAddressSpace()) {
1532 switch (addrspace) {
1533 case LangAS::opencl_global:
1536 case LangAS::opencl_local:
1539 case LangAS::opencl_constant:
1542 case LangAS::opencl_generic:
1546 OS << "__attribute__((address_space(";
1551 if (Qualifiers::GC gc = getObjCGCAttr()) {
1555 if (gc == Qualifiers::Weak)
1560 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
1561 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){
1568 case Qualifiers::OCL_None: llvm_unreachable("none but true");
1569 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
1570 case Qualifiers::OCL_Strong:
1571 if (!Policy.SuppressStrongLifetime)
1575 case Qualifiers::OCL_Weak: OS << "__weak"; break;
1576 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
1580 if (appendSpaceIfNonEmpty && addSpace)
1584 std::string QualType::getAsString(const PrintingPolicy &Policy) const {
1586 getAsStringInternal(S, Policy);
1590 std::string QualType::getAsString(const Type *ty, Qualifiers qs) {
1592 LangOptions options;
1593 getAsStringInternal(ty, qs, buffer, PrintingPolicy(options));
1597 void QualType::print(const Type *ty, Qualifiers qs,
1598 raw_ostream &OS, const PrintingPolicy &policy,
1599 const Twine &PlaceHolder) {
1600 SmallString<128> PHBuf;
1601 StringRef PH = PlaceHolder.toStringRef(PHBuf);
1603 TypePrinter(policy).print(ty, qs, OS, PH);
1606 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
1607 std::string &buffer,
1608 const PrintingPolicy &policy) {
1609 SmallString<256> Buf;
1610 llvm::raw_svector_ostream StrOS(Buf);
1611 TypePrinter(policy).print(ty, qs, StrOS, buffer);
1612 std::string str = StrOS.str();
unsigned getNumElements() const
unsigned getAddressSpace() const
getAddressSpace - 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
getDecl - Get the declaration of this interface.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS=false) const
Print the template name.
StringRef getName() const
unsigned getDepth() const
Represents the dependent type named by a dependently-scoped typename using declaration, e.g. using typename Base<T>::foo; Template instantiation turns these into the underlying type.
unsigned getColumn() const
Return the presumed column number of this location.
IdentifierInfo * getIdentifier() const
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
unsigned getNumArgs() const
Retrieve the number of template arguments.
Defines the SourceManager interface.
Qualifiers::GC getObjCGCAttr() const
getObjCGCAttr - 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++1y decltype(auto) type.
QualType getPointeeType() const
bool isObjCQualifiedClassType() const
NamespaceDecl - Represent a C++ namespace.
bool isDecltypeAuto() const
A container of type source information.
unsigned getIndex() const
const llvm::APInt & getSize() 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.
unsigned getNumArgs() const
Retrieve the number of template arguments.
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...
unsigned getIndexTypeCVRQualifiers() const
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
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 lvalue ref-qualifier was provided (&).
Microsoft throw(...) extension.
QualType getBaseType() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
QualType getReturnType() const
UnresolvedUsingTypenameDecl * getDecl() const
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool C99)
TypeOfExprType (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
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
EnumDecl * getDecl() const
QualType getValueType() const
ExtInfo getExtInfo() const
QualType getParamType(unsigned i) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Qualifiers::ObjCLifetime getObjCLifetime() const
getObjCLifetime - Returns lifetime attribute of this type.
QualType getPointeeType() const
SplitQualType split() const
QualType getPointeeType() const
Defines the clang::LangOptions interface.
StringRef getName() const
Return the actual identifier string.
bool isObjCClassType() const
bool isObjCGCWeak() const
isObjCGCWeak true when Type is objc's weak.
Expr * getUnderlyingExpr() const
QualType getNamedType() const
Retrieve the type named by the qualified-id.
DeclContext * getDeclContext()
bool isObjCIdType() const
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.
QualType getElementType() const
QualType getReplacementType() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute. The C++11 [[noreturn]] attr...
const IdentifierInfo * getIdentifier() const
There is no lifetime qualification on this type.
const char * getFilename() const
Return the presumed filename of this location.
QualType getElementType() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
TypeOfType (GCC extension).
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.
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. Used to record that a type was spelled with a bare identifier rather than as a template-id; the equivalent for non-templated classes is just RecordType.
QualType getPointeeType() const
Represents a pack expansion of types.
ArrayRef< QualType > getTypeArgsAsWritten() const
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.
QualType getEquivalentType() const
bool isCallingConv() const
CallingConv getCC() const
QualType getModifiedType() const
const TemplateArgument * getArgs() const
Retrieve the template arguments.
unsigned getTypeQuals() const
bool isSpecifierType() const
bool isObjCQualifiedIdType() const
bool isFunctionType() const
QualType getInnerType() const
const TemplateArgument * getArgs() const
Retrieve the template arguments.
NestedNameSpecifier * getQualifier() 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.
bool hasQualifiers() const
hasQualifiers - Return true if the set contains any qualifiers.
ArraySizeModifier getSizeModifier() const
ElaboratedTypeKeyword getKeyword() const
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
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
Represents a type template specialization; the template must be a class template, a type alias templa...
QualType getElementType() 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...
StringRef getKindName() const
SourceLocation getLocation() const
StringRef getName(const PrintingPolicy &Policy) const
No keyword precedes the qualified type name.
bool isUnspecializedAsWritten() const
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
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 ...