1 //===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Decl::dump method, which pretty print the
11 // AST back out to C/Objective-C/C++/Objective-C++ code.
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"
22 #include "llvm/Support/Format.h"
23 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
27 class VISIBILITY_HIDDEN DeclPrinter : public DeclVisitor<DeclPrinter> {
28 llvm::raw_ostream &Out;
30 PrintingPolicy Policy;
33 llvm::raw_ostream& Indent();
34 void ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls);
36 void Print(AccessSpecifier AS);
39 DeclPrinter(llvm::raw_ostream &Out, ASTContext &Context,
40 const PrintingPolicy &Policy,
41 unsigned Indentation = 0)
42 : Out(Out), Context(Context), Policy(Policy), Indentation(Indentation) { }
44 void VisitDeclContext(DeclContext *DC, bool Indent = true);
46 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
47 void VisitTypedefDecl(TypedefDecl *D);
48 void VisitEnumDecl(EnumDecl *D);
49 void VisitRecordDecl(RecordDecl *D);
50 void VisitEnumConstantDecl(EnumConstantDecl *D);
51 void VisitFunctionDecl(FunctionDecl *D);
52 void VisitFieldDecl(FieldDecl *D);
53 void VisitVarDecl(VarDecl *D);
54 void VisitParmVarDecl(ParmVarDecl *D);
55 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
56 void VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D);
57 void VisitNamespaceDecl(NamespaceDecl *D);
58 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
59 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
60 void VisitCXXRecordDecl(CXXRecordDecl *D);
61 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
62 void VisitTemplateDecl(TemplateDecl *D);
63 void VisitObjCMethodDecl(ObjCMethodDecl *D);
64 void VisitObjCClassDecl(ObjCClassDecl *D);
65 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
66 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
67 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
68 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
69 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
70 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
71 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
72 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
73 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
74 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
75 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
76 void VisitUsingDecl(UsingDecl *D);
77 void VisitUsingShadowDecl(UsingShadowDecl *D);
81 void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) const {
82 print(Out, getASTContext().PrintingPolicy, Indentation);
85 void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
86 unsigned Indentation) const {
87 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation);
88 Printer.Visit(const_cast<Decl*>(this));
91 static QualType GetBaseType(QualType T) {
92 // FIXME: This should be on the Type class!
93 QualType BaseType = T;
94 while (!BaseType->isSpecifierType()) {
95 if (isa<TypedefType>(BaseType))
97 else if (const PointerType* PTy = BaseType->getAs<PointerType>())
98 BaseType = PTy->getPointeeType();
99 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
100 BaseType = ATy->getElementType();
101 else if (const FunctionType* FTy = BaseType->getAs<FunctionType>())
102 BaseType = FTy->getResultType();
103 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
104 BaseType = VTy->getElementType();
106 assert(0 && "Unknown declarator!");
111 static QualType getDeclType(Decl* D) {
112 if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D))
113 return TDD->getUnderlyingType();
114 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
115 return VD->getType();
119 void Decl::printGroup(Decl** Begin, unsigned NumDecls,
120 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
121 unsigned Indentation) {
123 (*Begin)->print(Out, Policy, Indentation);
127 Decl** End = Begin + NumDecls;
128 TagDecl* TD = dyn_cast<TagDecl>(*Begin);
132 PrintingPolicy SubPolicy(Policy);
133 if (TD && TD->isDefinition()) {
134 TD->print(Out, Policy, Indentation);
136 SubPolicy.SuppressTag = true;
140 for ( ; Begin != End; ++Begin) {
142 SubPolicy.SuppressSpecifiers = false;
145 if (!isFirst) Out << ", ";
146 SubPolicy.SuppressSpecifiers = true;
149 (*Begin)->print(Out, SubPolicy, Indentation);
153 void Decl::dump() const {
157 llvm::raw_ostream& DeclPrinter::Indent() {
158 for (unsigned i = 0; i < Indentation; ++i)
163 void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) {
165 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
171 void DeclPrinter::Print(AccessSpecifier AS) {
173 case AS_none: assert(0 && "No access specifier!"); break;
174 case AS_public: Out << "public"; break;
175 case AS_protected: Out << "protected"; break;
176 case AS_private: Out << " private"; break;
180 //----------------------------------------------------------------------------
181 // Common C declarations
182 //----------------------------------------------------------------------------
184 void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
186 Indentation += Policy.Indentation;
188 bool PrintAccess = isa<CXXRecordDecl>(DC);
189 AccessSpecifier CurAS = AS_none;
191 llvm::SmallVector<Decl*, 2> Decls;
192 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
195 // Skip over implicit declarations in pretty-printing mode.
196 if (D->isImplicit()) continue;
197 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
198 // of __builtin_va_list. There should be some other way to check that.
199 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() ==
205 AccessSpecifier AS = D->getAccess();
214 // 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.
220 // Check whether the current declaration should be grouped with a previous
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]) {
232 // If we have a merged group waiting to be handled, handle it now.
234 ProcessDeclGroup(Decls);
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()) {
245 // FIXME: Need to be able to tell the DeclPrinter when
246 const char *Terminator = 0;
247 if (isa<FunctionDecl>(*D) &&
248 cast<FunctionDecl>(*D)->isThisDeclarationADefinition())
250 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody())
252 else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
253 isa<ObjCImplementationDecl>(*D) ||
254 isa<ObjCInterfaceDecl>(*D) ||
255 isa<ObjCProtocolDecl>(*D) ||
256 isa<ObjCCategoryImplDecl>(*D) ||
257 isa<ObjCCategoryDecl>(*D))
259 else if (isa<EnumConstantDecl>(*D)) {
260 DeclContext::decl_iterator Next = D;
273 ProcessDeclGroup(Decls);
276 Indentation -= Policy.Indentation;
279 void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
280 VisitDeclContext(D, false);
283 void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
284 std::string S = D->getNameAsString();
285 D->getUnderlyingType().getAsStringInternal(S, Policy);
286 if (!Policy.SuppressSpecifiers)
291 void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
292 Out << "enum " << D->getNameAsString() << " {\n";
297 void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
298 Out << D->getKindName();
299 if (D->getIdentifier()) {
301 Out << D->getNameAsString();
304 if (D->isDefinition()) {
311 void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
312 Out << D->getNameAsString();
313 if (Expr *Init = D->getInitExpr()) {
315 Init->printPretty(Out, Context, 0, Policy, Indentation);
319 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
320 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;
328 if (D->isInlineSpecified()) Out << "inline ";
329 if (D->isVirtualAsWritten()) Out << "virtual ";
332 PrintingPolicy SubPolicy(Policy);
333 SubPolicy.SuppressSpecifiers = false;
334 std::string Proto = D->getNameAsString();
335 if (isa<FunctionType>(D->getType().getTypePtr())) {
336 const FunctionType *AFT = D->getType()->getAs<FunctionType>();
338 const FunctionProtoType *FT = 0;
339 if (D->hasWrittenPrototype())
340 FT = dyn_cast<FunctionProtoType>(AFT);
344 llvm::raw_string_ostream POut(Proto);
345 DeclPrinter ParamPrinter(POut, Context, SubPolicy, Indentation);
346 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
348 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
351 if (FT->isVariadic()) {
352 if (D->getNumParams()) POut << ", ";
355 } else if (D->isThisDeclarationADefinition() && !D->hasPrototype()) {
356 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
359 Proto += D->getParamDecl(i)->getNameAsString();
364 if (D->hasAttr<NoReturnAttr>())
365 Proto += " __attribute((noreturn))";
366 if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) {
367 if (CDecl->getNumBaseOrMemberInitializers() > 0) {
371 for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
372 E = CDecl->init_end();
374 CXXBaseOrMemberInitializer * BMInitializer = (*B);
375 if (B != CDecl->init_begin())
377 bool hasArguments = (BMInitializer->arg_begin() !=
378 BMInitializer->arg_end());
379 if (BMInitializer->isMemberInitializer()) {
380 FieldDecl *FD = BMInitializer->getMember();
381 Out << FD->getNameAsString();
383 else // FIXME. skip dependent types for now.
384 if (const RecordType *RT =
385 BMInitializer->getBaseClass()->getAs<RecordType>()) {
386 const CXXRecordDecl *BaseDecl =
387 cast<CXXRecordDecl>(RT->getDecl());
388 Out << BaseDecl->getNameAsString();
392 for (CXXBaseOrMemberInitializer::const_arg_iterator BE =
393 BMInitializer->const_arg_begin(),
394 EE = BMInitializer->const_arg_end(); BE != EE; ++BE) {
395 if (BE != BMInitializer->const_arg_begin())
397 const Expr *Exp = (*BE);
398 Exp->printPretty(Out, Context, 0, Policy, Indentation);
407 AFT->getResultType().getAsStringInternal(Proto, Policy);
409 D->getType().getAsStringInternal(Proto, Policy);
416 else if (D->isDeleted())
418 else if (D->isThisDeclarationADefinition()) {
419 if (!D->hasPrototype() && D->getNumParams()) {
420 // This is a K&R function definition, so we need to print the
423 DeclPrinter ParamPrinter(Out, Context, SubPolicy, Indentation);
424 Indentation += Policy.Indentation;
425 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
427 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
430 Indentation -= Policy.Indentation;
434 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
439 void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
440 if (!Policy.SuppressSpecifiers && D->isMutable())
443 std::string Name = D->getNameAsString();
444 D->getType().getAsStringInternal(Name, Policy);
447 if (D->isBitField()) {
449 D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
453 void DeclPrinter::VisitVarDecl(VarDecl *D) {
454 if (!Policy.SuppressSpecifiers && D->getStorageClass() != VarDecl::None)
455 Out << VarDecl::getStorageClassSpecifierString(D->getStorageClass()) << " ";
457 if (!Policy.SuppressSpecifiers && D->isThreadSpecified())
460 std::string Name = D->getNameAsString();
461 QualType T = D->getType();
462 if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
463 T = Parm->getOriginalType();
464 T.getAsStringInternal(Name, Policy);
467 if (D->hasCXXDirectInitializer())
471 D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
472 if (D->hasCXXDirectInitializer())
477 void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
481 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
483 D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
487 //----------------------------------------------------------------------------
489 //----------------------------------------------------------------------------
490 void DeclPrinter::VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D) {
492 "OverloadedFunctionDecls aren't really decls and are never printed");
495 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
496 Out << "namespace " << D->getNameAsString() << " {\n";
501 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
502 Out << "using namespace ";
503 if (D->getQualifier())
504 D->getQualifier()->print(Out, Policy);
505 Out << D->getNominatedNamespace()->getNameAsString();
508 void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
509 Out << "namespace " << D->getNameAsString() << " = ";
510 if (D->getQualifier())
511 D->getQualifier()->print(Out, Policy);
512 Out << D->getAliasedNamespace()->getNameAsString();
515 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
516 Out << D->getKindName();
517 if (D->getIdentifier()) {
519 Out << D->getNameAsString();
522 if (D->isDefinition()) {
523 // Print the base classes
524 if (D->getNumBases()) {
526 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
527 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
528 if (Base != D->bases_begin())
531 if (Base->isVirtual())
534 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
537 Out << " " << Base->getType().getAsString(Policy);
541 // Print the class definition
542 // FIXME: Doesn't print access specifiers, e.g., "public:"
549 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
551 if (D->getLanguage() == LinkageSpecDecl::lang_c)
554 assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
555 "unknown language in linkage specification");
559 Out << "extern \"" << l << "\" ";
560 if (D->hasBraces()) {
565 Visit(*D->decls_begin());
568 void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
571 TemplateParameterList *Params = D->getTemplateParameters();
572 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
576 const Decl *Param = Params->getParam(i);
577 if (const TemplateTypeParmDecl *TTP =
578 dyn_cast<TemplateTypeParmDecl>(Param)) {
581 Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP));
583 if (TTP->wasDeclaredWithTypename())
588 if (TTP->isParameterPack())
591 Out << ParamType.getAsString(Policy);
593 if (TTP->hasDefaultArgument()) {
595 Out << TTP->getDefaultArgument().getAsString(Policy);
597 } else if (const NonTypeTemplateParmDecl *NTTP =
598 dyn_cast<NonTypeTemplateParmDecl>(Param)) {
599 Out << NTTP->getType().getAsString(Policy);
601 if (IdentifierInfo *Name = NTTP->getIdentifier()) {
603 Out << Name->getName();
606 if (NTTP->hasDefaultArgument()) {
608 NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy,
616 Visit(D->getTemplatedDecl());
619 //----------------------------------------------------------------------------
620 // Objective-C declarations
621 //----------------------------------------------------------------------------
623 void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
625 for (ObjCClassDecl::iterator I = D->begin(), E = D->end();
627 if (I != D->begin()) Out << ", ";
628 Out << I->getInterface()->getNameAsString();
632 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
633 if (OMD->isInstanceMethod())
637 if (!OMD->getResultType().isNull())
638 Out << '(' << OMD->getResultType().getAsString(Policy) << ")";
640 std::string name = OMD->getSelector().getAsString();
641 std::string::size_type pos, lastPos = 0;
642 for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
643 E = OMD->param_end(); PI != E; ++PI) {
644 // FIXME: selector is missing here!
645 pos = name.find_first_of(":", lastPos);
646 Out << " " << name.substr(lastPos, pos - lastPos);
647 Out << ":(" << (*PI)->getType().getAsString(Policy) << ")"
648 << (*PI)->getNameAsString();
652 if (OMD->param_begin() == OMD->param_end())
655 if (OMD->isVariadic())
658 if (OMD->getBody()) {
660 OMD->getBody()->printPretty(Out, Context, 0, Policy);
665 void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
666 std::string I = OID->getNameAsString();
667 ObjCInterfaceDecl *SID = OID->getSuperClass();
670 Out << "@implementation " << I << " : " << SID->getNameAsString();
672 Out << "@implementation " << I;
674 VisitDeclContext(OID, false);
678 void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
679 std::string I = OID->getNameAsString();
680 ObjCInterfaceDecl *SID = OID->getSuperClass();
683 Out << "@interface " << I << " : " << SID->getNameAsString();
685 Out << "@interface " << I;
688 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
689 if (!Protocols.empty()) {
690 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
691 E = Protocols.end(); I != E; ++I)
692 Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString();
695 if (!Protocols.empty())
698 if (OID->ivar_size() > 0) {
700 Indentation += Policy.Indentation;
701 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
702 E = OID->ivar_end(); I != E; ++I) {
703 Indent() << (*I)->getType().getAsString(Policy)
704 << ' ' << (*I)->getNameAsString() << ";\n";
706 Indentation -= Policy.Indentation;
710 VisitDeclContext(OID, false);
712 // FIXME: implement the rest...
715 void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
717 for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(),
718 E = D->protocol_end();
720 if (I != D->protocol_begin()) Out << ", ";
721 Out << (*I)->getNameAsString();
725 void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
726 Out << "@protocol " << PID->getNameAsString() << '\n';
727 VisitDeclContext(PID, false);
731 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
732 Out << "@implementation "
733 << PID->getClassInterface()->getNameAsString()
734 << '(' << PID->getNameAsString() << ")\n";
736 VisitDeclContext(PID, false);
738 // FIXME: implement the rest...
741 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
743 << PID->getClassInterface()->getNameAsString()
744 << '(' << PID->getNameAsString() << ")\n";
745 VisitDeclContext(PID, false);
748 // FIXME: implement the rest...
751 void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
752 Out << "@compatibility_alias " << AID->getNameAsString()
753 << ' ' << AID->getClassInterface()->getNameAsString() << ";\n";
756 /// PrintObjCPropertyDecl - print a property declaration.
758 void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
759 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
760 Out << "@required\n";
761 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
762 Out << "@optional\n";
765 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
768 if (PDecl->getPropertyAttributes() &
769 ObjCPropertyDecl::OBJC_PR_readonly) {
770 Out << (first ? ' ' : ',') << "readonly";
774 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
775 Out << (first ? ' ' : ',') << "getter = "
776 << PDecl->getGetterName().getAsString();
779 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
780 Out << (first ? ' ' : ',') << "setter = "
781 << PDecl->getSetterName().getAsString();
785 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
786 Out << (first ? ' ' : ',') << "assign";
790 if (PDecl->getPropertyAttributes() &
791 ObjCPropertyDecl::OBJC_PR_readwrite) {
792 Out << (first ? ' ' : ',') << "readwrite";
796 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
797 Out << (first ? ' ' : ',') << "retain";
801 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
802 Out << (first ? ' ' : ',') << "copy";
806 if (PDecl->getPropertyAttributes() &
807 ObjCPropertyDecl::OBJC_PR_nonatomic) {
808 Out << (first ? ' ' : ',') << "nonatomic";
813 Out << ' ' << PDecl->getType().getAsString(Policy)
814 << ' ' << PDecl->getNameAsString();
817 void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
818 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
819 Out << "@synthesize ";
822 Out << PID->getPropertyDecl()->getNameAsString();
823 if (PID->getPropertyIvarDecl())
824 Out << "=" << PID->getPropertyIvarDecl()->getNameAsString();
827 void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
829 D->getTargetNestedNameDecl()->print(Out, Policy);
830 Out << D->getNameAsString();
834 DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
835 Out << "using typename ";
836 D->getTargetNestedNameSpecifier()->print(Out, Policy);
837 Out << D->getDeclName().getAsString();
840 void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
842 D->getTargetNestedNameSpecifier()->print(Out, Policy);
843 Out << D->getDeclName().getAsString();
846 void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {