clang  5.0.0
DeclPrinter.cpp
Go to the documentation of this file.
1 //===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
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 file implements the Decl::print method, which pretty prints the
11 // AST back out to C/Objective-C/C++/Objective-C++ code.
12 //
13 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclVisitor.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.h"
23 #include "clang/Basic/Module.h"
24 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
26 
27 namespace {
28  class DeclPrinter : public DeclVisitor<DeclPrinter> {
29  raw_ostream &Out;
30  PrintingPolicy Policy;
31  unsigned Indentation;
32  bool PrintInstantiation;
33 
34  raw_ostream& Indent() { return Indent(Indentation); }
35  raw_ostream& Indent(unsigned Indentation);
36  void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls);
37 
38  void Print(AccessSpecifier AS);
39 
40  /// Print an Objective-C method type in parentheses.
41  ///
42  /// \param Quals The Objective-C declaration qualifiers.
43  /// \param T The type to print.
44  void PrintObjCMethodType(ASTContext &Ctx, Decl::ObjCDeclQualifier Quals,
45  QualType T);
46 
47  void PrintObjCTypeParams(ObjCTypeParamList *Params);
48 
49  public:
50  DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy,
51  unsigned Indentation = 0, bool PrintInstantiation = false)
52  : Out(Out), Policy(Policy), Indentation(Indentation),
53  PrintInstantiation(PrintInstantiation) { }
54 
55  void VisitDeclContext(DeclContext *DC, bool Indent = true);
56 
57  void VisitTranslationUnitDecl(TranslationUnitDecl *D);
58  void VisitTypedefDecl(TypedefDecl *D);
59  void VisitTypeAliasDecl(TypeAliasDecl *D);
60  void VisitEnumDecl(EnumDecl *D);
61  void VisitRecordDecl(RecordDecl *D);
62  void VisitEnumConstantDecl(EnumConstantDecl *D);
63  void VisitEmptyDecl(EmptyDecl *D);
64  void VisitFunctionDecl(FunctionDecl *D);
65  void VisitFriendDecl(FriendDecl *D);
66  void VisitFieldDecl(FieldDecl *D);
67  void VisitVarDecl(VarDecl *D);
68  void VisitLabelDecl(LabelDecl *D);
69  void VisitParmVarDecl(ParmVarDecl *D);
70  void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
71  void VisitImportDecl(ImportDecl *D);
72  void VisitStaticAssertDecl(StaticAssertDecl *D);
73  void VisitNamespaceDecl(NamespaceDecl *D);
74  void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
75  void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
76  void VisitCXXRecordDecl(CXXRecordDecl *D);
77  void VisitLinkageSpecDecl(LinkageSpecDecl *D);
78  void VisitTemplateDecl(const TemplateDecl *D);
79  void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
80  void VisitClassTemplateDecl(ClassTemplateDecl *D);
81  void VisitClassTemplateSpecializationDecl(
83  void VisitClassTemplatePartialSpecializationDecl(
85  void VisitObjCMethodDecl(ObjCMethodDecl *D);
86  void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
87  void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
88  void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
89  void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
90  void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
91  void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
92  void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
93  void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
94  void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
95  void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
96  void VisitUsingDecl(UsingDecl *D);
97  void VisitUsingShadowDecl(UsingShadowDecl *D);
98  void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
99  void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
100  void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
101 
102  void printTemplateParameters(const TemplateParameterList *Params);
103  void printTemplateArguments(const TemplateArgumentList &Args,
104  const TemplateParameterList *Params = nullptr);
105  void prettyPrintAttributes(Decl *D);
106  void prettyPrintPragmas(Decl *D);
107  void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
108  };
109 }
110 
111 void Decl::print(raw_ostream &Out, unsigned Indentation,
112  bool PrintInstantiation) const {
113  print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
114 }
115 
116 void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
117  unsigned Indentation, bool PrintInstantiation) const {
118  DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation);
119  Printer.Visit(const_cast<Decl*>(this));
120 }
121 
123  // FIXME: This should be on the Type class!
124  QualType BaseType = T;
125  while (!BaseType->isSpecifierType()) {
126  if (isa<TypedefType>(BaseType))
127  break;
128  else if (const PointerType* PTy = BaseType->getAs<PointerType>())
129  BaseType = PTy->getPointeeType();
130  else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
131  BaseType = BPy->getPointeeType();
132  else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
133  BaseType = ATy->getElementType();
134  else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
135  BaseType = FTy->getReturnType();
136  else if (const VectorType *VTy = BaseType->getAs<VectorType>())
137  BaseType = VTy->getElementType();
138  else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
139  BaseType = RTy->getPointeeType();
140  else if (const AutoType *ATy = BaseType->getAs<AutoType>())
141  BaseType = ATy->getDeducedType();
142  else
143  llvm_unreachable("Unknown declarator!");
144  }
145  return BaseType;
146 }
147 
149  if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
150  return TDD->getUnderlyingType();
151  if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
152  return VD->getType();
153  return QualType();
154 }
155 
156 void Decl::printGroup(Decl** Begin, unsigned NumDecls,
157  raw_ostream &Out, const PrintingPolicy &Policy,
158  unsigned Indentation) {
159  if (NumDecls == 1) {
160  (*Begin)->print(Out, Policy, Indentation);
161  return;
162  }
163 
164  Decl** End = Begin + NumDecls;
165  TagDecl* TD = dyn_cast<TagDecl>(*Begin);
166  if (TD)
167  ++Begin;
168 
169  PrintingPolicy SubPolicy(Policy);
170 
171  bool isFirst = true;
172  for ( ; Begin != End; ++Begin) {
173  if (isFirst) {
174  if(TD)
175  SubPolicy.IncludeTagDefinition = true;
176  SubPolicy.SuppressSpecifiers = false;
177  isFirst = false;
178  } else {
179  if (!isFirst) Out << ", ";
180  SubPolicy.IncludeTagDefinition = false;
181  SubPolicy.SuppressSpecifiers = true;
182  }
183 
184  (*Begin)->print(Out, SubPolicy, Indentation);
185  }
186 }
187 
188 LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
189  // Get the translation unit
190  const DeclContext *DC = this;
191  while (!DC->isTranslationUnit())
192  DC = DC->getParent();
193 
194  ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
195  DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0);
196  Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
197 }
198 
199 raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
200  for (unsigned i = 0; i != Indentation; ++i)
201  Out << " ";
202  return Out;
203 }
204 
205 void DeclPrinter::prettyPrintAttributes(Decl *D) {
206  if (Policy.PolishForDeclaration)
207  return;
208 
209  if (D->hasAttrs()) {
210  AttrVec &Attrs = D->getAttrs();
211  for (auto *A : Attrs) {
212  switch (A->getKind()) {
213 #define ATTR(X)
214 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
215 #include "clang/Basic/AttrList.inc"
216  break;
217  default:
218  A->printPretty(Out, Policy);
219  break;
220  }
221  }
222  }
223 }
224 
225 void DeclPrinter::prettyPrintPragmas(Decl *D) {
226  if (Policy.PolishForDeclaration)
227  return;
228 
229  if (D->hasAttrs()) {
230  AttrVec &Attrs = D->getAttrs();
231  for (auto *A : Attrs) {
232  switch (A->getKind()) {
233 #define ATTR(X)
234 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
235 #include "clang/Basic/AttrList.inc"
236  A->printPretty(Out, Policy);
237  Indent();
238  break;
239  default:
240  break;
241  }
242  }
243  }
244 }
245 
246 void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
247  // Normally, a PackExpansionType is written as T[3]... (for instance, as a
248  // template argument), but if it is the type of a declaration, the ellipsis
249  // is placed before the name being declared.
250  if (auto *PET = T->getAs<PackExpansionType>()) {
251  Pack = true;
252  T = PET->getPattern();
253  }
254  T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
255 }
256 
257 void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
258  this->Indent();
259  Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
260  Out << ";\n";
261  Decls.clear();
262 
263 }
264 
265 void DeclPrinter::Print(AccessSpecifier AS) {
266  switch(AS) {
267  case AS_none: llvm_unreachable("No access specifier!");
268  case AS_public: Out << "public"; break;
269  case AS_protected: Out << "protected"; break;
270  case AS_private: Out << "private"; break;
271  }
272 }
273 
274 //----------------------------------------------------------------------------
275 // Common C declarations
276 //----------------------------------------------------------------------------
277 
278 void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
279  if (Policy.TerseOutput)
280  return;
281 
282  if (Indent)
283  Indentation += Policy.Indentation;
284 
285  SmallVector<Decl*, 2> Decls;
286  for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
287  D != DEnd; ++D) {
288 
289  // Don't print ObjCIvarDecls, as they are printed when visiting the
290  // containing ObjCInterfaceDecl.
291  if (isa<ObjCIvarDecl>(*D))
292  continue;
293 
294  // Skip over implicit declarations in pretty-printing mode.
295  if (D->isImplicit())
296  continue;
297 
298  // Don't print implicit specializations, as they are printed when visiting
299  // corresponding templates.
300  if (auto FD = dyn_cast<FunctionDecl>(*D))
301  if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation &&
302  !isa<ClassTemplateSpecializationDecl>(DC))
303  continue;
304 
305  // The next bits of code handles stuff like "struct {int x;} a,b"; we're
306  // forced to merge the declarations because there's no other way to
307  // refer to the struct in question. This limited merging is safe without
308  // a bunch of other checks because it only merges declarations directly
309  // referring to the tag, not typedefs.
310  //
311  // Check whether the current declaration should be grouped with a previous
312  // unnamed struct.
313  QualType CurDeclType = getDeclType(*D);
314  if (!Decls.empty() && !CurDeclType.isNull()) {
315  QualType BaseType = GetBaseType(CurDeclType);
316  if (!BaseType.isNull() && isa<ElaboratedType>(BaseType))
317  BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
318  if (!BaseType.isNull() && isa<TagType>(BaseType) &&
319  cast<TagType>(BaseType)->getDecl() == Decls[0]) {
320  Decls.push_back(*D);
321  continue;
322  }
323  }
324 
325  // If we have a merged group waiting to be handled, handle it now.
326  if (!Decls.empty())
327  ProcessDeclGroup(Decls);
328 
329  // If the current declaration is an unnamed tag type, save it
330  // so we can merge it with the subsequent declaration(s) using it.
331  if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
332  Decls.push_back(*D);
333  continue;
334  }
335 
336  if (isa<AccessSpecDecl>(*D)) {
337  Indentation -= Policy.Indentation;
338  this->Indent();
339  Print(D->getAccess());
340  Out << ":\n";
341  Indentation += Policy.Indentation;
342  continue;
343  }
344 
345  this->Indent();
346  Visit(*D);
347 
348  // FIXME: Need to be able to tell the DeclPrinter when
349  const char *Terminator = nullptr;
350  if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D))
351  Terminator = nullptr;
352  else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
353  Terminator = nullptr;
354  else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
355  if (FD->isThisDeclarationADefinition())
356  Terminator = nullptr;
357  else
358  Terminator = ";";
359  } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
360  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
361  Terminator = nullptr;
362  else
363  Terminator = ";";
364  } else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
365  isa<ObjCImplementationDecl>(*D) ||
366  isa<ObjCInterfaceDecl>(*D) ||
367  isa<ObjCProtocolDecl>(*D) ||
368  isa<ObjCCategoryImplDecl>(*D) ||
369  isa<ObjCCategoryDecl>(*D))
370  Terminator = nullptr;
371  else if (isa<EnumConstantDecl>(*D)) {
373  ++Next;
374  if (Next != DEnd)
375  Terminator = ",";
376  } else
377  Terminator = ";";
378 
379  if (Terminator)
380  Out << Terminator;
381  if (!Policy.TerseOutput &&
382  ((isa<FunctionDecl>(*D) &&
383  cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
384  (isa<FunctionTemplateDecl>(*D) &&
385  cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
386  ; // StmtPrinter already added '\n' after CompoundStmt.
387  else
388  Out << "\n";
389 
390  // Declare target attribute is special one, natural spelling for the pragma
391  // assumes "ending" construct so print it here.
392  if (D->hasAttr<OMPDeclareTargetDeclAttr>())
393  Out << "#pragma omp end declare target\n";
394  }
395 
396  if (!Decls.empty())
397  ProcessDeclGroup(Decls);
398 
399  if (Indent)
400  Indentation -= Policy.Indentation;
401 }
402 
403 void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
404  VisitDeclContext(D, false);
405 }
406 
407 void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
408  if (!Policy.SuppressSpecifiers) {
409  Out << "typedef ";
410 
411  if (D->isModulePrivate())
412  Out << "__module_private__ ";
413  }
414  QualType Ty = D->getTypeSourceInfo()->getType();
415  Ty.print(Out, Policy, D->getName(), Indentation);
416  prettyPrintAttributes(D);
417 }
418 
419 void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
420  Out << "using " << *D;
421  prettyPrintAttributes(D);
422  Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
423 }
424 
425 void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
426  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
427  Out << "__module_private__ ";
428  Out << "enum ";
429  if (D->isScoped()) {
430  if (D->isScopedUsingClassTag())
431  Out << "class ";
432  else
433  Out << "struct ";
434  }
435  Out << *D;
436 
437  if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11)
438  Out << " : " << D->getIntegerType().stream(Policy);
439 
440  if (D->isCompleteDefinition()) {
441  Out << " {\n";
442  VisitDeclContext(D);
443  Indent() << "}";
444  }
445  prettyPrintAttributes(D);
446 }
447 
448 void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
449  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
450  Out << "__module_private__ ";
451  Out << D->getKindName();
452 
453  prettyPrintAttributes(D);
454 
455  if (D->getIdentifier())
456  Out << ' ' << *D;
457 
458  if (D->isCompleteDefinition()) {
459  Out << " {\n";
460  VisitDeclContext(D);
461  Indent() << "}";
462  }
463 }
464 
465 void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
466  Out << *D;
467  prettyPrintAttributes(D);
468  if (Expr *Init = D->getInitExpr()) {
469  Out << " = ";
470  Init->printPretty(Out, nullptr, Policy, Indentation);
471  }
472 }
473 
474 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
475  if (!D->getDescribedFunctionTemplate() &&
477  prettyPrintPragmas(D);
478 
480  Out << "template<> ";
481  else if (!D->getDescribedFunctionTemplate()) {
482  for (unsigned I = 0, NumTemplateParams = D->getNumTemplateParameterLists();
483  I < NumTemplateParams; ++I)
484  printTemplateParameters(D->getTemplateParameterList(I));
485  }
486 
487  CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
488  CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
489  CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D);
490  if (!Policy.SuppressSpecifiers) {
491  switch (D->getStorageClass()) {
492  case SC_None: break;
493  case SC_Extern: Out << "extern "; break;
494  case SC_Static: Out << "static "; break;
495  case SC_PrivateExtern: Out << "__private_extern__ "; break;
496  case SC_Auto: case SC_Register:
497  llvm_unreachable("invalid for functions");
498  }
499 
500  if (D->isInlineSpecified()) Out << "inline ";
501  if (D->isVirtualAsWritten()) Out << "virtual ";
502  if (D->isModulePrivate()) Out << "__module_private__ ";
503  if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr ";
504  if ((CDecl && CDecl->isExplicitSpecified()) ||
505  (ConversionDecl && ConversionDecl->isExplicitSpecified()) ||
506  (GuideDecl && GuideDecl->isExplicitSpecified()))
507  Out << "explicit ";
508  }
509 
510  PrintingPolicy SubPolicy(Policy);
511  SubPolicy.SuppressSpecifiers = false;
512  std::string Proto;
513  if (!Policy.SuppressScope) {
514  if (const NestedNameSpecifier *NS = D->getQualifier()) {
515  llvm::raw_string_ostream OS(Proto);
516  NS->print(OS, Policy);
517  }
518  }
519  Proto += D->getNameInfo().getAsString();
520  if (GuideDecl)
521  Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
522  if (const TemplateArgumentList *TArgs = D->getTemplateSpecializationArgs()) {
523  llvm::raw_string_ostream POut(Proto);
524  DeclPrinter TArgPrinter(POut, SubPolicy, Indentation);
525  TArgPrinter.printTemplateArguments(*TArgs);
526  }
527 
528  QualType Ty = D->getType();
529  while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
530  Proto = '(' + Proto + ')';
531  Ty = PT->getInnerType();
532  }
533 
534  if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
535  const FunctionProtoType *FT = nullptr;
536  if (D->hasWrittenPrototype())
537  FT = dyn_cast<FunctionProtoType>(AFT);
538 
539  Proto += "(";
540  if (FT) {
541  llvm::raw_string_ostream POut(Proto);
542  DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
543  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
544  if (i) POut << ", ";
545  ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
546  }
547 
548  if (FT->isVariadic()) {
549  if (D->getNumParams()) POut << ", ";
550  POut << "...";
551  }
552  } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
553  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
554  if (i)
555  Proto += ", ";
556  Proto += D->getParamDecl(i)->getNameAsString();
557  }
558  }
559 
560  Proto += ")";
561 
562  if (FT) {
563  if (FT->isConst())
564  Proto += " const";
565  if (FT->isVolatile())
566  Proto += " volatile";
567  if (FT->isRestrict())
568  Proto += " restrict";
569 
570  switch (FT->getRefQualifier()) {
571  case RQ_None:
572  break;
573  case RQ_LValue:
574  Proto += " &";
575  break;
576  case RQ_RValue:
577  Proto += " &&";
578  break;
579  }
580  }
581 
582  if (FT && FT->hasDynamicExceptionSpec()) {
583  Proto += " throw(";
584  if (FT->getExceptionSpecType() == EST_MSAny)
585  Proto += "...";
586  else
587  for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
588  if (I)
589  Proto += ", ";
590 
591  Proto += FT->getExceptionType(I).getAsString(SubPolicy);
592  }
593  Proto += ")";
594  } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
595  Proto += " noexcept";
597  Proto += "(";
598  llvm::raw_string_ostream EOut(Proto);
599  FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
600  Indentation);
601  EOut.flush();
602  Proto += EOut.str();
603  Proto += ")";
604  }
605  }
606 
607  if (CDecl) {
608  bool HasInitializerList = false;
609  for (const auto *BMInitializer : CDecl->inits()) {
610  if (BMInitializer->isInClassMemberInitializer())
611  continue;
612 
613  if (!HasInitializerList) {
614  Proto += " : ";
615  Out << Proto;
616  Proto.clear();
617  HasInitializerList = true;
618  } else
619  Out << ", ";
620 
621  if (BMInitializer->isAnyMemberInitializer()) {
622  FieldDecl *FD = BMInitializer->getAnyMember();
623  Out << *FD;
624  } else {
625  Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
626  }
627 
628  Out << "(";
629  if (!BMInitializer->getInit()) {
630  // Nothing to print
631  } else {
632  Expr *Init = BMInitializer->getInit();
633  if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
634  Init = Tmp->getSubExpr();
635 
636  Init = Init->IgnoreParens();
637 
638  Expr *SimpleInit = nullptr;
639  Expr **Args = nullptr;
640  unsigned NumArgs = 0;
641  if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
642  Args = ParenList->getExprs();
643  NumArgs = ParenList->getNumExprs();
644  } else if (CXXConstructExpr *Construct
645  = dyn_cast<CXXConstructExpr>(Init)) {
646  Args = Construct->getArgs();
647  NumArgs = Construct->getNumArgs();
648  } else
649  SimpleInit = Init;
650 
651  if (SimpleInit)
652  SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
653  else {
654  for (unsigned I = 0; I != NumArgs; ++I) {
655  assert(Args[I] != nullptr && "Expected non-null Expr");
656  if (isa<CXXDefaultArgExpr>(Args[I]))
657  break;
658 
659  if (I)
660  Out << ", ";
661  Args[I]->printPretty(Out, nullptr, Policy, Indentation);
662  }
663  }
664  }
665  Out << ")";
666  if (BMInitializer->isPackExpansion())
667  Out << "...";
668  }
669  } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
670  if (FT && FT->hasTrailingReturn()) {
671  if (!GuideDecl)
672  Out << "auto ";
673  Out << Proto << " -> ";
674  Proto.clear();
675  }
676  AFT->getReturnType().print(Out, Policy, Proto);
677  Proto.clear();
678  }
679  Out << Proto;
680  } else {
681  Ty.print(Out, Policy, Proto);
682  }
683 
684  prettyPrintAttributes(D);
685 
686  if (D->isPure())
687  Out << " = 0";
688  else if (D->isDeletedAsWritten())
689  Out << " = delete";
690  else if (D->isExplicitlyDefaulted())
691  Out << " = default";
692  else if (D->doesThisDeclarationHaveABody()) {
693  if (!Policy.TerseOutput) {
694  if (!D->hasPrototype() && D->getNumParams()) {
695  // This is a K&R function definition, so we need to print the
696  // parameters.
697  Out << '\n';
698  DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
699  Indentation += Policy.Indentation;
700  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
701  Indent();
702  ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
703  Out << ";\n";
704  }
705  Indentation -= Policy.Indentation;
706  } else
707  Out << ' ';
708 
709  if (D->getBody())
710  D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation);
711  } else {
712  if (isa<CXXConstructorDecl>(*D))
713  Out << " {}";
714  }
715  }
716 }
717 
718 void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
719  if (TypeSourceInfo *TSI = D->getFriendType()) {
720  unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
721  for (unsigned i = 0; i < NumTPLists; ++i)
722  printTemplateParameters(D->getFriendTypeTemplateParameterList(i));
723  Out << "friend ";
724  Out << " " << TSI->getType().getAsString(Policy);
725  }
726  else if (FunctionDecl *FD =
727  dyn_cast<FunctionDecl>(D->getFriendDecl())) {
728  Out << "friend ";
729  VisitFunctionDecl(FD);
730  }
731  else if (FunctionTemplateDecl *FTD =
732  dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
733  Out << "friend ";
734  VisitFunctionTemplateDecl(FTD);
735  }
736  else if (ClassTemplateDecl *CTD =
737  dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
738  Out << "friend ";
739  VisitRedeclarableTemplateDecl(CTD);
740  }
741 }
742 
743 void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
744  // FIXME: add printing of pragma attributes if required.
745  if (!Policy.SuppressSpecifiers && D->isMutable())
746  Out << "mutable ";
747  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
748  Out << "__module_private__ ";
749 
751  stream(Policy, D->getName(), Indentation);
752 
753  if (D->isBitField()) {
754  Out << " : ";
755  D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation);
756  }
757 
758  Expr *Init = D->getInClassInitializer();
759  if (!Policy.SuppressInitializers && Init) {
761  Out << " ";
762  else
763  Out << " = ";
764  Init->printPretty(Out, nullptr, Policy, Indentation);
765  }
766  prettyPrintAttributes(D);
767 }
768 
769 void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
770  Out << *D << ":";
771 }
772 
773 void DeclPrinter::VisitVarDecl(VarDecl *D) {
774  prettyPrintPragmas(D);
775 
776  QualType T = D->getTypeSourceInfo()
777  ? D->getTypeSourceInfo()->getType()
779 
780  if (!Policy.SuppressSpecifiers) {
781  StorageClass SC = D->getStorageClass();
782  if (SC != SC_None)
783  Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
784 
785  switch (D->getTSCSpec()) {
786  case TSCS_unspecified:
787  break;
788  case TSCS___thread:
789  Out << "__thread ";
790  break;
791  case TSCS__Thread_local:
792  Out << "_Thread_local ";
793  break;
794  case TSCS_thread_local:
795  Out << "thread_local ";
796  break;
797  }
798 
799  if (D->isModulePrivate())
800  Out << "__module_private__ ";
801 
802  if (D->isConstexpr()) {
803  Out << "constexpr ";
804  T.removeLocalConst();
805  }
806  }
807 
808  printDeclType(T, D->getName());
809  Expr *Init = D->getInit();
810  if (!Policy.SuppressInitializers && Init) {
811  bool ImplicitInit = false;
812  if (CXXConstructExpr *Construct =
813  dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
814  if (D->getInitStyle() == VarDecl::CallInit &&
815  !Construct->isListInitialization()) {
816  ImplicitInit = Construct->getNumArgs() == 0 ||
817  Construct->getArg(0)->isDefaultArgument();
818  }
819  }
820  if (!ImplicitInit) {
821  if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
822  Out << "(";
823  else if (D->getInitStyle() == VarDecl::CInit) {
824  Out << " = ";
825  }
826  PrintingPolicy SubPolicy(Policy);
827  SubPolicy.SuppressSpecifiers = false;
828  SubPolicy.IncludeTagDefinition = false;
829  Init->printPretty(Out, nullptr, SubPolicy, Indentation);
830  if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
831  Out << ")";
832  }
833  }
834  prettyPrintAttributes(D);
835 }
836 
837 void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
838  VisitVarDecl(D);
839 }
840 
841 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
842  Out << "__asm (";
843  D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation);
844  Out << ")";
845 }
846 
847 void DeclPrinter::VisitImportDecl(ImportDecl *D) {
848  Out << "@import " << D->getImportedModule()->getFullModuleName()
849  << ";\n";
850 }
851 
852 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
853  Out << "static_assert(";
854  D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation);
855  if (StringLiteral *SL = D->getMessage()) {
856  Out << ", ";
857  SL->printPretty(Out, nullptr, Policy, Indentation);
858  }
859  Out << ")";
860 }
861 
862 //----------------------------------------------------------------------------
863 // C++ declarations
864 //----------------------------------------------------------------------------
865 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
866  if (D->isInline())
867  Out << "inline ";
868  Out << "namespace " << *D << " {\n";
869  VisitDeclContext(D);
870  Indent() << "}";
871 }
872 
873 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
874  Out << "using namespace ";
875  if (D->getQualifier())
876  D->getQualifier()->print(Out, Policy);
877  Out << *D->getNominatedNamespaceAsWritten();
878 }
879 
880 void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
881  Out << "namespace " << *D << " = ";
882  if (D->getQualifier())
883  D->getQualifier()->print(Out, Policy);
884  Out << *D->getAliasedNamespace();
885 }
886 
887 void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
888  prettyPrintAttributes(D);
889 }
890 
891 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
892  // FIXME: add printing of pragma attributes if required.
893  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
894  Out << "__module_private__ ";
895  Out << D->getKindName();
896 
897  prettyPrintAttributes(D);
898 
899  if (D->getIdentifier()) {
900  Out << ' ' << *D;
901 
902  if (auto S = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
903  printTemplateArguments(S->getTemplateArgs(), S->getTemplateParameters());
904  else if (auto S = dyn_cast<ClassTemplateSpecializationDecl>(D))
905  printTemplateArguments(S->getTemplateArgs());
906  }
907 
908  if (D->isCompleteDefinition()) {
909  // Print the base classes
910  if (D->getNumBases()) {
911  Out << " : ";
912  for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
913  BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
914  if (Base != D->bases_begin())
915  Out << ", ";
916 
917  if (Base->isVirtual())
918  Out << "virtual ";
919 
920  AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
921  if (AS != AS_none) {
922  Print(AS);
923  Out << " ";
924  }
925  Out << Base->getType().getAsString(Policy);
926 
927  if (Base->isPackExpansion())
928  Out << "...";
929  }
930  }
931 
932  // Print the class definition
933  // FIXME: Doesn't print access specifiers, e.g., "public:"
934  if (Policy.TerseOutput) {
935  Out << " {}";
936  } else {
937  Out << " {\n";
938  VisitDeclContext(D);
939  Indent() << "}";
940  }
941  }
942 }
943 
944 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
945  const char *l;
947  l = "C";
948  else {
949  assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
950  "unknown language in linkage specification");
951  l = "C++";
952  }
953 
954  Out << "extern \"" << l << "\" ";
955  if (D->hasBraces()) {
956  Out << "{\n";
957  VisitDeclContext(D);
958  Indent() << "}";
959  } else
960  Visit(*D->decls_begin());
961 }
962 
963 void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {
964  assert(Params);
965 
966  Out << "template <";
967 
968  for (unsigned i = 0, e = Params->size(); i != e; ++i) {
969  if (i != 0)
970  Out << ", ";
971 
972  const Decl *Param = Params->getParam(i);
973  if (auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
974 
975  if (TTP->wasDeclaredWithTypename())
976  Out << "typename ";
977  else
978  Out << "class ";
979 
980  if (TTP->isParameterPack())
981  Out << "...";
982 
983  Out << *TTP;
984 
985  if (TTP->hasDefaultArgument()) {
986  Out << " = ";
987  Out << TTP->getDefaultArgument().getAsString(Policy);
988  };
989  } else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
990  StringRef Name;
991  if (IdentifierInfo *II = NTTP->getIdentifier())
992  Name = II->getName();
993  printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
994 
995  if (NTTP->hasDefaultArgument()) {
996  Out << " = ";
997  NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy,
998  Indentation);
999  }
1000  } else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1001  VisitTemplateDecl(TTPD);
1002  // FIXME: print the default argument, if present.
1003  }
1004  }
1005 
1006  Out << "> ";
1007 }
1008 
1009 void DeclPrinter::printTemplateArguments(const TemplateArgumentList &Args,
1010  const TemplateParameterList *Params) {
1011  Out << "<";
1012  for (size_t I = 0, E = Args.size(); I < E; ++I) {
1013  const TemplateArgument &A = Args[I];
1014  if (I)
1015  Out << ", ";
1016  if (Params) {
1017  if (A.getKind() == TemplateArgument::Type)
1018  if (auto T = A.getAsType()->getAs<TemplateTypeParmType>()) {
1019  auto P = cast<TemplateTypeParmDecl>(Params->getParam(T->getIndex()));
1020  Out << *P;
1021  continue;
1022  }
1023  if (A.getKind() == TemplateArgument::Template) {
1024  if (auto T = A.getAsTemplate().getAsTemplateDecl())
1025  if (auto TD = dyn_cast<TemplateTemplateParmDecl>(T)) {
1026  auto P = cast<TemplateTemplateParmDecl>(
1027  Params->getParam(TD->getIndex()));
1028  Out << *P;
1029  continue;
1030  }
1031  }
1033  if (auto E = dyn_cast<DeclRefExpr>(A.getAsExpr()))
1034  if (auto N = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) {
1035  auto P = cast<NonTypeTemplateParmDecl>(
1036  Params->getParam(N->getIndex()));
1037  Out << *P;
1038  continue;
1039  }
1040  }
1041  }
1042  A.print(Policy, Out);
1043  }
1044  Out << ">";
1045 }
1046 
1047 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1048  printTemplateParameters(D->getTemplateParameters());
1049 
1050  if (const TemplateTemplateParmDecl *TTP =
1051  dyn_cast<TemplateTemplateParmDecl>(D)) {
1052  Out << "class ";
1053  if (TTP->isParameterPack())
1054  Out << "...";
1055  Out << D->getName();
1056  } else {
1057  Visit(D->getTemplatedDecl());
1058  }
1059 }
1060 
1061 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1062  prettyPrintPragmas(D->getTemplatedDecl());
1063  // Print any leading template parameter lists.
1064  if (const FunctionDecl *FD = D->getTemplatedDecl()) {
1065  for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1066  I < NumTemplateParams; ++I)
1067  printTemplateParameters(FD->getTemplateParameterList(I));
1068  }
1069  VisitRedeclarableTemplateDecl(D);
1070 
1071  // Never print "instantiations" for deduction guides (they don't really
1072  // have them).
1073  if (PrintInstantiation &&
1074  !isa<CXXDeductionGuideDecl>(D->getTemplatedDecl())) {
1075  FunctionDecl *PrevDecl = D->getTemplatedDecl();
1076  const FunctionDecl *Def;
1077  if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1078  return;
1079  for (auto *I : D->specializations())
1080  if (I->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) {
1081  if (!PrevDecl->isThisDeclarationADefinition())
1082  Out << ";\n";
1083  Indent();
1084  prettyPrintPragmas(I);
1085  Visit(I);
1086  }
1087  }
1088 }
1089 
1090 void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1091  VisitRedeclarableTemplateDecl(D);
1092 
1093  if (PrintInstantiation) {
1094  for (auto *I : D->specializations())
1095  if (I->getSpecializationKind() == TSK_ImplicitInstantiation) {
1097  Out << ";";
1098  Out << "\n";
1099  Visit(I);
1100  }
1101  }
1102 }
1103 
1104 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1106  Out << "template<> ";
1107  VisitCXXRecordDecl(D);
1108 }
1109 
1110 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1112  printTemplateParameters(D->getTemplateParameters());
1113  VisitCXXRecordDecl(D);
1114 }
1115 
1116 //----------------------------------------------------------------------------
1117 // Objective-C declarations
1118 //----------------------------------------------------------------------------
1119 
1120 void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1121  Decl::ObjCDeclQualifier Quals,
1122  QualType T) {
1123  Out << '(';
1124  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1125  Out << "in ";
1126  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1127  Out << "inout ";
1128  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1129  Out << "out ";
1130  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1131  Out << "bycopy ";
1132  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1133  Out << "byref ";
1134  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1135  Out << "oneway ";
1136  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1137  if (auto nullability = AttributedType::stripOuterNullability(T))
1138  Out << getNullabilitySpelling(*nullability, true) << ' ';
1139  }
1140 
1141  Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy);
1142  Out << ')';
1143 }
1144 
1145 void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1146  Out << "<";
1147  unsigned First = true;
1148  for (auto *Param : *Params) {
1149  if (First) {
1150  First = false;
1151  } else {
1152  Out << ", ";
1153  }
1154 
1155  switch (Param->getVariance()) {
1157  break;
1158 
1160  Out << "__covariant ";
1161  break;
1162 
1164  Out << "__contravariant ";
1165  break;
1166  }
1167 
1168  Out << Param->getDeclName().getAsString();
1169 
1170  if (Param->hasExplicitBound()) {
1171  Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1172  }
1173  }
1174  Out << ">";
1175 }
1176 
1177 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1178  if (OMD->isInstanceMethod())
1179  Out << "- ";
1180  else
1181  Out << "+ ";
1182  if (!OMD->getReturnType().isNull()) {
1183  PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1184  OMD->getReturnType());
1185  }
1186 
1187  std::string name = OMD->getSelector().getAsString();
1188  std::string::size_type pos, lastPos = 0;
1189  for (const auto *PI : OMD->parameters()) {
1190  // FIXME: selector is missing here!
1191  pos = name.find_first_of(':', lastPos);
1192  if (lastPos != 0)
1193  Out << " ";
1194  Out << name.substr(lastPos, pos - lastPos) << ':';
1195  PrintObjCMethodType(OMD->getASTContext(),
1196  PI->getObjCDeclQualifier(),
1197  PI->getType());
1198  Out << *PI;
1199  lastPos = pos + 1;
1200  }
1201 
1202  if (OMD->param_begin() == OMD->param_end())
1203  Out << name;
1204 
1205  if (OMD->isVariadic())
1206  Out << ", ...";
1207 
1208  prettyPrintAttributes(OMD);
1209 
1210  if (OMD->getBody() && !Policy.TerseOutput) {
1211  Out << ' ';
1212  OMD->getBody()->printPretty(Out, nullptr, Policy);
1213  }
1214  else if (Policy.PolishForDeclaration)
1215  Out << ';';
1216 }
1217 
1218 void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1219  std::string I = OID->getNameAsString();
1220  ObjCInterfaceDecl *SID = OID->getSuperClass();
1221 
1222  bool eolnOut = false;
1223  if (SID)
1224  Out << "@implementation " << I << " : " << *SID;
1225  else
1226  Out << "@implementation " << I;
1227 
1228  if (OID->ivar_size() > 0) {
1229  Out << "{\n";
1230  eolnOut = true;
1231  Indentation += Policy.Indentation;
1232  for (const auto *I : OID->ivars()) {
1233  Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1234  getAsString(Policy) << ' ' << *I << ";\n";
1235  }
1236  Indentation -= Policy.Indentation;
1237  Out << "}\n";
1238  }
1239  else if (SID || (OID->decls_begin() != OID->decls_end())) {
1240  Out << "\n";
1241  eolnOut = true;
1242  }
1243  VisitDeclContext(OID, false);
1244  if (!eolnOut)
1245  Out << "\n";
1246  Out << "@end";
1247 }
1248 
1249 void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1250  std::string I = OID->getNameAsString();
1251  ObjCInterfaceDecl *SID = OID->getSuperClass();
1252 
1253  if (!OID->isThisDeclarationADefinition()) {
1254  Out << "@class " << I;
1255 
1256  if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1257  PrintObjCTypeParams(TypeParams);
1258  }
1259 
1260  Out << ";";
1261  return;
1262  }
1263  bool eolnOut = false;
1264  Out << "@interface " << I;
1265 
1266  if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1267  PrintObjCTypeParams(TypeParams);
1268  }
1269 
1270  if (SID)
1271  Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
1272 
1273  // Protocols?
1274  const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1275  if (!Protocols.empty()) {
1276  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1277  E = Protocols.end(); I != E; ++I)
1278  Out << (I == Protocols.begin() ? '<' : ',') << **I;
1279  Out << "> ";
1280  }
1281 
1282  if (OID->ivar_size() > 0) {
1283  Out << "{\n";
1284  eolnOut = true;
1285  Indentation += Policy.Indentation;
1286  for (const auto *I : OID->ivars()) {
1287  Indent() << I->getASTContext()
1288  .getUnqualifiedObjCPointerType(I->getType())
1289  .getAsString(Policy) << ' ' << *I << ";\n";
1290  }
1291  Indentation -= Policy.Indentation;
1292  Out << "}\n";
1293  }
1294  else if (SID || (OID->decls_begin() != OID->decls_end())) {
1295  Out << "\n";
1296  eolnOut = true;
1297  }
1298 
1299  VisitDeclContext(OID, false);
1300  if (!eolnOut)
1301  Out << "\n";
1302  Out << "@end";
1303  // FIXME: implement the rest...
1304 }
1305 
1306 void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1307  if (!PID->isThisDeclarationADefinition()) {
1308  Out << "@protocol " << *PID << ";\n";
1309  return;
1310  }
1311  // Protocols?
1312  const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1313  if (!Protocols.empty()) {
1314  Out << "@protocol " << *PID;
1315  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1316  E = Protocols.end(); I != E; ++I)
1317  Out << (I == Protocols.begin() ? '<' : ',') << **I;
1318  Out << ">\n";
1319  } else
1320  Out << "@protocol " << *PID << '\n';
1321  VisitDeclContext(PID, false);
1322  Out << "@end";
1323 }
1324 
1325 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
1326  Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
1327 
1328  VisitDeclContext(PID, false);
1329  Out << "@end";
1330  // FIXME: implement the rest...
1331 }
1332 
1333 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1334  Out << "@interface " << *PID->getClassInterface();
1335  if (auto TypeParams = PID->getTypeParamList()) {
1336  PrintObjCTypeParams(TypeParams);
1337  }
1338  Out << "(" << *PID << ")\n";
1339  if (PID->ivar_size() > 0) {
1340  Out << "{\n";
1341  Indentation += Policy.Indentation;
1342  for (const auto *I : PID->ivars())
1343  Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1344  getAsString(Policy) << ' ' << *I << ";\n";
1345  Indentation -= Policy.Indentation;
1346  Out << "}\n";
1347  }
1348 
1349  VisitDeclContext(PID, false);
1350  Out << "@end";
1351 
1352  // FIXME: implement the rest...
1353 }
1354 
1355 void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
1356  Out << "@compatibility_alias " << *AID
1357  << ' ' << *AID->getClassInterface() << ";\n";
1358 }
1359 
1360 /// PrintObjCPropertyDecl - print a property declaration.
1361 ///
1362 void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1364  Out << "@required\n";
1366  Out << "@optional\n";
1367 
1368  QualType T = PDecl->getType();
1369 
1370  Out << "@property";
1372  bool first = true;
1373  Out << " (";
1374  if (PDecl->getPropertyAttributes() &
1376  Out << (first ? ' ' : ',') << "readonly";
1377  first = false;
1378  }
1379 
1381  Out << (first ? ' ' : ',') << "getter = ";
1382  PDecl->getGetterName().print(Out);
1383  first = false;
1384  }
1386  Out << (first ? ' ' : ',') << "setter = ";
1387  PDecl->getSetterName().print(Out);
1388  first = false;
1389  }
1390 
1392  Out << (first ? ' ' : ',') << "assign";
1393  first = false;
1394  }
1395 
1396  if (PDecl->getPropertyAttributes() &
1398  Out << (first ? ' ' : ',') << "readwrite";
1399  first = false;
1400  }
1401 
1403  Out << (first ? ' ' : ',') << "retain";
1404  first = false;
1405  }
1406 
1408  Out << (first ? ' ' : ',') << "strong";
1409  first = false;
1410  }
1411 
1413  Out << (first ? ' ' : ',') << "copy";
1414  first = false;
1415  }
1416 
1417  if (PDecl->getPropertyAttributes() &
1419  Out << (first ? ' ' : ',') << "nonatomic";
1420  first = false;
1421  }
1422  if (PDecl->getPropertyAttributes() &
1424  Out << (first ? ' ' : ',') << "atomic";
1425  first = false;
1426  }
1427 
1428  if (PDecl->getPropertyAttributes() &
1430  if (auto nullability = AttributedType::stripOuterNullability(T)) {
1431  if (*nullability == NullabilityKind::Unspecified &&
1432  (PDecl->getPropertyAttributes() &
1434  Out << (first ? ' ' : ',') << "null_resettable";
1435  } else {
1436  Out << (first ? ' ' : ',')
1437  << getNullabilitySpelling(*nullability, true);
1438  }
1439  first = false;
1440  }
1441  }
1442 
1444  Out << (first ? ' ' : ',') << "class";
1445  first = false;
1446  }
1447 
1448  (void) first; // Silence dead store warning due to idiomatic code.
1449  Out << " )";
1450  }
1451  Out << ' ' << PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
1452  getAsString(Policy) << ' ' << *PDecl;
1453  if (Policy.PolishForDeclaration)
1454  Out << ';';
1455 }
1456 
1457 void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1459  Out << "@synthesize ";
1460  else
1461  Out << "@dynamic ";
1462  Out << *PID->getPropertyDecl();
1463  if (PID->getPropertyIvarDecl())
1464  Out << '=' << *PID->getPropertyIvarDecl();
1465 }
1466 
1467 void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1468  if (!D->isAccessDeclaration())
1469  Out << "using ";
1470  if (D->hasTypename())
1471  Out << "typename ";
1472  D->getQualifier()->print(Out, Policy);
1473 
1474  // Use the correct record name when the using declaration is used for
1475  // inheriting constructors.
1476  for (const auto *Shadow : D->shadows()) {
1477  if (const auto *ConstructorShadow =
1478  dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1479  assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1480  Out << *ConstructorShadow->getNominatedBaseClass();
1481  return;
1482  }
1483  }
1484  Out << *D;
1485 }
1486 
1487 void
1488 DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1489  Out << "using typename ";
1490  D->getQualifier()->print(Out, Policy);
1491  Out << D->getDeclName();
1492 }
1493 
1494 void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1495  if (!D->isAccessDeclaration())
1496  Out << "using ";
1497  D->getQualifier()->print(Out, Policy);
1498  Out << D->getDeclName();
1499 }
1500 
1501 void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1502  // ignore
1503 }
1504 
1505 void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1506  Out << "#pragma omp threadprivate";
1507  if (!D->varlist_empty()) {
1509  E = D->varlist_end();
1510  I != E; ++I) {
1511  Out << (I == D->varlist_begin() ? '(' : ',');
1512  NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
1513  ND->printQualifiedName(Out);
1514  }
1515  Out << ")";
1516  }
1517 }
1518 
1519 void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1520  if (!D->isInvalidDecl()) {
1521  Out << "#pragma omp declare reduction (";
1523  static const char *const OperatorNames[NUM_OVERLOADED_OPERATORS] = {
1524  nullptr,
1525 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1526  Spelling,
1527 #include "clang/Basic/OperatorKinds.def"
1528  };
1529  const char *OpName =
1530  OperatorNames[D->getDeclName().getCXXOverloadedOperator()];
1531  assert(OpName && "not an overloaded operator");
1532  Out << OpName;
1533  } else {
1534  assert(D->getDeclName().isIdentifier());
1535  D->printName(Out);
1536  }
1537  Out << " : ";
1538  D->getType().print(Out, Policy);
1539  Out << " : ";
1540  D->getCombiner()->printPretty(Out, nullptr, Policy, 0);
1541  Out << ")";
1542  if (auto *Init = D->getInitializer()) {
1543  Out << " initializer(";
1544  Init->printPretty(Out, nullptr, Policy, 0);
1545  Out << ")";
1546  }
1547  }
1548 }
1549 
1550 void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
1551  D->getInit()->printPretty(Out, nullptr, Policy, Indentation);
1552 }
1553 
param_const_iterator param_begin() const
Definition: DeclObjC.h:354
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0) const
Defines the clang::ASTContext interface.
QualType getExceptionType(unsigned i) const
Definition: Type.h:3402
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
Definition: DeclFriend.h:114
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
bool isVariadic() const
Definition: Type.h:3442
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:237
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2224
A (possibly-)qualified type.
Definition: Type.h:616
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2232
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2434
spec_range specializations() const
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:885
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2923
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1452
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
Definition: Decl.h:2554
TypedefDecl - Represents the declaration of a typedef-name via the 'typedef' type specifier...
Definition: Decl.h:2770
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
Defines the clang::Module class, which describes a module in the source code.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
StringRef P
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4206
std::string getAsString() const
Definition: Type.h:942
Represents an empty-declaration.
Definition: Decl.h:3938
The parameter is covariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant and ...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2497
const Expr * getInit() const
Definition: Decl.h:1146
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:461
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1177
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:112
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:94
A container of type source information.
Definition: Decl.h:62
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:306
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:997
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2329
Expr * getInClassInitializer() const
getInClassInitializer - Get the C++11 in-class initializer for this member, or null if one has not be...
Definition: Decl.h:2489
InClassInitStyle getInClassInitStyle() const
getInClassInitStyle - Get the kind of (C++11) in-class initializer which this field has...
Definition: Decl.h:2473
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:40
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
AccessSpecifier getAccess() const
Definition: DeclBase.h:451
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:50
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
decl_iterator decls_end() const
Definition: DeclBase.h:1539
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:2920
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1434
Defines the clang::Expr interface and subclasses for C++ expressions.
QualType getType() const
Definition: DeclObjC.h:788
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:108
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2707
unsigned ivar_size() const
Definition: DeclObjC.h:1398
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3354
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Definition: DeclObjC.h:1241
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2230
C11 _Thread_local.
Definition: Specifiers.h:198
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3282
unsigned getFriendTypeNumTemplateParameterLists() const
Definition: DeclFriend.h:111
StringLiteral * getMessage()
Definition: DeclCXX.h:3599
bool hasAttr() const
Definition: DeclBase.h:521
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3314
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
bool isIdentifier() const
Predicate functions for querying what type of name this is.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3232
The parameter is contravariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant ...
bool isExplicitSpecified() const
Whether this function is marked as explicit explicitly.
Definition: DeclCXX.h:2435
std::string getNameAsString() const
Get the name of the class associated with this interface.
Definition: DeclObjC.h:2569
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2366
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Definition: DeclTemplate.h:998
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
Definition: Decl.h:2960
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:1898
bool isTranslationUnit() const
Definition: DeclBase.h:1364
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:253
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:158
bool varlist_empty() const
Definition: DeclOpenMP.h:75
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2713
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:947
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Definition: Decl.h:1919
Represents a C++ using-declaration.
Definition: DeclCXX.h:3183
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Definition: DeclOpenMP.h:143
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1262
static QualType getDeclType(Decl *D)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:537
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:516
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2237
Microsoft throw(...) extension.
virtual void printName(raw_ostream &os) const
Definition: Decl.cpp:1447
Whether values of this type can be null is (explicitly) unspecified.
NamedDecl * getNominatedNamespaceAsWritten()
Definition: DeclCXX.h:2805
Expr * getNoexceptExpr() const
Definition: Type.h:3406
Selector getSetterName() const
Definition: DeclObjC.h:868
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
Definition: Decl.h:252
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:952
bool empty() const
Definition: DeclObjC.h:46
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1985
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3193
Represents an ObjC class declaration.
Definition: DeclObjC.h:1108
Represents a linkage specification.
Definition: DeclCXX.h:2666
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1306
detail::InMemoryDirectory::const_iterator I
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:799
QualType getType() const
Definition: Decl.h:589
bool isDefined(const FunctionDecl *&Definition) const
isDefined - Returns true if the function is defined at all, including a deleted definition.
Definition: Decl.cpp:2586
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition: Decl.h:1932
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2645
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2126
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
Definition: Decl.h:2790
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3129
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3371
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: DeclObjC.h:269
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
ivar_range ivars() const
Definition: DeclObjC.h:1382
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
Definition: DeclOpenMP.h:136
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition: DeclOpenMP.h:69
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2136
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:414
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:580
Expr - This represents one expression.
Definition: Expr.h:105
bool isDeletedAsWritten() const
Definition: Decl.h:1980
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2711
bool IncludeTagDefinition
When true, include the body of a tag definition.
Expr * getBitWidth() const
Definition: Decl.h:2448
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:1839
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:213
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2088
SourceLocation Begin
void removeLocalConst()
Definition: Type.h:5583
static QualType GetBaseType(QualType T)
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:3663
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3277
StorageClass
Storage classes.
Definition: Specifiers.h:202
bool isInstanceMethod() const
Definition: DeclObjC.h:416
bool hasTrailingReturn() const
Definition: Type.h:3452
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1294
Represents a GCC generic vector type.
Definition: Type.h:2797
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:258
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1857
unsigned ivar_size() const
Definition: DeclObjC.h:2598
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2605
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:148
shadow_range shadows() const
Definition: DeclCXX.h:3280
ivar_range ivars() const
Definition: DeclObjC.h:2591
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:661
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:608
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:1944
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition: DeclCXX.h:2801
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:1893
AttrVec & getAttrs()
Definition: DeclBase.h:466
param_const_iterator param_end() const
Definition: DeclObjC.h:357
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:371
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
Definition: Decl.cpp:2597
bool doesThisDeclarationHaveABody() const
doesThisDeclarationHaveABody - Returns whether this specific declaration of the function has a body -...
Definition: Decl.h:1882
SmallVectorImpl< AnnotatedLine * >::const_iterator Next
Sugar for parentheses used when specifying types.
Definition: Type.h:2193
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
Definition: Decl.cpp:2878
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:259
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:102
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:171
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:3458
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2632
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3536
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
bool SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Definition: PrettyPrinter.h:82
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2816
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:346
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:414
bool isVariadic() const
Definition: DeclObjC.h:418
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3400
std::string getAsString() const
getAsString - Retrieve the human-readable string for this name.
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:793
bool isRestrict() const
Definition: Type.h:3077
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
varlist_iterator varlist_begin()
Definition: DeclOpenMP.h:83
GNU __thread.
Definition: Specifiers.h:192
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
No ref-qualifier was provided.
Definition: Type.h:1260
C-style initialization with assignment.
Definition: Decl.h:768
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2189
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:3873
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2341
Direct list-initialization.
Definition: Specifiers.h:228
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:956
std::string getAsString() const
Derive the full selector name (e.g.
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:704
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
QualType getReturnType() const
Definition: DeclObjC.h:330
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
Definition: DeclObjC.h:723
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3576
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2140
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1264
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
void printQualifiedName(raw_ostream &OS) const
printQualifiedName - Returns human-readable qualified name for declaration, like A::B::i, for i being member of namespace A::B.
Definition: Decl.cpp:1458
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3443
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:3829
Represents a pack expansion of types.
Definition: Type.h:4787
C++11 thread_local.
Definition: Specifiers.h:195
static const char * getStorageClassSpecifierString(StorageClass SC)
getStorageClassSpecifierString - Return the string used to specify the storage class SC...
Definition: Decl.cpp:1828
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:1496
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2682
Represents a template argument.
Definition: TemplateBase.h:40
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:2035
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:235
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition: DeclCXX.h:3235
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3436
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
StringRef Name
Definition: USRFinder.cpp:123
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:378
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
bool isInvalidDecl() const
Definition: DeclBase.h:532
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2554
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2707
bool hasWrittenPrototype() const
Definition: Decl.h:1936
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3497
Selector getGetterName() const
Definition: DeclObjC.h:861
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:1874
Selector getSelector() const
Definition: DeclObjC.h:328
EnumDecl - Represents an enum.
Definition: Decl.h:3102
bool hasAttrs() const
Definition: DeclBase.h:462
detail::InMemoryDirectory::const_iterator E
iterator begin() const
Definition: DeclObjC.h:65
spec_range specializations() const
Pointer to a block type.
Definition: Type.h:2327
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2448
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition: DeclFriend.h:121
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:2357
QualType getIntegerType() const
getIntegerType - Return the integer type this enum decl corresponds to.
Definition: Decl.h:3226
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2360
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition: Decl.h:1205
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1271
The template argument is a type.
Definition: TemplateBase.h:48
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition: DeclCXX.h:2927
Represents a base class of a C++ class.
Definition: DeclCXX.h:158
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3223
A template argument list.
Definition: DeclTemplate.h:195
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2702
varlist_iterator varlist_end()
Definition: DeclOpenMP.h:84
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Call-style initialization (C++98)
Definition: Decl.h:769
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Definition: DeclTemplate.h:431
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition: DeclBase.h:190
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:3379
Declaration of a class template.
void dumpDeclContext() const
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:615
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1299
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:410
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1506
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:314
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:80
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition: Decl.h:689
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition: Decl.h:707
StringRef getKindName() const
Definition: Decl.h:3015
bool isVolatile() const
Definition: Type.h:3076
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1806
Represents a C++ namespace alias.
Definition: DeclCXX.h:2861
Represents C++ using-directive.
Definition: DeclCXX.h:2758
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:2722
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:39
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2396
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
Definition: DeclBase.h:586
The parameter is invariant: must match exactly.
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition: DeclObjC.h:1487
iterator end() const
Definition: DeclObjC.h:66
Declaration of a template function.
Definition: DeclTemplate.h:939
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Definition: DeclCXX.h:2978
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2616
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2368
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Definition: Decl.h:2431
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:704
bool isConst() const
Definition: Type.h:3075
unsigned getNumExceptions() const
Definition: Type.h:3401
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2577
unsigned Indent
The current line's indent.
const StringLiteral * getAsmString() const
Definition: Decl.h:3545