blob: adf7ed3b0e2d479c5f93b20e5ceb0e24b20827aa [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 Gregor5f478b72009-05-30 06:58:37 +000055 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000056 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor18231932009-05-30 06:48:27 +000057 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor5f478b72009-05-30 06:58:37 +000058 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000059 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
60 void VisitTemplateDecl(TemplateDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000061 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +000062 void VisitObjCClassDecl(ObjCClassDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000063 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
64 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
65 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
66 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
67 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
68 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
69 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
70 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
71 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
John McCalle61f2ba2009-11-18 02:36:19 +000072 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
73 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssondf5a1c82009-08-28 19:16:39 +000074 void VisitUsingDecl(UsingDecl *D);
John McCall3f746822009-11-17 05:59:44 +000075 void VisitUsingShadowDecl(UsingShadowDecl *D);
Douglas Gregor278f52e2009-05-30 00:08:05 +000076 };
77}
78
Anders Carlsson46f87dc2009-09-26 21:58:53 +000079void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) const {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +000080 print(Out, getASTContext().PrintingPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +000081}
82
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +000083void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Anders Carlsson46f87dc2009-09-26 21:58:53 +000084 unsigned Indentation) const {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +000085 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation);
Anders Carlsson46f87dc2009-09-26 21:58:53 +000086 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor278f52e2009-05-30 00:08:05 +000087}
88
Eli Friedman79635842009-05-30 04:20:30 +000089static QualType GetBaseType(QualType T) {
90 // FIXME: This should be on the Type class!
91 QualType BaseType = T;
92 while (!BaseType->isSpecifierType()) {
93 if (isa<TypedefType>(BaseType))
94 break;
Ted Kremenekc23c7e62009-07-29 21:53:49 +000095 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman79635842009-05-30 04:20:30 +000096 BaseType = PTy->getPointeeType();
97 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
98 BaseType = ATy->getElementType();
John McCall9dd450b2009-09-21 23:43:11 +000099 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Eli Friedman79635842009-05-30 04:20:30 +0000100 BaseType = FTy->getResultType();
John McCall9dd450b2009-09-21 23:43:11 +0000101 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor15548252009-07-01 23:58:14 +0000102 BaseType = VTy->getElementType();
Eli Friedman79635842009-05-30 04:20:30 +0000103 else
104 assert(0 && "Unknown declarator!");
105 }
106 return BaseType;
107}
108
109static QualType getDeclType(Decl* D) {
110 if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D))
111 return TDD->getUnderlyingType();
112 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
113 return VD->getType();
114 return QualType();
115}
116
117void Decl::printGroup(Decl** Begin, unsigned NumDecls,
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000118 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman79635842009-05-30 04:20:30 +0000119 unsigned Indentation) {
120 if (NumDecls == 1) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000121 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000122 return;
123 }
124
125 Decl** End = Begin + NumDecls;
126 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
127 if (TD)
128 ++Begin;
129
130 PrintingPolicy SubPolicy(Policy);
131 if (TD && TD->isDefinition()) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000132 TD->print(Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000133 Out << " ";
134 SubPolicy.SuppressTag = true;
135 }
136
137 bool isFirst = true;
138 for ( ; Begin != End; ++Begin) {
139 if (isFirst) {
140 SubPolicy.SuppressSpecifiers = false;
141 isFirst = false;
142 } else {
143 if (!isFirst) Out << ", ";
144 SubPolicy.SuppressSpecifiers = true;
145 }
146
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000147 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000148 }
149}
150
Anders Carlsson46f87dc2009-09-26 21:58:53 +0000151void Decl::dump() const {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000152 print(llvm::errs());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000153}
154
Daniel Dunbar671f45e2009-11-21 09:12:06 +0000155llvm::raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
156 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000157 Out << " ";
158 return Out;
159}
160
Eli Friedman79635842009-05-30 04:20:30 +0000161void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) {
162 this->Indent();
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000163 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman79635842009-05-30 04:20:30 +0000164 Out << ";\n";
165 Decls.clear();
166
167}
168
Anders Carlsson601d6e42009-08-28 22:39:52 +0000169void DeclPrinter::Print(AccessSpecifier AS) {
170 switch(AS) {
Anders Carlsson6df9e072009-08-29 20:36:12 +0000171 case AS_none: assert(0 && "No access specifier!"); break;
Anders Carlsson601d6e42009-08-28 22:39:52 +0000172 case AS_public: Out << "public"; break;
173 case AS_protected: Out << "protected"; break;
174 case AS_private: Out << " private"; break;
175 }
176}
177
Douglas Gregor278f52e2009-05-30 00:08:05 +0000178//----------------------------------------------------------------------------
179// Common C declarations
180//----------------------------------------------------------------------------
181
182void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
183 if (Indent)
184 Indentation += Policy.Indentation;
185
Anders Carlsson601d6e42009-08-28 22:39:52 +0000186 bool PrintAccess = isa<CXXRecordDecl>(DC);
187 AccessSpecifier CurAS = AS_none;
Mike Stump11289f42009-09-09 15:08:12 +0000188
Eli Friedman79635842009-05-30 04:20:30 +0000189 llvm::SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000190 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000191 D != DEnd; ++D) {
Eli Friedmanef334fd2009-05-30 05:03:24 +0000192 if (!Policy.Dump) {
193 // Skip over implicit declarations in pretty-printing mode.
194 if (D->isImplicit()) continue;
Eli Friedman17304242009-05-30 06:35:22 +0000195 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
196 // of __builtin_va_list. There should be some other way to check that.
197 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() ==
198 "__builtin_va_list")
199 continue;
Eli Friedmanef334fd2009-05-30 05:03:24 +0000200 }
201
Anders Carlsson601d6e42009-08-28 22:39:52 +0000202 if (PrintAccess) {
203 AccessSpecifier AS = D->getAccess();
Anders Carlssonadf36b22009-08-29 20:47:47 +0000204
John McCall2dc078f2009-09-02 00:55:30 +0000205 if (AS != CurAS) {
Daniel Dunbar671f45e2009-11-21 09:12:06 +0000206 if (Indent)
207 this->Indent(Indentation - Policy.Indentation);
Anders Carlsson601d6e42009-08-28 22:39:52 +0000208 Print(AS);
209 Out << ":\n";
210 CurAS = AS;
211 }
212 }
Mike Stump11289f42009-09-09 15:08:12 +0000213
Eli Friedman79635842009-05-30 04:20:30 +0000214 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
215 // forced to merge the declarations because there's no other way to
216 // refer to the struct in question. This limited merging is safe without
217 // a bunch of other checks because it only merges declarations directly
218 // referring to the tag, not typedefs.
219 //
220 // Check whether the current declaration should be grouped with a previous
221 // unnamed struct.
222 QualType CurDeclType = getDeclType(*D);
223 if (!Decls.empty() && !CurDeclType.isNull()) {
224 QualType BaseType = GetBaseType(CurDeclType);
225 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
226 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
227 Decls.push_back(*D);
228 continue;
229 }
230 }
231
232 // If we have a merged group waiting to be handled, handle it now.
233 if (!Decls.empty())
234 ProcessDeclGroup(Decls);
235
236 // If the current declaration is an unnamed tag type, save it
237 // so we can merge it with the subsequent declaration(s) using it.
238 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
239 Decls.push_back(*D);
240 continue;
241 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000242 this->Indent();
243 Visit(*D);
Mike Stump11289f42009-09-09 15:08:12 +0000244
245 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor278f52e2009-05-30 00:08:05 +0000246 const char *Terminator = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000247 if (isa<FunctionDecl>(*D) &&
Douglas Gregor278f52e2009-05-30 00:08:05 +0000248 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
249 Terminator = 0;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000250 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
251 Terminator = 0;
252 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump11289f42009-09-09 15:08:12 +0000253 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor36098ff2009-05-30 00:56:08 +0000254 isa<ObjCInterfaceDecl>(*D) ||
255 isa<ObjCProtocolDecl>(*D) ||
256 isa<ObjCCategoryImplDecl>(*D) ||
257 isa<ObjCCategoryDecl>(*D))
Douglas Gregor278f52e2009-05-30 00:08:05 +0000258 Terminator = 0;
259 else if (isa<EnumConstantDecl>(*D)) {
260 DeclContext::decl_iterator Next = D;
261 ++Next;
262 if (Next != DEnd)
263 Terminator = ",";
264 } else
265 Terminator = ";";
266
267 if (Terminator)
268 Out << Terminator;
269 Out << "\n";
270 }
271
Eli Friedman79635842009-05-30 04:20:30 +0000272 if (!Decls.empty())
273 ProcessDeclGroup(Decls);
274
Douglas Gregor278f52e2009-05-30 00:08:05 +0000275 if (Indent)
276 Indentation -= Policy.Indentation;
277}
278
279void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
280 VisitDeclContext(D, false);
281}
282
283void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
284 std::string S = D->getNameAsString();
285 D->getUnderlyingType().getAsStringInternal(S, Policy);
Eli Friedman79635842009-05-30 04:20:30 +0000286 if (!Policy.SuppressSpecifiers)
287 Out << "typedef ";
288 Out << S;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000289}
290
291void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
292 Out << "enum " << D->getNameAsString() << " {\n";
293 VisitDeclContext(D);
294 Indent() << "}";
295}
296
297void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor278f52e2009-05-30 00:08:05 +0000298 Out << D->getKindName();
Eli Friedman79635842009-05-30 04:20:30 +0000299 if (D->getIdentifier()) {
300 Out << " ";
301 Out << D->getNameAsString();
302 }
Mike Stump11289f42009-09-09 15:08:12 +0000303
Douglas Gregor278f52e2009-05-30 00:08:05 +0000304 if (D->isDefinition()) {
305 Out << " {\n";
306 VisitDeclContext(D);
307 Indent() << "}";
308 }
309}
310
311void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
312 Out << D->getNameAsString();
313 if (Expr *Init = D->getInitExpr()) {
314 Out << " = ";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000315 Init->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000316 }
317}
318
Mike Stump11289f42009-09-09 15:08:12 +0000319void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000320 if (!Policy.SuppressSpecifiers) {
321 switch (D->getStorageClass()) {
322 case FunctionDecl::None: break;
323 case FunctionDecl::Extern: Out << "extern "; break;
324 case FunctionDecl::Static: Out << "static "; break;
325 case FunctionDecl::PrivateExtern: Out << "__private_extern__ "; break;
326 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000327
Douglas Gregor35b57532009-10-27 21:01:01 +0000328 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman79635842009-05-30 04:20:30 +0000329 if (D->isVirtualAsWritten()) Out << "virtual ";
330 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000331
Douglas Gregor2d042f12009-05-30 05:39:39 +0000332 PrintingPolicy SubPolicy(Policy);
333 SubPolicy.SuppressSpecifiers = false;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000334 std::string Proto = D->getNameAsString();
335 if (isa<FunctionType>(D->getType().getTypePtr())) {
John McCall9dd450b2009-09-21 23:43:11 +0000336 const FunctionType *AFT = D->getType()->getAs<FunctionType>();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000337
338 const FunctionProtoType *FT = 0;
339 if (D->hasWrittenPrototype())
340 FT = dyn_cast<FunctionProtoType>(AFT);
341
342 Proto += "(";
343 if (FT) {
344 llvm::raw_string_ostream POut(Proto);
Douglas Gregor2d042f12009-05-30 05:39:39 +0000345 DeclPrinter ParamPrinter(POut, Context, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000346 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
347 if (i) POut << ", ";
348 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
349 }
Mike Stump11289f42009-09-09 15:08:12 +0000350
Douglas Gregor278f52e2009-05-30 00:08:05 +0000351 if (FT->isVariadic()) {
352 if (D->getNumParams()) POut << ", ";
353 POut << "...";
354 }
Eli Friedman79635842009-05-30 04:20:30 +0000355 } else if (D->isThisDeclarationADefinition() && !D->hasPrototype()) {
356 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
357 if (i)
358 Proto += ", ";
359 Proto += D->getParamDecl(i)->getNameAsString();
360 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000361 }
362
363 Proto += ")";
Douglas Gregor049bdca2009-12-08 17:45:32 +0000364
365 if (FT && FT->hasExceptionSpec()) {
366 Proto += " throw(";
367 if (FT->hasAnyExceptionSpec())
368 Proto += "...";
369 else
370 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
371 if (I)
372 Proto += ", ";
373
374
375 std::string ExceptionType;
376 FT->getExceptionType(I).getAsStringInternal(ExceptionType, SubPolicy);
377 Proto += ExceptionType;
378 }
379 Proto += ")";
380 }
381
Mike Stump9a9e0c22009-07-27 21:33:40 +0000382 if (D->hasAttr<NoReturnAttr>())
383 Proto += " __attribute((noreturn))";
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000384 if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
385 if (CDecl->getNumBaseOrMemberInitializers() > 0) {
386 Proto += " : ";
387 Out << Proto;
388 Proto.clear();
Mike Stump11289f42009-09-09 15:08:12 +0000389 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000390 E = CDecl->init_end();
391 B != E; ++B) {
392 CXXBaseOrMemberInitializer * BMInitializer = (*B);
393 if (B != CDecl->init_begin())
394 Out << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000395 bool hasArguments = (BMInitializer->arg_begin() !=
Fariborz Jahanian2a1b5af12009-07-24 17:57:02 +0000396 BMInitializer->arg_end());
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000397 if (BMInitializer->isMemberInitializer()) {
398 FieldDecl *FD = BMInitializer->getMember();
399 Out << FD->getNameAsString();
400 }
Fariborz Jahaniandfbd05d2009-07-14 23:41:35 +0000401 else // FIXME. skip dependent types for now.
Mike Stump11289f42009-09-09 15:08:12 +0000402 if (const RecordType *RT =
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000403 BMInitializer->getBaseClass()->getAs<RecordType>()) {
Mike Stump11289f42009-09-09 15:08:12 +0000404 const CXXRecordDecl *BaseDecl =
Fariborz Jahaniandfbd05d2009-07-14 23:41:35 +0000405 cast<CXXRecordDecl>(RT->getDecl());
406 Out << BaseDecl->getNameAsString();
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000407 }
408 if (hasArguments) {
409 Out << "(";
Mike Stump11289f42009-09-09 15:08:12 +0000410 for (CXXBaseOrMemberInitializer::const_arg_iterator BE =
411 BMInitializer->const_arg_begin(),
Fariborz Jahanian2a1b5af12009-07-24 17:57:02 +0000412 EE = BMInitializer->const_arg_end(); BE != EE; ++BE) {
413 if (BE != BMInitializer->const_arg_begin())
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000414 Out<< ", ";
Fariborz Jahanian2a1b5af12009-07-24 17:57:02 +0000415 const Expr *Exp = (*BE);
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000416 Exp->printPretty(Out, Context, 0, Policy, Indentation);
417 }
418 Out << ")";
Fariborz Jahanian44e56ca2009-07-13 23:31:10 +0000419 } else
420 Out << "()";
Fariborz Jahanian494720b2009-07-13 20:18:13 +0000421 }
422 }
423 }
424 else
425 AFT->getResultType().getAsStringInternal(Proto, Policy);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000426 } else {
427 D->getType().getAsStringInternal(Proto, Policy);
428 }
429
430 Out << Proto;
431
432 if (D->isPure())
433 Out << " = 0";
434 else if (D->isDeleted())
435 Out << " = delete";
436 else if (D->isThisDeclarationADefinition()) {
437 if (!D->hasPrototype() && D->getNumParams()) {
438 // This is a K&R function definition, so we need to print the
439 // parameters.
440 Out << '\n';
Douglas Gregor2d042f12009-05-30 05:39:39 +0000441 DeclPrinter ParamPrinter(Out, Context, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000442 Indentation += Policy.Indentation;
443 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
444 Indent();
Douglas Gregor2d042f12009-05-30 05:39:39 +0000445 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor278f52e2009-05-30 00:08:05 +0000446 Out << ";\n";
447 }
448 Indentation -= Policy.Indentation;
449 } else
450 Out << ' ';
451
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000452 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000453 Out << '\n';
454 }
455}
456
457void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000458 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000459 Out << "mutable ";
460
461 std::string Name = D->getNameAsString();
462 D->getType().getAsStringInternal(Name, Policy);
463 Out << Name;
464
465 if (D->isBitField()) {
466 Out << " : ";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000467 D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000468 }
469}
470
471void DeclPrinter::VisitVarDecl(VarDecl *D) {
Eli Friedman79635842009-05-30 04:20:30 +0000472 if (!Policy.SuppressSpecifiers && D->getStorageClass() != VarDecl::None)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000473 Out << VarDecl::getStorageClassSpecifierString(D->getStorageClass()) << " ";
474
Eli Friedman79635842009-05-30 04:20:30 +0000475 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor278f52e2009-05-30 00:08:05 +0000476 Out << "__thread ";
477
478 std::string Name = D->getNameAsString();
479 QualType T = D->getType();
John McCall856bbea2009-10-23 21:48:59 +0000480 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor278f52e2009-05-30 00:08:05 +0000481 T = Parm->getOriginalType();
482 T.getAsStringInternal(Name, Policy);
483 Out << Name;
484 if (D->getInit()) {
485 if (D->hasCXXDirectInitializer())
486 Out << "(";
487 else
488 Out << " = ";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000489 D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000490 if (D->hasCXXDirectInitializer())
491 Out << ")";
492 }
493}
494
495void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
496 VisitVarDecl(D);
497}
498
499void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
500 Out << "__asm (";
Eli Friedmanef334fd2009-05-30 05:03:24 +0000501 D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000502 Out << ")";
503}
504
505//----------------------------------------------------------------------------
506// C++ declarations
507//----------------------------------------------------------------------------
Douglas Gregor5f478b72009-05-30 06:58:37 +0000508void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
509 Out << "namespace " << D->getNameAsString() << " {\n";
510 VisitDeclContext(D);
511 Indent() << "}";
512}
513
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000514void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
515 Out << "using namespace ";
516 if (D->getQualifier())
517 D->getQualifier()->print(Out, Policy);
Sebastian Redla6602e92009-11-23 15:34:23 +0000518 Out << D->getNominatedNamespaceAsWritten()->getNameAsString();
Douglas Gregor3bc6e4c2009-05-30 06:31:56 +0000519}
520
Douglas Gregor18231932009-05-30 06:48:27 +0000521void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
522 Out << "namespace " << D->getNameAsString() << " = ";
523 if (D->getQualifier())
524 D->getQualifier()->print(Out, Policy);
525 Out << D->getAliasedNamespace()->getNameAsString();
526}
527
Douglas Gregor5f478b72009-05-30 06:58:37 +0000528void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
529 Out << D->getKindName();
530 if (D->getIdentifier()) {
531 Out << " ";
532 Out << D->getNameAsString();
533 }
Mike Stump11289f42009-09-09 15:08:12 +0000534
Douglas Gregor5f478b72009-05-30 06:58:37 +0000535 if (D->isDefinition()) {
536 // Print the base classes
537 if (D->getNumBases()) {
538 Out << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000539 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
540 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor5f478b72009-05-30 06:58:37 +0000541 if (Base != D->bases_begin())
542 Out << ", ";
543
544 if (Base->isVirtual())
545 Out << "virtual ";
546
Anders Carlsson6df9e072009-08-29 20:36:12 +0000547 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
548 if (AS != AS_none)
549 Print(AS);
Anders Carlsson601d6e42009-08-28 22:39:52 +0000550 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor5f478b72009-05-30 06:58:37 +0000551 }
552 }
553
554 // Print the class definition
Douglas Gregor7a1a7cb2009-05-31 07:13:39 +0000555 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor5f478b72009-05-30 06:58:37 +0000556 Out << " {\n";
557 VisitDeclContext(D);
558 Indent() << "}";
Mike Stump11289f42009-09-09 15:08:12 +0000559 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000560}
561
562void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
563 const char *l;
564 if (D->getLanguage() == LinkageSpecDecl::lang_c)
565 l = "C";
566 else {
567 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
568 "unknown language in linkage specification");
569 l = "C++";
570 }
571
572 Out << "extern \"" << l << "\" ";
573 if (D->hasBraces()) {
574 Out << "{\n";
575 VisitDeclContext(D);
576 Indent() << "}";
577 } else
Argyrios Kyrtzidiscfbfe782009-06-30 02:36:12 +0000578 Visit(*D->decls_begin());
Douglas Gregor278f52e2009-05-30 00:08:05 +0000579}
580
581void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000582 Out << "template <";
Mike Stump11289f42009-09-09 15:08:12 +0000583
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000584 TemplateParameterList *Params = D->getTemplateParameters();
585 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
586 if (i != 0)
587 Out << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000588
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000589 const Decl *Param = Params->getParam(i);
Mike Stump11289f42009-09-09 15:08:12 +0000590 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000591 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump11289f42009-09-09 15:08:12 +0000592
593 QualType ParamType =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000594 Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP));
595
596 if (TTP->wasDeclaredWithTypename())
597 Out << "typename ";
598 else
599 Out << "class ";
600
Anders Carlssonfb1d7762009-06-12 22:23:22 +0000601 if (TTP->isParameterPack())
602 Out << "... ";
Mike Stump11289f42009-09-09 15:08:12 +0000603
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000604 Out << ParamType.getAsString(Policy);
605
606 if (TTP->hasDefaultArgument()) {
607 Out << " = ";
608 Out << TTP->getDefaultArgument().getAsString(Policy);
609 };
Mike Stump11289f42009-09-09 15:08:12 +0000610 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000611 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
612 Out << NTTP->getType().getAsString(Policy);
613
614 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
615 Out << ' ';
616 Out << Name->getName();
617 }
Mike Stump11289f42009-09-09 15:08:12 +0000618
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000619 if (NTTP->hasDefaultArgument()) {
620 Out << " = ";
Mike Stump11289f42009-09-09 15:08:12 +0000621 NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy,
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000622 Indentation);
623 }
624 }
625 }
Mike Stump11289f42009-09-09 15:08:12 +0000626
Anders Carlsson40f8f8d2009-06-04 05:37:43 +0000627 Out << "> ";
628
Douglas Gregor278f52e2009-05-30 00:08:05 +0000629 Visit(D->getTemplatedDecl());
630}
631
632//----------------------------------------------------------------------------
633// Objective-C declarations
634//----------------------------------------------------------------------------
635
636void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
637 Out << "@class ";
638 for (ObjCClassDecl::iterator I = D->begin(), E = D->end();
639 I != E; ++I) {
640 if (I != D->begin()) Out << ", ";
Ted Kremenek9b124e12009-11-18 00:28:11 +0000641 Out << I->getInterface()->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000642 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000643}
644
645void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
646 if (OMD->isInstanceMethod())
Douglas Gregor36098ff2009-05-30 00:56:08 +0000647 Out << "- ";
Mike Stump11289f42009-09-09 15:08:12 +0000648 else
Douglas Gregor36098ff2009-05-30 00:56:08 +0000649 Out << "+ ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000650 if (!OMD->getResultType().isNull())
Douglas Gregor5f478b72009-05-30 06:58:37 +0000651 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000652
Douglas Gregor278f52e2009-05-30 00:08:05 +0000653 std::string name = OMD->getSelector().getAsString();
654 std::string::size_type pos, lastPos = 0;
655 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
656 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump11289f42009-09-09 15:08:12 +0000657 // FIXME: selector is missing here!
Douglas Gregor278f52e2009-05-30 00:08:05 +0000658 pos = name.find_first_of(":", lastPos);
659 Out << " " << name.substr(lastPos, pos - lastPos);
Douglas Gregor5f478b72009-05-30 06:58:37 +0000660 Out << ":(" << (*PI)->getType().getAsString(Policy) << ")"
Mike Stump11289f42009-09-09 15:08:12 +0000661 << (*PI)->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000662 lastPos = pos + 1;
663 }
Mike Stump11289f42009-09-09 15:08:12 +0000664
Douglas Gregor278f52e2009-05-30 00:08:05 +0000665 if (OMD->param_begin() == OMD->param_end())
666 Out << " " << name;
Mike Stump11289f42009-09-09 15:08:12 +0000667
Douglas Gregor278f52e2009-05-30 00:08:05 +0000668 if (OMD->isVariadic())
669 Out << ", ...";
Mike Stump11289f42009-09-09 15:08:12 +0000670
Douglas Gregor278f52e2009-05-30 00:08:05 +0000671 if (OMD->getBody()) {
672 Out << ' ';
Eli Friedmanef334fd2009-05-30 05:03:24 +0000673 OMD->getBody()->printPretty(Out, Context, 0, Policy);
Douglas Gregor278f52e2009-05-30 00:08:05 +0000674 Out << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +0000675 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000676}
677
678void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
679 std::string I = OID->getNameAsString();
680 ObjCInterfaceDecl *SID = OID->getSuperClass();
681
682 if (SID)
683 Out << "@implementation " << I << " : " << SID->getNameAsString();
684 else
685 Out << "@implementation " << I;
Douglas Gregor36098ff2009-05-30 00:56:08 +0000686 Out << "\n";
687 VisitDeclContext(OID, false);
688 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000689}
690
691void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
692 std::string I = OID->getNameAsString();
693 ObjCInterfaceDecl *SID = OID->getSuperClass();
694
695 if (SID)
696 Out << "@interface " << I << " : " << SID->getNameAsString();
697 else
698 Out << "@interface " << I;
Mike Stump11289f42009-09-09 15:08:12 +0000699
Douglas Gregor278f52e2009-05-30 00:08:05 +0000700 // Protocols?
701 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
702 if (!Protocols.empty()) {
703 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
704 E = Protocols.end(); I != E; ++I)
705 Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString();
706 }
Mike Stump11289f42009-09-09 15:08:12 +0000707
Douglas Gregor278f52e2009-05-30 00:08:05 +0000708 if (!Protocols.empty())
Douglas Gregor36098ff2009-05-30 00:56:08 +0000709 Out << "> ";
Mike Stump11289f42009-09-09 15:08:12 +0000710
Douglas Gregor278f52e2009-05-30 00:08:05 +0000711 if (OID->ivar_size() > 0) {
Douglas Gregor36098ff2009-05-30 00:56:08 +0000712 Out << "{\n";
713 Indentation += Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000714 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
715 E = OID->ivar_end(); I != E; ++I) {
Douglas Gregor36098ff2009-05-30 00:56:08 +0000716 Indent() << (*I)->getType().getAsString(Policy)
Mike Stump11289f42009-09-09 15:08:12 +0000717 << ' ' << (*I)->getNameAsString() << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000718 }
Douglas Gregor36098ff2009-05-30 00:56:08 +0000719 Indentation -= Policy.Indentation;
Douglas Gregor278f52e2009-05-30 00:08:05 +0000720 Out << "}\n";
721 }
Mike Stump11289f42009-09-09 15:08:12 +0000722
Douglas Gregor278f52e2009-05-30 00:08:05 +0000723 VisitDeclContext(OID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +0000724 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000725 // FIXME: implement the rest...
726}
727
728void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
729 Out << "@protocol ";
Mike Stump11289f42009-09-09 15:08:12 +0000730 for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(),
Douglas Gregor278f52e2009-05-30 00:08:05 +0000731 E = D->protocol_end();
732 I != E; ++I) {
733 if (I != D->protocol_begin()) Out << ", ";
734 Out << (*I)->getNameAsString();
735 }
Douglas Gregor278f52e2009-05-30 00:08:05 +0000736}
737
738void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
739 Out << "@protocol " << PID->getNameAsString() << '\n';
Douglas Gregor36098ff2009-05-30 00:56:08 +0000740 VisitDeclContext(PID, false);
741 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000742}
743
744void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
745 Out << "@implementation "
746 << PID->getClassInterface()->getNameAsString()
Mike Stump11289f42009-09-09 15:08:12 +0000747 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000748
749 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +0000750 Out << "@end";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000751 // FIXME: implement the rest...
752}
753
754void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Mike Stump11289f42009-09-09 15:08:12 +0000755 Out << "@interface "
Douglas Gregor278f52e2009-05-30 00:08:05 +0000756 << PID->getClassInterface()->getNameAsString()
Douglas Gregor36098ff2009-05-30 00:56:08 +0000757 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000758 VisitDeclContext(PID, false);
Douglas Gregor36098ff2009-05-30 00:56:08 +0000759 Out << "@end";
Mike Stump11289f42009-09-09 15:08:12 +0000760
Douglas Gregor278f52e2009-05-30 00:08:05 +0000761 // FIXME: implement the rest...
762}
763
764void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Mike Stump11289f42009-09-09 15:08:12 +0000765 Out << "@compatibility_alias " << AID->getNameAsString()
766 << ' ' << AID->getClassInterface()->getNameAsString() << ";\n";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000767}
768
769/// PrintObjCPropertyDecl - print a property declaration.
770///
771void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
772 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
773 Out << "@required\n";
774 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
775 Out << "@optional\n";
Mike Stump11289f42009-09-09 15:08:12 +0000776
Douglas Gregor278f52e2009-05-30 00:08:05 +0000777 Out << "@property";
778 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
779 bool first = true;
780 Out << " (";
Mike Stump11289f42009-09-09 15:08:12 +0000781 if (PDecl->getPropertyAttributes() &
Douglas Gregor278f52e2009-05-30 00:08:05 +0000782 ObjCPropertyDecl::OBJC_PR_readonly) {
783 Out << (first ? ' ' : ',') << "readonly";
784 first = false;
785 }
Mike Stump11289f42009-09-09 15:08:12 +0000786
Douglas Gregor278f52e2009-05-30 00:08:05 +0000787 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
788 Out << (first ? ' ' : ',') << "getter = "
789 << PDecl->getGetterName().getAsString();
790 first = false;
791 }
792 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
793 Out << (first ? ' ' : ',') << "setter = "
794 << PDecl->getSetterName().getAsString();
795 first = false;
796 }
Mike Stump11289f42009-09-09 15:08:12 +0000797
Douglas Gregor278f52e2009-05-30 00:08:05 +0000798 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
799 Out << (first ? ' ' : ',') << "assign";
800 first = false;
801 }
Mike Stump11289f42009-09-09 15:08:12 +0000802
Douglas Gregor278f52e2009-05-30 00:08:05 +0000803 if (PDecl->getPropertyAttributes() &
804 ObjCPropertyDecl::OBJC_PR_readwrite) {
805 Out << (first ? ' ' : ',') << "readwrite";
806 first = false;
807 }
Mike Stump11289f42009-09-09 15:08:12 +0000808
Douglas Gregor278f52e2009-05-30 00:08:05 +0000809 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
810 Out << (first ? ' ' : ',') << "retain";
811 first = false;
812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregor278f52e2009-05-30 00:08:05 +0000814 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
815 Out << (first ? ' ' : ',') << "copy";
816 first = false;
817 }
Mike Stump11289f42009-09-09 15:08:12 +0000818
819 if (PDecl->getPropertyAttributes() &
Douglas Gregor278f52e2009-05-30 00:08:05 +0000820 ObjCPropertyDecl::OBJC_PR_nonatomic) {
821 Out << (first ? ' ' : ',') << "nonatomic";
822 first = false;
823 }
824 Out << " )";
825 }
826 Out << ' ' << PDecl->getType().getAsString(Policy)
827 << ' ' << PDecl->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000828}
829
830void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
831 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor36098ff2009-05-30 00:56:08 +0000832 Out << "@synthesize ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000833 else
Douglas Gregor36098ff2009-05-30 00:56:08 +0000834 Out << "@dynamic ";
Douglas Gregor278f52e2009-05-30 00:08:05 +0000835 Out << PID->getPropertyDecl()->getNameAsString();
836 if (PID->getPropertyIvarDecl())
837 Out << "=" << PID->getPropertyIvarDecl()->getNameAsString();
Douglas Gregor278f52e2009-05-30 00:08:05 +0000838}
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000839
840void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
841 Out << "using ";
842 D->getTargetNestedNameDecl()->print(Out, Policy);
John McCall3f746822009-11-17 05:59:44 +0000843 Out << D->getNameAsString();
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000844}
845
John McCalle61f2ba2009-11-18 02:36:19 +0000846void
847DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
848 Out << "using typename ";
849 D->getTargetNestedNameSpecifier()->print(Out, Policy);
850 Out << D->getDeclName().getAsString();
851}
852
853void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000854 Out << "using ";
855 D->getTargetNestedNameSpecifier()->print(Out, Policy);
John McCalle61f2ba2009-11-18 02:36:19 +0000856 Out << D->getDeclName().getAsString();
Anders Carlssondf5a1c82009-08-28 19:16:39 +0000857}
John McCall3f746822009-11-17 05:59:44 +0000858
859void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
860 // ignore
861}