blob: b8ebe1c568c790d9e01b5e4abc7df4fc15f94a53 [file] [log] [blame]
Douglas Gregor278f52e2009-05-30 00:08:05 +00001//===--- 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//
Alexander Kornienko90ff6072012-12-20 02:09:13 +000010// This file implements the Decl::print method, which pretty prints the
Douglas Gregor278f52e2009-05-30 00:08:05 +000011// AST back out to C/Objective-C/C++/Objective-C++ code.
12//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000015#include "clang/AST/Attr.h"
Douglas Gregor278f52e2009-05-30 00:08:05 +000016#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclObjC.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000019#include "clang/AST/DeclVisitor.h"
Douglas Gregor278f52e2009-05-30 00:08:05 +000020#include "clang/AST/Expr.h"
Douglas Gregor7ae2d772010-01-31 09:12:51 +000021#include "clang/AST/ExprCXX.h"
Douglas Gregor278f52e2009-05-30 00:08:05 +000022#include "clang/AST/PrettyPrinter.h"
Douglas Gregorba345522011-12-02 23:23:56 +000023#include "clang/Basic/Module.h"
Douglas Gregor278f52e2009-05-30 00:08:05 +000024#include "llvm/Support/raw_ostream.h"
25using namespace clang;
26
27namespace {
Benjamin Kramer26222b62009-11-28 19:03:38 +000028 class DeclPrinter : public DeclVisitor<DeclPrinter> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000029 raw_ostream &Out;
Douglas Gregor278f52e2009-05-30 00:08:05 +000030 PrintingPolicy Policy;
31 unsigned Indentation;
Richard Trieu82398f92011-07-28 00:19:05 +000032 bool PrintInstantiation;
Douglas Gregor278f52e2009-05-30 00:08:05 +000033
Chris Lattner0e62c1c2011-07-23 10:55:15 +000034 raw_ostream& Indent() { return Indent(Indentation); }
35 raw_ostream& Indent(unsigned Indentation);
36 void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls);
Douglas Gregor278f52e2009-05-30 00:08:05 +000037
Anders Carlsson601d6e42009-08-28 22:39:52 +000038 void Print(AccessSpecifier AS);
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregor813a0662015-06-19 18:14:38 +000040 /// 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
Douglas Gregor85f3f952015-07-07 03:57:15 +000047 void PrintObjCTypeParams(ObjCTypeParamList *Params);
48
Douglas Gregor278f52e2009-05-30 00:08:05 +000049 public:
Richard Smith235341b2012-08-16 03:56:14 +000050 DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy,
51 unsigned Indentation = 0, bool PrintInstantiation = false)
52 : Out(Out), Policy(Policy), Indentation(Indentation),
Richard Trieu82398f92011-07-28 00:19:05 +000053 PrintInstantiation(PrintInstantiation) { }
Douglas Gregor278f52e2009-05-30 00:08:05 +000054
55 void VisitDeclContext(DeclContext *DC, bool Indent = true);
56
57 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
58 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000059 void VisitTypeAliasDecl(TypeAliasDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000060 void VisitEnumDecl(EnumDecl *D);
61 void VisitRecordDecl(RecordDecl *D);
62 void VisitEnumConstantDecl(EnumConstantDecl *D);
Michael Han84324352013-02-22 17:15:32 +000063 void VisitEmptyDecl(EmptyDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000064 void VisitFunctionDecl(FunctionDecl *D);
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +000065 void VisitFriendDecl(FriendDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000066 void VisitFieldDecl(FieldDecl *D);
67 void VisitVarDecl(VarDecl *D);
Chris Lattnercab02a62011-02-17 20:34:02 +000068 void VisitLabelDecl(LabelDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000069 void VisitParmVarDecl(ParmVarDecl *D);
70 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +000071 void VisitImportDecl(ImportDecl *D);
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +000072 void VisitStaticAssertDecl(StaticAssertDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000073 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000074 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor18231932009-05-30 06:48:27 +000075 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000076 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000077 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith030f4992011-04-15 13:38:57 +000078 void VisitTemplateDecl(const TemplateDecl *D);
Richard Trieu82398f92011-07-28 00:19:05 +000079 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
80 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Serge Pavlova67a4d22016-11-10 08:49:37 +000081 void VisitClassTemplateSpecializationDecl(
82 ClassTemplateSpecializationDecl *D);
83 void VisitClassTemplatePartialSpecializationDecl(
84 ClassTemplatePartialSpecializationDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000085 void VisitObjCMethodDecl(ObjCMethodDecl *D);
86 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
87 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000088 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);
John McCalle61f2ba2009-11-18 02:36:19 +000094 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
95 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssondf5a1c82009-08-28 19:16:39 +000096 void VisitUsingDecl(UsingDecl *D);
John McCall3f746822009-11-17 05:59:44 +000097 void VisitUsingShadowDecl(UsingShadowDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +000098 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000099 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000100 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Trieu82398f92011-07-28 00:19:05 +0000101
Serge Pavlova67a4d22016-11-10 08:49:37 +0000102 void printTemplateParameters(const TemplateParameterList *Params);
103 void printTemplateArguments(const TemplateArgumentList &Args,
104 const TemplateParameterList *Params = nullptr);
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000105 void prettyPrintAttributes(Decl *D);
Alexey Bataev6d455322015-10-12 06:59:48 +0000106 void prettyPrintPragmas(Decl *D);
Richard Smitha4bb2922014-07-23 03:17:06 +0000107 void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000108 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000109}
Douglas Gregor278f52e2009-05-30 00:08:05 +0000110
Richard Trieu82398f92011-07-28 00:19:05 +0000111void Decl::print(raw_ostream &Out, unsigned Indentation,
112 bool PrintInstantiation) const {
Douglas Gregorc0b07282011-09-27 22:38:19 +0000113 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000114}
115
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000116void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
Richard Trieu82398f92011-07-28 00:19:05 +0000117 unsigned Indentation, bool PrintInstantiation) const {
Richard Smith235341b2012-08-16 03:56:14 +0000118 DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation);
Anders Carlsson46f87dc2009-09-26 21:58:53 +0000119 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor278f52e2009-05-30 00:08:05 +0000120}
121
Eli Friedman79635842009-05-30 04:20:30 +0000122static 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))
127 break;
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000128 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman79635842009-05-30 04:20:30 +0000129 BaseType = PTy->getPointeeType();
Ted Kremenekfa0a0b62012-10-11 20:58:14 +0000130 else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
131 BaseType = BPy->getPointeeType();
Eli Friedman79635842009-05-30 04:20:30 +0000132 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
133 BaseType = ATy->getElementType();
John McCall9dd450b2009-09-21 23:43:11 +0000134 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Alp Toker314cc812014-01-25 16:55:45 +0000135 BaseType = FTy->getReturnType();
John McCall9dd450b2009-09-21 23:43:11 +0000136 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor15548252009-07-01 23:58:14 +0000137 BaseType = VTy->getElementType();
Eli Friedman70bc6e62012-08-08 03:47:15 +0000138 else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
139 BaseType = RTy->getPointeeType();
Vassil Vassilevcdaa31f2016-07-08 16:04:22 +0000140 else if (const AutoType *ATy = BaseType->getAs<AutoType>())
141 BaseType = ATy->getDeducedType();
Eli Friedman79635842009-05-30 04:20:30 +0000142 else
David Blaikie83d382b2011-09-23 05:06:16 +0000143 llvm_unreachable("Unknown declarator!");
Eli Friedman79635842009-05-30 04:20:30 +0000144 }
145 return BaseType;
146}
147
148static QualType getDeclType(Decl* D) {
Richard Smithdda56e42011-04-15 14:24:37 +0000149 if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
Eli Friedman79635842009-05-30 04:20:30 +0000150 return TDD->getUnderlyingType();
151 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
152 return VD->getType();
153 return QualType();
154}
155
156void Decl::printGroup(Decl** Begin, unsigned NumDecls,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000157 raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman79635842009-05-30 04:20:30 +0000158 unsigned Indentation) {
159 if (NumDecls == 1) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000160 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000161 return;
162 }
163
164 Decl** End = Begin + NumDecls;
165 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
166 if (TD)
167 ++Begin;
168
169 PrintingPolicy SubPolicy(Policy);
Eli Friedman79635842009-05-30 04:20:30 +0000170
171 bool isFirst = true;
172 for ( ; Begin != End; ++Begin) {
173 if (isFirst) {
Steven Watanabe9359b8f2016-03-18 21:35:59 +0000174 if(TD)
175 SubPolicy.IncludeTagDefinition = true;
Eli Friedman79635842009-05-30 04:20:30 +0000176 SubPolicy.SuppressSpecifiers = false;
177 isFirst = false;
178 } else {
179 if (!isFirst) Out << ", ";
Steven Watanabe9359b8f2016-03-18 21:35:59 +0000180 SubPolicy.IncludeTagDefinition = false;
Eli Friedman79635842009-05-30 04:20:30 +0000181 SubPolicy.SuppressSpecifiers = true;
182 }
183
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000184 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000185 }
186}
187
Alp Tokeref6b0072014-01-04 13:47:14 +0000188LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
Anders Carlsson538af092009-12-09 17:27:46 +0000189 // Get the translation unit
190 const DeclContext *DC = this;
191 while (!DC->isTranslationUnit())
192 DC = DC->getParent();
193
194 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith235341b2012-08-16 03:56:14 +0000195 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0);
Anders Carlsson538af092009-12-09 17:27:46 +0000196 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
197}
198
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000199raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
Daniel Dunbar671f45e2009-11-21 09:12:06 +0000200 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000201 Out << " ";
202 return Out;
203}
204
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000205void DeclPrinter::prettyPrintAttributes(Decl *D) {
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000206 if (Policy.PolishForDeclaration)
Fariborz Jahaniana7d76d22012-10-17 21:58:03 +0000207 return;
Alexey Bataev6d455322015-10-12 06:59:48 +0000208
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000209 if (D->hasAttrs()) {
210 AttrVec &Attrs = D->getAttrs();
Alexey Bataev6d455322015-10-12 06:59:48 +0000211 for (auto *A : Attrs) {
212 switch (A->getKind()) {
213#define ATTR(X)
214#define PRAGMA_SPELLING_ATTR(X) case attr::X:
215#include "clang/Basic/AttrList.inc"
216 break;
217 default:
218 A->printPretty(Out, Policy);
219 break;
220 }
221 }
222 }
223}
224
225void DeclPrinter::prettyPrintPragmas(Decl *D) {
226 if (Policy.PolishForDeclaration)
227 return;
228
229 if (D->hasAttrs()) {
230 AttrVec &Attrs = D->getAttrs();
231 for (auto *A : Attrs) {
232 switch (A->getKind()) {
233#define ATTR(X)
234#define PRAGMA_SPELLING_ATTR(X) case attr::X:
235#include "clang/Basic/AttrList.inc"
236 A->printPretty(Out, Policy);
237 Indent();
238 break;
239 default:
240 break;
241 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000242 }
243 }
244}
245
Richard Smitha4bb2922014-07-23 03:17:06 +0000246void 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>()) {
251 Pack = true;
252 T = PET->getPattern();
253 }
Steven Watanabe9359b8f2016-03-18 21:35:59 +0000254 T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
Richard Smitha4bb2922014-07-23 03:17:06 +0000255}
256
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000257void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
Eli Friedman79635842009-05-30 04:20:30 +0000258 this->Indent();
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000259 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000260 Out << ";\n";
261 Decls.clear();
262
263}
264
Anders Carlsson601d6e42009-08-28 22:39:52 +0000265void DeclPrinter::Print(AccessSpecifier AS) {
266 switch(AS) {
David Blaikieaa347f92011-09-23 20:26:49 +0000267 case AS_none: llvm_unreachable("No access specifier!");
Anders Carlsson601d6e42009-08-28 22:39:52 +0000268 case AS_public: Out << "public"; break;
269 case AS_protected: Out << "protected"; break;
Abramo Bagnarad7340582010-06-05 05:09:32 +0000270 case AS_private: Out << "private"; break;
Anders Carlsson601d6e42009-08-28 22:39:52 +0000271 }
272}
273
Douglas Gregor278f52e2009-05-30 00:08:05 +0000274//----------------------------------------------------------------------------
275// Common C declarations
276//----------------------------------------------------------------------------
277
278void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
Dmitri Gribenkoa93a7e82012-08-21 17:36:32 +0000279 if (Policy.TerseOutput)
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000280 return;
281
Douglas Gregor278f52e2009-05-30 00:08:05 +0000282 if (Indent)
283 Indentation += Policy.Indentation;
284
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000285 SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000286 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000287 D != DEnd; ++D) {
Ted Kremenek28e1c912010-07-30 00:47:46 +0000288
289 // Don't print ObjCIvarDecls, as they are printed when visiting the
290 // containing ObjCInterfaceDecl.
291 if (isa<ObjCIvarDecl>(*D))
292 continue;
293
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000294 // Skip over implicit declarations in pretty-printing mode.
295 if (D->isImplicit())
296 continue;
297
Serge Pavlova67a4d22016-11-10 08:49:37 +0000298 // 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))
303 continue;
304
Eli Friedman79635842009-05-30 04:20:30 +0000305 // 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.
310 //
311 // Check whether the current declaration should be grouped with a previous
312 // unnamed struct.
313 QualType CurDeclType = getDeclType(*D);
314 if (!Decls.empty() && !CurDeclType.isNull()) {
315 QualType BaseType = GetBaseType(CurDeclType);
Eli Friedman24b3fed2013-08-12 21:54:04 +0000316 if (!BaseType.isNull() && isa<ElaboratedType>(BaseType))
317 BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
Eli Friedman79635842009-05-30 04:20:30 +0000318 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
319 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
320 Decls.push_back(*D);
321 continue;
322 }
323 }
324
325 // If we have a merged group waiting to be handled, handle it now.
326 if (!Decls.empty())
327 ProcessDeclGroup(Decls);
328
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()) {
332 Decls.push_back(*D);
333 continue;
334 }
Abramo Bagnarad7340582010-06-05 05:09:32 +0000335
336 if (isa<AccessSpecDecl>(*D)) {
337 Indentation -= Policy.Indentation;
338 this->Indent();
339 Print(D->getAccess());
340 Out << ":\n";
341 Indentation += Policy.Indentation;
342 continue;
343 }
344
Douglas Gregor278f52e2009-05-30 00:08:05 +0000345 this->Indent();
346 Visit(*D);
Mike Stump11289f42009-09-09 15:08:12 +0000347
348 // FIXME: Need to be able to tell the DeclPrinter when
Yaron Keren51db8772014-05-07 09:53:02 +0000349 const char *Terminator = nullptr;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000350 if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D))
Yaron Keren51db8772014-05-07 09:53:02 +0000351 Terminator = nullptr;
Serge Pavlovdc586c42016-10-31 05:11:12 +0000352 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
Yaron Keren51db8772014-05-07 09:53:02 +0000353 Terminator = nullptr;
Serge Pavlova67a4d22016-11-10 08:49:37 +0000354 else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
355 if (FD->isThisDeclarationADefinition())
356 Terminator = nullptr;
357 else
358 Terminator = ";";
359 } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
360 if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
361 Terminator = nullptr;
362 else
363 Terminator = ";";
364 } else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump11289f42009-09-09 15:08:12 +0000365 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor36098ff2009-05-30 00:56:08 +0000366 isa<ObjCInterfaceDecl>(*D) ||
367 isa<ObjCProtocolDecl>(*D) ||
368 isa<ObjCCategoryImplDecl>(*D) ||
369 isa<ObjCCategoryDecl>(*D))
Yaron Keren51db8772014-05-07 09:53:02 +0000370 Terminator = nullptr;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000371 else if (isa<EnumConstantDecl>(*D)) {
372 DeclContext::decl_iterator Next = D;
373 ++Next;
374 if (Next != DEnd)
375 Terminator = ",";
376 } else
377 Terminator = ";";
378
379 if (Terminator)
380 Out << Terminator;
Serge Pavlova67a4d22016-11-10 08:49:37 +0000381 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.
387 else
388 Out << "\n";
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000389
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";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000394 }
395
Eli Friedman79635842009-05-30 04:20:30 +0000396 if (!Decls.empty())
397 ProcessDeclGroup(Decls);
398
Douglas Gregor278f52e2009-05-30 00:08:05 +0000399 if (Indent)
400 Indentation -= Policy.Indentation;
401}
402
403void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
404 VisitDeclContext(D, false);
405}
406
407void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000408 if (!Policy.SuppressSpecifiers) {
Eli Friedman79635842009-05-30 04:20:30 +0000409 Out << "typedef ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000410
411 if (D->isModulePrivate())
412 Out << "__module_private__ ";
413 }
Steven Watanabe9359b8f2016-03-18 21:35:59 +0000414 QualType Ty = D->getTypeSourceInfo()->getType();
415 Ty.print(Out, Policy, D->getName(), Indentation);
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000416 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000417}
418
Richard Smithdda56e42011-04-15 14:24:37 +0000419void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000420 Out << "using " << *D;
421 prettyPrintAttributes(D);
422 Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
Richard Smithdda56e42011-04-15 14:24:37 +0000423}
424
Douglas Gregor278f52e2009-05-30 00:08:05 +0000425void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000426 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
427 Out << "__module_private__ ";
Douglas Gregorec0e3662010-12-01 16:01:08 +0000428 Out << "enum ";
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000429 if (D->isScoped()) {
430 if (D->isScopedUsingClassTag())
431 Out << "class ";
432 else
433 Out << "struct ";
434 }
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000435 Out << *D;
Douglas Gregorec0e3662010-12-01 16:01:08 +0000436
Serge Pavlov08c8de22016-11-04 06:03:34 +0000437 if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11)
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000438 Out << " : " << D->getIntegerType().stream(Policy);
Douglas Gregorec0e3662010-12-01 16:01:08 +0000439
John McCallf937c022011-10-07 06:10:15 +0000440 if (D->isCompleteDefinition()) {
Douglas Gregorec0e3662010-12-01 16:01:08 +0000441 Out << " {\n";
442 VisitDeclContext(D);
443 Indent() << "}";
444 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000445 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000446}
447
448void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000449 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
450 Out << "__module_private__ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000451 Out << D->getKindName();
Aaron Ballman53885382014-09-15 16:45:30 +0000452
453 prettyPrintAttributes(D);
454
Benjamin Kramerb11416d2010-04-17 09:33:03 +0000455 if (D->getIdentifier())
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000456 Out << ' ' << *D;
Mike Stump11289f42009-09-09 15:08:12 +0000457
John McCallf937c022011-10-07 06:10:15 +0000458 if (D->isCompleteDefinition()) {
Douglas Gregor278f52e2009-05-30 00:08:05 +0000459 Out << " {\n";
460 VisitDeclContext(D);
461 Indent() << "}";
462 }
463}
464
465void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000466 Out << *D;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000467 if (Expr *Init = D->getInitExpr()) {
468 Out << " = ";
Craig Topper36250ad2014-05-12 05:36:57 +0000469 Init->printPretty(Out, nullptr, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000470 }
471}
472
Mike Stump11289f42009-09-09 15:08:12 +0000473void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Alexey Bataev6d455322015-10-12 06:59:48 +0000474 if (!D->getDescribedFunctionTemplate() &&
475 !D->isFunctionTemplateSpecialization())
476 prettyPrintPragmas(D);
477
Serge Pavlova67a4d22016-11-10 08:49:37 +0000478 if (D->isFunctionTemplateSpecialization())
479 Out << "template<> ";
480
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000481 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000482 CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
Eli Friedman79635842009-05-30 04:20:30 +0000483 if (!Policy.SuppressSpecifiers) {
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000484 switch (D->getStorageClass()) {
John McCall8e7d6562010-08-26 03:08:43 +0000485 case SC_None: break;
486 case SC_Extern: Out << "extern "; break;
487 case SC_Static: Out << "static "; break;
488 case SC_PrivateExtern: Out << "__private_extern__ "; break;
Anastasia Stulovabcea6962015-09-30 14:08:20 +0000489 case SC_Auto: case SC_Register:
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000490 llvm_unreachable("invalid for functions");
Eli Friedman79635842009-05-30 04:20:30 +0000491 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000492
Douglas Gregor26701a42011-09-09 02:06:17 +0000493 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman79635842009-05-30 04:20:30 +0000494 if (D->isVirtualAsWritten()) Out << "virtual ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000495 if (D->isModulePrivate()) Out << "__module_private__ ";
Benjamin Kramer2907b082014-02-25 18:49:49 +0000496 if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr ";
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000497 if ((CDecl && CDecl->isExplicitSpecified()) ||
498 (ConversionDecl && ConversionDecl->isExplicit()))
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000499 Out << "explicit ";
Eli Friedman79635842009-05-30 04:20:30 +0000500 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000501
Douglas Gregor2d042f12009-05-30 05:39:39 +0000502 PrintingPolicy SubPolicy(Policy);
503 SubPolicy.SuppressSpecifiers = false;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000504 std::string Proto = D->getNameInfo().getAsString();
Serge Pavlova67a4d22016-11-10 08:49:37 +0000505 if (const TemplateArgumentList *TArgs = D->getTemplateSpecializationArgs()) {
506 llvm::raw_string_ostream POut(Proto);
507 DeclPrinter TArgPrinter(POut, SubPolicy, Indentation);
508 TArgPrinter.printTemplateArguments(*TArgs);
509 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000510
Abramo Bagnara6d810632010-12-14 22:11:44 +0000511 QualType Ty = D->getType();
John McCall424cec92011-01-19 06:33:43 +0000512 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
Abramo Bagnara6d810632010-12-14 22:11:44 +0000513 Proto = '(' + Proto + ')';
514 Ty = PT->getInnerType();
515 }
516
Reid Kleckner0503a872013-12-05 01:23:43 +0000517 if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
Craig Topper36250ad2014-05-12 05:36:57 +0000518 const FunctionProtoType *FT = nullptr;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000519 if (D->hasWrittenPrototype())
520 FT = dyn_cast<FunctionProtoType>(AFT);
521
522 Proto += "(";
523 if (FT) {
524 llvm::raw_string_ostream POut(Proto);
Richard Smith235341b2012-08-16 03:56:14 +0000525 DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000526 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
527 if (i) POut << ", ";
528 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
529 }
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregor278f52e2009-05-30 00:08:05 +0000531 if (FT->isVariadic()) {
532 if (D->getNumParams()) POut << ", ";
533 POut << "...";
534 }
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000535 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
Eli Friedman79635842009-05-30 04:20:30 +0000536 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
537 if (i)
538 Proto += ", ";
539 Proto += D->getParamDecl(i)->getNameAsString();
540 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000541 }
542
543 Proto += ")";
Douglas Gregor049bdca2009-12-08 17:45:32 +0000544
David Blaikief5697e52012-08-10 00:55:35 +0000545 if (FT) {
546 if (FT->isConst())
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000547 Proto += " const";
David Blaikief5697e52012-08-10 00:55:35 +0000548 if (FT->isVolatile())
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000549 Proto += " volatile";
David Blaikief5697e52012-08-10 00:55:35 +0000550 if (FT->isRestrict())
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000551 Proto += " restrict";
Benjamin Kramer2907b082014-02-25 18:49:49 +0000552
553 switch (FT->getRefQualifier()) {
554 case RQ_None:
555 break;
556 case RQ_LValue:
557 Proto += " &";
558 break;
559 case RQ_RValue:
560 Proto += " &&";
561 break;
562 }
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000563 }
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000564
565 if (FT && FT->hasDynamicExceptionSpec()) {
Douglas Gregor049bdca2009-12-08 17:45:32 +0000566 Proto += " throw(";
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000567 if (FT->getExceptionSpecType() == EST_MSAny)
Douglas Gregor049bdca2009-12-08 17:45:32 +0000568 Proto += "...";
569 else
570 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
571 if (I)
572 Proto += ", ";
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000573
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +0000574 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
Douglas Gregor049bdca2009-12-08 17:45:32 +0000575 }
576 Proto += ")";
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000577 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
578 Proto += " noexcept";
579 if (FT->getExceptionSpecType() == EST_ComputedNoexcept) {
580 Proto += "(";
581 llvm::raw_string_ostream EOut(Proto);
Craig Topper36250ad2014-05-12 05:36:57 +0000582 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000583 Indentation);
584 EOut.flush();
585 Proto += EOut.str();
586 Proto += ")";
587 }
Douglas Gregor049bdca2009-12-08 17:45:32 +0000588 }
589
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000590 if (CDecl) {
Richard Smith938f40b2011-06-11 17:19:42 +0000591 bool HasInitializerList = false;
Aaron Ballman0ad78302014-03-13 17:34:31 +0000592 for (const auto *BMInitializer : CDecl->inits()) {
Richard Smith938f40b2011-06-11 17:19:42 +0000593 if (BMInitializer->isInClassMemberInitializer())
594 continue;
595
596 if (!HasInitializerList) {
597 Proto += " : ";
598 Out << Proto;
599 Proto.clear();
600 HasInitializerList = true;
601 } else
602 Out << ", ";
603
604 if (BMInitializer->isAnyMemberInitializer()) {
605 FieldDecl *FD = BMInitializer->getAnyMember();
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000606 Out << *FD;
Richard Smith938f40b2011-06-11 17:19:42 +0000607 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000608 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
Richard Smith938f40b2011-06-11 17:19:42 +0000609 }
610
611 Out << "(";
612 if (!BMInitializer->getInit()) {
613 // Nothing to print
614 } else {
615 Expr *Init = BMInitializer->getInit();
616 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
617 Init = Tmp->getSubExpr();
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000618
Richard Smith938f40b2011-06-11 17:19:42 +0000619 Init = Init->IgnoreParens();
Craig Topper36250ad2014-05-12 05:36:57 +0000620
621 Expr *SimpleInit = nullptr;
622 Expr **Args = nullptr;
Richard Smith938f40b2011-06-11 17:19:42 +0000623 unsigned NumArgs = 0;
624 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
625 Args = ParenList->getExprs();
626 NumArgs = ParenList->getNumExprs();
627 } else if (CXXConstructExpr *Construct
628 = dyn_cast<CXXConstructExpr>(Init)) {
629 Args = Construct->getArgs();
630 NumArgs = Construct->getNumArgs();
631 } else
632 SimpleInit = Init;
633
634 if (SimpleInit)
Craig Topper36250ad2014-05-12 05:36:57 +0000635 SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
Richard Smith938f40b2011-06-11 17:19:42 +0000636 else {
637 for (unsigned I = 0; I != NumArgs; ++I) {
Richard Trieuddd01ce2014-06-09 22:53:25 +0000638 assert(Args[I] != nullptr && "Expected non-null Expr");
Richard Smith938f40b2011-06-11 17:19:42 +0000639 if (isa<CXXDefaultArgExpr>(Args[I]))
640 break;
641
642 if (I)
643 Out << ", ";
Craig Topper36250ad2014-05-12 05:36:57 +0000644 Args[I]->printPretty(Out, nullptr, Policy, Indentation);
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000645 }
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000646 }
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000647 }
Richard Smith938f40b2011-06-11 17:19:42 +0000648 Out << ")";
Benjamin Kramer2907b082014-02-25 18:49:49 +0000649 if (BMInitializer->isPackExpansion())
650 Out << "...";
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000651 }
Benjamin Kramer2907b082014-02-25 18:49:49 +0000652 } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
Richard Smithe6560762013-02-22 05:54:51 +0000653 if (FT && FT->hasTrailingReturn()) {
654 Out << "auto " << Proto << " -> ";
655 Proto.clear();
656 }
Alp Toker314cc812014-01-25 16:55:45 +0000657 AFT->getReturnType().print(Out, Policy, Proto);
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000658 Proto.clear();
Richard Smithe6560762013-02-22 05:54:51 +0000659 }
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000660 Out << Proto;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000661 } else {
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000662 Ty.print(Out, Policy, Proto);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000663 }
664
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000665 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000666
667 if (D->isPure())
668 Out << " = 0";
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000669 else if (D->isDeletedAsWritten())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000670 Out << " = delete";
Fariborz Jahaniande872af2012-12-05 22:53:06 +0000671 else if (D->isExplicitlyDefaulted())
672 Out << " = default";
Serge Pavlova67a4d22016-11-10 08:49:37 +0000673 else if (D->doesThisDeclarationHaveABody()) {
674 if (!Policy.TerseOutput) {
675 if (!D->hasPrototype() && D->getNumParams()) {
676 // This is a K&R function definition, so we need to print the
677 // parameters.
678 Out << '\n';
679 DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
680 Indentation += Policy.Indentation;
681 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
682 Indent();
683 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
684 Out << ";\n";
685 }
686 Indentation -= Policy.Indentation;
687 } else
688 Out << ' ';
Douglas Gregor278f52e2009-05-30 00:08:05 +0000689
Serge Pavlova67a4d22016-11-10 08:49:37 +0000690 if (D->getBody())
691 D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation);
692 } else {
693 if (isa<CXXConstructorDecl>(*D))
694 Out << " {}";
695 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000696 }
697}
698
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +0000699void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
700 if (TypeSourceInfo *TSI = D->getFriendType()) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +0000701 unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
702 for (unsigned i = 0; i < NumTPLists; ++i)
Serge Pavlova67a4d22016-11-10 08:49:37 +0000703 printTemplateParameters(D->getFriendTypeTemplateParameterList(i));
Fariborz Jahanian7a16a022012-12-21 21:43:05 +0000704 Out << "friend ";
705 Out << " " << TSI->getType().getAsString(Policy);
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +0000706 }
707 else if (FunctionDecl *FD =
708 dyn_cast<FunctionDecl>(D->getFriendDecl())) {
709 Out << "friend ";
710 VisitFunctionDecl(FD);
711 }
712 else if (FunctionTemplateDecl *FTD =
713 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
714 Out << "friend ";
715 VisitFunctionTemplateDecl(FTD);
716 }
717 else if (ClassTemplateDecl *CTD =
718 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
719 Out << "friend ";
Fariborz Jahanian7a16a022012-12-21 21:43:05 +0000720 VisitRedeclarableTemplateDecl(CTD);
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +0000721 }
722}
723
Douglas Gregor278f52e2009-05-30 00:08:05 +0000724void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Alexey Bataev6d455322015-10-12 06:59:48 +0000725 // FIXME: add printing of pragma attributes if required.
Eli Friedman79635842009-05-30 04:20:30 +0000726 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000727 Out << "mutable ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000728 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
729 Out << "__module_private__ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000730
Fariborz Jahanianb5f34682013-05-01 20:53:21 +0000731 Out << D->getASTContext().getUnqualifiedObjCPointerType(D->getType()).
Steven Watanabe9359b8f2016-03-18 21:35:59 +0000732 stream(Policy, D->getName(), Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000733
734 if (D->isBitField()) {
735 Out << " : ";
Craig Topper36250ad2014-05-12 05:36:57 +0000736 D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000737 }
Richard Smith938f40b2011-06-11 17:19:42 +0000738
739 Expr *Init = D->getInClassInitializer();
740 if (!Policy.SuppressInitializers && Init) {
Richard Smith2b013182012-06-10 03:12:00 +0000741 if (D->getInClassInitStyle() == ICIS_ListInit)
742 Out << " ";
743 else
744 Out << " = ";
Craig Topper36250ad2014-05-12 05:36:57 +0000745 Init->printPretty(Out, nullptr, Policy, Indentation);
Richard Smith938f40b2011-06-11 17:19:42 +0000746 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000747 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000748}
749
Chris Lattnercab02a62011-02-17 20:34:02 +0000750void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
Benjamin Kramerdb0fc512012-02-07 11:57:57 +0000751 Out << *D << ":";
Chris Lattnercab02a62011-02-17 20:34:02 +0000752}
753
Douglas Gregor278f52e2009-05-30 00:08:05 +0000754void DeclPrinter::VisitVarDecl(VarDecl *D) {
Alexey Bataev6d455322015-10-12 06:59:48 +0000755 prettyPrintPragmas(D);
Vassil Vassilev10023732016-07-08 21:09:08 +0000756
757 QualType T = D->getTypeSourceInfo()
758 ? D->getTypeSourceInfo()->getType()
759 : D->getASTContext().getUnqualifiedObjCPointerType(D->getType());
760
Richard Smithfd3834f2013-04-13 02:43:54 +0000761 if (!Policy.SuppressSpecifiers) {
762 StorageClass SC = D->getStorageClass();
763 if (SC != SC_None)
764 Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000765
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000766 switch (D->getTSCSpec()) {
767 case TSCS_unspecified:
Richard Smithfd3834f2013-04-13 02:43:54 +0000768 break;
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000769 case TSCS___thread:
770 Out << "__thread ";
771 break;
772 case TSCS__Thread_local:
Richard Smithfd3834f2013-04-13 02:43:54 +0000773 Out << "_Thread_local ";
774 break;
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000775 case TSCS_thread_local:
Richard Smithfd3834f2013-04-13 02:43:54 +0000776 Out << "thread_local ";
777 break;
778 }
779
780 if (D->isModulePrivate())
781 Out << "__module_private__ ";
Vassil Vassilev10023732016-07-08 21:09:08 +0000782
783 if (D->isConstexpr()) {
784 Out << "constexpr ";
785 T.removeLocalConst();
786 }
Richard Smithfd3834f2013-04-13 02:43:54 +0000787 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000788
Richard Smitha4bb2922014-07-23 03:17:06 +0000789 printDeclType(T, D->getName());
Richard Smith02e85f32011-04-14 22:09:26 +0000790 Expr *Init = D->getInit();
791 if (!Policy.SuppressInitializers && Init) {
Sebastian Redla9351792012-02-11 23:51:47 +0000792 bool ImplicitInit = false;
Dmitri Gribenkob614fab2013-02-03 23:02:47 +0000793 if (CXXConstructExpr *Construct =
794 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
Dmitri Gribenko6835e372013-01-27 21:28:24 +0000795 if (D->getInitStyle() == VarDecl::CallInit &&
796 !Construct->isListInitialization()) {
797 ImplicitInit = Construct->getNumArgs() == 0 ||
798 Construct->getArg(0)->isDefaultArgument();
799 }
800 }
Sebastian Redla9351792012-02-11 23:51:47 +0000801 if (!ImplicitInit) {
Eli Friedman92125c42012-10-19 20:36:44 +0000802 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redla9351792012-02-11 23:51:47 +0000803 Out << "(";
804 else if (D->getInitStyle() == VarDecl::CInit) {
805 Out << " = ";
806 }
Benjamin Kramer54f81ed2016-01-25 10:34:06 +0000807 PrintingPolicy SubPolicy(Policy);
808 SubPolicy.SuppressSpecifiers = false;
Steven Watanabe9359b8f2016-03-18 21:35:59 +0000809 SubPolicy.IncludeTagDefinition = false;
Benjamin Kramer54f81ed2016-01-25 10:34:06 +0000810 Init->printPretty(Out, nullptr, SubPolicy, Indentation);
Eli Friedman92125c42012-10-19 20:36:44 +0000811 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redla9351792012-02-11 23:51:47 +0000812 Out << ")";
Ted Kremenek35869382010-09-17 23:04:38 +0000813 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000814 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000815 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000816}
817
818void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
819 VisitVarDecl(D);
820}
821
822void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
823 Out << "__asm (";
Craig Topper36250ad2014-05-12 05:36:57 +0000824 D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000825 Out << ")";
826}
827
Douglas Gregorba345522011-12-02 23:23:56 +0000828void DeclPrinter::VisitImportDecl(ImportDecl *D) {
Douglas Gregorc50d4922012-12-11 22:11:52 +0000829 Out << "@import " << D->getImportedModule()->getFullModuleName()
Douglas Gregorba345522011-12-02 23:23:56 +0000830 << ";\n";
831}
832
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +0000833void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
834 Out << "static_assert(";
Craig Topper36250ad2014-05-12 05:36:57 +0000835 D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation);
David Majnemercdffc362015-06-05 18:03:58 +0000836 if (StringLiteral *SL = D->getMessage()) {
837 Out << ", ";
838 SL->printPretty(Out, nullptr, Policy, Indentation);
839 }
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +0000840 Out << ")";
841}
842
Douglas Gregor278f52e2009-05-30 00:08:05 +0000843//----------------------------------------------------------------------------
844// C++ declarations
845//----------------------------------------------------------------------------
Douglas Gregor5f478b72009-05-30 06:58:37 +0000846void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregorb5263702012-05-01 01:43:38 +0000847 if (D->isInline())
848 Out << "inline ";
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000849 Out << "namespace " << *D << " {\n";
Douglas Gregor5f478b72009-05-30 06:58:37 +0000850 VisitDeclContext(D);
851 Indent() << "}";
852}
853
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000854void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
855 Out << "using namespace ";
856 if (D->getQualifier())
857 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000858 Out << *D->getNominatedNamespaceAsWritten();
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000859}
860
Douglas Gregor18231932009-05-30 06:48:27 +0000861void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000862 Out << "namespace " << *D << " = ";
Douglas Gregor18231932009-05-30 06:48:27 +0000863 if (D->getQualifier())
864 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000865 Out << *D->getAliasedNamespace();
Douglas Gregor18231932009-05-30 06:48:27 +0000866}
867
Michael Han84324352013-02-22 17:15:32 +0000868void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
869 prettyPrintAttributes(D);
Michael Han84324352013-02-22 17:15:32 +0000870}
871
Douglas Gregor5f478b72009-05-30 06:58:37 +0000872void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Alexey Bataev6d455322015-10-12 06:59:48 +0000873 // FIXME: add printing of pragma attributes if required.
Douglas Gregor26701a42011-09-09 02:06:17 +0000874 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
875 Out << "__module_private__ ";
Douglas Gregor5f478b72009-05-30 06:58:37 +0000876 Out << D->getKindName();
Aaron Ballman53885382014-09-15 16:45:30 +0000877
878 prettyPrintAttributes(D);
879
Serge Pavlova67a4d22016-11-10 08:49:37 +0000880 if (D->getIdentifier()) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000881 Out << ' ' << *D;
Mike Stump11289f42009-09-09 15:08:12 +0000882
Serge Pavlova67a4d22016-11-10 08:49:37 +0000883 if (auto S = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
884 printTemplateArguments(S->getTemplateArgs(), S->getTemplateParameters());
885 else if (auto S = dyn_cast<ClassTemplateSpecializationDecl>(D))
886 printTemplateArguments(S->getTemplateArgs());
887 }
888
John McCallf937c022011-10-07 06:10:15 +0000889 if (D->isCompleteDefinition()) {
Douglas Gregor5f478b72009-05-30 06:58:37 +0000890 // Print the base classes
891 if (D->getNumBases()) {
892 Out << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000893 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
894 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor5f478b72009-05-30 06:58:37 +0000895 if (Base != D->bases_begin())
896 Out << ", ";
897
898 if (Base->isVirtual())
899 Out << "virtual ";
900
Anders Carlsson6df9e072009-08-29 20:36:12 +0000901 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
Richard Smitha5934192014-07-23 03:22:10 +0000902 if (AS != AS_none) {
Anders Carlsson6df9e072009-08-29 20:36:12 +0000903 Print(AS);
Richard Smitha5934192014-07-23 03:22:10 +0000904 Out << " ";
905 }
906 Out << Base->getType().getAsString(Policy);
Douglas Gregor5fc8c9e2011-04-27 17:07:55 +0000907
908 if (Base->isPackExpansion())
909 Out << "...";
Douglas Gregor5f478b72009-05-30 06:58:37 +0000910 }
911 }
912
913 // Print the class definition
Douglas Gregor7a1a7cb2009-05-31 07:13:39 +0000914 // FIXME: Doesn't print access specifiers, e.g., "public:"
Serge Pavlova67a4d22016-11-10 08:49:37 +0000915 if (Policy.TerseOutput) {
916 Out << " {}";
917 } else {
918 Out << " {\n";
919 VisitDeclContext(D);
920 Indent() << "}";
921 }
Mike Stump11289f42009-09-09 15:08:12 +0000922 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000923}
924
925void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
926 const char *l;
927 if (D->getLanguage() == LinkageSpecDecl::lang_c)
928 l = "C";
929 else {
930 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
931 "unknown language in linkage specification");
932 l = "C++";
933 }
934
935 Out << "extern \"" << l << "\" ";
936 if (D->hasBraces()) {
937 Out << "{\n";
938 VisitDeclContext(D);
939 Indent() << "}";
940 } else
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000941 Visit(*D->decls_begin());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000942}
943
Serge Pavlova67a4d22016-11-10 08:49:37 +0000944void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {
Richard Trieu82398f92011-07-28 00:19:05 +0000945 assert(Params);
Richard Trieu82398f92011-07-28 00:19:05 +0000946
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000947 Out << "template <";
Mike Stump11289f42009-09-09 15:08:12 +0000948
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000949 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
950 if (i != 0)
951 Out << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000952
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000953 const Decl *Param = Params->getParam(i);
Serge Pavlova67a4d22016-11-10 08:49:37 +0000954 if (auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump11289f42009-09-09 15:08:12 +0000955
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000956 if (TTP->wasDeclaredWithTypename())
957 Out << "typename ";
958 else
959 Out << "class ";
960
Anders Carlssonfb1d7762009-06-12 22:23:22 +0000961 if (TTP->isParameterPack())
Richard Smitha4bb2922014-07-23 03:17:06 +0000962 Out << "...";
Mike Stump11289f42009-09-09 15:08:12 +0000963
Benjamin Kramerdb0fc512012-02-07 11:57:57 +0000964 Out << *TTP;
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000965
Serge Pavlova67a4d22016-11-10 08:49:37 +0000966 if (TTP->hasDefaultArgument()) {
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000967 Out << " = ";
968 Out << TTP->getDefaultArgument().getAsString(Policy);
969 };
Serge Pavlova67a4d22016-11-10 08:49:37 +0000970 } else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
Richard Smitha4bb2922014-07-23 03:17:06 +0000971 StringRef Name;
972 if (IdentifierInfo *II = NTTP->getIdentifier())
973 Name = II->getName();
974 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
Mike Stump11289f42009-09-09 15:08:12 +0000975
Serge Pavlova67a4d22016-11-10 08:49:37 +0000976 if (NTTP->hasDefaultArgument()) {
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000977 Out << " = ";
Craig Topper36250ad2014-05-12 05:36:57 +0000978 NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy,
979 Indentation);
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000980 }
Serge Pavlova67a4d22016-11-10 08:49:37 +0000981 } else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
Richard Smith030f4992011-04-15 13:38:57 +0000982 VisitTemplateDecl(TTPD);
983 // FIXME: print the default argument, if present.
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000984 }
985 }
Mike Stump11289f42009-09-09 15:08:12 +0000986
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000987 Out << "> ";
Richard Trieu82398f92011-07-28 00:19:05 +0000988}
989
Serge Pavlova67a4d22016-11-10 08:49:37 +0000990void DeclPrinter::printTemplateArguments(const TemplateArgumentList &Args,
991 const TemplateParameterList *Params) {
992 Out << "<";
993 for (size_t I = 0, E = Args.size(); I < E; ++I) {
994 const TemplateArgument &A = Args[I];
995 if (I)
996 Out << ", ";
997 if (Params) {
998 if (A.getKind() == TemplateArgument::Type)
999 if (auto T = A.getAsType()->getAs<TemplateTypeParmType>()) {
1000 auto P = cast<TemplateTypeParmDecl>(Params->getParam(T->getIndex()));
1001 Out << *P;
1002 continue;
1003 }
1004 if (A.getKind() == TemplateArgument::Template) {
1005 if (auto T = A.getAsTemplate().getAsTemplateDecl())
1006 if (auto TD = dyn_cast<TemplateTemplateParmDecl>(T)) {
1007 auto P = cast<TemplateTemplateParmDecl>(
1008 Params->getParam(TD->getIndex()));
1009 Out << *P;
1010 continue;
1011 }
1012 }
1013 if (A.getKind() == TemplateArgument::Expression) {
1014 if (auto E = dyn_cast<DeclRefExpr>(A.getAsExpr()))
1015 if (auto N = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) {
1016 auto P = cast<NonTypeTemplateParmDecl>(
1017 Params->getParam(N->getIndex()));
1018 Out << *P;
1019 continue;
1020 }
1021 }
1022 }
1023 A.print(Policy, Out);
1024 }
1025 Out << ">";
1026}
1027
Richard Trieu82398f92011-07-28 00:19:05 +00001028void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
Serge Pavlova67a4d22016-11-10 08:49:37 +00001029 printTemplateParameters(D->getTemplateParameters());
Anders Carlsson40f8f8d2009-06-04 05:37:43 +00001030
Richard Smith030f4992011-04-15 13:38:57 +00001031 if (const TemplateTemplateParmDecl *TTP =
1032 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorf5500772011-01-05 15:48:55 +00001033 Out << "class ";
1034 if (TTP->isParameterPack())
1035 Out << "...";
1036 Out << D->getName();
Craig Silverstein4a5d0862010-07-09 20:25:10 +00001037 } else {
1038 Visit(D->getTemplatedDecl());
1039 }
Douglas Gregor278f52e2009-05-30 00:08:05 +00001040}
1041
Richard Trieu82398f92011-07-28 00:19:05 +00001042void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Alexey Bataev6d455322015-10-12 06:59:48 +00001043 prettyPrintPragmas(D->getTemplatedDecl());
Serge Pavlova67a4d22016-11-10 08:49:37 +00001044 VisitRedeclarableTemplateDecl(D);
1045
1046 if (PrintInstantiation) {
1047 FunctionDecl *PrevDecl = D->getTemplatedDecl();
1048 const FunctionDecl *Def;
1049 if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1050 return;
1051 for (auto *I : D->specializations())
1052 if (I->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) {
1053 if (!PrevDecl->isThisDeclarationADefinition())
1054 Out << ";\n";
1055 Indent();
1056 prettyPrintPragmas(I);
1057 Visit(I);
1058 }
1059 }
Richard Trieu82398f92011-07-28 00:19:05 +00001060}
1061
1062void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Serge Pavlova67a4d22016-11-10 08:49:37 +00001063 VisitRedeclarableTemplateDecl(D);
Richard Trieu82398f92011-07-28 00:19:05 +00001064
Serge Pavlova67a4d22016-11-10 08:49:37 +00001065 if (PrintInstantiation) {
1066 for (auto *I : D->specializations())
1067 if (I->getSpecializationKind() == TSK_ImplicitInstantiation) {
1068 if (D->isThisDeclarationADefinition())
1069 Out << ";";
1070 Out << "\n";
1071 Visit(I);
1072 }
1073 }
1074}
1075
1076void DeclPrinter::VisitClassTemplateSpecializationDecl(
1077 ClassTemplateSpecializationDecl *D) {
1078 Out << "template<> ";
1079 VisitCXXRecordDecl(D);
1080}
1081
1082void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1083 ClassTemplatePartialSpecializationDecl *D) {
1084 printTemplateParameters(D->getTemplateParameters());
1085 VisitCXXRecordDecl(D);
Richard Trieu82398f92011-07-28 00:19:05 +00001086}
1087
Douglas Gregor278f52e2009-05-30 00:08:05 +00001088//----------------------------------------------------------------------------
1089// Objective-C declarations
1090//----------------------------------------------------------------------------
1091
Douglas Gregor813a0662015-06-19 18:14:38 +00001092void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1093 Decl::ObjCDeclQualifier Quals,
1094 QualType T) {
1095 Out << '(';
1096 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1097 Out << "in ";
1098 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1099 Out << "inout ";
1100 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1101 Out << "out ";
1102 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1103 Out << "bycopy ";
1104 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1105 Out << "byref ";
1106 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1107 Out << "oneway ";
1108 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
Douglas Gregoraea7afd2015-06-24 22:02:08 +00001109 if (auto nullability = AttributedType::stripOuterNullability(T))
1110 Out << getNullabilitySpelling(*nullability, true) << ' ';
Douglas Gregor813a0662015-06-19 18:14:38 +00001111 }
1112
1113 Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy);
1114 Out << ')';
1115}
1116
Douglas Gregor85f3f952015-07-07 03:57:15 +00001117void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1118 Out << "<";
1119 unsigned First = true;
1120 for (auto *Param : *Params) {
1121 if (First) {
1122 First = false;
1123 } else {
1124 Out << ", ";
1125 }
1126
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001127 switch (Param->getVariance()) {
1128 case ObjCTypeParamVariance::Invariant:
1129 break;
1130
1131 case ObjCTypeParamVariance::Covariant:
1132 Out << "__covariant ";
1133 break;
1134
1135 case ObjCTypeParamVariance::Contravariant:
1136 Out << "__contravariant ";
1137 break;
1138 }
1139
Douglas Gregor85f3f952015-07-07 03:57:15 +00001140 Out << Param->getDeclName().getAsString();
1141
1142 if (Param->hasExplicitBound()) {
1143 Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1144 }
1145 }
1146 Out << ">";
1147}
1148
Douglas Gregor278f52e2009-05-30 00:08:05 +00001149void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1150 if (OMD->isInstanceMethod())
Douglas Gregor36098ff2009-05-30 00:56:08 +00001151 Out << "- ";
Mike Stump11289f42009-09-09 15:08:12 +00001152 else
Douglas Gregor36098ff2009-05-30 00:56:08 +00001153 Out << "+ ";
Douglas Gregor813a0662015-06-19 18:14:38 +00001154 if (!OMD->getReturnType().isNull()) {
1155 PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1156 OMD->getReturnType());
1157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregor278f52e2009-05-30 00:08:05 +00001159 std::string name = OMD->getSelector().getAsString();
1160 std::string::size_type pos, lastPos = 0;
David Majnemer59f77922016-06-24 04:05:48 +00001161 for (const auto *PI : OMD->parameters()) {
Mike Stump11289f42009-09-09 15:08:12 +00001162 // FIXME: selector is missing here!
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001163 pos = name.find_first_of(':', lastPos);
Douglas Gregor813a0662015-06-19 18:14:38 +00001164 Out << " " << name.substr(lastPos, pos - lastPos) << ':';
1165 PrintObjCMethodType(OMD->getASTContext(),
1166 PI->getObjCDeclQualifier(),
1167 PI->getType());
1168 Out << *PI;
Douglas Gregor278f52e2009-05-30 00:08:05 +00001169 lastPos = pos + 1;
1170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregor278f52e2009-05-30 00:08:05 +00001172 if (OMD->param_begin() == OMD->param_end())
1173 Out << " " << name;
Mike Stump11289f42009-09-09 15:08:12 +00001174
Douglas Gregor278f52e2009-05-30 00:08:05 +00001175 if (OMD->isVariadic())
1176 Out << ", ...";
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001177
1178 prettyPrintAttributes(OMD);
Mike Stump11289f42009-09-09 15:08:12 +00001179
Fariborz Jahaniana7d76d22012-10-17 21:58:03 +00001180 if (OMD->getBody() && !Policy.TerseOutput) {
Douglas Gregor278f52e2009-05-30 00:08:05 +00001181 Out << ' ';
Craig Topper36250ad2014-05-12 05:36:57 +00001182 OMD->getBody()->printPretty(Out, nullptr, Policy);
Douglas Gregor36098ff2009-05-30 00:56:08 +00001183 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001184 else if (Policy.PolishForDeclaration)
Fariborz Jahanian9b7ab872012-12-18 23:02:59 +00001185 Out << ';';
Douglas Gregor278f52e2009-05-30 00:08:05 +00001186}
1187
1188void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1189 std::string I = OID->getNameAsString();
1190 ObjCInterfaceDecl *SID = OID->getSuperClass();
1191
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001192 bool eolnOut = false;
Douglas Gregor278f52e2009-05-30 00:08:05 +00001193 if (SID)
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001194 Out << "@implementation " << I << " : " << *SID;
Douglas Gregor278f52e2009-05-30 00:08:05 +00001195 else
1196 Out << "@implementation " << I;
Fariborz Jahanian95759ff2012-12-04 00:47:33 +00001197
1198 if (OID->ivar_size() > 0) {
1199 Out << "{\n";
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001200 eolnOut = true;
Fariborz Jahanian95759ff2012-12-04 00:47:33 +00001201 Indentation += Policy.Indentation;
Aaron Ballmand6d25de2014-03-14 15:16:45 +00001202 for (const auto *I : OID->ivars()) {
Fariborz Jahanianb5f34682013-05-01 20:53:21 +00001203 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
Aaron Ballmand6d25de2014-03-14 15:16:45 +00001204 getAsString(Policy) << ' ' << *I << ";\n";
Fariborz Jahanian95759ff2012-12-04 00:47:33 +00001205 }
1206 Indentation -= Policy.Indentation;
1207 Out << "}\n";
1208 }
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001209 else if (SID || (OID->decls_begin() != OID->decls_end())) {
1210 Out << "\n";
1211 eolnOut = true;
1212 }
Douglas Gregor36098ff2009-05-30 00:56:08 +00001213 VisitDeclContext(OID, false);
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001214 if (!eolnOut)
1215 Out << "\n";
Douglas Gregor36098ff2009-05-30 00:56:08 +00001216 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001217}
1218
1219void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1220 std::string I = OID->getNameAsString();
1221 ObjCInterfaceDecl *SID = OID->getSuperClass();
1222
Douglas Gregordc9166c2011-12-15 20:29:51 +00001223 if (!OID->isThisDeclarationADefinition()) {
Douglas Gregor85f3f952015-07-07 03:57:15 +00001224 Out << "@class " << I;
1225
1226 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1227 PrintObjCTypeParams(TypeParams);
1228 }
1229
1230 Out << ";";
Douglas Gregordc9166c2011-12-15 20:29:51 +00001231 return;
1232 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001233 bool eolnOut = false;
Douglas Gregor85f3f952015-07-07 03:57:15 +00001234 Out << "@interface " << I;
1235
1236 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1237 PrintObjCTypeParams(TypeParams);
1238 }
1239
Douglas Gregor278f52e2009-05-30 00:08:05 +00001240 if (SID)
Bob Wilson1f24ea152015-10-01 00:53:13 +00001241 Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregor278f52e2009-05-30 00:08:05 +00001243 // Protocols?
1244 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1245 if (!Protocols.empty()) {
1246 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1247 E = Protocols.end(); I != E; ++I)
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001248 Out << (I == Protocols.begin() ? '<' : ',') << **I;
Douglas Gregor36098ff2009-05-30 00:56:08 +00001249 Out << "> ";
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregor278f52e2009-05-30 00:08:05 +00001252 if (OID->ivar_size() > 0) {
Douglas Gregor36098ff2009-05-30 00:56:08 +00001253 Out << "{\n";
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001254 eolnOut = true;
Douglas Gregor36098ff2009-05-30 00:56:08 +00001255 Indentation += Policy.Indentation;
Aaron Ballman59abbd42014-03-13 21:09:43 +00001256 for (const auto *I : OID->ivars()) {
1257 Indent() << I->getASTContext()
1258 .getUnqualifiedObjCPointerType(I->getType())
1259 .getAsString(Policy) << ' ' << *I << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001260 }
Douglas Gregor36098ff2009-05-30 00:56:08 +00001261 Indentation -= Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +00001262 Out << "}\n";
1263 }
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001264 else if (SID || (OID->decls_begin() != OID->decls_end())) {
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001265 Out << "\n";
1266 eolnOut = true;
1267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Douglas Gregor278f52e2009-05-30 00:08:05 +00001269 VisitDeclContext(OID, false);
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001270 if (!eolnOut)
Fariborz Jahanianaae7fef2014-10-03 20:05:33 +00001271 Out << "\n";
Douglas Gregor36098ff2009-05-30 00:56:08 +00001272 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001273 // FIXME: implement the rest...
1274}
1275
Douglas Gregor278f52e2009-05-30 00:08:05 +00001276void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
Douglas Gregorf6102672012-01-01 21:23:57 +00001277 if (!PID->isThisDeclarationADefinition()) {
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001278 Out << "@protocol " << *PID << ";\n";
Douglas Gregorf6102672012-01-01 21:23:57 +00001279 return;
1280 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001281 // Protocols?
1282 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1283 if (!Protocols.empty()) {
1284 Out << "@protocol " << *PID;
1285 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1286 E = Protocols.end(); I != E; ++I)
1287 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1288 Out << ">\n";
1289 } else
1290 Out << "@protocol " << *PID << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +00001291 VisitDeclContext(PID, false);
1292 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001293}
1294
1295void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001296 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001297
1298 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +00001299 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001300 // FIXME: implement the rest...
1301}
1302
1303void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Douglas Gregor85f3f952015-07-07 03:57:15 +00001304 Out << "@interface " << *PID->getClassInterface();
1305 if (auto TypeParams = PID->getTypeParamList()) {
1306 PrintObjCTypeParams(TypeParams);
1307 }
1308 Out << "(" << *PID << ")\n";
Fariborz Jahanian4cf177e2012-12-04 17:20:57 +00001309 if (PID->ivar_size() > 0) {
1310 Out << "{\n";
1311 Indentation += Policy.Indentation;
Aaron Ballman865fbcd2014-03-14 13:13:27 +00001312 for (const auto *I : PID->ivars())
Fariborz Jahanianb5f34682013-05-01 20:53:21 +00001313 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
Aaron Ballman865fbcd2014-03-14 13:13:27 +00001314 getAsString(Policy) << ' ' << *I << ";\n";
Fariborz Jahanian4cf177e2012-12-04 17:20:57 +00001315 Indentation -= Policy.Indentation;
1316 Out << "}\n";
1317 }
1318
Douglas Gregor278f52e2009-05-30 00:08:05 +00001319 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +00001320 Out << "@end";
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregor278f52e2009-05-30 00:08:05 +00001322 // FIXME: implement the rest...
1323}
1324
1325void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001326 Out << "@compatibility_alias " << *AID
1327 << ' ' << *AID->getClassInterface() << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001328}
1329
1330/// PrintObjCPropertyDecl - print a property declaration.
1331///
1332void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1333 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
1334 Out << "@required\n";
1335 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1336 Out << "@optional\n";
Mike Stump11289f42009-09-09 15:08:12 +00001337
Douglas Gregor813a0662015-06-19 18:14:38 +00001338 QualType T = PDecl->getType();
1339
Douglas Gregor278f52e2009-05-30 00:08:05 +00001340 Out << "@property";
1341 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
1342 bool first = true;
1343 Out << " (";
Mike Stump11289f42009-09-09 15:08:12 +00001344 if (PDecl->getPropertyAttributes() &
Douglas Gregor278f52e2009-05-30 00:08:05 +00001345 ObjCPropertyDecl::OBJC_PR_readonly) {
1346 Out << (first ? ' ' : ',') << "readonly";
1347 first = false;
Ted Kremenek897af912011-08-17 21:09:35 +00001348 }
Mike Stump11289f42009-09-09 15:08:12 +00001349
Ted Kremenek897af912011-08-17 21:09:35 +00001350 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00001351 Out << (first ? ' ' : ',') << "getter = ";
1352 PDecl->getGetterName().print(Out);
Ted Kremenek897af912011-08-17 21:09:35 +00001353 first = false;
1354 }
1355 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00001356 Out << (first ? ' ' : ',') << "setter = ";
1357 PDecl->getSetterName().print(Out);
Ted Kremenek897af912011-08-17 21:09:35 +00001358 first = false;
1359 }
Mike Stump11289f42009-09-09 15:08:12 +00001360
Ted Kremenek897af912011-08-17 21:09:35 +00001361 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
1362 Out << (first ? ' ' : ',') << "assign";
1363 first = false;
1364 }
Mike Stump11289f42009-09-09 15:08:12 +00001365
Ted Kremenek897af912011-08-17 21:09:35 +00001366 if (PDecl->getPropertyAttributes() &
1367 ObjCPropertyDecl::OBJC_PR_readwrite) {
1368 Out << (first ? ' ' : ',') << "readwrite";
1369 first = false;
1370 }
Mike Stump11289f42009-09-09 15:08:12 +00001371
Ted Kremenek897af912011-08-17 21:09:35 +00001372 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
1373 Out << (first ? ' ' : ',') << "retain";
1374 first = false;
1375 }
Mike Stump11289f42009-09-09 15:08:12 +00001376
Ted Kremenek897af912011-08-17 21:09:35 +00001377 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) {
1378 Out << (first ? ' ' : ',') << "strong";
1379 first = false;
1380 }
John McCall31168b02011-06-15 23:02:42 +00001381
Ted Kremenek897af912011-08-17 21:09:35 +00001382 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
1383 Out << (first ? ' ' : ',') << "copy";
1384 first = false;
1385 }
Mike Stump11289f42009-09-09 15:08:12 +00001386
Ted Kremenek897af912011-08-17 21:09:35 +00001387 if (PDecl->getPropertyAttributes() &
1388 ObjCPropertyDecl::OBJC_PR_nonatomic) {
1389 Out << (first ? ' ' : ',') << "nonatomic";
1390 first = false;
1391 }
1392 if (PDecl->getPropertyAttributes() &
1393 ObjCPropertyDecl::OBJC_PR_atomic) {
1394 Out << (first ? ' ' : ',') << "atomic";
1395 first = false;
1396 }
1397
Douglas Gregor813a0662015-06-19 18:14:38 +00001398 if (PDecl->getPropertyAttributes() &
1399 ObjCPropertyDecl::OBJC_PR_nullability) {
Douglas Gregor86b42682015-06-19 18:27:52 +00001400 if (auto nullability = AttributedType::stripOuterNullability(T)) {
Douglas Gregor849ebc22015-06-19 18:14:46 +00001401 if (*nullability == NullabilityKind::Unspecified &&
1402 (PDecl->getPropertyAttributes() &
1403 ObjCPropertyDecl::OBJC_PR_null_resettable)) {
1404 Out << (first ? ' ' : ',') << "null_resettable";
1405 } else {
1406 Out << (first ? ' ' : ',')
Douglas Gregoraea7afd2015-06-24 22:02:08 +00001407 << getNullabilitySpelling(*nullability, true);
Douglas Gregor849ebc22015-06-19 18:14:46 +00001408 }
Douglas Gregor813a0662015-06-19 18:14:38 +00001409 first = false;
1410 }
1411 }
1412
Manman Ren387ff7f2016-01-26 18:52:43 +00001413 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_class) {
1414 Out << (first ? ' ' : ',') << "class";
1415 first = false;
1416 }
1417
Ted Kremenek897af912011-08-17 21:09:35 +00001418 (void) first; // Silence dead store warning due to idiomatic code.
1419 Out << " )";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001420 }
Douglas Gregor813a0662015-06-19 18:14:38 +00001421 Out << ' ' << PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
Fariborz Jahanian9e075842013-05-01 17:28:37 +00001422 getAsString(Policy) << ' ' << *PDecl;
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001423 if (Policy.PolishForDeclaration)
1424 Out << ';';
Douglas Gregor278f52e2009-05-30 00:08:05 +00001425}
1426
1427void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1428 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor36098ff2009-05-30 00:56:08 +00001429 Out << "@synthesize ";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001430 else
Douglas Gregor36098ff2009-05-30 00:56:08 +00001431 Out << "@dynamic ";
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001432 Out << *PID->getPropertyDecl();
Douglas Gregor278f52e2009-05-30 00:08:05 +00001433 if (PID->getPropertyIvarDecl())
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001434 Out << '=' << *PID->getPropertyIvarDecl();
Douglas Gregor278f52e2009-05-30 00:08:05 +00001435}
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001436
1437void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
Enea Zaffanellac70b2512013-07-17 17:28:56 +00001438 if (!D->isAccessDeclaration())
1439 Out << "using ";
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001440 if (D->hasTypename())
Enea Zaffanellac70b2512013-07-17 17:28:56 +00001441 Out << "typename ";
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001442 D->getQualifier()->print(Out, Policy);
Alex Lorenzea9b59a2016-10-03 12:22:17 +00001443
1444 // Use the correct record name when the using declaration is used for
1445 // inheriting constructors.
1446 for (const auto *Shadow : D->shadows()) {
1447 if (const auto *ConstructorShadow =
1448 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1449 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1450 Out << *ConstructorShadow->getNominatedBaseClass();
1451 return;
1452 }
1453 }
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001454 Out << *D;
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001455}
1456
John McCalle61f2ba2009-11-18 02:36:19 +00001457void
1458DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1459 Out << "using typename ";
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001460 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001461 Out << D->getDeclName();
John McCalle61f2ba2009-11-18 02:36:19 +00001462}
1463
1464void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Enea Zaffanellac70b2512013-07-17 17:28:56 +00001465 if (!D->isAccessDeclaration())
1466 Out << "using ";
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001467 D->getQualifier()->print(Out, Policy);
Benjamin Kramer36d514e2015-09-23 13:43:16 +00001468 Out << D->getDeclName();
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001469}
John McCall3f746822009-11-17 05:59:44 +00001470
1471void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1472 // ignore
1473}
Alexey Bataeva769e072013-03-22 06:34:35 +00001474
1475void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1476 Out << "#pragma omp threadprivate";
1477 if (!D->varlist_empty()) {
1478 for (OMPThreadPrivateDecl::varlist_iterator I = D->varlist_begin(),
1479 E = D->varlist_end();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001480 I != E; ++I) {
Alexey Bataev7d2960b2013-09-26 03:24:06 +00001481 Out << (I == D->varlist_begin() ? '(' : ',');
1482 NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
1483 ND->printQualifiedName(Out);
Alexey Bataeva769e072013-03-22 06:34:35 +00001484 }
1485 Out << ")";
1486 }
1487}
1488
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001489void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1490 if (!D->isInvalidDecl()) {
1491 Out << "#pragma omp declare reduction (";
1492 if (D->getDeclName().getNameKind() == DeclarationName::CXXOperatorName) {
1493 static const char *const OperatorNames[NUM_OVERLOADED_OPERATORS] = {
1494 nullptr,
1495#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
1496 Spelling,
1497#include "clang/Basic/OperatorKinds.def"
1498 };
1499 const char *OpName =
1500 OperatorNames[D->getDeclName().getCXXOverloadedOperator()];
1501 assert(OpName && "not an overloaded operator");
1502 Out << OpName;
1503 } else {
1504 assert(D->getDeclName().isIdentifier());
1505 D->printName(Out);
1506 }
1507 Out << " : ";
1508 D->getType().print(Out, Policy);
1509 Out << " : ";
1510 D->getCombiner()->printPretty(Out, nullptr, Policy, 0);
1511 Out << ")";
1512 if (auto *Init = D->getInitializer()) {
1513 Out << " initializer(";
1514 Init->printPretty(Out, nullptr, Policy, 0);
1515 Out << ")";
1516 }
1517 }
1518}
1519
Alexey Bataev4244be22016-02-11 05:35:55 +00001520void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001521 D->getInit()->printPretty(Out, nullptr, Policy, Indentation);
1522}
1523