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 | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
| 23 | using namespace clang; |
| 24 | |
| 25 | namespace { |
Benjamin Kramer | 770b4a8 | 2009-11-28 19:03:38 +0000 | [diff] [blame] | 26 | class DeclPrinter : public DeclVisitor<DeclPrinter> { |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 27 | llvm::raw_ostream &Out; |
| 28 | ASTContext &Context; |
| 29 | PrintingPolicy Policy; |
| 30 | unsigned Indentation; |
| 31 | |
Daniel Dunbar | 512ce60 | 2009-11-21 09:12:06 +0000 | [diff] [blame] | 32 | llvm::raw_ostream& Indent() { return Indent(Indentation); } |
| 33 | llvm::raw_ostream& Indent(unsigned Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 34 | void ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 35 | |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 36 | void Print(AccessSpecifier AS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 38 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | DeclPrinter(llvm::raw_ostream &Out, ASTContext &Context, |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 40 | const PrintingPolicy &Policy, |
| 41 | unsigned Indentation = 0) |
| 42 | : Out(Out), Context(Context), Policy(Policy), Indentation(Indentation) { } |
| 43 | |
| 44 | void VisitDeclContext(DeclContext *DC, bool Indent = true); |
| 45 | |
| 46 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 47 | void VisitTypedefDecl(TypedefDecl *D); |
| 48 | void VisitEnumDecl(EnumDecl *D); |
| 49 | void VisitRecordDecl(RecordDecl *D); |
| 50 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
| 51 | void VisitFunctionDecl(FunctionDecl *D); |
| 52 | void VisitFieldDecl(FieldDecl *D); |
| 53 | void VisitVarDecl(VarDecl *D); |
| 54 | void VisitParmVarDecl(ParmVarDecl *D); |
| 55 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 56 | void VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 57 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 58 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 59 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 60 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 61 | void VisitTemplateDecl(TemplateDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 62 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 63 | void VisitObjCClassDecl(ObjCClassDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 64 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 65 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 66 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 67 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 68 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 69 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 70 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 71 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 72 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 73 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 74 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 75 | void VisitUsingDecl(UsingDecl *D); |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 76 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 77 | }; |
| 78 | } |
| 79 | |
Anders Carlsson | f88df86 | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 80 | void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) const { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 81 | print(Out, getASTContext().PrintingPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 84 | void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy, |
Anders Carlsson | f88df86 | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 85 | unsigned Indentation) const { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 86 | DeclPrinter Printer(Out, getASTContext(), Policy, Indentation); |
Anders Carlsson | f88df86 | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 87 | Printer.Visit(const_cast<Decl*>(this)); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 90 | static QualType GetBaseType(QualType T) { |
| 91 | // FIXME: This should be on the Type class! |
| 92 | QualType BaseType = T; |
| 93 | while (!BaseType->isSpecifierType()) { |
| 94 | if (isa<TypedefType>(BaseType)) |
| 95 | break; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 96 | else if (const PointerType* PTy = BaseType->getAs<PointerType>()) |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 97 | BaseType = PTy->getPointeeType(); |
| 98 | else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType)) |
| 99 | BaseType = ATy->getElementType(); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 100 | else if (const FunctionType* FTy = BaseType->getAs<FunctionType>()) |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 101 | BaseType = FTy->getResultType(); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 102 | else if (const VectorType *VTy = BaseType->getAs<VectorType>()) |
Douglas Gregor | 5068ab6 | 2009-07-01 23:58:14 +0000 | [diff] [blame] | 103 | BaseType = VTy->getElementType(); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 104 | else |
| 105 | assert(0 && "Unknown declarator!"); |
| 106 | } |
| 107 | return BaseType; |
| 108 | } |
| 109 | |
| 110 | static QualType getDeclType(Decl* D) { |
| 111 | if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D)) |
| 112 | return TDD->getUnderlyingType(); |
| 113 | if (ValueDecl* VD = dyn_cast<ValueDecl>(D)) |
| 114 | return VD->getType(); |
| 115 | return QualType(); |
| 116 | } |
| 117 | |
| 118 | void Decl::printGroup(Decl** Begin, unsigned NumDecls, |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 119 | llvm::raw_ostream &Out, const PrintingPolicy &Policy, |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 120 | unsigned Indentation) { |
| 121 | if (NumDecls == 1) { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 122 | (*Begin)->print(Out, Policy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | |
| 126 | Decl** End = Begin + NumDecls; |
| 127 | TagDecl* TD = dyn_cast<TagDecl>(*Begin); |
| 128 | if (TD) |
| 129 | ++Begin; |
| 130 | |
| 131 | PrintingPolicy SubPolicy(Policy); |
| 132 | if (TD && TD->isDefinition()) { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 133 | TD->print(Out, Policy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 134 | Out << " "; |
| 135 | SubPolicy.SuppressTag = true; |
| 136 | } |
| 137 | |
| 138 | bool isFirst = true; |
| 139 | for ( ; Begin != End; ++Begin) { |
| 140 | if (isFirst) { |
| 141 | SubPolicy.SuppressSpecifiers = false; |
| 142 | isFirst = false; |
| 143 | } else { |
| 144 | if (!isFirst) Out << ", "; |
| 145 | SubPolicy.SuppressSpecifiers = true; |
| 146 | } |
| 147 | |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 148 | (*Begin)->print(Out, SubPolicy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Anders Carlsson | 8483443 | 2009-12-14 00:51:04 +0000 | [diff] [blame] | 152 | void DeclContext::dumpDeclContext() const { |
Anders Carlsson | 2b7d8dd | 2009-12-09 17:27:46 +0000 | [diff] [blame] | 153 | // Get the translation unit |
| 154 | const DeclContext *DC = this; |
| 155 | while (!DC->isTranslationUnit()) |
| 156 | DC = DC->getParent(); |
| 157 | |
| 158 | ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); |
| 159 | DeclPrinter Printer(llvm::errs(), Ctx, Ctx.PrintingPolicy, 0); |
| 160 | Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false); |
| 161 | } |
| 162 | |
Anders Carlsson | f88df86 | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 163 | void Decl::dump() const { |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 164 | print(llvm::errs()); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Daniel Dunbar | 512ce60 | 2009-11-21 09:12:06 +0000 | [diff] [blame] | 167 | llvm::raw_ostream& DeclPrinter::Indent(unsigned Indentation) { |
| 168 | for (unsigned i = 0; i != Indentation; ++i) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 169 | Out << " "; |
| 170 | return Out; |
| 171 | } |
| 172 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 173 | void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) { |
| 174 | this->Indent(); |
Argyrios Kyrtzidis | f1d60ea | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 175 | Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 176 | Out << ";\n"; |
| 177 | Decls.clear(); |
| 178 | |
| 179 | } |
| 180 | |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 181 | void DeclPrinter::Print(AccessSpecifier AS) { |
| 182 | switch(AS) { |
Anders Carlsson | 018e9fe | 2009-08-29 20:36:12 +0000 | [diff] [blame] | 183 | case AS_none: assert(0 && "No access specifier!"); break; |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 184 | case AS_public: Out << "public"; break; |
| 185 | case AS_protected: Out << "protected"; break; |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 186 | case AS_private: Out << "private"; break; |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 190 | //---------------------------------------------------------------------------- |
| 191 | // Common C declarations |
| 192 | //---------------------------------------------------------------------------- |
| 193 | |
| 194 | void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { |
| 195 | if (Indent) |
| 196 | Indentation += Policy.Indentation; |
| 197 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 198 | llvm::SmallVector<Decl*, 2> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 199 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 200 | D != DEnd; ++D) { |
Ted Kremenek | 2d6c906 | 2010-07-30 00:47:46 +0000 | [diff] [blame] | 201 | |
| 202 | // Don't print ObjCIvarDecls, as they are printed when visiting the |
| 203 | // containing ObjCInterfaceDecl. |
| 204 | if (isa<ObjCIvarDecl>(*D)) |
| 205 | continue; |
| 206 | |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 207 | if (!Policy.Dump) { |
| 208 | // Skip over implicit declarations in pretty-printing mode. |
| 209 | if (D->isImplicit()) continue; |
Eli Friedman | 3d4a7c9 | 2009-05-30 06:35:22 +0000 | [diff] [blame] | 210 | // FIXME: Ugly hack so we don't pretty-print the builtin declaration |
Argyrios Kyrtzidis | 2574f6f | 2010-06-17 10:52:11 +0000 | [diff] [blame] | 211 | // of __builtin_va_list or __[u]int128_t. There should be some other way |
| 212 | // to check that. |
| 213 | if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) { |
| 214 | if (IdentifierInfo *II = ND->getIdentifier()) { |
| 215 | if (II->isStr("__builtin_va_list") || |
| 216 | II->isStr("__int128_t") || II->isStr("__uint128_t")) |
| 217 | continue; |
| 218 | } |
| 219 | } |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 222 | // The next bits of code handles stuff like "struct {int x;} a,b"; we're |
| 223 | // forced to merge the declarations because there's no other way to |
| 224 | // refer to the struct in question. This limited merging is safe without |
| 225 | // a bunch of other checks because it only merges declarations directly |
| 226 | // referring to the tag, not typedefs. |
| 227 | // |
| 228 | // Check whether the current declaration should be grouped with a previous |
| 229 | // unnamed struct. |
| 230 | QualType CurDeclType = getDeclType(*D); |
| 231 | if (!Decls.empty() && !CurDeclType.isNull()) { |
| 232 | QualType BaseType = GetBaseType(CurDeclType); |
| 233 | if (!BaseType.isNull() && isa<TagType>(BaseType) && |
| 234 | cast<TagType>(BaseType)->getDecl() == Decls[0]) { |
| 235 | Decls.push_back(*D); |
| 236 | continue; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // If we have a merged group waiting to be handled, handle it now. |
| 241 | if (!Decls.empty()) |
| 242 | ProcessDeclGroup(Decls); |
| 243 | |
| 244 | // If the current declaration is an unnamed tag type, save it |
| 245 | // so we can merge it with the subsequent declaration(s) using it. |
| 246 | if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) { |
| 247 | Decls.push_back(*D); |
| 248 | continue; |
| 249 | } |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 250 | |
| 251 | if (isa<AccessSpecDecl>(*D)) { |
| 252 | Indentation -= Policy.Indentation; |
| 253 | this->Indent(); |
| 254 | Print(D->getAccess()); |
| 255 | Out << ":\n"; |
| 256 | Indentation += Policy.Indentation; |
| 257 | continue; |
| 258 | } |
| 259 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 260 | this->Indent(); |
| 261 | Visit(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
| 263 | // FIXME: Need to be able to tell the DeclPrinter when |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 264 | const char *Terminator = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | if (isa<FunctionDecl>(*D) && |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 266 | cast<FunctionDecl>(*D)->isThisDeclarationADefinition()) |
| 267 | Terminator = 0; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 268 | else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody()) |
| 269 | Terminator = 0; |
| 270 | else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) || |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | isa<ObjCImplementationDecl>(*D) || |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 272 | isa<ObjCInterfaceDecl>(*D) || |
| 273 | isa<ObjCProtocolDecl>(*D) || |
| 274 | isa<ObjCCategoryImplDecl>(*D) || |
| 275 | isa<ObjCCategoryDecl>(*D)) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 276 | Terminator = 0; |
| 277 | else if (isa<EnumConstantDecl>(*D)) { |
| 278 | DeclContext::decl_iterator Next = D; |
| 279 | ++Next; |
| 280 | if (Next != DEnd) |
| 281 | Terminator = ","; |
| 282 | } else |
| 283 | Terminator = ";"; |
| 284 | |
| 285 | if (Terminator) |
| 286 | Out << Terminator; |
| 287 | Out << "\n"; |
| 288 | } |
| 289 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 290 | if (!Decls.empty()) |
| 291 | ProcessDeclGroup(Decls); |
| 292 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 293 | if (Indent) |
| 294 | Indentation -= Policy.Indentation; |
| 295 | } |
| 296 | |
| 297 | void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 298 | VisitDeclContext(D, false); |
| 299 | } |
| 300 | |
| 301 | void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) { |
| 302 | std::string S = D->getNameAsString(); |
| 303 | D->getUnderlyingType().getAsStringInternal(S, Policy); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 304 | if (!Policy.SuppressSpecifiers) |
| 305 | Out << "typedef "; |
| 306 | Out << S; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void DeclPrinter::VisitEnumDecl(EnumDecl *D) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 310 | Out << "enum " << D << " {\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 311 | VisitDeclContext(D); |
| 312 | Indent() << "}"; |
| 313 | } |
| 314 | |
| 315 | void DeclPrinter::VisitRecordDecl(RecordDecl *D) { |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 316 | Out << D->getKindName(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 317 | if (D->getIdentifier()) |
| 318 | Out << ' ' << D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 320 | if (D->isDefinition()) { |
| 321 | Out << " {\n"; |
| 322 | VisitDeclContext(D); |
| 323 | Indent() << "}"; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 328 | Out << D; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 329 | if (Expr *Init = D->getInitExpr()) { |
| 330 | Out << " = "; |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 331 | Init->printPretty(Out, Context, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 335 | void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 336 | if (!Policy.SuppressSpecifiers) { |
| 337 | switch (D->getStorageClass()) { |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 338 | case SC_None: break; |
| 339 | case SC_Extern: Out << "extern "; break; |
| 340 | case SC_Static: Out << "static "; break; |
| 341 | case SC_PrivateExtern: Out << "__private_extern__ "; break; |
| 342 | case SC_Auto: case SC_Register: llvm_unreachable("invalid for functions"); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 343 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 344 | |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 345 | if (D->isInlineSpecified()) Out << "inline "; |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 346 | if (D->isVirtualAsWritten()) Out << "virtual "; |
| 347 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 348 | |
Douglas Gregor | 6620a62 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 349 | PrintingPolicy SubPolicy(Policy); |
| 350 | SubPolicy.SuppressSpecifiers = false; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 351 | std::string Proto = D->getNameInfo().getAsString(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 352 | if (isa<FunctionType>(D->getType().getTypePtr())) { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 353 | const FunctionType *AFT = D->getType()->getAs<FunctionType>(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 354 | |
| 355 | const FunctionProtoType *FT = 0; |
| 356 | if (D->hasWrittenPrototype()) |
| 357 | FT = dyn_cast<FunctionProtoType>(AFT); |
| 358 | |
| 359 | Proto += "("; |
| 360 | if (FT) { |
| 361 | llvm::raw_string_ostream POut(Proto); |
Douglas Gregor | 6620a62 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 362 | DeclPrinter ParamPrinter(POut, Context, SubPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 363 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 364 | if (i) POut << ", "; |
| 365 | ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); |
| 366 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 368 | if (FT->isVariadic()) { |
| 369 | if (D->getNumParams()) POut << ", "; |
| 370 | POut << "..."; |
| 371 | } |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 372 | } else if (D->isThisDeclarationADefinition() && !D->hasPrototype()) { |
| 373 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 374 | if (i) |
| 375 | Proto += ", "; |
| 376 | Proto += D->getParamDecl(i)->getNameAsString(); |
| 377 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | Proto += ")"; |
Douglas Gregor | 0ae7b3f | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 381 | |
| 382 | if (FT && FT->hasExceptionSpec()) { |
| 383 | Proto += " throw("; |
| 384 | if (FT->hasAnyExceptionSpec()) |
| 385 | Proto += "..."; |
| 386 | else |
| 387 | for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) { |
| 388 | if (I) |
| 389 | Proto += ", "; |
| 390 | |
| 391 | |
| 392 | std::string ExceptionType; |
| 393 | FT->getExceptionType(I).getAsStringInternal(ExceptionType, SubPolicy); |
| 394 | Proto += ExceptionType; |
| 395 | } |
| 396 | Proto += ")"; |
| 397 | } |
| 398 | |
Mike Stump | fd350b5 | 2009-07-27 21:33:40 +0000 | [diff] [blame] | 399 | if (D->hasAttr<NoReturnAttr>()) |
| 400 | Proto += " __attribute((noreturn))"; |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 401 | if (CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D)) { |
| 402 | if (CDecl->getNumBaseOrMemberInitializers() > 0) { |
| 403 | Proto += " : "; |
| 404 | Out << Proto; |
| 405 | Proto.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(), |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 407 | E = CDecl->init_end(); |
| 408 | B != E; ++B) { |
| 409 | CXXBaseOrMemberInitializer * BMInitializer = (*B); |
| 410 | if (B != CDecl->init_begin()) |
| 411 | Out << ", "; |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 412 | if (BMInitializer->isMemberInitializer()) { |
| 413 | FieldDecl *FD = BMInitializer->getMember(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 414 | Out << FD; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 415 | } else { |
Daniel Dunbar | 6cb5b5f | 2010-06-30 19:16:48 +0000 | [diff] [blame] | 416 | Out << QualType(BMInitializer->getBaseClass(), |
| 417 | 0).getAsString(Policy); |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 418 | } |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 419 | |
| 420 | Out << "("; |
| 421 | if (!BMInitializer->getInit()) { |
| 422 | // Nothing to print |
| 423 | } else { |
| 424 | Expr *Init = BMInitializer->getInit(); |
| 425 | if (CXXExprWithTemporaries *Tmp |
| 426 | = dyn_cast<CXXExprWithTemporaries>(Init)) |
| 427 | Init = Tmp->getSubExpr(); |
| 428 | |
| 429 | Init = Init->IgnoreParens(); |
| 430 | |
| 431 | Expr *SimpleInit = 0; |
| 432 | Expr **Args = 0; |
| 433 | unsigned NumArgs = 0; |
| 434 | if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) { |
| 435 | Args = ParenList->getExprs(); |
| 436 | NumArgs = ParenList->getNumExprs(); |
| 437 | } else if (CXXConstructExpr *Construct |
| 438 | = dyn_cast<CXXConstructExpr>(Init)) { |
| 439 | Args = Construct->getArgs(); |
| 440 | NumArgs = Construct->getNumArgs(); |
| 441 | } else |
| 442 | SimpleInit = Init; |
| 443 | |
| 444 | if (SimpleInit) |
| 445 | SimpleInit->printPretty(Out, Context, 0, Policy, Indentation); |
| 446 | else { |
| 447 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 448 | if (isa<CXXDefaultArgExpr>(Args[I])) |
| 449 | break; |
| 450 | |
| 451 | if (I) |
| 452 | Out << ", "; |
| 453 | Args[I]->printPretty(Out, Context, 0, Policy, Indentation); |
| 454 | } |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 455 | } |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 456 | } |
| 457 | Out << ")"; |
Fariborz Jahanian | 66192ad | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | } |
| 461 | else |
| 462 | AFT->getResultType().getAsStringInternal(Proto, Policy); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 463 | } else { |
| 464 | D->getType().getAsStringInternal(Proto, Policy); |
| 465 | } |
| 466 | |
| 467 | Out << Proto; |
| 468 | |
| 469 | if (D->isPure()) |
| 470 | Out << " = 0"; |
| 471 | else if (D->isDeleted()) |
| 472 | Out << " = delete"; |
| 473 | else if (D->isThisDeclarationADefinition()) { |
| 474 | if (!D->hasPrototype() && D->getNumParams()) { |
| 475 | // This is a K&R function definition, so we need to print the |
| 476 | // parameters. |
| 477 | Out << '\n'; |
Douglas Gregor | 6620a62 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 478 | DeclPrinter ParamPrinter(Out, Context, SubPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 479 | Indentation += Policy.Indentation; |
| 480 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 481 | Indent(); |
Douglas Gregor | 6620a62 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 482 | ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 483 | Out << ";\n"; |
| 484 | } |
| 485 | Indentation -= Policy.Indentation; |
| 486 | } else |
| 487 | Out << ' '; |
| 488 | |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 489 | D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 490 | Out << '\n'; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | void DeclPrinter::VisitFieldDecl(FieldDecl *D) { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 495 | if (!Policy.SuppressSpecifiers && D->isMutable()) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 496 | Out << "mutable "; |
| 497 | |
| 498 | std::string Name = D->getNameAsString(); |
| 499 | D->getType().getAsStringInternal(Name, Policy); |
| 500 | Out << Name; |
| 501 | |
| 502 | if (D->isBitField()) { |
| 503 | Out << " : "; |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 504 | D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | void DeclPrinter::VisitVarDecl(VarDecl *D) { |
John McCall | d931b08 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 509 | if (!Policy.SuppressSpecifiers && D->getStorageClass() != SC_None) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 510 | Out << VarDecl::getStorageClassSpecifierString(D->getStorageClass()) << " "; |
| 511 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 512 | if (!Policy.SuppressSpecifiers && D->isThreadSpecified()) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 513 | Out << "__thread "; |
| 514 | |
| 515 | std::string Name = D->getNameAsString(); |
| 516 | QualType T = D->getType(); |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 517 | if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 518 | T = Parm->getOriginalType(); |
| 519 | T.getAsStringInternal(Name, Policy); |
| 520 | Out << Name; |
Ted Kremenek | bccfd31 | 2010-09-07 22:21:59 +0000 | [diff] [blame^] | 521 | if (Expr *Init = D->getInit()) { |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 522 | if (D->hasCXXDirectInitializer()) |
| 523 | Out << "("; |
Ted Kremenek | bccfd31 | 2010-09-07 22:21:59 +0000 | [diff] [blame^] | 524 | else if (!dyn_cast<CXXConstructExpr>(Init)) |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 525 | Out << " = "; |
Ted Kremenek | bccfd31 | 2010-09-07 22:21:59 +0000 | [diff] [blame^] | 526 | Init->printPretty(Out, Context, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 527 | if (D->hasCXXDirectInitializer()) |
| 528 | Out << ")"; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) { |
| 533 | VisitVarDecl(D); |
| 534 | } |
| 535 | |
| 536 | void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
| 537 | Out << "__asm ("; |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 538 | D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 539 | Out << ")"; |
| 540 | } |
| 541 | |
| 542 | //---------------------------------------------------------------------------- |
| 543 | // C++ declarations |
| 544 | //---------------------------------------------------------------------------- |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 545 | void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 546 | Out << "namespace " << D << " {\n"; |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 547 | VisitDeclContext(D); |
| 548 | Indent() << "}"; |
| 549 | } |
| 550 | |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 551 | void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 552 | Out << "using namespace "; |
| 553 | if (D->getQualifier()) |
| 554 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 555 | Out << D->getNominatedNamespaceAsWritten(); |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 558 | void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 559 | Out << "namespace " << D << " = "; |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 560 | if (D->getQualifier()) |
| 561 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 562 | Out << D->getAliasedNamespace(); |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 565 | void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 566 | Out << D->getKindName(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 567 | if (D->getIdentifier()) |
| 568 | Out << ' ' << D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 570 | if (D->isDefinition()) { |
| 571 | // Print the base classes |
| 572 | if (D->getNumBases()) { |
| 573 | Out << " : "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(), |
| 575 | BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) { |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 576 | if (Base != D->bases_begin()) |
| 577 | Out << ", "; |
| 578 | |
| 579 | if (Base->isVirtual()) |
| 580 | Out << "virtual "; |
| 581 | |
Anders Carlsson | 018e9fe | 2009-08-29 20:36:12 +0000 | [diff] [blame] | 582 | AccessSpecifier AS = Base->getAccessSpecifierAsWritten(); |
| 583 | if (AS != AS_none) |
| 584 | Print(AS); |
Anders Carlsson | 0d59292 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 585 | Out << " " << Base->getType().getAsString(Policy); |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | // Print the class definition |
Douglas Gregor | f757ae7 | 2009-05-31 07:13:39 +0000 | [diff] [blame] | 590 | // FIXME: Doesn't print access specifiers, e.g., "public:" |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 591 | Out << " {\n"; |
| 592 | VisitDeclContext(D); |
| 593 | Indent() << "}"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 594 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 598 | const char *l; |
| 599 | if (D->getLanguage() == LinkageSpecDecl::lang_c) |
| 600 | l = "C"; |
| 601 | else { |
| 602 | assert(D->getLanguage() == LinkageSpecDecl::lang_cxx && |
| 603 | "unknown language in linkage specification"); |
| 604 | l = "C++"; |
| 605 | } |
| 606 | |
| 607 | Out << "extern \"" << l << "\" "; |
| 608 | if (D->hasBraces()) { |
| 609 | Out << "{\n"; |
| 610 | VisitDeclContext(D); |
| 611 | Indent() << "}"; |
| 612 | } else |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 613 | Visit(*D->decls_begin()); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) { |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 617 | Out << "template <"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 619 | TemplateParameterList *Params = D->getTemplateParameters(); |
| 620 | for (unsigned i = 0, e = Params->size(); i != e; ++i) { |
| 621 | if (i != 0) |
| 622 | Out << ", "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 624 | const Decl *Param = Params->getParam(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | if (const TemplateTypeParmDecl *TTP = |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 626 | dyn_cast<TemplateTypeParmDecl>(Param)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
| 628 | QualType ParamType = |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 629 | Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP)); |
| 630 | |
| 631 | if (TTP->wasDeclaredWithTypename()) |
| 632 | Out << "typename "; |
| 633 | else |
| 634 | Out << "class "; |
| 635 | |
Anders Carlsson | 6d845ae | 2009-06-12 22:23:22 +0000 | [diff] [blame] | 636 | if (TTP->isParameterPack()) |
| 637 | Out << "... "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | |
Douglas Gregor | efed5c8 | 2010-06-16 15:23:05 +0000 | [diff] [blame] | 639 | Out << ParamType.getAsString(Policy); |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 640 | |
| 641 | if (TTP->hasDefaultArgument()) { |
| 642 | Out << " = "; |
| 643 | Out << TTP->getDefaultArgument().getAsString(Policy); |
| 644 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 645 | } else if (const NonTypeTemplateParmDecl *NTTP = |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 646 | dyn_cast<NonTypeTemplateParmDecl>(Param)) { |
| 647 | Out << NTTP->getType().getAsString(Policy); |
| 648 | |
| 649 | if (IdentifierInfo *Name = NTTP->getIdentifier()) { |
| 650 | Out << ' '; |
| 651 | Out << Name->getName(); |
| 652 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 654 | if (NTTP->hasDefaultArgument()) { |
| 655 | Out << " = "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy, |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 657 | Indentation); |
| 658 | } |
| 659 | } |
| 660 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 | |
Anders Carlsson | 0487f66 | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 662 | Out << "> "; |
| 663 | |
Craig Silverstein | 0193a72 | 2010-07-09 20:25:10 +0000 | [diff] [blame] | 664 | if (isa<TemplateTemplateParmDecl>(D)) { |
| 665 | Out << "class " << D->getName(); |
| 666 | } else { |
| 667 | Visit(D->getTemplatedDecl()); |
| 668 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | //---------------------------------------------------------------------------- |
| 672 | // Objective-C declarations |
| 673 | //---------------------------------------------------------------------------- |
| 674 | |
| 675 | void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) { |
| 676 | Out << "@class "; |
| 677 | for (ObjCClassDecl::iterator I = D->begin(), E = D->end(); |
| 678 | I != E; ++I) { |
| 679 | if (I != D->begin()) Out << ", "; |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 680 | Out << I->getInterface(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 681 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { |
| 685 | if (OMD->isInstanceMethod()) |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 686 | Out << "- "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | else |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 688 | Out << "+ "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 689 | if (!OMD->getResultType().isNull()) |
Douglas Gregor | 59e6357 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 690 | Out << '(' << OMD->getResultType().getAsString(Policy) << ")"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 692 | std::string name = OMD->getSelector().getAsString(); |
| 693 | std::string::size_type pos, lastPos = 0; |
| 694 | for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(), |
| 695 | E = OMD->param_end(); PI != E; ++PI) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | // FIXME: selector is missing here! |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 697 | pos = name.find_first_of(":", lastPos); |
| 698 | Out << " " << name.substr(lastPos, pos - lastPos); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 699 | Out << ":(" << (*PI)->getType().getAsString(Policy) << ')' << *PI; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 700 | lastPos = pos + 1; |
| 701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 702 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 703 | if (OMD->param_begin() == OMD->param_end()) |
| 704 | Out << " " << name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 706 | if (OMD->isVariadic()) |
| 707 | Out << ", ..."; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 709 | if (OMD->getBody()) { |
| 710 | Out << ' '; |
Eli Friedman | 48d14a2 | 2009-05-30 05:03:24 +0000 | [diff] [blame] | 711 | OMD->getBody()->printPretty(Out, Context, 0, Policy); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 712 | Out << '\n'; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 713 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { |
| 717 | std::string I = OID->getNameAsString(); |
| 718 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
| 719 | |
| 720 | if (SID) |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 721 | Out << "@implementation " << I << " : " << SID; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 722 | else |
| 723 | Out << "@implementation " << I; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 724 | Out << "\n"; |
| 725 | VisitDeclContext(OID, false); |
| 726 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) { |
| 730 | std::string I = OID->getNameAsString(); |
| 731 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
| 732 | |
| 733 | if (SID) |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 734 | Out << "@interface " << I << " : " << SID; |
| 735 | else |
| 736 | Out << "@interface " << I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 738 | // Protocols? |
| 739 | const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols(); |
| 740 | if (!Protocols.empty()) { |
| 741 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 742 | E = Protocols.end(); I != E; ++I) |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 743 | Out << (I == Protocols.begin() ? '<' : ',') << *I; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 746 | if (!Protocols.empty()) |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 747 | Out << "> "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 749 | if (OID->ivar_size() > 0) { |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 750 | Out << "{\n"; |
| 751 | Indentation += Policy.Indentation; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 752 | for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(), |
| 753 | E = OID->ivar_end(); I != E; ++I) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 754 | Indent() << (*I)->getType().getAsString(Policy) << ' ' << *I << ";\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 755 | } |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 756 | Indentation -= Policy.Indentation; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 757 | Out << "}\n"; |
| 758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 760 | VisitDeclContext(OID, false); |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 761 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 762 | // FIXME: implement the rest... |
| 763 | } |
| 764 | |
| 765 | void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { |
| 766 | Out << "@protocol "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(), |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 768 | E = D->protocol_end(); |
| 769 | I != E; ++I) { |
| 770 | if (I != D->protocol_begin()) Out << ", "; |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 771 | Out << *I; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 772 | } |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 776 | Out << "@protocol " << PID << '\n'; |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 777 | VisitDeclContext(PID, false); |
| 778 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 782 | Out << "@implementation " << PID->getClassInterface() << '(' << PID << ")\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 783 | |
| 784 | VisitDeclContext(PID, false); |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 785 | Out << "@end"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 786 | // FIXME: implement the rest... |
| 787 | } |
| 788 | |
| 789 | void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 790 | Out << "@interface " << PID->getClassInterface() << '(' << PID << ")\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 791 | VisitDeclContext(PID, false); |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 792 | Out << "@end"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 793 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 794 | // FIXME: implement the rest... |
| 795 | } |
| 796 | |
| 797 | void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 798 | Out << "@compatibility_alias " << AID |
| 799 | << ' ' << AID->getClassInterface() << ";\n"; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /// PrintObjCPropertyDecl - print a property declaration. |
| 803 | /// |
| 804 | void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { |
| 805 | if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required) |
| 806 | Out << "@required\n"; |
| 807 | else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 808 | Out << "@optional\n"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 810 | Out << "@property"; |
| 811 | if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) { |
| 812 | bool first = true; |
| 813 | Out << " ("; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 814 | if (PDecl->getPropertyAttributes() & |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 815 | ObjCPropertyDecl::OBJC_PR_readonly) { |
| 816 | Out << (first ? ' ' : ',') << "readonly"; |
| 817 | first = false; |
| 818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 819 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 820 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { |
| 821 | Out << (first ? ' ' : ',') << "getter = " |
| 822 | << PDecl->getGetterName().getAsString(); |
| 823 | first = false; |
| 824 | } |
| 825 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { |
| 826 | Out << (first ? ' ' : ',') << "setter = " |
| 827 | << PDecl->getSetterName().getAsString(); |
| 828 | first = false; |
| 829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 831 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) { |
| 832 | Out << (first ? ' ' : ',') << "assign"; |
| 833 | first = false; |
| 834 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 836 | if (PDecl->getPropertyAttributes() & |
| 837 | ObjCPropertyDecl::OBJC_PR_readwrite) { |
| 838 | Out << (first ? ' ' : ',') << "readwrite"; |
| 839 | first = false; |
| 840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 842 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) { |
| 843 | Out << (first ? ' ' : ',') << "retain"; |
| 844 | first = false; |
| 845 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 847 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) { |
| 848 | Out << (first ? ' ' : ',') << "copy"; |
| 849 | first = false; |
| 850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 851 | |
| 852 | if (PDecl->getPropertyAttributes() & |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 853 | ObjCPropertyDecl::OBJC_PR_nonatomic) { |
| 854 | Out << (first ? ' ' : ',') << "nonatomic"; |
| 855 | first = false; |
| 856 | } |
| 857 | Out << " )"; |
| 858 | } |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 859 | Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << PDecl; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) { |
| 863 | if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 864 | Out << "@synthesize "; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 865 | else |
Douglas Gregor | 64f6500 | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 866 | Out << "@dynamic "; |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 867 | Out << PID->getPropertyDecl(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 868 | if (PID->getPropertyIvarDecl()) |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 869 | Out << '=' << PID->getPropertyIvarDecl(); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 870 | } |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 871 | |
| 872 | void DeclPrinter::VisitUsingDecl(UsingDecl *D) { |
| 873 | Out << "using "; |
| 874 | D->getTargetNestedNameDecl()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 875 | Out << D; |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 876 | } |
| 877 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 878 | void |
| 879 | DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { |
| 880 | Out << "using typename "; |
| 881 | D->getTargetNestedNameSpecifier()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 882 | Out << D->getDeclName(); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 886 | Out << "using "; |
| 887 | D->getTargetNestedNameSpecifier()->print(Out, Policy); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 888 | Out << D->getDeclName(); |
Anders Carlsson | f53eaa5 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 889 | } |
John McCall | 9488ea1 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 890 | |
| 891 | void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 892 | // ignore |
| 893 | } |