blob: 864f1145a07bd35d990fd218644358a40218185a [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"
20#include "clang/AST/PrettyPrinter.h"
21#include "llvm/Support/Compiler.h"
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000022#include "llvm/Support/Format.h"
23#include "llvm/Support/raw_ostream.h"
24using namespace clang;
25
26namespace {
27 class VISIBILITY_HIDDEN DeclPrinter : public DeclVisitor<DeclPrinter> {
28 llvm::raw_ostream &Out;
29 ASTContext &Context;
30 PrintingPolicy Policy;
31 unsigned Indentation;
32
Daniel Dunbar512ce602009-11-21 09:12:06 +000033 llvm::raw_ostream& Indent() { return Indent(Indentation); }
34 llvm::raw_ostream& Indent(unsigned Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +000035 void ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000036
Anders Carlsson0d592922009-08-28 22:39:52 +000037 void Print(AccessSpecifier AS);
Mike Stump1eb44332009-09-09 15:08:12 +000038
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000039 public:
Mike Stump1eb44332009-09-09 15:08:12 +000040 DeclPrinter(llvm::raw_ostream &Out, ASTContext &Context,
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000041 const PrintingPolicy &Policy,
42 unsigned Indentation = 0)
43 : Out(Out), Context(Context), Policy(Policy), Indentation(Indentation) { }
44
45 void VisitDeclContext(DeclContext *DC, bool Indent = true);
46
47 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
48 void VisitTypedefDecl(TypedefDecl *D);
49 void VisitEnumDecl(EnumDecl *D);
50 void VisitRecordDecl(RecordDecl *D);
51 void VisitEnumConstantDecl(EnumConstantDecl *D);
52 void VisitFunctionDecl(FunctionDecl *D);
53 void VisitFieldDecl(FieldDecl *D);
54 void VisitVarDecl(VarDecl *D);
55 void VisitParmVarDecl(ParmVarDecl *D);
56 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregor8419fa32009-05-30 06:31:56 +000057 void VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D);
Douglas Gregor59e63572009-05-30 06:58:37 +000058 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor8419fa32009-05-30 06:31:56 +000059 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
Douglas Gregor6c9c9402009-05-30 06:48:27 +000060 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregor59e63572009-05-30 06:58:37 +000061 void VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000062 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
63 void VisitTemplateDecl(TemplateDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000064 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor8419fa32009-05-30 06:31:56 +000065 void VisitObjCClassDecl(ObjCClassDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000066 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
67 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
68 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
69 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
70 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
71 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
72 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
73 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
74 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
John McCall7ba107a2009-11-18 02:36:19 +000075 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
76 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Anders Carlssonf53eaa52009-08-28 19:16:39 +000077 void VisitUsingDecl(UsingDecl *D);
John McCall9488ea12009-11-17 05:59:44 +000078 void VisitUsingShadowDecl(UsingShadowDecl *D);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000079 };
80}
81
Anders Carlssonf88df862009-09-26 21:58:53 +000082void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) const {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000083 print(Out, getASTContext().PrintingPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000084}
85
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000086void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Anders Carlssonf88df862009-09-26 21:58:53 +000087 unsigned Indentation) const {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +000088 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation);
Anders Carlssonf88df862009-09-26 21:58:53 +000089 Printer.Visit(const_cast<Decl*>(this));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000090}
91
Eli Friedman42f42c02009-05-30 04:20:30 +000092static QualType GetBaseType(QualType T) {
93 // FIXME: This should be on the Type class!
94 QualType BaseType = T;
95 while (!BaseType->isSpecifierType()) {
96 if (isa<TypedefType>(BaseType))
97 break;
Ted Kremenek6217b802009-07-29 21:53:49 +000098 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
Eli Friedman42f42c02009-05-30 04:20:30 +000099 BaseType = PTy->getPointeeType();
100 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
101 BaseType = ATy->getElementType();
John McCall183700f2009-09-21 23:43:11 +0000102 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
Eli Friedman42f42c02009-05-30 04:20:30 +0000103 BaseType = FTy->getResultType();
John McCall183700f2009-09-21 23:43:11 +0000104 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
Douglas Gregor5068ab62009-07-01 23:58:14 +0000105 BaseType = VTy->getElementType();
Eli Friedman42f42c02009-05-30 04:20:30 +0000106 else
107 assert(0 && "Unknown declarator!");
108 }
109 return BaseType;
110}
111
112static QualType getDeclType(Decl* D) {
113 if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D))
114 return TDD->getUnderlyingType();
115 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
116 return VD->getType();
117 return QualType();
118}
119
120void Decl::printGroup(Decl** Begin, unsigned NumDecls,
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000121 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman42f42c02009-05-30 04:20:30 +0000122 unsigned Indentation) {
123 if (NumDecls == 1) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000124 (*Begin)->print(Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000125 return;
126 }
127
128 Decl** End = Begin + NumDecls;
129 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
130 if (TD)
131 ++Begin;
132
133 PrintingPolicy SubPolicy(Policy);
134 if (TD && TD->isDefinition()) {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000135 TD->print(Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000136 Out << " ";
137 SubPolicy.SuppressTag = true;
138 }
139
140 bool isFirst = true;
141 for ( ; Begin != End; ++Begin) {
142 if (isFirst) {
143 SubPolicy.SuppressSpecifiers = false;
144 isFirst = false;
145 } else {
146 if (!isFirst) Out << ", ";
147 SubPolicy.SuppressSpecifiers = true;
148 }
149
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000150 (*Begin)->print(Out, SubPolicy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000151 }
152}
153
Anders Carlssonf88df862009-09-26 21:58:53 +0000154void Decl::dump() const {
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000155 print(llvm::errs());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000156}
157
Daniel Dunbar512ce602009-11-21 09:12:06 +0000158llvm::raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
159 for (unsigned i = 0; i != Indentation; ++i)
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000160 Out << " ";
161 return Out;
162}
163
Eli Friedman42f42c02009-05-30 04:20:30 +0000164void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) {
165 this->Indent();
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000166 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
Eli Friedman42f42c02009-05-30 04:20:30 +0000167 Out << ";\n";
168 Decls.clear();
169
170}
171
Anders Carlsson0d592922009-08-28 22:39:52 +0000172void DeclPrinter::Print(AccessSpecifier AS) {
173 switch(AS) {
Anders Carlsson018e9fe2009-08-29 20:36:12 +0000174 case AS_none: assert(0 && "No access specifier!"); break;
Anders Carlsson0d592922009-08-28 22:39:52 +0000175 case AS_public: Out << "public"; break;
176 case AS_protected: Out << "protected"; break;
177 case AS_private: Out << " private"; break;
178 }
179}
180
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000181//----------------------------------------------------------------------------
182// Common C declarations
183//----------------------------------------------------------------------------
184
185void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
186 if (Indent)
187 Indentation += Policy.Indentation;
188
Anders Carlsson0d592922009-08-28 22:39:52 +0000189 bool PrintAccess = isa<CXXRecordDecl>(DC);
190 AccessSpecifier CurAS = AS_none;
Mike Stump1eb44332009-09-09 15:08:12 +0000191
Eli Friedman42f42c02009-05-30 04:20:30 +0000192 llvm::SmallVector<Decl*, 2> Decls;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000193 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000194 D != DEnd; ++D) {
Eli Friedman48d14a22009-05-30 05:03:24 +0000195 if (!Policy.Dump) {
196 // Skip over implicit declarations in pretty-printing mode.
197 if (D->isImplicit()) continue;
Eli Friedman3d4a7c92009-05-30 06:35:22 +0000198 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
199 // of __builtin_va_list. There should be some other way to check that.
200 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() ==
201 "__builtin_va_list")
202 continue;
Eli Friedman48d14a22009-05-30 05:03:24 +0000203 }
204
Anders Carlsson0d592922009-08-28 22:39:52 +0000205 if (PrintAccess) {
206 AccessSpecifier AS = D->getAccess();
Anders Carlsson35eda442009-08-29 20:47:47 +0000207
John McCalld7eff682009-09-02 00:55:30 +0000208 if (AS != CurAS) {
Daniel Dunbar512ce602009-11-21 09:12:06 +0000209 if (Indent)
210 this->Indent(Indentation - Policy.Indentation);
Anders Carlsson0d592922009-08-28 22:39:52 +0000211 Print(AS);
212 Out << ":\n";
213 CurAS = AS;
214 }
215 }
Mike Stump1eb44332009-09-09 15:08:12 +0000216
Eli Friedman42f42c02009-05-30 04:20:30 +0000217 // The next bits of code handles stuff like "struct {int x;} a,b"; we're
218 // forced to merge the declarations because there's no other way to
219 // refer to the struct in question. This limited merging is safe without
220 // a bunch of other checks because it only merges declarations directly
221 // referring to the tag, not typedefs.
222 //
223 // Check whether the current declaration should be grouped with a previous
224 // unnamed struct.
225 QualType CurDeclType = getDeclType(*D);
226 if (!Decls.empty() && !CurDeclType.isNull()) {
227 QualType BaseType = GetBaseType(CurDeclType);
228 if (!BaseType.isNull() && isa<TagType>(BaseType) &&
229 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
230 Decls.push_back(*D);
231 continue;
232 }
233 }
234
235 // If we have a merged group waiting to be handled, handle it now.
236 if (!Decls.empty())
237 ProcessDeclGroup(Decls);
238
239 // If the current declaration is an unnamed tag type, save it
240 // so we can merge it with the subsequent declaration(s) using it.
241 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
242 Decls.push_back(*D);
243 continue;
244 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000245 this->Indent();
246 Visit(*D);
Mike Stump1eb44332009-09-09 15:08:12 +0000247
248 // FIXME: Need to be able to tell the DeclPrinter when
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000249 const char *Terminator = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000250 if (isa<FunctionDecl>(*D) &&
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000251 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
252 Terminator = 0;
Douglas Gregor64f65002009-05-30 00:56:08 +0000253 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
254 Terminator = 0;
255 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
Mike Stump1eb44332009-09-09 15:08:12 +0000256 isa<ObjCImplementationDecl>(*D) ||
Douglas Gregor64f65002009-05-30 00:56:08 +0000257 isa<ObjCInterfaceDecl>(*D) ||
258 isa<ObjCProtocolDecl>(*D) ||
259 isa<ObjCCategoryImplDecl>(*D) ||
260 isa<ObjCCategoryDecl>(*D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000261 Terminator = 0;
262 else if (isa<EnumConstantDecl>(*D)) {
263 DeclContext::decl_iterator Next = D;
264 ++Next;
265 if (Next != DEnd)
266 Terminator = ",";
267 } else
268 Terminator = ";";
269
270 if (Terminator)
271 Out << Terminator;
272 Out << "\n";
273 }
274
Eli Friedman42f42c02009-05-30 04:20:30 +0000275 if (!Decls.empty())
276 ProcessDeclGroup(Decls);
277
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000278 if (Indent)
279 Indentation -= Policy.Indentation;
280}
281
282void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
283 VisitDeclContext(D, false);
284}
285
286void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
287 std::string S = D->getNameAsString();
288 D->getUnderlyingType().getAsStringInternal(S, Policy);
Eli Friedman42f42c02009-05-30 04:20:30 +0000289 if (!Policy.SuppressSpecifiers)
290 Out << "typedef ";
291 Out << S;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000292}
293
294void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
295 Out << "enum " << D->getNameAsString() << " {\n";
296 VisitDeclContext(D);
297 Indent() << "}";
298}
299
300void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000301 Out << D->getKindName();
Eli Friedman42f42c02009-05-30 04:20:30 +0000302 if (D->getIdentifier()) {
303 Out << " ";
304 Out << D->getNameAsString();
305 }
Mike Stump1eb44332009-09-09 15:08:12 +0000306
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000307 if (D->isDefinition()) {
308 Out << " {\n";
309 VisitDeclContext(D);
310 Indent() << "}";
311 }
312}
313
314void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
315 Out << D->getNameAsString();
316 if (Expr *Init = D->getInitExpr()) {
317 Out << " = ";
Eli Friedman48d14a22009-05-30 05:03:24 +0000318 Init->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000319 }
320}
321
Mike Stump1eb44332009-09-09 15:08:12 +0000322void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000323 if (!Policy.SuppressSpecifiers) {
324 switch (D->getStorageClass()) {
325 case FunctionDecl::None: break;
326 case FunctionDecl::Extern: Out << "extern "; break;
327 case FunctionDecl::Static: Out << "static "; break;
328 case FunctionDecl::PrivateExtern: Out << "__private_extern__ "; break;
329 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000330
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000331 if (D->isInlineSpecified()) Out << "inline ";
Eli Friedman42f42c02009-05-30 04:20:30 +0000332 if (D->isVirtualAsWritten()) Out << "virtual ";
333 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000334
Douglas Gregor6620a622009-05-30 05:39:39 +0000335 PrintingPolicy SubPolicy(Policy);
336 SubPolicy.SuppressSpecifiers = false;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000337 std::string Proto = D->getNameAsString();
338 if (isa<FunctionType>(D->getType().getTypePtr())) {
John McCall183700f2009-09-21 23:43:11 +0000339 const FunctionType *AFT = D->getType()->getAs<FunctionType>();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000340
341 const FunctionProtoType *FT = 0;
342 if (D->hasWrittenPrototype())
343 FT = dyn_cast<FunctionProtoType>(AFT);
344
345 Proto += "(";
346 if (FT) {
347 llvm::raw_string_ostream POut(Proto);
Douglas Gregor6620a622009-05-30 05:39:39 +0000348 DeclPrinter ParamPrinter(POut, Context, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000349 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
350 if (i) POut << ", ";
351 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
352 }
Mike Stump1eb44332009-09-09 15:08:12 +0000353
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000354 if (FT->isVariadic()) {
355 if (D->getNumParams()) POut << ", ";
356 POut << "...";
357 }
Eli Friedman42f42c02009-05-30 04:20:30 +0000358 } else if (D->isThisDeclarationADefinition() && !D->hasPrototype()) {
359 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
360 if (i)
361 Proto += ", ";
362 Proto += D->getParamDecl(i)->getNameAsString();
363 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000364 }
365
366 Proto += ")";
Mike Stumpfd350b52009-07-27 21:33:40 +0000367 if (D->hasAttr<NoReturnAttr>())
368 Proto += " __attribute((noreturn))";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000369 if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
370 if (CDecl->getNumBaseOrMemberInitializers() > 0) {
371 Proto += " : ";
372 Out << Proto;
373 Proto.clear();
Mike Stump1eb44332009-09-09 15:08:12 +0000374 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000375 E = CDecl->init_end();
376 B != E; ++B) {
377 CXXBaseOrMemberInitializer * BMInitializer = (*B);
378 if (B != CDecl->init_begin())
379 Out << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000380 bool hasArguments = (BMInitializer->arg_begin() !=
Fariborz Jahanian50b8eea2009-07-24 17:57:02 +0000381 BMInitializer->arg_end());
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000382 if (BMInitializer->isMemberInitializer()) {
383 FieldDecl *FD = BMInitializer->getMember();
384 Out << FD->getNameAsString();
385 }
Fariborz Jahanian29146ad2009-07-14 23:41:35 +0000386 else // FIXME. skip dependent types for now.
Mike Stump1eb44332009-09-09 15:08:12 +0000387 if (const RecordType *RT =
Ted Kremenek6217b802009-07-29 21:53:49 +0000388 BMInitializer->getBaseClass()->getAs<RecordType>()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000389 const CXXRecordDecl *BaseDecl =
Fariborz Jahanian29146ad2009-07-14 23:41:35 +0000390 cast<CXXRecordDecl>(RT->getDecl());
391 Out << BaseDecl->getNameAsString();
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000392 }
393 if (hasArguments) {
394 Out << "(";
Mike Stump1eb44332009-09-09 15:08:12 +0000395 for (CXXBaseOrMemberInitializer::const_arg_iterator BE =
396 BMInitializer->const_arg_begin(),
Fariborz Jahanian50b8eea2009-07-24 17:57:02 +0000397 EE = BMInitializer->const_arg_end(); BE != EE; ++BE) {
398 if (BE != BMInitializer->const_arg_begin())
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000399 Out<< ", ";
Fariborz Jahanian50b8eea2009-07-24 17:57:02 +0000400 const Expr *Exp = (*BE);
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000401 Exp->printPretty(Out, Context, 0, Policy, Indentation);
402 }
403 Out << ")";
Fariborz Jahanian939afd82009-07-13 23:31:10 +0000404 } else
405 Out << "()";
Fariborz Jahanian66192ad2009-07-13 20:18:13 +0000406 }
407 }
408 }
409 else
410 AFT->getResultType().getAsStringInternal(Proto, Policy);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000411 } else {
412 D->getType().getAsStringInternal(Proto, Policy);
413 }
414
415 Out << Proto;
416
417 if (D->isPure())
418 Out << " = 0";
419 else if (D->isDeleted())
420 Out << " = delete";
421 else if (D->isThisDeclarationADefinition()) {
422 if (!D->hasPrototype() && D->getNumParams()) {
423 // This is a K&R function definition, so we need to print the
424 // parameters.
425 Out << '\n';
Douglas Gregor6620a622009-05-30 05:39:39 +0000426 DeclPrinter ParamPrinter(Out, Context, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000427 Indentation += Policy.Indentation;
428 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
429 Indent();
Douglas Gregor6620a622009-05-30 05:39:39 +0000430 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000431 Out << ";\n";
432 }
433 Indentation -= Policy.Indentation;
434 } else
435 Out << ' ';
436
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000437 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000438 Out << '\n';
439 }
440}
441
442void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000443 if (!Policy.SuppressSpecifiers && D->isMutable())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000444 Out << "mutable ";
445
446 std::string Name = D->getNameAsString();
447 D->getType().getAsStringInternal(Name, Policy);
448 Out << Name;
449
450 if (D->isBitField()) {
451 Out << " : ";
Eli Friedman48d14a22009-05-30 05:03:24 +0000452 D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000453 }
454}
455
456void DeclPrinter::VisitVarDecl(VarDecl *D) {
Eli Friedman42f42c02009-05-30 04:20:30 +0000457 if (!Policy.SuppressSpecifiers && D->getStorageClass() != VarDecl::None)
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000458 Out << VarDecl::getStorageClassSpecifierString(D->getStorageClass()) << " ";
459
Eli Friedman42f42c02009-05-30 04:20:30 +0000460 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000461 Out << "__thread ";
462
463 std::string Name = D->getNameAsString();
464 QualType T = D->getType();
John McCall58e46772009-10-23 21:48:59 +0000465 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000466 T = Parm->getOriginalType();
467 T.getAsStringInternal(Name, Policy);
468 Out << Name;
469 if (D->getInit()) {
470 if (D->hasCXXDirectInitializer())
471 Out << "(";
472 else
473 Out << " = ";
Eli Friedman48d14a22009-05-30 05:03:24 +0000474 D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000475 if (D->hasCXXDirectInitializer())
476 Out << ")";
477 }
478}
479
480void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
481 VisitVarDecl(D);
482}
483
484void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
485 Out << "__asm (";
Eli Friedman48d14a22009-05-30 05:03:24 +0000486 D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000487 Out << ")";
488}
489
490//----------------------------------------------------------------------------
491// C++ declarations
492//----------------------------------------------------------------------------
Douglas Gregor8419fa32009-05-30 06:31:56 +0000493void DeclPrinter::VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D) {
Mike Stump1eb44332009-09-09 15:08:12 +0000494 assert(false &&
Douglas Gregor8419fa32009-05-30 06:31:56 +0000495 "OverloadedFunctionDecls aren't really decls and are never printed");
496}
497
Douglas Gregor59e63572009-05-30 06:58:37 +0000498void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
499 Out << "namespace " << D->getNameAsString() << " {\n";
500 VisitDeclContext(D);
501 Indent() << "}";
502}
503
Douglas Gregor8419fa32009-05-30 06:31:56 +0000504void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
505 Out << "using namespace ";
506 if (D->getQualifier())
507 D->getQualifier()->print(Out, Policy);
508 Out << D->getNominatedNamespace()->getNameAsString();
509}
510
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000511void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
512 Out << "namespace " << D->getNameAsString() << " = ";
513 if (D->getQualifier())
514 D->getQualifier()->print(Out, Policy);
515 Out << D->getAliasedNamespace()->getNameAsString();
516}
517
Douglas Gregor59e63572009-05-30 06:58:37 +0000518void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
519 Out << D->getKindName();
520 if (D->getIdentifier()) {
521 Out << " ";
522 Out << D->getNameAsString();
523 }
Mike Stump1eb44332009-09-09 15:08:12 +0000524
Douglas Gregor59e63572009-05-30 06:58:37 +0000525 if (D->isDefinition()) {
526 // Print the base classes
527 if (D->getNumBases()) {
528 Out << " : ";
Mike Stump1eb44332009-09-09 15:08:12 +0000529 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
530 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
Douglas Gregor59e63572009-05-30 06:58:37 +0000531 if (Base != D->bases_begin())
532 Out << ", ";
533
534 if (Base->isVirtual())
535 Out << "virtual ";
536
Anders Carlsson018e9fe2009-08-29 20:36:12 +0000537 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
538 if (AS != AS_none)
539 Print(AS);
Anders Carlsson0d592922009-08-28 22:39:52 +0000540 Out << " " << Base->getType().getAsString(Policy);
Douglas Gregor59e63572009-05-30 06:58:37 +0000541 }
542 }
543
544 // Print the class definition
Douglas Gregorf757ae72009-05-31 07:13:39 +0000545 // FIXME: Doesn't print access specifiers, e.g., "public:"
Douglas Gregor59e63572009-05-30 06:58:37 +0000546 Out << " {\n";
547 VisitDeclContext(D);
548 Indent() << "}";
Mike Stump1eb44332009-09-09 15:08:12 +0000549 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000550}
551
552void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
553 const char *l;
554 if (D->getLanguage() == LinkageSpecDecl::lang_c)
555 l = "C";
556 else {
557 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
558 "unknown language in linkage specification");
559 l = "C++";
560 }
561
562 Out << "extern \"" << l << "\" ";
563 if (D->hasBraces()) {
564 Out << "{\n";
565 VisitDeclContext(D);
566 Indent() << "}";
567 } else
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000568 Visit(*D->decls_begin());
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000569}
570
571void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
Anders Carlsson0487f662009-06-04 05:37:43 +0000572 Out << "template <";
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Anders Carlsson0487f662009-06-04 05:37:43 +0000574 TemplateParameterList *Params = D->getTemplateParameters();
575 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
576 if (i != 0)
577 Out << ", ";
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Anders Carlsson0487f662009-06-04 05:37:43 +0000579 const Decl *Param = Params->getParam(i);
Mike Stump1eb44332009-09-09 15:08:12 +0000580 if (const TemplateTypeParmDecl *TTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000581 dyn_cast<TemplateTypeParmDecl>(Param)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000582
583 QualType ParamType =
Anders Carlsson0487f662009-06-04 05:37:43 +0000584 Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP));
585
586 if (TTP->wasDeclaredWithTypename())
587 Out << "typename ";
588 else
589 Out << "class ";
590
Anders Carlsson6d845ae2009-06-12 22:23:22 +0000591 if (TTP->isParameterPack())
592 Out << "... ";
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Anders Carlsson0487f662009-06-04 05:37:43 +0000594 Out << ParamType.getAsString(Policy);
595
596 if (TTP->hasDefaultArgument()) {
597 Out << " = ";
598 Out << TTP->getDefaultArgument().getAsString(Policy);
599 };
Mike Stump1eb44332009-09-09 15:08:12 +0000600 } else if (const NonTypeTemplateParmDecl *NTTP =
Anders Carlsson0487f662009-06-04 05:37:43 +0000601 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
602 Out << NTTP->getType().getAsString(Policy);
603
604 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
605 Out << ' ';
606 Out << Name->getName();
607 }
Mike Stump1eb44332009-09-09 15:08:12 +0000608
Anders Carlsson0487f662009-06-04 05:37:43 +0000609 if (NTTP->hasDefaultArgument()) {
610 Out << " = ";
Mike Stump1eb44332009-09-09 15:08:12 +0000611 NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy,
Anders Carlsson0487f662009-06-04 05:37:43 +0000612 Indentation);
613 }
614 }
615 }
Mike Stump1eb44332009-09-09 15:08:12 +0000616
Anders Carlsson0487f662009-06-04 05:37:43 +0000617 Out << "> ";
618
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000619 Visit(D->getTemplatedDecl());
620}
621
622//----------------------------------------------------------------------------
623// Objective-C declarations
624//----------------------------------------------------------------------------
625
626void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
627 Out << "@class ";
628 for (ObjCClassDecl::iterator I = D->begin(), E = D->end();
629 I != E; ++I) {
630 if (I != D->begin()) Out << ", ";
Ted Kremenek321c22f2009-11-18 00:28:11 +0000631 Out << I->getInterface()->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000632 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000633}
634
635void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
636 if (OMD->isInstanceMethod())
Douglas Gregor64f65002009-05-30 00:56:08 +0000637 Out << "- ";
Mike Stump1eb44332009-09-09 15:08:12 +0000638 else
Douglas Gregor64f65002009-05-30 00:56:08 +0000639 Out << "+ ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000640 if (!OMD->getResultType().isNull())
Douglas Gregor59e63572009-05-30 06:58:37 +0000641 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000643 std::string name = OMD->getSelector().getAsString();
644 std::string::size_type pos, lastPos = 0;
645 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
646 E = OMD->param_end(); PI != E; ++PI) {
Mike Stump1eb44332009-09-09 15:08:12 +0000647 // FIXME: selector is missing here!
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000648 pos = name.find_first_of(":", lastPos);
649 Out << " " << name.substr(lastPos, pos - lastPos);
Douglas Gregor59e63572009-05-30 06:58:37 +0000650 Out << ":(" << (*PI)->getType().getAsString(Policy) << ")"
Mike Stump1eb44332009-09-09 15:08:12 +0000651 << (*PI)->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000652 lastPos = pos + 1;
653 }
Mike Stump1eb44332009-09-09 15:08:12 +0000654
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000655 if (OMD->param_begin() == OMD->param_end())
656 Out << " " << name;
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000658 if (OMD->isVariadic())
659 Out << ", ...";
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000661 if (OMD->getBody()) {
662 Out << ' ';
Eli Friedman48d14a22009-05-30 05:03:24 +0000663 OMD->getBody()->printPretty(Out, Context, 0, Policy);
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000664 Out << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000665 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000666}
667
668void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
669 std::string I = OID->getNameAsString();
670 ObjCInterfaceDecl *SID = OID->getSuperClass();
671
672 if (SID)
673 Out << "@implementation " << I << " : " << SID->getNameAsString();
674 else
675 Out << "@implementation " << I;
Douglas Gregor64f65002009-05-30 00:56:08 +0000676 Out << "\n";
677 VisitDeclContext(OID, false);
678 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000679}
680
681void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
682 std::string I = OID->getNameAsString();
683 ObjCInterfaceDecl *SID = OID->getSuperClass();
684
685 if (SID)
686 Out << "@interface " << I << " : " << SID->getNameAsString();
687 else
688 Out << "@interface " << I;
Mike Stump1eb44332009-09-09 15:08:12 +0000689
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000690 // Protocols?
691 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
692 if (!Protocols.empty()) {
693 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
694 E = Protocols.end(); I != E; ++I)
695 Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString();
696 }
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000698 if (!Protocols.empty())
Douglas Gregor64f65002009-05-30 00:56:08 +0000699 Out << "> ";
Mike Stump1eb44332009-09-09 15:08:12 +0000700
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000701 if (OID->ivar_size() > 0) {
Douglas Gregor64f65002009-05-30 00:56:08 +0000702 Out << "{\n";
703 Indentation += Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000704 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
705 E = OID->ivar_end(); I != E; ++I) {
Douglas Gregor64f65002009-05-30 00:56:08 +0000706 Indent() << (*I)->getType().getAsString(Policy)
Mike Stump1eb44332009-09-09 15:08:12 +0000707 << ' ' << (*I)->getNameAsString() << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000708 }
Douglas Gregor64f65002009-05-30 00:56:08 +0000709 Indentation -= Policy.Indentation;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000710 Out << "}\n";
711 }
Mike Stump1eb44332009-09-09 15:08:12 +0000712
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000713 VisitDeclContext(OID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000714 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000715 // FIXME: implement the rest...
716}
717
718void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
719 Out << "@protocol ";
Mike Stump1eb44332009-09-09 15:08:12 +0000720 for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(),
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000721 E = D->protocol_end();
722 I != E; ++I) {
723 if (I != D->protocol_begin()) Out << ", ";
724 Out << (*I)->getNameAsString();
725 }
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000726}
727
728void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
729 Out << "@protocol " << PID->getNameAsString() << '\n';
Douglas Gregor64f65002009-05-30 00:56:08 +0000730 VisitDeclContext(PID, false);
731 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000732}
733
734void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
735 Out << "@implementation "
736 << PID->getClassInterface()->getNameAsString()
Mike Stump1eb44332009-09-09 15:08:12 +0000737 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000738
739 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000740 Out << "@end";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000741 // FIXME: implement the rest...
742}
743
744void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
Mike Stump1eb44332009-09-09 15:08:12 +0000745 Out << "@interface "
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000746 << PID->getClassInterface()->getNameAsString()
Douglas Gregor64f65002009-05-30 00:56:08 +0000747 << '(' << PID->getNameAsString() << ")\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000748 VisitDeclContext(PID, false);
Douglas Gregor64f65002009-05-30 00:56:08 +0000749 Out << "@end";
Mike Stump1eb44332009-09-09 15:08:12 +0000750
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000751 // FIXME: implement the rest...
752}
753
754void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Mike Stump1eb44332009-09-09 15:08:12 +0000755 Out << "@compatibility_alias " << AID->getNameAsString()
756 << ' ' << AID->getClassInterface()->getNameAsString() << ";\n";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000757}
758
759/// PrintObjCPropertyDecl - print a property declaration.
760///
761void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
762 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
763 Out << "@required\n";
764 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
765 Out << "@optional\n";
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000767 Out << "@property";
768 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
769 bool first = true;
770 Out << " (";
Mike Stump1eb44332009-09-09 15:08:12 +0000771 if (PDecl->getPropertyAttributes() &
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000772 ObjCPropertyDecl::OBJC_PR_readonly) {
773 Out << (first ? ' ' : ',') << "readonly";
774 first = false;
775 }
Mike Stump1eb44332009-09-09 15:08:12 +0000776
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000777 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
778 Out << (first ? ' ' : ',') << "getter = "
779 << PDecl->getGetterName().getAsString();
780 first = false;
781 }
782 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
783 Out << (first ? ' ' : ',') << "setter = "
784 << PDecl->getSetterName().getAsString();
785 first = false;
786 }
Mike Stump1eb44332009-09-09 15:08:12 +0000787
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000788 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
789 Out << (first ? ' ' : ',') << "assign";
790 first = false;
791 }
Mike Stump1eb44332009-09-09 15:08:12 +0000792
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000793 if (PDecl->getPropertyAttributes() &
794 ObjCPropertyDecl::OBJC_PR_readwrite) {
795 Out << (first ? ' ' : ',') << "readwrite";
796 first = false;
797 }
Mike Stump1eb44332009-09-09 15:08:12 +0000798
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000799 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
800 Out << (first ? ' ' : ',') << "retain";
801 first = false;
802 }
Mike Stump1eb44332009-09-09 15:08:12 +0000803
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000804 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
805 Out << (first ? ' ' : ',') << "copy";
806 first = false;
807 }
Mike Stump1eb44332009-09-09 15:08:12 +0000808
809 if (PDecl->getPropertyAttributes() &
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000810 ObjCPropertyDecl::OBJC_PR_nonatomic) {
811 Out << (first ? ' ' : ',') << "nonatomic";
812 first = false;
813 }
814 Out << " )";
815 }
816 Out << ' ' << PDecl->getType().getAsString(Policy)
817 << ' ' << PDecl->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000818}
819
820void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
821 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Douglas Gregor64f65002009-05-30 00:56:08 +0000822 Out << "@synthesize ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000823 else
Douglas Gregor64f65002009-05-30 00:56:08 +0000824 Out << "@dynamic ";
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000825 Out << PID->getPropertyDecl()->getNameAsString();
826 if (PID->getPropertyIvarDecl())
827 Out << "=" << PID->getPropertyIvarDecl()->getNameAsString();
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000828}
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000829
830void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
831 Out << "using ";
832 D->getTargetNestedNameDecl()->print(Out, Policy);
John McCall9488ea12009-11-17 05:59:44 +0000833 Out << D->getNameAsString();
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000834}
835
John McCall7ba107a2009-11-18 02:36:19 +0000836void
837DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
838 Out << "using typename ";
839 D->getTargetNestedNameSpecifier()->print(Out, Policy);
840 Out << D->getDeclName().getAsString();
841}
842
843void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000844 Out << "using ";
845 D->getTargetNestedNameSpecifier()->print(Out, Policy);
John McCall7ba107a2009-11-18 02:36:19 +0000846 Out << D->getDeclName().getAsString();
Anders Carlssonf53eaa52009-08-28 19:16:39 +0000847}
John McCall9488ea12009-11-17 05:59:44 +0000848
849void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
850 // ignore
851}