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