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