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