clang  8.0.0svn
TypePrinter.cpp
Go to the documentation of this file.
1 //===- TypePrinter.cpp - Pretty-Print Clang Types -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This contains code to print types from Clang's type system.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
23 #include "clang/AST/TemplateBase.h"
24 #include "clang/AST/TemplateName.h"
25 #include "clang/AST/Type.h"
29 #include "clang/Basic/LLVM.h"
33 #include "clang/Basic/Specifiers.h"
34 #include "llvm/ADT/ArrayRef.h"
35 #include "llvm/ADT/SmallString.h"
36 #include "llvm/ADT/StringRef.h"
37 #include "llvm/ADT/Twine.h"
38 #include "llvm/Support/Casting.h"
39 #include "llvm/Support/Compiler.h"
40 #include "llvm/Support/ErrorHandling.h"
41 #include "llvm/Support/SaveAndRestore.h"
42 #include "llvm/Support/raw_ostream.h"
43 #include <cassert>
44 #include <string>
45 
46 using namespace clang;
47 
48 namespace {
49 
50  /// RAII object that enables printing of the ARC __strong lifetime
51  /// qualifier.
52  class IncludeStrongLifetimeRAII {
53  PrintingPolicy &Policy;
54  bool Old;
55 
56  public:
57  explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy)
58  : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
59  if (!Policy.SuppressLifetimeQualifiers)
60  Policy.SuppressStrongLifetime = false;
61  }
62 
63  ~IncludeStrongLifetimeRAII() {
64  Policy.SuppressStrongLifetime = Old;
65  }
66  };
67 
68  class ParamPolicyRAII {
69  PrintingPolicy &Policy;
70  bool Old;
71 
72  public:
73  explicit ParamPolicyRAII(PrintingPolicy &Policy)
74  : Policy(Policy), Old(Policy.SuppressSpecifiers) {
75  Policy.SuppressSpecifiers = false;
76  }
77 
78  ~ParamPolicyRAII() {
79  Policy.SuppressSpecifiers = Old;
80  }
81  };
82 
83  class ElaboratedTypePolicyRAII {
84  PrintingPolicy &Policy;
85  bool SuppressTagKeyword;
86  bool SuppressScope;
87 
88  public:
89  explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
90  SuppressTagKeyword = Policy.SuppressTagKeyword;
91  SuppressScope = Policy.SuppressScope;
92  Policy.SuppressTagKeyword = true;
93  Policy.SuppressScope = true;
94  }
95 
96  ~ElaboratedTypePolicyRAII() {
97  Policy.SuppressTagKeyword = SuppressTagKeyword;
98  Policy.SuppressScope = SuppressScope;
99  }
100  };
101 
102  class TypePrinter {
103  PrintingPolicy Policy;
104  unsigned Indentation;
105  bool HasEmptyPlaceHolder = false;
106  bool InsideCCAttribute = false;
107 
108  public:
109  explicit TypePrinter(const PrintingPolicy &Policy, unsigned Indentation = 0)
110  : Policy(Policy), Indentation(Indentation) {}
111 
112  void print(const Type *ty, Qualifiers qs, raw_ostream &OS,
113  StringRef PlaceHolder);
114  void print(QualType T, raw_ostream &OS, StringRef PlaceHolder);
115 
116  static bool canPrefixQualifiers(const Type *T, bool &NeedARCStrongQualifier);
117  void spaceBeforePlaceHolder(raw_ostream &OS);
118  void printTypeSpec(NamedDecl *D, raw_ostream &OS);
119 
120  void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);
121  void printBefore(QualType T, raw_ostream &OS);
122  void printAfter(const Type *ty, Qualifiers qs, raw_ostream &OS);
123  void printAfter(QualType T, raw_ostream &OS);
124  void AppendScope(DeclContext *DC, raw_ostream &OS);
125  void printTag(TagDecl *T, raw_ostream &OS);
126  void printFunctionAfter(const FunctionType::ExtInfo &Info, raw_ostream &OS);
127 #define ABSTRACT_TYPE(CLASS, PARENT)
128 #define TYPE(CLASS, PARENT) \
129  void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
130  void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
131 #include "clang/AST/TypeNodes.def"
132  };
133 
134 } // namespace
135 
136 static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
137  bool HasRestrictKeyword) {
138  bool appendSpace = false;
139  if (TypeQuals & Qualifiers::Const) {
140  OS << "const";
141  appendSpace = true;
142  }
143  if (TypeQuals & Qualifiers::Volatile) {
144  if (appendSpace) OS << ' ';
145  OS << "volatile";
146  appendSpace = true;
147  }
148  if (TypeQuals & Qualifiers::Restrict) {
149  if (appendSpace) OS << ' ';
150  if (HasRestrictKeyword) {
151  OS << "restrict";
152  } else {
153  OS << "__restrict";
154  }
155  }
156 }
157 
158 void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
159  if (!HasEmptyPlaceHolder)
160  OS << ' ';
161 }
162 
163 void TypePrinter::print(QualType t, raw_ostream &OS, StringRef PlaceHolder) {
164  SplitQualType split = t.split();
165  print(split.Ty, split.Quals, OS, PlaceHolder);
166 }
167 
168 void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
169  StringRef PlaceHolder) {
170  if (!T) {
171  OS << "NULL TYPE";
172  return;
173  }
174 
175  SaveAndRestore<bool> PHVal(HasEmptyPlaceHolder, PlaceHolder.empty());
176 
177  printBefore(T, Quals, OS);
178  OS << PlaceHolder;
179  printAfter(T, Quals, OS);
180 }
181 
182 bool TypePrinter::canPrefixQualifiers(const Type *T,
183  bool &NeedARCStrongQualifier) {
184  // CanPrefixQualifiers - We prefer to print type qualifiers before the type,
185  // so that we get "const int" instead of "int const", but we can't do this if
186  // the type is complex. For example if the type is "int*", we *must* print
187  // "int * const", printing "const int *" is different. Only do this when the
188  // type expands to a simple string.
189  bool CanPrefixQualifiers = false;
190  NeedARCStrongQualifier = false;
191  Type::TypeClass TC = T->getTypeClass();
192  if (const auto *AT = dyn_cast<AutoType>(T))
193  TC = AT->desugar()->getTypeClass();
194  if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))
195  TC = Subst->getReplacementType()->getTypeClass();
196 
197  switch (TC) {
198  case Type::Auto:
199  case Type::Builtin:
200  case Type::Complex:
201  case Type::UnresolvedUsing:
202  case Type::Typedef:
203  case Type::TypeOfExpr:
204  case Type::TypeOf:
205  case Type::Decltype:
206  case Type::UnaryTransform:
207  case Type::Record:
208  case Type::Enum:
209  case Type::Elaborated:
210  case Type::TemplateTypeParm:
211  case Type::SubstTemplateTypeParmPack:
212  case Type::DeducedTemplateSpecialization:
213  case Type::TemplateSpecialization:
214  case Type::InjectedClassName:
215  case Type::DependentName:
216  case Type::DependentTemplateSpecialization:
217  case Type::ObjCObject:
218  case Type::ObjCTypeParam:
219  case Type::ObjCInterface:
220  case Type::Atomic:
221  case Type::Pipe:
222  CanPrefixQualifiers = true;
223  break;
224 
225  case Type::ObjCObjectPointer:
226  CanPrefixQualifiers = T->isObjCIdType() || T->isObjCClassType() ||
228  break;
229 
230  case Type::ConstantArray:
231  case Type::IncompleteArray:
232  case Type::VariableArray:
233  case Type::DependentSizedArray:
234  NeedARCStrongQualifier = true;
235  LLVM_FALLTHROUGH;
236 
237  case Type::Adjusted:
238  case Type::Decayed:
239  case Type::Pointer:
240  case Type::BlockPointer:
241  case Type::LValueReference:
242  case Type::RValueReference:
243  case Type::MemberPointer:
244  case Type::DependentAddressSpace:
245  case Type::DependentVector:
246  case Type::DependentSizedExtVector:
247  case Type::Vector:
248  case Type::ExtVector:
249  case Type::FunctionProto:
250  case Type::FunctionNoProto:
251  case Type::Paren:
252  case Type::Attributed:
253  case Type::PackExpansion:
254  case Type::SubstTemplateTypeParm:
255  CanPrefixQualifiers = false;
256  break;
257  }
258 
259  return CanPrefixQualifiers;
260 }
261 
262 void TypePrinter::printBefore(QualType T, raw_ostream &OS) {
263  SplitQualType Split = T.split();
264 
265  // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2
266  // at this level.
267  Qualifiers Quals = Split.Quals;
268  if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(Split.Ty))
269  Quals -= QualType(Subst, 0).getQualifiers();
270 
271  printBefore(Split.Ty, Quals, OS);
272 }
273 
274 /// Prints the part of the type string before an identifier, e.g. for
275 /// "int foo[10]" it prints "int ".
276 void TypePrinter::printBefore(const Type *T,Qualifiers Quals, raw_ostream &OS) {
277  if (Policy.SuppressSpecifiers && T->isSpecifierType())
278  return;
279 
280  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder);
281 
282  // Print qualifiers as appropriate.
283 
284  bool CanPrefixQualifiers = false;
285  bool NeedARCStrongQualifier = false;
286  CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
287 
288  if (CanPrefixQualifiers && !Quals.empty()) {
289  if (NeedARCStrongQualifier) {
290  IncludeStrongLifetimeRAII Strong(Policy);
291  Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
292  } else {
293  Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
294  }
295  }
296 
297  bool hasAfterQuals = false;
298  if (!CanPrefixQualifiers && !Quals.empty()) {
299  hasAfterQuals = !Quals.isEmptyWhenPrinted(Policy);
300  if (hasAfterQuals)
301  HasEmptyPlaceHolder = false;
302  }
303 
304  switch (T->getTypeClass()) {
305 #define ABSTRACT_TYPE(CLASS, PARENT)
306 #define TYPE(CLASS, PARENT) case Type::CLASS: \
307  print##CLASS##Before(cast<CLASS##Type>(T), OS); \
308  break;
309 #include "clang/AST/TypeNodes.def"
310  }
311 
312  if (hasAfterQuals) {
313  if (NeedARCStrongQualifier) {
314  IncludeStrongLifetimeRAII Strong(Policy);
315  Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
316  } else {
317  Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
318  }
319  }
320 }
321 
322 void TypePrinter::printAfter(QualType t, raw_ostream &OS) {
323  SplitQualType split = t.split();
324  printAfter(split.Ty, split.Quals, OS);
325 }
326 
327 /// Prints the part of the type string after an identifier, e.g. for
328 /// "int foo[10]" it prints "[10]".
329 void TypePrinter::printAfter(const Type *T, Qualifiers Quals, raw_ostream &OS) {
330  switch (T->getTypeClass()) {
331 #define ABSTRACT_TYPE(CLASS, PARENT)
332 #define TYPE(CLASS, PARENT) case Type::CLASS: \
333  print##CLASS##After(cast<CLASS##Type>(T), OS); \
334  break;
335 #include "clang/AST/TypeNodes.def"
336  }
337 }
338 
339 void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) {
340  OS << T->getName(Policy);
341  spaceBeforePlaceHolder(OS);
342 }
343 
344 void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) {}
345 
346 void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) {
347  OS << "_Complex ";
348  printBefore(T->getElementType(), OS);
349 }
350 
351 void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) {
352  printAfter(T->getElementType(), OS);
353 }
354 
355 void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) {
356  IncludeStrongLifetimeRAII Strong(Policy);
357  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
358  printBefore(T->getPointeeType(), OS);
359  // Handle things like 'int (*A)[4];' correctly.
360  // FIXME: this should include vectors, but vectors use attributes I guess.
361  if (isa<ArrayType>(T->getPointeeType()))
362  OS << '(';
363  OS << '*';
364 }
365 
366 void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) {
367  IncludeStrongLifetimeRAII Strong(Policy);
368  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
369  // Handle things like 'int (*A)[4];' correctly.
370  // FIXME: this should include vectors, but vectors use attributes I guess.
371  if (isa<ArrayType>(T->getPointeeType()))
372  OS << ')';
373  printAfter(T->getPointeeType(), OS);
374 }
375 
376 void TypePrinter::printBlockPointerBefore(const BlockPointerType *T,
377  raw_ostream &OS) {
378  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
379  printBefore(T->getPointeeType(), OS);
380  OS << '^';
381 }
382 
383 void TypePrinter::printBlockPointerAfter(const BlockPointerType *T,
384  raw_ostream &OS) {
385  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
386  printAfter(T->getPointeeType(), OS);
387 }
388 
389 // When printing a reference, the referenced type might also be a reference.
390 // If so, we want to skip that before printing the inner type.
392  if (auto *Ref = T->getAs<ReferenceType>())
393  return skipTopLevelReferences(Ref->getPointeeTypeAsWritten());
394  return T;
395 }
396 
397 void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
398  raw_ostream &OS) {
399  IncludeStrongLifetimeRAII Strong(Policy);
400  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
402  printBefore(Inner, OS);
403  // Handle things like 'int (&A)[4];' correctly.
404  // FIXME: this should include vectors, but vectors use attributes I guess.
405  if (isa<ArrayType>(Inner))
406  OS << '(';
407  OS << '&';
408 }
409 
410 void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T,
411  raw_ostream &OS) {
412  IncludeStrongLifetimeRAII Strong(Policy);
413  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
415  // Handle things like 'int (&A)[4];' correctly.
416  // FIXME: this should include vectors, but vectors use attributes I guess.
417  if (isa<ArrayType>(Inner))
418  OS << ')';
419  printAfter(Inner, OS);
420 }
421 
422 void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
423  raw_ostream &OS) {
424  IncludeStrongLifetimeRAII Strong(Policy);
425  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
427  printBefore(Inner, OS);
428  // Handle things like 'int (&&A)[4];' correctly.
429  // FIXME: this should include vectors, but vectors use attributes I guess.
430  if (isa<ArrayType>(Inner))
431  OS << '(';
432  OS << "&&";
433 }
434 
435 void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T,
436  raw_ostream &OS) {
437  IncludeStrongLifetimeRAII Strong(Policy);
438  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
440  // Handle things like 'int (&&A)[4];' correctly.
441  // FIXME: this should include vectors, but vectors use attributes I guess.
442  if (isa<ArrayType>(Inner))
443  OS << ')';
444  printAfter(Inner, OS);
445 }
446 
447 void TypePrinter::printMemberPointerBefore(const MemberPointerType *T,
448  raw_ostream &OS) {
449  IncludeStrongLifetimeRAII Strong(Policy);
450  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
451  printBefore(T->getPointeeType(), OS);
452  // Handle things like 'int (Cls::*A)[4];' correctly.
453  // FIXME: this should include vectors, but vectors use attributes I guess.
454  if (isa<ArrayType>(T->getPointeeType()))
455  OS << '(';
456 
457  PrintingPolicy InnerPolicy(Policy);
458  InnerPolicy.IncludeTagDefinition = false;
459  TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
460 
461  OS << "::*";
462 }
463 
464 void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
465  raw_ostream &OS) {
466  IncludeStrongLifetimeRAII Strong(Policy);
467  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
468  // Handle things like 'int (Cls::*A)[4];' correctly.
469  // FIXME: this should include vectors, but vectors use attributes I guess.
470  if (isa<ArrayType>(T->getPointeeType()))
471  OS << ')';
472  printAfter(T->getPointeeType(), OS);
473 }
474 
475 void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
476  raw_ostream &OS) {
477  IncludeStrongLifetimeRAII Strong(Policy);
478  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
479  printBefore(T->getElementType(), OS);
480 }
481 
482 void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
483  raw_ostream &OS) {
484  OS << '[';
487  Policy.Restrict);
488  OS << ' ';
489  }
490 
492  OS << "static ";
493 
494  OS << T->getSize().getZExtValue() << ']';
495  printAfter(T->getElementType(), OS);
496 }
497 
498 void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
499  raw_ostream &OS) {
500  IncludeStrongLifetimeRAII Strong(Policy);
501  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
502  printBefore(T->getElementType(), OS);
503 }
504 
505 void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
506  raw_ostream &OS) {
507  OS << "[]";
508  printAfter(T->getElementType(), OS);
509 }
510 
511 void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
512  raw_ostream &OS) {
513  IncludeStrongLifetimeRAII Strong(Policy);
514  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
515  printBefore(T->getElementType(), OS);
516 }
517 
518 void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
519  raw_ostream &OS) {
520  OS << '[';
522  AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict);
523  OS << ' ';
524  }
525 
527  OS << "static ";
528  else if (T->getSizeModifier() == VariableArrayType::Star)
529  OS << '*';
530 
531  if (T->getSizeExpr())
532  T->getSizeExpr()->printPretty(OS, nullptr, Policy);
533  OS << ']';
534 
535  printAfter(T->getElementType(), OS);
536 }
537 
538 void TypePrinter::printAdjustedBefore(const AdjustedType *T, raw_ostream &OS) {
539  // Print the adjusted representation, otherwise the adjustment will be
540  // invisible.
541  printBefore(T->getAdjustedType(), OS);
542 }
543 
544 void TypePrinter::printAdjustedAfter(const AdjustedType *T, raw_ostream &OS) {
545  printAfter(T->getAdjustedType(), OS);
546 }
547 
548 void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) {
549  // Print as though it's a pointer.
550  printAdjustedBefore(T, OS);
551 }
552 
553 void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) {
554  printAdjustedAfter(T, OS);
555 }
556 
557 void TypePrinter::printDependentSizedArrayBefore(
558  const DependentSizedArrayType *T,
559  raw_ostream &OS) {
560  IncludeStrongLifetimeRAII Strong(Policy);
561  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
562  printBefore(T->getElementType(), OS);
563 }
564 
565 void TypePrinter::printDependentSizedArrayAfter(
566  const DependentSizedArrayType *T,
567  raw_ostream &OS) {
568  OS << '[';
569  if (T->getSizeExpr())
570  T->getSizeExpr()->printPretty(OS, nullptr, Policy);
571  OS << ']';
572  printAfter(T->getElementType(), OS);
573 }
574 
575 void TypePrinter::printDependentAddressSpaceBefore(
576  const DependentAddressSpaceType *T, raw_ostream &OS) {
577  printBefore(T->getPointeeType(), OS);
578 }
579 
580 void TypePrinter::printDependentAddressSpaceAfter(
581  const DependentAddressSpaceType *T, raw_ostream &OS) {
582  OS << " __attribute__((address_space(";
583  if (T->getAddrSpaceExpr())
584  T->getAddrSpaceExpr()->printPretty(OS, nullptr, Policy);
585  OS << ")))";
586  printAfter(T->getPointeeType(), OS);
587 }
588 
589 void TypePrinter::printDependentSizedExtVectorBefore(
591  raw_ostream &OS) {
592  printBefore(T->getElementType(), OS);
593 }
594 
595 void TypePrinter::printDependentSizedExtVectorAfter(
597  raw_ostream &OS) {
598  OS << " __attribute__((ext_vector_type(";
599  if (T->getSizeExpr())
600  T->getSizeExpr()->printPretty(OS, nullptr, Policy);
601  OS << ")))";
602  printAfter(T->getElementType(), OS);
603 }
604 
605 void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) {
606  switch (T->getVectorKind()) {
608  OS << "__vector __pixel ";
609  break;
611  OS << "__vector __bool ";
612  printBefore(T->getElementType(), OS);
613  break;
615  OS << "__vector ";
616  printBefore(T->getElementType(), OS);
617  break;
619  OS << "__attribute__((neon_vector_type("
620  << T->getNumElements() << "))) ";
621  printBefore(T->getElementType(), OS);
622  break;
624  OS << "__attribute__((neon_polyvector_type(" <<
625  T->getNumElements() << "))) ";
626  printBefore(T->getElementType(), OS);
627  break;
629  // FIXME: We prefer to print the size directly here, but have no way
630  // to get the size of the type.
631  OS << "__attribute__((__vector_size__("
632  << T->getNumElements()
633  << " * sizeof(";
634  print(T->getElementType(), OS, StringRef());
635  OS << ")))) ";
636  printBefore(T->getElementType(), OS);
637  break;
638  }
639  }
640 }
641 
642 void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) {
643  printAfter(T->getElementType(), OS);
644 }
645 
646 void TypePrinter::printDependentVectorBefore(
647  const DependentVectorType *T, raw_ostream &OS) {
648  switch (T->getVectorKind()) {
650  OS << "__vector __pixel ";
651  break;
653  OS << "__vector __bool ";
654  printBefore(T->getElementType(), OS);
655  break;
657  OS << "__vector ";
658  printBefore(T->getElementType(), OS);
659  break;
661  OS << "__attribute__((neon_vector_type(";
662  if (T->getSizeExpr())
663  T->getSizeExpr()->printPretty(OS, nullptr, Policy);
664  OS << "))) ";
665  printBefore(T->getElementType(), OS);
666  break;
668  OS << "__attribute__((neon_polyvector_type(";
669  if (T->getSizeExpr())
670  T->getSizeExpr()->printPretty(OS, nullptr, Policy);
671  OS << "))) ";
672  printBefore(T->getElementType(), OS);
673  break;
675  // FIXME: We prefer to print the size directly here, but have no way
676  // to get the size of the type.
677  OS << "__attribute__((__vector_size__(";
678  if (T->getSizeExpr())
679  T->getSizeExpr()->printPretty(OS, nullptr, Policy);
680  OS << " * sizeof(";
681  print(T->getElementType(), OS, StringRef());
682  OS << ")))) ";
683  printBefore(T->getElementType(), OS);
684  break;
685  }
686  }
687 }
688 
689 void TypePrinter::printDependentVectorAfter(
690  const DependentVectorType *T, raw_ostream &OS) {
691  printAfter(T->getElementType(), OS);
692 }
693 
694 void TypePrinter::printExtVectorBefore(const ExtVectorType *T,
695  raw_ostream &OS) {
696  printBefore(T->getElementType(), OS);
697 }
698 
699 void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) {
700  printAfter(T->getElementType(), OS);
701  OS << " __attribute__((ext_vector_type(";
702  OS << T->getNumElements();
703  OS << ")))";
704 }
705 
706 void
708  const PrintingPolicy &Policy)
709  const {
710  if (hasDynamicExceptionSpec()) {
711  OS << " throw(";
712  if (getExceptionSpecType() == EST_MSAny)
713  OS << "...";
714  else
715  for (unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
716  if (I)
717  OS << ", ";
718 
719  OS << getExceptionType(I).stream(Policy);
720  }
721  OS << ')';
722  } else if (isNoexceptExceptionSpec(getExceptionSpecType())) {
723  OS << " noexcept";
724  // FIXME:Is it useful to print out the expression for a non-dependent
725  // noexcept specification?
726  if (isComputedNoexcept(getExceptionSpecType())) {
727  OS << '(';
728  if (getNoexceptExpr())
729  getNoexceptExpr()->printPretty(OS, nullptr, Policy);
730  OS << ')';
731  }
732  }
733 }
734 
735 void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T,
736  raw_ostream &OS) {
737  if (T->hasTrailingReturn()) {
738  OS << "auto ";
739  if (!HasEmptyPlaceHolder)
740  OS << '(';
741  } else {
742  // If needed for precedence reasons, wrap the inner part in grouping parens.
743  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
744  printBefore(T->getReturnType(), OS);
745  if (!PrevPHIsEmpty.get())
746  OS << '(';
747  }
748 }
749 
751  switch (ABI) {
753  llvm_unreachable("asking for spelling of ordinary parameter ABI");
755  return "swift_context";
757  return "swift_error_result";
759  return "swift_indirect_result";
760  }
761  llvm_unreachable("bad parameter ABI kind");
762 }
763 
764 void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T,
765  raw_ostream &OS) {
766  // If needed for precedence reasons, wrap the inner part in grouping parens.
767  if (!HasEmptyPlaceHolder)
768  OS << ')';
769  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
770 
771  OS << '(';
772  {
773  ParamPolicyRAII ParamPolicy(Policy);
774  for (unsigned i = 0, e = T->getNumParams(); i != e; ++i) {
775  if (i) OS << ", ";
776 
777  auto EPI = T->getExtParameterInfo(i);
778  if (EPI.isConsumed()) OS << "__attribute__((ns_consumed)) ";
779  if (EPI.isNoEscape())
780  OS << "__attribute__((noescape)) ";
781  auto ABI = EPI.getABI();
782  if (ABI != ParameterABI::Ordinary)
783  OS << "__attribute__((" << getParameterABISpelling(ABI) << ")) ";
784 
785  print(T->getParamType(i), OS, StringRef());
786  }
787  }
788 
789  if (T->isVariadic()) {
790  if (T->getNumParams())
791  OS << ", ";
792  OS << "...";
793  } else if (T->getNumParams() == 0 && Policy.UseVoidForZeroParams) {
794  // Do not emit int() if we have a proto, emit 'int(void)'.
795  OS << "void";
796  }
797 
798  OS << ')';
799 
800  FunctionType::ExtInfo Info = T->getExtInfo();
801 
802  printFunctionAfter(Info, OS);
803 
804  if (unsigned quals = T->getTypeQuals()) {
805  OS << ' ';
806  AppendTypeQualList(OS, quals, Policy.Restrict);
807  }
808 
809  switch (T->getRefQualifier()) {
810  case RQ_None:
811  break;
812 
813  case RQ_LValue:
814  OS << " &";
815  break;
816 
817  case RQ_RValue:
818  OS << " &&";
819  break;
820  }
821  T->printExceptionSpecification(OS, Policy);
822 
823  if (T->hasTrailingReturn()) {
824  OS << " -> ";
825  print(T->getReturnType(), OS, StringRef());
826  } else
827  printAfter(T->getReturnType(), OS);
828 }
829 
830 void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
831  raw_ostream &OS) {
832  if (!InsideCCAttribute) {
833  switch (Info.getCC()) {
834  case CC_C:
835  // The C calling convention is the default on the vast majority of platforms
836  // we support. If the user wrote it explicitly, it will usually be printed
837  // while traversing the AttributedType. If the type has been desugared, let
838  // the canonical spelling be the implicit calling convention.
839  // FIXME: It would be better to be explicit in certain contexts, such as a
840  // cdecl function typedef used to declare a member function with the
841  // Microsoft C++ ABI.
842  break;
843  case CC_X86StdCall:
844  OS << " __attribute__((stdcall))";
845  break;
846  case CC_X86FastCall:
847  OS << " __attribute__((fastcall))";
848  break;
849  case CC_X86ThisCall:
850  OS << " __attribute__((thiscall))";
851  break;
852  case CC_X86VectorCall:
853  OS << " __attribute__((vectorcall))";
854  break;
855  case CC_X86Pascal:
856  OS << " __attribute__((pascal))";
857  break;
858  case CC_AAPCS:
859  OS << " __attribute__((pcs(\"aapcs\")))";
860  break;
861  case CC_AAPCS_VFP:
862  OS << " __attribute__((pcs(\"aapcs-vfp\")))";
863  break;
864  case CC_IntelOclBicc:
865  OS << " __attribute__((intel_ocl_bicc))";
866  break;
867  case CC_Win64:
868  OS << " __attribute__((ms_abi))";
869  break;
870  case CC_X86_64SysV:
871  OS << " __attribute__((sysv_abi))";
872  break;
873  case CC_X86RegCall:
874  OS << " __attribute__((regcall))";
875  break;
876  case CC_SpirFunction:
877  case CC_OpenCLKernel:
878  // Do nothing. These CCs are not available as attributes.
879  break;
880  case CC_Swift:
881  OS << " __attribute__((swiftcall))";
882  break;
883  case CC_PreserveMost:
884  OS << " __attribute__((preserve_most))";
885  break;
886  case CC_PreserveAll:
887  OS << " __attribute__((preserve_all))";
888  break;
889  }
890  }
891 
892  if (Info.getNoReturn())
893  OS << " __attribute__((noreturn))";
894  if (Info.getProducesResult())
895  OS << " __attribute__((ns_returns_retained))";
896  if (Info.getRegParm())
897  OS << " __attribute__((regparm ("
898  << Info.getRegParm() << ")))";
899  if (Info.getNoCallerSavedRegs())
900  OS << " __attribute__((no_caller_saved_registers))";
901  if (Info.getNoCfCheck())
902  OS << " __attribute__((nocf_check))";
903 }
904 
905 void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T,
906  raw_ostream &OS) {
907  // If needed for precedence reasons, wrap the inner part in grouping parens.
908  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
909  printBefore(T->getReturnType(), OS);
910  if (!PrevPHIsEmpty.get())
911  OS << '(';
912 }
913 
914 void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T,
915  raw_ostream &OS) {
916  // If needed for precedence reasons, wrap the inner part in grouping parens.
917  if (!HasEmptyPlaceHolder)
918  OS << ')';
919  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
920 
921  OS << "()";
922  printFunctionAfter(T->getExtInfo(), OS);
923  printAfter(T->getReturnType(), OS);
924 }
925 
926 void TypePrinter::printTypeSpec(NamedDecl *D, raw_ostream &OS) {
927 
928  // Compute the full nested-name-specifier for this type.
929  // In C, this will always be empty except when the type
930  // being printed is anonymous within other Record.
931  if (!Policy.SuppressScope)
932  AppendScope(D->getDeclContext(), OS);
933 
934  IdentifierInfo *II = D->getIdentifier();
935  OS << II->getName();
936  spaceBeforePlaceHolder(OS);
937 }
938 
939 void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T,
940  raw_ostream &OS) {
941  printTypeSpec(T->getDecl(), OS);
942 }
943 
944 void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T,
945  raw_ostream &OS) {}
946 
947 void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) {
948  printTypeSpec(T->getDecl(), OS);
949 }
950 
951 void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {}
952 
953 void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
954  raw_ostream &OS) {
955  OS << "typeof ";
956  if (T->getUnderlyingExpr())
957  T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
958  spaceBeforePlaceHolder(OS);
959 }
960 
961 void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
962  raw_ostream &OS) {}
963 
964 void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
965  OS << "typeof(";
966  print(T->getUnderlyingType(), OS, StringRef());
967  OS << ')';
968  spaceBeforePlaceHolder(OS);
969 }
970 
971 void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) {}
972 
973 void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
974  OS << "decltype(";
975  if (T->getUnderlyingExpr())
976  T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
977  OS << ')';
978  spaceBeforePlaceHolder(OS);
979 }
980 
981 void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) {}
982 
983 void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T,
984  raw_ostream &OS) {
985  IncludeStrongLifetimeRAII Strong(Policy);
986 
987  switch (T->getUTTKind()) {
989  OS << "__underlying_type(";
990  print(T->getBaseType(), OS, StringRef());
991  OS << ')';
992  spaceBeforePlaceHolder(OS);
993  return;
994  }
995 
996  printBefore(T->getBaseType(), OS);
997 }
998 
999 void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T,
1000  raw_ostream &OS) {
1001  IncludeStrongLifetimeRAII Strong(Policy);
1002 
1003  switch (T->getUTTKind()) {
1005  return;
1006  }
1007 
1008  printAfter(T->getBaseType(), OS);
1009 }
1010 
1011 void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
1012  // If the type has been deduced, do not print 'auto'.
1013  if (!T->getDeducedType().isNull()) {
1014  printBefore(T->getDeducedType(), OS);
1015  } else {
1016  switch (T->getKeyword()) {
1017  case AutoTypeKeyword::Auto: OS << "auto"; break;
1018  case AutoTypeKeyword::DecltypeAuto: OS << "decltype(auto)"; break;
1019  case AutoTypeKeyword::GNUAutoType: OS << "__auto_type"; break;
1020  }
1021  spaceBeforePlaceHolder(OS);
1022  }
1023 }
1024 
1025 void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) {
1026  // If the type has been deduced, do not print 'auto'.
1027  if (!T->getDeducedType().isNull())
1028  printAfter(T->getDeducedType(), OS);
1029 }
1030 
1031 void TypePrinter::printDeducedTemplateSpecializationBefore(
1032  const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1033  // If the type has been deduced, print the deduced type.
1034  if (!T->getDeducedType().isNull()) {
1035  printBefore(T->getDeducedType(), OS);
1036  } else {
1037  IncludeStrongLifetimeRAII Strong(Policy);
1038  T->getTemplateName().print(OS, Policy);
1039  spaceBeforePlaceHolder(OS);
1040  }
1041 }
1042 
1043 void TypePrinter::printDeducedTemplateSpecializationAfter(
1044  const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1045  // If the type has been deduced, print the deduced type.
1046  if (!T->getDeducedType().isNull())
1047  printAfter(T->getDeducedType(), OS);
1048 }
1049 
1050 void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) {
1051  IncludeStrongLifetimeRAII Strong(Policy);
1052 
1053  OS << "_Atomic(";
1054  print(T->getValueType(), OS, StringRef());
1055  OS << ')';
1056  spaceBeforePlaceHolder(OS);
1057 }
1058 
1059 void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) {}
1060 
1061 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
1062  IncludeStrongLifetimeRAII Strong(Policy);
1063 
1064  if (T->isReadOnly())
1065  OS << "read_only ";
1066  else
1067  OS << "write_only ";
1068  OS << "pipe ";
1069  print(T->getElementType(), OS, StringRef());
1070  spaceBeforePlaceHolder(OS);
1071 }
1072 
1073 void TypePrinter::printPipeAfter(const PipeType *T, raw_ostream &OS) {}
1074 
1075 /// Appends the given scope to the end of a string.
1076 void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
1077  if (DC->isTranslationUnit()) return;
1078  if (DC->isFunctionOrMethod()) return;
1079  AppendScope(DC->getParent(), OS);
1080 
1081  if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1082  if (Policy.SuppressUnwrittenScope &&
1083  (NS->isAnonymousNamespace() || NS->isInline()))
1084  return;
1085  if (NS->getIdentifier())
1086  OS << NS->getName() << "::";
1087  else
1088  OS << "(anonymous namespace)::";
1089  } else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1090  IncludeStrongLifetimeRAII Strong(Policy);
1091  OS << Spec->getIdentifier()->getName();
1092  const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1093  printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
1094  OS << "::";
1095  } else if (const auto *Tag = dyn_cast<TagDecl>(DC)) {
1096  if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
1097  OS << Typedef->getIdentifier()->getName() << "::";
1098  else if (Tag->getIdentifier())
1099  OS << Tag->getIdentifier()->getName() << "::";
1100  else
1101  return;
1102  }
1103 }
1104 
1105 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
1106  if (Policy.IncludeTagDefinition) {
1107  PrintingPolicy SubPolicy = Policy;
1108  SubPolicy.IncludeTagDefinition = false;
1109  D->print(OS, SubPolicy, Indentation);
1110  spaceBeforePlaceHolder(OS);
1111  return;
1112  }
1113 
1114  bool HasKindDecoration = false;
1115 
1116  // We don't print tags unless this is an elaborated type.
1117  // In C, we just assume every RecordType is an elaborated type.
1118  if (!Policy.SuppressTagKeyword && !D->getTypedefNameForAnonDecl()) {
1119  HasKindDecoration = true;
1120  OS << D->getKindName();
1121  OS << ' ';
1122  }
1123 
1124  // Compute the full nested-name-specifier for this type.
1125  // In C, this will always be empty except when the type
1126  // being printed is anonymous within other Record.
1127  if (!Policy.SuppressScope)
1128  AppendScope(D->getDeclContext(), OS);
1129 
1130  if (const IdentifierInfo *II = D->getIdentifier())
1131  OS << II->getName();
1132  else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
1133  assert(Typedef->getIdentifier() && "Typedef without identifier?");
1134  OS << Typedef->getIdentifier()->getName();
1135  } else {
1136  // Make an unambiguous representation for anonymous types, e.g.
1137  // (anonymous enum at /usr/include/string.h:120:9)
1138  OS << (Policy.MSVCFormatting ? '`' : '(');
1139 
1140  if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
1141  OS << "lambda";
1142  HasKindDecoration = true;
1143  } else {
1144  OS << "anonymous";
1145  }
1146 
1147  if (Policy.AnonymousTagLocations) {
1148  // Suppress the redundant tag keyword if we just printed one.
1149  // We don't have to worry about ElaboratedTypes here because you can't
1150  // refer to an anonymous type with one.
1151  if (!HasKindDecoration)
1152  OS << " " << D->getKindName();
1153 
1155  D->getLocation());
1156  if (PLoc.isValid()) {
1157  OS << " at " << PLoc.getFilename()
1158  << ':' << PLoc.getLine()
1159  << ':' << PLoc.getColumn();
1160  }
1161  }
1162 
1163  OS << (Policy.MSVCFormatting ? '\'' : ')');
1164  }
1165 
1166  // If this is a class template specialization, print the template
1167  // arguments.
1168  if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1170  if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) {
1171  const TemplateSpecializationType *TST =
1172  cast<TemplateSpecializationType>(TAW->getType());
1173  Args = TST->template_arguments();
1174  } else {
1175  const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1176  Args = TemplateArgs.asArray();
1177  }
1178  IncludeStrongLifetimeRAII Strong(Policy);
1179  printTemplateArgumentList(OS, Args, Policy);
1180  }
1181 
1182  spaceBeforePlaceHolder(OS);
1183 }
1184 
1185 void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
1186  printTag(T->getDecl(), OS);
1187 }
1188 
1189 void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) {}
1190 
1191 void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) {
1192  printTag(T->getDecl(), OS);
1193 }
1194 
1195 void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) {}
1196 
1197 void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T,
1198  raw_ostream &OS) {
1199  if (IdentifierInfo *Id = T->getIdentifier())
1200  OS << Id->getName();
1201  else
1202  OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex();
1203  spaceBeforePlaceHolder(OS);
1204 }
1205 
1206 void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T,
1207  raw_ostream &OS) {}
1208 
1209 void TypePrinter::printSubstTemplateTypeParmBefore(
1210  const SubstTemplateTypeParmType *T,
1211  raw_ostream &OS) {
1212  IncludeStrongLifetimeRAII Strong(Policy);
1213  printBefore(T->getReplacementType(), OS);
1214 }
1215 
1216 void TypePrinter::printSubstTemplateTypeParmAfter(
1217  const SubstTemplateTypeParmType *T,
1218  raw_ostream &OS) {
1219  IncludeStrongLifetimeRAII Strong(Policy);
1220  printAfter(T->getReplacementType(), OS);
1221 }
1222 
1223 void TypePrinter::printSubstTemplateTypeParmPackBefore(
1225  raw_ostream &OS) {
1226  IncludeStrongLifetimeRAII Strong(Policy);
1227  printTemplateTypeParmBefore(T->getReplacedParameter(), OS);
1228 }
1229 
1230 void TypePrinter::printSubstTemplateTypeParmPackAfter(
1232  raw_ostream &OS) {
1233  IncludeStrongLifetimeRAII Strong(Policy);
1234  printTemplateTypeParmAfter(T->getReplacedParameter(), OS);
1235 }
1236 
1237 void TypePrinter::printTemplateSpecializationBefore(
1238  const TemplateSpecializationType *T,
1239  raw_ostream &OS) {
1240  IncludeStrongLifetimeRAII Strong(Policy);
1241  T->getTemplateName().print(OS, Policy);
1242 
1244  spaceBeforePlaceHolder(OS);
1245 }
1246 
1247 void TypePrinter::printTemplateSpecializationAfter(
1248  const TemplateSpecializationType *T,
1249  raw_ostream &OS) {}
1250 
1251 void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T,
1252  raw_ostream &OS) {
1253  printTemplateSpecializationBefore(T->getInjectedTST(), OS);
1254 }
1255 
1256 void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
1257  raw_ostream &OS) {}
1258 
1259 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
1260  raw_ostream &OS) {
1261  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
1262  TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
1263  assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
1264  "OwnedTagDecl expected to be a declaration for the type");
1265  PrintingPolicy SubPolicy = Policy;
1266  SubPolicy.IncludeTagDefinition = false;
1267  OwnedTagDecl->print(OS, SubPolicy, Indentation);
1268  spaceBeforePlaceHolder(OS);
1269  return;
1270  }
1271 
1272  // The tag definition will take care of these.
1273  if (!Policy.IncludeTagDefinition)
1274  {
1276  if (T->getKeyword() != ETK_None)
1277  OS << " ";
1278  NestedNameSpecifier *Qualifier = T->getQualifier();
1279  if (Qualifier)
1280  Qualifier->print(OS, Policy);
1281  }
1282 
1283  ElaboratedTypePolicyRAII PolicyRAII(Policy);
1284  printBefore(T->getNamedType(), OS);
1285 }
1286 
1287 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
1288  raw_ostream &OS) {
1289  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
1290  return;
1291  ElaboratedTypePolicyRAII PolicyRAII(Policy);
1292  printAfter(T->getNamedType(), OS);
1293 }
1294 
1295 void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) {
1296  if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
1297  printBefore(T->getInnerType(), OS);
1298  OS << '(';
1299  } else
1300  printBefore(T->getInnerType(), OS);
1301 }
1302 
1303 void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) {
1304  if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
1305  OS << ')';
1306  printAfter(T->getInnerType(), OS);
1307  } else
1308  printAfter(T->getInnerType(), OS);
1309 }
1310 
1311 void TypePrinter::printDependentNameBefore(const DependentNameType *T,
1312  raw_ostream &OS) {
1314  if (T->getKeyword() != ETK_None)
1315  OS << " ";
1316 
1317  T->getQualifier()->print(OS, Policy);
1318 
1319  OS << T->getIdentifier()->getName();
1320  spaceBeforePlaceHolder(OS);
1321 }
1322 
1323 void TypePrinter::printDependentNameAfter(const DependentNameType *T,
1324  raw_ostream &OS) {}
1325 
1326 void TypePrinter::printDependentTemplateSpecializationBefore(
1327  const DependentTemplateSpecializationType *T, raw_ostream &OS) {
1328  IncludeStrongLifetimeRAII Strong(Policy);
1329 
1331  if (T->getKeyword() != ETK_None)
1332  OS << " ";
1333 
1334  if (T->getQualifier())
1335  T->getQualifier()->print(OS, Policy);
1336  OS << T->getIdentifier()->getName();
1338  spaceBeforePlaceHolder(OS);
1339 }
1340 
1341 void TypePrinter::printDependentTemplateSpecializationAfter(
1342  const DependentTemplateSpecializationType *T, raw_ostream &OS) {}
1343 
1344 void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
1345  raw_ostream &OS) {
1346  printBefore(T->getPattern(), OS);
1347 }
1348 
1349 void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
1350  raw_ostream &OS) {
1351  printAfter(T->getPattern(), OS);
1352  OS << "...";
1353 }
1354 
1355 void TypePrinter::printAttributedBefore(const AttributedType *T,
1356  raw_ostream &OS) {
1357  // Prefer the macro forms of the GC and ownership qualifiers.
1360  return printBefore(T->getEquivalentType(), OS);
1361 
1363  OS << "__kindof ";
1364 
1365  printBefore(T->getModifiedType(), OS);
1366 
1367  if (T->isMSTypeSpec()) {
1368  switch (T->getAttrKind()) {
1369  default: return;
1370  case AttributedType::attr_ptr32: OS << " __ptr32"; break;
1371  case AttributedType::attr_ptr64: OS << " __ptr64"; break;
1372  case AttributedType::attr_sptr: OS << " __sptr"; break;
1373  case AttributedType::attr_uptr: OS << " __uptr"; break;
1374  }
1375  spaceBeforePlaceHolder(OS);
1376  }
1377 
1378  // Print nullability type specifiers.
1383  OS << " _Nonnull";
1384  else if (T->getAttrKind() == AttributedType::attr_nullable)
1385  OS << " _Nullable";
1387  OS << " _Null_unspecified";
1388  else
1389  llvm_unreachable("unhandled nullability");
1390  spaceBeforePlaceHolder(OS);
1391  }
1392 }
1393 
1394 void TypePrinter::printAttributedAfter(const AttributedType *T,
1395  raw_ostream &OS) {
1396  // Prefer the macro forms of the GC and ownership qualifiers.
1399  return printAfter(T->getEquivalentType(), OS);
1400 
1401  // If this is a calling convention attribute, don't print the implicit CC from
1402  // the modified type.
1403  SaveAndRestore<bool> MaybeSuppressCC(InsideCCAttribute, T->isCallingConv());
1404 
1405  printAfter(T->getModifiedType(), OS);
1406 
1407  // Some attributes are printed as qualifiers before the type, so we have
1408  // nothing left to do.
1410  T->isMSTypeSpec() ||
1414  return;
1415 
1416  // Don't print the inert __unsafe_unretained attribute at all.
1418  return;
1419 
1420  // Don't print ns_returns_retained unless it had an effect.
1423  ->getExtInfo().getProducesResult())
1424  return;
1425 
1427  OS << " [[clang::lifetimebound]]";
1428  return;
1429  }
1430 
1431  OS << " __attribute__((";
1432  switch (T->getAttrKind()) {
1445  llvm_unreachable("This attribute should have been handled already");
1446 
1448  OS << "address_space(";
1449  // FIXME: printing the raw LangAS value is wrong. This should probably
1450  // use the same code as Qualifiers::print()
1451  OS << (unsigned)T->getEquivalentType().getAddressSpace();
1452  OS << ')';
1453  break;
1454 
1456  OS << "__vector_size__(";
1457  if (const auto *vector = T->getEquivalentType()->getAs<VectorType>()) {
1458  OS << vector->getNumElements();
1459  OS << " * sizeof(";
1460  print(vector->getElementType(), OS, StringRef());
1461  OS << ')';
1462  }
1463  OS << ')';
1464  break;
1465 
1469  OS << "neon_vector_type(";
1470  else
1471  OS << "neon_polyvector_type(";
1472  const auto *vector = T->getEquivalentType()->getAs<VectorType>();
1473  OS << vector->getNumElements();
1474  OS << ')';
1475  break;
1476  }
1477 
1479  // FIXME: When Sema learns to form this AttributedType, avoid printing the
1480  // attribute again in printFunctionProtoAfter.
1481  OS << "regparm(";
1482  QualType t = T->getEquivalentType();
1483  while (!t->isFunctionType())
1484  t = t->getPointeeType();
1485  OS << t->getAs<FunctionType>()->getRegParmType();
1486  OS << ')';
1487  break;
1488  }
1489 
1491  OS << "ns_returns_retained";
1492  break;
1493 
1494  // FIXME: When Sema learns to form this AttributedType, avoid printing the
1495  // attribute again in printFunctionProtoAfter.
1496  case AttributedType::attr_noreturn: OS << "noreturn"; break;
1497  case AttributedType::attr_nocf_check: OS << "nocf_check"; break;
1498  case AttributedType::attr_cdecl: OS << "cdecl"; break;
1499  case AttributedType::attr_fastcall: OS << "fastcall"; break;
1500  case AttributedType::attr_stdcall: OS << "stdcall"; break;
1501  case AttributedType::attr_thiscall: OS << "thiscall"; break;
1502  case AttributedType::attr_swiftcall: OS << "swiftcall"; break;
1503  case AttributedType::attr_vectorcall: OS << "vectorcall"; break;
1504  case AttributedType::attr_pascal: OS << "pascal"; break;
1505  case AttributedType::attr_ms_abi: OS << "ms_abi"; break;
1506  case AttributedType::attr_sysv_abi: OS << "sysv_abi"; break;
1507  case AttributedType::attr_regcall: OS << "regcall"; break;
1510  OS << "pcs(";
1511  QualType t = T->getEquivalentType();
1512  while (!t->isFunctionType())
1513  t = t->getPointeeType();
1514  OS << (t->getAs<FunctionType>()->getCallConv() == CC_AAPCS ?
1515  "\"aapcs\"" : "\"aapcs-vfp\"");
1516  OS << ')';
1517  break;
1518  }
1519 
1520  case AttributedType::attr_inteloclbicc: OS << "inteloclbicc"; break;
1522  OS << "preserve_most";
1523  break;
1524 
1526  OS << "preserve_all";
1527  break;
1528  }
1529  OS << "))";
1530 }
1531 
1532 void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
1533  raw_ostream &OS) {
1534  OS << T->getDecl()->getName();
1535  spaceBeforePlaceHolder(OS);
1536 }
1537 
1538 void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T,
1539  raw_ostream &OS) {}
1540 
1541 void TypePrinter::printObjCTypeParamBefore(const ObjCTypeParamType *T,
1542  raw_ostream &OS) {
1543  OS << T->getDecl()->getName();
1544  if (!T->qual_empty()) {
1545  bool isFirst = true;
1546  OS << '<';
1547  for (const auto *I : T->quals()) {
1548  if (isFirst)
1549  isFirst = false;
1550  else
1551  OS << ',';
1552  OS << I->getName();
1553  }
1554  OS << '>';
1555  }
1556 
1557  spaceBeforePlaceHolder(OS);
1558 }
1559 
1560 void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T,
1561  raw_ostream &OS) {}
1562 
1563 void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T,
1564  raw_ostream &OS) {
1565  if (T->qual_empty() && T->isUnspecializedAsWritten() &&
1566  !T->isKindOfTypeAsWritten())
1567  return printBefore(T->getBaseType(), OS);
1568 
1569  if (T->isKindOfTypeAsWritten())
1570  OS << "__kindof ";
1571 
1572  print(T->getBaseType(), OS, StringRef());
1573 
1574  if (T->isSpecializedAsWritten()) {
1575  bool isFirst = true;
1576  OS << '<';
1577  for (auto typeArg : T->getTypeArgsAsWritten()) {
1578  if (isFirst)
1579  isFirst = false;
1580  else
1581  OS << ",";
1582 
1583  print(typeArg, OS, StringRef());
1584  }
1585  OS << '>';
1586  }
1587 
1588  if (!T->qual_empty()) {
1589  bool isFirst = true;
1590  OS << '<';
1591  for (const auto *I : T->quals()) {
1592  if (isFirst)
1593  isFirst = false;
1594  else
1595  OS << ',';
1596  OS << I->getName();
1597  }
1598  OS << '>';
1599  }
1600 
1601  spaceBeforePlaceHolder(OS);
1602 }
1603 
1604 void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1605  raw_ostream &OS) {
1606  if (T->qual_empty() && T->isUnspecializedAsWritten() &&
1607  !T->isKindOfTypeAsWritten())
1608  return printAfter(T->getBaseType(), OS);
1609 }
1610 
1611 void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1612  raw_ostream &OS) {
1613  printBefore(T->getPointeeType(), OS);
1614 
1615  // If we need to print the pointer, print it now.
1616  if (!T->isObjCIdType() && !T->isObjCQualifiedIdType() &&
1617  !T->isObjCClassType() && !T->isObjCQualifiedClassType()) {
1618  if (HasEmptyPlaceHolder)
1619  OS << ' ';
1620  OS << '*';
1621  }
1622 }
1623 
1624 void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
1625  raw_ostream &OS) {}
1626 
1627 static
1628 const TemplateArgument &getArgument(const TemplateArgument &A) { return A; }
1629 
1630 static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) {
1631  return A.getArgument();
1632 }
1633 
1634 template<typename TA>
1635 static void printTo(raw_ostream &OS, ArrayRef<TA> Args,
1636  const PrintingPolicy &Policy, bool SkipBrackets) {
1637  const char *Comma = Policy.MSVCFormatting ? "," : ", ";
1638  if (!SkipBrackets)
1639  OS << '<';
1640 
1641  bool NeedSpace = false;
1642  bool FirstArg = true;
1643  for (const auto &Arg : Args) {
1644  // Print the argument into a string.
1645  SmallString<128> Buf;
1646  llvm::raw_svector_ostream ArgOS(Buf);
1647  const TemplateArgument &Argument = getArgument(Arg);
1648  if (Argument.getKind() == TemplateArgument::Pack) {
1649  if (Argument.pack_size() && !FirstArg)
1650  OS << Comma;
1651  printTo(ArgOS, Argument.getPackAsArray(), Policy, true);
1652  } else {
1653  if (!FirstArg)
1654  OS << Comma;
1655  Argument.print(Policy, ArgOS);
1656  }
1657  StringRef ArgString = ArgOS.str();
1658 
1659  // If this is the first argument and its string representation
1660  // begins with the global scope specifier ('::foo'), add a space
1661  // to avoid printing the diagraph '<:'.
1662  if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
1663  OS << ' ';
1664 
1665  OS << ArgString;
1666 
1667  NeedSpace = (!ArgString.empty() && ArgString.back() == '>');
1668  FirstArg = false;
1669  }
1670 
1671  // If the last character of our string is '>', add another space to
1672  // keep the two '>''s separate tokens. We don't *have* to do this in
1673  // C++0x, but it's still good hygiene.
1674  if (NeedSpace)
1675  OS << ' ';
1676 
1677  if (!SkipBrackets)
1678  OS << '>';
1679 }
1680 
1681 void clang::printTemplateArgumentList(raw_ostream &OS,
1682  const TemplateArgumentListInfo &Args,
1683  const PrintingPolicy &Policy) {
1684  return printTo(OS, Args.arguments(), Policy, false);
1685 }
1686 
1687 void clang::printTemplateArgumentList(raw_ostream &OS,
1688  ArrayRef<TemplateArgument> Args,
1689  const PrintingPolicy &Policy) {
1690  printTo(OS, Args, Policy, false);
1691 }
1692 
1693 void clang::printTemplateArgumentList(raw_ostream &OS,
1694  ArrayRef<TemplateArgumentLoc> Args,
1695  const PrintingPolicy &Policy) {
1696  printTo(OS, Args, Policy, false);
1697 }
1698 
1699 std::string Qualifiers::getAsString() const {
1700  LangOptions LO;
1701  return getAsString(PrintingPolicy(LO));
1702 }
1703 
1704 // Appends qualifiers to the given string, separated by spaces. Will
1705 // prefix a space if the string is non-empty. Will not append a final
1706 // space.
1707 std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
1708  SmallString<64> Buf;
1709  llvm::raw_svector_ostream StrOS(Buf);
1710  print(StrOS, Policy);
1711  return StrOS.str();
1712 }
1713 
1714 bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
1715  if (getCVRQualifiers())
1716  return false;
1717 
1718  if (getAddressSpace() != LangAS::Default)
1719  return false;
1720 
1721  if (getObjCGCAttr())
1722  return false;
1723 
1724  if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
1725  if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
1726  return false;
1727 
1728  return true;
1729 }
1730 
1731 // Appends qualifiers to the given string, separated by spaces. Will
1732 // prefix a space if the string is non-empty. Will not append a final
1733 // space.
1734 void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
1735  bool appendSpaceIfNonEmpty) const {
1736  bool addSpace = false;
1737 
1738  unsigned quals = getCVRQualifiers();
1739  if (quals) {
1740  AppendTypeQualList(OS, quals, Policy.Restrict);
1741  addSpace = true;
1742  }
1743  if (hasUnaligned()) {
1744  if (addSpace)
1745  OS << ' ';
1746  OS << "__unaligned";
1747  addSpace = true;
1748  }
1749  LangAS addrspace = getAddressSpace();
1750  if (addrspace != LangAS::Default) {
1751  if (addrspace != LangAS::opencl_private) {
1752  if (addSpace)
1753  OS << ' ';
1754  addSpace = true;
1755  switch (addrspace) {
1756  case LangAS::opencl_global:
1757  OS << "__global";
1758  break;
1759  case LangAS::opencl_local:
1760  OS << "__local";
1761  break;
1762  case LangAS::opencl_private:
1763  break;
1764  case LangAS::opencl_constant:
1765  case LangAS::cuda_constant:
1766  OS << "__constant";
1767  break;
1768  case LangAS::opencl_generic:
1769  OS << "__generic";
1770  break;
1771  case LangAS::cuda_device:
1772  OS << "__device";
1773  break;
1774  case LangAS::cuda_shared:
1775  OS << "__shared";
1776  break;
1777  default:
1778  OS << "__attribute__((address_space(";
1779  OS << toTargetAddressSpace(addrspace);
1780  OS << ")))";
1781  }
1782  }
1783  }
1784  if (Qualifiers::GC gc = getObjCGCAttr()) {
1785  if (addSpace)
1786  OS << ' ';
1787  addSpace = true;
1788  if (gc == Qualifiers::Weak)
1789  OS << "__weak";
1790  else
1791  OS << "__strong";
1792  }
1793  if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
1794  if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){
1795  if (addSpace)
1796  OS << ' ';
1797  addSpace = true;
1798  }
1799 
1800  switch (lifetime) {
1801  case Qualifiers::OCL_None: llvm_unreachable("none but true");
1802  case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
1803  case Qualifiers::OCL_Strong:
1804  if (!Policy.SuppressStrongLifetime)
1805  OS << "__strong";
1806  break;
1807 
1808  case Qualifiers::OCL_Weak: OS << "__weak"; break;
1809  case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
1810  }
1811  }
1812 
1813  if (appendSpaceIfNonEmpty && addSpace)
1814  OS << ' ';
1815 }
1816 
1817 std::string QualType::getAsString() const {
1818  return getAsString(split(), LangOptions());
1819 }
1820 
1821 std::string QualType::getAsString(const PrintingPolicy &Policy) const {
1822  std::string S;
1823  getAsStringInternal(S, Policy);
1824  return S;
1825 }
1826 
1827 std::string QualType::getAsString(const Type *ty, Qualifiers qs,
1828  const PrintingPolicy &Policy) {
1829  std::string buffer;
1830  getAsStringInternal(ty, qs, buffer, Policy);
1831  return buffer;
1832 }
1833 
1834 void QualType::print(const Type *ty, Qualifiers qs,
1835  raw_ostream &OS, const PrintingPolicy &policy,
1836  const Twine &PlaceHolder, unsigned Indentation) {
1837  SmallString<128> PHBuf;
1838  StringRef PH = PlaceHolder.toStringRef(PHBuf);
1839 
1840  TypePrinter(policy, Indentation).print(ty, qs, OS, PH);
1841 }
1842 
1843 void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
1844  std::string &buffer,
1845  const PrintingPolicy &policy) {
1846  SmallString<256> Buf;
1847  llvm::raw_svector_ostream StrOS(Buf);
1848  TypePrinter(policy).print(ty, qs, StrOS, buffer);
1849  std::string str = StrOS.str();
1850  buffer.swap(str);
1851 }
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:2585
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Definition: Type.h:3470
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:5196
Defines the clang::ASTContext interface.
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it&#39;s either not been deduced or was deduce...
Definition: Type.h:4552
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4949
const Type * Ty
The locally-unqualified type.
Definition: Type.h:581
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool HasRestrictKeyword)
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:4832
StringRef getName(const PrintingPolicy &Policy) const
Definition: Type.cpp:2658
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:3793
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2397
QualType getElementType() const
Definition: Type.h:5837
QualType getPointeeType() const
Definition: Type.h:2410
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
Definition: Type.h:3890
A (possibly-)qualified type.
Definition: Type.h:640
bool getNoCfCheck() const
Definition: Type.h:3289
__auto_type (GNU extension)
Expr * getUnderlyingExpr() const
Definition: Type.h:4025
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3215
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:497
C Language Family Type Representation.
Defines the SourceManager interface.
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5024
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5043
const Type * getTypeForDecl() const
Definition: Decl.h:2873
bool isVariadic() const
Definition: Type.h:3778
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4566
The base class of the type hierarchy.
Definition: Type.h:1413
A container of type source information.
Definition: Decl.h:86
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:5804
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
QualType getElementType() const
Definition: Type.h:2707
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:4620
unsigned getNumParams() const
Definition: Type.h:3672
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6530
Represents a C++17 deduced template specialization type.
Definition: Type.h:4602
bool isCallingConv() const
Definition: Type.cpp:3230
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4421
The collection of all-type qualifiers we support.
Definition: Type.h:139
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
PipeType - OpenCL20.
Definition: Type.h:5823
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
One of these records is kept for each identifier that is lexed.
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS=false) const
Print the template name.
unsigned getRegParm() const
Definition: Type.h:3292
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
QualType getPointeeType() const
Definition: Type.h:2514
is ARM Neon vector
Definition: Type.h:3044
bool isObjCIdType() const
Definition: Type.h:6243
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4728
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:4477
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if none...
Definition: Type.h:4992
bool isObjCQualifiedClassType() const
Definition: Type.h:6237
unsigned getTypeQuals() const
Definition: Type.h:3790
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
bool getProducesResult() const
Definition: Type.h:3287
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2598
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:3901
bool isMSTypeSpec() const
Definition: Type.cpp:3218
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1369
Microsoft throw(...) extension.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Represents a typeof (or typeof) expression (a GCC extension).
Definition: Type.h:3945
const Type * getClass() const
Definition: Type.h:2650
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, const ASTContext *Context=nullptr) const
Expr * getSizeExpr() const
Definition: Type.h:2851
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5893
bool getNoReturn() const
Definition: Type.h:3286
is ARM Neon polynomial vector
Definition: Type.h:3047
Expr * getSizeExpr() const
Definition: Type.h:2908
bool getNoCallerSavedRegs() const
Definition: Type.h:3288
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2552
Expr * getSizeExpr() const
Definition: Type.h:3118
QualType getElementType() const
Definition: Type.h:3004
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:2988
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3401
Expr * getAddrSpaceExpr() const
Definition: Type.h:2959
Provides definitions for the various language-specific address spaces.
llvm::StringRef getParameterABISpelling(ParameterABI kind)
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3436
qual_range quals() const
Definition: Type.h:5259
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:5328
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:2886
bool isValid() const
QualType getElementType() const
Definition: Type.h:2350
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
Definition: PrettyPrinter.h:94
IdentifierInfo * getIdentifier() const
Definition: Type.cpp:3278
Defines the clang::LangOptions interface.
StringRef getKindName() const
Definition: Decl.h:3218
int Id
Definition: ASTDiff.cpp:191
unsigned getIndex() const
Definition: Type.h:4384
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6593
unsigned getLine() const
Return the presumed line number of this location.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
bool isObjCClassType() const
Definition: Type.h:6249
DeclContext * getDeclContext()
Definition: DeclBase.h:434
QualType getBaseType() const
Definition: Type.h:4084
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:5050
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:264
Represents the type decltype(expr) (C++11).
Definition: Type.h:4015
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:579
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isFunctionOrMethod() const
Definition: DeclBase.h:1817
A unary type transform, which is a type constructed from another.
Definition: Type.h:4058
Qualifiers Quals
The local qualifiers.
Definition: Type.h:584
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:2491
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1769
Represents an unpacked "presumed" location which can be presented to the user.
Represents a GCC generic vector type.
Definition: Type.h:3028
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2709
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2580
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Definition: PrettyPrinter.h:84
UTTKind getUTTKind() const
Definition: Type.h:4086
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:705
Expr * getUnderlyingExpr() const
Definition: Type.h:3954
bool hasTrailingReturn() const
Definition: Type.h:3788
bool hasQualifiers() const
Return true if the set contains any qualifiers.
Definition: Type.h:415
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:5901
RecordDecl * getDecl() const
Definition: Type.h:4149
const char * getFilename() const
Return the presumed filename of this location.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
is AltiVec &#39;vector Pixel&#39;
Definition: Type.h:3038
not a target-specific vector type
Definition: Type.h:3032
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:3847
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4910
unsigned getColumn() const
Return the presumed column number of this location.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.h:5572
Sugar for parentheses used when specifying types.
Definition: Type.h:2367
QualType getAdjustedType() const
Definition: Type.h:2462
QualType getReturnType() const
Definition: Type.h:3369
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4165
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6009
Represents typeof(type), a GCC extension.
Definition: Type.h:3988
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5559
unsigned SuppressScope
Suppresses printing of scope specifiers.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3043
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
CallingConv getCC() const
Definition: Type.h:3299
QualType getElementType() const
Definition: Type.h:3063
Represents a vector type where either the type or size is dependent.
Definition: Type.h:3105
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
No ref-qualifier was provided.
Definition: Type.h:1366
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4498
QualType getEquivalentType() const
Definition: Type.h:4269
QualType getInnerType() const
Definition: Type.h:2380
is AltiVec &#39;vector bool ...&#39;
Definition: Type.h:3041
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4979
is AltiVec vector
Definition: Type.h:3035
AutoTypeKeyword getKeyword() const
Definition: Type.h:4581
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2713
TypeClass getTypeClass() const
Definition: Type.h:1695
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5119
EnumDecl * getDecl() const
Definition: Type.h:4172
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1372
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:308
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2482
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4798
QualType getPointeeType() const
Definition: Type.h:2960
Represents a pack expansion of types.
Definition: Type.h:5169
Defines various enumerations that describe declaration and type specifiers.
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2895
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Definition: Type.h:2445
Dataflow Directional Tag Classes.
ExtInfo getExtInfo() const
Definition: Type.h:3380
NestedNameSpecifier * getQualifier() const
Definition: Type.h:5106
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1272
VectorKind getVectorKind() const
Definition: Type.h:3073
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2616
QualType getModifiedType() const
Definition: Type.h:4268
Pointer to a block type.
Definition: Type.h:2499
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4139
Complex values, per C99 6.2.5p11.
Definition: Type.h:2337
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2717
bool empty() const
Definition: Type.h:416
const llvm::APInt & getSize() const
Definition: Type.h:2750
Kind getAttrKind() const
Definition: Type.h:4264
bool isFunctionType() const
Definition: Type.h:6113
bool isObjCQualifiedIdType() const
Definition: Type.h:6231
ExtVectorType - Extended vector type.
Definition: Type.h:3147
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2533
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
QualType getUnderlyingType() const
Definition: Type.h:4003
SourceManager & getSourceManager()
Definition: ASTContext.h:670
A template argument list.
Definition: DeclTemplate.h:210
VectorType::VectorKind getVectorKind() const
Definition: Type.h:3121
TypedefNameDecl * getDecl() const
Definition: Type.h:3936
unsigned getDepth() const
Definition: Type.h:4383
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4194
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getParamType(unsigned i) const
Definition: Type.h:3674
Represents a type parameter type in Objective C.
Definition: Type.h:5285
Defines the clang::SourceLocation class and associated facilities.
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3253
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:5076
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:4742
Represents a C array with an unspecified size.
Definition: Type.h:2786
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:5920
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4982
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4442
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2254
static QualType skipTopLevelReferences(QualType T)
bool qual_empty() const
Definition: Type.h:5263
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
unsigned getNumElements() const
Definition: Type.h:3064
bool isReadOnly() const
Definition: Type.h:5856
Represents an extended address space qualifier where the input address space value is dependent...
Definition: Type.h:2946
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4658
This represents a decl that may have a name.
Definition: Decl.h:248
bool isTranslationUnit() const
Definition: DeclBase.h:1840
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2831
No keyword precedes the qualified type name.
Definition: Type.h:4891
QualType getElementType() const
Definition: Type.h:3119
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2732
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3240
SourceLocation getLocation() const
Definition: DeclBase.h:425
QualType getPointeeType() const
Definition: Type.h:2636
This parameter (which must have pointer type) is a Swift indirect result parameter.
const IdentifierInfo * getIdentifier() const
Definition: Type.h:5107