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