1 //===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Decl::print method, which pretty prints the
11 // AST back out to C/Objective-C/C++/Objective-C++ code.
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"
22 #include "clang/AST/PrettyPrinter.h"
23 #include "clang/Basic/Module.h"
24 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
28 class DeclPrinter : public DeclVisitor<DeclPrinter> {
30 PrintingPolicy Policy;
32 bool PrintInstantiation;
34 raw_ostream& Indent() { return Indent(Indentation); }
35 raw_ostream& Indent(unsigned Indentation);
36 void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls);
38 void Print(AccessSpecifier AS);
40 /// Print an Objective-C method type in parentheses.
42 /// \param Quals The Objective-C declaration qualifiers.
43 /// \param T The type to print.
44 void PrintObjCMethodType(ASTContext &Ctx, Decl::ObjCDeclQualifier Quals,
47 void PrintObjCTypeParams(ObjCTypeParamList *Params);
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) { }
55 void VisitDeclContext(DeclContext *DC, bool Indent = true);
57 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
58 void VisitTypedefDecl(TypedefDecl *D);
59 void VisitTypeAliasDecl(TypeAliasDecl *D);
60 void VisitEnumDecl(EnumDecl *D);
61 void VisitRecordDecl(RecordDecl *D);
62 void VisitEnumConstantDecl(EnumConstantDecl *D);
63 void VisitEmptyDecl(EmptyDecl *D);
64 void VisitFunctionDecl(FunctionDecl *D);
65 void VisitFriendDecl(FriendDecl *D);
66 void VisitFieldDecl(FieldDecl *D);
67 void VisitVarDecl(VarDecl *D);
68 void VisitLabelDecl(LabelDecl *D);
69 void VisitParmVarDecl(ParmVarDecl *D);
70 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
71 void VisitImportDecl(ImportDecl *D);
72 void VisitStaticAssertDecl(StaticAssertDecl *D);
73 void VisitNamespaceDecl(NamespaceDecl *D);
74 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
75 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
76 void VisitCXXRecordDecl(CXXRecordDecl *D);
77 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
78 void VisitTemplateDecl(const TemplateDecl *D);
79 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
80 void VisitClassTemplateDecl(ClassTemplateDecl *D);
81 void VisitClassTemplateSpecializationDecl(
82 ClassTemplateSpecializationDecl *D);
83 void VisitClassTemplatePartialSpecializationDecl(
84 ClassTemplatePartialSpecializationDecl *D);
85 void VisitObjCMethodDecl(ObjCMethodDecl *D);
86 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
87 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
88 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
89 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
90 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
91 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
92 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
93 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
94 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
95 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
96 void VisitUsingDecl(UsingDecl *D);
97 void VisitUsingShadowDecl(UsingShadowDecl *D);
98 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
99 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
100 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
102 void printTemplateParameters(const TemplateParameterList *Params);
103 void printTemplateArguments(const TemplateArgumentList &Args,
104 const TemplateParameterList *Params = nullptr);
105 void prettyPrintAttributes(Decl *D);
106 void prettyPrintPragmas(Decl *D);
107 void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
111 void Decl::print(raw_ostream &Out, unsigned Indentation,
112 bool PrintInstantiation) const {
113 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
116 void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
117 unsigned Indentation, bool PrintInstantiation) const {
118 DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation);
119 Printer.Visit(const_cast<Decl*>(this));
122 static QualType GetBaseType(QualType T) {
123 // FIXME: This should be on the Type class!
124 QualType BaseType = T;
125 while (!BaseType->isSpecifierType()) {
126 if (isa<TypedefType>(BaseType))
128 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
129 BaseType = PTy->getPointeeType();
130 else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
131 BaseType = BPy->getPointeeType();
132 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
133 BaseType = ATy->getElementType();
134 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
135 BaseType = FTy->getReturnType();
136 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
137 BaseType = VTy->getElementType();
138 else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
139 BaseType = RTy->getPointeeType();
140 else if (const AutoType *ATy = BaseType->getAs<AutoType>())
141 BaseType = ATy->getDeducedType();
143 llvm_unreachable("Unknown declarator!");
148 static QualType getDeclType(Decl* D) {
149 if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
150 return TDD->getUnderlyingType();
151 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
152 return VD->getType();
156 void Decl::printGroup(Decl** Begin, unsigned NumDecls,
157 raw_ostream &Out, const PrintingPolicy &Policy,
158 unsigned Indentation) {
160 (*Begin)->print(Out, Policy, Indentation);
164 Decl** End = Begin + NumDecls;
165 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
169 PrintingPolicy SubPolicy(Policy);
172 for ( ; Begin != End; ++Begin) {
175 SubPolicy.IncludeTagDefinition = true;
176 SubPolicy.SuppressSpecifiers = false;
179 if (!isFirst) Out << ", ";
180 SubPolicy.IncludeTagDefinition = false;
181 SubPolicy.SuppressSpecifiers = true;
184 (*Begin)->print(Out, SubPolicy, Indentation);
188 LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
189 // Get the translation unit
190 const DeclContext *DC = this;
191 while (!DC->isTranslationUnit())
192 DC = DC->getParent();
194 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
195 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0);
196 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
199 raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
200 for (unsigned i = 0; i != Indentation; ++i)
205 void DeclPrinter::prettyPrintAttributes(Decl *D) {
206 if (Policy.PolishForDeclaration)
210 AttrVec &Attrs = D->getAttrs();
211 for (auto *A : Attrs) {
212 switch (A->getKind()) {
214 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
215 #include "clang/Basic/AttrList.inc"
218 A->printPretty(Out, Policy);
225 void DeclPrinter::prettyPrintPragmas(Decl *D) {
226 if (Policy.PolishForDeclaration)
230 AttrVec &Attrs = D->getAttrs();
231 for (auto *A : Attrs) {
232 switch (A->getKind()) {
234 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
235 #include "clang/Basic/AttrList.inc"
236 A->printPretty(Out, Policy);
246 void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
247 // Normally, a PackExpansionType is written as T[3]... (for instance, as a
248 // template argument), but if it is the type of a declaration, the ellipsis
249 // is placed before the name being declared.
250 if (auto *PET = T->getAs<PackExpansionType>()) {
252 T = PET->getPattern();
254 T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
257 void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
259 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
265 void DeclPrinter::Print(AccessSpecifier AS) {
267 case AS_none: llvm_unreachable("No access specifier!");
268 case AS_public: Out << "public"; break;
269 case AS_protected: Out << "protected"; break;
270 case AS_private: Out << "private"; break;
274 //----------------------------------------------------------------------------
275 // Common C declarations
276 //----------------------------------------------------------------------------
278 void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
279 if (Policy.TerseOutput)
283 Indentation += Policy.Indentation;
285 SmallVector<Decl*, 2> Decls;
286 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
289 // Don't print ObjCIvarDecls, as they are printed when visiting the
290 // containing ObjCInterfaceDecl.
291 if (isa<ObjCIvarDecl>(*D))
294 // Skip over implicit declarations in pretty-printing mode.
298 // Don't print implicit specializations, as they are printed when visiting
299 // corresponding templates.
300 if (auto FD = dyn_cast<FunctionDecl>(*D))
301 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation &&
302 !isa<ClassTemplateSpecializationDecl>(DC))
305 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
306 // forced to merge the declarations because there's no other way to
307 // refer to the struct in question. This limited merging is safe without
308 // a bunch of other checks because it only merges declarations directly
309 // referring to the tag, not typedefs.
311 // Check whether the current declaration should be grouped with a previous
313 QualType CurDeclType = getDeclType(*D);
314 if (!Decls.empty() && !CurDeclType.isNull()) {
315 QualType BaseType = GetBaseType(CurDeclType);
316 if (!BaseType.isNull() && isa<ElaboratedType>(BaseType))
317 BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
318 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
319 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
325 // If we have a merged group waiting to be handled, handle it now.
327 ProcessDeclGroup(Decls);
329 // If the current declaration is an unnamed tag type, save it
330 // so we can merge it with the subsequent declaration(s) using it.
331 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
336 if (isa<AccessSpecDecl>(*D)) {
337 Indentation -= Policy.Indentation;
339 Print(D->getAccess());
341 Indentation += Policy.Indentation;
348 // FIXME: Need to be able to tell the DeclPrinter when
349 const char *Terminator = nullptr;
350 if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D))
351 Terminator = nullptr;
352 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
353 Terminator = nullptr;
354 else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
355 if (FD->isThisDeclarationADefinition())
356 Terminator = nullptr;
359 } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
360 if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
361 Terminator = nullptr;
364 } else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
365 isa<ObjCImplementationDecl>(*D) ||
366 isa<ObjCInterfaceDecl>(*D) ||
367 isa<ObjCProtocolDecl>(*D) ||
368 isa<ObjCCategoryImplDecl>(*D) ||
369 isa<ObjCCategoryDecl>(*D))
370 Terminator = nullptr;
371 else if (isa<EnumConstantDecl>(*D)) {
372 DeclContext::decl_iterator Next = D;
381 if (!Policy.TerseOutput &&
382 ((isa<FunctionDecl>(*D) &&
383 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
384 (isa<FunctionTemplateDecl>(*D) &&
385 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
386 ; // StmtPrinter already added '\n' after CompoundStmt.
390 // Declare target attribute is special one, natural spelling for the pragma
391 // assumes "ending" construct so print it here.
392 if (D->hasAttr<OMPDeclareTargetDeclAttr>())
393 Out << "#pragma omp end declare target\n";
397 ProcessDeclGroup(Decls);
400 Indentation -= Policy.Indentation;
403 void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
404 VisitDeclContext(D, false);
407 void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
408 if (!Policy.SuppressSpecifiers) {
411 if (D->isModulePrivate())
412 Out << "__module_private__ ";
414 QualType Ty = D->getTypeSourceInfo()->getType();
415 Ty.print(Out, Policy, D->getName(), Indentation);
416 prettyPrintAttributes(D);
419 void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
420 Out << "using " << *D;
421 prettyPrintAttributes(D);
422 Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
425 void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
426 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
427 Out << "__module_private__ ";
430 if (D->isScopedUsingClassTag())
437 if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11)
438 Out << " : " << D->getIntegerType().stream(Policy);
440 if (D->isCompleteDefinition()) {
445 prettyPrintAttributes(D);
448 void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
449 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
450 Out << "__module_private__ ";
451 Out << D->getKindName();
453 prettyPrintAttributes(D);
455 if (D->getIdentifier())
458 if (D->isCompleteDefinition()) {
465 void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
467 prettyPrintAttributes(D);
468 if (Expr *Init = D->getInitExpr()) {
470 Init->printPretty(Out, nullptr, Policy, Indentation);
474 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
475 if (!D->getDescribedFunctionTemplate() &&
476 !D->isFunctionTemplateSpecialization())
477 prettyPrintPragmas(D);
479 if (D->isFunctionTemplateSpecialization())
480 Out << "template<> ";
481 else if (!D->getDescribedFunctionTemplate()) {
482 for (unsigned I = 0, NumTemplateParams = D->getNumTemplateParameterLists();
483 I < NumTemplateParams; ++I)
484 printTemplateParameters(D->getTemplateParameterList(I));
487 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
488 CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
489 CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D);
490 if (!Policy.SuppressSpecifiers) {
491 switch (D->getStorageClass()) {
493 case SC_Extern: Out << "extern "; break;
494 case SC_Static: Out << "static "; break;
495 case SC_PrivateExtern: Out << "__private_extern__ "; break;
496 case SC_Auto: case SC_Register:
497 llvm_unreachable("invalid for functions");
500 if (D->isInlineSpecified()) Out << "inline ";
501 if (D->isVirtualAsWritten()) Out << "virtual ";
502 if (D->isModulePrivate()) Out << "__module_private__ ";
503 if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr ";
504 if ((CDecl && CDecl->isExplicitSpecified()) ||
505 (ConversionDecl && ConversionDecl->isExplicitSpecified()) ||
506 (GuideDecl && GuideDecl->isExplicitSpecified()))
510 PrintingPolicy SubPolicy(Policy);
511 SubPolicy.SuppressSpecifiers = false;
513 if (!Policy.SuppressScope) {
514 if (const NestedNameSpecifier *NS = D->getQualifier()) {
515 llvm::raw_string_ostream OS(Proto);
516 NS->print(OS, Policy);
519 Proto += D->getNameInfo().getAsString();
521 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
522 if (const TemplateArgumentList *TArgs = D->getTemplateSpecializationArgs()) {
523 llvm::raw_string_ostream POut(Proto);
524 DeclPrinter TArgPrinter(POut, SubPolicy, Indentation);
525 TArgPrinter.printTemplateArguments(*TArgs);
528 QualType Ty = D->getType();
529 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
530 Proto = '(' + Proto + ')';
531 Ty = PT->getInnerType();
534 if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
535 const FunctionProtoType *FT = nullptr;
536 if (D->hasWrittenPrototype())
537 FT = dyn_cast<FunctionProtoType>(AFT);
541 llvm::raw_string_ostream POut(Proto);
542 DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
543 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
545 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
548 if (FT->isVariadic()) {
549 if (D->getNumParams()) POut << ", ";
552 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
553 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
556 Proto += D->getParamDecl(i)->getNameAsString();
565 if (FT->isVolatile())
566 Proto += " volatile";
567 if (FT->isRestrict())
568 Proto += " restrict";
570 switch (FT->getRefQualifier()) {
582 if (FT && FT->hasDynamicExceptionSpec()) {
584 if (FT->getExceptionSpecType() == EST_MSAny)
587 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
591 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
594 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
595 Proto += " noexcept";
596 if (FT->getExceptionSpecType() == EST_ComputedNoexcept) {
598 llvm::raw_string_ostream EOut(Proto);
599 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
608 bool HasInitializerList = false;
609 for (const auto *BMInitializer : CDecl->inits()) {
610 if (BMInitializer->isInClassMemberInitializer())
613 if (!HasInitializerList) {
617 HasInitializerList = true;
621 if (BMInitializer->isAnyMemberInitializer()) {
622 FieldDecl *FD = BMInitializer->getAnyMember();
625 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
629 if (!BMInitializer->getInit()) {
632 Expr *Init = BMInitializer->getInit();
633 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
634 Init = Tmp->getSubExpr();
636 Init = Init->IgnoreParens();
638 Expr *SimpleInit = nullptr;
639 Expr **Args = nullptr;
640 unsigned NumArgs = 0;
641 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
642 Args = ParenList->getExprs();
643 NumArgs = ParenList->getNumExprs();
644 } else if (CXXConstructExpr *Construct
645 = dyn_cast<CXXConstructExpr>(Init)) {
646 Args = Construct->getArgs();
647 NumArgs = Construct->getNumArgs();
652 SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
654 for (unsigned I = 0; I != NumArgs; ++I) {
655 assert(Args[I] != nullptr && "Expected non-null Expr");
656 if (isa<CXXDefaultArgExpr>(Args[I]))
661 Args[I]->printPretty(Out, nullptr, Policy, Indentation);
666 if (BMInitializer->isPackExpansion())
669 } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
670 if (FT && FT->hasTrailingReturn()) {
673 Out << Proto << " -> ";
676 AFT->getReturnType().print(Out, Policy, Proto);
681 Ty.print(Out, Policy, Proto);
684 prettyPrintAttributes(D);
688 else if (D->isDeletedAsWritten())
690 else if (D->isExplicitlyDefaulted())
692 else if (D->doesThisDeclarationHaveABody()) {
693 if (!Policy.TerseOutput) {
694 if (!D->hasPrototype() && D->getNumParams()) {
695 // This is a K&R function definition, so we need to print the
698 DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
699 Indentation += Policy.Indentation;
700 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
702 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
705 Indentation -= Policy.Indentation;
710 D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation);
712 if (isa<CXXConstructorDecl>(*D))
718 void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
719 if (TypeSourceInfo *TSI = D->getFriendType()) {
720 unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
721 for (unsigned i = 0; i < NumTPLists; ++i)
722 printTemplateParameters(D->getFriendTypeTemplateParameterList(i));
724 Out << " " << TSI->getType().getAsString(Policy);
726 else if (FunctionDecl *FD =
727 dyn_cast<FunctionDecl>(D->getFriendDecl())) {
729 VisitFunctionDecl(FD);
731 else if (FunctionTemplateDecl *FTD =
732 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
734 VisitFunctionTemplateDecl(FTD);
736 else if (ClassTemplateDecl *CTD =
737 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
739 VisitRedeclarableTemplateDecl(CTD);
743 void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
744 // FIXME: add printing of pragma attributes if required.
745 if (!Policy.SuppressSpecifiers && D->isMutable())
747 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
748 Out << "__module_private__ ";
750 Out << D->getASTContext().getUnqualifiedObjCPointerType(D->getType()).
751 stream(Policy, D->getName(), Indentation);
753 if (D->isBitField()) {
755 D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation);
758 Expr *Init = D->getInClassInitializer();
759 if (!Policy.SuppressInitializers && Init) {
760 if (D->getInClassInitStyle() == ICIS_ListInit)
764 Init->printPretty(Out, nullptr, Policy, Indentation);
766 prettyPrintAttributes(D);
769 void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
773 void DeclPrinter::VisitVarDecl(VarDecl *D) {
774 prettyPrintPragmas(D);
776 QualType T = D->getTypeSourceInfo()
777 ? D->getTypeSourceInfo()->getType()
778 : D->getASTContext().getUnqualifiedObjCPointerType(D->getType());
780 if (!Policy.SuppressSpecifiers) {
781 StorageClass SC = D->getStorageClass();
783 Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
785 switch (D->getTSCSpec()) {
786 case TSCS_unspecified:
791 case TSCS__Thread_local:
792 Out << "_Thread_local ";
794 case TSCS_thread_local:
795 Out << "thread_local ";
799 if (D->isModulePrivate())
800 Out << "__module_private__ ";
802 if (D->isConstexpr()) {
804 T.removeLocalConst();
808 printDeclType(T, D->getName());
809 Expr *Init = D->getInit();
810 if (!Policy.SuppressInitializers && Init) {
811 bool ImplicitInit = false;
812 if (CXXConstructExpr *Construct =
813 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
814 if (D->getInitStyle() == VarDecl::CallInit &&
815 !Construct->isListInitialization()) {
816 ImplicitInit = Construct->getNumArgs() == 0 ||
817 Construct->getArg(0)->isDefaultArgument();
821 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
823 else if (D->getInitStyle() == VarDecl::CInit) {
826 PrintingPolicy SubPolicy(Policy);
827 SubPolicy.SuppressSpecifiers = false;
828 SubPolicy.IncludeTagDefinition = false;
829 Init->printPretty(Out, nullptr, SubPolicy, Indentation);
830 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
834 prettyPrintAttributes(D);
837 void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
841 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
843 D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation);
847 void DeclPrinter::VisitImportDecl(ImportDecl *D) {
848 Out << "@import " << D->getImportedModule()->getFullModuleName()
852 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
853 Out << "static_assert(";
854 D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation);
855 if (StringLiteral *SL = D->getMessage()) {
857 SL->printPretty(Out, nullptr, Policy, Indentation);
862 //----------------------------------------------------------------------------
864 //----------------------------------------------------------------------------
865 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
868 Out << "namespace " << *D << " {\n";
873 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
874 Out << "using namespace ";
875 if (D->getQualifier())
876 D->getQualifier()->print(Out, Policy);
877 Out << *D->getNominatedNamespaceAsWritten();
880 void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
881 Out << "namespace " << *D << " = ";
882 if (D->getQualifier())
883 D->getQualifier()->print(Out, Policy);
884 Out << *D->getAliasedNamespace();
887 void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
888 prettyPrintAttributes(D);
891 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
892 // FIXME: add printing of pragma attributes if required.
893 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
894 Out << "__module_private__ ";
895 Out << D->getKindName();
897 prettyPrintAttributes(D);
899 if (D->getIdentifier()) {
902 if (auto S = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
903 printTemplateArguments(S->getTemplateArgs(), S->getTemplateParameters());
904 else if (auto S = dyn_cast<ClassTemplateSpecializationDecl>(D))
905 printTemplateArguments(S->getTemplateArgs());
908 if (D->isCompleteDefinition()) {
909 // Print the base classes
910 if (D->getNumBases()) {
912 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
913 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
914 if (Base != D->bases_begin())
917 if (Base->isVirtual())
920 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
925 Out << Base->getType().getAsString(Policy);
927 if (Base->isPackExpansion())
932 // Print the class definition
933 // FIXME: Doesn't print access specifiers, e.g., "public:"
934 if (Policy.TerseOutput) {
944 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
946 if (D->getLanguage() == LinkageSpecDecl::lang_c)
949 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
950 "unknown language in linkage specification");
954 Out << "extern \"" << l << "\" ";
955 if (D->hasBraces()) {
960 Visit(*D->decls_begin());
963 void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {
968 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
972 const Decl *Param = Params->getParam(i);
973 if (auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
975 if (TTP->wasDeclaredWithTypename())
980 if (TTP->isParameterPack())
985 if (TTP->hasDefaultArgument()) {
987 Out << TTP->getDefaultArgument().getAsString(Policy);
989 } else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
991 if (IdentifierInfo *II = NTTP->getIdentifier())
992 Name = II->getName();
993 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
995 if (NTTP->hasDefaultArgument()) {
997 NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy,
1000 } else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1001 VisitTemplateDecl(TTPD);
1002 // FIXME: print the default argument, if present.
1009 void DeclPrinter::printTemplateArguments(const TemplateArgumentList &Args,
1010 const TemplateParameterList *Params) {
1012 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1013 const TemplateArgument &A = Args[I];
1017 if (A.getKind() == TemplateArgument::Type)
1018 if (auto T = A.getAsType()->getAs<TemplateTypeParmType>()) {
1019 auto P = cast<TemplateTypeParmDecl>(Params->getParam(T->getIndex()));
1023 if (A.getKind() == TemplateArgument::Template) {
1024 if (auto T = A.getAsTemplate().getAsTemplateDecl())
1025 if (auto TD = dyn_cast<TemplateTemplateParmDecl>(T)) {
1026 auto P = cast<TemplateTemplateParmDecl>(
1027 Params->getParam(TD->getIndex()));
1032 if (A.getKind() == TemplateArgument::Expression) {
1033 if (auto E = dyn_cast<DeclRefExpr>(A.getAsExpr()))
1034 if (auto N = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) {
1035 auto P = cast<NonTypeTemplateParmDecl>(
1036 Params->getParam(N->getIndex()));
1042 A.print(Policy, Out);
1047 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1048 printTemplateParameters(D->getTemplateParameters());
1050 if (const TemplateTemplateParmDecl *TTP =
1051 dyn_cast<TemplateTemplateParmDecl>(D)) {
1053 if (TTP->isParameterPack())
1055 Out << D->getName();
1057 Visit(D->getTemplatedDecl());
1061 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1062 prettyPrintPragmas(D->getTemplatedDecl());
1063 // Print any leading template parameter lists.
1064 if (const FunctionDecl *FD = D->getTemplatedDecl()) {
1065 for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1066 I < NumTemplateParams; ++I)
1067 printTemplateParameters(FD->getTemplateParameterList(I));
1069 VisitRedeclarableTemplateDecl(D);
1071 // Never print "instantiations" for deduction guides (they don't really
1073 if (PrintInstantiation &&
1074 !isa<CXXDeductionGuideDecl>(D->getTemplatedDecl())) {
1075 FunctionDecl *PrevDecl = D->getTemplatedDecl();
1076 const FunctionDecl *Def;
1077 if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1079 for (auto *I : D->specializations())
1080 if (I->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) {
1081 if (!PrevDecl->isThisDeclarationADefinition())
1084 prettyPrintPragmas(I);
1090 void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1091 VisitRedeclarableTemplateDecl(D);
1093 if (PrintInstantiation) {
1094 for (auto *I : D->specializations())
1095 if (I->getSpecializationKind() == TSK_ImplicitInstantiation) {
1096 if (D->isThisDeclarationADefinition())
1104 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1105 ClassTemplateSpecializationDecl *D) {
1106 Out << "template<> ";
1107 VisitCXXRecordDecl(D);
1110 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1111 ClassTemplatePartialSpecializationDecl *D) {
1112 printTemplateParameters(D->getTemplateParameters());
1113 VisitCXXRecordDecl(D);
1116 //----------------------------------------------------------------------------
1117 // Objective-C declarations
1118 //----------------------------------------------------------------------------
1120 void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1121 Decl::ObjCDeclQualifier Quals,
1124 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1126 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1128 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1130 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1132 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1134 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1136 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1137 if (auto nullability = AttributedType::stripOuterNullability(T))
1138 Out << getNullabilitySpelling(*nullability, true) << ' ';
1141 Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy);
1145 void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1147 unsigned First = true;
1148 for (auto *Param : *Params) {
1155 switch (Param->getVariance()) {
1156 case ObjCTypeParamVariance::Invariant:
1159 case ObjCTypeParamVariance::Covariant:
1160 Out << "__covariant ";
1163 case ObjCTypeParamVariance::Contravariant:
1164 Out << "__contravariant ";
1168 Out << Param->getDeclName().getAsString();
1170 if (Param->hasExplicitBound()) {
1171 Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1177 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1178 if (OMD->isInstanceMethod())
1182 if (!OMD->getReturnType().isNull()) {
1183 PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1184 OMD->getReturnType());
1187 std::string name = OMD->getSelector().getAsString();
1188 std::string::size_type pos, lastPos = 0;
1189 for (const auto *PI : OMD->parameters()) {
1190 // FIXME: selector is missing here!
1191 pos = name.find_first_of(':', lastPos);
1194 Out << name.substr(lastPos, pos - lastPos) << ':';
1195 PrintObjCMethodType(OMD->getASTContext(),
1196 PI->getObjCDeclQualifier(),
1202 if (OMD->param_begin() == OMD->param_end())
1205 if (OMD->isVariadic())
1208 prettyPrintAttributes(OMD);
1210 if (OMD->getBody() && !Policy.TerseOutput) {
1212 OMD->getBody()->printPretty(Out, nullptr, Policy);
1214 else if (Policy.PolishForDeclaration)
1218 void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1219 std::string I = OID->getNameAsString();
1220 ObjCInterfaceDecl *SID = OID->getSuperClass();
1222 bool eolnOut = false;
1224 Out << "@implementation " << I << " : " << *SID;
1226 Out << "@implementation " << I;
1228 if (OID->ivar_size() > 0) {
1231 Indentation += Policy.Indentation;
1232 for (const auto *I : OID->ivars()) {
1233 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1234 getAsString(Policy) << ' ' << *I << ";\n";
1236 Indentation -= Policy.Indentation;
1239 else if (SID || (OID->decls_begin() != OID->decls_end())) {
1243 VisitDeclContext(OID, false);
1249 void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1250 std::string I = OID->getNameAsString();
1251 ObjCInterfaceDecl *SID = OID->getSuperClass();
1253 if (!OID->isThisDeclarationADefinition()) {
1254 Out << "@class " << I;
1256 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1257 PrintObjCTypeParams(TypeParams);
1263 bool eolnOut = false;
1264 Out << "@interface " << I;
1266 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1267 PrintObjCTypeParams(TypeParams);
1271 Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
1274 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1275 if (!Protocols.empty()) {
1276 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1277 E = Protocols.end(); I != E; ++I)
1278 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1282 if (OID->ivar_size() > 0) {
1285 Indentation += Policy.Indentation;
1286 for (const auto *I : OID->ivars()) {
1287 Indent() << I->getASTContext()
1288 .getUnqualifiedObjCPointerType(I->getType())
1289 .getAsString(Policy) << ' ' << *I << ";\n";
1291 Indentation -= Policy.Indentation;
1294 else if (SID || (OID->decls_begin() != OID->decls_end())) {
1299 VisitDeclContext(OID, false);
1303 // FIXME: implement the rest...
1306 void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1307 if (!PID->isThisDeclarationADefinition()) {
1308 Out << "@protocol " << *PID << ";\n";
1312 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1313 if (!Protocols.empty()) {
1314 Out << "@protocol " << *PID;
1315 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1316 E = Protocols.end(); I != E; ++I)
1317 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1320 Out << "@protocol " << *PID << '\n';
1321 VisitDeclContext(PID, false);
1325 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
1326 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
1328 VisitDeclContext(PID, false);
1330 // FIXME: implement the rest...
1333 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1334 Out << "@interface " << *PID->getClassInterface();
1335 if (auto TypeParams = PID->getTypeParamList()) {
1336 PrintObjCTypeParams(TypeParams);
1338 Out << "(" << *PID << ")\n";
1339 if (PID->ivar_size() > 0) {
1341 Indentation += Policy.Indentation;
1342 for (const auto *I : PID->ivars())
1343 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1344 getAsString(Policy) << ' ' << *I << ";\n";
1345 Indentation -= Policy.Indentation;
1349 VisitDeclContext(PID, false);
1352 // FIXME: implement the rest...
1355 void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
1356 Out << "@compatibility_alias " << *AID
1357 << ' ' << *AID->getClassInterface() << ";\n";
1360 /// PrintObjCPropertyDecl - print a property declaration.
1362 void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1363 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
1364 Out << "@required\n";
1365 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1366 Out << "@optional\n";
1368 QualType T = PDecl->getType();
1371 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
1374 if (PDecl->getPropertyAttributes() &
1375 ObjCPropertyDecl::OBJC_PR_readonly) {
1376 Out << (first ? ' ' : ',') << "readonly";
1380 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
1381 Out << (first ? ' ' : ',') << "getter = ";
1382 PDecl->getGetterName().print(Out);
1385 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
1386 Out << (first ? ' ' : ',') << "setter = ";
1387 PDecl->getSetterName().print(Out);
1391 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
1392 Out << (first ? ' ' : ',') << "assign";
1396 if (PDecl->getPropertyAttributes() &
1397 ObjCPropertyDecl::OBJC_PR_readwrite) {
1398 Out << (first ? ' ' : ',') << "readwrite";
1402 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
1403 Out << (first ? ' ' : ',') << "retain";
1407 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) {
1408 Out << (first ? ' ' : ',') << "strong";
1412 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
1413 Out << (first ? ' ' : ',') << "copy";
1417 if (PDecl->getPropertyAttributes() &
1418 ObjCPropertyDecl::OBJC_PR_nonatomic) {
1419 Out << (first ? ' ' : ',') << "nonatomic";
1422 if (PDecl->getPropertyAttributes() &
1423 ObjCPropertyDecl::OBJC_PR_atomic) {
1424 Out << (first ? ' ' : ',') << "atomic";
1428 if (PDecl->getPropertyAttributes() &
1429 ObjCPropertyDecl::OBJC_PR_nullability) {
1430 if (auto nullability = AttributedType::stripOuterNullability(T)) {
1431 if (*nullability == NullabilityKind::Unspecified &&
1432 (PDecl->getPropertyAttributes() &
1433 ObjCPropertyDecl::OBJC_PR_null_resettable)) {
1434 Out << (first ? ' ' : ',') << "null_resettable";
1436 Out << (first ? ' ' : ',')
1437 << getNullabilitySpelling(*nullability, true);
1443 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_class) {
1444 Out << (first ? ' ' : ',') << "class";
1448 (void) first; // Silence dead store warning due to idiomatic code.
1451 Out << ' ' << PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
1452 getAsString(Policy) << ' ' << *PDecl;
1453 if (Policy.PolishForDeclaration)
1457 void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1458 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1459 Out << "@synthesize ";
1462 Out << *PID->getPropertyDecl();
1463 if (PID->getPropertyIvarDecl())
1464 Out << '=' << *PID->getPropertyIvarDecl();
1467 void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1468 if (!D->isAccessDeclaration())
1470 if (D->hasTypename())
1472 D->getQualifier()->print(Out, Policy);
1474 // Use the correct record name when the using declaration is used for
1475 // inheriting constructors.
1476 for (const auto *Shadow : D->shadows()) {
1477 if (const auto *ConstructorShadow =
1478 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1479 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1480 Out << *ConstructorShadow->getNominatedBaseClass();
1488 DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1489 Out << "using typename ";
1490 D->getQualifier()->print(Out, Policy);
1491 Out << D->getDeclName();
1494 void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1495 if (!D->isAccessDeclaration())
1497 D->getQualifier()->print(Out, Policy);
1498 Out << D->getDeclName();
1501 void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1505 void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1506 Out << "#pragma omp threadprivate";
1507 if (!D->varlist_empty()) {
1508 for (OMPThreadPrivateDecl::varlist_iterator I = D->varlist_begin(),
1509 E = D->varlist_end();
1511 Out << (I == D->varlist_begin() ? '(' : ',');
1512 NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
1513 ND->printQualifiedName(Out);
1519 void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1520 if (!D->isInvalidDecl()) {
1521 Out << "#pragma omp declare reduction (";
1522 if (D->getDeclName().getNameKind() == DeclarationName::CXXOperatorName) {
1523 static const char *const OperatorNames[NUM_OVERLOADED_OPERATORS] = {
1525 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1527 #include "clang/Basic/OperatorKinds.def"
1529 const char *OpName =
1530 OperatorNames[D->getDeclName().getCXXOverloadedOperator()];
1531 assert(OpName && "not an overloaded operator");
1534 assert(D->getDeclName().isIdentifier());
1538 D->getType().print(Out, Policy);
1540 D->getCombiner()->printPretty(Out, nullptr, Policy, 0);
1542 if (auto *Init = D->getInitializer()) {
1543 Out << " initializer(";
1544 Init->printPretty(Out, nullptr, Policy, 0);
1550 void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
1551 D->getInit()->printPretty(Out, nullptr, Policy, Indentation);