clang  3.7.0
DeclPrinter.cpp
Go to the documentation of this file.
1 //===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Decl::print method, which pretty prints the
11 // AST back out to C/Objective-C/C++/Objective-C++ code.
12 //
13 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclVisitor.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.h"
23 #include "clang/Basic/Module.h"
24 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
26 
27 namespace {
28  class DeclPrinter : public DeclVisitor<DeclPrinter> {
29  raw_ostream &Out;
30  PrintingPolicy Policy;
31  unsigned Indentation;
32  bool PrintInstantiation;
33 
34  raw_ostream& Indent() { return Indent(Indentation); }
35  raw_ostream& Indent(unsigned Indentation);
36  void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls);
37 
38  void Print(AccessSpecifier AS);
39 
40  /// Print an Objective-C method type in parentheses.
41  ///
42  /// \param Quals The Objective-C declaration qualifiers.
43  /// \param T The type to print.
44  void PrintObjCMethodType(ASTContext &Ctx, Decl::ObjCDeclQualifier Quals,
45  QualType T);
46 
47  void PrintObjCTypeParams(ObjCTypeParamList *Params);
48 
49  public:
50  DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy,
51  unsigned Indentation = 0, bool PrintInstantiation = false)
52  : Out(Out), Policy(Policy), Indentation(Indentation),
53  PrintInstantiation(PrintInstantiation) { }
54 
55  void VisitDeclContext(DeclContext *DC, bool Indent = true);
56 
60  void VisitEnumDecl(EnumDecl *D);
61  void VisitRecordDecl(RecordDecl *D);
63  void VisitEmptyDecl(EmptyDecl *D);
65  void VisitFriendDecl(FriendDecl *D);
66  void VisitFieldDecl(FieldDecl *D);
67  void VisitVarDecl(VarDecl *D);
68  void VisitLabelDecl(LabelDecl *D);
71  void VisitImportDecl(ImportDecl *D);
78  void VisitTemplateDecl(const TemplateDecl *D);
92  void VisitUsingDecl(UsingDecl *D);
95 
96  void PrintTemplateParameters(const TemplateParameterList *Params,
97  const TemplateArgumentList *Args = nullptr);
98  void prettyPrintAttributes(Decl *D);
99  void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
100  };
101 }
102 
103 void Decl::print(raw_ostream &Out, unsigned Indentation,
104  bool PrintInstantiation) const {
105  print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
106 }
107 
108 void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
109  unsigned Indentation, bool PrintInstantiation) const {
110  DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation);
111  Printer.Visit(const_cast<Decl*>(this));
112 }
113 
115  // FIXME: This should be on the Type class!
116  QualType BaseType = T;
117  while (!BaseType->isSpecifierType()) {
118  if (isa<TypedefType>(BaseType))
119  break;
120  else if (const PointerType* PTy = BaseType->getAs<PointerType>())
121  BaseType = PTy->getPointeeType();
122  else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
123  BaseType = BPy->getPointeeType();
124  else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
125  BaseType = ATy->getElementType();
126  else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
127  BaseType = FTy->getReturnType();
128  else if (const VectorType *VTy = BaseType->getAs<VectorType>())
129  BaseType = VTy->getElementType();
130  else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
131  BaseType = RTy->getPointeeType();
132  else
133  llvm_unreachable("Unknown declarator!");
134  }
135  return BaseType;
136 }
137 
139  if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
140  return TDD->getUnderlyingType();
141  if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
142  return VD->getType();
143  return QualType();
144 }
145 
146 void Decl::printGroup(Decl** Begin, unsigned NumDecls,
147  raw_ostream &Out, const PrintingPolicy &Policy,
148  unsigned Indentation) {
149  if (NumDecls == 1) {
150  (*Begin)->print(Out, Policy, Indentation);
151  return;
152  }
153 
154  Decl** End = Begin + NumDecls;
155  TagDecl* TD = dyn_cast<TagDecl>(*Begin);
156  if (TD)
157  ++Begin;
158 
159  PrintingPolicy SubPolicy(Policy);
160  if (TD && TD->isCompleteDefinition()) {
161  TD->print(Out, Policy, Indentation);
162  Out << " ";
163  SubPolicy.SuppressTag = true;
164  }
165 
166  bool isFirst = true;
167  for ( ; Begin != End; ++Begin) {
168  if (isFirst) {
169  SubPolicy.SuppressSpecifiers = false;
170  isFirst = false;
171  } else {
172  if (!isFirst) Out << ", ";
173  SubPolicy.SuppressSpecifiers = true;
174  }
175 
176  (*Begin)->print(Out, SubPolicy, Indentation);
177  }
178 }
179 
180 LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
181  // Get the translation unit
182  const DeclContext *DC = this;
183  while (!DC->isTranslationUnit())
184  DC = DC->getParent();
185 
186  ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
187  DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0);
188  Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
189 }
190 
191 raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
192  for (unsigned i = 0; i != Indentation; ++i)
193  Out << " ";
194  return Out;
195 }
196 
197 void DeclPrinter::prettyPrintAttributes(Decl *D) {
198  if (Policy.PolishForDeclaration)
199  return;
200 
201  if (D->hasAttrs()) {
202  AttrVec &Attrs = D->getAttrs();
203  for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) {
204  Attr *A = *i;
205  A->printPretty(Out, Policy);
206  }
207  }
208 }
209 
210 void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
211  // Normally, a PackExpansionType is written as T[3]... (for instance, as a
212  // template argument), but if it is the type of a declaration, the ellipsis
213  // is placed before the name being declared.
214  if (auto *PET = T->getAs<PackExpansionType>()) {
215  Pack = true;
216  T = PET->getPattern();
217  }
218  T.print(Out, Policy, (Pack ? "..." : "") + DeclName);
219 }
220 
221 void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
222  this->Indent();
223  Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
224  Out << ";\n";
225  Decls.clear();
226 
227 }
228 
229 void DeclPrinter::Print(AccessSpecifier AS) {
230  switch(AS) {
231  case AS_none: llvm_unreachable("No access specifier!");
232  case AS_public: Out << "public"; break;
233  case AS_protected: Out << "protected"; break;
234  case AS_private: Out << "private"; break;
235  }
236 }
237 
238 //----------------------------------------------------------------------------
239 // Common C declarations
240 //----------------------------------------------------------------------------
241 
242 void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
243  if (Policy.TerseOutput)
244  return;
245 
246  if (Indent)
247  Indentation += Policy.Indentation;
248 
249  SmallVector<Decl*, 2> Decls;
250  for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
251  D != DEnd; ++D) {
252 
253  // Don't print ObjCIvarDecls, as they are printed when visiting the
254  // containing ObjCInterfaceDecl.
255  if (isa<ObjCIvarDecl>(*D))
256  continue;
257 
258  // Skip over implicit declarations in pretty-printing mode.
259  if (D->isImplicit())
260  continue;
261 
262  // The next bits of code handles stuff like "struct {int x;} a,b"; we're
263  // forced to merge the declarations because there's no other way to
264  // refer to the struct in question. This limited merging is safe without
265  // a bunch of other checks because it only merges declarations directly
266  // referring to the tag, not typedefs.
267  //
268  // Check whether the current declaration should be grouped with a previous
269  // unnamed struct.
270  QualType CurDeclType = getDeclType(*D);
271  if (!Decls.empty() && !CurDeclType.isNull()) {
272  QualType BaseType = GetBaseType(CurDeclType);
273  if (!BaseType.isNull() && isa<ElaboratedType>(BaseType))
274  BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
275  if (!BaseType.isNull() && isa<TagType>(BaseType) &&
276  cast<TagType>(BaseType)->getDecl() == Decls[0]) {
277  Decls.push_back(*D);
278  continue;
279  }
280  }
281 
282  // If we have a merged group waiting to be handled, handle it now.
283  if (!Decls.empty())
284  ProcessDeclGroup(Decls);
285 
286  // If the current declaration is an unnamed tag type, save it
287  // so we can merge it with the subsequent declaration(s) using it.
288  if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
289  Decls.push_back(*D);
290  continue;
291  }
292 
293  if (isa<AccessSpecDecl>(*D)) {
294  Indentation -= Policy.Indentation;
295  this->Indent();
296  Print(D->getAccess());
297  Out << ":\n";
298  Indentation += Policy.Indentation;
299  continue;
300  }
301 
302  this->Indent();
303  Visit(*D);
304 
305  // FIXME: Need to be able to tell the DeclPrinter when
306  const char *Terminator = nullptr;
307  if (isa<OMPThreadPrivateDecl>(*D))
308  Terminator = nullptr;
309  else if (isa<FunctionDecl>(*D) &&
310  cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
311  Terminator = nullptr;
312  else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
313  Terminator = nullptr;
314  else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
315  isa<ObjCImplementationDecl>(*D) ||
316  isa<ObjCInterfaceDecl>(*D) ||
317  isa<ObjCProtocolDecl>(*D) ||
318  isa<ObjCCategoryImplDecl>(*D) ||
319  isa<ObjCCategoryDecl>(*D))
320  Terminator = nullptr;
321  else if (isa<EnumConstantDecl>(*D)) {
323  ++Next;
324  if (Next != DEnd)
325  Terminator = ",";
326  } else
327  Terminator = ";";
328 
329  if (Terminator)
330  Out << Terminator;
331  Out << "\n";
332  }
333 
334  if (!Decls.empty())
335  ProcessDeclGroup(Decls);
336 
337  if (Indent)
338  Indentation -= Policy.Indentation;
339 }
340 
341 void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
342  VisitDeclContext(D, false);
343 }
344 
345 void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
346  if (!Policy.SuppressSpecifiers) {
347  Out << "typedef ";
348 
349  if (D->isModulePrivate())
350  Out << "__module_private__ ";
351  }
352  D->getTypeSourceInfo()->getType().print(Out, Policy, D->getName());
353  prettyPrintAttributes(D);
354 }
355 
356 void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
357  Out << "using " << *D;
358  prettyPrintAttributes(D);
359  Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
360 }
361 
362 void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
363  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
364  Out << "__module_private__ ";
365  Out << "enum ";
366  if (D->isScoped()) {
367  if (D->isScopedUsingClassTag())
368  Out << "class ";
369  else
370  Out << "struct ";
371  }
372  Out << *D;
373 
374  if (D->isFixed())
375  Out << " : " << D->getIntegerType().stream(Policy);
376 
377  if (D->isCompleteDefinition()) {
378  Out << " {\n";
379  VisitDeclContext(D);
380  Indent() << "}";
381  }
382  prettyPrintAttributes(D);
383 }
384 
385 void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
386  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
387  Out << "__module_private__ ";
388  Out << D->getKindName();
389 
390  prettyPrintAttributes(D);
391 
392  if (D->getIdentifier())
393  Out << ' ' << *D;
394 
395  if (D->isCompleteDefinition()) {
396  Out << " {\n";
397  VisitDeclContext(D);
398  Indent() << "}";
399  }
400 }
401 
402 void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
403  Out << *D;
404  if (Expr *Init = D->getInitExpr()) {
405  Out << " = ";
406  Init->printPretty(Out, nullptr, Policy, Indentation);
407  }
408 }
409 
410 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
411  CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
412  CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
413  if (!Policy.SuppressSpecifiers) {
414  switch (D->getStorageClass()) {
415  case SC_None: break;
416  case SC_Extern: Out << "extern "; break;
417  case SC_Static: Out << "static "; break;
418  case SC_PrivateExtern: Out << "__private_extern__ "; break;
420  llvm_unreachable("invalid for functions");
421  }
422 
423  if (D->isInlineSpecified()) Out << "inline ";
424  if (D->isVirtualAsWritten()) Out << "virtual ";
425  if (D->isModulePrivate()) Out << "__module_private__ ";
426  if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr ";
427  if ((CDecl && CDecl->isExplicitSpecified()) ||
428  (ConversionDecl && ConversionDecl->isExplicit()))
429  Out << "explicit ";
430  }
431 
432  PrintingPolicy SubPolicy(Policy);
433  SubPolicy.SuppressSpecifiers = false;
434  std::string Proto = D->getNameInfo().getAsString();
435 
436  QualType Ty = D->getType();
437  while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
438  Proto = '(' + Proto + ')';
439  Ty = PT->getInnerType();
440  }
441 
442  if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
443  const FunctionProtoType *FT = nullptr;
444  if (D->hasWrittenPrototype())
445  FT = dyn_cast<FunctionProtoType>(AFT);
446 
447  Proto += "(";
448  if (FT) {
449  llvm::raw_string_ostream POut(Proto);
450  DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
451  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
452  if (i) POut << ", ";
453  ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
454  }
455 
456  if (FT->isVariadic()) {
457  if (D->getNumParams()) POut << ", ";
458  POut << "...";
459  }
460  } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
461  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
462  if (i)
463  Proto += ", ";
464  Proto += D->getParamDecl(i)->getNameAsString();
465  }
466  }
467 
468  Proto += ")";
469 
470  if (FT) {
471  if (FT->isConst())
472  Proto += " const";
473  if (FT->isVolatile())
474  Proto += " volatile";
475  if (FT->isRestrict())
476  Proto += " restrict";
477 
478  switch (FT->getRefQualifier()) {
479  case RQ_None:
480  break;
481  case RQ_LValue:
482  Proto += " &";
483  break;
484  case RQ_RValue:
485  Proto += " &&";
486  break;
487  }
488  }
489 
490  if (FT && FT->hasDynamicExceptionSpec()) {
491  Proto += " throw(";
492  if (FT->getExceptionSpecType() == EST_MSAny)
493  Proto += "...";
494  else
495  for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
496  if (I)
497  Proto += ", ";
498 
499  Proto += FT->getExceptionType(I).getAsString(SubPolicy);
500  }
501  Proto += ")";
502  } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
503  Proto += " noexcept";
505  Proto += "(";
506  llvm::raw_string_ostream EOut(Proto);
507  FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
508  Indentation);
509  EOut.flush();
510  Proto += EOut.str();
511  Proto += ")";
512  }
513  }
514 
515  if (CDecl) {
516  bool HasInitializerList = false;
517  for (const auto *BMInitializer : CDecl->inits()) {
518  if (BMInitializer->isInClassMemberInitializer())
519  continue;
520 
521  if (!HasInitializerList) {
522  Proto += " : ";
523  Out << Proto;
524  Proto.clear();
525  HasInitializerList = true;
526  } else
527  Out << ", ";
528 
529  if (BMInitializer->isAnyMemberInitializer()) {
530  FieldDecl *FD = BMInitializer->getAnyMember();
531  Out << *FD;
532  } else {
533  Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
534  }
535 
536  Out << "(";
537  if (!BMInitializer->getInit()) {
538  // Nothing to print
539  } else {
540  Expr *Init = BMInitializer->getInit();
541  if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
542  Init = Tmp->getSubExpr();
543 
544  Init = Init->IgnoreParens();
545 
546  Expr *SimpleInit = nullptr;
547  Expr **Args = nullptr;
548  unsigned NumArgs = 0;
549  if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
550  Args = ParenList->getExprs();
551  NumArgs = ParenList->getNumExprs();
552  } else if (CXXConstructExpr *Construct
553  = dyn_cast<CXXConstructExpr>(Init)) {
554  Args = Construct->getArgs();
555  NumArgs = Construct->getNumArgs();
556  } else
557  SimpleInit = Init;
558 
559  if (SimpleInit)
560  SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
561  else {
562  for (unsigned I = 0; I != NumArgs; ++I) {
563  assert(Args[I] != nullptr && "Expected non-null Expr");
564  if (isa<CXXDefaultArgExpr>(Args[I]))
565  break;
566 
567  if (I)
568  Out << ", ";
569  Args[I]->printPretty(Out, nullptr, Policy, Indentation);
570  }
571  }
572  }
573  Out << ")";
574  if (BMInitializer->isPackExpansion())
575  Out << "...";
576  }
577  } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
578  if (FT && FT->hasTrailingReturn()) {
579  Out << "auto " << Proto << " -> ";
580  Proto.clear();
581  }
582  AFT->getReturnType().print(Out, Policy, Proto);
583  Proto.clear();
584  }
585  Out << Proto;
586  } else {
587  Ty.print(Out, Policy, Proto);
588  }
589 
590  prettyPrintAttributes(D);
591 
592  if (D->isPure())
593  Out << " = 0";
594  else if (D->isDeletedAsWritten())
595  Out << " = delete";
596  else if (D->isExplicitlyDefaulted())
597  Out << " = default";
598  else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) {
599  if (!D->hasPrototype() && D->getNumParams()) {
600  // This is a K&R function definition, so we need to print the
601  // parameters.
602  Out << '\n';
603  DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
604  Indentation += Policy.Indentation;
605  for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
606  Indent();
607  ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
608  Out << ";\n";
609  }
610  Indentation -= Policy.Indentation;
611  } else
612  Out << ' ';
613 
614  if (D->getBody())
615  D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation);
616  Out << '\n';
617  }
618 }
619 
620 void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
621  if (TypeSourceInfo *TSI = D->getFriendType()) {
622  unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
623  for (unsigned i = 0; i < NumTPLists; ++i)
624  PrintTemplateParameters(D->getFriendTypeTemplateParameterList(i));
625  Out << "friend ";
626  Out << " " << TSI->getType().getAsString(Policy);
627  }
628  else if (FunctionDecl *FD =
629  dyn_cast<FunctionDecl>(D->getFriendDecl())) {
630  Out << "friend ";
631  VisitFunctionDecl(FD);
632  }
633  else if (FunctionTemplateDecl *FTD =
634  dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
635  Out << "friend ";
636  VisitFunctionTemplateDecl(FTD);
637  }
638  else if (ClassTemplateDecl *CTD =
639  dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
640  Out << "friend ";
641  VisitRedeclarableTemplateDecl(CTD);
642  }
643 }
644 
645 void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
646  if (!Policy.SuppressSpecifiers && D->isMutable())
647  Out << "mutable ";
648  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
649  Out << "__module_private__ ";
650 
652  stream(Policy, D->getName());
653 
654  if (D->isBitField()) {
655  Out << " : ";
656  D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation);
657  }
658 
659  Expr *Init = D->getInClassInitializer();
660  if (!Policy.SuppressInitializers && Init) {
662  Out << " ";
663  else
664  Out << " = ";
665  Init->printPretty(Out, nullptr, Policy, Indentation);
666  }
667  prettyPrintAttributes(D);
668 }
669 
670 void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
671  Out << *D << ":";
672 }
673 
674 void DeclPrinter::VisitVarDecl(VarDecl *D) {
675  if (!Policy.SuppressSpecifiers) {
676  StorageClass SC = D->getStorageClass();
677  if (SC != SC_None)
678  Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
679 
680  switch (D->getTSCSpec()) {
681  case TSCS_unspecified:
682  break;
683  case TSCS___thread:
684  Out << "__thread ";
685  break;
686  case TSCS__Thread_local:
687  Out << "_Thread_local ";
688  break;
689  case TSCS_thread_local:
690  Out << "thread_local ";
691  break;
692  }
693 
694  if (D->isModulePrivate())
695  Out << "__module_private__ ";
696  }
697 
698  QualType T = D->getTypeSourceInfo()
699  ? D->getTypeSourceInfo()->getType()
701  printDeclType(T, D->getName());
702  Expr *Init = D->getInit();
703  if (!Policy.SuppressInitializers && Init) {
704  bool ImplicitInit = false;
705  if (CXXConstructExpr *Construct =
706  dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
707  if (D->getInitStyle() == VarDecl::CallInit &&
708  !Construct->isListInitialization()) {
709  ImplicitInit = Construct->getNumArgs() == 0 ||
710  Construct->getArg(0)->isDefaultArgument();
711  }
712  }
713  if (!ImplicitInit) {
714  if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
715  Out << "(";
716  else if (D->getInitStyle() == VarDecl::CInit) {
717  Out << " = ";
718  }
719  Init->printPretty(Out, nullptr, Policy, Indentation);
720  if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
721  Out << ")";
722  }
723  }
724  prettyPrintAttributes(D);
725 }
726 
727 void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
728  VisitVarDecl(D);
729 }
730 
731 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
732  Out << "__asm (";
733  D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation);
734  Out << ")";
735 }
736 
737 void DeclPrinter::VisitImportDecl(ImportDecl *D) {
738  Out << "@import " << D->getImportedModule()->getFullModuleName()
739  << ";\n";
740 }
741 
742 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
743  Out << "static_assert(";
744  D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation);
745  if (StringLiteral *SL = D->getMessage()) {
746  Out << ", ";
747  SL->printPretty(Out, nullptr, Policy, Indentation);
748  }
749  Out << ")";
750 }
751 
752 //----------------------------------------------------------------------------
753 // C++ declarations
754 //----------------------------------------------------------------------------
755 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
756  if (D->isInline())
757  Out << "inline ";
758  Out << "namespace " << *D << " {\n";
759  VisitDeclContext(D);
760  Indent() << "}";
761 }
762 
763 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
764  Out << "using namespace ";
765  if (D->getQualifier())
766  D->getQualifier()->print(Out, Policy);
767  Out << *D->getNominatedNamespaceAsWritten();
768 }
769 
770 void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
771  Out << "namespace " << *D << " = ";
772  if (D->getQualifier())
773  D->getQualifier()->print(Out, Policy);
774  Out << *D->getAliasedNamespace();
775 }
776 
777 void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
778  prettyPrintAttributes(D);
779 }
780 
781 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
782  if (!Policy.SuppressSpecifiers && D->isModulePrivate())
783  Out << "__module_private__ ";
784  Out << D->getKindName();
785 
786  prettyPrintAttributes(D);
787 
788  if (D->getIdentifier())
789  Out << ' ' << *D;
790 
791  if (D->isCompleteDefinition()) {
792  // Print the base classes
793  if (D->getNumBases()) {
794  Out << " : ";
796  BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
797  if (Base != D->bases_begin())
798  Out << ", ";
799 
800  if (Base->isVirtual())
801  Out << "virtual ";
802 
803  AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
804  if (AS != AS_none) {
805  Print(AS);
806  Out << " ";
807  }
808  Out << Base->getType().getAsString(Policy);
809 
810  if (Base->isPackExpansion())
811  Out << "...";
812  }
813  }
814 
815  // Print the class definition
816  // FIXME: Doesn't print access specifiers, e.g., "public:"
817  Out << " {\n";
818  VisitDeclContext(D);
819  Indent() << "}";
820  }
821 }
822 
823 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
824  const char *l;
826  l = "C";
827  else {
828  assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
829  "unknown language in linkage specification");
830  l = "C++";
831  }
832 
833  Out << "extern \"" << l << "\" ";
834  if (D->hasBraces()) {
835  Out << "{\n";
836  VisitDeclContext(D);
837  Indent() << "}";
838  } else
839  Visit(*D->decls_begin());
840 }
841 
842 void DeclPrinter::PrintTemplateParameters(const TemplateParameterList *Params,
843  const TemplateArgumentList *Args) {
844  assert(Params);
845  assert(!Args || Params->size() == Args->size());
846 
847  Out << "template <";
848 
849  for (unsigned i = 0, e = Params->size(); i != e; ++i) {
850  if (i != 0)
851  Out << ", ";
852 
853  const Decl *Param = Params->getParam(i);
854  if (const TemplateTypeParmDecl *TTP =
855  dyn_cast<TemplateTypeParmDecl>(Param)) {
856 
857  if (TTP->wasDeclaredWithTypename())
858  Out << "typename ";
859  else
860  Out << "class ";
861 
862  if (TTP->isParameterPack())
863  Out << "...";
864 
865  Out << *TTP;
866 
867  if (Args) {
868  Out << " = ";
869  Args->get(i).print(Policy, Out);
870  } else if (TTP->hasDefaultArgument()) {
871  Out << " = ";
872  Out << TTP->getDefaultArgument().getAsString(Policy);
873  };
874  } else if (const NonTypeTemplateParmDecl *NTTP =
875  dyn_cast<NonTypeTemplateParmDecl>(Param)) {
876  StringRef Name;
877  if (IdentifierInfo *II = NTTP->getIdentifier())
878  Name = II->getName();
879  printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
880 
881  if (Args) {
882  Out << " = ";
883  Args->get(i).print(Policy, Out);
884  } else if (NTTP->hasDefaultArgument()) {
885  Out << " = ";
886  NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy,
887  Indentation);
888  }
889  } else if (const TemplateTemplateParmDecl *TTPD =
890  dyn_cast<TemplateTemplateParmDecl>(Param)) {
891  VisitTemplateDecl(TTPD);
892  // FIXME: print the default argument, if present.
893  }
894  }
895 
896  Out << "> ";
897 }
898 
899 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
900  PrintTemplateParameters(D->getTemplateParameters());
901 
902  if (const TemplateTemplateParmDecl *TTP =
903  dyn_cast<TemplateTemplateParmDecl>(D)) {
904  Out << "class ";
905  if (TTP->isParameterPack())
906  Out << "...";
907  Out << D->getName();
908  } else {
909  Visit(D->getTemplatedDecl());
910  }
911 }
912 
913 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
914  if (PrintInstantiation) {
916  for (auto *I : D->specializations()) {
917  PrintTemplateParameters(Params, I->getTemplateSpecializationArgs());
918  Visit(I);
919  }
920  }
921 
922  return VisitRedeclarableTemplateDecl(D);
923 }
924 
925 void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
926  if (PrintInstantiation) {
928  for (auto *I : D->specializations()) {
929  PrintTemplateParameters(Params, &I->getTemplateArgs());
930  Visit(I);
931  Out << '\n';
932  }
933  }
934 
935  return VisitRedeclarableTemplateDecl(D);
936 }
937 
938 //----------------------------------------------------------------------------
939 // Objective-C declarations
940 //----------------------------------------------------------------------------
941 
942 void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
944  QualType T) {
945  Out << '(';
946  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
947  Out << "in ";
948  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
949  Out << "inout ";
950  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
951  Out << "out ";
952  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
953  Out << "bycopy ";
954  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
955  Out << "byref ";
956  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
957  Out << "oneway ";
958  if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
959  if (auto nullability = AttributedType::stripOuterNullability(T))
960  Out << getNullabilitySpelling(*nullability, true) << ' ';
961  }
962 
963  Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy);
964  Out << ')';
965 }
966 
967 void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
968  Out << "<";
969  unsigned First = true;
970  for (auto *Param : *Params) {
971  if (First) {
972  First = false;
973  } else {
974  Out << ", ";
975  }
976 
977  switch (Param->getVariance()) {
979  break;
980 
982  Out << "__covariant ";
983  break;
984 
986  Out << "__contravariant ";
987  break;
988  }
989 
990  Out << Param->getDeclName().getAsString();
991 
992  if (Param->hasExplicitBound()) {
993  Out << " : " << Param->getUnderlyingType().getAsString(Policy);
994  }
995  }
996  Out << ">";
997 }
998 
999 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1000  if (OMD->isInstanceMethod())
1001  Out << "- ";
1002  else
1003  Out << "+ ";
1004  if (!OMD->getReturnType().isNull()) {
1005  PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1006  OMD->getReturnType());
1007  }
1008 
1009  std::string name = OMD->getSelector().getAsString();
1010  std::string::size_type pos, lastPos = 0;
1011  for (const auto *PI : OMD->params()) {
1012  // FIXME: selector is missing here!
1013  pos = name.find_first_of(':', lastPos);
1014  Out << " " << name.substr(lastPos, pos - lastPos) << ':';
1015  PrintObjCMethodType(OMD->getASTContext(),
1016  PI->getObjCDeclQualifier(),
1017  PI->getType());
1018  Out << *PI;
1019  lastPos = pos + 1;
1020  }
1021 
1022  if (OMD->param_begin() == OMD->param_end())
1023  Out << " " << name;
1024 
1025  if (OMD->isVariadic())
1026  Out << ", ...";
1027 
1028  prettyPrintAttributes(OMD);
1029 
1030  if (OMD->getBody() && !Policy.TerseOutput) {
1031  Out << ' ';
1032  OMD->getBody()->printPretty(Out, nullptr, Policy);
1033  }
1034  else if (Policy.PolishForDeclaration)
1035  Out << ';';
1036 }
1037 
1038 void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1039  std::string I = OID->getNameAsString();
1040  ObjCInterfaceDecl *SID = OID->getSuperClass();
1041 
1042  bool eolnOut = false;
1043  if (SID)
1044  Out << "@implementation " << I << " : " << *SID;
1045  else
1046  Out << "@implementation " << I;
1047 
1048  if (OID->ivar_size() > 0) {
1049  Out << "{\n";
1050  eolnOut = true;
1051  Indentation += Policy.Indentation;
1052  for (const auto *I : OID->ivars()) {
1053  Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1054  getAsString(Policy) << ' ' << *I << ";\n";
1055  }
1056  Indentation -= Policy.Indentation;
1057  Out << "}\n";
1058  }
1059  else if (SID || (OID->decls_begin() != OID->decls_end())) {
1060  Out << "\n";
1061  eolnOut = true;
1062  }
1063  VisitDeclContext(OID, false);
1064  if (!eolnOut)
1065  Out << "\n";
1066  Out << "@end";
1067 }
1068 
1069 void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1070  std::string I = OID->getNameAsString();
1071  ObjCInterfaceDecl *SID = OID->getSuperClass();
1072 
1073  if (!OID->isThisDeclarationADefinition()) {
1074  Out << "@class " << I;
1075 
1076  if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1077  PrintObjCTypeParams(TypeParams);
1078  }
1079 
1080  Out << ";";
1081  return;
1082  }
1083  bool eolnOut = false;
1084  Out << "@interface " << I;
1085 
1086  if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1087  PrintObjCTypeParams(TypeParams);
1088  }
1089 
1090  if (SID)
1091  Out << " : " << OID->getSuperClass()->getName();
1092 
1093  // Protocols?
1094  const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1095  if (!Protocols.empty()) {
1096  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1097  E = Protocols.end(); I != E; ++I)
1098  Out << (I == Protocols.begin() ? '<' : ',') << **I;
1099  Out << "> ";
1100  }
1101 
1102  if (OID->ivar_size() > 0) {
1103  Out << "{\n";
1104  eolnOut = true;
1105  Indentation += Policy.Indentation;
1106  for (const auto *I : OID->ivars()) {
1107  Indent() << I->getASTContext()
1108  .getUnqualifiedObjCPointerType(I->getType())
1109  .getAsString(Policy) << ' ' << *I << ";\n";
1110  }
1111  Indentation -= Policy.Indentation;
1112  Out << "}\n";
1113  }
1114  else if (SID || (OID->decls_begin() != OID->decls_end())) {
1115  Out << "\n";
1116  eolnOut = true;
1117  }
1118 
1119  VisitDeclContext(OID, false);
1120  if (!eolnOut)
1121  Out << "\n";
1122  Out << "@end";
1123  // FIXME: implement the rest...
1124 }
1125 
1126 void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1127  if (!PID->isThisDeclarationADefinition()) {
1128  Out << "@protocol " << *PID << ";\n";
1129  return;
1130  }
1131  // Protocols?
1132  const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1133  if (!Protocols.empty()) {
1134  Out << "@protocol " << *PID;
1135  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1136  E = Protocols.end(); I != E; ++I)
1137  Out << (I == Protocols.begin() ? '<' : ',') << **I;
1138  Out << ">\n";
1139  } else
1140  Out << "@protocol " << *PID << '\n';
1141  VisitDeclContext(PID, false);
1142  Out << "@end";
1143 }
1144 
1145 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
1146  Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
1147 
1148  VisitDeclContext(PID, false);
1149  Out << "@end";
1150  // FIXME: implement the rest...
1151 }
1152 
1153 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1154  Out << "@interface " << *PID->getClassInterface();
1155  if (auto TypeParams = PID->getTypeParamList()) {
1156  PrintObjCTypeParams(TypeParams);
1157  }
1158  Out << "(" << *PID << ")\n";
1159  if (PID->ivar_size() > 0) {
1160  Out << "{\n";
1161  Indentation += Policy.Indentation;
1162  for (const auto *I : PID->ivars())
1163  Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1164  getAsString(Policy) << ' ' << *I << ";\n";
1165  Indentation -= Policy.Indentation;
1166  Out << "}\n";
1167  }
1168 
1169  VisitDeclContext(PID, false);
1170  Out << "@end";
1171 
1172  // FIXME: implement the rest...
1173 }
1174 
1175 void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
1176  Out << "@compatibility_alias " << *AID
1177  << ' ' << *AID->getClassInterface() << ";\n";
1178 }
1179 
1180 /// PrintObjCPropertyDecl - print a property declaration.
1181 ///
1182 void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1184  Out << "@required\n";
1186  Out << "@optional\n";
1187 
1188  QualType T = PDecl->getType();
1189 
1190  Out << "@property";
1192  bool first = true;
1193  Out << " (";
1194  if (PDecl->getPropertyAttributes() &
1196  Out << (first ? ' ' : ',') << "readonly";
1197  first = false;
1198  }
1199 
1201  Out << (first ? ' ' : ',') << "getter = ";
1202  PDecl->getGetterName().print(Out);
1203  first = false;
1204  }
1206  Out << (first ? ' ' : ',') << "setter = ";
1207  PDecl->getSetterName().print(Out);
1208  first = false;
1209  }
1210 
1212  Out << (first ? ' ' : ',') << "assign";
1213  first = false;
1214  }
1215 
1216  if (PDecl->getPropertyAttributes() &
1218  Out << (first ? ' ' : ',') << "readwrite";
1219  first = false;
1220  }
1221 
1223  Out << (first ? ' ' : ',') << "retain";
1224  first = false;
1225  }
1226 
1228  Out << (first ? ' ' : ',') << "strong";
1229  first = false;
1230  }
1231 
1233  Out << (first ? ' ' : ',') << "copy";
1234  first = false;
1235  }
1236 
1237  if (PDecl->getPropertyAttributes() &
1239  Out << (first ? ' ' : ',') << "nonatomic";
1240  first = false;
1241  }
1242  if (PDecl->getPropertyAttributes() &
1244  Out << (first ? ' ' : ',') << "atomic";
1245  first = false;
1246  }
1247 
1248  if (PDecl->getPropertyAttributes() &
1250  if (auto nullability = AttributedType::stripOuterNullability(T)) {
1251  if (*nullability == NullabilityKind::Unspecified &&
1252  (PDecl->getPropertyAttributes() &
1254  Out << (first ? ' ' : ',') << "null_resettable";
1255  } else {
1256  Out << (first ? ' ' : ',')
1257  << getNullabilitySpelling(*nullability, true);
1258  }
1259  first = false;
1260  }
1261  }
1262 
1263  (void) first; // Silence dead store warning due to idiomatic code.
1264  Out << " )";
1265  }
1266  Out << ' ' << PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
1267  getAsString(Policy) << ' ' << *PDecl;
1268  if (Policy.PolishForDeclaration)
1269  Out << ';';
1270 }
1271 
1272 void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1274  Out << "@synthesize ";
1275  else
1276  Out << "@dynamic ";
1277  Out << *PID->getPropertyDecl();
1278  if (PID->getPropertyIvarDecl())
1279  Out << '=' << *PID->getPropertyIvarDecl();
1280 }
1281 
1282 void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1283  if (!D->isAccessDeclaration())
1284  Out << "using ";
1285  if (D->hasTypename())
1286  Out << "typename ";
1287  D->getQualifier()->print(Out, Policy);
1288  Out << *D;
1289 }
1290 
1291 void
1292 DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1293  Out << "using typename ";
1294  D->getQualifier()->print(Out, Policy);
1295  Out << D->getDeclName();
1296 }
1297 
1298 void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1299  if (!D->isAccessDeclaration())
1300  Out << "using ";
1301  D->getQualifier()->print(Out, Policy);
1302  Out << D->getName();
1303 }
1304 
1305 void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1306  // ignore
1307 }
1308 
1309 void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1310  Out << "#pragma omp threadprivate";
1311  if (!D->varlist_empty()) {
1313  E = D->varlist_end();
1314  I != E; ++I) {
1315  Out << (I == D->varlist_begin() ? '(' : ',');
1316  NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
1317  ND->printQualifiedName(Out);
1318  }
1319  Out << ")";
1320  }
1321 }
1322 
param_const_iterator param_begin() const
Definition: DeclObjC.h:359
Defines the clang::ASTContext interface.
QualType getExceptionType(unsigned i) const
Definition: Type.h:3194
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
Definition: DeclFriend.h:119
bool isVariadic() const
Definition: Type.h:3228
void VisitVarDecl(VarDecl *VD)
StringRef getName() const
Definition: Decl.h:168
void VisitImportDecl(ImportDecl *D)
void VisitUsingDecl(UsingDecl *D)
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:1982
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2330
spec_range specializations() const
Definition: DeclTemplate.h:937
IdentifierInfo * getIdentifier() const
Definition: Decl.h:163
void VisitFieldDecl(FieldDecl *FD)
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:2591
void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D)
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1195
void VisitEnumConstantDecl(EnumConstantDecl *ECD)
Defines the clang::Module class, which describes a module in the source code.
std::string getAsString() const
Definition: Type.h:897
void VisitObjCCategoryDecl(ObjCCategoryDecl *D)
Represents an empty-declaration.
Definition: Decl.h:3762
const Expr * getInit() const
Definition: Decl.h:1068
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:400
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1075
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:96
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:83
A container of type source information.
Definition: Decl.h:60
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:197
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2147
Expr * getInClassInitializer() const
Definition: Decl.h:2385
InClassInitStyle getInClassInitStyle() const
Definition: Decl.h:2369
void VisitStaticAssertDecl(StaticAssertDecl *D)
AccessSpecifier getAccess() const
Definition: DeclBase.h:416
void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const
void VisitClassTemplateDecl(ClassTemplateDecl *D)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:46
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:35
decl_iterator decls_end() const
Definition: DeclBase.h:1415
void VisitTypeAliasDecl(TypeAliasDecl *TD)
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1334
Defines the clang::Expr interface and subclasses for C++ expressions.
QualType getType() const
Definition: DeclObjC.h:2505
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
TypeSourceInfo * getFriendType() const
Definition: DeclFriend.h:113
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2683
unsigned ivar_size() const
Definition: DeclObjC.h:1141
std::string getFullModuleName() const
Retrieve the full name of this module, including the path from its top-level module.
ObjCTypeParamList * getTypeParamListAsWritten() const
Definition: DeclObjC.h:984
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3171
unsigned getFriendTypeNumTemplateParameterLists() const
Definition: DeclFriend.h:116
StringLiteral * getMessage()
Definition: DeclCXX.h:3182
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:2920
bool isExplicitSpecified() const
Determine whether this constructor declaration has the explicit keyword specified.
Definition: DeclCXX.h:2184
std::string getNameAsString() const
Get the name of the class associated with this interface.
Definition: DeclObjC.h:2346
bool isCompleteDefinition() const
Definition: Decl.h:2838
bool isPure() const
Definition: Decl.h:1789
bool isTranslationUnit() const
Definition: DeclBase.h:1243
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:212
bool varlist_empty() const
Definition: DeclOpenMP.h:71
void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD)
param_range params()
Definition: DeclObjC.h:354
unsigned size() const
Definition: DeclTemplate.h:87
void VisitLabelDecl(LabelDecl *LD)
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2514
StorageClass getStorageClass() const
Returns the storage class as written in the source. For the computed linkage of symbol, see getLinkage.
Definition: Decl.h:871
bool isExplicitlyDefaulted() const
Definition: Decl.h:1810
Represents a C++ using-declaration.
Definition: DeclCXX.h:2871
void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1204
static QualType getDeclType(Decl *D)
bool isImplicit() const
Definition: DeclBase.h:503
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:455
ObjCTypeParamList * getTypeParamList() const
Definition: DeclObjC.h:1987
Microsoft throw(...) extension.
NamedDecl * getNominatedNamespaceAsWritten()
Definition: DeclCXX.h:2606
void VisitCXXRecordDecl(CXXRecordDecl *D)
Expr * getNoexceptExpr() const
Definition: Type.h:3198
void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Selector getSetterName() const
Definition: DeclObjC.h:2578
DeclID VisitTemplateDecl(TemplateDecl *D)
std::string getNameAsString() const
Definition: Decl.h:183
base_class_iterator bases_begin()
Definition: DeclCXX.h:720
bool empty() const
Definition: DeclObjC.h:46
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1731
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
Represents an ObjC class declaration.
Definition: DeclObjC.h:851
Represents a linkage specification.
Definition: DeclCXX.h:2467
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1141
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:2516
QualType getType() const
Definition: Decl.h:538
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition: Decl.h:1823
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:1877
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3166
void VisitParmVarDecl(ParmVarDecl *PD)
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: DeclObjC.h:269
void VisitLinkageSpecDecl(LinkageSpecDecl *D)
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
ivar_range ivars() const
Definition: DeclObjC.h:1125
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition: DeclOpenMP.h:65
StorageClass getStorageClass() const
Returns the storage class as written in the source. For the computed linkage of symbol, see getLinkage.
Definition: Decl.h:2020
QualType getPointeeType() const
Definition: Type.cpp:414
void VisitUsingShadowDecl(UsingShadowDecl *D)
void VisitFriendDecl(FriendDecl *D)
bool isDeletedAsWritten() const
Definition: Decl.h:1862
Declaration of a template type parameter.
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2687
Expr * getBitWidth() const
Definition: Decl.h:2344
void VisitTypedefDecl(TypedefDecl *TD)
QualType getUnqualifiedObjCPointerType(QualType type) const
Definition: ASTContext.h:1616
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:1968
static QualType GetBaseType(QualType T)
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Definition: Type.cpp:3462
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3166
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine()) const
Definition: Type.h:907
StorageClass
Storage classes.
Definition: Specifiers.h:173
bool isInstanceMethod() const
Definition: DeclObjC.h:419
bool hasTrailingReturn() const
Definition: Type.h:3238
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1174
DeclarationName getDeclName() const
Definition: Decl.h:189
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:707
unsigned ivar_size() const
Definition: DeclObjC.h:2375
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2405
ivar_range ivars() const
Definition: DeclObjC.h:2368
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:611
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:486
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:1835
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition: DeclCXX.h:2602
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:1784
void VisitObjCProtocolDecl(ObjCProtocolDecl *D)
AttrVec & getAttrs()
Definition: DeclBase.h:431
param_const_iterator param_end() const
Definition: DeclObjC.h:362
Stmt * getBody(const FunctionDecl *&Definition) const
Definition: Decl.cpp:2405
bool doesThisDeclarationHaveABody() const
Definition: Decl.h:1773
SmallVectorImpl< AnnotatedLine * >::const_iterator Next
unsigned getNumParams() const
Definition: Decl.cpp:2651
bool SuppressTag
Whether type printing should skip printing the actual tag type.
Definition: PrettyPrinter.h:87
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:3244
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2409
void VisitEmptyDecl(EmptyDecl *D)
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3134
bool SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Definition: PrettyPrinter.h:67
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2694
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:284
bool isVariadic() const
Definition: DeclObjC.h:421
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3017
std::string getAsString() const
getAsString - Retrieve the human-readable string for this name.
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:731
bool isRestrict() const
Definition: Type.h:2964
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
varlist_iterator varlist_begin()
Definition: DeclOpenMP.h:79
GNU __thread.
Definition: Specifiers.h:163
No ref-qualifier was provided.
Definition: Type.h:1202
C-style initialization with assignment.
Definition: Decl.h:718
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:3746
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2093
Direct list-initialization.
Definition: Specifiers.h:200
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:880
std::string getAsString() const
Derive the full selector name (e.g. "foo:bar:") and return it as an std::string.
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:2424
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
QualType getReturnType() const
Definition: DeclObjC.h:330
void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
void VisitRecordDecl(RecordDecl *RD)
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3159
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2024
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1206
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:68
void printQualifiedName(raw_ostream &OS) const
Definition: Decl.cpp:1367
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3056
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:3704
Represents a pack expansion of types.
Definition: Type.h:4428
static const char * getStorageClassSpecifierString(StorageClass SC)
Definition: Decl.cpp:1754
void VisitEnumDecl(EnumDecl *ED)
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2576
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1781
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition: DeclCXX.h:2923
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3049
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:311
void VisitFunctionDecl(FunctionDecl *FD)
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2594
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2508
bool hasWrittenPrototype() const
Definition: Decl.h:1827
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3100
void VisitObjCMethodDecl(ObjCMethodDecl *D)
Selector getGetterName() const
Definition: DeclObjC.h:2575
void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
void VisitObjCImplementationDecl(ObjCImplementationDecl *D)
Selector getSelector() const
Definition: DeclObjC.h:328
bool hasAttrs() const
Definition: DeclBase.h:427
void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D)
iterator begin() const
Definition: DeclObjC.h:65
spec_range specializations() const
void VisitObjCPropertyDecl(ObjCPropertyDecl *D)
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
const T * getAs() const
Definition: Type.h:5555
NamedDecl * getFriendDecl() const
Definition: DeclFriend.h:126
bool isSpecifierType() const
Definition: Type.cpp:2307
QualType getIntegerType() const
Definition: Decl.h:3115
void VisitNamespaceDecl(NamespaceDecl *D)
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition: Decl.h:1173
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1014
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition: DeclCXX.h:2728
Represents a base class of a C++ class.
Definition: DeclCXX.h:157
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:2911
A template argument list.
Definition: DeclTemplate.h:150
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2678
varlist_iterator varlist_end()
Definition: DeclOpenMP.h:80
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Call-style initialization (C++98)
Definition: Decl.h:719
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Definition: DeclTemplate.h:340
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:3174
base_class_iterator bases_end()
Definition: DeclCXX.h:722
Declaration of a class template.
void dumpDeclContext() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:335
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:271
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:78
std::pair< uint64_t, uint64_t > VisitDeclContext(DeclContext *DC)
void VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
StringRef getKindName() const
Definition: Decl.h:2893
bool isVolatile() const
Definition: Type.h:2963
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1709
Represents a C++ namespace alias.
Definition: DeclCXX.h:2662
Represents C++ using-directive.
Definition: DeclCXX.h:2559
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Definition: Type.h:633
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:2611
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
void VisitTranslationUnitDecl(TranslationUnitDecl *TU)
This represents '#pragma omp threadprivate ...' directive. For example, in the following, both 'a' and 'A::b' are threadprivate:
Definition: DeclOpenMP.h:36
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
Definition: DeclBase.h:552
The parameter is invariant: must match exactly.
iterator end() const
Definition: DeclObjC.h:66
Declaration of a template function.
Definition: DeclTemplate.h:821
Attr - This represents one attribute.
Definition: Attr.h:44
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Definition: DeclCXX.h:2779
Expr * IgnoreParens() LLVM_READONLY
Definition: Expr.cpp:2408
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine()) const
Definition: Type.h:947
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Definition: Decl.h:2327
bool isConst() const
Definition: Type.h:2962
unsigned getNumExceptions() const
Definition: Type.h:3193
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2354
unsigned Indent
The current line's indent.
const StringLiteral * getAsmString() const
Definition: Decl.h:3411