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