clang  11.0.0git
DeclPrinter.cpp
Go to the documentation of this file.
1 //===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Decl::print method, which pretty prints the
10 // AST back out to C/Objective-C/C++/Objective-C++ code.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/Attr.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclTemplate.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 VisitOMPAllocateDecl(OMPAllocateDecl *D);
104  void VisitOMPRequiresDecl(OMPRequiresDecl *D);
105  void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
106  void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
107  void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
108  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP);
109  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP);
110 
111  void printTemplateParameters(const TemplateParameterList *Params,
112  bool OmitTemplateKW = false);
113  void printTemplateArguments(llvm::ArrayRef<TemplateArgument> Args);
114  void printTemplateArguments(llvm::ArrayRef<TemplateArgumentLoc> Args);
115  void prettyPrintAttributes(Decl *D);
116  void prettyPrintPragmas(Decl *D);
117  void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
118  };
119 }
120 
121 void Decl::print(raw_ostream &Out, unsigned Indentation,
122  bool PrintInstantiation) const {
123  print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
124 }
125 
126 void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
127  unsigned Indentation, bool PrintInstantiation) const {
128  DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
129  PrintInstantiation);
130  Printer.Visit(const_cast<Decl*>(this));
131 }
132 
133 void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
134  bool OmitTemplateKW) const {
135  print(Out, Context, Context.getPrintingPolicy(), OmitTemplateKW);
136 }
137 
138 void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
139  const PrintingPolicy &Policy,
140  bool OmitTemplateKW) const {
141  DeclPrinter Printer(Out, Policy, Context);
142  Printer.printTemplateParameters(this, OmitTemplateKW);
143 }
144 
146  // FIXME: This should be on the Type class!
147  QualType BaseType = T;
148  while (!BaseType->isSpecifierType()) {
149  if (const PointerType *PTy = BaseType->getAs<PointerType>())
150  BaseType = PTy->getPointeeType();
151  else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
152  BaseType = BPy->getPointeeType();
153  else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
154  BaseType = ATy->getElementType();
155  else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
156  BaseType = FTy->getReturnType();
157  else if (const VectorType *VTy = BaseType->getAs<VectorType>())
158  BaseType = VTy->getElementType();
159  else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
160  BaseType = RTy->getPointeeType();
161  else if (const AutoType *ATy = BaseType->getAs<AutoType>())
162  BaseType = ATy->getDeducedType();
163  else if (const ParenType *PTy = BaseType->getAs<ParenType>())
164  BaseType = PTy->desugar();
165  else
166  // This must be a syntax error.
167  break;
168  }
169  return BaseType;
170 }
171 
173  if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
174  return TDD->getUnderlyingType();
175  if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
176  return VD->getType();
177  return QualType();
178 }
179 
180 void Decl::printGroup(Decl** Begin, unsigned NumDecls,
181  raw_ostream &Out, const PrintingPolicy &Policy,
182  unsigned Indentation) {
183  if (NumDecls == 1) {
184  (*Begin)->print(Out, Policy, Indentation);
185  return;
186  }
187 
188  Decl** End = Begin + NumDecls;
189  TagDecl* TD = dyn_cast<TagDecl>(*Begin);
190  if (TD)
191  ++Begin;
192 
193  PrintingPolicy SubPolicy(Policy);
194 
195  bool isFirst = true;
196  for ( ; Begin != End; ++Begin) {
197  if (isFirst) {
198  if(TD)
199  SubPolicy.IncludeTagDefinition = true;
200  SubPolicy.SuppressSpecifiers = false;
201  isFirst = false;
202  } else {
203  if (!isFirst) Out << ", ";
204  SubPolicy.IncludeTagDefinition = false;
205  SubPolicy.SuppressSpecifiers = true;
206  }
207 
208  (*Begin)->print(Out, SubPolicy, Indentation);
209  }
210 }
211 
212 LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
213  // Get the translation unit
214  const DeclContext *DC = this;
215  while (!DC->isTranslationUnit())
216  DC = DC->getParent();
217 
218  ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
219  DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), Ctx, 0);
220  Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
221 }
222 
223 raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
224  for (unsigned i = 0; i != Indentation; ++i)
225  Out << " ";
226  return Out;
227 }
228 
229 void DeclPrinter::prettyPrintAttributes(Decl *D) {
230  if (Policy.PolishForDeclaration)
231  return;
232 
233  if (D->hasAttrs()) {
234  AttrVec &Attrs = D->getAttrs();
235  for (auto *A : Attrs) {
236  if (A->isInherited() || A->isImplicit())
237  continue;
238  switch (A->getKind()) {
239 #define ATTR(X)
240 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
241 #include "clang/Basic/AttrList.inc"
242  break;
243  default:
244  A->printPretty(Out, Policy);
245  break;
246  }
247  }
248  }
249 }
250 
251 void DeclPrinter::prettyPrintPragmas(Decl *D) {
252  if (Policy.PolishForDeclaration)
253  return;
254 
255  if (D->hasAttrs()) {
256  AttrVec &Attrs = D->getAttrs();
257  for (auto *A : Attrs) {
258  switch (A->getKind()) {
259 #define ATTR(X)
260 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
261 #include "clang/Basic/AttrList.inc"
262  A->printPretty(Out, Policy);
263  Indent();
264  break;
265  default:
266  break;
267  }
268  }
269  }
270 }
271 
272 void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
273  // Normally, a PackExpansionType is written as T[3]... (for instance, as a
274  // template argument), but if it is the type of a declaration, the ellipsis
275  // is placed before the name being declared.
276  if (auto *PET = T->getAs<PackExpansionType>()) {
277  Pack = true;
278  T = PET->getPattern();
279  }
280  T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
281 }
282 
283 void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
284  this->Indent();
285  Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
286  Out << ";\n";
287  Decls.clear();
288 
289 }
290 
291 void DeclPrinter::Print(AccessSpecifier AS) {
292  const auto AccessSpelling = getAccessSpelling(AS);
293  if (AccessSpelling.empty())
294  llvm_unreachable("No access specifier!");
295  Out << AccessSpelling;
296 }
297 
298 void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl,
299  std::string &Proto) {
300  bool HasInitializerList = false;
301  for (const auto *BMInitializer : CDecl->inits()) {
302  if (BMInitializer->isInClassMemberInitializer())
303  continue;
304 
305  if (!HasInitializerList) {
306  Proto += " : ";
307  Out << Proto;
308  Proto.clear();
309  HasInitializerList = true;
310  } else
311  Out << ", ";
312 
313  if (BMInitializer->isAnyMemberInitializer()) {
314  FieldDecl *FD = BMInitializer->getAnyMember();
315  Out << *FD;
316  } else {
317  Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
318  }
319 
320  Out << "(";
321  if (!BMInitializer->getInit()) {
322  // Nothing to print
323  } else {
324  Expr *Init = BMInitializer->getInit();
325  if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
326  Init = Tmp->getSubExpr();
327 
328  Init = Init->IgnoreParens();
329 
330  Expr *SimpleInit = nullptr;
331  Expr **Args = nullptr;
332  unsigned NumArgs = 0;
333  if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
334  Args = ParenList->getExprs();
335  NumArgs = ParenList->getNumExprs();
336  } else if (CXXConstructExpr *Construct =
337  dyn_cast<CXXConstructExpr>(Init)) {
338  Args = Construct->getArgs();
339  NumArgs = Construct->getNumArgs();
340  } else
341  SimpleInit = Init;
342 
343  if (SimpleInit)
344  SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
345  else {
346  for (unsigned I = 0; I != NumArgs; ++I) {
347  assert(Args[I] != nullptr && "Expected non-null Expr");
348  if (isa<CXXDefaultArgExpr>(Args[I]))
349  break;
350 
351  if (I)
352  Out << ", ";
353  Args[I]->printPretty(Out, nullptr, Policy, Indentation);
354  }
355  }
356  }
357  Out << ")";
358  if (BMInitializer->isPackExpansion())
359  Out << "...";
360  }
361 }
362 
363 //----------------------------------------------------------------------------
364 // Common C declarations
365 //----------------------------------------------------------------------------
366 
367 void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
368  if (Policy.TerseOutput)
369  return;
370 
371  if (Indent)
372  Indentation += Policy.Indentation;
373 
374  SmallVector<Decl*, 2> Decls;
375  for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
376  D != DEnd; ++D) {
377 
378  // Don't print ObjCIvarDecls, as they are printed when visiting the
379  // containing ObjCInterfaceDecl.
380  if (isa<ObjCIvarDecl>(*D))
381  continue;
382 
383  // Skip over implicit declarations in pretty-printing mode.
384  if (D->isImplicit())
385  continue;
386 
387  // Don't print implicit specializations, as they are printed when visiting
388  // corresponding templates.
389  if (auto FD = dyn_cast<FunctionDecl>(*D))
390  if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation &&
391  !isa<ClassTemplateSpecializationDecl>(DC))
392  continue;
393 
394  // The next bits of code handle stuff like "struct {int x;} a,b"; we're
395  // forced to merge the declarations because there's no other way to
396  // refer to the struct in question. When that struct is named instead, we
397  // also need to merge to avoid splitting off a stand-alone struct
398  // declaration that produces the warning ext_no_declarators in some
399  // contexts.
400  //
401  // This limited merging is safe without a bunch of other checks because it
402  // only merges declarations directly referring to the tag, not typedefs.
403  //
404  // Check whether the current declaration should be grouped with a previous
405  // non-free-standing tag declaration.
406  QualType CurDeclType = getDeclType(*D);
407  if (!Decls.empty() && !CurDeclType.isNull()) {
408  QualType BaseType = GetBaseType(CurDeclType);
409  if (!BaseType.isNull() && isa<ElaboratedType>(BaseType) &&
410  cast<ElaboratedType>(BaseType)->getOwnedTagDecl() == Decls[0]) {
411  Decls.push_back(*D);
412  continue;
413  }
414  }
415 
416  // If we have a merged group waiting to be handled, handle it now.
417  if (!Decls.empty())
418  ProcessDeclGroup(Decls);
419 
420  // If the current declaration is not a free standing declaration, save it
421  // so we can merge it with the subsequent declaration(s) using it.
422  if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
423  Decls.push_back(*D);
424  continue;
425  }
426 
427  if (isa<AccessSpecDecl>(*D)) {
428  Indentation -= Policy.Indentation;
429  this->Indent();
430  Print(D->getAccess());
431  Out << ":\n";
432  Indentation += Policy.Indentation;
433  continue;
434  }
435 
436  this->Indent();
437  Visit(*D);
438 
439  // FIXME: Need to be able to tell the DeclPrinter when
440  const char *Terminator = nullptr;
441  if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D) ||
442  isa<OMPDeclareMapperDecl>(*D) || isa<OMPRequiresDecl>(*D) ||
443  isa<OMPAllocateDecl>(*D))
444  Terminator = nullptr;
445  else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
446  Terminator = nullptr;
447  else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
448  if (FD->isThisDeclarationADefinition())
449  Terminator = nullptr;
450  else
451  Terminator = ";";
452  } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
453  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
454  Terminator = nullptr;
455  else
456  Terminator = ";";
457  } else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
458  isa<ObjCImplementationDecl>(*D) ||
459  isa<ObjCInterfaceDecl>(*D) ||
460  isa<ObjCProtocolDecl>(*D) ||
461  isa<ObjCCategoryImplDecl>(*D) ||
462  isa<ObjCCategoryDecl>(*D))
463  Terminator = nullptr;
464  else if (isa<EnumConstantDecl>(*D)) {
466  ++Next;
467  if (Next != DEnd)
468  Terminator = ",";
469  } else
470  Terminator = ";";
471 
472  if (Terminator)
473  Out << Terminator;
474  if (!Policy.TerseOutput &&
475  ((isa<FunctionDecl>(*D) &&
476  cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
477  (isa<FunctionTemplateDecl>(*D) &&
478  cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
479  ; // StmtPrinter already added '\n' after CompoundStmt.
480  else
481  Out << "\n";
482 
483  // Declare target attribute is special one, natural spelling for the pragma
484  // assumes "ending" construct so print it here.
485  if (D->hasAttr<OMPDeclareTargetDeclAttr>())
486  Out << "#pragma omp end declare target\n";
487  }
488 
489  if (!Decls.empty())
490  ProcessDeclGroup(Decls);
491 
492  if (Indent)
493  Indentation -= Policy.Indentation;
494 }
495 
496 void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
497  VisitDeclContext(D, false);
498 }
499 
500 void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
501  if (!Policy.SuppressSpecifiers) {
502  Out << "typedef ";
503 
504  if (D->isModulePrivate())
505  Out << "__module_private__ ";
506  }
507  QualType Ty = D->getTypeSourceInfo()->getType();
508  Ty.print(Out, Policy, D->getName(), Indentation);
509  prettyPrintAttributes(D);
510 }
511 
512 void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
513  Out << "using " << *D;
514  prettyPrintAttributes(D);
515  Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
516 }
517 
518 void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
519  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
520  Out << "__module_private__ ";
521  Out << "enum";
522  if (D->isScoped()) {
523  if (D->isScopedUsingClassTag())
524  Out << " class";
525  else
526  Out << " struct";
527  }
528 
529  prettyPrintAttributes(D);
530 
531  Out << ' ' << *D;
532 
533  if (D->isFixed())
534  Out << " : " << D->getIntegerType().stream(Policy);
535 
536  if (D->isCompleteDefinition()) {
537  Out << " {\n";
538  VisitDeclContext(D);
539  Indent() << "}";
540  }
541 }
542 
543 void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
544  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
545  Out << "__module_private__ ";
546  Out << D->getKindName();
547 
548  prettyPrintAttributes(D);
549 
550  if (D->getIdentifier())
551  Out << ' ' << *D;
552 
553  if (D->isCompleteDefinition()) {
554  Out << " {\n";
555  VisitDeclContext(D);
556  Indent() << "}";
557  }
558 }
559 
560 void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
561  Out << *D;
562  prettyPrintAttributes(D);
563  if (Expr *Init = D->getInitExpr()) {
564  Out << " = ";
565  Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
566  }
567 }
568 
569 static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out,
570  PrintingPolicy &Policy,
571  unsigned Indentation) {
572  std::string Proto = "explicit";
573  llvm::raw_string_ostream EOut(Proto);
574  if (ES.getExpr()) {
575  EOut << "(";
576  ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation);
577  EOut << ")";
578  }
579  EOut << " ";
580  EOut.flush();
581  Out << EOut.str();
582 }
583 
584 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
585  if (!D->getDescribedFunctionTemplate() &&
587  prettyPrintPragmas(D);
588 
590  Out << "template<> ";
591  else if (!D->getDescribedFunctionTemplate()) {
592  for (unsigned I = 0, NumTemplateParams = D->getNumTemplateParameterLists();
593  I < NumTemplateParams; ++I)
594  printTemplateParameters(D->getTemplateParameterList(I));
595  }
596 
597  CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
598  CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
599  CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D);
600  if (!Policy.SuppressSpecifiers) {
601  switch (D->getStorageClass()) {
602  case SC_None: break;
603  case SC_Extern: Out << "extern "; break;
604  case SC_Static: Out << "static "; break;
605  case SC_PrivateExtern: Out << "__private_extern__ "; break;
606  case SC_Auto: case SC_Register:
607  llvm_unreachable("invalid for functions");
608  }
609 
610  if (D->isInlineSpecified()) Out << "inline ";
611  if (D->isVirtualAsWritten()) Out << "virtual ";
612  if (D->isModulePrivate()) Out << "__module_private__ ";
614  Out << "constexpr ";
615  if (D->isConsteval()) Out << "consteval ";
617  if (ExplicitSpec.isSpecified())
618  printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation);
619  }
620 
621  PrintingPolicy SubPolicy(Policy);
622  SubPolicy.SuppressSpecifiers = false;
623  std::string Proto;
624 
625  if (Policy.FullyQualifiedName) {
626  Proto += D->getQualifiedNameAsString();
627  } else {
628  llvm::raw_string_ostream OS(Proto);
629  if (!Policy.SuppressScope) {
630  if (const NestedNameSpecifier *NS = D->getQualifier()) {
631  NS->print(OS, Policy);
632  }
633  }
634  D->getNameInfo().printName(OS, Policy);
635  }
636 
637  if (GuideDecl)
638  Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
640  llvm::raw_string_ostream POut(Proto);
641  DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
642  const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten();
643  if (TArgAsWritten && !Policy.PrintCanonicalTypes)
644  TArgPrinter.printTemplateArguments(TArgAsWritten->arguments());
645  else if (const TemplateArgumentList *TArgs =
647  TArgPrinter.printTemplateArguments(TArgs->asArray());
648  }
649 
650  QualType Ty = D->getType();
651  while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
652  Proto = '(' + Proto + ')';
653  Ty = PT->getInnerType();
654  }
655 
656  if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
657  const FunctionProtoType *FT = nullptr;
658  if (D->hasWrittenPrototype())
659  FT = dyn_cast<FunctionProtoType>(AFT);
660 
661  Proto += "(";
662  if (FT) {
663  llvm::raw_string_ostream POut(Proto);
664  DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
665  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
666  if (i) POut << ", ";
667  ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
668  }
669 
670  if (FT->isVariadic()) {
671  if (D->getNumParams()) POut << ", ";
672  POut << "...";
673  }
674  } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
675  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
676  if (i)
677  Proto += ", ";
678  Proto += D->getParamDecl(i)->getNameAsString();
679  }
680  }
681 
682  Proto += ")";
683 
684  if (FT) {
685  if (FT->isConst())
686  Proto += " const";
687  if (FT->isVolatile())
688  Proto += " volatile";
689  if (FT->isRestrict())
690  Proto += " restrict";
691 
692  switch (FT->getRefQualifier()) {
693  case RQ_None:
694  break;
695  case RQ_LValue:
696  Proto += " &";
697  break;
698  case RQ_RValue:
699  Proto += " &&";
700  break;
701  }
702  }
703 
704  if (FT && FT->hasDynamicExceptionSpec()) {
705  Proto += " throw(";
706  if (FT->getExceptionSpecType() == EST_MSAny)
707  Proto += "...";
708  else
709  for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
710  if (I)
711  Proto += ", ";
712 
713  Proto += FT->getExceptionType(I).getAsString(SubPolicy);
714  }
715  Proto += ")";
716  } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
717  Proto += " noexcept";
719  Proto += "(";
720  llvm::raw_string_ostream EOut(Proto);
721  FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
722  Indentation);
723  EOut.flush();
724  Proto += EOut.str();
725  Proto += ")";
726  }
727  }
728 
729  if (CDecl) {
730  if (!Policy.TerseOutput)
731  PrintConstructorInitializers(CDecl, Proto);
732  } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
733  if (FT && FT->hasTrailingReturn()) {
734  if (!GuideDecl)
735  Out << "auto ";
736  Out << Proto << " -> ";
737  Proto.clear();
738  }
739  AFT->getReturnType().print(Out, Policy, Proto);
740  Proto.clear();
741  }
742  Out << Proto;
743 
744  if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) {
745  Out << " requires ";
746  TrailingRequiresClause->printPretty(Out, nullptr, SubPolicy, Indentation);
747  }
748  } else {
749  Ty.print(Out, Policy, Proto);
750  }
751 
752  prettyPrintAttributes(D);
753 
754  if (D->isPure())
755  Out << " = 0";
756  else if (D->isDeletedAsWritten())
757  Out << " = delete";
758  else if (D->isExplicitlyDefaulted())
759  Out << " = default";
760  else if (D->doesThisDeclarationHaveABody()) {
761  if (!Policy.TerseOutput) {
762  if (!D->hasPrototype() && D->getNumParams()) {
763  // This is a K&R function definition, so we need to print the
764  // parameters.
765  Out << '\n';
766  DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
767  Indentation += Policy.Indentation;
768  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
769  Indent();
770  ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
771  Out << ";\n";
772  }
773  Indentation -= Policy.Indentation;
774  } else
775  Out << ' ';
776 
777  if (D->getBody())
778  D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation);
779  } else {
780  if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
781  Out << " {}";
782  }
783  }
784 }
785 
786 void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
787  if (TypeSourceInfo *TSI = D->getFriendType()) {
788  unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
789  for (unsigned i = 0; i < NumTPLists; ++i)
790  printTemplateParameters(D->getFriendTypeTemplateParameterList(i));
791  Out << "friend ";
792  Out << " " << TSI->getType().getAsString(Policy);
793  }
794  else if (FunctionDecl *FD =
795  dyn_cast<FunctionDecl>(D->getFriendDecl())) {
796  Out << "friend ";
797  VisitFunctionDecl(FD);
798  }
799  else if (FunctionTemplateDecl *FTD =
800  dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
801  Out << "friend ";
802  VisitFunctionTemplateDecl(FTD);
803  }
804  else if (ClassTemplateDecl *CTD =
805  dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
806  Out << "friend ";
807  VisitRedeclarableTemplateDecl(CTD);
808  }
809 }
810 
811 void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
812  // FIXME: add printing of pragma attributes if required.
813  if (!Policy.SuppressSpecifiers && D->isMutable())
814  Out << "mutable ";
815  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
816  Out << "__module_private__ ";
817 
819  stream(Policy, D->getName(), Indentation);
820 
821  if (D->isBitField()) {
822  Out << " : ";
823  D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation);
824  }
825 
826  Expr *Init = D->getInClassInitializer();
827  if (!Policy.SuppressInitializers && Init) {
829  Out << " ";
830  else
831  Out << " = ";
832  Init->printPretty(Out, nullptr, Policy, Indentation);
833  }
834  prettyPrintAttributes(D);
835 }
836 
837 void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
838  Out << *D << ":";
839 }
840 
841 void DeclPrinter::VisitVarDecl(VarDecl *D) {
842  prettyPrintPragmas(D);
843 
844  QualType T = D->getTypeSourceInfo()
845  ? D->getTypeSourceInfo()->getType()
847 
848  if (!Policy.SuppressSpecifiers) {
849  StorageClass SC = D->getStorageClass();
850  if (SC != SC_None)
851  Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
852 
853  switch (D->getTSCSpec()) {
854  case TSCS_unspecified:
855  break;
856  case TSCS___thread:
857  Out << "__thread ";
858  break;
859  case TSCS__Thread_local:
860  Out << "_Thread_local ";
861  break;
862  case TSCS_thread_local:
863  Out << "thread_local ";
864  break;
865  }
866 
867  if (D->isModulePrivate())
868  Out << "__module_private__ ";
869 
870  if (D->isConstexpr()) {
871  Out << "constexpr ";
872  T.removeLocalConst();
873  }
874  }
875 
876  printDeclType(T, D->getName());
877  Expr *Init = D->getInit();
878  if (!Policy.SuppressInitializers && Init) {
879  bool ImplicitInit = false;
880  if (CXXConstructExpr *Construct =
881  dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
882  if (D->getInitStyle() == VarDecl::CallInit &&
883  !Construct->isListInitialization()) {
884  ImplicitInit = Construct->getNumArgs() == 0 ||
885  Construct->getArg(0)->isDefaultArgument();
886  }
887  }
888  if (!ImplicitInit) {
889  if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
890  Out << "(";
891  else if (D->getInitStyle() == VarDecl::CInit) {
892  Out << " = ";
893  }
894  PrintingPolicy SubPolicy(Policy);
895  SubPolicy.SuppressSpecifiers = false;
896  SubPolicy.IncludeTagDefinition = false;
897  Init->printPretty(Out, nullptr, SubPolicy, Indentation);
898  if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
899  Out << ")";
900  }
901  }
902  prettyPrintAttributes(D);
903 }
904 
905 void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
906  VisitVarDecl(D);
907 }
908 
909 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
910  Out << "__asm (";
911  D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation);
912  Out << ")";
913 }
914 
915 void DeclPrinter::VisitImportDecl(ImportDecl *D) {
916  Out << "@import " << D->getImportedModule()->getFullModuleName()
917  << ";\n";
918 }
919 
920 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
921  Out << "static_assert(";
922  D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation);
923  if (StringLiteral *SL = D->getMessage()) {
924  Out << ", ";
925  SL->printPretty(Out, nullptr, Policy, Indentation);
926  }
927  Out << ")";
928 }
929 
930 //----------------------------------------------------------------------------
931 // C++ declarations
932 //----------------------------------------------------------------------------
933 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
934  if (D->isInline())
935  Out << "inline ";
936  Out << "namespace " << *D << " {\n";
937  VisitDeclContext(D);
938  Indent() << "}";
939 }
940 
941 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
942  Out << "using namespace ";
943  if (D->getQualifier())
944  D->getQualifier()->print(Out, Policy);
945  Out << *D->getNominatedNamespaceAsWritten();
946 }
947 
948 void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
949  Out << "namespace " << *D << " = ";
950  if (D->getQualifier())
951  D->getQualifier()->print(Out, Policy);
952  Out << *D->getAliasedNamespace();
953 }
954 
955 void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
956  prettyPrintAttributes(D);
957 }
958 
959 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
960  // FIXME: add printing of pragma attributes if required.
961  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
962  Out << "__module_private__ ";
963  Out << D->getKindName();
964 
965  prettyPrintAttributes(D);
966 
967  if (D->getIdentifier()) {
968  Out << ' ' << *D;
969 
970  if (auto S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
971  ArrayRef<TemplateArgument> Args = S->getTemplateArgs().asArray();
972  if (!Policy.PrintCanonicalTypes)
973  if (const auto* TSI = S->getTypeAsWritten())
974  if (const auto *TST =
975  dyn_cast<TemplateSpecializationType>(TSI->getType()))
976  Args = TST->template_arguments();
977  printTemplateArguments(Args);
978  }
979  }
980 
981  if (D->isCompleteDefinition()) {
982  // Print the base classes
983  if (D->getNumBases()) {
984  Out << " : ";
986  BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
987  if (Base != D->bases_begin())
988  Out << ", ";
989 
990  if (Base->isVirtual())
991  Out << "virtual ";
992 
993  AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
994  if (AS != AS_none) {
995  Print(AS);
996  Out << " ";
997  }
998  Out << Base->getType().getAsString(Policy);
999 
1000  if (Base->isPackExpansion())
1001  Out << "...";
1002  }
1003  }
1004 
1005  // Print the class definition
1006  // FIXME: Doesn't print access specifiers, e.g., "public:"
1007  if (Policy.TerseOutput) {
1008  Out << " {}";
1009  } else {
1010  Out << " {\n";
1011  VisitDeclContext(D);
1012  Indent() << "}";
1013  }
1014  }
1015 }
1016 
1017 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1018  const char *l;
1020  l = "C";
1021  else {
1022  assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
1023  "unknown language in linkage specification");
1024  l = "C++";
1025  }
1026 
1027  Out << "extern \"" << l << "\" ";
1028  if (D->hasBraces()) {
1029  Out << "{\n";
1030  VisitDeclContext(D);
1031  Indent() << "}";
1032  } else
1033  Visit(*D->decls_begin());
1034 }
1035 
1036 void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
1037  bool OmitTemplateKW) {
1038  assert(Params);
1039 
1040  if (!OmitTemplateKW)
1041  Out << "template ";
1042  Out << '<';
1043 
1044  bool NeedComma = false;
1045  for (const Decl *Param : *Params) {
1046  if (Param->isImplicit())
1047  continue;
1048 
1049  if (NeedComma)
1050  Out << ", ";
1051  else
1052  NeedComma = true;
1053 
1054  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1055  VisitTemplateTypeParmDecl(TTP);
1056  } else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1057  VisitNonTypeTemplateParmDecl(NTTP);
1058  } else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1059  VisitTemplateDecl(TTPD);
1060  // FIXME: print the default argument, if present.
1061  }
1062  }
1063 
1064  Out << '>';
1065  if (!OmitTemplateKW)
1066  Out << ' ';
1067 }
1068 
1069 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args) {
1070  Out << "<";
1071  for (size_t I = 0, E = Args.size(); I < E; ++I) {
1072  if (I)
1073  Out << ", ";
1074  Args[I].print(Policy, Out);
1075  }
1076  Out << ">";
1077 }
1078 
1079 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args) {
1080  Out << "<";
1081  for (size_t I = 0, E = Args.size(); I < E; ++I) {
1082  if (I)
1083  Out << ", ";
1084  Args[I].getArgument().print(Policy, Out);
1085  }
1086  Out << ">";
1087 }
1088 
1089 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1090  printTemplateParameters(D->getTemplateParameters());
1091 
1092  if (const TemplateTemplateParmDecl *TTP =
1093  dyn_cast<TemplateTemplateParmDecl>(D)) {
1094  Out << "class ";
1095  if (TTP->isParameterPack())
1096  Out << "...";
1097  Out << D->getName();
1098  } else if (auto *TD = D->getTemplatedDecl())
1099  Visit(TD);
1100  else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) {
1101  Out << "concept " << Concept->getName() << " = " ;
1102  Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy,
1103  Indentation);
1104  Out << ";";
1105  }
1106 }
1107 
1108 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1109  prettyPrintPragmas(D->getTemplatedDecl());
1110  // Print any leading template parameter lists.
1111  if (const FunctionDecl *FD = D->getTemplatedDecl()) {
1112  for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1113  I < NumTemplateParams; ++I)
1114  printTemplateParameters(FD->getTemplateParameterList(I));
1115  }
1116  VisitRedeclarableTemplateDecl(D);
1117  // Declare target attribute is special one, natural spelling for the pragma
1118  // assumes "ending" construct so print it here.
1119  if (D->getTemplatedDecl()->hasAttr<OMPDeclareTargetDeclAttr>())
1120  Out << "#pragma omp end declare target\n";
1121 
1122  // Never print "instantiations" for deduction guides (they don't really
1123  // have them).
1124  if (PrintInstantiation &&
1125  !isa<CXXDeductionGuideDecl>(D->getTemplatedDecl())) {
1126  FunctionDecl *PrevDecl = D->getTemplatedDecl();
1127  const FunctionDecl *Def;
1128  if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1129  return;
1130  for (auto *I : D->specializations())
1131  if (I->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) {
1132  if (!PrevDecl->isThisDeclarationADefinition())
1133  Out << ";\n";
1134  Indent();
1135  prettyPrintPragmas(I);
1136  Visit(I);
1137  }
1138  }
1139 }
1140 
1141 void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1142  VisitRedeclarableTemplateDecl(D);
1143 
1144  if (PrintInstantiation) {
1145  for (auto *I : D->specializations())
1146  if (I->getSpecializationKind() == TSK_ImplicitInstantiation) {
1148  Out << ";";
1149  Out << "\n";
1150  Visit(I);
1151  }
1152  }
1153 }
1154 
1155 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1157  Out << "template<> ";
1158  VisitCXXRecordDecl(D);
1159 }
1160 
1161 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1163  printTemplateParameters(D->getTemplateParameters());
1164  VisitCXXRecordDecl(D);
1165 }
1166 
1167 //----------------------------------------------------------------------------
1168 // Objective-C declarations
1169 //----------------------------------------------------------------------------
1170 
1171 void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1173  QualType T) {
1174  Out << '(';
1175  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1176  Out << "in ";
1177  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1178  Out << "inout ";
1179  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1180  Out << "out ";
1181  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1182  Out << "bycopy ";
1183  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1184  Out << "byref ";
1185  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1186  Out << "oneway ";
1187  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1188  if (auto nullability = AttributedType::stripOuterNullability(T))
1189  Out << getNullabilitySpelling(*nullability, true) << ' ';
1190  }
1191 
1192  Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy);
1193  Out << ')';
1194 }
1195 
1196 void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1197  Out << "<";
1198  unsigned First = true;
1199  for (auto *Param : *Params) {
1200  if (First) {
1201  First = false;
1202  } else {
1203  Out << ", ";
1204  }
1205 
1206  switch (Param->getVariance()) {
1208  break;
1209 
1211  Out << "__covariant ";
1212  break;
1213 
1215  Out << "__contravariant ";
1216  break;
1217  }
1218 
1219  Out << Param->getDeclName().getAsString();
1220 
1221  if (Param->hasExplicitBound()) {
1222  Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1223  }
1224  }
1225  Out << ">";
1226 }
1227 
1228 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1229  if (OMD->isInstanceMethod())
1230  Out << "- ";
1231  else
1232  Out << "+ ";
1233  if (!OMD->getReturnType().isNull()) {
1234  PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1235  OMD->getReturnType());
1236  }
1237 
1238  std::string name = OMD->getSelector().getAsString();
1239  std::string::size_type pos, lastPos = 0;
1240  for (const auto *PI : OMD->parameters()) {
1241  // FIXME: selector is missing here!
1242  pos = name.find_first_of(':', lastPos);
1243  if (lastPos != 0)
1244  Out << " ";
1245  Out << name.substr(lastPos, pos - lastPos) << ':';
1246  PrintObjCMethodType(OMD->getASTContext(),
1247  PI->getObjCDeclQualifier(),
1248  PI->getType());
1249  Out << *PI;
1250  lastPos = pos + 1;
1251  }
1252 
1253  if (OMD->param_begin() == OMD->param_end())
1254  Out << name;
1255 
1256  if (OMD->isVariadic())
1257  Out << ", ...";
1258 
1259  prettyPrintAttributes(OMD);
1260 
1261  if (OMD->getBody() && !Policy.TerseOutput) {
1262  Out << ' ';
1263  OMD->getBody()->printPretty(Out, nullptr, Policy);
1264  }
1265  else if (Policy.PolishForDeclaration)
1266  Out << ';';
1267 }
1268 
1269 void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1270  std::string I = OID->getNameAsString();
1271  ObjCInterfaceDecl *SID = OID->getSuperClass();
1272 
1273  bool eolnOut = false;
1274  if (SID)
1275  Out << "@implementation " << I << " : " << *SID;
1276  else
1277  Out << "@implementation " << I;
1278 
1279  if (OID->ivar_size() > 0) {
1280  Out << "{\n";
1281  eolnOut = true;
1282  Indentation += Policy.Indentation;
1283  for (const auto *I : OID->ivars()) {
1284  Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1285  getAsString(Policy) << ' ' << *I << ";\n";
1286  }
1287  Indentation -= Policy.Indentation;
1288  Out << "}\n";
1289  }
1290  else if (SID || (OID->decls_begin() != OID->decls_end())) {
1291  Out << "\n";
1292  eolnOut = true;
1293  }
1294  VisitDeclContext(OID, false);
1295  if (!eolnOut)
1296  Out << "\n";
1297  Out << "@end";
1298 }
1299 
1300 void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1301  std::string I = OID->getNameAsString();
1302  ObjCInterfaceDecl *SID = OID->getSuperClass();
1303 
1304  if (!OID->isThisDeclarationADefinition()) {
1305  Out << "@class " << I;
1306 
1307  if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1308  PrintObjCTypeParams(TypeParams);
1309  }
1310 
1311  Out << ";";
1312  return;
1313  }
1314  bool eolnOut = false;
1315  Out << "@interface " << I;
1316 
1317  if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1318  PrintObjCTypeParams(TypeParams);
1319  }
1320 
1321  if (SID)
1322  Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
1323 
1324  // Protocols?
1325  const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1326  if (!Protocols.empty()) {
1327  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1328  E = Protocols.end(); I != E; ++I)
1329  Out << (I == Protocols.begin() ? '<' : ',') << **I;
1330  Out << "> ";
1331  }
1332 
1333  if (OID->ivar_size() > 0) {
1334  Out << "{\n";
1335  eolnOut = true;
1336  Indentation += Policy.Indentation;
1337  for (const auto *I : OID->ivars()) {
1338  Indent() << I->getASTContext()
1339  .getUnqualifiedObjCPointerType(I->getType())
1340  .getAsString(Policy) << ' ' << *I << ";\n";
1341  }
1342  Indentation -= Policy.Indentation;
1343  Out << "}\n";
1344  }
1345  else if (SID || (OID->decls_begin() != OID->decls_end())) {
1346  Out << "\n";
1347  eolnOut = true;
1348  }
1349 
1350  VisitDeclContext(OID, false);
1351  if (!eolnOut)
1352  Out << "\n";
1353  Out << "@end";
1354  // FIXME: implement the rest...
1355 }
1356 
1357 void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1358  if (!PID->isThisDeclarationADefinition()) {
1359  Out << "@protocol " << *PID << ";\n";
1360  return;
1361  }
1362  // Protocols?
1363  const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1364  if (!Protocols.empty()) {
1365  Out << "@protocol " << *PID;
1366  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1367  E = Protocols.end(); I != E; ++I)
1368  Out << (I == Protocols.begin() ? '<' : ',') << **I;
1369  Out << ">\n";
1370  } else
1371  Out << "@protocol " << *PID << '\n';
1372  VisitDeclContext(PID, false);
1373  Out << "@end";
1374 }
1375 
1376 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
1377  Out << "@implementation ";
1378  if (const auto *CID = PID->getClassInterface())
1379  Out << *CID;
1380  else
1381  Out << "<<error-type>>";
1382  Out << '(' << *PID << ")\n";
1383 
1384  VisitDeclContext(PID, false);
1385  Out << "@end";
1386  // FIXME: implement the rest...
1387 }
1388 
1389 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1390  Out << "@interface ";
1391  if (const auto *CID = PID->getClassInterface())
1392  Out << *CID;
1393  else
1394  Out << "<<error-type>>";
1395  if (auto TypeParams = PID->getTypeParamList()) {
1396  PrintObjCTypeParams(TypeParams);
1397  }
1398  Out << "(" << *PID << ")\n";
1399  if (PID->ivar_size() > 0) {
1400  Out << "{\n";
1401  Indentation += Policy.Indentation;
1402  for (const auto *I : PID->ivars())
1403  Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1404  getAsString(Policy) << ' ' << *I << ";\n";
1405  Indentation -= Policy.Indentation;
1406  Out << "}\n";
1407  }
1408 
1409  VisitDeclContext(PID, false);
1410  Out << "@end";
1411 
1412  // FIXME: implement the rest...
1413 }
1414 
1415 void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
1416  Out << "@compatibility_alias " << *AID
1417  << ' ' << *AID->getClassInterface() << ";\n";
1418 }
1419 
1420 /// PrintObjCPropertyDecl - print a property declaration.
1421 ///
1422 /// Print attributes in the following order:
1423 /// - class
1424 /// - nonatomic | atomic
1425 /// - assign | retain | strong | copy | weak | unsafe_unretained
1426 /// - readwrite | readonly
1427 /// - getter & setter
1428 /// - nullability
1429 void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1431  Out << "@required\n";
1433  Out << "@optional\n";
1434 
1435  QualType T = PDecl->getType();
1436 
1437  Out << "@property";
1439  bool first = true;
1440  Out << "(";
1442  Out << (first ? "" : ", ") << "class";
1443  first = false;
1444  }
1445 
1447  Out << (first ? "" : ", ") << "direct";
1448  first = false;
1449  }
1450 
1451  if (PDecl->getPropertyAttributes() &
1453  Out << (first ? "" : ", ") << "nonatomic";
1454  first = false;
1455  }
1457  Out << (first ? "" : ", ") << "atomic";
1458  first = false;
1459  }
1460 
1462  Out << (first ? "" : ", ") << "assign";
1463  first = false;
1464  }
1466  Out << (first ? "" : ", ") << "retain";
1467  first = false;
1468  }
1469 
1471  Out << (first ? "" : ", ") << "strong";
1472  first = false;
1473  }
1475  Out << (first ? "" : ", ") << "copy";
1476  first = false;
1477  }
1479  Out << (first ? "" : ", ") << "weak";
1480  first = false;
1481  }
1482  if (PDecl->getPropertyAttributes() &
1484  Out << (first ? "" : ", ") << "unsafe_unretained";
1485  first = false;
1486  }
1487 
1488  if (PDecl->getPropertyAttributes() &
1490  Out << (first ? "" : ", ") << "readwrite";
1491  first = false;
1492  }
1494  Out << (first ? "" : ", ") << "readonly";
1495  first = false;
1496  }
1497 
1499  Out << (first ? "" : ", ") << "getter = ";
1500  PDecl->getGetterName().print(Out);
1501  first = false;
1502  }
1504  Out << (first ? "" : ", ") << "setter = ";
1505  PDecl->getSetterName().print(Out);
1506  first = false;
1507  }
1508 
1509  if (PDecl->getPropertyAttributes() &
1511  if (auto nullability = AttributedType::stripOuterNullability(T)) {
1512  if (*nullability == NullabilityKind::Unspecified &&
1513  (PDecl->getPropertyAttributes() &
1515  Out << (first ? "" : ", ") << "null_resettable";
1516  } else {
1517  Out << (first ? "" : ", ")
1518  << getNullabilitySpelling(*nullability, true);
1519  }
1520  first = false;
1521  }
1522  }
1523 
1524  (void) first; // Silence dead store warning due to idiomatic code.
1525  Out << ")";
1526  }
1527  std::string TypeStr = PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
1528  getAsString(Policy);
1529  Out << ' ' << TypeStr;
1530  if (!StringRef(TypeStr).endswith("*"))
1531  Out << ' ';
1532  Out << *PDecl;
1533  if (Policy.PolishForDeclaration)
1534  Out << ';';
1535 }
1536 
1537 void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1539  Out << "@synthesize ";
1540  else
1541  Out << "@dynamic ";
1542  Out << *PID->getPropertyDecl();
1543  if (PID->getPropertyIvarDecl())
1544  Out << '=' << *PID->getPropertyIvarDecl();
1545 }
1546 
1547 void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1548  if (!D->isAccessDeclaration())
1549  Out << "using ";
1550  if (D->hasTypename())
1551  Out << "typename ";
1552  D->getQualifier()->print(Out, Policy);
1553 
1554  // Use the correct record name when the using declaration is used for
1555  // inheriting constructors.
1556  for (const auto *Shadow : D->shadows()) {
1557  if (const auto *ConstructorShadow =
1558  dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1559  assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1560  Out << *ConstructorShadow->getNominatedBaseClass();
1561  return;
1562  }
1563  }
1564  Out << *D;
1565 }
1566 
1567 void
1568 DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1569  Out << "using typename ";
1570  D->getQualifier()->print(Out, Policy);
1571  Out << D->getDeclName();
1572 }
1573 
1574 void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1575  if (!D->isAccessDeclaration())
1576  Out << "using ";
1577  D->getQualifier()->print(Out, Policy);
1578  Out << D->getDeclName();
1579 }
1580 
1581 void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1582  // ignore
1583 }
1584 
1585 void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1586  Out << "#pragma omp threadprivate";
1587  if (!D->varlist_empty()) {
1589  E = D->varlist_end();
1590  I != E; ++I) {
1591  Out << (I == D->varlist_begin() ? '(' : ',');
1592  NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1593  ND->printQualifiedName(Out);
1594  }
1595  Out << ")";
1596  }
1597 }
1598 
1599 void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1600  Out << "#pragma omp allocate";
1601  if (!D->varlist_empty()) {
1603  E = D->varlist_end();
1604  I != E; ++I) {
1605  Out << (I == D->varlist_begin() ? '(' : ',');
1606  NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1607  ND->printQualifiedName(Out);
1608  }
1609  Out << ")";
1610  }
1611  if (!D->clauselist_empty()) {
1612  Out << " ";
1613  OMPClausePrinter Printer(Out, Policy);
1614  for (OMPClause *C : D->clauselists())
1615  Printer.Visit(C);
1616  }
1617 }
1618 
1619 void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1620  Out << "#pragma omp requires ";
1621  if (!D->clauselist_empty()) {
1622  OMPClausePrinter Printer(Out, Policy);
1623  for (auto I = D->clauselist_begin(), E = D->clauselist_end(); I != E; ++I)
1624  Printer.Visit(*I);
1625  }
1626 }
1627 
1628 void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1629  if (!D->isInvalidDecl()) {
1630  Out << "#pragma omp declare reduction (";
1632  const char *OpName =
1634  assert(OpName && "not an overloaded operator");
1635  Out << OpName;
1636  } else {
1637  assert(D->getDeclName().isIdentifier());
1638  D->printName(Out);
1639  }
1640  Out << " : ";
1641  D->getType().print(Out, Policy);
1642  Out << " : ";
1643  D->getCombiner()->printPretty(Out, nullptr, Policy, 0);
1644  Out << ")";
1645  if (auto *Init = D->getInitializer()) {
1646  Out << " initializer(";
1647  switch (D->getInitializerKind()) {
1649  Out << "omp_priv(";
1650  break;
1652  Out << "omp_priv = ";
1653  break;
1655  break;
1656  }
1657  Init->printPretty(Out, nullptr, Policy, 0);
1659  Out << ")";
1660  Out << ")";
1661  }
1662  }
1663 }
1664 
1665 void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
1666  if (!D->isInvalidDecl()) {
1667  Out << "#pragma omp declare mapper (";
1668  D->printName(Out);
1669  Out << " : ";
1670  D->getType().print(Out, Policy);
1671  Out << " ";
1672  Out << D->getVarName();
1673  Out << ")";
1674  if (!D->clauselist_empty()) {
1675  OMPClausePrinter Printer(Out, Policy);
1676  for (auto *C : D->clauselists()) {
1677  Out << " ";
1678  Printer.Visit(C);
1679  }
1680  }
1681  }
1682 }
1683 
1684 void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
1685  D->getInit()->printPretty(Out, nullptr, Policy, Indentation);
1686 }
1687 
1688 void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) {
1689  if (const TypeConstraint *TC = TTP->getTypeConstraint())
1690  TC->print(Out, Policy);
1691  else if (TTP->wasDeclaredWithTypename())
1692  Out << "typename";
1693  else
1694  Out << "class";
1695 
1696  if (TTP->isParameterPack())
1697  Out << " ...";
1698  else if (!TTP->getName().empty())
1699  Out << ' ';
1700 
1701  Out << *TTP;
1702 
1703  if (TTP->hasDefaultArgument()) {
1704  Out << " = ";
1705  Out << TTP->getDefaultArgument().getAsString(Policy);
1706  }
1707 }
1708 
1709 void DeclPrinter::VisitNonTypeTemplateParmDecl(
1710  const NonTypeTemplateParmDecl *NTTP) {
1711  StringRef Name;
1712  if (IdentifierInfo *II = NTTP->getIdentifier())
1713  Name = II->getName();
1714  printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1715 
1716  if (NTTP->hasDefaultArgument()) {
1717  Out << " = ";
1718  NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, Indentation);
1719  }
1720 }
clauselist_range clauselists()
Definition: DeclOpenMP.h:270
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
Definition: Decl.h:1783
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:4244
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2645
A (possibly-)qualified type.
Definition: Type.h:655
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
unsigned getFriendTypeNumTemplateParameterLists() const
Definition: DeclFriend.h:127
varlist_iterator varlist_end()
Definition: DeclOpenMP.h:498
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2316
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:582
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4164
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:1521
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2821
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:2879
Expr * getBitWidth() const
Definition: Decl.h:2835
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3547
This represents &#39;#pragma omp allocate ...&#39; directive.
Definition: DeclOpenMP.h:422
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition: Decl.cpp:3696
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:627
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2961
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1029
Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier.
Definition: Decl.h:3193
spec_range specializations() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4218
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:1038
Defines the C++ template declaration subclasses.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Definition: ASTContext.h:1949
ivar_range ivars() const
Definition: DeclObjC.h:1449
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:4981
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2176
Represents an empty-declaration.
Definition: Decl.h:4485
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:2888
Represent a C++ namespace.
Definition: Decl.h:497
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1426
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition: DeclCXX.h:2941
bool clauselist_empty() const
Definition: DeclOpenMP.h:489
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:115
A container of type source information.
Definition: Type.h:6373
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1816
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:2870
param_const_iterator param_end() const
Definition: DeclObjC.h:354
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2413
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2096
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3344
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:53
Represents a variable declaration or definition.
Definition: Decl.h:820
llvm::StringRef getAccessSpelling(AccessSpecifier AS)
Definition: Specifiers.h:373
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:7153
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
bool clauselist_empty() const
Definition: DeclOpenMP.h:268
bool isConst() const
Definition: Type.h:3828
bool isInvalidDecl() const
Definition: DeclBase.h:558
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:69
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:49
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Definition: InterpFrame.cpp:62
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Definition: ExprCXX.h:3295
Represents a parameter to a function.
Definition: Decl.h:1595
Defines the clang::Expr interface and subclasses for C++ expressions.
iterator end() const
Definition: DeclObjC.h:92
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2678
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
Represents a struct/union/class.
Definition: Decl.h:3770
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2836
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:272
C11 _Thread_local.
Definition: Specifiers.h:236
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:123
StringLiteral * getMessage()
Definition: DeclCXX.h:3818
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:2112
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:174
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:558
The parameter is contravariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant ...
NameKind getNameKind() const
Determine what kind of name this is.
Represents a member of a struct/union/class.
Definition: Decl.h:2746
RetTy Visit(PTR(OMPClause) S)
InitKind getInitializerKind() const
Get initializer kind.
Definition: DeclOpenMP.h:173
std::string getNameAsString() const
Get the name of the class associated with this interface.
Definition: DeclObjC.h:2672
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:138
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Definition: DeclObjC.h:1302
Represents a C++ using-declaration.
Definition: DeclCXX.h:3398
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Definition: DeclOpenMP.h:170
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2824
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1428
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2881
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:225
Microsoft throw(...) extension.
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4172
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
unsigned ivar_size() const
Definition: DeclObjC.h:2702
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition: Decl.h:2171
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3575
bool clauselist_empty() const
Definition: DeclOpenMP.h:388
Whether values of this type can be null is (explicitly) unspecified.
NamedDecl * getNominatedNamespaceAsWritten()
Definition: DeclCXX.h:2945
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:611
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no &#39;using&#39;).
Definition: DeclCXX.h:3450
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1412
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:4130
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
Definition: DeclFriend.h:131
base_class_iterator bases_begin()
Definition: DeclCXX.h:595
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2055
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:924
Represents an ObjC class declaration.
Definition: DeclObjC.h:1163
Represents a linkage specification.
Definition: DeclCXX.h:2807
QualType getReturnType() const
Definition: DeclObjC.h:325
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
bool isConstexprSpecified() const
Definition: Decl.h:2207
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:4417
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2748
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2845
bool hasAttr() const
Definition: DeclBase.h:547
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition: DeclCXX.h:3064
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3213
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3886
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition: DeclObjC.h:1556
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
Definition: DeclOpenMP.h:288
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
bool empty() const
Definition: DeclObjC.h:72
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
Definition: DeclOpenMP.h:152
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition: DeclOpenMP.h:69
unsigned ivar_size() const
Definition: DeclObjC.h:1467
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3141
This represents &#39;#pragma omp requires...&#39; directive.
Definition: DeclOpenMP.h:345
bool isConsteval() const
Definition: Decl.h:2210
varlist_iterator varlist_begin()
Definition: DeclOpenMP.h:497
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2510
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:619
This represents one expression.
Definition: Expr.h:110
StringRef getKindName() const
Definition: Decl.h:3414
SourceLocation End
Selector getSetterName() const
Definition: DeclObjC.h:905
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:50
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3700
Declaration of a template type parameter.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:2071
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2212
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:563
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3686
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition: Decl.h:729
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition: Decl.h:763
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:338
SourceLocation Begin
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2499
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
const Expr * getExpr() const
Definition: DeclCXX.h:1825
void removeLocalConst()
Definition: Type.h:6496
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2600
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:4104
StorageClass
Storage classes.
Definition: Specifiers.h:240
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:2715
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1816
bool isInstanceMethod() const
Definition: DeclObjC.h:424
clauselist_range clauselists()
Definition: DeclOpenMP.h:502
Represents a GCC generic vector type.
Definition: Type.h:3234
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Definition: PrettyPrinter.h:95
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1871
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:1537
Selector getSelector() const
Definition: DeclObjC.h:323
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2743
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:186
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:720
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition: Decl.h:1309
QualType getType() const
Definition: DeclObjC.h:814
AttrVec & getAttrs()
Definition: DeclBase.h:495
bool hasAttrs() const
Definition: DeclBase.h:489
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3752
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4234
virtual void printName(raw_ostream &os) const
Definition: Decl.cpp:1526
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:747
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
std::string getAsString() const
Derive the full selector name (e.g.
bool isParameterPack() const
Returns whether this is a parameter pack.
Sugar for parentheses used when specifying types.
Definition: Type.h:2619
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2105
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1437
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3662
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:312
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2321
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:266
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the &#39;typename&#39; keyword.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3239
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
Represents the declaration of a label.
Definition: Decl.h:451
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3617
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2893
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:856
bool isRestrict() const
Definition: Type.h:3830
varlist_iterator varlist_begin()
Definition: DeclOpenMP.h:83
GNU __thread.
Definition: Specifiers.h:230
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
No ref-qualifier was provided.
Definition: Type.h:1425
C-style initialization with assignment.
Definition: Decl.h:825
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2425
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2271
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:52
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:4179
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3697
Defines the clang::Module class, which describes a module in the source code.
Direct list-initialization.
Definition: Specifiers.h:266
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:742
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:66
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
Definition: DeclCXX.cpp:1993
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: DeclObjC.h:249
static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, PrintingPolicy &Policy, unsigned Indentation)
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition: Decl.h:2134
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1977
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3792
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1431
clauselist_iterator clauselist_begin()
Definition: DeclOpenMP.h:396
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4121
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4358
Represents a pack expansion of types.
Definition: Type.h:5610
C++11 thread_local.
Definition: Specifiers.h:233
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:1937
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2022
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3091
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2431
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1053
Dataflow Directional Tag Classes.
ivar_range ivars() const
Definition: DeclObjC.h:2692
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1303
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:402
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2817
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no &#39;using&#39;).
Definition: DeclCXX.h:3655
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1332
const Expr * getInit() const
Definition: Decl.h:1229
AccessSpecifier getAccess() const
Definition: DeclBase.h:478
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3713
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:997
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:759
Represents an enum.
Definition: Decl.h:3501
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2736
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition: DeclOpenMP.h:476
Pointer to a block type.
Definition: Type.h:2725
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2543
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword...
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:700
param_const_iterator param_begin() const
Definition: DeclObjC.h:350
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2756
clauselist_iterator clauselist_end()
Definition: DeclOpenMP.h:397
bool isVolatile() const
Definition: Type.h:3829
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
bool hasTypename() const
Return true if the using declaration has &#39;typename&#39;.
Definition: DeclCXX.h:3453
A template argument list.
Definition: DeclTemplate.h:239
shadow_range shadows() const
Definition: DeclCXX.h:3498
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:828
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2821
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
ObjCDeclQualifier
ObjCDeclQualifier - &#39;Qualifiers&#39; written next to the return and parameter types in method declaration...
Definition: DeclBase.h:201
base_class_iterator bases_end()
Definition: DeclCXX.h:597
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:825
bool varlist_empty() const
Definition: DeclOpenMP.h:487
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:650
bool isVariadic() const
Definition: DeclObjC.h:429
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
Definition: DeclCXX.h:1829
This represents &#39;#pragma omp declare mapper ...&#39; directive.
Definition: DeclOpenMP.h:217
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1720
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3657
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2078
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3441
std::string getQualifiedNameAsString() const
Definition: Decl.cpp:1530
The top declaration context.
Definition: Decl.h:82
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition: JsonSupport.h:20
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2812
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:3023
QualType getDefaultArgument() const
Retrieve the default argument, if any.
QualType getType() const
Definition: Decl.h:630
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
Definition: DeclBase.h:612
This represents a decl that may have a name.
Definition: Decl.h:223
bool isTranslationUnit() const
Definition: DeclBase.h:1891
Represents a C++ namespace alias.
Definition: DeclCXX.h:2996
Selector getGetterName() const
Definition: DeclObjC.h:897
Represents C++ using-directive.
Definition: DeclCXX.h:2892
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:3242
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:2490
The parameter is invariant: must match exactly.
void dumpDeclContext() const
Declaration of a template function.
Definition: DeclTemplate.h:977
bool isDeletedAsWritten() const
Definition: Decl.h:2261
const StringLiteral * getAsmString() const
Definition: Decl.h:4053
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Definition: DeclCXX.h:3191
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6384
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:369
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2718
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2943
decl_iterator decls_end() const
Definition: DeclBase.h:2067