Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1 | //===--- 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" |
Benjamin Kramer | 2fa67ef | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/Attr.h" |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/DeclCXX.h" |
| 18 | #include "clang/AST/DeclObjC.h" |
Benjamin Kramer | 2fa67ef | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclVisitor.h" |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 22 | #include "clang/AST/PrettyPrinter.h" |
Douglas Gregor | 15de72c | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Module.h" |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | using namespace clang; |
| 26 | |
| 27 | namespace { |
Benjamin Kramer | 770b4a8 | 2009-11-28 19:03:38 +0000 | [diff] [blame] | 28 | class DeclPrinter : public DeclVisitor<DeclPrinter> { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 29 | raw_ostream &Out; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 30 | PrintingPolicy Policy; |
| 31 | unsigned Indentation; |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 32 | bool PrintInstantiation; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 33 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 34 | raw_ostream& Indent() { return Indent(Indentation); } |
| 35 | raw_ostream& Indent(unsigned Indentation); |
| 36 | void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 37 | |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 38 | void Print(AccessSpecifier AS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 40 | public: |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 41 | DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy, |
| 42 | unsigned Indentation = 0, bool PrintInstantiation = false) |
| 43 | : Out(Out), Policy(Policy), Indentation(Indentation), |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 44 | PrintInstantiation(PrintInstantiation) { } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 45 | |
| 46 | void VisitDeclContext(DeclContext *DC, bool Indent = true); |
| 47 | |
| 48 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 49 | void VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 50 | void VisitTypeAliasDecl(TypeAliasDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 51 | void VisitEnumDecl(EnumDecl *D); |
| 52 | void VisitRecordDecl(RecordDecl *D); |
| 53 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
| 54 | void VisitFunctionDecl(FunctionDecl *D); |
| 55 | void VisitFieldDecl(FieldDecl *D); |
| 56 | void VisitVarDecl(VarDecl *D); |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 57 | void VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 58 | void VisitParmVarDecl(ParmVarDecl *D); |
| 59 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
Douglas Gregor | 15de72c | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 60 | void VisitImportDecl(ImportDecl *D); |
Peter Collingbourne | 28ac87e | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 61 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 62 | void VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 63 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 64 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 65 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 66 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Richard Smith | 98a5786 | 2011-04-15 13:38:57 +0000 | [diff] [blame] | 67 | void VisitTemplateDecl(const TemplateDecl *D); |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 68 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| 69 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 70 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 71 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 72 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 73 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 74 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 75 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 76 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 77 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 78 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 79 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 80 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 81 | void VisitUsingDecl(UsingDecl *D); |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 82 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 83 | |
| 84 | void PrintTemplateParameters(const TemplateParameterList *Params, |
| 85 | const TemplateArgumentList *Args); |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 86 | void prettyPrintAttributes(Decl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 87 | }; |
| 88 | } |
| 89 | |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 90 | void Decl::print(raw_ostream &Out, unsigned Indentation, |
| 91 | bool PrintInstantiation) const { |
Douglas Gregor | 30c4240 | 2011-09-27 22:38:19 +0000 | [diff] [blame] | 92 | print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 95 | void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy, |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 96 | unsigned Indentation, bool PrintInstantiation) const { |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 97 | DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation); |
Anders Carlsson | f88df86 | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 98 | Printer.Visit(const_cast<Decl*>(this)); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 101 | static QualType GetBaseType(QualType T) { |
| 102 | // FIXME: This should be on the Type class! |
| 103 | QualType BaseType = T; |
| 104 | while (!BaseType->isSpecifierType()) { |
| 105 | if (isa<TypedefType>(BaseType)) |
| 106 | break; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 107 | else if (const PointerType* PTy = BaseType->getAs<PointerType>()) |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 108 | BaseType = PTy->getPointeeType(); |
Ted Kremenek | 41c1f21 | 2012-10-11 20:58:14 +0000 | [diff] [blame] | 109 | else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>()) |
| 110 | BaseType = BPy->getPointeeType(); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 111 | else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType)) |
| 112 | BaseType = ATy->getElementType(); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 113 | else if (const FunctionType* FTy = BaseType->getAs<FunctionType>()) |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 114 | BaseType = FTy->getResultType(); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 115 | else if (const VectorType *VTy = BaseType->getAs<VectorType>()) |
Douglas Gregor | 5068ab6 | 2009-07-01 23:58:14 +0000 | [diff] [blame] | 116 | BaseType = VTy->getElementType(); |
Eli Friedman | 15631b4 | 2012-08-08 03:47:15 +0000 | [diff] [blame] | 117 | else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>()) |
| 118 | BaseType = RTy->getPointeeType(); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 119 | else |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 120 | llvm_unreachable("Unknown declarator!"); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 121 | } |
| 122 | return BaseType; |
| 123 | } |
| 124 | |
| 125 | static QualType getDeclType(Decl* D) { |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 126 | if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D)) |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 127 | return TDD->getUnderlyingType(); |
| 128 | if (ValueDecl* VD = dyn_cast<ValueDecl>(D)) |
| 129 | return VD->getType(); |
| 130 | return QualType(); |
| 131 | } |
| 132 | |
| 133 | void Decl::printGroup(Decl** Begin, unsigned NumDecls, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 134 | raw_ostream &Out, const PrintingPolicy &Policy, |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 135 | unsigned Indentation) { |
| 136 | if (NumDecls == 1) { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 137 | (*Begin)->print(Out, Policy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 138 | return; |
| 139 | } |
| 140 | |
| 141 | Decl** End = Begin + NumDecls; |
| 142 | TagDecl* TD = dyn_cast<TagDecl>(*Begin); |
| 143 | if (TD) |
| 144 | ++Begin; |
| 145 | |
| 146 | PrintingPolicy SubPolicy(Policy); |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 147 | if (TD && TD->isCompleteDefinition()) { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 148 | TD->print(Out, Policy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 149 | Out << " "; |
| 150 | SubPolicy.SuppressTag = true; |
| 151 | } |
| 152 | |
| 153 | bool isFirst = true; |
| 154 | for ( ; Begin != End; ++Begin) { |
| 155 | if (isFirst) { |
| 156 | SubPolicy.SuppressSpecifiers = false; |
| 157 | isFirst = false; |
| 158 | } else { |
| 159 | if (!isFirst) Out << ", "; |
| 160 | SubPolicy.SuppressSpecifiers = true; |
| 161 | } |
| 162 | |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 163 | (*Begin)->print(Out, SubPolicy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
Anders Carlsson | 8483443 | 2009-12-14 00:51:04 +0000 | [diff] [blame] | 167 | void DeclContext::dumpDeclContext() const { |
Anders Carlsson | 2b7d8dd | 2009-12-09 17:27:46 +0000 | [diff] [blame] | 168 | // Get the translation unit |
| 169 | const DeclContext *DC = this; |
| 170 | while (!DC->isTranslationUnit()) |
| 171 | DC = DC->getParent(); |
| 172 | |
| 173 | ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 174 | DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0); |
Anders Carlsson | 2b7d8dd | 2009-12-09 17:27:46 +0000 | [diff] [blame] | 175 | Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false); |
| 176 | } |
| 177 | |
Benjamin Kramer | 42c72c2 | 2012-08-14 14:50:32 +0000 | [diff] [blame] | 178 | void Decl::dump() const { |
| 179 | dump(llvm::errs()); |
| 180 | } |
| 181 | |
Alexander Kornienko | e34a052 | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 182 | void Decl::dump(raw_ostream &Out) const { |
| 183 | PrintingPolicy Policy = getASTContext().getPrintingPolicy(); |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 184 | Policy.DumpSourceManager = &getASTContext().getSourceManager(); |
Alexander Kornienko | e34a052 | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 185 | print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ true); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 188 | raw_ostream& DeclPrinter::Indent(unsigned Indentation) { |
Daniel Dunbar | 512ce60 | 2009-11-21 09:12:06 +0000 | [diff] [blame] | 189 | for (unsigned i = 0; i != Indentation; ++i) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 190 | Out << " "; |
| 191 | return Out; |
| 192 | } |
| 193 | |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 194 | void DeclPrinter::prettyPrintAttributes(Decl *D) { |
Fariborz Jahanian | 1bfb00d | 2012-10-17 21:58:03 +0000 | [diff] [blame] | 195 | if (Policy.SuppressAttributes) |
| 196 | return; |
| 197 | |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 198 | if (D->hasAttrs()) { |
| 199 | AttrVec &Attrs = D->getAttrs(); |
| 200 | for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) { |
Richard Smith | 0dae729 | 2012-08-16 02:43:29 +0000 | [diff] [blame] | 201 | Attr *A = *i; |
| 202 | A->printPretty(Out, Policy); |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 207 | void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 208 | this->Indent(); |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 209 | Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 210 | Out << ";\n"; |
| 211 | Decls.clear(); |
| 212 | |
| 213 | } |
| 214 | |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 215 | void DeclPrinter::Print(AccessSpecifier AS) { |
| 216 | switch(AS) { |
David Blaikie | eb2d1f1 | 2011-09-23 20:26:49 +0000 | [diff] [blame] | 217 | case AS_none: llvm_unreachable("No access specifier!"); |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 218 | case AS_public: Out << "public"; break; |
| 219 | case AS_protected: Out << "protected"; break; |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 220 | case AS_private: Out << "private"; break; |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 224 | //---------------------------------------------------------------------------- |
| 225 | // Common C declarations |
| 226 | //---------------------------------------------------------------------------- |
| 227 | |
| 228 | void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { |
Dmitri Gribenko | d1fc82e | 2012-08-21 17:36:32 +0000 | [diff] [blame] | 229 | if (Policy.TerseOutput) |
Dmitri Gribenko | 49795ae | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 230 | return; |
| 231 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 232 | if (Indent) |
| 233 | Indentation += Policy.Indentation; |
| 234 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 235 | SmallVector<Decl*, 2> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 236 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 237 | D != DEnd; ++D) { |
Ted Kremenek | 2d6c906 | 2010-07-30 00:47:46 +0000 | [diff] [blame] | 238 | |
| 239 | // Don't print ObjCIvarDecls, as they are printed when visiting the |
| 240 | // containing ObjCInterfaceDecl. |
| 241 | if (isa<ObjCIvarDecl>(*D)) |
| 242 | continue; |
| 243 | |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 244 | if (!Policy.DumpSourceManager) { |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 245 | // Skip over implicit declarations in pretty-printing mode. |
| 246 | if (D->isImplicit()) continue; |
Eli Friedman | 3d4a7c9 | 2009-05-30 06:35:22 +0000 | [diff] [blame] | 247 | // FIXME: Ugly hack so we don't pretty-print the builtin declaration |
Argyrios Kyrtzidis | 2574f6f | 2010-06-17 10:52:11 +0000 | [diff] [blame] | 248 | // of __builtin_va_list or __[u]int128_t. There should be some other way |
| 249 | // to check that. |
| 250 | if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) { |
| 251 | if (IdentifierInfo *II = ND->getIdentifier()) { |
| 252 | if (II->isStr("__builtin_va_list") || |
| 253 | II->isStr("__int128_t") || II->isStr("__uint128_t")) |
| 254 | continue; |
| 255 | } |
| 256 | } |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 259 | // The next bits of code handles stuff like "struct {int x;} a,b"; we're |
| 260 | // forced to merge the declarations because there's no other way to |
| 261 | // refer to the struct in question. This limited merging is safe without |
| 262 | // a bunch of other checks because it only merges declarations directly |
| 263 | // referring to the tag, not typedefs. |
| 264 | // |
| 265 | // Check whether the current declaration should be grouped with a previous |
| 266 | // unnamed struct. |
| 267 | QualType CurDeclType = getDeclType(*D); |
| 268 | if (!Decls.empty() && !CurDeclType.isNull()) { |
| 269 | QualType BaseType = GetBaseType(CurDeclType); |
| 270 | if (!BaseType.isNull() && isa<TagType>(BaseType) && |
| 271 | cast<TagType>(BaseType)->getDecl() == Decls[0]) { |
| 272 | Decls.push_back(*D); |
| 273 | continue; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // If we have a merged group waiting to be handled, handle it now. |
| 278 | if (!Decls.empty()) |
| 279 | ProcessDeclGroup(Decls); |
| 280 | |
| 281 | // If the current declaration is an unnamed tag type, save it |
| 282 | // so we can merge it with the subsequent declaration(s) using it. |
| 283 | if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) { |
| 284 | Decls.push_back(*D); |
| 285 | continue; |
| 286 | } |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 287 | |
| 288 | if (isa<AccessSpecDecl>(*D)) { |
| 289 | Indentation -= Policy.Indentation; |
| 290 | this->Indent(); |
| 291 | Print(D->getAccess()); |
| 292 | Out << ":\n"; |
| 293 | Indentation += Policy.Indentation; |
| 294 | continue; |
| 295 | } |
| 296 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 297 | this->Indent(); |
| 298 | Visit(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 299 | |
| 300 | // FIXME: Need to be able to tell the DeclPrinter when |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 301 | const char *Terminator = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | if (isa<FunctionDecl>(*D) && |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 303 | cast<FunctionDecl>(*D)->isThisDeclarationADefinition()) |
| 304 | Terminator = 0; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 305 | else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody()) |
| 306 | Terminator = 0; |
| 307 | else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) || |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | isa<ObjCImplementationDecl>(*D) || |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 309 | isa<ObjCInterfaceDecl>(*D) || |
| 310 | isa<ObjCProtocolDecl>(*D) || |
| 311 | isa<ObjCCategoryImplDecl>(*D) || |
| 312 | isa<ObjCCategoryDecl>(*D)) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 313 | Terminator = 0; |
| 314 | else if (isa<EnumConstantDecl>(*D)) { |
| 315 | DeclContext::decl_iterator Next = D; |
| 316 | ++Next; |
| 317 | if (Next != DEnd) |
| 318 | Terminator = ","; |
| 319 | } else |
| 320 | Terminator = ";"; |
| 321 | |
| 322 | if (Terminator) |
| 323 | Out << Terminator; |
| 324 | Out << "\n"; |
| 325 | } |
| 326 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 327 | if (!Decls.empty()) |
| 328 | ProcessDeclGroup(Decls); |
| 329 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 330 | if (Indent) |
| 331 | Indentation -= Policy.Indentation; |
| 332 | } |
| 333 | |
| 334 | void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 335 | VisitDeclContext(D, false); |
| 336 | } |
| 337 | |
| 338 | void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) { |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 339 | if (!Policy.SuppressSpecifiers) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 340 | Out << "typedef "; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 341 | |
| 342 | if (D->isModulePrivate()) |
| 343 | Out << "__module_private__ "; |
| 344 | } |
Argyrios Kyrtzidis | 7ad5c99 | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 345 | D->getUnderlyingType().print(Out, Policy, D->getName()); |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 346 | prettyPrintAttributes(D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 349 | void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Benjamin Kramer | a59d20b | 2012-02-07 11:57:57 +0000 | [diff] [blame] | 350 | Out << "using " << *D << " = " << D->getUnderlyingType().getAsString(Policy); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 353 | void DeclPrinter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 354 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 355 | Out << "__module_private__ "; |
Douglas Gregor | 9fa8c46 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 356 | Out << "enum "; |
Abramo Bagnara | a88cefd | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 357 | if (D->isScoped()) { |
| 358 | if (D->isScopedUsingClassTag()) |
| 359 | Out << "class "; |
| 360 | else |
| 361 | Out << "struct "; |
| 362 | } |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 363 | Out << *D; |
Douglas Gregor | 9fa8c46 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 364 | |
Argyrios Kyrtzidis | 7ad5c99 | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 365 | if (D->isFixed()) |
| 366 | Out << " : " << D->getIntegerType().stream(Policy); |
Douglas Gregor | 9fa8c46 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 367 | |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 368 | if (D->isCompleteDefinition()) { |
Douglas Gregor | 9fa8c46 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 369 | Out << " {\n"; |
| 370 | VisitDeclContext(D); |
| 371 | Indent() << "}"; |
| 372 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 373 | prettyPrintAttributes(D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void DeclPrinter::VisitRecordDecl(RecordDecl *D) { |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 377 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 378 | Out << "__module_private__ "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 379 | Out << D->getKindName(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 380 | if (D->getIdentifier()) |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 381 | Out << ' ' << *D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 383 | if (D->isCompleteDefinition()) { |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 384 | Out << " {\n"; |
| 385 | VisitDeclContext(D); |
| 386 | Indent() << "}"; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 391 | Out << *D; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 392 | if (Expr *Init = D->getInitExpr()) { |
| 393 | Out << " = "; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 394 | Init->printPretty(Out, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 399 | if (!Policy.SuppressSpecifiers) { |
Peter Collingbourne | 13330c4 | 2011-11-08 02:52:52 +0000 | [diff] [blame] | 400 | switch (D->getStorageClassAsWritten()) { |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 401 | case SC_None: break; |
| 402 | case SC_Extern: Out << "extern "; break; |
| 403 | case SC_Static: Out << "static "; break; |
| 404 | case SC_PrivateExtern: Out << "__private_extern__ "; break; |
Peter Collingbourne | 8c25fc5 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 405 | case SC_Auto: case SC_Register: case SC_OpenCLWorkGroupLocal: |
| 406 | llvm_unreachable("invalid for functions"); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 407 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 408 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 409 | if (D->isInlineSpecified()) Out << "inline "; |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 410 | if (D->isVirtualAsWritten()) Out << "virtual "; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 411 | if (D->isModulePrivate()) Out << "__module_private__ "; |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 412 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 413 | |
Douglas Gregor | 6620a62 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 414 | PrintingPolicy SubPolicy(Policy); |
| 415 | SubPolicy.SuppressSpecifiers = false; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 416 | std::string Proto = D->getNameInfo().getAsString(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 417 | |
Abramo Bagnara | 723df24 | 2010-12-14 22:11:44 +0000 | [diff] [blame] | 418 | QualType Ty = D->getType(); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 419 | while (const ParenType *PT = dyn_cast<ParenType>(Ty)) { |
Abramo Bagnara | 723df24 | 2010-12-14 22:11:44 +0000 | [diff] [blame] | 420 | Proto = '(' + Proto + ')'; |
| 421 | Ty = PT->getInnerType(); |
| 422 | } |
| 423 | |
| 424 | if (isa<FunctionType>(Ty)) { |
| 425 | const FunctionType *AFT = Ty->getAs<FunctionType>(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 426 | const FunctionProtoType *FT = 0; |
| 427 | if (D->hasWrittenPrototype()) |
| 428 | FT = dyn_cast<FunctionProtoType>(AFT); |
| 429 | |
| 430 | Proto += "("; |
| 431 | if (FT) { |
| 432 | llvm::raw_string_ostream POut(Proto); |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 433 | DeclPrinter ParamPrinter(POut, SubPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 434 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 435 | if (i) POut << ", "; |
| 436 | ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); |
| 437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 439 | if (FT->isVariadic()) { |
| 440 | if (D->getNumParams()) POut << ", "; |
| 441 | POut << "..."; |
| 442 | } |
Sean Hunt | 10620eb | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 443 | } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 444 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 445 | if (i) |
| 446 | Proto += ", "; |
| 447 | Proto += D->getParamDecl(i)->getNameAsString(); |
| 448 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | Proto += ")"; |
Douglas Gregor | 0ae7b3f | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 452 | |
David Blaikie | 4ef832f | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 453 | if (FT) { |
| 454 | if (FT->isConst()) |
Douglas Gregor | b95cfe4 | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 455 | Proto += " const"; |
David Blaikie | 4ef832f | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 456 | if (FT->isVolatile()) |
Douglas Gregor | b95cfe4 | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 457 | Proto += " volatile"; |
David Blaikie | 4ef832f | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 458 | if (FT->isRestrict()) |
Douglas Gregor | b95cfe4 | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 459 | Proto += " restrict"; |
| 460 | } |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 461 | |
| 462 | if (FT && FT->hasDynamicExceptionSpec()) { |
Douglas Gregor | 0ae7b3f | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 463 | Proto += " throw("; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 464 | if (FT->getExceptionSpecType() == EST_MSAny) |
Douglas Gregor | 0ae7b3f | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 465 | Proto += "..."; |
| 466 | else |
| 467 | for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) { |
| 468 | if (I) |
| 469 | Proto += ", "; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 470 | |
Dmitri Gribenko | 1ad23d6 | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 471 | Proto += FT->getExceptionType(I).getAsString(SubPolicy); |
Douglas Gregor | 0ae7b3f | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 472 | } |
| 473 | Proto += ")"; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 474 | } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) { |
| 475 | Proto += " noexcept"; |
| 476 | if (FT->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 477 | Proto += "("; |
| 478 | llvm::raw_string_ostream EOut(Proto); |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 479 | FT->getNoexceptExpr()->printPretty(EOut, 0, SubPolicy, |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 480 | Indentation); |
| 481 | EOut.flush(); |
| 482 | Proto += EOut.str(); |
| 483 | Proto += ")"; |
| 484 | } |
Douglas Gregor | 0ae7b3f | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 487 | if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) { |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 488 | bool HasInitializerList = false; |
| 489 | for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(), |
| 490 | E = CDecl->init_end(); |
| 491 | B != E; ++B) { |
| 492 | CXXCtorInitializer * BMInitializer = (*B); |
| 493 | if (BMInitializer->isInClassMemberInitializer()) |
| 494 | continue; |
| 495 | |
| 496 | if (!HasInitializerList) { |
| 497 | Proto += " : "; |
| 498 | Out << Proto; |
| 499 | Proto.clear(); |
| 500 | HasInitializerList = true; |
| 501 | } else |
| 502 | Out << ", "; |
| 503 | |
| 504 | if (BMInitializer->isAnyMemberInitializer()) { |
| 505 | FieldDecl *FD = BMInitializer->getAnyMember(); |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 506 | Out << *FD; |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 507 | } else { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 508 | Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | Out << "("; |
| 512 | if (!BMInitializer->getInit()) { |
| 513 | // Nothing to print |
| 514 | } else { |
| 515 | Expr *Init = BMInitializer->getInit(); |
| 516 | if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init)) |
| 517 | Init = Tmp->getSubExpr(); |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 518 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 519 | Init = Init->IgnoreParens(); |
| 520 | |
| 521 | Expr *SimpleInit = 0; |
| 522 | Expr **Args = 0; |
| 523 | unsigned NumArgs = 0; |
| 524 | if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) { |
| 525 | Args = ParenList->getExprs(); |
| 526 | NumArgs = ParenList->getNumExprs(); |
| 527 | } else if (CXXConstructExpr *Construct |
| 528 | = dyn_cast<CXXConstructExpr>(Init)) { |
| 529 | Args = Construct->getArgs(); |
| 530 | NumArgs = Construct->getNumArgs(); |
| 531 | } else |
| 532 | SimpleInit = Init; |
| 533 | |
| 534 | if (SimpleInit) |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 535 | SimpleInit->printPretty(Out, 0, Policy, Indentation); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 536 | else { |
| 537 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 538 | if (isa<CXXDefaultArgExpr>(Args[I])) |
| 539 | break; |
| 540 | |
| 541 | if (I) |
| 542 | Out << ", "; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 543 | Args[I]->printPretty(Out, 0, Policy, Indentation); |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 544 | } |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 545 | } |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 546 | } |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 547 | Out << ")"; |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | else |
Argyrios Kyrtzidis | 7ad5c99 | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 551 | AFT->getResultType().print(Out, Policy, Proto); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 552 | } else { |
Argyrios Kyrtzidis | 7ad5c99 | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 553 | Ty.print(Out, Policy, Proto); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 556 | prettyPrintAttributes(D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 557 | |
| 558 | if (D->isPure()) |
| 559 | Out << " = 0"; |
Sean Hunt | 10620eb | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 560 | else if (D->isDeletedAsWritten()) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 561 | Out << " = delete"; |
Dmitri Gribenko | 2e0b8d9 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 562 | else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) { |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 563 | if (!D->hasPrototype() && D->getNumParams()) { |
| 564 | // This is a K&R function definition, so we need to print the |
| 565 | // parameters. |
| 566 | Out << '\n'; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 567 | DeclPrinter ParamPrinter(Out, SubPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 568 | Indentation += Policy.Indentation; |
| 569 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 570 | Indent(); |
Douglas Gregor | 6620a62 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 571 | ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 572 | Out << ";\n"; |
| 573 | } |
| 574 | Indentation -= Policy.Indentation; |
| 575 | } else |
| 576 | Out << ' '; |
| 577 | |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 578 | D->getBody()->printPretty(Out, 0, SubPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 579 | Out << '\n'; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | void DeclPrinter::VisitFieldDecl(FieldDecl *D) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 584 | if (!Policy.SuppressSpecifiers && D->isMutable()) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 585 | Out << "mutable "; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 586 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 587 | Out << "__module_private__ "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 588 | |
Argyrios Kyrtzidis | 7ad5c99 | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 589 | Out << D->getType().stream(Policy, D->getName()); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 590 | |
| 591 | if (D->isBitField()) { |
| 592 | Out << " : "; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 593 | D->getBitWidth()->printPretty(Out, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 594 | } |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 595 | |
| 596 | Expr *Init = D->getInClassInitializer(); |
| 597 | if (!Policy.SuppressInitializers && Init) { |
Richard Smith | ca52330 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 598 | if (D->getInClassInitStyle() == ICIS_ListInit) |
| 599 | Out << " "; |
| 600 | else |
| 601 | Out << " = "; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 602 | Init->printPretty(Out, 0, Policy, Indentation); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 603 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 604 | prettyPrintAttributes(D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 607 | void DeclPrinter::VisitLabelDecl(LabelDecl *D) { |
Benjamin Kramer | a59d20b | 2012-02-07 11:57:57 +0000 | [diff] [blame] | 608 | Out << *D << ":"; |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 612 | void DeclPrinter::VisitVarDecl(VarDecl *D) { |
Peter Collingbourne | 13330c4 | 2011-11-08 02:52:52 +0000 | [diff] [blame] | 613 | StorageClass SCAsWritten = D->getStorageClassAsWritten(); |
| 614 | if (!Policy.SuppressSpecifiers && SCAsWritten != SC_None) |
| 615 | Out << VarDecl::getStorageClassSpecifierString(SCAsWritten) << " "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 616 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 617 | if (!Policy.SuppressSpecifiers && D->isThreadSpecified()) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 618 | Out << "__thread "; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 619 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 620 | Out << "__module_private__ "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 622 | QualType T = D->getType(); |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 623 | if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 624 | T = Parm->getOriginalType(); |
Argyrios Kyrtzidis | 7ad5c99 | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 625 | T.print(Out, Policy, D->getName()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 626 | Expr *Init = D->getInit(); |
| 627 | if (!Policy.SuppressInitializers && Init) { |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 628 | bool ImplicitInit = false; |
| 629 | if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init)) |
| 630 | ImplicitInit = D->getInitStyle() == VarDecl::CallInit && |
| 631 | Construct->getNumArgs() == 0 && !Construct->isListInitialization(); |
| 632 | if (!ImplicitInit) { |
Eli Friedman | e1aebe1 | 2012-10-19 20:36:44 +0000 | [diff] [blame] | 633 | if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 634 | Out << "("; |
| 635 | else if (D->getInitStyle() == VarDecl::CInit) { |
| 636 | Out << " = "; |
| 637 | } |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 638 | Init->printPretty(Out, 0, Policy, Indentation); |
Eli Friedman | e1aebe1 | 2012-10-19 20:36:44 +0000 | [diff] [blame] | 639 | if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 640 | Out << ")"; |
Ted Kremenek | c57d655 | 2010-09-17 23:04:38 +0000 | [diff] [blame] | 641 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 642 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 643 | prettyPrintAttributes(D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) { |
| 647 | VisitVarDecl(D); |
| 648 | } |
| 649 | |
| 650 | void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
| 651 | Out << "__asm ("; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 652 | D->getAsmString()->printPretty(Out, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 653 | Out << ")"; |
| 654 | } |
| 655 | |
Douglas Gregor | 15de72c | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 656 | void DeclPrinter::VisitImportDecl(ImportDecl *D) { |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 657 | Out << "@__experimental_modules_import " << D->getImportedModule()->getFullModuleName() |
Douglas Gregor | 15de72c | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 658 | << ";\n"; |
| 659 | } |
| 660 | |
Peter Collingbourne | 28ac87e | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 661 | void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 662 | Out << "static_assert("; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 663 | D->getAssertExpr()->printPretty(Out, 0, Policy, Indentation); |
Peter Collingbourne | 28ac87e | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 664 | Out << ", "; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 665 | D->getMessage()->printPretty(Out, 0, Policy, Indentation); |
Peter Collingbourne | 28ac87e | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 666 | Out << ")"; |
| 667 | } |
| 668 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 669 | //---------------------------------------------------------------------------- |
| 670 | // C++ declarations |
| 671 | //---------------------------------------------------------------------------- |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 672 | void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | c30636a | 2012-05-01 01:43:38 +0000 | [diff] [blame] | 673 | if (D->isInline()) |
| 674 | Out << "inline "; |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 675 | Out << "namespace " << *D << " {\n"; |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 676 | VisitDeclContext(D); |
| 677 | Indent() << "}"; |
| 678 | } |
| 679 | |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 680 | void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 681 | Out << "using namespace "; |
| 682 | if (D->getQualifier()) |
| 683 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 684 | Out << *D->getNominatedNamespaceAsWritten(); |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 687 | void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 688 | Out << "namespace " << *D << " = "; |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 689 | if (D->getQualifier()) |
| 690 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 691 | Out << *D->getAliasedNamespace(); |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 694 | void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 695 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 696 | Out << "__module_private__ "; |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 697 | Out << D->getKindName(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 698 | if (D->getIdentifier()) |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 699 | Out << ' ' << *D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 701 | if (D->isCompleteDefinition()) { |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 702 | // Print the base classes |
| 703 | if (D->getNumBases()) { |
| 704 | Out << " : "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(), |
| 706 | BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) { |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 707 | if (Base != D->bases_begin()) |
| 708 | Out << ", "; |
| 709 | |
| 710 | if (Base->isVirtual()) |
| 711 | Out << "virtual "; |
| 712 | |
Anders Carlsson | 018e9fe | 2009-08-29 20:36:12 +0000 | [diff] [blame] | 713 | AccessSpecifier AS = Base->getAccessSpecifierAsWritten(); |
| 714 | if (AS != AS_none) |
| 715 | Print(AS); |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 716 | Out << " " << Base->getType().getAsString(Policy); |
Douglas Gregor | 34a99e7 | 2011-04-27 17:07:55 +0000 | [diff] [blame] | 717 | |
| 718 | if (Base->isPackExpansion()) |
| 719 | Out << "..."; |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | // Print the class definition |
Douglas Gregor | f757ae7 | 2009-05-31 07:13:39 +0000 | [diff] [blame] | 724 | // FIXME: Doesn't print access specifiers, e.g., "public:" |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 725 | Out << " {\n"; |
| 726 | VisitDeclContext(D); |
| 727 | Indent() << "}"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 732 | const char *l; |
| 733 | if (D->getLanguage() == LinkageSpecDecl::lang_c) |
| 734 | l = "C"; |
| 735 | else { |
| 736 | assert(D->getLanguage() == LinkageSpecDecl::lang_cxx && |
| 737 | "unknown language in linkage specification"); |
| 738 | l = "C++"; |
| 739 | } |
| 740 | |
| 741 | Out << "extern \"" << l << "\" "; |
| 742 | if (D->hasBraces()) { |
| 743 | Out << "{\n"; |
| 744 | VisitDeclContext(D); |
| 745 | Indent() << "}"; |
| 746 | } else |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 747 | Visit(*D->decls_begin()); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 750 | void DeclPrinter::PrintTemplateParameters( |
| 751 | const TemplateParameterList *Params, const TemplateArgumentList *Args = 0) { |
| 752 | assert(Params); |
| 753 | assert(!Args || Params->size() == Args->size()); |
| 754 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 755 | Out << "template <"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 757 | for (unsigned i = 0, e = Params->size(); i != e; ++i) { |
| 758 | if (i != 0) |
| 759 | Out << ", "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 761 | const Decl *Param = Params->getParam(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | if (const TemplateTypeParmDecl *TTP = |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 763 | dyn_cast<TemplateTypeParmDecl>(Param)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 765 | if (TTP->wasDeclaredWithTypename()) |
| 766 | Out << "typename "; |
| 767 | else |
| 768 | Out << "class "; |
| 769 | |
Anders Carlsson | 6d845ae | 2009-06-12 22:23:22 +0000 | [diff] [blame] | 770 | if (TTP->isParameterPack()) |
| 771 | Out << "... "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 772 | |
Benjamin Kramer | a59d20b | 2012-02-07 11:57:57 +0000 | [diff] [blame] | 773 | Out << *TTP; |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 774 | |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 775 | if (Args) { |
| 776 | Out << " = "; |
| 777 | Args->get(i).print(Policy, Out); |
| 778 | } else if (TTP->hasDefaultArgument()) { |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 779 | Out << " = "; |
| 780 | Out << TTP->getDefaultArgument().getAsString(Policy); |
| 781 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | } else if (const NonTypeTemplateParmDecl *NTTP = |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 783 | dyn_cast<NonTypeTemplateParmDecl>(Param)) { |
| 784 | Out << NTTP->getType().getAsString(Policy); |
| 785 | |
Douglas Gregor | 56bc983 | 2010-12-24 00:15:10 +0000 | [diff] [blame] | 786 | if (NTTP->isParameterPack() && !isa<PackExpansionType>(NTTP->getType())) |
| 787 | Out << "..."; |
| 788 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 789 | if (IdentifierInfo *Name = NTTP->getIdentifier()) { |
| 790 | Out << ' '; |
| 791 | Out << Name->getName(); |
| 792 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 793 | |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 794 | if (Args) { |
| 795 | Out << " = "; |
| 796 | Args->get(i).print(Policy, Out); |
| 797 | } else if (NTTP->hasDefaultArgument()) { |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 798 | Out << " = "; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 799 | NTTP->getDefaultArgument()->printPretty(Out, 0, Policy, Indentation); |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 800 | } |
Richard Smith | 98a5786 | 2011-04-15 13:38:57 +0000 | [diff] [blame] | 801 | } else if (const TemplateTemplateParmDecl *TTPD = |
| 802 | dyn_cast<TemplateTemplateParmDecl>(Param)) { |
| 803 | VisitTemplateDecl(TTPD); |
| 804 | // FIXME: print the default argument, if present. |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 805 | } |
| 806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 808 | Out << "> "; |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { |
| 812 | PrintTemplateParameters(D->getTemplateParameters()); |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 813 | |
Richard Smith | 98a5786 | 2011-04-15 13:38:57 +0000 | [diff] [blame] | 814 | if (const TemplateTemplateParmDecl *TTP = |
| 815 | dyn_cast<TemplateTemplateParmDecl>(D)) { |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 816 | Out << "class "; |
| 817 | if (TTP->isParameterPack()) |
| 818 | Out << "..."; |
| 819 | Out << D->getName(); |
Craig Silverstein | 0193a72 | 2010-07-09 20:25:10 +0000 | [diff] [blame] | 820 | } else { |
| 821 | Visit(D->getTemplatedDecl()); |
| 822 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 825 | void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 826 | if (PrintInstantiation) { |
| 827 | TemplateParameterList *Params = D->getTemplateParameters(); |
| 828 | for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end(); |
| 829 | I != E; ++I) { |
| 830 | PrintTemplateParameters(Params, (*I)->getTemplateSpecializationArgs()); |
| 831 | Visit(*I); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | return VisitRedeclarableTemplateDecl(D); |
| 836 | } |
| 837 | |
| 838 | void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 839 | if (PrintInstantiation) { |
| 840 | TemplateParameterList *Params = D->getTemplateParameters(); |
| 841 | for (ClassTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end(); |
| 842 | I != E; ++I) { |
| 843 | PrintTemplateParameters(Params, &(*I)->getTemplateArgs()); |
| 844 | Visit(*I); |
| 845 | Out << '\n'; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | return VisitRedeclarableTemplateDecl(D); |
| 850 | } |
| 851 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 852 | //---------------------------------------------------------------------------- |
| 853 | // Objective-C declarations |
| 854 | //---------------------------------------------------------------------------- |
| 855 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 856 | void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { |
| 857 | if (OMD->isInstanceMethod()) |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 858 | Out << "- "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | else |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 860 | Out << "+ "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 861 | if (!OMD->getResultType().isNull()) |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 862 | Out << '(' << OMD->getResultType().getAsString(Policy) << ")"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 864 | std::string name = OMD->getSelector().getAsString(); |
| 865 | std::string::size_type pos, lastPos = 0; |
| 866 | for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(), |
| 867 | E = OMD->param_end(); PI != E; ++PI) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 868 | // FIXME: selector is missing here! |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 869 | pos = name.find_first_of(':', lastPos); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 870 | Out << " " << name.substr(lastPos, pos - lastPos); |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 871 | Out << ":(" << (*PI)->getType().getAsString(Policy) << ')' << **PI; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 872 | lastPos = pos + 1; |
| 873 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 874 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 875 | if (OMD->param_begin() == OMD->param_end()) |
| 876 | Out << " " << name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 878 | if (OMD->isVariadic()) |
| 879 | Out << ", ..."; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 880 | |
Fariborz Jahanian | 1bfb00d | 2012-10-17 21:58:03 +0000 | [diff] [blame] | 881 | if (OMD->getBody() && !Policy.TerseOutput) { |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 882 | Out << ' '; |
Richard Smith | d1420c6 | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 883 | OMD->getBody()->printPretty(Out, 0, Policy); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 884 | Out << '\n'; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 885 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { |
| 889 | std::string I = OID->getNameAsString(); |
| 890 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
| 891 | |
| 892 | if (SID) |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 893 | Out << "@implementation " << I << " : " << *SID; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 894 | else |
| 895 | Out << "@implementation " << I; |
Fariborz Jahanian | 482b4fd | 2012-12-04 00:47:33 +0000 | [diff] [blame] | 896 | |
| 897 | if (OID->ivar_size() > 0) { |
| 898 | Out << "{\n"; |
| 899 | Indentation += Policy.Indentation; |
| 900 | for (ObjCImplementationDecl::ivar_iterator I = OID->ivar_begin(), |
| 901 | E = OID->ivar_end(); I != E; ++I) { |
| 902 | Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n"; |
| 903 | } |
| 904 | Indentation -= Policy.Indentation; |
| 905 | Out << "}\n"; |
| 906 | } |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 907 | VisitDeclContext(OID, false); |
| 908 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) { |
| 912 | std::string I = OID->getNameAsString(); |
| 913 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
| 914 | |
Douglas Gregor | 7723fec | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 915 | if (!OID->isThisDeclarationADefinition()) { |
| 916 | Out << "@class " << I << ";"; |
| 917 | return; |
| 918 | } |
| 919 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 920 | if (SID) |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 921 | Out << "@interface " << I << " : " << *SID; |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 922 | else |
| 923 | Out << "@interface " << I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 925 | // Protocols? |
| 926 | const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols(); |
| 927 | if (!Protocols.empty()) { |
| 928 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 929 | E = Protocols.end(); I != E; ++I) |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 930 | Out << (I == Protocols.begin() ? '<' : ',') << **I; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 931 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 932 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 933 | if (!Protocols.empty()) |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 934 | Out << "> "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 936 | if (OID->ivar_size() > 0) { |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 937 | Out << "{\n"; |
| 938 | Indentation += Policy.Indentation; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 939 | for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(), |
| 940 | E = OID->ivar_end(); I != E; ++I) { |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 941 | Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 942 | } |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 943 | Indentation -= Policy.Indentation; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 944 | Out << "}\n"; |
| 945 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 947 | VisitDeclContext(OID, false); |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 948 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 949 | // FIXME: implement the rest... |
| 950 | } |
| 951 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 952 | void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { |
Douglas Gregor | bd9482d | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 953 | if (!PID->isThisDeclarationADefinition()) { |
| 954 | Out << "@protocol " << PID->getIdentifier() << ";\n"; |
| 955 | return; |
| 956 | } |
| 957 | |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 958 | Out << "@protocol " << *PID << '\n'; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 959 | VisitDeclContext(PID, false); |
| 960 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 964 | Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 965 | |
| 966 | VisitDeclContext(PID, false); |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 967 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 968 | // FIXME: implement the rest... |
| 969 | } |
| 970 | |
| 971 | void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 972 | Out << "@interface " << *PID->getClassInterface() << '(' << *PID << ")\n"; |
Fariborz Jahanian | ff685c5 | 2012-12-04 17:20:57 +0000 | [diff] [blame^] | 973 | if (PID->ivar_size() > 0) { |
| 974 | Out << "{\n"; |
| 975 | Indentation += Policy.Indentation; |
| 976 | for (ObjCCategoryDecl::ivar_iterator I = PID->ivar_begin(), |
| 977 | E = PID->ivar_end(); I != E; ++I) { |
| 978 | Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n"; |
| 979 | } |
| 980 | Indentation -= Policy.Indentation; |
| 981 | Out << "}\n"; |
| 982 | } |
| 983 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 984 | VisitDeclContext(PID, false); |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 985 | Out << "@end"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 987 | // FIXME: implement the rest... |
| 988 | } |
| 989 | |
| 990 | void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) { |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 991 | Out << "@compatibility_alias " << *AID |
| 992 | << ' ' << *AID->getClassInterface() << ";\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /// PrintObjCPropertyDecl - print a property declaration. |
| 996 | /// |
| 997 | void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { |
| 998 | if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required) |
| 999 | Out << "@required\n"; |
| 1000 | else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 1001 | Out << "@optional\n"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1003 | Out << "@property"; |
| 1004 | if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) { |
| 1005 | bool first = true; |
| 1006 | Out << " ("; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | if (PDecl->getPropertyAttributes() & |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1008 | ObjCPropertyDecl::OBJC_PR_readonly) { |
| 1009 | Out << (first ? ' ' : ',') << "readonly"; |
| 1010 | first = false; |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1011 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1012 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1013 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { |
| 1014 | Out << (first ? ' ' : ',') << "getter = " |
| 1015 | << PDecl->getGetterName().getAsString(); |
| 1016 | first = false; |
| 1017 | } |
| 1018 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { |
| 1019 | Out << (first ? ' ' : ',') << "setter = " |
| 1020 | << PDecl->getSetterName().getAsString(); |
| 1021 | first = false; |
| 1022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1024 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) { |
| 1025 | Out << (first ? ' ' : ',') << "assign"; |
| 1026 | first = false; |
| 1027 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1029 | if (PDecl->getPropertyAttributes() & |
| 1030 | ObjCPropertyDecl::OBJC_PR_readwrite) { |
| 1031 | Out << (first ? ' ' : ',') << "readwrite"; |
| 1032 | first = false; |
| 1033 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1035 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) { |
| 1036 | Out << (first ? ' ' : ',') << "retain"; |
| 1037 | first = false; |
| 1038 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1040 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) { |
| 1041 | Out << (first ? ' ' : ',') << "strong"; |
| 1042 | first = false; |
| 1043 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1044 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1045 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) { |
| 1046 | Out << (first ? ' ' : ',') << "copy"; |
| 1047 | first = false; |
| 1048 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | |
Ted Kremenek | 07c682a | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1050 | if (PDecl->getPropertyAttributes() & |
| 1051 | ObjCPropertyDecl::OBJC_PR_nonatomic) { |
| 1052 | Out << (first ? ' ' : ',') << "nonatomic"; |
| 1053 | first = false; |
| 1054 | } |
| 1055 | if (PDecl->getPropertyAttributes() & |
| 1056 | ObjCPropertyDecl::OBJC_PR_atomic) { |
| 1057 | Out << (first ? ' ' : ',') << "atomic"; |
| 1058 | first = false; |
| 1059 | } |
| 1060 | |
| 1061 | (void) first; // Silence dead store warning due to idiomatic code. |
| 1062 | Out << " )"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1063 | } |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1064 | Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << *PDecl; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) { |
| 1068 | if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1069 | Out << "@synthesize "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1070 | else |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1071 | Out << "@dynamic "; |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1072 | Out << *PID->getPropertyDecl(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1073 | if (PID->getPropertyIvarDecl()) |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1074 | Out << '=' << *PID->getPropertyIvarDecl(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1075 | } |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1076 | |
| 1077 | void DeclPrinter::VisitUsingDecl(UsingDecl *D) { |
| 1078 | Out << "using "; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1079 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1080 | Out << *D; |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1083 | void |
| 1084 | DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { |
| 1085 | Out << "using typename "; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1086 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1087 | Out << D->getDeclName(); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1091 | Out << "using "; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1092 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1093 | Out << D->getDeclName(); |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1094 | } |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 1095 | |
| 1096 | void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 1097 | // ignore |
| 1098 | } |