blob: 6057f601362029394d9816c12fb0ad5c94bd0d55 [file] [log] [blame]
Douglas Gregor4fe0c8e2009-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 Kornienkod538ed92012-12-20 02:09:13 +000010// This file implements the Decl::print method, which pretty prints the
Douglas Gregor4fe0c8e2009-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 Kramer2fa67ef2012-12-01 15:09:41 +000015#include "clang/AST/Attr.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000016#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclObjC.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000019#include "clang/AST/DeclVisitor.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000020#include "clang/AST/Expr.h"
Douglas Gregor9db7dbb2010-01-31 09:12:51 +000021#include "clang/AST/ExprCXX.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000022#include "clang/AST/PrettyPrinter.h"
Douglas Gregor15de72c2011-12-02 23:23:56 +000023#include "clang/Basic/Module.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000024#include "llvm/Support/raw_ostream.h"
25using namespace clang;
26
27namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000028 class DeclPrinter : public DeclVisitor<DeclPrinter> {
Chris Lattner5f9e2722011-07-23 10:55:15 +000029 raw_ostream &Out;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000030 PrintingPolicy Policy;
31 unsigned Indentation;
Richard Trieu5cb3d692011-07-28 00:19:05 +000032 bool PrintInstantiation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000033
Chris Lattner5f9e2722011-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 Gregor4fe0c8e2009-05-30 00:08:05 +000037
Anders Carlsson0d592922009-08-28 22:39:52 +000038 void Print(AccessSpecifier AS);
Mike Stump1eb44332009-09-09 15:08:12 +000039
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000040 public:
Richard Smithd1420c62012-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 Trieu5cb3d692011-07-28 00:19:05 +000044 PrintInstantiation(PrintInstantiation) { }
Douglas Gregor4fe0c8e2009-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 Smith162e1c12011-04-15 14:24:37 +000050 void VisitTypeAliasDecl(TypeAliasDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000051 void VisitEnumDecl(EnumDecl *D);
52 void VisitRecordDecl(RecordDecl *D);
53 void VisitEnumConstantDecl(EnumConstantDecl *D);
54 void VisitFunctionDecl(FunctionDecl *D);
Fariborz Jahanian8920eb72012-12-05 00:38:44 +000055 void VisitFriendDecl(FriendDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000056 void VisitFieldDecl(FieldDecl *D);
57 void VisitVarDecl(VarDecl *D);
Chris Lattner57ad3782011-02-17 20:34:02 +000058 void VisitLabelDecl(LabelDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000059 void VisitParmVarDecl(ParmVarDecl *D);
60 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregor15de72c2011-12-02 23:23:56 +000061 void VisitImportDecl(ImportDecl *D);
Peter Collingbourne28ac87e2011-03-16 18:37:27 +000062 void VisitStaticAssertDecl(StaticAssertDecl *D);
Douglas Gregor59e63572009-05-30 06:58:37 +000063 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor8419fa32009-05-30 06:31:56 +000064 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor6c9c9402009-05-30 06:48:27 +000065 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor59e63572009-05-30 06:58:37 +000066 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000067 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith98a57862011-04-15 13:38:57 +000068 void VisitTemplateDecl(const TemplateDecl *D);
Richard Trieu5cb3d692011-07-28 00:19:05 +000069 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
70 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000071 void VisitObjCMethodDecl(ObjCMethodDecl *D);
72 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
73 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000074 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
75 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
76 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
77 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
78 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
79 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
John McCall7ba107a2009-11-18 02:36:19 +000080 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
81 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssonf53eaa52009-08-28 19:16:39 +000082 void VisitUsingDecl(UsingDecl *D);
John McCall9488ea12009-11-17 05:59:44 +000083 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Trieu5cb3d692011-07-28 00:19:05 +000084
85 void PrintTemplateParameters(const TemplateParameterList *Params,
86 const TemplateArgumentList *Args);
Douglas Gregor1bea8802011-11-19 19:22:57 +000087 void prettyPrintAttributes(Decl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000088 };
89}
90
Richard Trieu5cb3d692011-07-28 00:19:05 +000091void Decl::print(raw_ostream &Out, unsigned Indentation,
92 bool PrintInstantiation) const {
Douglas Gregor30c42402011-09-27 22:38:19 +000093 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000094}
95
Chris Lattner5f9e2722011-07-23 10:55:15 +000096void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
Richard Trieu5cb3d692011-07-28 00:19:05 +000097 unsigned Indentation, bool PrintInstantiation) const {
Richard Smithd1420c62012-08-16 03:56:14 +000098 DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation);
Anders Carlssonf88df862009-09-26 21:58:53 +000099 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000100}
101
Eli Friedman42f42c02009-05-30 04:20:30 +0000102static QualType GetBaseType(QualType T) {
103 // FIXME: This should be on the Type class!
104 QualType BaseType = T;
105 while (!BaseType->isSpecifierType()) {
106 if (isa<TypedefType>(BaseType))
107 break;
Ted Kremenek6217b802009-07-29 21:53:49 +0000108 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman42f42c02009-05-30 04:20:30 +0000109 BaseType = PTy->getPointeeType();
Ted Kremenek41c1f212012-10-11 20:58:14 +0000110 else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
111 BaseType = BPy->getPointeeType();
Eli Friedman42f42c02009-05-30 04:20:30 +0000112 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
113 BaseType = ATy->getElementType();
John McCall183700f2009-09-21 23:43:11 +0000114 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Eli Friedman42f42c02009-05-30 04:20:30 +0000115 BaseType = FTy->getResultType();
John McCall183700f2009-09-21 23:43:11 +0000116 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor5068ab62009-07-01 23:58:14 +0000117 BaseType = VTy->getElementType();
Eli Friedman15631b42012-08-08 03:47:15 +0000118 else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
119 BaseType = RTy->getPointeeType();
Eli Friedman42f42c02009-05-30 04:20:30 +0000120 else
David Blaikieb219cfc2011-09-23 05:06:16 +0000121 llvm_unreachable("Unknown declarator!");
Eli Friedman42f42c02009-05-30 04:20:30 +0000122 }
123 return BaseType;
124}
125
126static QualType getDeclType(Decl* D) {
Richard Smith162e1c12011-04-15 14:24:37 +0000127 if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
Eli Friedman42f42c02009-05-30 04:20:30 +0000128 return TDD->getUnderlyingType();
129 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
130 return VD->getType();
131 return QualType();
132}
133
134void Decl::printGroup(Decl** Begin, unsigned NumDecls,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000135 raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman42f42c02009-05-30 04:20:30 +0000136 unsigned Indentation) {
137 if (NumDecls == 1) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000138 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000139 return;
140 }
141
142 Decl** End = Begin + NumDecls;
143 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
144 if (TD)
145 ++Begin;
146
147 PrintingPolicy SubPolicy(Policy);
John McCall5e1cdac2011-10-07 06:10:15 +0000148 if (TD && TD->isCompleteDefinition()) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000149 TD->print(Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000150 Out << " ";
151 SubPolicy.SuppressTag = true;
152 }
153
154 bool isFirst = true;
155 for ( ; Begin != End; ++Begin) {
156 if (isFirst) {
157 SubPolicy.SuppressSpecifiers = false;
158 isFirst = false;
159 } else {
160 if (!isFirst) Out << ", ";
161 SubPolicy.SuppressSpecifiers = true;
162 }
163
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000164 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000165 }
166}
167
Anders Carlsson84834432009-12-14 00:51:04 +0000168void DeclContext::dumpDeclContext() const {
Anders Carlsson2b7d8dd2009-12-09 17:27:46 +0000169 // Get the translation unit
170 const DeclContext *DC = this;
171 while (!DC->isTranslationUnit())
172 DC = DC->getParent();
173
174 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smithd1420c62012-08-16 03:56:14 +0000175 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0);
Anders Carlsson2b7d8dd2009-12-09 17:27:46 +0000176 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
177}
178
Chris Lattner5f9e2722011-07-23 10:55:15 +0000179raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
Daniel Dunbar512ce602009-11-21 09:12:06 +0000180 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000181 Out << " ";
182 return Out;
183}
184
Douglas Gregor1bea8802011-11-19 19:22:57 +0000185void DeclPrinter::prettyPrintAttributes(Decl *D) {
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000186 if (Policy.PolishForDeclaration)
Fariborz Jahanian1bfb00d2012-10-17 21:58:03 +0000187 return;
188
Douglas Gregor1bea8802011-11-19 19:22:57 +0000189 if (D->hasAttrs()) {
190 AttrVec &Attrs = D->getAttrs();
191 for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) {
Richard Smith0dae7292012-08-16 02:43:29 +0000192 Attr *A = *i;
193 A->printPretty(Out, Policy);
Douglas Gregor1bea8802011-11-19 19:22:57 +0000194 }
195 }
196}
197
Chris Lattner5f9e2722011-07-23 10:55:15 +0000198void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000199 this->Indent();
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000200 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000201 Out << ";\n";
202 Decls.clear();
203
204}
205
Anders Carlsson0d592922009-08-28 22:39:52 +0000206void DeclPrinter::Print(AccessSpecifier AS) {
207 switch(AS) {
David Blaikieeb2d1f12011-09-23 20:26:49 +0000208 case AS_none: llvm_unreachable("No access specifier!");
Anders Carlsson0d592922009-08-28 22:39:52 +0000209 case AS_public: Out << "public"; break;
210 case AS_protected: Out << "protected"; break;
Abramo Bagnara6206d532010-06-05 05:09:32 +0000211 case AS_private: Out << "private"; break;
Anders Carlsson0d592922009-08-28 22:39:52 +0000212 }
213}
214
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000215//----------------------------------------------------------------------------
216// Common C declarations
217//----------------------------------------------------------------------------
218
219void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
Dmitri Gribenkod1fc82e2012-08-21 17:36:32 +0000220 if (Policy.TerseOutput)
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000221 return;
222
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000223 if (Indent)
224 Indentation += Policy.Indentation;
225
Chris Lattner5f9e2722011-07-23 10:55:15 +0000226 SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000227 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000228 D != DEnd; ++D) {
Ted Kremenek2d6c9062010-07-30 00:47:46 +0000229
230 // Don't print ObjCIvarDecls, as they are printed when visiting the
231 // containing ObjCInterfaceDecl.
232 if (isa<ObjCIvarDecl>(*D))
233 continue;
234
Alexander Kornienkod538ed92012-12-20 02:09:13 +0000235 // Skip over implicit declarations in pretty-printing mode.
236 if (D->isImplicit())
237 continue;
238
239 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
240 // of __builtin_va_list or __[u]int128_t. There should be some other way
241 // to check that.
242 if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) {
243 if (IdentifierInfo *II = ND->getIdentifier()) {
244 if (II->isStr("__builtin_va_list") ||
245 II->isStr("__int128_t") || II->isStr("__uint128_t"))
246 continue;
Argyrios Kyrtzidis2574f6f2010-06-17 10:52:11 +0000247 }
Eli Friedman48d14a22009-05-30 05:03:24 +0000248 }
249
Eli Friedman42f42c02009-05-30 04:20:30 +0000250 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
251 // forced to merge the declarations because there's no other way to
252 // refer to the struct in question. This limited merging is safe without
253 // a bunch of other checks because it only merges declarations directly
254 // referring to the tag, not typedefs.
255 //
256 // Check whether the current declaration should be grouped with a previous
257 // unnamed struct.
258 QualType CurDeclType = getDeclType(*D);
259 if (!Decls.empty() && !CurDeclType.isNull()) {
260 QualType BaseType = GetBaseType(CurDeclType);
261 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
262 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
263 Decls.push_back(*D);
264 continue;
265 }
266 }
267
268 // If we have a merged group waiting to be handled, handle it now.
269 if (!Decls.empty())
270 ProcessDeclGroup(Decls);
271
272 // If the current declaration is an unnamed tag type, save it
273 // so we can merge it with the subsequent declaration(s) using it.
274 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
275 Decls.push_back(*D);
276 continue;
277 }
Abramo Bagnara6206d532010-06-05 05:09:32 +0000278
279 if (isa<AccessSpecDecl>(*D)) {
280 Indentation -= Policy.Indentation;
281 this->Indent();
282 Print(D->getAccess());
283 Out << ":\n";
284 Indentation += Policy.Indentation;
285 continue;
286 }
287
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000288 this->Indent();
289 Visit(*D);
Mike Stump1eb44332009-09-09 15:08:12 +0000290
291 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000292 const char *Terminator = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000293 if (isa<FunctionDecl>(*D) &&
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000294 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
295 Terminator = 0;
Douglas Gregor64f65002009-05-30 00:56:08 +0000296 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
297 Terminator = 0;
298 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump1eb44332009-09-09 15:08:12 +0000299 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor64f65002009-05-30 00:56:08 +0000300 isa<ObjCInterfaceDecl>(*D) ||
301 isa<ObjCProtocolDecl>(*D) ||
302 isa<ObjCCategoryImplDecl>(*D) ||
303 isa<ObjCCategoryDecl>(*D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000304 Terminator = 0;
305 else if (isa<EnumConstantDecl>(*D)) {
306 DeclContext::decl_iterator Next = D;
307 ++Next;
308 if (Next != DEnd)
309 Terminator = ",";
310 } else
311 Terminator = ";";
312
313 if (Terminator)
314 Out << Terminator;
315 Out << "\n";
316 }
317
Eli Friedman42f42c02009-05-30 04:20:30 +0000318 if (!Decls.empty())
319 ProcessDeclGroup(Decls);
320
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000321 if (Indent)
322 Indentation -= Policy.Indentation;
323}
324
325void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
326 VisitDeclContext(D, false);
327}
328
329void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000330 if (!Policy.SuppressSpecifiers) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000331 Out << "typedef ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000332
333 if (D->isModulePrivate())
334 Out << "__module_private__ ";
335 }
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000336 D->getUnderlyingType().print(Out, Policy, D->getName());
Douglas Gregor1bea8802011-11-19 19:22:57 +0000337 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000338}
339
Richard Smith162e1c12011-04-15 14:24:37 +0000340void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000341 Out << "using " << *D << " = " << D->getUnderlyingType().getAsString(Policy);
Richard Smith162e1c12011-04-15 14:24:37 +0000342}
343
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000344void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000345 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
346 Out << "__module_private__ ";
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000347 Out << "enum ";
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000348 if (D->isScoped()) {
349 if (D->isScopedUsingClassTag())
350 Out << "class ";
351 else
352 Out << "struct ";
353 }
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000354 Out << *D;
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000355
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000356 if (D->isFixed())
357 Out << " : " << D->getIntegerType().stream(Policy);
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000358
John McCall5e1cdac2011-10-07 06:10:15 +0000359 if (D->isCompleteDefinition()) {
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000360 Out << " {\n";
361 VisitDeclContext(D);
362 Indent() << "}";
363 }
Douglas Gregor1bea8802011-11-19 19:22:57 +0000364 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000365}
366
367void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000368 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
369 Out << "__module_private__ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000370 Out << D->getKindName();
Benjamin Kramer900fc632010-04-17 09:33:03 +0000371 if (D->getIdentifier())
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000372 Out << ' ' << *D;
Mike Stump1eb44332009-09-09 15:08:12 +0000373
John McCall5e1cdac2011-10-07 06:10:15 +0000374 if (D->isCompleteDefinition()) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000375 Out << " {\n";
376 VisitDeclContext(D);
377 Indent() << "}";
378 }
379}
380
381void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000382 Out << *D;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000383 if (Expr *Init = D->getInitExpr()) {
384 Out << " = ";
Richard Smithd1420c62012-08-16 03:56:14 +0000385 Init->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000386 }
387}
388
Mike Stump1eb44332009-09-09 15:08:12 +0000389void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Fariborz Jahanian65bcdab2012-12-05 22:19:06 +0000390 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
Eli Friedman42f42c02009-05-30 04:20:30 +0000391 if (!Policy.SuppressSpecifiers) {
Peter Collingbourne13330c42011-11-08 02:52:52 +0000392 switch (D->getStorageClassAsWritten()) {
John McCalld931b082010-08-26 03:08:43 +0000393 case SC_None: break;
394 case SC_Extern: Out << "extern "; break;
395 case SC_Static: Out << "static "; break;
396 case SC_PrivateExtern: Out << "__private_extern__ "; break;
Peter Collingbourne8c25fc52011-09-19 21:14:35 +0000397 case SC_Auto: case SC_Register: case SC_OpenCLWorkGroupLocal:
398 llvm_unreachable("invalid for functions");
Eli Friedman42f42c02009-05-30 04:20:30 +0000399 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000400
Douglas Gregor8d267c52011-09-09 02:06:17 +0000401 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman42f42c02009-05-30 04:20:30 +0000402 if (D->isVirtualAsWritten()) Out << "virtual ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000403 if (D->isModulePrivate()) Out << "__module_private__ ";
Fariborz Jahanian65bcdab2012-12-05 22:19:06 +0000404 if (CDecl && CDecl->isExplicitSpecified())
405 Out << "explicit ";
Eli Friedman42f42c02009-05-30 04:20:30 +0000406 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000407
Douglas Gregor6620a622009-05-30 05:39:39 +0000408 PrintingPolicy SubPolicy(Policy);
409 SubPolicy.SuppressSpecifiers = false;
Abramo Bagnara25777432010-08-11 22:01:17 +0000410 std::string Proto = D->getNameInfo().getAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000411
Abramo Bagnara723df242010-12-14 22:11:44 +0000412 QualType Ty = D->getType();
John McCallf4c73712011-01-19 06:33:43 +0000413 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
Abramo Bagnara723df242010-12-14 22:11:44 +0000414 Proto = '(' + Proto + ')';
415 Ty = PT->getInnerType();
416 }
417
418 if (isa<FunctionType>(Ty)) {
419 const FunctionType *AFT = Ty->getAs<FunctionType>();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000420 const FunctionProtoType *FT = 0;
421 if (D->hasWrittenPrototype())
422 FT = dyn_cast<FunctionProtoType>(AFT);
423
424 Proto += "(";
425 if (FT) {
426 llvm::raw_string_ostream POut(Proto);
Richard Smithd1420c62012-08-16 03:56:14 +0000427 DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000428 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
429 if (i) POut << ", ";
430 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
431 }
Mike Stump1eb44332009-09-09 15:08:12 +0000432
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000433 if (FT->isVariadic()) {
434 if (D->getNumParams()) POut << ", ";
435 POut << "...";
436 }
Sean Hunt10620eb2011-05-06 20:44:56 +0000437 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000438 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
439 if (i)
440 Proto += ", ";
441 Proto += D->getParamDecl(i)->getNameAsString();
442 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000443 }
444
445 Proto += ")";
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000446
David Blaikie4ef832f2012-08-10 00:55:35 +0000447 if (FT) {
448 if (FT->isConst())
Douglas Gregorb95cfe42010-11-19 18:44:34 +0000449 Proto += " const";
David Blaikie4ef832f2012-08-10 00:55:35 +0000450 if (FT->isVolatile())
Douglas Gregorb95cfe42010-11-19 18:44:34 +0000451 Proto += " volatile";
David Blaikie4ef832f2012-08-10 00:55:35 +0000452 if (FT->isRestrict())
Douglas Gregorb95cfe42010-11-19 18:44:34 +0000453 Proto += " restrict";
454 }
Sebastian Redl60618fa2011-03-12 11:50:43 +0000455
456 if (FT && FT->hasDynamicExceptionSpec()) {
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000457 Proto += " throw(";
Sebastian Redl60618fa2011-03-12 11:50:43 +0000458 if (FT->getExceptionSpecType() == EST_MSAny)
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000459 Proto += "...";
460 else
461 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
462 if (I)
463 Proto += ", ";
Sebastian Redl60618fa2011-03-12 11:50:43 +0000464
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +0000465 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000466 }
467 Proto += ")";
Sebastian Redl60618fa2011-03-12 11:50:43 +0000468 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
469 Proto += " noexcept";
470 if (FT->getExceptionSpecType() == EST_ComputedNoexcept) {
471 Proto += "(";
472 llvm::raw_string_ostream EOut(Proto);
Richard Smithd1420c62012-08-16 03:56:14 +0000473 FT->getNoexceptExpr()->printPretty(EOut, 0, SubPolicy,
Sebastian Redl60618fa2011-03-12 11:50:43 +0000474 Indentation);
475 EOut.flush();
476 Proto += EOut.str();
477 Proto += ")";
478 }
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000479 }
480
Fariborz Jahanian65bcdab2012-12-05 22:19:06 +0000481 if (CDecl) {
Richard Smith7a614d82011-06-11 17:19:42 +0000482 bool HasInitializerList = false;
483 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
484 E = CDecl->init_end();
485 B != E; ++B) {
486 CXXCtorInitializer * BMInitializer = (*B);
487 if (BMInitializer->isInClassMemberInitializer())
488 continue;
489
490 if (!HasInitializerList) {
491 Proto += " : ";
492 Out << Proto;
493 Proto.clear();
494 HasInitializerList = true;
495 } else
496 Out << ", ";
497
498 if (BMInitializer->isAnyMemberInitializer()) {
499 FieldDecl *FD = BMInitializer->getAnyMember();
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000500 Out << *FD;
Richard Smith7a614d82011-06-11 17:19:42 +0000501 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000502 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
Richard Smith7a614d82011-06-11 17:19:42 +0000503 }
504
505 Out << "(";
506 if (!BMInitializer->getInit()) {
507 // Nothing to print
508 } else {
509 Expr *Init = BMInitializer->getInit();
510 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
511 Init = Tmp->getSubExpr();
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000512
Richard Smith7a614d82011-06-11 17:19:42 +0000513 Init = Init->IgnoreParens();
514
515 Expr *SimpleInit = 0;
516 Expr **Args = 0;
517 unsigned NumArgs = 0;
518 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
519 Args = ParenList->getExprs();
520 NumArgs = ParenList->getNumExprs();
521 } else if (CXXConstructExpr *Construct
522 = dyn_cast<CXXConstructExpr>(Init)) {
523 Args = Construct->getArgs();
524 NumArgs = Construct->getNumArgs();
525 } else
526 SimpleInit = Init;
527
528 if (SimpleInit)
Richard Smithd1420c62012-08-16 03:56:14 +0000529 SimpleInit->printPretty(Out, 0, Policy, Indentation);
Richard Smith7a614d82011-06-11 17:19:42 +0000530 else {
531 for (unsigned I = 0; I != NumArgs; ++I) {
532 if (isa<CXXDefaultArgExpr>(Args[I]))
533 break;
534
535 if (I)
536 Out << ", ";
Richard Smithd1420c62012-08-16 03:56:14 +0000537 Args[I]->printPretty(Out, 0, Policy, Indentation);
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000538 }
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000539 }
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000540 }
Richard Smith7a614d82011-06-11 17:19:42 +0000541 Out << ")";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000542 }
Fariborz Jahanian02a2e5a2012-12-05 19:54:11 +0000543 if (!Proto.empty())
544 Out << Proto;
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000545 }
546 else
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000547 AFT->getResultType().print(Out, Policy, Proto);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000548 } else {
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000549 Ty.print(Out, Policy, Proto);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000550 }
551
Douglas Gregor1bea8802011-11-19 19:22:57 +0000552 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000553
554 if (D->isPure())
555 Out << " = 0";
Sean Hunt10620eb2011-05-06 20:44:56 +0000556 else if (D->isDeletedAsWritten())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000557 Out << " = delete";
Fariborz Jahanianddb29682012-12-05 22:53:06 +0000558 else if (D->isExplicitlyDefaulted())
559 Out << " = default";
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000560 else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000561 if (!D->hasPrototype() && D->getNumParams()) {
562 // This is a K&R function definition, so we need to print the
563 // parameters.
564 Out << '\n';
Richard Smithd1420c62012-08-16 03:56:14 +0000565 DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000566 Indentation += Policy.Indentation;
567 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
568 Indent();
Douglas Gregor6620a622009-05-30 05:39:39 +0000569 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000570 Out << ";\n";
571 }
572 Indentation -= Policy.Indentation;
573 } else
574 Out << ' ';
575
Richard Smithd1420c62012-08-16 03:56:14 +0000576 D->getBody()->printPretty(Out, 0, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000577 Out << '\n';
578 }
579}
580
Fariborz Jahanian8920eb72012-12-05 00:38:44 +0000581void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
582 if (TypeSourceInfo *TSI = D->getFriendType()) {
Fariborz Jahaniand4ae6532012-12-21 21:43:05 +0000583 Out << "friend ";
584 Out << " " << TSI->getType().getAsString(Policy);
Fariborz Jahanian8920eb72012-12-05 00:38:44 +0000585 }
586 else if (FunctionDecl *FD =
587 dyn_cast<FunctionDecl>(D->getFriendDecl())) {
588 Out << "friend ";
589 VisitFunctionDecl(FD);
590 }
591 else if (FunctionTemplateDecl *FTD =
592 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
593 Out << "friend ";
594 VisitFunctionTemplateDecl(FTD);
595 }
596 else if (ClassTemplateDecl *CTD =
597 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
598 Out << "friend ";
Fariborz Jahaniand4ae6532012-12-21 21:43:05 +0000599 VisitRedeclarableTemplateDecl(CTD);
Fariborz Jahanian8920eb72012-12-05 00:38:44 +0000600 }
601}
602
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000603void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000604 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000605 Out << "mutable ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000606 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
607 Out << "__module_private__ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000608
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000609 Out << D->getType().stream(Policy, D->getName());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000610
611 if (D->isBitField()) {
612 Out << " : ";
Richard Smithd1420c62012-08-16 03:56:14 +0000613 D->getBitWidth()->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000614 }
Richard Smith7a614d82011-06-11 17:19:42 +0000615
616 Expr *Init = D->getInClassInitializer();
617 if (!Policy.SuppressInitializers && Init) {
Richard Smithca523302012-06-10 03:12:00 +0000618 if (D->getInClassInitStyle() == ICIS_ListInit)
619 Out << " ";
620 else
621 Out << " = ";
Richard Smithd1420c62012-08-16 03:56:14 +0000622 Init->printPretty(Out, 0, Policy, Indentation);
Richard Smith7a614d82011-06-11 17:19:42 +0000623 }
Douglas Gregor1bea8802011-11-19 19:22:57 +0000624 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000625}
626
Chris Lattner57ad3782011-02-17 20:34:02 +0000627void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000628 Out << *D << ":";
Chris Lattner57ad3782011-02-17 20:34:02 +0000629}
630
631
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000632void DeclPrinter::VisitVarDecl(VarDecl *D) {
Peter Collingbourne13330c42011-11-08 02:52:52 +0000633 StorageClass SCAsWritten = D->getStorageClassAsWritten();
634 if (!Policy.SuppressSpecifiers && SCAsWritten != SC_None)
635 Out << VarDecl::getStorageClassSpecifierString(SCAsWritten) << " ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000636
Eli Friedman42f42c02009-05-30 04:20:30 +0000637 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000638 Out << "__thread ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000639 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
640 Out << "__module_private__ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000641
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000642 QualType T = D->getType();
John McCall58e46772009-10-23 21:48:59 +0000643 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000644 T = Parm->getOriginalType();
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000645 T.print(Out, Policy, D->getName());
Richard Smithad762fc2011-04-14 22:09:26 +0000646 Expr *Init = D->getInit();
647 if (!Policy.SuppressInitializers && Init) {
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000648 bool ImplicitInit = false;
Dmitri Gribenko5250e2b2013-01-27 21:28:24 +0000649 if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init)) {
650 if (D->getInitStyle() == VarDecl::CallInit &&
651 !Construct->isListInitialization()) {
652 ImplicitInit = Construct->getNumArgs() == 0 ||
653 Construct->getArg(0)->isDefaultArgument();
654 }
655 }
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000656 if (!ImplicitInit) {
Eli Friedmane1aebe12012-10-19 20:36:44 +0000657 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000658 Out << "(";
659 else if (D->getInitStyle() == VarDecl::CInit) {
660 Out << " = ";
661 }
Richard Smithd1420c62012-08-16 03:56:14 +0000662 Init->printPretty(Out, 0, Policy, Indentation);
Eli Friedmane1aebe12012-10-19 20:36:44 +0000663 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000664 Out << ")";
Ted Kremenekc57d6552010-09-17 23:04:38 +0000665 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000666 }
Douglas Gregor1bea8802011-11-19 19:22:57 +0000667 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000668}
669
670void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
671 VisitVarDecl(D);
672}
673
674void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
675 Out << "__asm (";
Richard Smithd1420c62012-08-16 03:56:14 +0000676 D->getAsmString()->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000677 Out << ")";
678}
679
Douglas Gregor15de72c2011-12-02 23:23:56 +0000680void DeclPrinter::VisitImportDecl(ImportDecl *D) {
Douglas Gregor1b257af2012-12-11 22:11:52 +0000681 Out << "@import " << D->getImportedModule()->getFullModuleName()
Douglas Gregor15de72c2011-12-02 23:23:56 +0000682 << ";\n";
683}
684
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000685void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
686 Out << "static_assert(";
Richard Smithd1420c62012-08-16 03:56:14 +0000687 D->getAssertExpr()->printPretty(Out, 0, Policy, Indentation);
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000688 Out << ", ";
Richard Smithd1420c62012-08-16 03:56:14 +0000689 D->getMessage()->printPretty(Out, 0, Policy, Indentation);
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000690 Out << ")";
691}
692
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000693//----------------------------------------------------------------------------
694// C++ declarations
695//----------------------------------------------------------------------------
Douglas Gregor59e63572009-05-30 06:58:37 +0000696void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregorc30636a2012-05-01 01:43:38 +0000697 if (D->isInline())
698 Out << "inline ";
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000699 Out << "namespace " << *D << " {\n";
Douglas Gregor59e63572009-05-30 06:58:37 +0000700 VisitDeclContext(D);
701 Indent() << "}";
702}
703
Douglas Gregor8419fa32009-05-30 06:31:56 +0000704void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
705 Out << "using namespace ";
706 if (D->getQualifier())
707 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000708 Out << *D->getNominatedNamespaceAsWritten();
Douglas Gregor8419fa32009-05-30 06:31:56 +0000709}
710
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000711void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000712 Out << "namespace " << *D << " = ";
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000713 if (D->getQualifier())
714 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000715 Out << *D->getAliasedNamespace();
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000716}
717
Douglas Gregor59e63572009-05-30 06:58:37 +0000718void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000719 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
720 Out << "__module_private__ ";
Douglas Gregor59e63572009-05-30 06:58:37 +0000721 Out << D->getKindName();
Benjamin Kramer900fc632010-04-17 09:33:03 +0000722 if (D->getIdentifier())
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000723 Out << ' ' << *D;
Mike Stump1eb44332009-09-09 15:08:12 +0000724
John McCall5e1cdac2011-10-07 06:10:15 +0000725 if (D->isCompleteDefinition()) {
Douglas Gregor59e63572009-05-30 06:58:37 +0000726 // Print the base classes
727 if (D->getNumBases()) {
728 Out << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000729 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
730 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor59e63572009-05-30 06:58:37 +0000731 if (Base != D->bases_begin())
732 Out << ", ";
733
734 if (Base->isVirtual())
735 Out << "virtual ";
736
Anders Carlsson018e9fe2009-08-29 20:36:12 +0000737 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
738 if (AS != AS_none)
739 Print(AS);
Anders Carlsson0d592922009-08-28 22:39:52 +0000740 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor34a99e72011-04-27 17:07:55 +0000741
742 if (Base->isPackExpansion())
743 Out << "...";
Douglas Gregor59e63572009-05-30 06:58:37 +0000744 }
745 }
746
747 // Print the class definition
Douglas Gregorf757ae72009-05-31 07:13:39 +0000748 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor59e63572009-05-30 06:58:37 +0000749 Out << " {\n";
750 VisitDeclContext(D);
751 Indent() << "}";
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000753}
754
755void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
756 const char *l;
757 if (D->getLanguage() == LinkageSpecDecl::lang_c)
758 l = "C";
759 else {
760 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
761 "unknown language in linkage specification");
762 l = "C++";
763 }
764
765 Out << "extern \"" << l << "\" ";
766 if (D->hasBraces()) {
767 Out << "{\n";
768 VisitDeclContext(D);
769 Indent() << "}";
770 } else
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000771 Visit(*D->decls_begin());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000772}
773
Richard Trieu5cb3d692011-07-28 00:19:05 +0000774void DeclPrinter::PrintTemplateParameters(
775 const TemplateParameterList *Params, const TemplateArgumentList *Args = 0) {
776 assert(Params);
777 assert(!Args || Params->size() == Args->size());
778
Anders Carlsson0487f662009-06-04 05:37:43 +0000779 Out << "template <";
Mike Stump1eb44332009-09-09 15:08:12 +0000780
Anders Carlsson0487f662009-06-04 05:37:43 +0000781 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
782 if (i != 0)
783 Out << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000784
Anders Carlsson0487f662009-06-04 05:37:43 +0000785 const Decl *Param = Params->getParam(i);
Mike Stump1eb44332009-09-09 15:08:12 +0000786 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000787 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000788
Anders Carlsson0487f662009-06-04 05:37:43 +0000789 if (TTP->wasDeclaredWithTypename())
790 Out << "typename ";
791 else
792 Out << "class ";
793
Anders Carlsson6d845ae2009-06-12 22:23:22 +0000794 if (TTP->isParameterPack())
795 Out << "... ";
Mike Stump1eb44332009-09-09 15:08:12 +0000796
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000797 Out << *TTP;
Anders Carlsson0487f662009-06-04 05:37:43 +0000798
Richard Trieu5cb3d692011-07-28 00:19:05 +0000799 if (Args) {
800 Out << " = ";
801 Args->get(i).print(Policy, Out);
802 } else if (TTP->hasDefaultArgument()) {
Anders Carlsson0487f662009-06-04 05:37:43 +0000803 Out << " = ";
804 Out << TTP->getDefaultArgument().getAsString(Policy);
805 };
Mike Stump1eb44332009-09-09 15:08:12 +0000806 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000807 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
808 Out << NTTP->getType().getAsString(Policy);
809
Douglas Gregor56bc9832010-12-24 00:15:10 +0000810 if (NTTP->isParameterPack() && !isa<PackExpansionType>(NTTP->getType()))
811 Out << "...";
812
Anders Carlsson0487f662009-06-04 05:37:43 +0000813 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
814 Out << ' ';
815 Out << Name->getName();
816 }
Mike Stump1eb44332009-09-09 15:08:12 +0000817
Richard Trieu5cb3d692011-07-28 00:19:05 +0000818 if (Args) {
819 Out << " = ";
820 Args->get(i).print(Policy, Out);
821 } else if (NTTP->hasDefaultArgument()) {
Anders Carlsson0487f662009-06-04 05:37:43 +0000822 Out << " = ";
Richard Smithd1420c62012-08-16 03:56:14 +0000823 NTTP->getDefaultArgument()->printPretty(Out, 0, Policy, Indentation);
Anders Carlsson0487f662009-06-04 05:37:43 +0000824 }
Richard Smith98a57862011-04-15 13:38:57 +0000825 } else if (const TemplateTemplateParmDecl *TTPD =
826 dyn_cast<TemplateTemplateParmDecl>(Param)) {
827 VisitTemplateDecl(TTPD);
828 // FIXME: print the default argument, if present.
Anders Carlsson0487f662009-06-04 05:37:43 +0000829 }
830 }
Mike Stump1eb44332009-09-09 15:08:12 +0000831
Anders Carlsson0487f662009-06-04 05:37:43 +0000832 Out << "> ";
Richard Trieu5cb3d692011-07-28 00:19:05 +0000833}
834
835void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
836 PrintTemplateParameters(D->getTemplateParameters());
Anders Carlsson0487f662009-06-04 05:37:43 +0000837
Richard Smith98a57862011-04-15 13:38:57 +0000838 if (const TemplateTemplateParmDecl *TTP =
839 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregor61c4d282011-01-05 15:48:55 +0000840 Out << "class ";
841 if (TTP->isParameterPack())
842 Out << "...";
843 Out << D->getName();
Craig Silverstein0193a722010-07-09 20:25:10 +0000844 } else {
845 Visit(D->getTemplatedDecl());
846 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000847}
848
Richard Trieu5cb3d692011-07-28 00:19:05 +0000849void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
850 if (PrintInstantiation) {
851 TemplateParameterList *Params = D->getTemplateParameters();
852 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
853 I != E; ++I) {
854 PrintTemplateParameters(Params, (*I)->getTemplateSpecializationArgs());
855 Visit(*I);
856 }
857 }
858
859 return VisitRedeclarableTemplateDecl(D);
860}
861
862void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
863 if (PrintInstantiation) {
864 TemplateParameterList *Params = D->getTemplateParameters();
865 for (ClassTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
866 I != E; ++I) {
867 PrintTemplateParameters(Params, &(*I)->getTemplateArgs());
868 Visit(*I);
869 Out << '\n';
870 }
871 }
872
873 return VisitRedeclarableTemplateDecl(D);
874}
875
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000876//----------------------------------------------------------------------------
877// Objective-C declarations
878//----------------------------------------------------------------------------
879
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000880void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
881 if (OMD->isInstanceMethod())
Douglas Gregor64f65002009-05-30 00:56:08 +0000882 Out << "- ";
Mike Stump1eb44332009-09-09 15:08:12 +0000883 else
Douglas Gregor64f65002009-05-30 00:56:08 +0000884 Out << "+ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000885 if (!OMD->getResultType().isNull())
Douglas Gregor59e63572009-05-30 06:58:37 +0000886 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump1eb44332009-09-09 15:08:12 +0000887
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000888 std::string name = OMD->getSelector().getAsString();
889 std::string::size_type pos, lastPos = 0;
890 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
891 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump1eb44332009-09-09 15:08:12 +0000892 // FIXME: selector is missing here!
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000893 pos = name.find_first_of(':', lastPos);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000894 Out << " " << name.substr(lastPos, pos - lastPos);
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000895 Out << ":(" << (*PI)->getType().getAsString(Policy) << ')' << **PI;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000896 lastPos = pos + 1;
897 }
Mike Stump1eb44332009-09-09 15:08:12 +0000898
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000899 if (OMD->param_begin() == OMD->param_end())
900 Out << " " << name;
Mike Stump1eb44332009-09-09 15:08:12 +0000901
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000902 if (OMD->isVariadic())
903 Out << ", ...";
Mike Stump1eb44332009-09-09 15:08:12 +0000904
Fariborz Jahanian1bfb00d2012-10-17 21:58:03 +0000905 if (OMD->getBody() && !Policy.TerseOutput) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000906 Out << ' ';
Richard Smithd1420c62012-08-16 03:56:14 +0000907 OMD->getBody()->printPretty(Out, 0, Policy);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000908 Out << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000909 }
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000910 else if (Policy.PolishForDeclaration)
Fariborz Jahanian88b95212012-12-18 23:02:59 +0000911 Out << ';';
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000912}
913
914void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
915 std::string I = OID->getNameAsString();
916 ObjCInterfaceDecl *SID = OID->getSuperClass();
917
918 if (SID)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000919 Out << "@implementation " << I << " : " << *SID;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000920 else
921 Out << "@implementation " << I;
Fariborz Jahanian482b4fd2012-12-04 00:47:33 +0000922
923 if (OID->ivar_size() > 0) {
924 Out << "{\n";
925 Indentation += Policy.Indentation;
926 for (ObjCImplementationDecl::ivar_iterator I = OID->ivar_begin(),
927 E = OID->ivar_end(); I != E; ++I) {
928 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
929 }
930 Indentation -= Policy.Indentation;
931 Out << "}\n";
932 }
Douglas Gregor64f65002009-05-30 00:56:08 +0000933 VisitDeclContext(OID, false);
934 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000935}
936
937void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
938 std::string I = OID->getNameAsString();
939 ObjCInterfaceDecl *SID = OID->getSuperClass();
940
Douglas Gregor7723fec2011-12-15 20:29:51 +0000941 if (!OID->isThisDeclarationADefinition()) {
942 Out << "@class " << I << ";";
943 return;
944 }
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000945 bool eolnOut = false;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000946 if (SID)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000947 Out << "@interface " << I << " : " << *SID;
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000948 else
949 Out << "@interface " << I;
Mike Stump1eb44332009-09-09 15:08:12 +0000950
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000951 // Protocols?
952 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
953 if (!Protocols.empty()) {
954 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
955 E = Protocols.end(); I != E; ++I)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000956 Out << (I == Protocols.begin() ? '<' : ',') << **I;
Douglas Gregor64f65002009-05-30 00:56:08 +0000957 Out << "> ";
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000958 }
Mike Stump1eb44332009-09-09 15:08:12 +0000959
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000960 if (OID->ivar_size() > 0) {
Douglas Gregor64f65002009-05-30 00:56:08 +0000961 Out << "{\n";
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000962 eolnOut = true;
Douglas Gregor64f65002009-05-30 00:56:08 +0000963 Indentation += Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000964 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
965 E = OID->ivar_end(); I != E; ++I) {
David Blaikie581deb32012-06-06 20:45:41 +0000966 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000967 }
Douglas Gregor64f65002009-05-30 00:56:08 +0000968 Indentation -= Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000969 Out << "}\n";
970 }
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000971 else if (SID) {
972 Out << "\n";
973 eolnOut = true;
974 }
Mike Stump1eb44332009-09-09 15:08:12 +0000975
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000976 VisitDeclContext(OID, false);
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000977 if (!eolnOut)
978 Out << ' ';
Douglas Gregor64f65002009-05-30 00:56:08 +0000979 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000980 // FIXME: implement the rest...
981}
982
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000983void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
Douglas Gregorbd9482d2012-01-01 21:23:57 +0000984 if (!PID->isThisDeclarationADefinition()) {
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000985 Out << "@protocol " << *PID << ";\n";
Douglas Gregorbd9482d2012-01-01 21:23:57 +0000986 return;
987 }
Fariborz Jahanian40902d82012-12-19 23:36:00 +0000988 // Protocols?
989 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
990 if (!Protocols.empty()) {
991 Out << "@protocol " << *PID;
992 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
993 E = Protocols.end(); I != E; ++I)
994 Out << (I == Protocols.begin() ? '<' : ',') << **I;
995 Out << ">\n";
996 } else
997 Out << "@protocol " << *PID << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000998 VisitDeclContext(PID, false);
999 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001000}
1001
1002void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001003 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001004
1005 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +00001006 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001007 // FIXME: implement the rest...
1008}
1009
1010void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001011 Out << "@interface " << *PID->getClassInterface() << '(' << *PID << ")\n";
Fariborz Jahanianff685c52012-12-04 17:20:57 +00001012 if (PID->ivar_size() > 0) {
1013 Out << "{\n";
1014 Indentation += Policy.Indentation;
1015 for (ObjCCategoryDecl::ivar_iterator I = PID->ivar_begin(),
1016 E = PID->ivar_end(); I != E; ++I) {
1017 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
1018 }
1019 Indentation -= Policy.Indentation;
1020 Out << "}\n";
1021 }
1022
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001023 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +00001024 Out << "@end";
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001026 // FIXME: implement the rest...
1027}
1028
1029void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001030 Out << "@compatibility_alias " << *AID
1031 << ' ' << *AID->getClassInterface() << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001032}
1033
1034/// PrintObjCPropertyDecl - print a property declaration.
1035///
1036void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1037 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
1038 Out << "@required\n";
1039 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1040 Out << "@optional\n";
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001042 Out << "@property";
1043 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
1044 bool first = true;
1045 Out << " (";
Mike Stump1eb44332009-09-09 15:08:12 +00001046 if (PDecl->getPropertyAttributes() &
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001047 ObjCPropertyDecl::OBJC_PR_readonly) {
1048 Out << (first ? ' ' : ',') << "readonly";
1049 first = false;
Ted Kremenek07c682a2011-08-17 21:09:35 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Ted Kremenek07c682a2011-08-17 21:09:35 +00001052 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
1053 Out << (first ? ' ' : ',') << "getter = "
1054 << PDecl->getGetterName().getAsString();
1055 first = false;
1056 }
1057 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
1058 Out << (first ? ' ' : ',') << "setter = "
1059 << PDecl->getSetterName().getAsString();
1060 first = false;
1061 }
Mike Stump1eb44332009-09-09 15:08:12 +00001062
Ted Kremenek07c682a2011-08-17 21:09:35 +00001063 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
1064 Out << (first ? ' ' : ',') << "assign";
1065 first = false;
1066 }
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Ted Kremenek07c682a2011-08-17 21:09:35 +00001068 if (PDecl->getPropertyAttributes() &
1069 ObjCPropertyDecl::OBJC_PR_readwrite) {
1070 Out << (first ? ' ' : ',') << "readwrite";
1071 first = false;
1072 }
Mike Stump1eb44332009-09-09 15:08:12 +00001073
Ted Kremenek07c682a2011-08-17 21:09:35 +00001074 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
1075 Out << (first ? ' ' : ',') << "retain";
1076 first = false;
1077 }
Mike Stump1eb44332009-09-09 15:08:12 +00001078
Ted Kremenek07c682a2011-08-17 21:09:35 +00001079 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) {
1080 Out << (first ? ' ' : ',') << "strong";
1081 first = false;
1082 }
John McCallf85e1932011-06-15 23:02:42 +00001083
Ted Kremenek07c682a2011-08-17 21:09:35 +00001084 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
1085 Out << (first ? ' ' : ',') << "copy";
1086 first = false;
1087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Ted Kremenek07c682a2011-08-17 21:09:35 +00001089 if (PDecl->getPropertyAttributes() &
1090 ObjCPropertyDecl::OBJC_PR_nonatomic) {
1091 Out << (first ? ' ' : ',') << "nonatomic";
1092 first = false;
1093 }
1094 if (PDecl->getPropertyAttributes() &
1095 ObjCPropertyDecl::OBJC_PR_atomic) {
1096 Out << (first ? ' ' : ',') << "atomic";
1097 first = false;
1098 }
1099
1100 (void) first; // Silence dead store warning due to idiomatic code.
1101 Out << " )";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001102 }
Fariborz Jahanian40902d82012-12-19 23:36:00 +00001103 Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << *PDecl;
1104 if (Policy.PolishForDeclaration)
1105 Out << ';';
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001106}
1107
1108void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1109 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor64f65002009-05-30 00:56:08 +00001110 Out << "@synthesize ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001111 else
Douglas Gregor64f65002009-05-30 00:56:08 +00001112 Out << "@dynamic ";
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001113 Out << *PID->getPropertyDecl();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001114 if (PID->getPropertyIvarDecl())
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001115 Out << '=' << *PID->getPropertyIvarDecl();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001116}
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001117
1118void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1119 Out << "using ";
Douglas Gregordc355712011-02-25 00:36:19 +00001120 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001121 Out << *D;
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001122}
1123
John McCall7ba107a2009-11-18 02:36:19 +00001124void
1125DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1126 Out << "using typename ";
Douglas Gregordc355712011-02-25 00:36:19 +00001127 D->getQualifier()->print(Out, Policy);
Benjamin Kramer900fc632010-04-17 09:33:03 +00001128 Out << D->getDeclName();
John McCall7ba107a2009-11-18 02:36:19 +00001129}
1130
1131void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001132 Out << "using ";
Douglas Gregordc355712011-02-25 00:36:19 +00001133 D->getQualifier()->print(Out, Policy);
Fariborz Jahanian5e0ea192012-12-06 00:09:40 +00001134 Out << D->getName();
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001135}
John McCall9488ea12009-11-17 05:59:44 +00001136
1137void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1138 // ignore
1139}