blob: 34c69059c4b550b1d8a10e557e3eafc05fc0d4fd [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//
10// This file implements the Decl::dump method, which pretty print the
11// 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
Benjamin Kramer42c72c22012-08-14 14:50:32 +0000179void Decl::dump() const {
180 dump(llvm::errs());
181}
182
Alexander Kornienkoe34a0522012-07-26 16:01:23 +0000183void Decl::dump(raw_ostream &Out) const {
184 PrintingPolicy Policy = getASTContext().getPrintingPolicy();
Richard Smithd1420c62012-08-16 03:56:14 +0000185 Policy.DumpSourceManager = &getASTContext().getSourceManager();
Alexander Kornienkoe34a0522012-07-26 16:01:23 +0000186 print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ true);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000187}
188
Chris Lattner5f9e2722011-07-23 10:55:15 +0000189raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
Daniel Dunbar512ce602009-11-21 09:12:06 +0000190 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000191 Out << " ";
192 return Out;
193}
194
Douglas Gregor1bea8802011-11-19 19:22:57 +0000195void DeclPrinter::prettyPrintAttributes(Decl *D) {
Fariborz Jahanian1bfb00d2012-10-17 21:58:03 +0000196 if (Policy.SuppressAttributes)
197 return;
198
Douglas Gregor1bea8802011-11-19 19:22:57 +0000199 if (D->hasAttrs()) {
200 AttrVec &Attrs = D->getAttrs();
201 for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) {
Richard Smith0dae7292012-08-16 02:43:29 +0000202 Attr *A = *i;
203 A->printPretty(Out, Policy);
Douglas Gregor1bea8802011-11-19 19:22:57 +0000204 }
205 }
206}
207
Chris Lattner5f9e2722011-07-23 10:55:15 +0000208void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000209 this->Indent();
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000210 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000211 Out << ";\n";
212 Decls.clear();
213
214}
215
Anders Carlsson0d592922009-08-28 22:39:52 +0000216void DeclPrinter::Print(AccessSpecifier AS) {
217 switch(AS) {
David Blaikieeb2d1f12011-09-23 20:26:49 +0000218 case AS_none: llvm_unreachable("No access specifier!");
Anders Carlsson0d592922009-08-28 22:39:52 +0000219 case AS_public: Out << "public"; break;
220 case AS_protected: Out << "protected"; break;
Abramo Bagnara6206d532010-06-05 05:09:32 +0000221 case AS_private: Out << "private"; break;
Anders Carlsson0d592922009-08-28 22:39:52 +0000222 }
223}
224
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000225//----------------------------------------------------------------------------
226// Common C declarations
227//----------------------------------------------------------------------------
228
229void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
Dmitri Gribenkod1fc82e2012-08-21 17:36:32 +0000230 if (Policy.TerseOutput)
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000231 return;
232
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000233 if (Indent)
234 Indentation += Policy.Indentation;
235
Chris Lattner5f9e2722011-07-23 10:55:15 +0000236 SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000237 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000238 D != DEnd; ++D) {
Ted Kremenek2d6c9062010-07-30 00:47:46 +0000239
240 // Don't print ObjCIvarDecls, as they are printed when visiting the
241 // containing ObjCInterfaceDecl.
242 if (isa<ObjCIvarDecl>(*D))
243 continue;
244
Richard Smithd1420c62012-08-16 03:56:14 +0000245 if (!Policy.DumpSourceManager) {
Eli Friedman48d14a22009-05-30 05:03:24 +0000246 // Skip over implicit declarations in pretty-printing mode.
247 if (D->isImplicit()) continue;
Eli Friedman3d4a7c92009-05-30 06:35:22 +0000248 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
Argyrios Kyrtzidis2574f6f2010-06-17 10:52:11 +0000249 // of __builtin_va_list or __[u]int128_t. There should be some other way
250 // to check that.
251 if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) {
252 if (IdentifierInfo *II = ND->getIdentifier()) {
253 if (II->isStr("__builtin_va_list") ||
254 II->isStr("__int128_t") || II->isStr("__uint128_t"))
255 continue;
256 }
257 }
Eli Friedman48d14a22009-05-30 05:03:24 +0000258 }
259
Eli Friedman42f42c02009-05-30 04:20:30 +0000260 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
261 // forced to merge the declarations because there's no other way to
262 // refer to the struct in question. This limited merging is safe without
263 // a bunch of other checks because it only merges declarations directly
264 // referring to the tag, not typedefs.
265 //
266 // Check whether the current declaration should be grouped with a previous
267 // unnamed struct.
268 QualType CurDeclType = getDeclType(*D);
269 if (!Decls.empty() && !CurDeclType.isNull()) {
270 QualType BaseType = GetBaseType(CurDeclType);
271 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
272 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
273 Decls.push_back(*D);
274 continue;
275 }
276 }
277
278 // If we have a merged group waiting to be handled, handle it now.
279 if (!Decls.empty())
280 ProcessDeclGroup(Decls);
281
282 // If the current declaration is an unnamed tag type, save it
283 // so we can merge it with the subsequent declaration(s) using it.
284 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
285 Decls.push_back(*D);
286 continue;
287 }
Abramo Bagnara6206d532010-06-05 05:09:32 +0000288
289 if (isa<AccessSpecDecl>(*D)) {
290 Indentation -= Policy.Indentation;
291 this->Indent();
292 Print(D->getAccess());
293 Out << ":\n";
294 Indentation += Policy.Indentation;
295 continue;
296 }
297
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000298 this->Indent();
299 Visit(*D);
Mike Stump1eb44332009-09-09 15:08:12 +0000300
301 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000302 const char *Terminator = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000303 if (isa<FunctionDecl>(*D) &&
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000304 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
305 Terminator = 0;
Douglas Gregor64f65002009-05-30 00:56:08 +0000306 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
307 Terminator = 0;
308 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump1eb44332009-09-09 15:08:12 +0000309 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor64f65002009-05-30 00:56:08 +0000310 isa<ObjCInterfaceDecl>(*D) ||
311 isa<ObjCProtocolDecl>(*D) ||
312 isa<ObjCCategoryImplDecl>(*D) ||
313 isa<ObjCCategoryDecl>(*D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000314 Terminator = 0;
315 else if (isa<EnumConstantDecl>(*D)) {
316 DeclContext::decl_iterator Next = D;
317 ++Next;
318 if (Next != DEnd)
319 Terminator = ",";
320 } else
321 Terminator = ";";
322
323 if (Terminator)
324 Out << Terminator;
325 Out << "\n";
326 }
327
Eli Friedman42f42c02009-05-30 04:20:30 +0000328 if (!Decls.empty())
329 ProcessDeclGroup(Decls);
330
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000331 if (Indent)
332 Indentation -= Policy.Indentation;
333}
334
335void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
336 VisitDeclContext(D, false);
337}
338
339void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000340 if (!Policy.SuppressSpecifiers) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000341 Out << "typedef ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000342
343 if (D->isModulePrivate())
344 Out << "__module_private__ ";
345 }
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000346 D->getUnderlyingType().print(Out, Policy, D->getName());
Douglas Gregor1bea8802011-11-19 19:22:57 +0000347 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000348}
349
Richard Smith162e1c12011-04-15 14:24:37 +0000350void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000351 Out << "using " << *D << " = " << D->getUnderlyingType().getAsString(Policy);
Richard Smith162e1c12011-04-15 14:24:37 +0000352}
353
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000354void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000355 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
356 Out << "__module_private__ ";
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000357 Out << "enum ";
Abramo Bagnaraa88cefd2010-12-03 18:54:17 +0000358 if (D->isScoped()) {
359 if (D->isScopedUsingClassTag())
360 Out << "class ";
361 else
362 Out << "struct ";
363 }
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000364 Out << *D;
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000365
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000366 if (D->isFixed())
367 Out << " : " << D->getIntegerType().stream(Policy);
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000368
John McCall5e1cdac2011-10-07 06:10:15 +0000369 if (D->isCompleteDefinition()) {
Douglas Gregor9fa8c462010-12-01 16:01:08 +0000370 Out << " {\n";
371 VisitDeclContext(D);
372 Indent() << "}";
373 }
Douglas Gregor1bea8802011-11-19 19:22:57 +0000374 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000375}
376
377void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000378 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
379 Out << "__module_private__ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000380 Out << D->getKindName();
Benjamin Kramer900fc632010-04-17 09:33:03 +0000381 if (D->getIdentifier())
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000382 Out << ' ' << *D;
Mike Stump1eb44332009-09-09 15:08:12 +0000383
John McCall5e1cdac2011-10-07 06:10:15 +0000384 if (D->isCompleteDefinition()) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000385 Out << " {\n";
386 VisitDeclContext(D);
387 Indent() << "}";
388 }
389}
390
391void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000392 Out << *D;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000393 if (Expr *Init = D->getInitExpr()) {
394 Out << " = ";
Richard Smithd1420c62012-08-16 03:56:14 +0000395 Init->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000396 }
397}
398
Mike Stump1eb44332009-09-09 15:08:12 +0000399void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Fariborz Jahanian65bcdab2012-12-05 22:19:06 +0000400 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
Eli Friedman42f42c02009-05-30 04:20:30 +0000401 if (!Policy.SuppressSpecifiers) {
Peter Collingbourne13330c42011-11-08 02:52:52 +0000402 switch (D->getStorageClassAsWritten()) {
John McCalld931b082010-08-26 03:08:43 +0000403 case SC_None: break;
404 case SC_Extern: Out << "extern "; break;
405 case SC_Static: Out << "static "; break;
406 case SC_PrivateExtern: Out << "__private_extern__ "; break;
Peter Collingbourne8c25fc52011-09-19 21:14:35 +0000407 case SC_Auto: case SC_Register: case SC_OpenCLWorkGroupLocal:
408 llvm_unreachable("invalid for functions");
Eli Friedman42f42c02009-05-30 04:20:30 +0000409 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000410
Douglas Gregor8d267c52011-09-09 02:06:17 +0000411 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman42f42c02009-05-30 04:20:30 +0000412 if (D->isVirtualAsWritten()) Out << "virtual ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000413 if (D->isModulePrivate()) Out << "__module_private__ ";
Fariborz Jahanian65bcdab2012-12-05 22:19:06 +0000414 if (CDecl && CDecl->isExplicitSpecified())
415 Out << "explicit ";
Eli Friedman42f42c02009-05-30 04:20:30 +0000416 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000417
Douglas Gregor6620a622009-05-30 05:39:39 +0000418 PrintingPolicy SubPolicy(Policy);
419 SubPolicy.SuppressSpecifiers = false;
Abramo Bagnara25777432010-08-11 22:01:17 +0000420 std::string Proto = D->getNameInfo().getAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000421
Abramo Bagnara723df242010-12-14 22:11:44 +0000422 QualType Ty = D->getType();
John McCallf4c73712011-01-19 06:33:43 +0000423 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
Abramo Bagnara723df242010-12-14 22:11:44 +0000424 Proto = '(' + Proto + ')';
425 Ty = PT->getInnerType();
426 }
427
428 if (isa<FunctionType>(Ty)) {
429 const FunctionType *AFT = Ty->getAs<FunctionType>();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000430 const FunctionProtoType *FT = 0;
431 if (D->hasWrittenPrototype())
432 FT = dyn_cast<FunctionProtoType>(AFT);
433
434 Proto += "(";
435 if (FT) {
436 llvm::raw_string_ostream POut(Proto);
Richard Smithd1420c62012-08-16 03:56:14 +0000437 DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000438 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
439 if (i) POut << ", ";
440 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
441 }
Mike Stump1eb44332009-09-09 15:08:12 +0000442
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000443 if (FT->isVariadic()) {
444 if (D->getNumParams()) POut << ", ";
445 POut << "...";
446 }
Sean Hunt10620eb2011-05-06 20:44:56 +0000447 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000448 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
449 if (i)
450 Proto += ", ";
451 Proto += D->getParamDecl(i)->getNameAsString();
452 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000453 }
454
455 Proto += ")";
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000456
David Blaikie4ef832f2012-08-10 00:55:35 +0000457 if (FT) {
458 if (FT->isConst())
Douglas Gregorb95cfe42010-11-19 18:44:34 +0000459 Proto += " const";
David Blaikie4ef832f2012-08-10 00:55:35 +0000460 if (FT->isVolatile())
Douglas Gregorb95cfe42010-11-19 18:44:34 +0000461 Proto += " volatile";
David Blaikie4ef832f2012-08-10 00:55:35 +0000462 if (FT->isRestrict())
Douglas Gregorb95cfe42010-11-19 18:44:34 +0000463 Proto += " restrict";
464 }
Sebastian Redl60618fa2011-03-12 11:50:43 +0000465
466 if (FT && FT->hasDynamicExceptionSpec()) {
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000467 Proto += " throw(";
Sebastian Redl60618fa2011-03-12 11:50:43 +0000468 if (FT->getExceptionSpecType() == EST_MSAny)
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000469 Proto += "...";
470 else
471 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
472 if (I)
473 Proto += ", ";
Sebastian Redl60618fa2011-03-12 11:50:43 +0000474
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +0000475 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000476 }
477 Proto += ")";
Sebastian Redl60618fa2011-03-12 11:50:43 +0000478 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
479 Proto += " noexcept";
480 if (FT->getExceptionSpecType() == EST_ComputedNoexcept) {
481 Proto += "(";
482 llvm::raw_string_ostream EOut(Proto);
Richard Smithd1420c62012-08-16 03:56:14 +0000483 FT->getNoexceptExpr()->printPretty(EOut, 0, SubPolicy,
Sebastian Redl60618fa2011-03-12 11:50:43 +0000484 Indentation);
485 EOut.flush();
486 Proto += EOut.str();
487 Proto += ")";
488 }
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000489 }
490
Fariborz Jahanian65bcdab2012-12-05 22:19:06 +0000491 if (CDecl) {
Richard Smith7a614d82011-06-11 17:19:42 +0000492 bool HasInitializerList = false;
493 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
494 E = CDecl->init_end();
495 B != E; ++B) {
496 CXXCtorInitializer * BMInitializer = (*B);
497 if (BMInitializer->isInClassMemberInitializer())
498 continue;
499
500 if (!HasInitializerList) {
501 Proto += " : ";
502 Out << Proto;
503 Proto.clear();
504 HasInitializerList = true;
505 } else
506 Out << ", ";
507
508 if (BMInitializer->isAnyMemberInitializer()) {
509 FieldDecl *FD = BMInitializer->getAnyMember();
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000510 Out << *FD;
Richard Smith7a614d82011-06-11 17:19:42 +0000511 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000512 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
Richard Smith7a614d82011-06-11 17:19:42 +0000513 }
514
515 Out << "(";
516 if (!BMInitializer->getInit()) {
517 // Nothing to print
518 } else {
519 Expr *Init = BMInitializer->getInit();
520 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
521 Init = Tmp->getSubExpr();
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000522
Richard Smith7a614d82011-06-11 17:19:42 +0000523 Init = Init->IgnoreParens();
524
525 Expr *SimpleInit = 0;
526 Expr **Args = 0;
527 unsigned NumArgs = 0;
528 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
529 Args = ParenList->getExprs();
530 NumArgs = ParenList->getNumExprs();
531 } else if (CXXConstructExpr *Construct
532 = dyn_cast<CXXConstructExpr>(Init)) {
533 Args = Construct->getArgs();
534 NumArgs = Construct->getNumArgs();
535 } else
536 SimpleInit = Init;
537
538 if (SimpleInit)
Richard Smithd1420c62012-08-16 03:56:14 +0000539 SimpleInit->printPretty(Out, 0, Policy, Indentation);
Richard Smith7a614d82011-06-11 17:19:42 +0000540 else {
541 for (unsigned I = 0; I != NumArgs; ++I) {
542 if (isa<CXXDefaultArgExpr>(Args[I]))
543 break;
544
545 if (I)
546 Out << ", ";
Richard Smithd1420c62012-08-16 03:56:14 +0000547 Args[I]->printPretty(Out, 0, Policy, Indentation);
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000548 }
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000549 }
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000550 }
Richard Smith7a614d82011-06-11 17:19:42 +0000551 Out << ")";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000552 }
Fariborz Jahanian02a2e5a2012-12-05 19:54:11 +0000553 if (!Proto.empty())
554 Out << Proto;
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000555 }
556 else
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000557 AFT->getResultType().print(Out, Policy, Proto);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000558 } else {
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000559 Ty.print(Out, Policy, Proto);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000560 }
561
Douglas Gregor1bea8802011-11-19 19:22:57 +0000562 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000563
564 if (D->isPure())
565 Out << " = 0";
Sean Hunt10620eb2011-05-06 20:44:56 +0000566 else if (D->isDeletedAsWritten())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000567 Out << " = delete";
Fariborz Jahanianddb29682012-12-05 22:53:06 +0000568 else if (D->isExplicitlyDefaulted())
569 Out << " = default";
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000570 else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000571 if (!D->hasPrototype() && D->getNumParams()) {
572 // This is a K&R function definition, so we need to print the
573 // parameters.
574 Out << '\n';
Richard Smithd1420c62012-08-16 03:56:14 +0000575 DeclPrinter ParamPrinter(Out, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000576 Indentation += Policy.Indentation;
577 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
578 Indent();
Douglas Gregor6620a622009-05-30 05:39:39 +0000579 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000580 Out << ";\n";
581 }
582 Indentation -= Policy.Indentation;
583 } else
584 Out << ' ';
585
Richard Smithd1420c62012-08-16 03:56:14 +0000586 D->getBody()->printPretty(Out, 0, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000587 Out << '\n';
588 }
589}
590
Fariborz Jahanian8920eb72012-12-05 00:38:44 +0000591void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
592 if (TypeSourceInfo *TSI = D->getFriendType()) {
593 if (CXXRecordDecl *FriendD = TSI->getType()->getAsCXXRecordDecl()) {
594 Out << "friend ";
595 VisitCXXRecordDecl(FriendD);
596 }
597 }
598 else if (FunctionDecl *FD =
599 dyn_cast<FunctionDecl>(D->getFriendDecl())) {
600 Out << "friend ";
601 VisitFunctionDecl(FD);
602 }
603 else if (FunctionTemplateDecl *FTD =
604 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
605 Out << "friend ";
606 VisitFunctionTemplateDecl(FTD);
607 }
608 else if (ClassTemplateDecl *CTD =
609 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
610 Out << "friend ";
611 VisitClassTemplateDecl(CTD);
612 }
613}
614
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000615void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000616 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000617 Out << "mutable ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000618 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
619 Out << "__module_private__ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000620
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000621 Out << D->getType().stream(Policy, D->getName());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000622
623 if (D->isBitField()) {
624 Out << " : ";
Richard Smithd1420c62012-08-16 03:56:14 +0000625 D->getBitWidth()->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000626 }
Richard Smith7a614d82011-06-11 17:19:42 +0000627
628 Expr *Init = D->getInClassInitializer();
629 if (!Policy.SuppressInitializers && Init) {
Richard Smithca523302012-06-10 03:12:00 +0000630 if (D->getInClassInitStyle() == ICIS_ListInit)
631 Out << " ";
632 else
633 Out << " = ";
Richard Smithd1420c62012-08-16 03:56:14 +0000634 Init->printPretty(Out, 0, Policy, Indentation);
Richard Smith7a614d82011-06-11 17:19:42 +0000635 }
Douglas Gregor1bea8802011-11-19 19:22:57 +0000636 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000637}
638
Chris Lattner57ad3782011-02-17 20:34:02 +0000639void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000640 Out << *D << ":";
Chris Lattner57ad3782011-02-17 20:34:02 +0000641}
642
643
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000644void DeclPrinter::VisitVarDecl(VarDecl *D) {
Peter Collingbourne13330c42011-11-08 02:52:52 +0000645 StorageClass SCAsWritten = D->getStorageClassAsWritten();
646 if (!Policy.SuppressSpecifiers && SCAsWritten != SC_None)
647 Out << VarDecl::getStorageClassSpecifierString(SCAsWritten) << " ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000648
Eli Friedman42f42c02009-05-30 04:20:30 +0000649 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000650 Out << "__thread ";
Douglas Gregor8d267c52011-09-09 02:06:17 +0000651 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
652 Out << "__module_private__ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000653
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000654 QualType T = D->getType();
John McCall58e46772009-10-23 21:48:59 +0000655 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000656 T = Parm->getOriginalType();
Argyrios Kyrtzidis7ad5c992012-05-05 04:20:37 +0000657 T.print(Out, Policy, D->getName());
Richard Smithad762fc2011-04-14 22:09:26 +0000658 Expr *Init = D->getInit();
659 if (!Policy.SuppressInitializers && Init) {
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000660 bool ImplicitInit = false;
661 if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init))
662 ImplicitInit = D->getInitStyle() == VarDecl::CallInit &&
663 Construct->getNumArgs() == 0 && !Construct->isListInitialization();
664 if (!ImplicitInit) {
Eli Friedmane1aebe12012-10-19 20:36:44 +0000665 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000666 Out << "(";
667 else if (D->getInitStyle() == VarDecl::CInit) {
668 Out << " = ";
669 }
Richard Smithd1420c62012-08-16 03:56:14 +0000670 Init->printPretty(Out, 0, Policy, Indentation);
Eli Friedmane1aebe12012-10-19 20:36:44 +0000671 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000672 Out << ")";
Ted Kremenekc57d6552010-09-17 23:04:38 +0000673 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000674 }
Douglas Gregor1bea8802011-11-19 19:22:57 +0000675 prettyPrintAttributes(D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000676}
677
678void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
679 VisitVarDecl(D);
680}
681
682void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
683 Out << "__asm (";
Richard Smithd1420c62012-08-16 03:56:14 +0000684 D->getAsmString()->printPretty(Out, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000685 Out << ")";
686}
687
Douglas Gregor15de72c2011-12-02 23:23:56 +0000688void DeclPrinter::VisitImportDecl(ImportDecl *D) {
Douglas Gregor1b257af2012-12-11 22:11:52 +0000689 Out << "@import " << D->getImportedModule()->getFullModuleName()
Douglas Gregor15de72c2011-12-02 23:23:56 +0000690 << ";\n";
691}
692
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000693void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
694 Out << "static_assert(";
Richard Smithd1420c62012-08-16 03:56:14 +0000695 D->getAssertExpr()->printPretty(Out, 0, Policy, Indentation);
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000696 Out << ", ";
Richard Smithd1420c62012-08-16 03:56:14 +0000697 D->getMessage()->printPretty(Out, 0, Policy, Indentation);
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000698 Out << ")";
699}
700
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000701//----------------------------------------------------------------------------
702// C++ declarations
703//----------------------------------------------------------------------------
Douglas Gregor59e63572009-05-30 06:58:37 +0000704void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregorc30636a2012-05-01 01:43:38 +0000705 if (D->isInline())
706 Out << "inline ";
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000707 Out << "namespace " << *D << " {\n";
Douglas Gregor59e63572009-05-30 06:58:37 +0000708 VisitDeclContext(D);
709 Indent() << "}";
710}
711
Douglas Gregor8419fa32009-05-30 06:31:56 +0000712void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
713 Out << "using namespace ";
714 if (D->getQualifier())
715 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000716 Out << *D->getNominatedNamespaceAsWritten();
Douglas Gregor8419fa32009-05-30 06:31:56 +0000717}
718
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000719void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000720 Out << "namespace " << *D << " = ";
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000721 if (D->getQualifier())
722 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000723 Out << *D->getAliasedNamespace();
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000724}
725
Douglas Gregor59e63572009-05-30 06:58:37 +0000726void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Douglas Gregor8d267c52011-09-09 02:06:17 +0000727 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
728 Out << "__module_private__ ";
Douglas Gregor59e63572009-05-30 06:58:37 +0000729 Out << D->getKindName();
Benjamin Kramer900fc632010-04-17 09:33:03 +0000730 if (D->getIdentifier())
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000731 Out << ' ' << *D;
Mike Stump1eb44332009-09-09 15:08:12 +0000732
John McCall5e1cdac2011-10-07 06:10:15 +0000733 if (D->isCompleteDefinition()) {
Douglas Gregor59e63572009-05-30 06:58:37 +0000734 // Print the base classes
735 if (D->getNumBases()) {
736 Out << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000737 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
738 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor59e63572009-05-30 06:58:37 +0000739 if (Base != D->bases_begin())
740 Out << ", ";
741
742 if (Base->isVirtual())
743 Out << "virtual ";
744
Anders Carlsson018e9fe2009-08-29 20:36:12 +0000745 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
746 if (AS != AS_none)
747 Print(AS);
Anders Carlsson0d592922009-08-28 22:39:52 +0000748 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor34a99e72011-04-27 17:07:55 +0000749
750 if (Base->isPackExpansion())
751 Out << "...";
Douglas Gregor59e63572009-05-30 06:58:37 +0000752 }
753 }
754
755 // Print the class definition
Douglas Gregorf757ae72009-05-31 07:13:39 +0000756 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor59e63572009-05-30 06:58:37 +0000757 Out << " {\n";
758 VisitDeclContext(D);
759 Indent() << "}";
Mike Stump1eb44332009-09-09 15:08:12 +0000760 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000761}
762
763void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
764 const char *l;
765 if (D->getLanguage() == LinkageSpecDecl::lang_c)
766 l = "C";
767 else {
768 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
769 "unknown language in linkage specification");
770 l = "C++";
771 }
772
773 Out << "extern \"" << l << "\" ";
774 if (D->hasBraces()) {
775 Out << "{\n";
776 VisitDeclContext(D);
777 Indent() << "}";
778 } else
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000779 Visit(*D->decls_begin());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000780}
781
Richard Trieu5cb3d692011-07-28 00:19:05 +0000782void DeclPrinter::PrintTemplateParameters(
783 const TemplateParameterList *Params, const TemplateArgumentList *Args = 0) {
784 assert(Params);
785 assert(!Args || Params->size() == Args->size());
786
Anders Carlsson0487f662009-06-04 05:37:43 +0000787 Out << "template <";
Mike Stump1eb44332009-09-09 15:08:12 +0000788
Anders Carlsson0487f662009-06-04 05:37:43 +0000789 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
790 if (i != 0)
791 Out << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000792
Anders Carlsson0487f662009-06-04 05:37:43 +0000793 const Decl *Param = Params->getParam(i);
Mike Stump1eb44332009-09-09 15:08:12 +0000794 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000795 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000796
Anders Carlsson0487f662009-06-04 05:37:43 +0000797 if (TTP->wasDeclaredWithTypename())
798 Out << "typename ";
799 else
800 Out << "class ";
801
Anders Carlsson6d845ae2009-06-12 22:23:22 +0000802 if (TTP->isParameterPack())
803 Out << "... ";
Mike Stump1eb44332009-09-09 15:08:12 +0000804
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000805 Out << *TTP;
Anders Carlsson0487f662009-06-04 05:37:43 +0000806
Richard Trieu5cb3d692011-07-28 00:19:05 +0000807 if (Args) {
808 Out << " = ";
809 Args->get(i).print(Policy, Out);
810 } else if (TTP->hasDefaultArgument()) {
Anders Carlsson0487f662009-06-04 05:37:43 +0000811 Out << " = ";
812 Out << TTP->getDefaultArgument().getAsString(Policy);
813 };
Mike Stump1eb44332009-09-09 15:08:12 +0000814 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000815 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
816 Out << NTTP->getType().getAsString(Policy);
817
Douglas Gregor56bc9832010-12-24 00:15:10 +0000818 if (NTTP->isParameterPack() && !isa<PackExpansionType>(NTTP->getType()))
819 Out << "...";
820
Anders Carlsson0487f662009-06-04 05:37:43 +0000821 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
822 Out << ' ';
823 Out << Name->getName();
824 }
Mike Stump1eb44332009-09-09 15:08:12 +0000825
Richard Trieu5cb3d692011-07-28 00:19:05 +0000826 if (Args) {
827 Out << " = ";
828 Args->get(i).print(Policy, Out);
829 } else if (NTTP->hasDefaultArgument()) {
Anders Carlsson0487f662009-06-04 05:37:43 +0000830 Out << " = ";
Richard Smithd1420c62012-08-16 03:56:14 +0000831 NTTP->getDefaultArgument()->printPretty(Out, 0, Policy, Indentation);
Anders Carlsson0487f662009-06-04 05:37:43 +0000832 }
Richard Smith98a57862011-04-15 13:38:57 +0000833 } else if (const TemplateTemplateParmDecl *TTPD =
834 dyn_cast<TemplateTemplateParmDecl>(Param)) {
835 VisitTemplateDecl(TTPD);
836 // FIXME: print the default argument, if present.
Anders Carlsson0487f662009-06-04 05:37:43 +0000837 }
838 }
Mike Stump1eb44332009-09-09 15:08:12 +0000839
Anders Carlsson0487f662009-06-04 05:37:43 +0000840 Out << "> ";
Richard Trieu5cb3d692011-07-28 00:19:05 +0000841}
842
843void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
844 PrintTemplateParameters(D->getTemplateParameters());
Anders Carlsson0487f662009-06-04 05:37:43 +0000845
Richard Smith98a57862011-04-15 13:38:57 +0000846 if (const TemplateTemplateParmDecl *TTP =
847 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregor61c4d282011-01-05 15:48:55 +0000848 Out << "class ";
849 if (TTP->isParameterPack())
850 Out << "...";
851 Out << D->getName();
Craig Silverstein0193a722010-07-09 20:25:10 +0000852 } else {
853 Visit(D->getTemplatedDecl());
854 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000855}
856
Richard Trieu5cb3d692011-07-28 00:19:05 +0000857void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
858 if (PrintInstantiation) {
859 TemplateParameterList *Params = D->getTemplateParameters();
860 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
861 I != E; ++I) {
862 PrintTemplateParameters(Params, (*I)->getTemplateSpecializationArgs());
863 Visit(*I);
864 }
865 }
866
867 return VisitRedeclarableTemplateDecl(D);
868}
869
870void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
871 if (PrintInstantiation) {
872 TemplateParameterList *Params = D->getTemplateParameters();
873 for (ClassTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
874 I != E; ++I) {
875 PrintTemplateParameters(Params, &(*I)->getTemplateArgs());
876 Visit(*I);
877 Out << '\n';
878 }
879 }
880
881 return VisitRedeclarableTemplateDecl(D);
882}
883
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000884//----------------------------------------------------------------------------
885// Objective-C declarations
886//----------------------------------------------------------------------------
887
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000888void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
889 if (OMD->isInstanceMethod())
Douglas Gregor64f65002009-05-30 00:56:08 +0000890 Out << "- ";
Mike Stump1eb44332009-09-09 15:08:12 +0000891 else
Douglas Gregor64f65002009-05-30 00:56:08 +0000892 Out << "+ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000893 if (!OMD->getResultType().isNull())
Douglas Gregor59e63572009-05-30 06:58:37 +0000894 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000896 std::string name = OMD->getSelector().getAsString();
897 std::string::size_type pos, lastPos = 0;
898 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
899 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump1eb44332009-09-09 15:08:12 +0000900 // FIXME: selector is missing here!
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000901 pos = name.find_first_of(':', lastPos);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000902 Out << " " << name.substr(lastPos, pos - lastPos);
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000903 Out << ":(" << (*PI)->getType().getAsString(Policy) << ')' << **PI;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000904 lastPos = pos + 1;
905 }
Mike Stump1eb44332009-09-09 15:08:12 +0000906
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000907 if (OMD->param_begin() == OMD->param_end())
908 Out << " " << name;
Mike Stump1eb44332009-09-09 15:08:12 +0000909
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000910 if (OMD->isVariadic())
911 Out << ", ...";
Mike Stump1eb44332009-09-09 15:08:12 +0000912
Fariborz Jahanian1bfb00d2012-10-17 21:58:03 +0000913 if (OMD->getBody() && !Policy.TerseOutput) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000914 Out << ' ';
Richard Smithd1420c62012-08-16 03:56:14 +0000915 OMD->getBody()->printPretty(Out, 0, Policy);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000916 Out << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000917 }
Fariborz Jahanian88b95212012-12-18 23:02:59 +0000918 else
919 Out << ';';
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000920}
921
922void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
923 std::string I = OID->getNameAsString();
924 ObjCInterfaceDecl *SID = OID->getSuperClass();
925
926 if (SID)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000927 Out << "@implementation " << I << " : " << *SID;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000928 else
929 Out << "@implementation " << I;
Fariborz Jahanian482b4fd2012-12-04 00:47:33 +0000930
931 if (OID->ivar_size() > 0) {
932 Out << "{\n";
933 Indentation += Policy.Indentation;
934 for (ObjCImplementationDecl::ivar_iterator I = OID->ivar_begin(),
935 E = OID->ivar_end(); I != E; ++I) {
936 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
937 }
938 Indentation -= Policy.Indentation;
939 Out << "}\n";
940 }
Douglas Gregor64f65002009-05-30 00:56:08 +0000941 VisitDeclContext(OID, false);
942 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000943}
944
945void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
946 std::string I = OID->getNameAsString();
947 ObjCInterfaceDecl *SID = OID->getSuperClass();
948
Douglas Gregor7723fec2011-12-15 20:29:51 +0000949 if (!OID->isThisDeclarationADefinition()) {
950 Out << "@class " << I << ";";
951 return;
952 }
953
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000954 if (SID)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000955 Out << "@interface " << I << " : " << *SID;
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000956 else
957 Out << "@interface " << I;
Mike Stump1eb44332009-09-09 15:08:12 +0000958
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000959 // Protocols?
960 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
961 if (!Protocols.empty()) {
962 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
963 E = Protocols.end(); I != E; ++I)
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000964 Out << (I == Protocols.begin() ? '<' : ',') << **I;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000965 }
Mike Stump1eb44332009-09-09 15:08:12 +0000966
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000967 if (!Protocols.empty())
Douglas Gregor64f65002009-05-30 00:56:08 +0000968 Out << "> ";
Mike Stump1eb44332009-09-09 15:08:12 +0000969
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000970 if (OID->ivar_size() > 0) {
Douglas Gregor64f65002009-05-30 00:56:08 +0000971 Out << "{\n";
972 Indentation += Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000973 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
974 E = OID->ivar_end(); I != E; ++I) {
David Blaikie581deb32012-06-06 20:45:41 +0000975 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000976 }
Douglas Gregor64f65002009-05-30 00:56:08 +0000977 Indentation -= Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000978 Out << "}\n";
979 }
Mike Stump1eb44332009-09-09 15:08:12 +0000980
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000981 VisitDeclContext(OID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000982 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000983 // FIXME: implement the rest...
984}
985
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000986void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
Douglas Gregorbd9482d2012-01-01 21:23:57 +0000987 if (!PID->isThisDeclarationADefinition()) {
988 Out << "@protocol " << PID->getIdentifier() << ";\n";
989 return;
990 }
991
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000992 Out << "@protocol " << *PID << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000993 VisitDeclContext(PID, false);
994 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000995}
996
997void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000998 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000999
1000 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +00001001 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001002 // FIXME: implement the rest...
1003}
1004
1005void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001006 Out << "@interface " << *PID->getClassInterface() << '(' << *PID << ")\n";
Fariborz Jahanianff685c52012-12-04 17:20:57 +00001007 if (PID->ivar_size() > 0) {
1008 Out << "{\n";
1009 Indentation += Policy.Indentation;
1010 for (ObjCCategoryDecl::ivar_iterator I = PID->ivar_begin(),
1011 E = PID->ivar_end(); I != E; ++I) {
1012 Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n";
1013 }
1014 Indentation -= Policy.Indentation;
1015 Out << "}\n";
1016 }
1017
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001018 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +00001019 Out << "@end";
Mike Stump1eb44332009-09-09 15:08:12 +00001020
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001021 // FIXME: implement the rest...
1022}
1023
1024void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001025 Out << "@compatibility_alias " << *AID
1026 << ' ' << *AID->getClassInterface() << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001027}
1028
1029/// PrintObjCPropertyDecl - print a property declaration.
1030///
1031void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1032 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
1033 Out << "@required\n";
1034 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1035 Out << "@optional\n";
Mike Stump1eb44332009-09-09 15:08:12 +00001036
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001037 Out << "@property";
1038 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
1039 bool first = true;
1040 Out << " (";
Mike Stump1eb44332009-09-09 15:08:12 +00001041 if (PDecl->getPropertyAttributes() &
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001042 ObjCPropertyDecl::OBJC_PR_readonly) {
1043 Out << (first ? ' ' : ',') << "readonly";
1044 first = false;
Ted Kremenek07c682a2011-08-17 21:09:35 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Ted Kremenek07c682a2011-08-17 21:09:35 +00001047 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
1048 Out << (first ? ' ' : ',') << "getter = "
1049 << PDecl->getGetterName().getAsString();
1050 first = false;
1051 }
1052 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
1053 Out << (first ? ' ' : ',') << "setter = "
1054 << PDecl->getSetterName().getAsString();
1055 first = false;
1056 }
Mike Stump1eb44332009-09-09 15:08:12 +00001057
Ted Kremenek07c682a2011-08-17 21:09:35 +00001058 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
1059 Out << (first ? ' ' : ',') << "assign";
1060 first = false;
1061 }
Mike Stump1eb44332009-09-09 15:08:12 +00001062
Ted Kremenek07c682a2011-08-17 21:09:35 +00001063 if (PDecl->getPropertyAttributes() &
1064 ObjCPropertyDecl::OBJC_PR_readwrite) {
1065 Out << (first ? ' ' : ',') << "readwrite";
1066 first = false;
1067 }
Mike Stump1eb44332009-09-09 15:08:12 +00001068
Ted Kremenek07c682a2011-08-17 21:09:35 +00001069 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
1070 Out << (first ? ' ' : ',') << "retain";
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_strong) {
1075 Out << (first ? ' ' : ',') << "strong";
1076 first = false;
1077 }
John McCallf85e1932011-06-15 23:02:42 +00001078
Ted Kremenek07c682a2011-08-17 21:09:35 +00001079 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
1080 Out << (first ? ' ' : ',') << "copy";
1081 first = false;
1082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Ted Kremenek07c682a2011-08-17 21:09:35 +00001084 if (PDecl->getPropertyAttributes() &
1085 ObjCPropertyDecl::OBJC_PR_nonatomic) {
1086 Out << (first ? ' ' : ',') << "nonatomic";
1087 first = false;
1088 }
1089 if (PDecl->getPropertyAttributes() &
1090 ObjCPropertyDecl::OBJC_PR_atomic) {
1091 Out << (first ? ' ' : ',') << "atomic";
1092 first = false;
1093 }
1094
1095 (void) first; // Silence dead store warning due to idiomatic code.
1096 Out << " )";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001097 }
Fariborz Jahanian88b95212012-12-18 23:02:59 +00001098 Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << *PDecl << ';';
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001099}
1100
1101void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1102 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor64f65002009-05-30 00:56:08 +00001103 Out << "@synthesize ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001104 else
Douglas Gregor64f65002009-05-30 00:56:08 +00001105 Out << "@dynamic ";
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001106 Out << *PID->getPropertyDecl();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001107 if (PID->getPropertyIvarDecl())
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001108 Out << '=' << *PID->getPropertyIvarDecl();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +00001109}
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001110
1111void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1112 Out << "using ";
Douglas Gregordc355712011-02-25 00:36:19 +00001113 D->getQualifier()->print(Out, Policy);
Benjamin Kramerb8989f22011-10-14 18:45:37 +00001114 Out << *D;
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001115}
1116
John McCall7ba107a2009-11-18 02:36:19 +00001117void
1118DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1119 Out << "using typename ";
Douglas Gregordc355712011-02-25 00:36:19 +00001120 D->getQualifier()->print(Out, Policy);
Benjamin Kramer900fc632010-04-17 09:33:03 +00001121 Out << D->getDeclName();
John McCall7ba107a2009-11-18 02:36:19 +00001122}
1123
1124void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001125 Out << "using ";
Douglas Gregordc355712011-02-25 00:36:19 +00001126 D->getQualifier()->print(Out, Policy);
Fariborz Jahanian5e0ea192012-12-06 00:09:40 +00001127 Out << D->getName();
Anders Carlssonf53eaa52009-08-28 19:16:39 +00001128}
John McCall9488ea12009-11-17 05:59:44 +00001129
1130void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1131 // ignore
1132}