blob: 54fa9ca5890f98d10e19309a4df509e721e446bb [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 Gregor278f52e2009-05-30 00:08:05 +000040 public:
Richard Smith235341b2012-08-16 03:56:14 +000041 DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy,
42 unsigned Indentation = 0, bool PrintInstantiation = false)
43 : Out(Out), Policy(Policy), Indentation(Indentation),
Richard Trieu82398f92011-07-28 00:19:05 +000044 PrintInstantiation(PrintInstantiation) { }
Douglas Gregor278f52e2009-05-30 00:08:05 +000045
46 void VisitDeclContext(DeclContext *DC, bool Indent = true);
47
48 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
49 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000050 void VisitTypeAliasDecl(TypeAliasDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000051 void VisitEnumDecl(EnumDecl *D);
52 void VisitRecordDecl(RecordDecl *D);
53 void VisitEnumConstantDecl(EnumConstantDecl *D);
Michael Han84324352013-02-22 17:15:32 +000054 void VisitEmptyDecl(EmptyDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000055 void VisitFunctionDecl(FunctionDecl *D);
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +000056 void VisitFriendDecl(FriendDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000057 void VisitFieldDecl(FieldDecl *D);
58 void VisitVarDecl(VarDecl *D);
Chris Lattnercab02a62011-02-17 20:34:02 +000059 void VisitLabelDecl(LabelDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000060 void VisitParmVarDecl(ParmVarDecl *D);
61 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +000062 void VisitImportDecl(ImportDecl *D);
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +000063 void VisitStaticAssertDecl(StaticAssertDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000064 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000065 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor18231932009-05-30 06:48:27 +000066 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000067 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000068 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith030f4992011-04-15 13:38:57 +000069 void VisitTemplateDecl(const TemplateDecl *D);
Richard Trieu82398f92011-07-28 00:19:05 +000070 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
71 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000072 void VisitObjCMethodDecl(ObjCMethodDecl *D);
73 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
74 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000075 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
76 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
77 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
78 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
79 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
80 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
John McCalle61f2ba2009-11-18 02:36:19 +000081 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
82 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssondf5a1c82009-08-28 19:16:39 +000083 void VisitUsingDecl(UsingDecl *D);
John McCall3f746822009-11-17 05:59:44 +000084 void VisitUsingShadowDecl(UsingShadowDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +000085 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Richard Trieu82398f92011-07-28 00:19:05 +000086
87 void PrintTemplateParameters(const TemplateParameterList *Params,
Enea Zaffanellaeb22c872013-01-31 09:54:08 +000088 const TemplateArgumentList *Args = 0);
Douglas Gregor49ccfaa2011-11-19 19:22:57 +000089 void prettyPrintAttributes(Decl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000090 };
91}
92
Richard Trieu82398f92011-07-28 00:19:05 +000093void Decl::print(raw_ostream &Out, unsigned Indentation,
94 bool PrintInstantiation) const {
Douglas Gregorc0b07282011-09-27 22:38:19 +000095 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
Douglas Gregor278f52e2009-05-30 00:08:05 +000096}
97
Chris Lattner0e62c1c2011-07-23 10:55:15 +000098void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
Richard Trieu82398f92011-07-28 00:19:05 +000099 unsigned Indentation, bool PrintInstantiation) const {
Richard Smith235341b2012-08-16 03:56:14 +0000100 DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation);
Anders Carlsson46f87dc2009-09-26 21:58:53 +0000101 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor278f52e2009-05-30 00:08:05 +0000102}
103
Eli Friedman79635842009-05-30 04:20:30 +0000104static QualType GetBaseType(QualType T) {
105 // FIXME: This should be on the Type class!
106 QualType BaseType = T;
107 while (!BaseType->isSpecifierType()) {
108 if (isa<TypedefType>(BaseType))
109 break;
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000110 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman79635842009-05-30 04:20:30 +0000111 BaseType = PTy->getPointeeType();
Ted Kremenekfa0a0b62012-10-11 20:58:14 +0000112 else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
113 BaseType = BPy->getPointeeType();
Eli Friedman79635842009-05-30 04:20:30 +0000114 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
115 BaseType = ATy->getElementType();
John McCall9dd450b2009-09-21 23:43:11 +0000116 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Eli Friedman79635842009-05-30 04:20:30 +0000117 BaseType = FTy->getResultType();
John McCall9dd450b2009-09-21 23:43:11 +0000118 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor15548252009-07-01 23:58:14 +0000119 BaseType = VTy->getElementType();
Eli Friedman70bc6e62012-08-08 03:47:15 +0000120 else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
121 BaseType = RTy->getPointeeType();
Eli Friedman79635842009-05-30 04:20:30 +0000122 else
David Blaikie83d382b2011-09-23 05:06:16 +0000123 llvm_unreachable("Unknown declarator!");
Eli Friedman79635842009-05-30 04:20:30 +0000124 }
125 return BaseType;
126}
127
128static QualType getDeclType(Decl* D) {
Richard Smithdda56e42011-04-15 14:24:37 +0000129 if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
Eli Friedman79635842009-05-30 04:20:30 +0000130 return TDD->getUnderlyingType();
131 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
132 return VD->getType();
133 return QualType();
134}
135
136void Decl::printGroup(Decl** Begin, unsigned NumDecls,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000137 raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman79635842009-05-30 04:20:30 +0000138 unsigned Indentation) {
139 if (NumDecls == 1) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000140 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000141 return;
142 }
143
144 Decl** End = Begin + NumDecls;
145 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
146 if (TD)
147 ++Begin;
148
149 PrintingPolicy SubPolicy(Policy);
John McCallf937c022011-10-07 06:10:15 +0000150 if (TD && TD->isCompleteDefinition()) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000151 TD->print(Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000152 Out << " ";
153 SubPolicy.SuppressTag = true;
154 }
155
156 bool isFirst = true;
157 for ( ; Begin != End; ++Begin) {
158 if (isFirst) {
159 SubPolicy.SuppressSpecifiers = false;
160 isFirst = false;
161 } else {
162 if (!isFirst) Out << ", ";
163 SubPolicy.SuppressSpecifiers = true;
164 }
165
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000166 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000167 }
168}
169
Anders Carlsson89112292009-12-14 00:51:04 +0000170void DeclContext::dumpDeclContext() const {
Anders Carlsson538af092009-12-09 17:27:46 +0000171 // Get the translation unit
172 const DeclContext *DC = this;
173 while (!DC->isTranslationUnit())
174 DC = DC->getParent();
175
176 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith235341b2012-08-16 03:56:14 +0000177 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0);
Anders Carlsson538af092009-12-09 17:27:46 +0000178 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
179}
180
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000181raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
Daniel Dunbar671f45e2009-11-21 09:12:06 +0000182 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000183 Out << " ";
184 return Out;
185}
186
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000187void DeclPrinter::prettyPrintAttributes(Decl *D) {
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000188 if (Policy.PolishForDeclaration)
Fariborz Jahaniana7d76d22012-10-17 21:58:03 +0000189 return;
190
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000191 if (D->hasAttrs()) {
192 AttrVec &Attrs = D->getAttrs();
193 for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) {
Richard Smith52f04a22012-08-16 02:43:29 +0000194 Attr *A = *i;
195 A->printPretty(Out, Policy);
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000196 }
197 }
198}
199
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000200void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
Eli Friedman79635842009-05-30 04:20:30 +0000201 this->Indent();
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000202 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000203 Out << ";\n";
204 Decls.clear();
205
206}
207
Anders Carlsson601d6e42009-08-28 22:39:52 +0000208void DeclPrinter::Print(AccessSpecifier AS) {
209 switch(AS) {
David Blaikieaa347f92011-09-23 20:26:49 +0000210 case AS_none: llvm_unreachable("No access specifier!");
Anders Carlsson601d6e42009-08-28 22:39:52 +0000211 case AS_public: Out << "public"; break;
212 case AS_protected: Out << "protected"; break;
Abramo Bagnarad7340582010-06-05 05:09:32 +0000213 case AS_private: Out << "private"; break;
Anders Carlsson601d6e42009-08-28 22:39:52 +0000214 }
215}
216
Douglas Gregor278f52e2009-05-30 00:08:05 +0000217//----------------------------------------------------------------------------
218// Common C declarations
219//----------------------------------------------------------------------------
220
221void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
Dmitri Gribenkoa93a7e82012-08-21 17:36:32 +0000222 if (Policy.TerseOutput)
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000223 return;
224
Douglas Gregor278f52e2009-05-30 00:08:05 +0000225 if (Indent)
226 Indentation += Policy.Indentation;
227
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000228 SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000229 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000230 D != DEnd; ++D) {
Ted Kremenek28e1c912010-07-30 00:47:46 +0000231
232 // Don't print ObjCIvarDecls, as they are printed when visiting the
233 // containing ObjCInterfaceDecl.
234 if (isa<ObjCIvarDecl>(*D))
235 continue;
236
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000237 // Skip over implicit declarations in pretty-printing mode.
238 if (D->isImplicit())
239 continue;
240
241 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
242 // of __builtin_va_list or __[u]int128_t. There should be some other way
243 // to check that.
244 if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) {
245 if (IdentifierInfo *II = ND->getIdentifier()) {
246 if (II->isStr("__builtin_va_list") ||
247 II->isStr("__int128_t") || II->isStr("__uint128_t"))
248 continue;
Argyrios Kyrtzidisfa533e72010-06-17 10:52:11 +0000249 }
Eli Friedmanef334fd2009-05-30 05:03:24 +0000250 }
251
Eli Friedman79635842009-05-30 04:20:30 +0000252 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
253 // forced to merge the declarations because there's no other way to
254 // refer to the struct in question. This limited merging is safe without
255 // a bunch of other checks because it only merges declarations directly
256 // referring to the tag, not typedefs.
257 //
258 // Check whether the current declaration should be grouped with a previous
259 // unnamed struct.
260 QualType CurDeclType = getDeclType(*D);
261 if (!Decls.empty() && !CurDeclType.isNull()) {
262 QualType BaseType = GetBaseType(CurDeclType);
263 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
264 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
265 Decls.push_back(*D);
266 continue;
267 }
268 }
269
270 // If we have a merged group waiting to be handled, handle it now.
271 if (!Decls.empty())
272 ProcessDeclGroup(Decls);
273
274 // If the current declaration is an unnamed tag type, save it
275 // so we can merge it with the subsequent declaration(s) using it.
276 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
277 Decls.push_back(*D);
278 continue;
279 }
Abramo Bagnarad7340582010-06-05 05:09:32 +0000280
281 if (isa<AccessSpecDecl>(*D)) {
282 Indentation -= Policy.Indentation;
283 this->Indent();
284 Print(D->getAccess());
285 Out << ":\n";
286 Indentation += Policy.Indentation;
287 continue;
288 }
289
Douglas Gregor278f52e2009-05-30 00:08:05 +0000290 this->Indent();
291 Visit(*D);
Mike Stump11289f42009-09-09 15:08:12 +0000292
293 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor278f52e2009-05-30 00:08:05 +0000294 const char *Terminator = 0;
Alexey Bataeva769e072013-03-22 06:34:35 +0000295 if (isa<OMPThreadPrivateDecl>(*D))
296 Terminator = 0;
297 else if (isa<FunctionDecl>(*D) &&
298 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000299 Terminator = 0;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000300 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
301 Terminator = 0;
302 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump11289f42009-09-09 15:08:12 +0000303 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor36098ff2009-05-30 00:56:08 +0000304 isa<ObjCInterfaceDecl>(*D) ||
305 isa<ObjCProtocolDecl>(*D) ||
306 isa<ObjCCategoryImplDecl>(*D) ||
307 isa<ObjCCategoryDecl>(*D))
Douglas Gregor278f52e2009-05-30 00:08:05 +0000308 Terminator = 0;
309 else if (isa<EnumConstantDecl>(*D)) {
310 DeclContext::decl_iterator Next = D;
311 ++Next;
312 if (Next != DEnd)
313 Terminator = ",";
314 } else
315 Terminator = ";";
316
317 if (Terminator)
318 Out << Terminator;
319 Out << "\n";
320 }
321
Eli Friedman79635842009-05-30 04:20:30 +0000322 if (!Decls.empty())
323 ProcessDeclGroup(Decls);
324
Douglas Gregor278f52e2009-05-30 00:08:05 +0000325 if (Indent)
326 Indentation -= Policy.Indentation;
327}
328
329void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
330 VisitDeclContext(D, false);
331}
332
333void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000334 if (!Policy.SuppressSpecifiers) {
Eli Friedman79635842009-05-30 04:20:30 +0000335 Out << "typedef ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000336
337 if (D->isModulePrivate())
338 Out << "__module_private__ ";
339 }
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000340 D->getUnderlyingType().print(Out, Policy, D->getName());
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000341 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000342}
343
Richard Smithdda56e42011-04-15 14:24:37 +0000344void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Benjamin Kramerdb0fc512012-02-07 11:57:57 +0000345 Out << "using " << *D << " = " << D->getUnderlyingType().getAsString(Policy);
Richard Smithdda56e42011-04-15 14:24:37 +0000346}
347
Douglas Gregor278f52e2009-05-30 00:08:05 +0000348void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000349 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
350 Out << "__module_private__ ";
Douglas Gregorec0e3662010-12-01 16:01:08 +0000351 Out << "enum ";
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000352 if (D->isScoped()) {
353 if (D->isScopedUsingClassTag())
354 Out << "class ";
355 else
356 Out << "struct ";
357 }
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000358 Out << *D;
Douglas Gregorec0e3662010-12-01 16:01:08 +0000359
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000360 if (D->isFixed())
361 Out << " : " << D->getIntegerType().stream(Policy);
Douglas Gregorec0e3662010-12-01 16:01:08 +0000362
John McCallf937c022011-10-07 06:10:15 +0000363 if (D->isCompleteDefinition()) {
Douglas Gregorec0e3662010-12-01 16:01:08 +0000364 Out << " {\n";
365 VisitDeclContext(D);
366 Indent() << "}";
367 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000368 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000369}
370
371void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000372 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
373 Out << "__module_private__ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000374 Out << D->getKindName();
Benjamin Kramerb11416d2010-04-17 09:33:03 +0000375 if (D->getIdentifier())
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000376 Out << ' ' << *D;
Mike Stump11289f42009-09-09 15:08:12 +0000377
John McCallf937c022011-10-07 06:10:15 +0000378 if (D->isCompleteDefinition()) {
Douglas Gregor278f52e2009-05-30 00:08:05 +0000379 Out << " {\n";
380 VisitDeclContext(D);
381 Indent() << "}";
382 }
383}
384
385void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000386 Out << *D;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000387 if (Expr *Init = D->getInitExpr()) {
388 Out << " = ";
Richard Smith235341b2012-08-16 03:56:14 +0000389 Init->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000390 }
391}
392
Mike Stump11289f42009-09-09 15:08:12 +0000393void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000394 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
Eli Friedman79635842009-05-30 04:20:30 +0000395 if (!Policy.SuppressSpecifiers) {
Peter Collingbourne32fab902011-11-08 02:52:52 +0000396 switch (D->getStorageClassAsWritten()) {
John McCall8e7d6562010-08-26 03:08:43 +0000397 case SC_None: break;
398 case SC_Extern: Out << "extern "; break;
399 case SC_Static: Out << "static "; break;
400 case SC_PrivateExtern: Out << "__private_extern__ "; break;
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000401 case SC_Auto: case SC_Register: case SC_OpenCLWorkGroupLocal:
402 llvm_unreachable("invalid for functions");
Eli Friedman79635842009-05-30 04:20:30 +0000403 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000404
Douglas Gregor26701a42011-09-09 02:06:17 +0000405 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman79635842009-05-30 04:20:30 +0000406 if (D->isVirtualAsWritten()) Out << "virtual ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000407 if (D->isModulePrivate()) Out << "__module_private__ ";
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000408 if (CDecl && CDecl->isExplicitSpecified())
409 Out << "explicit ";
Eli Friedman79635842009-05-30 04:20:30 +0000410 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000411
Douglas Gregor2d042f12009-05-30 05:39:39 +0000412 PrintingPolicy SubPolicy(Policy);
413 SubPolicy.SuppressSpecifiers = false;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000414 std::string Proto = D->getNameInfo().getAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000415
Abramo Bagnara6d810632010-12-14 22:11:44 +0000416 QualType Ty = D->getType();
John McCall424cec92011-01-19 06:33:43 +0000417 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
Abramo Bagnara6d810632010-12-14 22:11:44 +0000418 Proto = '(' + Proto + ')';
419 Ty = PT->getInnerType();
420 }
421
422 if (isa<FunctionType>(Ty)) {
423 const FunctionType *AFT = Ty->getAs<FunctionType>();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000424 const FunctionProtoType *FT = 0;
425 if (D->hasWrittenPrototype())
426 FT = dyn_cast<FunctionProtoType>(AFT);
427
428 Proto += "(";
429 if (FT) {
430 llvm::raw_string_ostream POut(Proto);
Richard Smith235341b2012-08-16 03:56:14 +0000431 DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000432 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
433 if (i) POut << ", ";
434 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
435 }
Mike Stump11289f42009-09-09 15:08:12 +0000436
Douglas Gregor278f52e2009-05-30 00:08:05 +0000437 if (FT->isVariadic()) {
438 if (D->getNumParams()) POut << ", ";
439 POut << "...";
440 }
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000441 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
Eli Friedman79635842009-05-30 04:20:30 +0000442 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
443 if (i)
444 Proto += ", ";
445 Proto += D->getParamDecl(i)->getNameAsString();
446 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000447 }
448
449 Proto += ")";
Douglas Gregor049bdca2009-12-08 17:45:32 +0000450
David Blaikief5697e52012-08-10 00:55:35 +0000451 if (FT) {
452 if (FT->isConst())
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000453 Proto += " const";
David Blaikief5697e52012-08-10 00:55:35 +0000454 if (FT->isVolatile())
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000455 Proto += " volatile";
David Blaikief5697e52012-08-10 00:55:35 +0000456 if (FT->isRestrict())
Douglas Gregor8fc96fc2010-11-19 18:44:34 +0000457 Proto += " restrict";
458 }
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000459
460 if (FT && FT->hasDynamicExceptionSpec()) {
Douglas Gregor049bdca2009-12-08 17:45:32 +0000461 Proto += " throw(";
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000462 if (FT->getExceptionSpecType() == EST_MSAny)
Douglas Gregor049bdca2009-12-08 17:45:32 +0000463 Proto += "...";
464 else
465 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
466 if (I)
467 Proto += ", ";
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000468
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +0000469 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
Douglas Gregor049bdca2009-12-08 17:45:32 +0000470 }
471 Proto += ")";
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000472 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
473 Proto += " noexcept";
474 if (FT->getExceptionSpecType() == EST_ComputedNoexcept) {
475 Proto += "(";
476 llvm::raw_string_ostream EOut(Proto);
Richard Smith235341b2012-08-16 03:56:14 +0000477 FT->getNoexceptExpr()->printPretty(EOut, 0, SubPolicy,
Sebastian Redlfa453cf2011-03-12 11:50:43 +0000478 Indentation);
479 EOut.flush();
480 Proto += EOut.str();
481 Proto += ")";
482 }
Douglas Gregor049bdca2009-12-08 17:45:32 +0000483 }
484
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000485 if (CDecl) {
Richard Smith938f40b2011-06-11 17:19:42 +0000486 bool HasInitializerList = false;
487 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
488 E = CDecl->init_end();
489 B != E; ++B) {
490 CXXCtorInitializer * BMInitializer = (*B);
491 if (BMInitializer->isInClassMemberInitializer())
492 continue;
493
494 if (!HasInitializerList) {
495 Proto += " : ";
496 Out << Proto;
497 Proto.clear();
498 HasInitializerList = true;
499 } else
500 Out << ", ";
501
502 if (BMInitializer->isAnyMemberInitializer()) {
503 FieldDecl *FD = BMInitializer->getAnyMember();
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000504 Out << *FD;
Richard Smith938f40b2011-06-11 17:19:42 +0000505 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000506 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
Richard Smith938f40b2011-06-11 17:19:42 +0000507 }
508
509 Out << "(";
510 if (!BMInitializer->getInit()) {
511 // Nothing to print
512 } else {
513 Expr *Init = BMInitializer->getInit();
514 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
515 Init = Tmp->getSubExpr();
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000516
Richard Smith938f40b2011-06-11 17:19:42 +0000517 Init = Init->IgnoreParens();
518
519 Expr *SimpleInit = 0;
520 Expr **Args = 0;
521 unsigned NumArgs = 0;
522 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
523 Args = ParenList->getExprs();
524 NumArgs = ParenList->getNumExprs();
525 } else if (CXXConstructExpr *Construct
526 = dyn_cast<CXXConstructExpr>(Init)) {
527 Args = Construct->getArgs();
528 NumArgs = Construct->getNumArgs();
529 } else
530 SimpleInit = Init;
531
532 if (SimpleInit)
Richard Smith235341b2012-08-16 03:56:14 +0000533 SimpleInit->printPretty(Out, 0, Policy, Indentation);
Richard Smith938f40b2011-06-11 17:19:42 +0000534 else {
535 for (unsigned I = 0; I != NumArgs; ++I) {
536 if (isa<CXXDefaultArgExpr>(Args[I]))
537 break;
538
539 if (I)
540 Out << ", ";
Richard Smith235341b2012-08-16 03:56:14 +0000541 Args[I]->printPretty(Out, 0, Policy, Indentation);
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000542 }
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000543 }
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000544 }
Richard Smith938f40b2011-06-11 17:19:42 +0000545 Out << ")";
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000546 }
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000547 if (!Proto.empty())
548 Out << Proto;
Richard Smithe6560762013-02-22 05:54:51 +0000549 } else {
550 if (FT && FT->hasTrailingReturn()) {
551 Out << "auto " << Proto << " -> ";
552 Proto.clear();
553 }
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000554 AFT->getResultType().print(Out, Policy, Proto);
Richard Smithe6560762013-02-22 05:54:51 +0000555 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000556 } else {
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000557 Ty.print(Out, Policy, Proto);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000558 }
559
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000560 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000561
562 if (D->isPure())
563 Out << " = 0";
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000564 else if (D->isDeletedAsWritten())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000565 Out << " = delete";
Fariborz Jahaniande872af2012-12-05 22:53:06 +0000566 else if (D->isExplicitlyDefaulted())
567 Out << " = default";
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000568 else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) {
Douglas Gregor278f52e2009-05-30 00:08:05 +0000569 if (!D->hasPrototype() && D->getNumParams()) {
570 // This is a K&R function definition, so we need to print the
571 // parameters.
572 Out << '\n';
Richard Smith235341b2012-08-16 03:56:14 +0000573 DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000574 Indentation += Policy.Indentation;
575 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
576 Indent();
Douglas Gregor2d042f12009-05-30 05:39:39 +0000577 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor278f52e2009-05-30 00:08:05 +0000578 Out << ";\n";
579 }
580 Indentation -= Policy.Indentation;
581 } else
582 Out << ' ';
583
Richard Smith235341b2012-08-16 03:56:14 +0000584 D->getBody()->printPretty(Out, 0, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000585 Out << '\n';
586 }
587}
588
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +0000589void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
590 if (TypeSourceInfo *TSI = D->getFriendType()) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +0000591 unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
592 for (unsigned i = 0; i < NumTPLists; ++i)
593 PrintTemplateParameters(D->getFriendTypeTemplateParameterList(i));
Fariborz Jahanian7a16a022012-12-21 21:43:05 +0000594 Out << "friend ";
595 Out << " " << TSI->getType().getAsString(Policy);
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +0000596 }
597 else if (FunctionDecl *FD =
598 dyn_cast<FunctionDecl>(D->getFriendDecl())) {
599 Out << "friend ";
600 VisitFunctionDecl(FD);
601 }
602 else if (FunctionTemplateDecl *FTD =
603 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
604 Out << "friend ";
605 VisitFunctionTemplateDecl(FTD);
606 }
607 else if (ClassTemplateDecl *CTD =
608 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
609 Out << "friend ";
Fariborz Jahanian7a16a022012-12-21 21:43:05 +0000610 VisitRedeclarableTemplateDecl(CTD);
Fariborz Jahanianbfc3ef52012-12-05 00:38:44 +0000611 }
612}
613
Douglas Gregor278f52e2009-05-30 00:08:05 +0000614void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000615 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000616 Out << "mutable ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000617 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
618 Out << "__module_private__ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000619
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000620 Out << D->getType().stream(Policy, D->getName());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000621
622 if (D->isBitField()) {
623 Out << " : ";
Richard Smith235341b2012-08-16 03:56:14 +0000624 D->getBitWidth()->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000625 }
Richard Smith938f40b2011-06-11 17:19:42 +0000626
627 Expr *Init = D->getInClassInitializer();
628 if (!Policy.SuppressInitializers && Init) {
Richard Smith2b013182012-06-10 03:12:00 +0000629 if (D->getInClassInitStyle() == ICIS_ListInit)
630 Out << " ";
631 else
632 Out << " = ";
Richard Smith235341b2012-08-16 03:56:14 +0000633 Init->printPretty(Out, 0, Policy, Indentation);
Richard Smith938f40b2011-06-11 17:19:42 +0000634 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000635 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000636}
637
Chris Lattnercab02a62011-02-17 20:34:02 +0000638void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
Benjamin Kramerdb0fc512012-02-07 11:57:57 +0000639 Out << *D << ":";
Chris Lattnercab02a62011-02-17 20:34:02 +0000640}
641
642
Douglas Gregor278f52e2009-05-30 00:08:05 +0000643void DeclPrinter::VisitVarDecl(VarDecl *D) {
Peter Collingbourne32fab902011-11-08 02:52:52 +0000644 StorageClass SCAsWritten = D->getStorageClassAsWritten();
645 if (!Policy.SuppressSpecifiers && SCAsWritten != SC_None)
646 Out << VarDecl::getStorageClassSpecifierString(SCAsWritten) << " ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000647
Eli Friedman79635842009-05-30 04:20:30 +0000648 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000649 Out << "__thread ";
Douglas Gregor26701a42011-09-09 02:06:17 +0000650 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
651 Out << "__module_private__ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000652
Douglas Gregor278f52e2009-05-30 00:08:05 +0000653 QualType T = D->getType();
John McCall856bbea2009-10-23 21:48:59 +0000654 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor278f52e2009-05-30 00:08:05 +0000655 T = Parm->getOriginalType();
Argyrios Kyrtzidisa18347e2012-05-05 04:20:37 +0000656 T.print(Out, Policy, D->getName());
Richard Smith02e85f32011-04-14 22:09:26 +0000657 Expr *Init = D->getInit();
658 if (!Policy.SuppressInitializers && Init) {
Sebastian Redla9351792012-02-11 23:51:47 +0000659 bool ImplicitInit = false;
Dmitri Gribenkob614fab2013-02-03 23:02:47 +0000660 if (CXXConstructExpr *Construct =
661 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
Dmitri Gribenko6835e372013-01-27 21:28:24 +0000662 if (D->getInitStyle() == VarDecl::CallInit &&
663 !Construct->isListInitialization()) {
664 ImplicitInit = Construct->getNumArgs() == 0 ||
665 Construct->getArg(0)->isDefaultArgument();
666 }
667 }
Sebastian Redla9351792012-02-11 23:51:47 +0000668 if (!ImplicitInit) {
Eli Friedman92125c42012-10-19 20:36:44 +0000669 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redla9351792012-02-11 23:51:47 +0000670 Out << "(";
671 else if (D->getInitStyle() == VarDecl::CInit) {
672 Out << " = ";
673 }
Richard Smith235341b2012-08-16 03:56:14 +0000674 Init->printPretty(Out, 0, Policy, Indentation);
Eli Friedman92125c42012-10-19 20:36:44 +0000675 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redla9351792012-02-11 23:51:47 +0000676 Out << ")";
Ted Kremenek35869382010-09-17 23:04:38 +0000677 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000678 }
Douglas Gregor49ccfaa2011-11-19 19:22:57 +0000679 prettyPrintAttributes(D);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000680}
681
682void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
683 VisitVarDecl(D);
684}
685
686void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
687 Out << "__asm (";
Richard Smith235341b2012-08-16 03:56:14 +0000688 D->getAsmString()->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000689 Out << ")";
690}
691
Douglas Gregorba345522011-12-02 23:23:56 +0000692void DeclPrinter::VisitImportDecl(ImportDecl *D) {
Douglas Gregorc50d4922012-12-11 22:11:52 +0000693 Out << "@import " << D->getImportedModule()->getFullModuleName()
Douglas Gregorba345522011-12-02 23:23:56 +0000694 << ";\n";
695}
696
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +0000697void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
698 Out << "static_assert(";
Richard Smith235341b2012-08-16 03:56:14 +0000699 D->getAssertExpr()->printPretty(Out, 0, Policy, Indentation);
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +0000700 Out << ", ";
Richard Smith235341b2012-08-16 03:56:14 +0000701 D->getMessage()->printPretty(Out, 0, Policy, Indentation);
Peter Collingbourne7d8a0b52011-03-16 18:37:27 +0000702 Out << ")";
703}
704
Douglas Gregor278f52e2009-05-30 00:08:05 +0000705//----------------------------------------------------------------------------
706// C++ declarations
707//----------------------------------------------------------------------------
Douglas Gregor5f478b72009-05-30 06:58:37 +0000708void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregorb5263702012-05-01 01:43:38 +0000709 if (D->isInline())
710 Out << "inline ";
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000711 Out << "namespace " << *D << " {\n";
Douglas Gregor5f478b72009-05-30 06:58:37 +0000712 VisitDeclContext(D);
713 Indent() << "}";
714}
715
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000716void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
717 Out << "using namespace ";
718 if (D->getQualifier())
719 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000720 Out << *D->getNominatedNamespaceAsWritten();
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000721}
722
Douglas Gregor18231932009-05-30 06:48:27 +0000723void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000724 Out << "namespace " << *D << " = ";
Douglas Gregor18231932009-05-30 06:48:27 +0000725 if (D->getQualifier())
726 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000727 Out << *D->getAliasedNamespace();
Douglas Gregor18231932009-05-30 06:48:27 +0000728}
729
Michael Han84324352013-02-22 17:15:32 +0000730void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
731 prettyPrintAttributes(D);
Michael Han84324352013-02-22 17:15:32 +0000732}
733
Douglas Gregor5f478b72009-05-30 06:58:37 +0000734void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Douglas Gregor26701a42011-09-09 02:06:17 +0000735 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
736 Out << "__module_private__ ";
Douglas Gregor5f478b72009-05-30 06:58:37 +0000737 Out << D->getKindName();
Benjamin Kramerb11416d2010-04-17 09:33:03 +0000738 if (D->getIdentifier())
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000739 Out << ' ' << *D;
Mike Stump11289f42009-09-09 15:08:12 +0000740
John McCallf937c022011-10-07 06:10:15 +0000741 if (D->isCompleteDefinition()) {
Douglas Gregor5f478b72009-05-30 06:58:37 +0000742 // Print the base classes
743 if (D->getNumBases()) {
744 Out << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000745 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
746 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor5f478b72009-05-30 06:58:37 +0000747 if (Base != D->bases_begin())
748 Out << ", ";
749
750 if (Base->isVirtual())
751 Out << "virtual ";
752
Anders Carlsson6df9e072009-08-29 20:36:12 +0000753 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
754 if (AS != AS_none)
755 Print(AS);
Anders Carlsson601d6e42009-08-28 22:39:52 +0000756 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor5fc8c9e2011-04-27 17:07:55 +0000757
758 if (Base->isPackExpansion())
759 Out << "...";
Douglas Gregor5f478b72009-05-30 06:58:37 +0000760 }
761 }
762
763 // Print the class definition
Douglas Gregor7a1a7cb2009-05-31 07:13:39 +0000764 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor5f478b72009-05-30 06:58:37 +0000765 Out << " {\n";
766 VisitDeclContext(D);
767 Indent() << "}";
Mike Stump11289f42009-09-09 15:08:12 +0000768 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000769}
770
771void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
772 const char *l;
773 if (D->getLanguage() == LinkageSpecDecl::lang_c)
774 l = "C";
775 else {
776 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
777 "unknown language in linkage specification");
778 l = "C++";
779 }
780
781 Out << "extern \"" << l << "\" ";
782 if (D->hasBraces()) {
783 Out << "{\n";
784 VisitDeclContext(D);
785 Indent() << "}";
786 } else
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000787 Visit(*D->decls_begin());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000788}
789
Enea Zaffanellaeb22c872013-01-31 09:54:08 +0000790void DeclPrinter::PrintTemplateParameters(const TemplateParameterList *Params,
791 const TemplateArgumentList *Args) {
Richard Trieu82398f92011-07-28 00:19:05 +0000792 assert(Params);
793 assert(!Args || Params->size() == Args->size());
794
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000795 Out << "template <";
Mike Stump11289f42009-09-09 15:08:12 +0000796
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000797 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
798 if (i != 0)
799 Out << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000800
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000801 const Decl *Param = Params->getParam(i);
Mike Stump11289f42009-09-09 15:08:12 +0000802 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000803 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump11289f42009-09-09 15:08:12 +0000804
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000805 if (TTP->wasDeclaredWithTypename())
806 Out << "typename ";
807 else
808 Out << "class ";
809
Anders Carlssonfb1d7762009-06-12 22:23:22 +0000810 if (TTP->isParameterPack())
811 Out << "... ";
Mike Stump11289f42009-09-09 15:08:12 +0000812
Benjamin Kramerdb0fc512012-02-07 11:57:57 +0000813 Out << *TTP;
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000814
Richard Trieu82398f92011-07-28 00:19:05 +0000815 if (Args) {
816 Out << " = ";
817 Args->get(i).print(Policy, Out);
818 } else if (TTP->hasDefaultArgument()) {
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000819 Out << " = ";
820 Out << TTP->getDefaultArgument().getAsString(Policy);
821 };
Mike Stump11289f42009-09-09 15:08:12 +0000822 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000823 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
824 Out << NTTP->getType().getAsString(Policy);
825
Douglas Gregoreb5a39d2010-12-24 00:15:10 +0000826 if (NTTP->isParameterPack() && !isa<PackExpansionType>(NTTP->getType()))
827 Out << "...";
828
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000829 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
830 Out << ' ';
831 Out << Name->getName();
832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Richard Trieu82398f92011-07-28 00:19:05 +0000834 if (Args) {
835 Out << " = ";
836 Args->get(i).print(Policy, Out);
837 } else if (NTTP->hasDefaultArgument()) {
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000838 Out << " = ";
Richard Smith235341b2012-08-16 03:56:14 +0000839 NTTP->getDefaultArgument()->printPretty(Out, 0, Policy, Indentation);
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000840 }
Richard Smith030f4992011-04-15 13:38:57 +0000841 } else if (const TemplateTemplateParmDecl *TTPD =
842 dyn_cast<TemplateTemplateParmDecl>(Param)) {
843 VisitTemplateDecl(TTPD);
844 // FIXME: print the default argument, if present.
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000845 }
846 }
Mike Stump11289f42009-09-09 15:08:12 +0000847
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000848 Out << "> ";
Richard Trieu82398f92011-07-28 00:19:05 +0000849}
850
851void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
852 PrintTemplateParameters(D->getTemplateParameters());
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000853
Richard Smith030f4992011-04-15 13:38:57 +0000854 if (const TemplateTemplateParmDecl *TTP =
855 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorf5500772011-01-05 15:48:55 +0000856 Out << "class ";
857 if (TTP->isParameterPack())
858 Out << "...";
859 Out << D->getName();
Craig Silverstein4a5d0862010-07-09 20:25:10 +0000860 } else {
861 Visit(D->getTemplatedDecl());
862 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000863}
864
Richard Trieu82398f92011-07-28 00:19:05 +0000865void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
866 if (PrintInstantiation) {
867 TemplateParameterList *Params = D->getTemplateParameters();
868 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
869 I != E; ++I) {
870 PrintTemplateParameters(Params, (*I)->getTemplateSpecializationArgs());
871 Visit(*I);
872 }
873 }
874
875 return VisitRedeclarableTemplateDecl(D);
876}
877
878void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
879 if (PrintInstantiation) {
880 TemplateParameterList *Params = D->getTemplateParameters();
881 for (ClassTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
882 I != E; ++I) {
883 PrintTemplateParameters(Params, &(*I)->getTemplateArgs());
884 Visit(*I);
885 Out << '\n';
886 }
887 }
888
889 return VisitRedeclarableTemplateDecl(D);
890}
891
Douglas Gregor278f52e2009-05-30 00:08:05 +0000892//----------------------------------------------------------------------------
893// Objective-C declarations
894//----------------------------------------------------------------------------
895
Douglas Gregor278f52e2009-05-30 00:08:05 +0000896void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
897 if (OMD->isInstanceMethod())
Douglas Gregor36098ff2009-05-30 00:56:08 +0000898 Out << "- ";
Mike Stump11289f42009-09-09 15:08:12 +0000899 else
Douglas Gregor36098ff2009-05-30 00:56:08 +0000900 Out << "+ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000901 if (!OMD->getResultType().isNull())
Douglas Gregor5f478b72009-05-30 06:58:37 +0000902 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000903
Douglas Gregor278f52e2009-05-30 00:08:05 +0000904 std::string name = OMD->getSelector().getAsString();
905 std::string::size_type pos, lastPos = 0;
906 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
907 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump11289f42009-09-09 15:08:12 +0000908 // FIXME: selector is missing here!
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000909 pos = name.find_first_of(':', lastPos);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000910 Out << " " << name.substr(lastPos, pos - lastPos);
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000911 Out << ":(" << (*PI)->getType().getAsString(Policy) << ')' << **PI;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000912 lastPos = pos + 1;
913 }
Mike Stump11289f42009-09-09 15:08:12 +0000914
Douglas Gregor278f52e2009-05-30 00:08:05 +0000915 if (OMD->param_begin() == OMD->param_end())
916 Out << " " << name;
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregor278f52e2009-05-30 00:08:05 +0000918 if (OMD->isVariadic())
919 Out << ", ...";
Mike Stump11289f42009-09-09 15:08:12 +0000920
Fariborz Jahaniana7d76d22012-10-17 21:58:03 +0000921 if (OMD->getBody() && !Policy.TerseOutput) {
Douglas Gregor278f52e2009-05-30 00:08:05 +0000922 Out << ' ';
Richard Smith235341b2012-08-16 03:56:14 +0000923 OMD->getBody()->printPretty(Out, 0, Policy);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000924 Out << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +0000925 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000926 else if (Policy.PolishForDeclaration)
Fariborz Jahanian9b7ab872012-12-18 23:02:59 +0000927 Out << ';';
Douglas Gregor278f52e2009-05-30 00:08:05 +0000928}
929
930void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
931 std::string I = OID->getNameAsString();
932 ObjCInterfaceDecl *SID = OID->getSuperClass();
933
934 if (SID)
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000935 Out << "@implementation " << I << " : " << *SID;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000936 else
937 Out << "@implementation " << I;
Fariborz Jahanian95759ff2012-12-04 00:47:33 +0000938
939 if (OID->ivar_size() > 0) {
940 Out << "{\n";
941 Indentation += Policy.Indentation;
942 for (ObjCImplementationDecl::ivar_iterator I = OID->ivar_begin(),
943 E = OID->ivar_end(); I != E; ++I) {
944 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
945 }
946 Indentation -= Policy.Indentation;
947 Out << "}\n";
948 }
Douglas Gregor36098ff2009-05-30 00:56:08 +0000949 VisitDeclContext(OID, false);
950 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000951}
952
953void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
954 std::string I = OID->getNameAsString();
955 ObjCInterfaceDecl *SID = OID->getSuperClass();
956
Douglas Gregordc9166c2011-12-15 20:29:51 +0000957 if (!OID->isThisDeclarationADefinition()) {
958 Out << "@class " << I << ";";
959 return;
960 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000961 bool eolnOut = false;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000962 if (SID)
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000963 Out << "@interface " << I << " : " << *SID;
Douglas Gregor1c283312010-08-11 12:19:30 +0000964 else
965 Out << "@interface " << I;
Mike Stump11289f42009-09-09 15:08:12 +0000966
Douglas Gregor278f52e2009-05-30 00:08:05 +0000967 // Protocols?
968 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
969 if (!Protocols.empty()) {
970 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
971 E = Protocols.end(); I != E; ++I)
Benjamin Kramerb89514a2011-10-14 18:45:37 +0000972 Out << (I == Protocols.begin() ? '<' : ',') << **I;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000973 Out << "> ";
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor278f52e2009-05-30 00:08:05 +0000976 if (OID->ivar_size() > 0) {
Douglas Gregor36098ff2009-05-30 00:56:08 +0000977 Out << "{\n";
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000978 eolnOut = true;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000979 Indentation += Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000980 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
981 E = OID->ivar_end(); I != E; ++I) {
David Blaikie40ed2972012-06-06 20:45:41 +0000982 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000983 }
Douglas Gregor36098ff2009-05-30 00:56:08 +0000984 Indentation -= Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000985 Out << "}\n";
986 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000987 else if (SID) {
988 Out << "\n";
989 eolnOut = true;
990 }
Mike Stump11289f42009-09-09 15:08:12 +0000991
Douglas Gregor278f52e2009-05-30 00:08:05 +0000992 VisitDeclContext(OID, false);
Fariborz Jahanian0389e522012-12-19 23:36:00 +0000993 if (!eolnOut)
994 Out << ' ';
Douglas Gregor36098ff2009-05-30 00:56:08 +0000995 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000996 // FIXME: implement the rest...
997}
998
Douglas Gregor278f52e2009-05-30 00:08:05 +0000999void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
Douglas Gregorf6102672012-01-01 21:23:57 +00001000 if (!PID->isThisDeclarationADefinition()) {
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001001 Out << "@protocol " << *PID << ";\n";
Douglas Gregorf6102672012-01-01 21:23:57 +00001002 return;
1003 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001004 // Protocols?
1005 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1006 if (!Protocols.empty()) {
1007 Out << "@protocol " << *PID;
1008 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1009 E = Protocols.end(); I != E; ++I)
1010 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1011 Out << ">\n";
1012 } else
1013 Out << "@protocol " << *PID << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +00001014 VisitDeclContext(PID, false);
1015 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001016}
1017
1018void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001019 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001020
1021 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +00001022 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001023 // FIXME: implement the rest...
1024}
1025
1026void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001027 Out << "@interface " << *PID->getClassInterface() << '(' << *PID << ")\n";
Fariborz Jahanian4cf177e2012-12-04 17:20:57 +00001028 if (PID->ivar_size() > 0) {
1029 Out << "{\n";
1030 Indentation += Policy.Indentation;
1031 for (ObjCCategoryDecl::ivar_iterator I = PID->ivar_begin(),
1032 E = PID->ivar_end(); I != E; ++I) {
1033 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
1034 }
1035 Indentation -= Policy.Indentation;
1036 Out << "}\n";
1037 }
1038
Douglas Gregor278f52e2009-05-30 00:08:05 +00001039 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +00001040 Out << "@end";
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregor278f52e2009-05-30 00:08:05 +00001042 // FIXME: implement the rest...
1043}
1044
1045void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001046 Out << "@compatibility_alias " << *AID
1047 << ' ' << *AID->getClassInterface() << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001048}
1049
1050/// PrintObjCPropertyDecl - print a property declaration.
1051///
1052void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1053 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
1054 Out << "@required\n";
1055 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1056 Out << "@optional\n";
Mike Stump11289f42009-09-09 15:08:12 +00001057
Douglas Gregor278f52e2009-05-30 00:08:05 +00001058 Out << "@property";
1059 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
1060 bool first = true;
1061 Out << " (";
Mike Stump11289f42009-09-09 15:08:12 +00001062 if (PDecl->getPropertyAttributes() &
Douglas Gregor278f52e2009-05-30 00:08:05 +00001063 ObjCPropertyDecl::OBJC_PR_readonly) {
1064 Out << (first ? ' ' : ',') << "readonly";
1065 first = false;
Ted Kremenek897af912011-08-17 21:09:35 +00001066 }
Mike Stump11289f42009-09-09 15:08:12 +00001067
Ted Kremenek897af912011-08-17 21:09:35 +00001068 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
1069 Out << (first ? ' ' : ',') << "getter = "
1070 << PDecl->getGetterName().getAsString();
1071 first = false;
1072 }
1073 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
1074 Out << (first ? ' ' : ',') << "setter = "
1075 << PDecl->getSetterName().getAsString();
1076 first = false;
1077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Ted Kremenek897af912011-08-17 21:09:35 +00001079 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
1080 Out << (first ? ' ' : ',') << "assign";
1081 first = false;
1082 }
Mike Stump11289f42009-09-09 15:08:12 +00001083
Ted Kremenek897af912011-08-17 21:09:35 +00001084 if (PDecl->getPropertyAttributes() &
1085 ObjCPropertyDecl::OBJC_PR_readwrite) {
1086 Out << (first ? ' ' : ',') << "readwrite";
1087 first = false;
1088 }
Mike Stump11289f42009-09-09 15:08:12 +00001089
Ted Kremenek897af912011-08-17 21:09:35 +00001090 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
1091 Out << (first ? ' ' : ',') << "retain";
1092 first = false;
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Ted Kremenek897af912011-08-17 21:09:35 +00001095 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) {
1096 Out << (first ? ' ' : ',') << "strong";
1097 first = false;
1098 }
John McCall31168b02011-06-15 23:02:42 +00001099
Ted Kremenek897af912011-08-17 21:09:35 +00001100 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
1101 Out << (first ? ' ' : ',') << "copy";
1102 first = false;
1103 }
Mike Stump11289f42009-09-09 15:08:12 +00001104
Ted Kremenek897af912011-08-17 21:09:35 +00001105 if (PDecl->getPropertyAttributes() &
1106 ObjCPropertyDecl::OBJC_PR_nonatomic) {
1107 Out << (first ? ' ' : ',') << "nonatomic";
1108 first = false;
1109 }
1110 if (PDecl->getPropertyAttributes() &
1111 ObjCPropertyDecl::OBJC_PR_atomic) {
1112 Out << (first ? ' ' : ',') << "atomic";
1113 first = false;
1114 }
1115
1116 (void) first; // Silence dead store warning due to idiomatic code.
1117 Out << " )";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001118 }
Fariborz Jahanian0389e522012-12-19 23:36:00 +00001119 Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << *PDecl;
1120 if (Policy.PolishForDeclaration)
1121 Out << ';';
Douglas Gregor278f52e2009-05-30 00:08:05 +00001122}
1123
1124void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1125 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor36098ff2009-05-30 00:56:08 +00001126 Out << "@synthesize ";
Douglas Gregor278f52e2009-05-30 00:08:05 +00001127 else
Douglas Gregor36098ff2009-05-30 00:56:08 +00001128 Out << "@dynamic ";
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001129 Out << *PID->getPropertyDecl();
Douglas Gregor278f52e2009-05-30 00:08:05 +00001130 if (PID->getPropertyIvarDecl())
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001131 Out << '=' << *PID->getPropertyIvarDecl();
Douglas Gregor278f52e2009-05-30 00:08:05 +00001132}
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001133
1134void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1135 Out << "using ";
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001136 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001137 Out << *D;
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001138}
1139
John McCalle61f2ba2009-11-18 02:36:19 +00001140void
1141DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1142 Out << "using typename ";
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001143 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001144 Out << D->getDeclName();
John McCalle61f2ba2009-11-18 02:36:19 +00001145}
1146
1147void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001148 Out << "using ";
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001149 D->getQualifier()->print(Out, Policy);
Fariborz Jahanian3ec39212012-12-06 00:09:40 +00001150 Out << D->getName();
Anders Carlssondf5a1c82009-08-28 19:16:39 +00001151}
John McCall3f746822009-11-17 05:59:44 +00001152
1153void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1154 // ignore
1155}
Alexey Bataeva769e072013-03-22 06:34:35 +00001156
1157void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1158 Out << "#pragma omp threadprivate";
1159 if (!D->varlist_empty()) {
1160 for (OMPThreadPrivateDecl::varlist_iterator I = D->varlist_begin(),
1161 E = D->varlist_end();
1162 I != E; ++I) {
1163 Out << (I == D->varlist_begin() ? '(' : ',')
1164 << *cast<NamedDecl>((*I)->getDecl());
1165 }
1166 Out << ")";
1167 }
1168}
1169