blob: a5982cfd97f111901c2f45f7691b7b9f60804764 [file] [log] [blame]
Douglas Gregor278f52e2009-05-30 00:08:05 +00001//===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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"
20#include "clang/AST/PrettyPrinter.h"
Douglas Gregor278f52e2009-05-30 00:08:05 +000021#include "llvm/Support/raw_ostream.h"
22using namespace clang;
23
24namespace {
Benjamin Kramer26222b62009-11-28 19:03:38 +000025 class DeclPrinter : public DeclVisitor<DeclPrinter> {
Douglas Gregor278f52e2009-05-30 00:08:05 +000026 llvm::raw_ostream &Out;
27 ASTContext &Context;
28 PrintingPolicy Policy;
29 unsigned Indentation;
30
Daniel Dunbar671f45e2009-11-21 09:12:06 +000031 llvm::raw_ostream& Indent() { return Indent(Indentation); }
32 llvm::raw_ostream& Indent(unsigned Indentation);
Eli Friedman79635842009-05-30 04:20:30 +000033 void ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls);
Douglas Gregor278f52e2009-05-30 00:08:05 +000034
Anders Carlsson601d6e42009-08-28 22:39:52 +000035 void Print(AccessSpecifier AS);
Mike Stump11289f42009-09-09 15:08:12 +000036
Douglas Gregor278f52e2009-05-30 00:08:05 +000037 public:
Mike Stump11289f42009-09-09 15:08:12 +000038 DeclPrinter(llvm::raw_ostream &Out, ASTContext &Context,
Douglas Gregor278f52e2009-05-30 00:08:05 +000039 const PrintingPolicy &Policy,
40 unsigned Indentation = 0)
41 : Out(Out), Context(Context), Policy(Policy), Indentation(Indentation) { }
42
43 void VisitDeclContext(DeclContext *DC, bool Indent = true);
44
45 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
46 void VisitTypedefDecl(TypedefDecl *D);
47 void VisitEnumDecl(EnumDecl *D);
48 void VisitRecordDecl(RecordDecl *D);
49 void VisitEnumConstantDecl(EnumConstantDecl *D);
50 void VisitFunctionDecl(FunctionDecl *D);
51 void VisitFieldDecl(FieldDecl *D);
52 void VisitVarDecl(VarDecl *D);
53 void VisitParmVarDecl(ParmVarDecl *D);
54 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000055 void VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000056 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000057 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor18231932009-05-30 06:48:27 +000058 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000059 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000060 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
61 void VisitTemplateDecl(TemplateDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000062 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000063 void VisitObjCClassDecl(ObjCClassDecl *D);
Douglas Gregor278f52e2009-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 McCalle61f2ba2009-11-18 02:36:19 +000073 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
74 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssondf5a1c82009-08-28 19:16:39 +000075 void VisitUsingDecl(UsingDecl *D);
John McCall3f746822009-11-17 05:59:44 +000076 void VisitUsingShadowDecl(UsingShadowDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000077 };
78}
79
Anders Carlsson46f87dc2009-09-26 21:58:53 +000080void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) const {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +000081 print(Out, getASTContext().PrintingPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +000082}
83
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +000084void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Anders Carlsson46f87dc2009-09-26 21:58:53 +000085 unsigned Indentation) const {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +000086 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation);
Anders Carlsson46f87dc2009-09-26 21:58:53 +000087 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor278f52e2009-05-30 00:08:05 +000088}
89
Eli Friedman79635842009-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 Kremenekc23c7e62009-07-29 21:53:49 +000096 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman79635842009-05-30 04:20:30 +000097 BaseType = PTy->getPointeeType();
98 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
99 BaseType = ATy->getElementType();
John McCall9dd450b2009-09-21 23:43:11 +0000100 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Eli Friedman79635842009-05-30 04:20:30 +0000101 BaseType = FTy->getResultType();
John McCall9dd450b2009-09-21 23:43:11 +0000102 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor15548252009-07-01 23:58:14 +0000103 BaseType = VTy->getElementType();
Eli Friedman79635842009-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 Kyrtzidis8a803cc2009-06-30 02:35:04 +0000119 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman79635842009-05-30 04:20:30 +0000120 unsigned Indentation) {
121 if (NumDecls == 1) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000122 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman79635842009-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 Kyrtzidis8a803cc2009-06-30 02:35:04 +0000133 TD->print(Out, Policy, Indentation);
Eli Friedman79635842009-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 Kyrtzidis8a803cc2009-06-30 02:35:04 +0000148 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000149 }
150}
151
Anders Carlsson46f87dc2009-09-26 21:58:53 +0000152void Decl::dump() const {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000153 print(llvm::errs());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000154}
155
Daniel Dunbar671f45e2009-11-21 09:12:06 +0000156llvm::raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
157 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000158 Out << " ";
159 return Out;
160}
161
Eli Friedman79635842009-05-30 04:20:30 +0000162void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) {
163 this->Indent();
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000164 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000165 Out << ";\n";
166 Decls.clear();
167
168}
169
Anders Carlsson601d6e42009-08-28 22:39:52 +0000170void DeclPrinter::Print(AccessSpecifier AS) {
171 switch(AS) {
Anders Carlsson6df9e072009-08-29 20:36:12 +0000172 case AS_none: assert(0 && "No access specifier!"); break;
Anders Carlsson601d6e42009-08-28 22:39:52 +0000173 case AS_public: Out << "public"; break;
174 case AS_protected: Out << "protected"; break;
175 case AS_private: Out << " private"; break;
176 }
177}
178
Douglas Gregor278f52e2009-05-30 00:08:05 +0000179//----------------------------------------------------------------------------
180// Common C declarations
181//----------------------------------------------------------------------------
182
183void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
184 if (Indent)
185 Indentation += Policy.Indentation;
186
Anders Carlsson601d6e42009-08-28 22:39:52 +0000187 bool PrintAccess = isa<CXXRecordDecl>(DC);
188 AccessSpecifier CurAS = AS_none;
Mike Stump11289f42009-09-09 15:08:12 +0000189
Eli Friedman79635842009-05-30 04:20:30 +0000190 llvm::SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000191 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000192 D != DEnd; ++D) {
Eli Friedmanef334fd2009-05-30 05:03:24 +0000193 if (!Policy.Dump) {
194 // Skip over implicit declarations in pretty-printing mode.
195 if (D->isImplicit()) continue;
Eli Friedman17304242009-05-30 06:35:22 +0000196 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
197 // of __builtin_va_list. There should be some other way to check that.
198 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() ==
199 "__builtin_va_list")
200 continue;
Eli Friedmanef334fd2009-05-30 05:03:24 +0000201 }
202
Anders Carlsson601d6e42009-08-28 22:39:52 +0000203 if (PrintAccess) {
204 AccessSpecifier AS = D->getAccess();
Anders Carlssonadf36b22009-08-29 20:47:47 +0000205
John McCall2dc078f2009-09-02 00:55:30 +0000206 if (AS != CurAS) {
Daniel Dunbar671f45e2009-11-21 09:12:06 +0000207 if (Indent)
208 this->Indent(Indentation - Policy.Indentation);
Anders Carlsson601d6e42009-08-28 22:39:52 +0000209 Print(AS);
210 Out << ":\n";
211 CurAS = AS;
212 }
213 }
Mike Stump11289f42009-09-09 15:08:12 +0000214
Eli Friedman79635842009-05-30 04:20:30 +0000215 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
216 // forced to merge the declarations because there's no other way to
217 // refer to the struct in question. This limited merging is safe without
218 // a bunch of other checks because it only merges declarations directly
219 // referring to the tag, not typedefs.
220 //
221 // Check whether the current declaration should be grouped with a previous
222 // unnamed struct.
223 QualType CurDeclType = getDeclType(*D);
224 if (!Decls.empty() && !CurDeclType.isNull()) {
225 QualType BaseType = GetBaseType(CurDeclType);
226 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
227 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
228 Decls.push_back(*D);
229 continue;
230 }
231 }
232
233 // If we have a merged group waiting to be handled, handle it now.
234 if (!Decls.empty())
235 ProcessDeclGroup(Decls);
236
237 // If the current declaration is an unnamed tag type, save it
238 // so we can merge it with the subsequent declaration(s) using it.
239 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
240 Decls.push_back(*D);
241 continue;
242 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000243 this->Indent();
244 Visit(*D);
Mike Stump11289f42009-09-09 15:08:12 +0000245
246 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor278f52e2009-05-30 00:08:05 +0000247 const char *Terminator = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000248 if (isa<FunctionDecl>(*D) &&
Douglas Gregor278f52e2009-05-30 00:08:05 +0000249 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
250 Terminator = 0;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000251 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
252 Terminator = 0;
253 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump11289f42009-09-09 15:08:12 +0000254 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor36098ff2009-05-30 00:56:08 +0000255 isa<ObjCInterfaceDecl>(*D) ||
256 isa<ObjCProtocolDecl>(*D) ||
257 isa<ObjCCategoryImplDecl>(*D) ||
258 isa<ObjCCategoryDecl>(*D))
Douglas Gregor278f52e2009-05-30 00:08:05 +0000259 Terminator = 0;
260 else if (isa<EnumConstantDecl>(*D)) {
261 DeclContext::decl_iterator Next = D;
262 ++Next;
263 if (Next != DEnd)
264 Terminator = ",";
265 } else
266 Terminator = ";";
267
268 if (Terminator)
269 Out << Terminator;
270 Out << "\n";
271 }
272
Eli Friedman79635842009-05-30 04:20:30 +0000273 if (!Decls.empty())
274 ProcessDeclGroup(Decls);
275
Douglas Gregor278f52e2009-05-30 00:08:05 +0000276 if (Indent)
277 Indentation -= Policy.Indentation;
278}
279
280void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
281 VisitDeclContext(D, false);
282}
283
284void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
285 std::string S = D->getNameAsString();
286 D->getUnderlyingType().getAsStringInternal(S, Policy);
Eli Friedman79635842009-05-30 04:20:30 +0000287 if (!Policy.SuppressSpecifiers)
288 Out << "typedef ";
289 Out << S;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000290}
291
292void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
293 Out << "enum " << D->getNameAsString() << " {\n";
294 VisitDeclContext(D);
295 Indent() << "}";
296}
297
298void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor278f52e2009-05-30 00:08:05 +0000299 Out << D->getKindName();
Eli Friedman79635842009-05-30 04:20:30 +0000300 if (D->getIdentifier()) {
301 Out << " ";
302 Out << D->getNameAsString();
303 }
Mike Stump11289f42009-09-09 15:08:12 +0000304
Douglas Gregor278f52e2009-05-30 00:08:05 +0000305 if (D->isDefinition()) {
306 Out << " {\n";
307 VisitDeclContext(D);
308 Indent() << "}";
309 }
310}
311
312void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
313 Out << D->getNameAsString();
314 if (Expr *Init = D->getInitExpr()) {
315 Out << " = ";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000316 Init->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000317 }
318}
319
Mike Stump11289f42009-09-09 15:08:12 +0000320void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000321 if (!Policy.SuppressSpecifiers) {
322 switch (D->getStorageClass()) {
323 case FunctionDecl::None: break;
324 case FunctionDecl::Extern: Out << "extern "; break;
325 case FunctionDecl::Static: Out << "static "; break;
326 case FunctionDecl::PrivateExtern: Out << "__private_extern__ "; break;
327 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000328
Douglas Gregor35b57532009-10-27 21:01:01 +0000329 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman79635842009-05-30 04:20:30 +0000330 if (D->isVirtualAsWritten()) Out << "virtual ";
331 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000332
Douglas Gregor2d042f12009-05-30 05:39:39 +0000333 PrintingPolicy SubPolicy(Policy);
334 SubPolicy.SuppressSpecifiers = false;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000335 std::string Proto = D->getNameAsString();
336 if (isa<FunctionType>(D->getType().getTypePtr())) {
John McCall9dd450b2009-09-21 23:43:11 +0000337 const FunctionType *AFT = D->getType()->getAs<FunctionType>();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000338
339 const FunctionProtoType *FT = 0;
340 if (D->hasWrittenPrototype())
341 FT = dyn_cast<FunctionProtoType>(AFT);
342
343 Proto += "(";
344 if (FT) {
345 llvm::raw_string_ostream POut(Proto);
Douglas Gregor2d042f12009-05-30 05:39:39 +0000346 DeclPrinter ParamPrinter(POut, Context, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000347 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
348 if (i) POut << ", ";
349 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
350 }
Mike Stump11289f42009-09-09 15:08:12 +0000351
Douglas Gregor278f52e2009-05-30 00:08:05 +0000352 if (FT->isVariadic()) {
353 if (D->getNumParams()) POut << ", ";
354 POut << "...";
355 }
Eli Friedman79635842009-05-30 04:20:30 +0000356 } else if (D->isThisDeclarationADefinition() && !D->hasPrototype()) {
357 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
358 if (i)
359 Proto += ", ";
360 Proto += D->getParamDecl(i)->getNameAsString();
361 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000362 }
363
364 Proto += ")";
Mike Stump9a9e0c22009-07-27 21:33:40 +0000365 if (D->hasAttr<NoReturnAttr>())
366 Proto += " __attribute((noreturn))";
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000367 if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
368 if (CDecl->getNumBaseOrMemberInitializers() > 0) {
369 Proto += " : ";
370 Out << Proto;
371 Proto.clear();
Mike Stump11289f42009-09-09 15:08:12 +0000372 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000373 E = CDecl->init_end();
374 B != E; ++B) {
375 CXXBaseOrMemberInitializer * BMInitializer = (*B);
376 if (B != CDecl->init_begin())
377 Out << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000378 bool hasArguments = (BMInitializer->arg_begin() !=
Fariborz Jahanian2a1b5af12009-07-24 17:57:02 +0000379 BMInitializer->arg_end());
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000380 if (BMInitializer->isMemberInitializer()) {
381 FieldDecl *FD = BMInitializer->getMember();
382 Out << FD->getNameAsString();
383 }
Fariborz Jahaniandfbd05d2009-07-14 23:41:35 +0000384 else // FIXME. skip dependent types for now.
Mike Stump11289f42009-09-09 15:08:12 +0000385 if (const RecordType *RT =
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000386 BMInitializer->getBaseClass()->getAs<RecordType>()) {
Mike Stump11289f42009-09-09 15:08:12 +0000387 const CXXRecordDecl *BaseDecl =
Fariborz Jahaniandfbd05d2009-07-14 23:41:35 +0000388 cast<CXXRecordDecl>(RT->getDecl());
389 Out << BaseDecl->getNameAsString();
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000390 }
391 if (hasArguments) {
392 Out << "(";
Mike Stump11289f42009-09-09 15:08:12 +0000393 for (CXXBaseOrMemberInitializer::const_arg_iterator BE =
394 BMInitializer->const_arg_begin(),
Fariborz Jahanian2a1b5af12009-07-24 17:57:02 +0000395 EE = BMInitializer->const_arg_end(); BE != EE; ++BE) {
396 if (BE != BMInitializer->const_arg_begin())
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000397 Out<< ", ";
Fariborz Jahanian2a1b5af12009-07-24 17:57:02 +0000398 const Expr *Exp = (*BE);
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000399 Exp->printPretty(Out, Context, 0, Policy, Indentation);
400 }
401 Out << ")";
Fariborz Jahanian44e56ca2009-07-13 23:31:10 +0000402 } else
403 Out << "()";
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000404 }
405 }
406 }
407 else
408 AFT->getResultType().getAsStringInternal(Proto, Policy);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000409 } else {
410 D->getType().getAsStringInternal(Proto, Policy);
411 }
412
413 Out << Proto;
414
415 if (D->isPure())
416 Out << " = 0";
417 else if (D->isDeleted())
418 Out << " = delete";
419 else if (D->isThisDeclarationADefinition()) {
420 if (!D->hasPrototype() && D->getNumParams()) {
421 // This is a K&R function definition, so we need to print the
422 // parameters.
423 Out << '\n';
Douglas Gregor2d042f12009-05-30 05:39:39 +0000424 DeclPrinter ParamPrinter(Out, Context, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000425 Indentation += Policy.Indentation;
426 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
427 Indent();
Douglas Gregor2d042f12009-05-30 05:39:39 +0000428 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor278f52e2009-05-30 00:08:05 +0000429 Out << ";\n";
430 }
431 Indentation -= Policy.Indentation;
432 } else
433 Out << ' ';
434
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000435 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000436 Out << '\n';
437 }
438}
439
440void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000441 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000442 Out << "mutable ";
443
444 std::string Name = D->getNameAsString();
445 D->getType().getAsStringInternal(Name, Policy);
446 Out << Name;
447
448 if (D->isBitField()) {
449 Out << " : ";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000450 D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000451 }
452}
453
454void DeclPrinter::VisitVarDecl(VarDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000455 if (!Policy.SuppressSpecifiers && D->getStorageClass() != VarDecl::None)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000456 Out << VarDecl::getStorageClassSpecifierString(D->getStorageClass()) << " ";
457
Eli Friedman79635842009-05-30 04:20:30 +0000458 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000459 Out << "__thread ";
460
461 std::string Name = D->getNameAsString();
462 QualType T = D->getType();
John McCall856bbea2009-10-23 21:48:59 +0000463 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor278f52e2009-05-30 00:08:05 +0000464 T = Parm->getOriginalType();
465 T.getAsStringInternal(Name, Policy);
466 Out << Name;
467 if (D->getInit()) {
468 if (D->hasCXXDirectInitializer())
469 Out << "(";
470 else
471 Out << " = ";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000472 D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000473 if (D->hasCXXDirectInitializer())
474 Out << ")";
475 }
476}
477
478void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
479 VisitVarDecl(D);
480}
481
482void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
483 Out << "__asm (";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000484 D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000485 Out << ")";
486}
487
488//----------------------------------------------------------------------------
489// C++ declarations
490//----------------------------------------------------------------------------
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000491void DeclPrinter::VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D) {
Mike Stump11289f42009-09-09 15:08:12 +0000492 assert(false &&
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000493 "OverloadedFunctionDecls aren't really decls and are never printed");
494}
495
Douglas Gregor5f478b72009-05-30 06:58:37 +0000496void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
497 Out << "namespace " << D->getNameAsString() << " {\n";
498 VisitDeclContext(D);
499 Indent() << "}";
500}
501
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000502void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
503 Out << "using namespace ";
504 if (D->getQualifier())
505 D->getQualifier()->print(Out, Policy);
Sebastian Redla6602e92009-11-23 15:34:23 +0000506 Out << D->getNominatedNamespaceAsWritten()->getNameAsString();
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000507}
508
Douglas Gregor18231932009-05-30 06:48:27 +0000509void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
510 Out << "namespace " << D->getNameAsString() << " = ";
511 if (D->getQualifier())
512 D->getQualifier()->print(Out, Policy);
513 Out << D->getAliasedNamespace()->getNameAsString();
514}
515
Douglas Gregor5f478b72009-05-30 06:58:37 +0000516void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
517 Out << D->getKindName();
518 if (D->getIdentifier()) {
519 Out << " ";
520 Out << D->getNameAsString();
521 }
Mike Stump11289f42009-09-09 15:08:12 +0000522
Douglas Gregor5f478b72009-05-30 06:58:37 +0000523 if (D->isDefinition()) {
524 // Print the base classes
525 if (D->getNumBases()) {
526 Out << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000527 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
528 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor5f478b72009-05-30 06:58:37 +0000529 if (Base != D->bases_begin())
530 Out << ", ";
531
532 if (Base->isVirtual())
533 Out << "virtual ";
534
Anders Carlsson6df9e072009-08-29 20:36:12 +0000535 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
536 if (AS != AS_none)
537 Print(AS);
Anders Carlsson601d6e42009-08-28 22:39:52 +0000538 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor5f478b72009-05-30 06:58:37 +0000539 }
540 }
541
542 // Print the class definition
Douglas Gregor7a1a7cb2009-05-31 07:13:39 +0000543 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor5f478b72009-05-30 06:58:37 +0000544 Out << " {\n";
545 VisitDeclContext(D);
546 Indent() << "}";
Mike Stump11289f42009-09-09 15:08:12 +0000547 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000548}
549
550void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
551 const char *l;
552 if (D->getLanguage() == LinkageSpecDecl::lang_c)
553 l = "C";
554 else {
555 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
556 "unknown language in linkage specification");
557 l = "C++";
558 }
559
560 Out << "extern \"" << l << "\" ";
561 if (D->hasBraces()) {
562 Out << "{\n";
563 VisitDeclContext(D);
564 Indent() << "}";
565 } else
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000566 Visit(*D->decls_begin());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000567}
568
569void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000570 Out << "template <";
Mike Stump11289f42009-09-09 15:08:12 +0000571
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000572 TemplateParameterList *Params = D->getTemplateParameters();
573 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
574 if (i != 0)
575 Out << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000576
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000577 const Decl *Param = Params->getParam(i);
Mike Stump11289f42009-09-09 15:08:12 +0000578 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000579 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump11289f42009-09-09 15:08:12 +0000580
581 QualType ParamType =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000582 Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP));
583
584 if (TTP->wasDeclaredWithTypename())
585 Out << "typename ";
586 else
587 Out << "class ";
588
Anders Carlssonfb1d7762009-06-12 22:23:22 +0000589 if (TTP->isParameterPack())
590 Out << "... ";
Mike Stump11289f42009-09-09 15:08:12 +0000591
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000592 Out << ParamType.getAsString(Policy);
593
594 if (TTP->hasDefaultArgument()) {
595 Out << " = ";
596 Out << TTP->getDefaultArgument().getAsString(Policy);
597 };
Mike Stump11289f42009-09-09 15:08:12 +0000598 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000599 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
600 Out << NTTP->getType().getAsString(Policy);
601
602 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
603 Out << ' ';
604 Out << Name->getName();
605 }
Mike Stump11289f42009-09-09 15:08:12 +0000606
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000607 if (NTTP->hasDefaultArgument()) {
608 Out << " = ";
Mike Stump11289f42009-09-09 15:08:12 +0000609 NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy,
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000610 Indentation);
611 }
612 }
613 }
Mike Stump11289f42009-09-09 15:08:12 +0000614
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000615 Out << "> ";
616
Douglas Gregor278f52e2009-05-30 00:08:05 +0000617 Visit(D->getTemplatedDecl());
618}
619
620//----------------------------------------------------------------------------
621// Objective-C declarations
622//----------------------------------------------------------------------------
623
624void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
625 Out << "@class ";
626 for (ObjCClassDecl::iterator I = D->begin(), E = D->end();
627 I != E; ++I) {
628 if (I != D->begin()) Out << ", ";
Ted Kremenek9b124e12009-11-18 00:28:11 +0000629 Out << I->getInterface()->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000630 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000631}
632
633void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
634 if (OMD->isInstanceMethod())
Douglas Gregor36098ff2009-05-30 00:56:08 +0000635 Out << "- ";
Mike Stump11289f42009-09-09 15:08:12 +0000636 else
Douglas Gregor36098ff2009-05-30 00:56:08 +0000637 Out << "+ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000638 if (!OMD->getResultType().isNull())
Douglas Gregor5f478b72009-05-30 06:58:37 +0000639 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregor278f52e2009-05-30 00:08:05 +0000641 std::string name = OMD->getSelector().getAsString();
642 std::string::size_type pos, lastPos = 0;
643 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
644 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump11289f42009-09-09 15:08:12 +0000645 // FIXME: selector is missing here!
Douglas Gregor278f52e2009-05-30 00:08:05 +0000646 pos = name.find_first_of(":", lastPos);
647 Out << " " << name.substr(lastPos, pos - lastPos);
Douglas Gregor5f478b72009-05-30 06:58:37 +0000648 Out << ":(" << (*PI)->getType().getAsString(Policy) << ")"
Mike Stump11289f42009-09-09 15:08:12 +0000649 << (*PI)->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000650 lastPos = pos + 1;
651 }
Mike Stump11289f42009-09-09 15:08:12 +0000652
Douglas Gregor278f52e2009-05-30 00:08:05 +0000653 if (OMD->param_begin() == OMD->param_end())
654 Out << " " << name;
Mike Stump11289f42009-09-09 15:08:12 +0000655
Douglas Gregor278f52e2009-05-30 00:08:05 +0000656 if (OMD->isVariadic())
657 Out << ", ...";
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregor278f52e2009-05-30 00:08:05 +0000659 if (OMD->getBody()) {
660 Out << ' ';
Eli Friedmanef334fd2009-05-30 05:03:24 +0000661 OMD->getBody()->printPretty(Out, Context, 0, Policy);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000662 Out << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +0000663 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000664}
665
666void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
667 std::string I = OID->getNameAsString();
668 ObjCInterfaceDecl *SID = OID->getSuperClass();
669
670 if (SID)
671 Out << "@implementation " << I << " : " << SID->getNameAsString();
672 else
673 Out << "@implementation " << I;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000674 Out << "\n";
675 VisitDeclContext(OID, false);
676 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000677}
678
679void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
680 std::string I = OID->getNameAsString();
681 ObjCInterfaceDecl *SID = OID->getSuperClass();
682
683 if (SID)
684 Out << "@interface " << I << " : " << SID->getNameAsString();
685 else
686 Out << "@interface " << I;
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregor278f52e2009-05-30 00:08:05 +0000688 // Protocols?
689 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
690 if (!Protocols.empty()) {
691 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
692 E = Protocols.end(); I != E; ++I)
693 Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString();
694 }
Mike Stump11289f42009-09-09 15:08:12 +0000695
Douglas Gregor278f52e2009-05-30 00:08:05 +0000696 if (!Protocols.empty())
Douglas Gregor36098ff2009-05-30 00:56:08 +0000697 Out << "> ";
Mike Stump11289f42009-09-09 15:08:12 +0000698
Douglas Gregor278f52e2009-05-30 00:08:05 +0000699 if (OID->ivar_size() > 0) {
Douglas Gregor36098ff2009-05-30 00:56:08 +0000700 Out << "{\n";
701 Indentation += Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000702 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
703 E = OID->ivar_end(); I != E; ++I) {
Douglas Gregor36098ff2009-05-30 00:56:08 +0000704 Indent() << (*I)->getType().getAsString(Policy)
Mike Stump11289f42009-09-09 15:08:12 +0000705 << ' ' << (*I)->getNameAsString() << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000706 }
Douglas Gregor36098ff2009-05-30 00:56:08 +0000707 Indentation -= Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000708 Out << "}\n";
709 }
Mike Stump11289f42009-09-09 15:08:12 +0000710
Douglas Gregor278f52e2009-05-30 00:08:05 +0000711 VisitDeclContext(OID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +0000712 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000713 // FIXME: implement the rest...
714}
715
716void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
717 Out << "@protocol ";
Mike Stump11289f42009-09-09 15:08:12 +0000718 for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(),
Douglas Gregor278f52e2009-05-30 00:08:05 +0000719 E = D->protocol_end();
720 I != E; ++I) {
721 if (I != D->protocol_begin()) Out << ", ";
722 Out << (*I)->getNameAsString();
723 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000724}
725
726void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
727 Out << "@protocol " << PID->getNameAsString() << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +0000728 VisitDeclContext(PID, false);
729 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000730}
731
732void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
733 Out << "@implementation "
734 << PID->getClassInterface()->getNameAsString()
Mike Stump11289f42009-09-09 15:08:12 +0000735 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000736
737 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +0000738 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000739 // FIXME: implement the rest...
740}
741
742void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Mike Stump11289f42009-09-09 15:08:12 +0000743 Out << "@interface "
Douglas Gregor278f52e2009-05-30 00:08:05 +0000744 << PID->getClassInterface()->getNameAsString()
Douglas Gregor36098ff2009-05-30 00:56:08 +0000745 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000746 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +0000747 Out << "@end";
Mike Stump11289f42009-09-09 15:08:12 +0000748
Douglas Gregor278f52e2009-05-30 00:08:05 +0000749 // FIXME: implement the rest...
750}
751
752void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Mike Stump11289f42009-09-09 15:08:12 +0000753 Out << "@compatibility_alias " << AID->getNameAsString()
754 << ' ' << AID->getClassInterface()->getNameAsString() << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000755}
756
757/// PrintObjCPropertyDecl - print a property declaration.
758///
759void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
760 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
761 Out << "@required\n";
762 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
763 Out << "@optional\n";
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregor278f52e2009-05-30 00:08:05 +0000765 Out << "@property";
766 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
767 bool first = true;
768 Out << " (";
Mike Stump11289f42009-09-09 15:08:12 +0000769 if (PDecl->getPropertyAttributes() &
Douglas Gregor278f52e2009-05-30 00:08:05 +0000770 ObjCPropertyDecl::OBJC_PR_readonly) {
771 Out << (first ? ' ' : ',') << "readonly";
772 first = false;
773 }
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregor278f52e2009-05-30 00:08:05 +0000775 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
776 Out << (first ? ' ' : ',') << "getter = "
777 << PDecl->getGetterName().getAsString();
778 first = false;
779 }
780 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
781 Out << (first ? ' ' : ',') << "setter = "
782 << PDecl->getSetterName().getAsString();
783 first = false;
784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Douglas Gregor278f52e2009-05-30 00:08:05 +0000786 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
787 Out << (first ? ' ' : ',') << "assign";
788 first = false;
789 }
Mike Stump11289f42009-09-09 15:08:12 +0000790
Douglas Gregor278f52e2009-05-30 00:08:05 +0000791 if (PDecl->getPropertyAttributes() &
792 ObjCPropertyDecl::OBJC_PR_readwrite) {
793 Out << (first ? ' ' : ',') << "readwrite";
794 first = false;
795 }
Mike Stump11289f42009-09-09 15:08:12 +0000796
Douglas Gregor278f52e2009-05-30 00:08:05 +0000797 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
798 Out << (first ? ' ' : ',') << "retain";
799 first = false;
800 }
Mike Stump11289f42009-09-09 15:08:12 +0000801
Douglas Gregor278f52e2009-05-30 00:08:05 +0000802 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
803 Out << (first ? ' ' : ',') << "copy";
804 first = false;
805 }
Mike Stump11289f42009-09-09 15:08:12 +0000806
807 if (PDecl->getPropertyAttributes() &
Douglas Gregor278f52e2009-05-30 00:08:05 +0000808 ObjCPropertyDecl::OBJC_PR_nonatomic) {
809 Out << (first ? ' ' : ',') << "nonatomic";
810 first = false;
811 }
812 Out << " )";
813 }
814 Out << ' ' << PDecl->getType().getAsString(Policy)
815 << ' ' << PDecl->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000816}
817
818void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
819 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor36098ff2009-05-30 00:56:08 +0000820 Out << "@synthesize ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000821 else
Douglas Gregor36098ff2009-05-30 00:56:08 +0000822 Out << "@dynamic ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000823 Out << PID->getPropertyDecl()->getNameAsString();
824 if (PID->getPropertyIvarDecl())
825 Out << "=" << PID->getPropertyIvarDecl()->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000826}
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000827
828void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
829 Out << "using ";
830 D->getTargetNestedNameDecl()->print(Out, Policy);
John McCall3f746822009-11-17 05:59:44 +0000831 Out << D->getNameAsString();
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000832}
833
John McCalle61f2ba2009-11-18 02:36:19 +0000834void
835DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
836 Out << "using typename ";
837 D->getTargetNestedNameSpecifier()->print(Out, Policy);
838 Out << D->getDeclName().getAsString();
839}
840
841void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000842 Out << "using ";
843 D->getTargetNestedNameSpecifier()->print(Out, Policy);
John McCalle61f2ba2009-11-18 02:36:19 +0000844 Out << D->getDeclName().getAsString();
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000845}
John McCall3f746822009-11-17 05:59:44 +0000846
847void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
848 // ignore
849}