1 //===--- TypePrinter.cpp - Pretty-Print Clang Types -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This contains code to print types from Clang's type system.
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/PrettyPrinter.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/Type.h"
21 #include "clang/Basic/LangOptions.h"
22 #include "clang/Basic/SourceManager.h"
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;
30 /// \brief RAII object that enables printing of the ARC __strong lifetime
32 class IncludeStrongLifetimeRAII {
33 PrintingPolicy &Policy;
37 explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy)
38 : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
39 if (!Policy.SuppressLifetimeQualifiers)
40 Policy.SuppressStrongLifetime = false;
43 ~IncludeStrongLifetimeRAII() {
44 Policy.SuppressStrongLifetime = Old;
48 class ParamPolicyRAII {
49 PrintingPolicy &Policy;
53 explicit ParamPolicyRAII(PrintingPolicy &Policy)
54 : Policy(Policy), Old(Policy.SuppressSpecifiers) {
55 Policy.SuppressSpecifiers = false;
59 Policy.SuppressSpecifiers = Old;
63 class ElaboratedTypePolicyRAII {
64 PrintingPolicy &Policy;
65 bool SuppressTagKeyword;
69 explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
70 SuppressTagKeyword = Policy.SuppressTagKeyword;
71 SuppressScope = Policy.SuppressScope;
72 Policy.SuppressTagKeyword = true;
73 Policy.SuppressScope = true;
76 ~ElaboratedTypePolicyRAII() {
77 Policy.SuppressTagKeyword = SuppressTagKeyword;
78 Policy.SuppressScope = SuppressScope;
83 PrintingPolicy Policy;
84 bool HasEmptyPlaceHolder;
85 bool InsideCCAttribute;
88 explicit TypePrinter(const PrintingPolicy &Policy)
89 : Policy(Policy), HasEmptyPlaceHolder(false), InsideCCAttribute(false) { }
91 void print(const Type *ty, Qualifiers qs, raw_ostream &OS,
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);
99 void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);
100 void printBefore(QualType T, raw_ostream &OS);
101 void printAfter(const Type *ty, Qualifiers qs, 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"
113 static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals) {
114 bool appendSpace = false;
115 if (TypeQuals & Qualifiers::Const) {
119 if (TypeQuals & Qualifiers::Volatile) {
120 if (appendSpace) OS << ' ';
124 if (TypeQuals & Qualifiers::Restrict) {
125 if (appendSpace) OS << ' ';
130 void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
131 if (!HasEmptyPlaceHolder)
135 void TypePrinter::print(QualType t, raw_ostream &OS, StringRef PlaceHolder) {
136 SplitQualType split = t.split();
137 print(split.Ty, split.Quals, OS, PlaceHolder);
140 void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
141 StringRef PlaceHolder) {
147 SaveAndRestore<bool> PHVal(HasEmptyPlaceHolder, PlaceHolder.empty());
149 printBefore(T, Quals, OS);
151 printAfter(T, Quals, OS);
154 bool TypePrinter::canPrefixQualifiers(const Type *T,
155 bool &NeedARCStrongQualifier) {
156 // CanPrefixQualifiers - We prefer to print type qualifiers before the type,
157 // so that we get "const int" instead of "int const", but we can't do this if
158 // the type is complex. For example if the type is "int*", we *must* print
159 // "int * const", printing "const int *" is different. Only do this when the
160 // type expands to a simple string.
161 bool CanPrefixQualifiers = false;
162 NeedARCStrongQualifier = false;
163 Type::TypeClass TC = T->getTypeClass();
164 if (const AutoType *AT = dyn_cast<AutoType>(T))
165 TC = AT->desugar()->getTypeClass();
166 if (const SubstTemplateTypeParmType *Subst
167 = dyn_cast<SubstTemplateTypeParmType>(T))
168 TC = Subst->getReplacementType()->getTypeClass();
174 case Type::UnresolvedUsing:
176 case Type::TypeOfExpr:
179 case Type::UnaryTransform:
182 case Type::Elaborated:
183 case Type::TemplateTypeParm:
184 case Type::SubstTemplateTypeParmPack:
185 case Type::TemplateSpecialization:
186 case Type::InjectedClassName:
187 case Type::DependentName:
188 case Type::DependentTemplateSpecialization:
189 case Type::ObjCObject:
190 case Type::ObjCInterface:
192 CanPrefixQualifiers = true;
195 case Type::ObjCObjectPointer:
196 CanPrefixQualifiers = T->isObjCIdType() || T->isObjCClassType() ||
197 T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType();
200 case Type::ConstantArray:
201 case Type::IncompleteArray:
202 case Type::VariableArray:
203 case Type::DependentSizedArray:
204 NeedARCStrongQualifier = true;
209 case Type::BlockPointer:
210 case Type::LValueReference:
211 case Type::RValueReference:
212 case Type::MemberPointer:
213 case Type::DependentSizedExtVector:
215 case Type::ExtVector:
216 case Type::FunctionProto:
217 case Type::FunctionNoProto:
219 case Type::Attributed:
220 case Type::PackExpansion:
221 case Type::SubstTemplateTypeParm:
222 CanPrefixQualifiers = false;
226 return CanPrefixQualifiers;
229 void TypePrinter::printBefore(QualType T, raw_ostream &OS) {
230 SplitQualType Split = T.split();
232 // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2
234 Qualifiers Quals = Split.Quals;
235 if (const SubstTemplateTypeParmType *Subst =
236 dyn_cast<SubstTemplateTypeParmType>(Split.Ty))
237 Quals -= QualType(Subst, 0).getQualifiers();
239 printBefore(Split.Ty, Quals, OS);
242 /// \brief Prints the part of the type string before an identifier, e.g. for
243 /// "int foo[10]" it prints "int ".
244 void TypePrinter::printBefore(const Type *T,Qualifiers Quals, raw_ostream &OS) {
245 if (Policy.SuppressSpecifiers && T->isSpecifierType())
248 SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder);
250 // Print qualifiers as appropriate.
252 bool CanPrefixQualifiers = false;
253 bool NeedARCStrongQualifier = false;
254 CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
256 if (CanPrefixQualifiers && !Quals.empty()) {
257 if (NeedARCStrongQualifier) {
258 IncludeStrongLifetimeRAII Strong(Policy);
259 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
261 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
265 bool hasAfterQuals = false;
266 if (!CanPrefixQualifiers && !Quals.empty()) {
267 hasAfterQuals = !Quals.isEmptyWhenPrinted(Policy);
269 HasEmptyPlaceHolder = false;
272 switch (T->getTypeClass()) {
273 #define ABSTRACT_TYPE(CLASS, PARENT)
274 #define TYPE(CLASS, PARENT) case Type::CLASS: \
275 print##CLASS##Before(cast<CLASS##Type>(T), OS); \
277 #include "clang/AST/TypeNodes.def"
281 if (NeedARCStrongQualifier) {
282 IncludeStrongLifetimeRAII Strong(Policy);
283 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
285 Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
290 void TypePrinter::printAfter(QualType t, raw_ostream &OS) {
291 SplitQualType split = t.split();
292 printAfter(split.Ty, split.Quals, OS);
295 /// \brief Prints the part of the type string after an identifier, e.g. for
296 /// "int foo[10]" it prints "[10]".
297 void TypePrinter::printAfter(const Type *T, Qualifiers Quals, raw_ostream &OS) {
298 switch (T->getTypeClass()) {
299 #define ABSTRACT_TYPE(CLASS, PARENT)
300 #define TYPE(CLASS, PARENT) case Type::CLASS: \
301 print##CLASS##After(cast<CLASS##Type>(T), OS); \
303 #include "clang/AST/TypeNodes.def"
307 void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) {
308 OS << T->getName(Policy);
309 spaceBeforePlaceHolder(OS);
311 void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) { }
313 void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) {
315 printBefore(T->getElementType(), OS);
317 void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) {
318 printAfter(T->getElementType(), OS);
321 void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) {
322 IncludeStrongLifetimeRAII Strong(Policy);
323 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
324 printBefore(T->getPointeeType(), OS);
325 // Handle things like 'int (*A)[4];' correctly.
326 // FIXME: this should include vectors, but vectors use attributes I guess.
327 if (isa<ArrayType>(T->getPointeeType()))
331 void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) {
332 IncludeStrongLifetimeRAII Strong(Policy);
333 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
334 // Handle things like 'int (*A)[4];' correctly.
335 // FIXME: this should include vectors, but vectors use attributes I guess.
336 if (isa<ArrayType>(T->getPointeeType()))
338 printAfter(T->getPointeeType(), OS);
341 void TypePrinter::printBlockPointerBefore(const BlockPointerType *T,
343 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
344 printBefore(T->getPointeeType(), OS);
347 void TypePrinter::printBlockPointerAfter(const BlockPointerType *T,
349 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
350 printAfter(T->getPointeeType(), OS);
353 void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
355 IncludeStrongLifetimeRAII Strong(Policy);
356 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
357 printBefore(T->getPointeeTypeAsWritten(), OS);
358 // Handle things like 'int (&A)[4];' correctly.
359 // FIXME: this should include vectors, but vectors use attributes I guess.
360 if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
364 void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T,
366 IncludeStrongLifetimeRAII Strong(Policy);
367 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
368 // Handle things like 'int (&A)[4];' correctly.
369 // FIXME: this should include vectors, but vectors use attributes I guess.
370 if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
372 printAfter(T->getPointeeTypeAsWritten(), OS);
375 void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
377 IncludeStrongLifetimeRAII Strong(Policy);
378 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
379 printBefore(T->getPointeeTypeAsWritten(), OS);
380 // Handle things like 'int (&&A)[4];' correctly.
381 // FIXME: this should include vectors, but vectors use attributes I guess.
382 if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
386 void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T,
388 IncludeStrongLifetimeRAII Strong(Policy);
389 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
390 // Handle things like 'int (&&A)[4];' correctly.
391 // FIXME: this should include vectors, but vectors use attributes I guess.
392 if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
394 printAfter(T->getPointeeTypeAsWritten(), OS);
397 void TypePrinter::printMemberPointerBefore(const MemberPointerType *T,
399 IncludeStrongLifetimeRAII Strong(Policy);
400 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
401 printBefore(T->getPointeeType(), OS);
402 // Handle things like 'int (Cls::*A)[4];' correctly.
403 // FIXME: this should include vectors, but vectors use attributes I guess.
404 if (isa<ArrayType>(T->getPointeeType()))
407 PrintingPolicy InnerPolicy(Policy);
408 InnerPolicy.SuppressTag = false;
409 TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
413 void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
415 IncludeStrongLifetimeRAII Strong(Policy);
416 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
417 // Handle things like 'int (Cls::*A)[4];' correctly.
418 // FIXME: this should include vectors, but vectors use attributes I guess.
419 if (isa<ArrayType>(T->getPointeeType()))
421 printAfter(T->getPointeeType(), OS);
424 void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
426 IncludeStrongLifetimeRAII Strong(Policy);
427 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
428 printBefore(T->getElementType(), OS);
430 void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
432 OS << '[' << T->getSize().getZExtValue() << ']';
433 printAfter(T->getElementType(), OS);
436 void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
438 IncludeStrongLifetimeRAII Strong(Policy);
439 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
440 printBefore(T->getElementType(), OS);
442 void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
445 printAfter(T->getElementType(), OS);
448 void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
450 IncludeStrongLifetimeRAII Strong(Policy);
451 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
452 printBefore(T->getElementType(), OS);
454 void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
457 if (T->getIndexTypeQualifiers().hasQualifiers()) {
458 AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers());
462 if (T->getSizeModifier() == VariableArrayType::Static)
464 else if (T->getSizeModifier() == VariableArrayType::Star)
467 if (T->getSizeExpr())
468 T->getSizeExpr()->printPretty(OS, 0, Policy);
471 printAfter(T->getElementType(), OS);
474 void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) {
475 // Print as though it's a pointer.
476 printBefore(T->getDecayedType(), OS);
478 void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) {
479 printAfter(T->getDecayedType(), OS);
482 void TypePrinter::printDependentSizedArrayBefore(
483 const DependentSizedArrayType *T,
485 IncludeStrongLifetimeRAII Strong(Policy);
486 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
487 printBefore(T->getElementType(), OS);
489 void TypePrinter::printDependentSizedArrayAfter(
490 const DependentSizedArrayType *T,
493 if (T->getSizeExpr())
494 T->getSizeExpr()->printPretty(OS, 0, Policy);
496 printAfter(T->getElementType(), OS);
499 void TypePrinter::printDependentSizedExtVectorBefore(
500 const DependentSizedExtVectorType *T,
502 printBefore(T->getElementType(), OS);
504 void TypePrinter::printDependentSizedExtVectorAfter(
505 const DependentSizedExtVectorType *T,
507 OS << " __attribute__((ext_vector_type(";
508 if (T->getSizeExpr())
509 T->getSizeExpr()->printPretty(OS, 0, Policy);
511 printAfter(T->getElementType(), OS);
514 void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) {
515 switch (T->getVectorKind()) {
516 case VectorType::AltiVecPixel:
517 OS << "__vector __pixel ";
519 case VectorType::AltiVecBool:
520 OS << "__vector __bool ";
521 printBefore(T->getElementType(), OS);
523 case VectorType::AltiVecVector:
525 printBefore(T->getElementType(), OS);
527 case VectorType::NeonVector:
528 OS << "__attribute__((neon_vector_type("
529 << T->getNumElements() << "))) ";
530 printBefore(T->getElementType(), OS);
532 case VectorType::NeonPolyVector:
533 OS << "__attribute__((neon_polyvector_type(" <<
534 T->getNumElements() << "))) ";
535 printBefore(T->getElementType(), OS);
537 case VectorType::GenericVector: {
538 // FIXME: We prefer to print the size directly here, but have no way
539 // to get the size of the type.
540 OS << "__attribute__((__vector_size__("
541 << T->getNumElements()
543 print(T->getElementType(), OS, StringRef());
545 printBefore(T->getElementType(), OS);
550 void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) {
551 printAfter(T->getElementType(), OS);
554 void TypePrinter::printExtVectorBefore(const ExtVectorType *T,
556 printBefore(T->getElementType(), OS);
558 void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) {
559 printAfter(T->getElementType(), OS);
560 OS << " __attribute__((ext_vector_type(";
561 OS << T->getNumElements();
566 FunctionProtoType::printExceptionSpecification(raw_ostream &OS,
567 const PrintingPolicy &Policy)
570 if (hasDynamicExceptionSpec()) {
572 if (getExceptionSpecType() == EST_MSAny)
575 for (unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
579 OS << getExceptionType(I).stream(Policy);
582 } else if (isNoexceptExceptionSpec(getExceptionSpecType())) {
584 if (getExceptionSpecType() == EST_ComputedNoexcept) {
586 getNoexceptExpr()->printPretty(OS, 0, Policy);
592 void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T,
594 if (T->hasTrailingReturn()) {
596 if (!HasEmptyPlaceHolder)
599 // If needed for precedence reasons, wrap the inner part in grouping parens.
600 SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
601 printBefore(T->getResultType(), OS);
602 if (!PrevPHIsEmpty.get())
607 void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T,
609 // If needed for precedence reasons, wrap the inner part in grouping parens.
610 if (!HasEmptyPlaceHolder)
612 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
616 ParamPolicyRAII ParamPolicy(Policy);
617 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
619 print(T->getArgType(i), OS, StringRef());
623 if (T->isVariadic()) {
627 } else if (T->getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) {
628 // Do not emit int() if we have a proto, emit 'int(void)'.
634 FunctionType::ExtInfo Info = T->getExtInfo();
636 if (!InsideCCAttribute) {
637 switch (Info.getCC()) {
639 // The C calling convention is the default on the vast majority of platforms
640 // we support. If the user wrote it explicitly, it will usually be printed
641 // while traversing the AttributedType. If the type has been desugared, let
642 // the canonical spelling be the implicit calling convention.
643 // FIXME: It would be better to be explicit in certain contexts, such as a
644 // cdecl function typedef used to declare a member function with the
645 // Microsoft C++ ABI.
648 OS << " __attribute__((stdcall))";
651 OS << " __attribute__((fastcall))";
654 OS << " __attribute__((thiscall))";
657 OS << " __attribute__((pascal))";
660 OS << " __attribute__((pcs(\"aapcs\")))";
663 OS << " __attribute__((pcs(\"aapcs-vfp\")))";
666 OS << " __attribute__((pnaclcall))";
668 case CC_IntelOclBicc:
669 OS << " __attribute__((intel_ocl_bicc))";
672 OS << " __attribute__((ms_abi))";
675 OS << " __attribute__((sysv_abi))";
680 if (Info.getNoReturn())
681 OS << " __attribute__((noreturn))";
682 if (Info.getRegParm())
683 OS << " __attribute__((regparm ("
684 << Info.getRegParm() << ")))";
686 if (unsigned quals = T->getTypeQuals()) {
688 AppendTypeQualList(OS, quals);
691 switch (T->getRefQualifier()) {
703 T->printExceptionSpecification(OS, Policy);
705 if (T->hasTrailingReturn()) {
707 print(T->getResultType(), OS, StringRef());
709 printAfter(T->getResultType(), OS);
712 void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T,
714 // If needed for precedence reasons, wrap the inner part in grouping parens.
715 SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
716 printBefore(T->getResultType(), OS);
717 if (!PrevPHIsEmpty.get())
720 void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T,
722 // If needed for precedence reasons, wrap the inner part in grouping parens.
723 if (!HasEmptyPlaceHolder)
725 SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
728 if (T->getNoReturnAttr())
729 OS << " __attribute__((noreturn))";
730 printAfter(T->getResultType(), OS);
733 void TypePrinter::printTypeSpec(const NamedDecl *D, raw_ostream &OS) {
734 IdentifierInfo *II = D->getIdentifier();
736 spaceBeforePlaceHolder(OS);
739 void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T,
741 printTypeSpec(T->getDecl(), OS);
743 void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T,
746 void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) {
747 printTypeSpec(T->getDecl(), OS);
749 void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) { }
751 void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
754 T->getUnderlyingExpr()->printPretty(OS, 0, Policy);
755 spaceBeforePlaceHolder(OS);
757 void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
760 void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
762 print(T->getUnderlyingType(), OS, StringRef());
764 spaceBeforePlaceHolder(OS);
766 void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) { }
768 void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
770 T->getUnderlyingExpr()->printPretty(OS, 0, Policy);
772 spaceBeforePlaceHolder(OS);
774 void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) { }
776 void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T,
778 IncludeStrongLifetimeRAII Strong(Policy);
780 switch (T->getUTTKind()) {
781 case UnaryTransformType::EnumUnderlyingType:
782 OS << "__underlying_type(";
783 print(T->getBaseType(), OS, StringRef());
785 spaceBeforePlaceHolder(OS);
789 printBefore(T->getBaseType(), OS);
791 void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T,
793 IncludeStrongLifetimeRAII Strong(Policy);
795 switch (T->getUTTKind()) {
796 case UnaryTransformType::EnumUnderlyingType:
800 printAfter(T->getBaseType(), OS);
803 void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
804 // If the type has been deduced, do not print 'auto'.
805 if (!T->getDeducedType().isNull()) {
806 printBefore(T->getDeducedType(), OS);
808 OS << (T->isDecltypeAuto() ? "decltype(auto)" : "auto");
809 spaceBeforePlaceHolder(OS);
812 void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) {
813 // If the type has been deduced, do not print 'auto'.
814 if (!T->getDeducedType().isNull())
815 printAfter(T->getDeducedType(), OS);
818 void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) {
819 IncludeStrongLifetimeRAII Strong(Policy);
822 print(T->getValueType(), OS, StringRef());
824 spaceBeforePlaceHolder(OS);
826 void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) { }
828 /// Appends the given scope to the end of a string.
829 void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
830 if (DC->isTranslationUnit()) return;
831 if (DC->isFunctionOrMethod()) return;
832 AppendScope(DC->getParent(), OS);
834 if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
835 if (Policy.SuppressUnwrittenScope &&
836 (NS->isAnonymousNamespace() || NS->isInline()))
838 if (NS->getIdentifier())
839 OS << NS->getName() << "::";
841 OS << "<anonymous>::";
842 } else if (ClassTemplateSpecializationDecl *Spec
843 = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
844 IncludeStrongLifetimeRAII Strong(Policy);
845 OS << Spec->getIdentifier()->getName();
846 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
847 TemplateSpecializationType::PrintTemplateArgumentList(OS,
852 } else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
853 if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
854 OS << Typedef->getIdentifier()->getName() << "::";
855 else if (Tag->getIdentifier())
856 OS << Tag->getIdentifier()->getName() << "::";
862 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
863 if (Policy.SuppressTag)
866 bool HasKindDecoration = false;
868 // bool SuppressTagKeyword
869 // = Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword;
871 // We don't print tags unless this is an elaborated type.
872 // In C, we just assume every RecordType is an elaborated type.
873 if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword ||
874 D->getTypedefNameForAnonDecl())) {
875 HasKindDecoration = true;
876 OS << D->getKindName();
880 // Compute the full nested-name-specifier for this type.
881 // In C, this will always be empty except when the type
882 // being printed is anonymous within other Record.
883 if (!Policy.SuppressScope)
884 AppendScope(D->getDeclContext(), OS);
886 if (const IdentifierInfo *II = D->getIdentifier())
888 else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
889 assert(Typedef->getIdentifier() && "Typedef without identifier?");
890 OS << Typedef->getIdentifier()->getName();
892 // Make an unambiguous representation for anonymous types, e.g.
893 // <anonymous enum at /usr/include/string.h:120:9>
895 if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
897 HasKindDecoration = true;
902 if (Policy.AnonymousTagLocations) {
903 // Suppress the redundant tag keyword if we just printed one.
904 // We don't have to worry about ElaboratedTypes here because you can't
905 // refer to an anonymous type with one.
906 if (!HasKindDecoration)
907 OS << " " << D->getKindName();
909 PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
911 if (PLoc.isValid()) {
912 OS << " at " << PLoc.getFilename()
913 << ':' << PLoc.getLine()
914 << ':' << PLoc.getColumn();
921 // If this is a class template specialization, print the template
923 if (ClassTemplateSpecializationDecl *Spec
924 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
925 const TemplateArgument *Args;
927 if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) {
928 const TemplateSpecializationType *TST =
929 cast<TemplateSpecializationType>(TAW->getType());
930 Args = TST->getArgs();
931 NumArgs = TST->getNumArgs();
933 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
934 Args = TemplateArgs.data();
935 NumArgs = TemplateArgs.size();
937 IncludeStrongLifetimeRAII Strong(Policy);
938 TemplateSpecializationType::PrintTemplateArgumentList(OS,
943 spaceBeforePlaceHolder(OS);
946 void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
947 printTag(T->getDecl(), OS);
949 void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) { }
951 void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) {
952 printTag(T->getDecl(), OS);
954 void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) { }
956 void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T,
958 if (IdentifierInfo *Id = T->getIdentifier())
961 OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex();
962 spaceBeforePlaceHolder(OS);
964 void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T,
967 void TypePrinter::printSubstTemplateTypeParmBefore(
968 const SubstTemplateTypeParmType *T,
970 IncludeStrongLifetimeRAII Strong(Policy);
971 printBefore(T->getReplacementType(), OS);
973 void TypePrinter::printSubstTemplateTypeParmAfter(
974 const SubstTemplateTypeParmType *T,
976 IncludeStrongLifetimeRAII Strong(Policy);
977 printAfter(T->getReplacementType(), OS);
980 void TypePrinter::printSubstTemplateTypeParmPackBefore(
981 const SubstTemplateTypeParmPackType *T,
983 IncludeStrongLifetimeRAII Strong(Policy);
984 printTemplateTypeParmBefore(T->getReplacedParameter(), OS);
986 void TypePrinter::printSubstTemplateTypeParmPackAfter(
987 const SubstTemplateTypeParmPackType *T,
989 IncludeStrongLifetimeRAII Strong(Policy);
990 printTemplateTypeParmAfter(T->getReplacedParameter(), OS);
993 void TypePrinter::printTemplateSpecializationBefore(
994 const TemplateSpecializationType *T,
996 IncludeStrongLifetimeRAII Strong(Policy);
997 T->getTemplateName().print(OS, Policy);
999 TemplateSpecializationType::PrintTemplateArgumentList(OS,
1003 spaceBeforePlaceHolder(OS);
1005 void TypePrinter::printTemplateSpecializationAfter(
1006 const TemplateSpecializationType *T,
1007 raw_ostream &OS) { }
1009 void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T,
1011 printTemplateSpecializationBefore(T->getInjectedTST(), OS);
1013 void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
1014 raw_ostream &OS) { }
1016 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
1018 if (Policy.SuppressTag && isa<TagType>(T->getNamedType()))
1020 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1021 if (T->getKeyword() != ETK_None)
1023 NestedNameSpecifier* Qualifier = T->getQualifier();
1025 Qualifier->print(OS, Policy);
1027 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1028 printBefore(T->getNamedType(), OS);
1030 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
1032 ElaboratedTypePolicyRAII PolicyRAII(Policy);
1033 printAfter(T->getNamedType(), OS);
1036 void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) {
1037 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
1038 printBefore(T->getInnerType(), OS);
1041 printBefore(T->getInnerType(), OS);
1043 void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) {
1044 if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
1046 printAfter(T->getInnerType(), OS);
1048 printAfter(T->getInnerType(), OS);
1051 void TypePrinter::printDependentNameBefore(const DependentNameType *T,
1053 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1054 if (T->getKeyword() != ETK_None)
1057 T->getQualifier()->print(OS, Policy);
1059 OS << T->getIdentifier()->getName();
1060 spaceBeforePlaceHolder(OS);
1062 void TypePrinter::printDependentNameAfter(const DependentNameType *T,
1063 raw_ostream &OS) { }
1065 void TypePrinter::printDependentTemplateSpecializationBefore(
1066 const DependentTemplateSpecializationType *T, raw_ostream &OS) {
1067 IncludeStrongLifetimeRAII Strong(Policy);
1069 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1070 if (T->getKeyword() != ETK_None)
1073 if (T->getQualifier())
1074 T->getQualifier()->print(OS, Policy);
1075 OS << T->getIdentifier()->getName();
1076 TemplateSpecializationType::PrintTemplateArgumentList(OS,
1080 spaceBeforePlaceHolder(OS);
1082 void TypePrinter::printDependentTemplateSpecializationAfter(
1083 const DependentTemplateSpecializationType *T, raw_ostream &OS) { }
1085 void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
1087 printBefore(T->getPattern(), OS);
1089 void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
1091 printAfter(T->getPattern(), OS);
1095 void TypePrinter::printAttributedBefore(const AttributedType *T,
1097 // Prefer the macro forms of the GC and ownership qualifiers.
1098 if (T->getAttrKind() == AttributedType::attr_objc_gc ||
1099 T->getAttrKind() == AttributedType::attr_objc_ownership)
1100 return printBefore(T->getEquivalentType(), OS);
1102 printBefore(T->getModifiedType(), OS);
1104 if (T->isMSTypeSpec()) {
1105 switch (T->getAttrKind()) {
1107 case AttributedType::attr_ptr32: OS << " __ptr32"; break;
1108 case AttributedType::attr_ptr64: OS << " __ptr64"; break;
1109 case AttributedType::attr_sptr: OS << " __sptr"; break;
1110 case AttributedType::attr_uptr: OS << " __uptr"; break;
1112 spaceBeforePlaceHolder(OS);
1116 void TypePrinter::printAttributedAfter(const AttributedType *T,
1118 // Prefer the macro forms of the GC and ownership qualifiers.
1119 if (T->getAttrKind() == AttributedType::attr_objc_gc ||
1120 T->getAttrKind() == AttributedType::attr_objc_ownership)
1121 return printAfter(T->getEquivalentType(), OS);
1123 // TODO: not all attributes are GCC-style attributes.
1124 if (T->isMSTypeSpec())
1127 // If this is a calling convention attribute, don't print the implicit CC from
1128 // the modified type.
1129 SaveAndRestore<bool> MaybeSuppressCC(InsideCCAttribute, T->isCallingConv());
1131 printAfter(T->getModifiedType(), OS);
1133 OS << " __attribute__((";
1134 switch (T->getAttrKind()) {
1135 default: llvm_unreachable("This attribute should have been handled already");
1136 case AttributedType::attr_address_space:
1137 OS << "address_space(";
1138 OS << T->getEquivalentType().getAddressSpace();
1142 case AttributedType::attr_vector_size: {
1143 OS << "__vector_size__(";
1144 if (const VectorType *vector =T->getEquivalentType()->getAs<VectorType>()) {
1145 OS << vector->getNumElements();
1147 print(vector->getElementType(), OS, StringRef());
1154 case AttributedType::attr_neon_vector_type:
1155 case AttributedType::attr_neon_polyvector_type: {
1156 if (T->getAttrKind() == AttributedType::attr_neon_vector_type)
1157 OS << "neon_vector_type(";
1159 OS << "neon_polyvector_type(";
1160 const VectorType *vector = T->getEquivalentType()->getAs<VectorType>();
1161 OS << vector->getNumElements();
1166 case AttributedType::attr_regparm: {
1167 // FIXME: When Sema learns to form this AttributedType, avoid printing the
1168 // attribute again in printFunctionProtoAfter.
1170 QualType t = T->getEquivalentType();
1171 while (!t->isFunctionType())
1172 t = t->getPointeeType();
1173 OS << t->getAs<FunctionType>()->getRegParmType();
1178 case AttributedType::attr_objc_gc: {
1181 QualType tmp = T->getEquivalentType();
1182 while (tmp.getObjCGCAttr() == Qualifiers::GCNone) {
1183 QualType next = tmp->getPointeeType();
1184 if (next == tmp) break;
1188 if (tmp.isObjCGCWeak())
1196 case AttributedType::attr_objc_ownership:
1197 OS << "objc_ownership(";
1198 switch (T->getEquivalentType().getObjCLifetime()) {
1199 case Qualifiers::OCL_None: llvm_unreachable("no ownership!");
1200 case Qualifiers::OCL_ExplicitNone: OS << "none"; break;
1201 case Qualifiers::OCL_Strong: OS << "strong"; break;
1202 case Qualifiers::OCL_Weak: OS << "weak"; break;
1203 case Qualifiers::OCL_Autoreleasing: OS << "autoreleasing"; break;
1208 // FIXME: When Sema learns to form this AttributedType, avoid printing the
1209 // attribute again in printFunctionProtoAfter.
1210 case AttributedType::attr_noreturn: OS << "noreturn"; break;
1212 case AttributedType::attr_cdecl: OS << "cdecl"; break;
1213 case AttributedType::attr_fastcall: OS << "fastcall"; break;
1214 case AttributedType::attr_stdcall: OS << "stdcall"; break;
1215 case AttributedType::attr_thiscall: OS << "thiscall"; break;
1216 case AttributedType::attr_pascal: OS << "pascal"; break;
1217 case AttributedType::attr_ms_abi: OS << "ms_abi"; break;
1218 case AttributedType::attr_sysv_abi: OS << "sysv_abi"; break;
1219 case AttributedType::attr_pcs:
1220 case AttributedType::attr_pcs_vfp: {
1222 QualType t = T->getEquivalentType();
1223 while (!t->isFunctionType())
1224 t = t->getPointeeType();
1225 OS << (t->getAs<FunctionType>()->getCallConv() == CC_AAPCS ?
1226 "\"aapcs\"" : "\"aapcs-vfp\"");
1230 case AttributedType::attr_pnaclcall: OS << "pnaclcall"; break;
1231 case AttributedType::attr_inteloclbicc: OS << "inteloclbicc"; break;
1236 void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
1238 OS << T->getDecl()->getName();
1239 spaceBeforePlaceHolder(OS);
1241 void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T,
1242 raw_ostream &OS) { }
1244 void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T,
1246 if (T->qual_empty())
1247 return printBefore(T->getBaseType(), OS);
1249 print(T->getBaseType(), OS, StringRef());
1251 bool isFirst = true;
1252 for (ObjCObjectType::qual_iterator
1253 I = T->qual_begin(), E = T->qual_end(); I != E; ++I) {
1258 OS << (*I)->getName();
1261 spaceBeforePlaceHolder(OS);
1263 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1265 if (T->qual_empty())
1266 return printAfter(T->getBaseType(), OS);
1269 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1271 T->getPointeeType().getLocalQualifiers().print(OS, Policy,
1272 /*appendSpaceIfNonEmpty=*/true);
1274 if (T->isObjCIdType() || T->isObjCQualifiedIdType())
1276 else if (T->isObjCClassType() || T->isObjCQualifiedClassType())
1278 else if (T->isObjCSelType())
1281 OS << T->getInterfaceDecl()->getName();
1283 if (!T->qual_empty()) {
1285 for (ObjCObjectPointerType::qual_iterator I = T->qual_begin(),
1288 OS << (*I)->getName();
1295 if (!T->isObjCIdType() && !T->isObjCQualifiedIdType()) {
1296 OS << " *"; // Don't forget the implicit pointer.
1298 spaceBeforePlaceHolder(OS);
1301 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
1302 raw_ostream &OS) { }
1304 void TemplateSpecializationType::
1305 PrintTemplateArgumentList(raw_ostream &OS,
1306 const TemplateArgumentListInfo &Args,
1307 const PrintingPolicy &Policy) {
1308 return PrintTemplateArgumentList(OS,
1309 Args.getArgumentArray(),
1315 TemplateSpecializationType::PrintTemplateArgumentList(
1317 const TemplateArgument *Args,
1319 const PrintingPolicy &Policy,
1320 bool SkipBrackets) {
1324 bool needSpace = false;
1325 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1326 // Print the argument into a string.
1327 SmallString<128> Buf;
1328 llvm::raw_svector_ostream ArgOS(Buf);
1329 if (Args[Arg].getKind() == TemplateArgument::Pack) {
1330 if (Args[Arg].pack_size() && Arg > 0)
1332 PrintTemplateArgumentList(ArgOS,
1333 Args[Arg].pack_begin(),
1334 Args[Arg].pack_size(),
1339 Args[Arg].print(Policy, ArgOS);
1341 StringRef ArgString = ArgOS.str();
1343 // If this is the first argument and its string representation
1344 // begins with the global scope specifier ('::foo'), add a space
1345 // to avoid printing the diagraph '<:'.
1346 if (!Arg && !ArgString.empty() && ArgString[0] == ':')
1351 needSpace = (!ArgString.empty() && ArgString.back() == '>');
1354 // If the last character of our string is '>', add another space to
1355 // keep the two '>''s separate tokens. We don't *have* to do this in
1356 // C++0x, but it's still good hygiene.
1364 // Sadly, repeat all that with TemplateArgLoc.
1365 void TemplateSpecializationType::
1366 PrintTemplateArgumentList(raw_ostream &OS,
1367 const TemplateArgumentLoc *Args, unsigned NumArgs,
1368 const PrintingPolicy &Policy) {
1371 bool needSpace = false;
1372 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1376 // Print the argument into a string.
1377 SmallString<128> Buf;
1378 llvm::raw_svector_ostream ArgOS(Buf);
1379 if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) {
1380 PrintTemplateArgumentList(ArgOS,
1381 Args[Arg].getArgument().pack_begin(),
1382 Args[Arg].getArgument().pack_size(),
1385 Args[Arg].getArgument().print(Policy, ArgOS);
1387 StringRef ArgString = ArgOS.str();
1389 // If this is the first argument and its string representation
1390 // begins with the global scope specifier ('::foo'), add a space
1391 // to avoid printing the diagraph '<:'.
1392 if (!Arg && !ArgString.empty() && ArgString[0] == ':')
1397 needSpace = (!ArgString.empty() && ArgString.back() == '>');
1400 // If the last character of our string is '>', add another space to
1401 // keep the two '>''s separate tokens. We don't *have* to do this in
1402 // C++0x, but it's still good hygiene.
1409 void QualType::dump(const char *msg) const {
1411 llvm::errs() << msg << ": ";
1413 print(llvm::errs(), PrintingPolicy(LO), "identifier");
1414 llvm::errs() << '\n';
1416 void QualType::dump() const {
1420 void Type::dump() const {
1421 QualType(this, 0).dump();
1424 std::string Qualifiers::getAsString() const {
1426 return getAsString(PrintingPolicy(LO));
1429 // Appends qualifiers to the given string, separated by spaces. Will
1430 // prefix a space if the string is non-empty. Will not append a final
1432 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
1433 SmallString<64> Buf;
1434 llvm::raw_svector_ostream StrOS(Buf);
1435 print(StrOS, Policy);
1439 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
1440 if (getCVRQualifiers())
1443 if (getAddressSpace())
1446 if (getObjCGCAttr())
1449 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
1450 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
1456 // Appends qualifiers to the given string, separated by spaces. Will
1457 // prefix a space if the string is non-empty. Will not append a final
1459 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
1460 bool appendSpaceIfNonEmpty) const {
1461 bool addSpace = false;
1463 unsigned quals = getCVRQualifiers();
1465 AppendTypeQualList(OS, quals);
1468 if (unsigned addrspace = getAddressSpace()) {
1472 switch (addrspace) {
1473 case LangAS::opencl_global:
1476 case LangAS::opencl_local:
1479 case LangAS::opencl_constant:
1483 OS << "__attribute__((address_space(";
1488 if (Qualifiers::GC gc = getObjCGCAttr()) {
1492 if (gc == Qualifiers::Weak)
1497 if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
1498 if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){
1505 case Qualifiers::OCL_None: llvm_unreachable("none but true");
1506 case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
1507 case Qualifiers::OCL_Strong:
1508 if (!Policy.SuppressStrongLifetime)
1512 case Qualifiers::OCL_Weak: OS << "__weak"; break;
1513 case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
1517 if (appendSpaceIfNonEmpty && addSpace)
1521 std::string QualType::getAsString(const PrintingPolicy &Policy) const {
1523 getAsStringInternal(S, Policy);
1527 std::string QualType::getAsString(const Type *ty, Qualifiers qs) {
1529 LangOptions options;
1530 getAsStringInternal(ty, qs, buffer, PrintingPolicy(options));
1534 void QualType::print(const Type *ty, Qualifiers qs,
1535 raw_ostream &OS, const PrintingPolicy &policy,
1536 const Twine &PlaceHolder) {
1537 SmallString<128> PHBuf;
1538 StringRef PH = PlaceHolder.toStringRef(PHBuf);
1540 TypePrinter(policy).print(ty, qs, OS, PH);
1543 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
1544 std::string &buffer,
1545 const PrintingPolicy &policy) {
1546 SmallString<256> Buf;
1547 llvm::raw_svector_ostream StrOS(Buf);
1548 TypePrinter(policy).print(ty, qs, StrOS, buffer);
1549 std::string str = StrOS.str();