blob: a625865ecdb3324f4dec5054eed60e0b00383f88 [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"
15#include "clang/AST/DeclVisitor.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclObjC.h"
19#include "clang/AST/Expr.h"
Douglas Gregor9db7dbb2010-01-31 09:12:51 +000020#include "clang/AST/ExprCXX.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000021#include "clang/AST/PrettyPrinter.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000022#include "llvm/Support/raw_ostream.h"
23using namespace clang;
24
25namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000026 class DeclPrinter : public DeclVisitor<DeclPrinter> {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000027 llvm::raw_ostream &Out;
28 ASTContext &Context;
29 PrintingPolicy Policy;
30 unsigned Indentation;
31
Daniel Dunbar512ce602009-11-21 09:12:06 +000032 llvm::raw_ostream& Indent() { return Indent(Indentation); }
33 llvm::raw_ostream& Indent(unsigned Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +000034 void ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000035
Anders Carlsson0d592922009-08-28 22:39:52 +000036 void Print(AccessSpecifier AS);
Mike Stump1eb44332009-09-09 15:08:12 +000037
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000038 public:
Mike Stump1eb44332009-09-09 15:08:12 +000039 DeclPrinter(llvm::raw_ostream &Out, ASTContext &Context,
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000040 const PrintingPolicy &Policy,
41 unsigned Indentation = 0)
42 : Out(Out), Context(Context), Policy(Policy), Indentation(Indentation) { }
43
44 void VisitDeclContext(DeclContext *DC, bool Indent = true);
45
46 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
47 void VisitTypedefDecl(TypedefDecl *D);
48 void VisitEnumDecl(EnumDecl *D);
49 void VisitRecordDecl(RecordDecl *D);
50 void VisitEnumConstantDecl(EnumConstantDecl *D);
51 void VisitFunctionDecl(FunctionDecl *D);
52 void VisitFieldDecl(FieldDecl *D);
53 void VisitVarDecl(VarDecl *D);
54 void VisitParmVarDecl(ParmVarDecl *D);
55 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregor59e63572009-05-30 06:58:37 +000056 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor8419fa32009-05-30 06:31:56 +000057 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor6c9c9402009-05-30 06:48:27 +000058 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor59e63572009-05-30 06:58:37 +000059 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000060 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
61 void VisitTemplateDecl(TemplateDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000062 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor8419fa32009-05-30 06:31:56 +000063 void VisitObjCClassDecl(ObjCClassDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000064 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
65 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
66 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
67 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
68 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
69 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
70 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
71 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
72 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
John McCall7ba107a2009-11-18 02:36:19 +000073 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
74 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssonf53eaa52009-08-28 19:16:39 +000075 void VisitUsingDecl(UsingDecl *D);
John McCall9488ea12009-11-17 05:59:44 +000076 void VisitUsingShadowDecl(UsingShadowDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000077 };
78}
79
Anders Carlssonf88df862009-09-26 21:58:53 +000080void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) const {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000081 print(Out, getASTContext().PrintingPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000082}
83
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000084void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Anders Carlssonf88df862009-09-26 21:58:53 +000085 unsigned Indentation) const {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000086 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation);
Anders Carlssonf88df862009-09-26 21:58:53 +000087 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000088}
89
Eli Friedman42f42c02009-05-30 04:20:30 +000090static QualType GetBaseType(QualType T) {
91 // FIXME: This should be on the Type class!
92 QualType BaseType = T;
93 while (!BaseType->isSpecifierType()) {
94 if (isa<TypedefType>(BaseType))
95 break;
Ted Kremenek6217b802009-07-29 21:53:49 +000096 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman42f42c02009-05-30 04:20:30 +000097 BaseType = PTy->getPointeeType();
98 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
99 BaseType = ATy->getElementType();
John McCall183700f2009-09-21 23:43:11 +0000100 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Eli Friedman42f42c02009-05-30 04:20:30 +0000101 BaseType = FTy->getResultType();
John McCall183700f2009-09-21 23:43:11 +0000102 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor5068ab62009-07-01 23:58:14 +0000103 BaseType = VTy->getElementType();
Eli Friedman42f42c02009-05-30 04:20:30 +0000104 else
105 assert(0 && "Unknown declarator!");
106 }
107 return BaseType;
108}
109
110static QualType getDeclType(Decl* D) {
111 if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D))
112 return TDD->getUnderlyingType();
113 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
114 return VD->getType();
115 return QualType();
116}
117
118void Decl::printGroup(Decl** Begin, unsigned NumDecls,
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000119 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman42f42c02009-05-30 04:20:30 +0000120 unsigned Indentation) {
121 if (NumDecls == 1) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000122 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000123 return;
124 }
125
126 Decl** End = Begin + NumDecls;
127 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
128 if (TD)
129 ++Begin;
130
131 PrintingPolicy SubPolicy(Policy);
132 if (TD && TD->isDefinition()) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000133 TD->print(Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000134 Out << " ";
135 SubPolicy.SuppressTag = true;
136 }
137
138 bool isFirst = true;
139 for ( ; Begin != End; ++Begin) {
140 if (isFirst) {
141 SubPolicy.SuppressSpecifiers = false;
142 isFirst = false;
143 } else {
144 if (!isFirst) Out << ", ";
145 SubPolicy.SuppressSpecifiers = true;
146 }
147
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000148 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000149 }
150}
151
Anders Carlsson84834432009-12-14 00:51:04 +0000152void DeclContext::dumpDeclContext() const {
Anders Carlsson2b7d8dd2009-12-09 17:27:46 +0000153 // Get the translation unit
154 const DeclContext *DC = this;
155 while (!DC->isTranslationUnit())
156 DC = DC->getParent();
157
158 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
159 DeclPrinter Printer(llvm::errs(), Ctx, Ctx.PrintingPolicy, 0);
160 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
161}
162
Anders Carlssonf88df862009-09-26 21:58:53 +0000163void Decl::dump() const {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000164 print(llvm::errs());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000165}
166
Daniel Dunbar512ce602009-11-21 09:12:06 +0000167llvm::raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
168 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000169 Out << " ";
170 return Out;
171}
172
Eli Friedman42f42c02009-05-30 04:20:30 +0000173void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) {
174 this->Indent();
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000175 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000176 Out << ";\n";
177 Decls.clear();
178
179}
180
Anders Carlsson0d592922009-08-28 22:39:52 +0000181void DeclPrinter::Print(AccessSpecifier AS) {
182 switch(AS) {
Anders Carlsson018e9fe2009-08-29 20:36:12 +0000183 case AS_none: assert(0 && "No access specifier!"); break;
Anders Carlsson0d592922009-08-28 22:39:52 +0000184 case AS_public: Out << "public"; break;
185 case AS_protected: Out << "protected"; break;
186 case AS_private: Out << " private"; break;
187 }
188}
189
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000190//----------------------------------------------------------------------------
191// Common C declarations
192//----------------------------------------------------------------------------
193
194void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
195 if (Indent)
196 Indentation += Policy.Indentation;
197
Anders Carlsson0d592922009-08-28 22:39:52 +0000198 bool PrintAccess = isa<CXXRecordDecl>(DC);
199 AccessSpecifier CurAS = AS_none;
Mike Stump1eb44332009-09-09 15:08:12 +0000200
Eli Friedman42f42c02009-05-30 04:20:30 +0000201 llvm::SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000202 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000203 D != DEnd; ++D) {
Eli Friedman48d14a22009-05-30 05:03:24 +0000204 if (!Policy.Dump) {
205 // Skip over implicit declarations in pretty-printing mode.
206 if (D->isImplicit()) continue;
Eli Friedman3d4a7c92009-05-30 06:35:22 +0000207 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
208 // of __builtin_va_list. There should be some other way to check that.
209 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() ==
210 "__builtin_va_list")
211 continue;
Eli Friedman48d14a22009-05-30 05:03:24 +0000212 }
213
Anders Carlsson0d592922009-08-28 22:39:52 +0000214 if (PrintAccess) {
215 AccessSpecifier AS = D->getAccess();
Anders Carlsson35eda442009-08-29 20:47:47 +0000216
John McCalld7eff682009-09-02 00:55:30 +0000217 if (AS != CurAS) {
Daniel Dunbar512ce602009-11-21 09:12:06 +0000218 if (Indent)
219 this->Indent(Indentation - Policy.Indentation);
Anders Carlsson0d592922009-08-28 22:39:52 +0000220 Print(AS);
221 Out << ":\n";
222 CurAS = AS;
223 }
224 }
Mike Stump1eb44332009-09-09 15:08:12 +0000225
Eli Friedman42f42c02009-05-30 04:20:30 +0000226 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
227 // forced to merge the declarations because there's no other way to
228 // refer to the struct in question. This limited merging is safe without
229 // a bunch of other checks because it only merges declarations directly
230 // referring to the tag, not typedefs.
231 //
232 // Check whether the current declaration should be grouped with a previous
233 // unnamed struct.
234 QualType CurDeclType = getDeclType(*D);
235 if (!Decls.empty() && !CurDeclType.isNull()) {
236 QualType BaseType = GetBaseType(CurDeclType);
237 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
238 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
239 Decls.push_back(*D);
240 continue;
241 }
242 }
243
244 // If we have a merged group waiting to be handled, handle it now.
245 if (!Decls.empty())
246 ProcessDeclGroup(Decls);
247
248 // If the current declaration is an unnamed tag type, save it
249 // so we can merge it with the subsequent declaration(s) using it.
250 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
251 Decls.push_back(*D);
252 continue;
253 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000254 this->Indent();
255 Visit(*D);
Mike Stump1eb44332009-09-09 15:08:12 +0000256
257 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000258 const char *Terminator = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000259 if (isa<FunctionDecl>(*D) &&
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000260 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
261 Terminator = 0;
Douglas Gregor64f65002009-05-30 00:56:08 +0000262 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
263 Terminator = 0;
264 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump1eb44332009-09-09 15:08:12 +0000265 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor64f65002009-05-30 00:56:08 +0000266 isa<ObjCInterfaceDecl>(*D) ||
267 isa<ObjCProtocolDecl>(*D) ||
268 isa<ObjCCategoryImplDecl>(*D) ||
269 isa<ObjCCategoryDecl>(*D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000270 Terminator = 0;
271 else if (isa<EnumConstantDecl>(*D)) {
272 DeclContext::decl_iterator Next = D;
273 ++Next;
274 if (Next != DEnd)
275 Terminator = ",";
276 } else
277 Terminator = ";";
278
279 if (Terminator)
280 Out << Terminator;
281 Out << "\n";
282 }
283
Eli Friedman42f42c02009-05-30 04:20:30 +0000284 if (!Decls.empty())
285 ProcessDeclGroup(Decls);
286
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000287 if (Indent)
288 Indentation -= Policy.Indentation;
289}
290
291void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
292 VisitDeclContext(D, false);
293}
294
295void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
296 std::string S = D->getNameAsString();
297 D->getUnderlyingType().getAsStringInternal(S, Policy);
Eli Friedman42f42c02009-05-30 04:20:30 +0000298 if (!Policy.SuppressSpecifiers)
299 Out << "typedef ";
300 Out << S;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000301}
302
303void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
304 Out << "enum " << D->getNameAsString() << " {\n";
305 VisitDeclContext(D);
306 Indent() << "}";
307}
308
309void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000310 Out << D->getKindName();
Eli Friedman42f42c02009-05-30 04:20:30 +0000311 if (D->getIdentifier()) {
312 Out << " ";
313 Out << D->getNameAsString();
314 }
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000316 if (D->isDefinition()) {
317 Out << " {\n";
318 VisitDeclContext(D);
319 Indent() << "}";
320 }
321}
322
323void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
324 Out << D->getNameAsString();
325 if (Expr *Init = D->getInitExpr()) {
326 Out << " = ";
Eli Friedman48d14a22009-05-30 05:03:24 +0000327 Init->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000328 }
329}
330
Mike Stump1eb44332009-09-09 15:08:12 +0000331void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000332 if (!Policy.SuppressSpecifiers) {
333 switch (D->getStorageClass()) {
334 case FunctionDecl::None: break;
335 case FunctionDecl::Extern: Out << "extern "; break;
336 case FunctionDecl::Static: Out << "static "; break;
337 case FunctionDecl::PrivateExtern: Out << "__private_extern__ "; break;
338 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000339
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000340 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman42f42c02009-05-30 04:20:30 +0000341 if (D->isVirtualAsWritten()) Out << "virtual ";
342 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000343
Douglas Gregor6620a622009-05-30 05:39:39 +0000344 PrintingPolicy SubPolicy(Policy);
345 SubPolicy.SuppressSpecifiers = false;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000346 std::string Proto = D->getNameAsString();
347 if (isa<FunctionType>(D->getType().getTypePtr())) {
John McCall183700f2009-09-21 23:43:11 +0000348 const FunctionType *AFT = D->getType()->getAs<FunctionType>();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000349
350 const FunctionProtoType *FT = 0;
351 if (D->hasWrittenPrototype())
352 FT = dyn_cast<FunctionProtoType>(AFT);
353
354 Proto += "(";
355 if (FT) {
356 llvm::raw_string_ostream POut(Proto);
Douglas Gregor6620a622009-05-30 05:39:39 +0000357 DeclPrinter ParamPrinter(POut, Context, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000358 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
359 if (i) POut << ", ";
360 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
361 }
Mike Stump1eb44332009-09-09 15:08:12 +0000362
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000363 if (FT->isVariadic()) {
364 if (D->getNumParams()) POut << ", ";
365 POut << "...";
366 }
Eli Friedman42f42c02009-05-30 04:20:30 +0000367 } else if (D->isThisDeclarationADefinition() && !D->hasPrototype()) {
368 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
369 if (i)
370 Proto += ", ";
371 Proto += D->getParamDecl(i)->getNameAsString();
372 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000373 }
374
375 Proto += ")";
Douglas Gregor0ae7b3f2009-12-08 17:45:32 +0000376
377 if (FT && FT->hasExceptionSpec()) {
378 Proto += " throw(";
379 if (FT->hasAnyExceptionSpec())
380 Proto += "...";
381 else
382 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
383 if (I)
384 Proto += ", ";
385
386
387 std::string ExceptionType;
388 FT->getExceptionType(I).getAsStringInternal(ExceptionType, SubPolicy);
389 Proto += ExceptionType;
390 }
391 Proto += ")";
392 }
393
Mike Stumpfd350b52009-07-27 21:33:40 +0000394 if (D->hasAttr<NoReturnAttr>())
395 Proto += " __attribute((noreturn))";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000396 if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
397 if (CDecl->getNumBaseOrMemberInitializers() > 0) {
398 Proto += " : ";
399 Out << Proto;
400 Proto.clear();
Mike Stump1eb44332009-09-09 15:08:12 +0000401 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000402 E = CDecl->init_end();
403 B != E; ++B) {
404 CXXBaseOrMemberInitializer * BMInitializer = (*B);
405 if (B != CDecl->init_begin())
406 Out << ", ";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000407 if (BMInitializer->isMemberInitializer()) {
408 FieldDecl *FD = BMInitializer->getMember();
409 Out << FD->getNameAsString();
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000410 } else {
411 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString();
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000412 }
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000413
414 Out << "(";
415 if (!BMInitializer->getInit()) {
416 // Nothing to print
417 } else {
418 Expr *Init = BMInitializer->getInit();
419 if (CXXExprWithTemporaries *Tmp
420 = dyn_cast<CXXExprWithTemporaries>(Init))
421 Init = Tmp->getSubExpr();
422
423 Init = Init->IgnoreParens();
424
425 Expr *SimpleInit = 0;
426 Expr **Args = 0;
427 unsigned NumArgs = 0;
428 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
429 Args = ParenList->getExprs();
430 NumArgs = ParenList->getNumExprs();
431 } else if (CXXConstructExpr *Construct
432 = dyn_cast<CXXConstructExpr>(Init)) {
433 Args = Construct->getArgs();
434 NumArgs = Construct->getNumArgs();
435 } else
436 SimpleInit = Init;
437
438 if (SimpleInit)
439 SimpleInit->printPretty(Out, Context, 0, Policy, Indentation);
440 else {
441 for (unsigned I = 0; I != NumArgs; ++I) {
442 if (isa<CXXDefaultArgExpr>(Args[I]))
443 break;
444
445 if (I)
446 Out << ", ";
447 Args[I]->printPretty(Out, Context, 0, Policy, Indentation);
448 }
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000449 }
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000450 }
451 Out << ")";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000452 }
453 }
454 }
455 else
456 AFT->getResultType().getAsStringInternal(Proto, Policy);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000457 } else {
458 D->getType().getAsStringInternal(Proto, Policy);
459 }
460
461 Out << Proto;
462
463 if (D->isPure())
464 Out << " = 0";
465 else if (D->isDeleted())
466 Out << " = delete";
467 else if (D->isThisDeclarationADefinition()) {
468 if (!D->hasPrototype() && D->getNumParams()) {
469 // This is a K&R function definition, so we need to print the
470 // parameters.
471 Out << '\n';
Douglas Gregor6620a622009-05-30 05:39:39 +0000472 DeclPrinter ParamPrinter(Out, Context, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000473 Indentation += Policy.Indentation;
474 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
475 Indent();
Douglas Gregor6620a622009-05-30 05:39:39 +0000476 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000477 Out << ";\n";
478 }
479 Indentation -= Policy.Indentation;
480 } else
481 Out << ' ';
482
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000483 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000484 Out << '\n';
485 }
486}
487
488void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000489 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000490 Out << "mutable ";
491
492 std::string Name = D->getNameAsString();
493 D->getType().getAsStringInternal(Name, Policy);
494 Out << Name;
495
496 if (D->isBitField()) {
497 Out << " : ";
Eli Friedman48d14a22009-05-30 05:03:24 +0000498 D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000499 }
500}
501
502void DeclPrinter::VisitVarDecl(VarDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000503 if (!Policy.SuppressSpecifiers && D->getStorageClass() != VarDecl::None)
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000504 Out << VarDecl::getStorageClassSpecifierString(D->getStorageClass()) << " ";
505
Eli Friedman42f42c02009-05-30 04:20:30 +0000506 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000507 Out << "__thread ";
508
509 std::string Name = D->getNameAsString();
510 QualType T = D->getType();
John McCall58e46772009-10-23 21:48:59 +0000511 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000512 T = Parm->getOriginalType();
513 T.getAsStringInternal(Name, Policy);
514 Out << Name;
515 if (D->getInit()) {
516 if (D->hasCXXDirectInitializer())
517 Out << "(";
518 else
519 Out << " = ";
Eli Friedman48d14a22009-05-30 05:03:24 +0000520 D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000521 if (D->hasCXXDirectInitializer())
522 Out << ")";
523 }
524}
525
526void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
527 VisitVarDecl(D);
528}
529
530void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
531 Out << "__asm (";
Eli Friedman48d14a22009-05-30 05:03:24 +0000532 D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000533 Out << ")";
534}
535
536//----------------------------------------------------------------------------
537// C++ declarations
538//----------------------------------------------------------------------------
Douglas Gregor59e63572009-05-30 06:58:37 +0000539void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
540 Out << "namespace " << D->getNameAsString() << " {\n";
541 VisitDeclContext(D);
542 Indent() << "}";
543}
544
Douglas Gregor8419fa32009-05-30 06:31:56 +0000545void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
546 Out << "using namespace ";
547 if (D->getQualifier())
548 D->getQualifier()->print(Out, Policy);
Sebastian Redleb0d8c92009-11-23 15:34:23 +0000549 Out << D->getNominatedNamespaceAsWritten()->getNameAsString();
Douglas Gregor8419fa32009-05-30 06:31:56 +0000550}
551
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000552void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
553 Out << "namespace " << D->getNameAsString() << " = ";
554 if (D->getQualifier())
555 D->getQualifier()->print(Out, Policy);
556 Out << D->getAliasedNamespace()->getNameAsString();
557}
558
Douglas Gregor59e63572009-05-30 06:58:37 +0000559void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
560 Out << D->getKindName();
561 if (D->getIdentifier()) {
562 Out << " ";
563 Out << D->getNameAsString();
564 }
Mike Stump1eb44332009-09-09 15:08:12 +0000565
Douglas Gregor59e63572009-05-30 06:58:37 +0000566 if (D->isDefinition()) {
567 // Print the base classes
568 if (D->getNumBases()) {
569 Out << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000570 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
571 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor59e63572009-05-30 06:58:37 +0000572 if (Base != D->bases_begin())
573 Out << ", ";
574
575 if (Base->isVirtual())
576 Out << "virtual ";
577
Anders Carlsson018e9fe2009-08-29 20:36:12 +0000578 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
579 if (AS != AS_none)
580 Print(AS);
Anders Carlsson0d592922009-08-28 22:39:52 +0000581 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor59e63572009-05-30 06:58:37 +0000582 }
583 }
584
585 // Print the class definition
Douglas Gregorf757ae72009-05-31 07:13:39 +0000586 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor59e63572009-05-30 06:58:37 +0000587 Out << " {\n";
588 VisitDeclContext(D);
589 Indent() << "}";
Mike Stump1eb44332009-09-09 15:08:12 +0000590 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000591}
592
593void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
594 const char *l;
595 if (D->getLanguage() == LinkageSpecDecl::lang_c)
596 l = "C";
597 else {
598 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
599 "unknown language in linkage specification");
600 l = "C++";
601 }
602
603 Out << "extern \"" << l << "\" ";
604 if (D->hasBraces()) {
605 Out << "{\n";
606 VisitDeclContext(D);
607 Indent() << "}";
608 } else
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000609 Visit(*D->decls_begin());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000610}
611
612void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
Anders Carlsson0487f662009-06-04 05:37:43 +0000613 Out << "template <";
Mike Stump1eb44332009-09-09 15:08:12 +0000614
Anders Carlsson0487f662009-06-04 05:37:43 +0000615 TemplateParameterList *Params = D->getTemplateParameters();
616 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
617 if (i != 0)
618 Out << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000619
Anders Carlsson0487f662009-06-04 05:37:43 +0000620 const Decl *Param = Params->getParam(i);
Mike Stump1eb44332009-09-09 15:08:12 +0000621 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000622 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000623
624 QualType ParamType =
Anders Carlsson0487f662009-06-04 05:37:43 +0000625 Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP));
626
627 if (TTP->wasDeclaredWithTypename())
628 Out << "typename ";
629 else
630 Out << "class ";
631
Anders Carlsson6d845ae2009-06-12 22:23:22 +0000632 if (TTP->isParameterPack())
633 Out << "... ";
Mike Stump1eb44332009-09-09 15:08:12 +0000634
Anders Carlsson0487f662009-06-04 05:37:43 +0000635 Out << ParamType.getAsString(Policy);
636
637 if (TTP->hasDefaultArgument()) {
638 Out << " = ";
639 Out << TTP->getDefaultArgument().getAsString(Policy);
640 };
Mike Stump1eb44332009-09-09 15:08:12 +0000641 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000642 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
643 Out << NTTP->getType().getAsString(Policy);
644
645 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
646 Out << ' ';
647 Out << Name->getName();
648 }
Mike Stump1eb44332009-09-09 15:08:12 +0000649
Anders Carlsson0487f662009-06-04 05:37:43 +0000650 if (NTTP->hasDefaultArgument()) {
651 Out << " = ";
Mike Stump1eb44332009-09-09 15:08:12 +0000652 NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy,
Anders Carlsson0487f662009-06-04 05:37:43 +0000653 Indentation);
654 }
655 }
656 }
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Anders Carlsson0487f662009-06-04 05:37:43 +0000658 Out << "> ";
659
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000660 Visit(D->getTemplatedDecl());
661}
662
663//----------------------------------------------------------------------------
664// Objective-C declarations
665//----------------------------------------------------------------------------
666
667void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
668 Out << "@class ";
669 for (ObjCClassDecl::iterator I = D->begin(), E = D->end();
670 I != E; ++I) {
671 if (I != D->begin()) Out << ", ";
Ted Kremenek321c22f2009-11-18 00:28:11 +0000672 Out << I->getInterface()->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000673 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000674}
675
676void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
677 if (OMD->isInstanceMethod())
Douglas Gregor64f65002009-05-30 00:56:08 +0000678 Out << "- ";
Mike Stump1eb44332009-09-09 15:08:12 +0000679 else
Douglas Gregor64f65002009-05-30 00:56:08 +0000680 Out << "+ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000681 if (!OMD->getResultType().isNull())
Douglas Gregor59e63572009-05-30 06:58:37 +0000682 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000684 std::string name = OMD->getSelector().getAsString();
685 std::string::size_type pos, lastPos = 0;
686 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
687 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump1eb44332009-09-09 15:08:12 +0000688 // FIXME: selector is missing here!
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000689 pos = name.find_first_of(":", lastPos);
690 Out << " " << name.substr(lastPos, pos - lastPos);
Douglas Gregor59e63572009-05-30 06:58:37 +0000691 Out << ":(" << (*PI)->getType().getAsString(Policy) << ")"
Mike Stump1eb44332009-09-09 15:08:12 +0000692 << (*PI)->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000693 lastPos = pos + 1;
694 }
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000696 if (OMD->param_begin() == OMD->param_end())
697 Out << " " << name;
Mike Stump1eb44332009-09-09 15:08:12 +0000698
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000699 if (OMD->isVariadic())
700 Out << ", ...";
Mike Stump1eb44332009-09-09 15:08:12 +0000701
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000702 if (OMD->getBody()) {
703 Out << ' ';
Eli Friedman48d14a22009-05-30 05:03:24 +0000704 OMD->getBody()->printPretty(Out, Context, 0, Policy);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000705 Out << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000706 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000707}
708
709void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
710 std::string I = OID->getNameAsString();
711 ObjCInterfaceDecl *SID = OID->getSuperClass();
712
713 if (SID)
714 Out << "@implementation " << I << " : " << SID->getNameAsString();
715 else
716 Out << "@implementation " << I;
Douglas Gregor64f65002009-05-30 00:56:08 +0000717 Out << "\n";
718 VisitDeclContext(OID, false);
719 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000720}
721
722void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
723 std::string I = OID->getNameAsString();
724 ObjCInterfaceDecl *SID = OID->getSuperClass();
725
726 if (SID)
727 Out << "@interface " << I << " : " << SID->getNameAsString();
728 else
729 Out << "@interface " << I;
Mike Stump1eb44332009-09-09 15:08:12 +0000730
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000731 // Protocols?
732 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
733 if (!Protocols.empty()) {
734 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
735 E = Protocols.end(); I != E; ++I)
736 Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString();
737 }
Mike Stump1eb44332009-09-09 15:08:12 +0000738
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000739 if (!Protocols.empty())
Douglas Gregor64f65002009-05-30 00:56:08 +0000740 Out << "> ";
Mike Stump1eb44332009-09-09 15:08:12 +0000741
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000742 if (OID->ivar_size() > 0) {
Douglas Gregor64f65002009-05-30 00:56:08 +0000743 Out << "{\n";
744 Indentation += Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000745 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
746 E = OID->ivar_end(); I != E; ++I) {
Douglas Gregor64f65002009-05-30 00:56:08 +0000747 Indent() << (*I)->getType().getAsString(Policy)
Mike Stump1eb44332009-09-09 15:08:12 +0000748 << ' ' << (*I)->getNameAsString() << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000749 }
Douglas Gregor64f65002009-05-30 00:56:08 +0000750 Indentation -= Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000751 Out << "}\n";
752 }
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000754 VisitDeclContext(OID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000755 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000756 // FIXME: implement the rest...
757}
758
759void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
760 Out << "@protocol ";
Mike Stump1eb44332009-09-09 15:08:12 +0000761 for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(),
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000762 E = D->protocol_end();
763 I != E; ++I) {
764 if (I != D->protocol_begin()) Out << ", ";
765 Out << (*I)->getNameAsString();
766 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000767}
768
769void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
770 Out << "@protocol " << PID->getNameAsString() << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000771 VisitDeclContext(PID, false);
772 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000773}
774
775void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
776 Out << "@implementation "
777 << PID->getClassInterface()->getNameAsString()
Mike Stump1eb44332009-09-09 15:08:12 +0000778 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000779
780 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000781 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000782 // FIXME: implement the rest...
783}
784
785void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Mike Stump1eb44332009-09-09 15:08:12 +0000786 Out << "@interface "
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000787 << PID->getClassInterface()->getNameAsString()
Douglas Gregor64f65002009-05-30 00:56:08 +0000788 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000789 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000790 Out << "@end";
Mike Stump1eb44332009-09-09 15:08:12 +0000791
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000792 // FIXME: implement the rest...
793}
794
795void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Mike Stump1eb44332009-09-09 15:08:12 +0000796 Out << "@compatibility_alias " << AID->getNameAsString()
797 << ' ' << AID->getClassInterface()->getNameAsString() << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000798}
799
800/// PrintObjCPropertyDecl - print a property declaration.
801///
802void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
803 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
804 Out << "@required\n";
805 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
806 Out << "@optional\n";
Mike Stump1eb44332009-09-09 15:08:12 +0000807
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000808 Out << "@property";
809 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
810 bool first = true;
811 Out << " (";
Mike Stump1eb44332009-09-09 15:08:12 +0000812 if (PDecl->getPropertyAttributes() &
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000813 ObjCPropertyDecl::OBJC_PR_readonly) {
814 Out << (first ? ' ' : ',') << "readonly";
815 first = false;
816 }
Mike Stump1eb44332009-09-09 15:08:12 +0000817
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000818 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
819 Out << (first ? ' ' : ',') << "getter = "
820 << PDecl->getGetterName().getAsString();
821 first = false;
822 }
823 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
824 Out << (first ? ' ' : ',') << "setter = "
825 << PDecl->getSetterName().getAsString();
826 first = false;
827 }
Mike Stump1eb44332009-09-09 15:08:12 +0000828
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000829 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
830 Out << (first ? ' ' : ',') << "assign";
831 first = false;
832 }
Mike Stump1eb44332009-09-09 15:08:12 +0000833
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000834 if (PDecl->getPropertyAttributes() &
835 ObjCPropertyDecl::OBJC_PR_readwrite) {
836 Out << (first ? ' ' : ',') << "readwrite";
837 first = false;
838 }
Mike Stump1eb44332009-09-09 15:08:12 +0000839
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000840 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
841 Out << (first ? ' ' : ',') << "retain";
842 first = false;
843 }
Mike Stump1eb44332009-09-09 15:08:12 +0000844
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000845 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
846 Out << (first ? ' ' : ',') << "copy";
847 first = false;
848 }
Mike Stump1eb44332009-09-09 15:08:12 +0000849
850 if (PDecl->getPropertyAttributes() &
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000851 ObjCPropertyDecl::OBJC_PR_nonatomic) {
852 Out << (first ? ' ' : ',') << "nonatomic";
853 first = false;
854 }
855 Out << " )";
856 }
857 Out << ' ' << PDecl->getType().getAsString(Policy)
858 << ' ' << PDecl->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000859}
860
861void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
862 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor64f65002009-05-30 00:56:08 +0000863 Out << "@synthesize ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000864 else
Douglas Gregor64f65002009-05-30 00:56:08 +0000865 Out << "@dynamic ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000866 Out << PID->getPropertyDecl()->getNameAsString();
867 if (PID->getPropertyIvarDecl())
868 Out << "=" << PID->getPropertyIvarDecl()->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000869}
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000870
871void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
872 Out << "using ";
873 D->getTargetNestedNameDecl()->print(Out, Policy);
John McCall9488ea12009-11-17 05:59:44 +0000874 Out << D->getNameAsString();
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000875}
876
John McCall7ba107a2009-11-18 02:36:19 +0000877void
878DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
879 Out << "using typename ";
880 D->getTargetNestedNameSpecifier()->print(Out, Policy);
881 Out << D->getDeclName().getAsString();
882}
883
884void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000885 Out << "using ";
886 D->getTargetNestedNameSpecifier()->print(Out, Policy);
John McCall7ba107a2009-11-18 02:36:19 +0000887 Out << D->getDeclName().getAsString();
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000888}
John McCall9488ea12009-11-17 05:59:44 +0000889
890void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
891 // ignore
892}