Chris Lattner | 97e8b6f | 2007-10-07 06:04:32 +0000 | [diff] [blame] | 1 | //===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 97e8b6f | 2007-10-07 06:04:32 +0000 | [diff] [blame] | 10 | // AST Consumer Implementations. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 97e8b6f | 2007-10-07 06:04:32 +0000 | [diff] [blame] | 14 | #include "ASTConsumers.h" |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 15 | #include "clang/Frontend/PathDiagnosticClients.h" |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 16 | #include "clang/Basic/Diagnostic.h" |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 17 | #include "clang/Basic/SourceManager.h" |
| 18 | #include "clang/Basic/FileManager.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "clang/AST/AST.h" |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTConsumer.h" |
Chris Lattner | 557c5b1 | 2009-03-28 04:27:18 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTContext.h" |
Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 22 | #include "clang/CodeGen/ModuleBuilder.h" |
| 23 | #include "llvm/Module.h" |
Daniel Dunbar | d46075f | 2008-10-21 23:54:00 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Streams.h" |
Ted Kremenek | cb33093 | 2008-02-18 21:21:23 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Timer.h" |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 557c5b1 | 2009-03-28 04:27:18 +0000 | [diff] [blame] | 27 | #include "llvm/System/Path.h" |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 28 | using namespace clang; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 29 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 30 | //===----------------------------------------------------------------------===// |
| 31 | /// DeclPrinter - Utility class for printing top-level decls. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 32 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 33 | namespace { |
| 34 | class DeclPrinter { |
| 35 | public: |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 36 | llvm::raw_ostream& Out; |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 37 | unsigned Indentation; |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 38 | |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 39 | DeclPrinter(llvm::raw_ostream* out) : Out(out ? *out : llvm::errs()), |
| 40 | Indentation(0) {} |
| 41 | DeclPrinter() : Out(llvm::errs()), Indentation(0) {} |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 42 | virtual ~DeclPrinter(); |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 43 | |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 44 | void ChangeIndent(int I) { |
| 45 | Indentation += I; |
| 46 | } |
| 47 | |
| 48 | llvm::raw_ostream& Indent() { |
| 49 | for (unsigned i = 0; i < Indentation; ++i) |
| 50 | Out << " "; |
| 51 | return Out; |
| 52 | } |
| 53 | |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 54 | void PrintDecl(Decl *D); |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 55 | void Print(NamedDecl *ND); |
| 56 | void Print(NamespaceDecl *NS); |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 57 | void PrintFunctionDeclStart(FunctionDecl *FD); |
| 58 | void PrintTypeDefDecl(TypedefDecl *TD); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 59 | void PrintLinkageSpec(LinkageSpecDecl *LS); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 60 | void PrintObjCMethodDecl(ObjCMethodDecl *OMD); |
| 61 | void PrintObjCImplementationDecl(ObjCImplementationDecl *OID); |
| 62 | void PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID); |
| 63 | void PrintObjCProtocolDecl(ObjCProtocolDecl *PID); |
| 64 | void PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID); |
| 65 | void PrintObjCCategoryDecl(ObjCCategoryDecl *PID); |
| 66 | void PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID); |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 67 | void PrintObjCPropertyDecl(ObjCPropertyDecl *PD); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 68 | void PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 69 | |
| 70 | void PrintTemplateDecl(TemplateDecl *TD); |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 71 | }; |
| 72 | } // end anonymous namespace |
| 73 | |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 74 | DeclPrinter::~DeclPrinter() { |
| 75 | Out.flush(); |
| 76 | } |
| 77 | |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 78 | void DeclPrinter:: PrintDecl(Decl *D) { |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 79 | Indent(); |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 80 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 81 | PrintFunctionDeclStart(FD); |
| 82 | |
| 83 | if (FD->getBody()) { |
| 84 | Out << ' '; |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 85 | FD->getBody()->printPretty(Out, 0, Indentation, true); |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 86 | Out << '\n'; |
| 87 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 88 | } else if (isa<ObjCMethodDecl>(D)) { |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 89 | // Do nothing, methods definitions are printed in |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 90 | // PrintObjCImplementationDecl. |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 91 | } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { |
| 92 | PrintTypeDefDecl(TD); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 93 | } else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 94 | PrintObjCInterfaceDecl(OID); |
| 95 | } else if (ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(D)) { |
| 96 | PrintObjCProtocolDecl(PID); |
| 97 | } else if (ObjCForwardProtocolDecl *OFPD = |
Chris Lattner | c81c814 | 2008-02-25 21:04:36 +0000 | [diff] [blame] | 98 | dyn_cast<ObjCForwardProtocolDecl>(D)) { |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 99 | Out << "@protocol "; |
Chris Lattner | 07fa774 | 2009-02-20 18:10:37 +0000 | [diff] [blame] | 100 | for (ObjCForwardProtocolDecl::iterator I = OFPD->begin(), E = OFPD->end(); |
| 101 | I != E; ++I) { |
| 102 | if (I != OFPD->begin()) Out << ", "; |
| 103 | Out << (*I)->getNameAsString(); |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 104 | } |
| 105 | Out << ";\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 106 | } else if (ObjCImplementationDecl *OID = |
Chris Lattner | c81c814 | 2008-02-25 21:04:36 +0000 | [diff] [blame] | 107 | dyn_cast<ObjCImplementationDecl>(D)) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 108 | PrintObjCImplementationDecl(OID); |
| 109 | } else if (ObjCCategoryImplDecl *OID = |
Chris Lattner | c81c814 | 2008-02-25 21:04:36 +0000 | [diff] [blame] | 110 | dyn_cast<ObjCCategoryImplDecl>(D)) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 111 | PrintObjCCategoryImplDecl(OID); |
| 112 | } else if (ObjCCategoryDecl *OID = |
Chris Lattner | c81c814 | 2008-02-25 21:04:36 +0000 | [diff] [blame] | 113 | dyn_cast<ObjCCategoryDecl>(D)) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 114 | PrintObjCCategoryDecl(OID); |
| 115 | } else if (ObjCCompatibleAliasDecl *OID = |
Chris Lattner | c81c814 | 2008-02-25 21:04:36 +0000 | [diff] [blame] | 116 | dyn_cast<ObjCCompatibleAliasDecl>(D)) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 117 | PrintObjCCompatibleAliasDecl(OID); |
Chris Lattner | 23a0e45 | 2008-06-21 21:40:20 +0000 | [diff] [blame] | 118 | } else if (ObjCClassDecl *OFCD = dyn_cast<ObjCClassDecl>(D)) { |
| 119 | Out << "@class "; |
Chris Lattner | 6795605 | 2009-02-20 18:04:31 +0000 | [diff] [blame] | 120 | for (ObjCClassDecl::iterator I = OFCD->begin(), E = OFCD->end(); |
| 121 | I != E; ++I) { |
| 122 | if (I != OFCD->begin()) Out << ", "; |
| 123 | Out << (*I)->getNameAsString(); |
Chris Lattner | 23a0e45 | 2008-06-21 21:40:20 +0000 | [diff] [blame] | 124 | } |
| 125 | Out << ";\n"; |
Douglas Gregor | 45579f5 | 2008-12-17 02:04:30 +0000 | [diff] [blame] | 126 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { |
| 127 | Out << "enum " << ED->getNameAsString() << " {\n"; |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 128 | // FIXME: Shouldn't pass a NULL context |
| 129 | ASTContext *Context = 0; |
| 130 | for (EnumDecl::enumerator_iterator E = ED->enumerator_begin(*Context), |
| 131 | EEnd = ED->enumerator_end(*Context); |
Douglas Gregor | 45579f5 | 2008-12-17 02:04:30 +0000 | [diff] [blame] | 132 | E != EEnd; ++E) |
| 133 | Out << " " << (*E)->getNameAsString() << ",\n"; |
| 134 | Out << "};\n"; |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 135 | } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 136 | // print a free standing tag decl (e.g. "struct x;"). |
| 137 | Out << TD->getKindName(); |
| 138 | Out << " "; |
| 139 | if (const IdentifierInfo *II = TD->getIdentifier()) |
| 140 | Out << II->getName(); |
| 141 | |
| 142 | Out << " {\n"; |
| 143 | ChangeIndent(1); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 144 | // FIXME: Shouldn't pass a NULL context |
| 145 | ASTContext *Context = 0; |
| 146 | for (DeclContext::decl_iterator i = TD->decls_begin(*Context); |
| 147 | i != TD->decls_end(*Context); |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 148 | ++i) |
| 149 | PrintDecl(*i); |
| 150 | ChangeIndent(-1); |
| 151 | Indent(); |
| 152 | Out << "}"; |
| 153 | |
| 154 | Out << "\n"; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 155 | } else if (TemplateDecl *TempD = dyn_cast<TemplateDecl>(D)) { |
| 156 | PrintTemplateDecl(TempD); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 157 | } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) { |
| 158 | PrintLinkageSpec(LSD); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 159 | } else if (FileScopeAsmDecl *AD = dyn_cast<FileScopeAsmDecl>(D)) { |
| 160 | Out << "asm("; |
| 161 | AD->getAsmString()->printPretty(Out); |
| 162 | Out << ")\n"; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 163 | } else if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) { |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 164 | Print(ND); |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 165 | } else { |
| 166 | assert(0 && "Unknown decl type!"); |
| 167 | } |
| 168 | } |
| 169 | |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 170 | void DeclPrinter::Print(NamedDecl *ND) { |
| 171 | switch (ND->getKind()) { |
| 172 | default: |
| 173 | // FIXME: Handle the rest of the NamedDecls. |
| 174 | Out << "### NamedDecl " << ND->getNameAsString() << "\n"; |
| 175 | break; |
| 176 | case Decl::Field: |
| 177 | case Decl::Var: { |
| 178 | // Emit storage class for vardecls. |
| 179 | if (VarDecl *V = dyn_cast<VarDecl>(ND)) { |
| 180 | switch (V->getStorageClass()) { |
| 181 | default: assert(0 && "Unknown storage class!"); |
Mike Stump | c5840c0 | 2009-02-10 23:49:50 +0000 | [diff] [blame] | 182 | case VarDecl::None: break; |
| 183 | case VarDecl::Auto: Out << "auto "; break; |
| 184 | case VarDecl::Register: Out << "register "; break; |
| 185 | case VarDecl::Extern: Out << "extern "; break; |
| 186 | case VarDecl::Static: Out << "static "; break; |
Daniel Dunbar | 7ab41f7 | 2009-02-13 22:49:34 +0000 | [diff] [blame] | 187 | case VarDecl::PrivateExtern: Out << "__private_extern__ "; break; |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | std::string Name = ND->getNameAsString(); |
| 191 | // This forms: "int a". |
| 192 | dyn_cast<ValueDecl>(ND)->getType().getAsStringInternal(Name); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame^] | 193 | Out << Name; |
| 194 | if (VarDecl *Var = dyn_cast<VarDecl>(ND)) { |
| 195 | if (Var->getInit()) { |
| 196 | Out << " = "; |
| 197 | Var->getInit()->printPretty(Out); |
| 198 | } |
| 199 | } |
| 200 | Out << ";\n"; |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | case Decl::Namespace: |
| 204 | Print(dyn_cast<NamespaceDecl>(ND)); |
| 205 | break; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void DeclPrinter::Print(NamespaceDecl *NS) { |
| 210 | Out << "namespace " << NS->getNameAsString() << " {\n"; |
| 211 | ChangeIndent(1); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 212 | // FIXME: Shouldn't pass a NULL context |
| 213 | ASTContext *Context = 0; |
| 214 | for (DeclContext::decl_iterator i = NS->decls_begin(*Context); |
| 215 | i != NS->decls_end(*Context); |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 216 | ++i) |
| 217 | PrintDecl(*i); |
| 218 | ChangeIndent(-1); |
| 219 | Indent(); |
| 220 | Out << "}\n"; |
| 221 | } |
| 222 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 223 | void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 224 | bool HasBody = FD->getBody(); |
| 225 | |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 226 | Out << '\n'; |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 227 | |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 228 | Indent(); |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 229 | switch (FD->getStorageClass()) { |
| 230 | default: assert(0 && "Unknown storage class"); |
| 231 | case FunctionDecl::None: break; |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 232 | case FunctionDecl::Extern: Out << "extern "; break; |
| 233 | case FunctionDecl::Static: Out << "static "; break; |
Ted Kremenek | 24bd3c4 | 2008-04-15 03:57:09 +0000 | [diff] [blame] | 234 | case FunctionDecl::PrivateExtern: Out << "__private_extern__ "; break; |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | if (FD->isInline()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 238 | Out << "inline "; |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 239 | |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 240 | std::string Proto = FD->getNameAsString(); |
Chris Lattner | 0d6ca11 | 2007-12-03 21:43:25 +0000 | [diff] [blame] | 241 | const FunctionType *AFT = FD->getType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 242 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 243 | if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(AFT)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 244 | Proto += "("; |
| 245 | for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { |
| 246 | if (i) Proto += ", "; |
| 247 | std::string ParamStr; |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 248 | if (HasBody) ParamStr = FD->getParamDecl(i)->getNameAsString(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 249 | |
| 250 | FT->getArgType(i).getAsStringInternal(ParamStr); |
| 251 | Proto += ParamStr; |
| 252 | } |
| 253 | |
| 254 | if (FT->isVariadic()) { |
| 255 | if (FD->getNumParams()) Proto += ", "; |
| 256 | Proto += "..."; |
| 257 | } |
| 258 | Proto += ")"; |
| 259 | } else { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 260 | assert(isa<FunctionNoProtoType>(AFT)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 261 | Proto += "()"; |
| 262 | } |
| 263 | |
| 264 | AFT->getResultType().getAsStringInternal(Proto); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 265 | Out << Proto; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 266 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 267 | if (!FD->getBody()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 268 | Out << ";\n"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 269 | // Doesn't print the body. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 272 | void DeclPrinter::PrintTypeDefDecl(TypedefDecl *TD) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 273 | std::string S = TD->getNameAsString(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 274 | TD->getUnderlyingType().getAsStringInternal(S); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 275 | Out << "typedef " << S << ";\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 278 | void DeclPrinter::PrintLinkageSpec(LinkageSpecDecl *LS) { |
| 279 | const char *l; |
| 280 | if (LS->getLanguage() == LinkageSpecDecl::lang_c) |
| 281 | l = "C"; |
Chris Lattner | 0676751 | 2008-04-08 05:52:18 +0000 | [diff] [blame] | 282 | else { |
| 283 | assert(LS->getLanguage() == LinkageSpecDecl::lang_cxx && |
| 284 | "unknown language in linkage specification"); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 285 | l = "C++"; |
Chris Lattner | 0676751 | 2008-04-08 05:52:18 +0000 | [diff] [blame] | 286 | } |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 287 | |
| 288 | Out << "extern \"" << l << "\" "; |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 289 | if (LS->hasBraces()) { |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 290 | Out << "{\n"; |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 291 | ChangeIndent(1); |
| 292 | } |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 293 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 294 | // FIXME: Should not use a NULL DeclContext! |
| 295 | ASTContext *Context = 0; |
| 296 | for (LinkageSpecDecl::decl_iterator D = LS->decls_begin(*Context), |
| 297 | DEnd = LS->decls_end(*Context); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 298 | D != DEnd; ++D) |
| 299 | PrintDecl(*D); |
| 300 | |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 301 | if (LS->hasBraces()) { |
| 302 | ChangeIndent(-1); |
| 303 | Indent() << "}"; |
| 304 | } |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 305 | Out << "\n"; |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 308 | void DeclPrinter::PrintObjCMethodDecl(ObjCMethodDecl *OMD) { |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 309 | if (OMD->isInstanceMethod()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 310 | Out << "\n- "; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 311 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 312 | Out << "\n+ "; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 313 | if (!OMD->getResultType().isNull()) |
Chris Lattner | efe8a96 | 2008-08-22 06:59:15 +0000 | [diff] [blame] | 314 | Out << '(' << OMD->getResultType().getAsString() << ")"; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 315 | |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 316 | std::string name = OMD->getSelector().getAsString(); |
Chris Lattner | efe8a96 | 2008-08-22 06:59:15 +0000 | [diff] [blame] | 317 | std::string::size_type pos, lastPos = 0; |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 318 | for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(), |
| 319 | E = OMD->param_end(); PI != E; ++PI) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 320 | // FIXME: selector is missing here! |
Chris Lattner | efe8a96 | 2008-08-22 06:59:15 +0000 | [diff] [blame] | 321 | pos = name.find_first_of(":", lastPos); |
| 322 | Out << " " << name.substr(lastPos, pos - lastPos); |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 323 | Out << ":(" << (*PI)->getType().getAsString() << ")" |
| 324 | << (*PI)->getNameAsString(); |
Chris Lattner | efe8a96 | 2008-08-22 06:59:15 +0000 | [diff] [blame] | 325 | lastPos = pos + 1; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 326 | } |
Chris Lattner | efe8a96 | 2008-08-22 06:59:15 +0000 | [diff] [blame] | 327 | |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 328 | if (OMD->param_begin() == OMD->param_end()) |
Chris Lattner | efe8a96 | 2008-08-22 06:59:15 +0000 | [diff] [blame] | 329 | Out << " " << name; |
| 330 | |
| 331 | if (OMD->isVariadic()) |
| 332 | Out << ", ..."; |
| 333 | |
| 334 | Out << ";"; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 337 | void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 338 | std::string I = OID->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 339 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 340 | |
| 341 | if (SID) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 342 | Out << "@implementation " << I << " : " << SID->getNameAsString(); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 343 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 344 | Out << "@implementation " << I; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 345 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 346 | for (ObjCImplementationDecl::instmeth_iterator I = OID->instmeth_begin(), |
Chris Lattner | ab4c4d5 | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 347 | E = OID->instmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 348 | ObjCMethodDecl *OMD = *I; |
| 349 | PrintObjCMethodDecl(OMD); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 350 | if (OMD->getBody()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 351 | Out << ' '; |
| 352 | OMD->getBody()->printPretty(Out); |
| 353 | Out << '\n'; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 357 | for (ObjCImplementationDecl::classmeth_iterator I = OID->classmeth_begin(), |
Chris Lattner | ab4c4d5 | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 358 | E = OID->classmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 359 | ObjCMethodDecl *OMD = *I; |
| 360 | PrintObjCMethodDecl(OMD); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 361 | if (OMD->getBody()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 362 | Out << ' '; |
| 363 | OMD->getBody()->printPretty(Out); |
| 364 | Out << '\n'; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 368 | for (ObjCImplementationDecl::propimpl_iterator I = OID->propimpl_begin(), |
| 369 | E = OID->propimpl_end(); I != E; ++I) |
| 370 | PrintObjCPropertyImplDecl(*I); |
| 371 | |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 372 | Out << "@end\n"; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 376 | void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 377 | std::string I = OID->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 378 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 379 | |
| 380 | if (SID) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 381 | Out << "@interface " << I << " : " << SID->getNameAsString(); |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 382 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 383 | Out << "@interface " << I; |
| 384 | |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 385 | // Protocols? |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 386 | const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols(); |
| 387 | if (!Protocols.empty()) { |
| 388 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 389 | E = Protocols.end(); I != E; ++I) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 390 | Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString(); |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 391 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 392 | |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 393 | if (!Protocols.empty()) |
| 394 | Out << ">"; |
| 395 | Out << '\n'; |
Fariborz Jahanian | edcfb42 | 2007-10-26 16:29:12 +0000 | [diff] [blame] | 396 | |
Chris Lattner | f3a7af9 | 2008-03-16 21:08:55 +0000 | [diff] [blame] | 397 | if (OID->ivar_size() > 0) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 398 | Out << '{'; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 399 | for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(), |
Chris Lattner | be6df08 | 2007-12-12 07:56:42 +0000 | [diff] [blame] | 400 | E = OID->ivar_end(); I != E; ++I) { |
| 401 | Out << '\t' << (*I)->getType().getAsString() |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 402 | << ' ' << (*I)->getNameAsString() << ";\n"; |
Fariborz Jahanian | edcfb42 | 2007-10-26 16:29:12 +0000 | [diff] [blame] | 403 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 404 | Out << "}\n"; |
Fariborz Jahanian | edcfb42 | 2007-10-26 16:29:12 +0000 | [diff] [blame] | 405 | } |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 407 | // FIXME: Should not use a NULL DeclContext! |
| 408 | ASTContext *Context = 0; |
| 409 | for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(*Context), |
| 410 | E = OID->prop_end(*Context); I != E; ++I) |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 411 | PrintObjCPropertyDecl(*I); |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 412 | bool eol_needed = false; |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 413 | for (ObjCInterfaceDecl::classmeth_iterator I = OID->classmeth_begin(*Context), |
| 414 | E = OID->classmeth_end(*Context); I != E; ++I) |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 415 | eol_needed = true, PrintObjCMethodDecl(*I); |
Fariborz Jahanian | b89ca23 | 2008-05-06 23:14:25 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 417 | for (ObjCInterfaceDecl::instmeth_iterator I = OID->instmeth_begin(*Context), |
| 418 | E = OID->instmeth_end(*Context); I != E; ++I) |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 419 | eol_needed = true, PrintObjCMethodDecl(*I); |
Fariborz Jahanian | b89ca23 | 2008-05-06 23:14:25 +0000 | [diff] [blame] | 420 | |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 421 | Out << (eol_needed ? "\n@end\n" : "@end\n"); |
Steve Naroff | 2bd42fa | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 422 | // FIXME: implement the rest... |
| 423 | } |
| 424 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 425 | void DeclPrinter::PrintObjCProtocolDecl(ObjCProtocolDecl *PID) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 426 | Out << "@protocol " << PID->getNameAsString() << '\n'; |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 427 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 428 | // FIXME: Should not use a NULL DeclContext! |
| 429 | ASTContext *Context = 0; |
| 430 | for (ObjCProtocolDecl::prop_iterator I = PID->prop_begin(*Context), |
| 431 | E = PID->prop_end(*Context); I != E; ++I) |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 432 | PrintObjCPropertyDecl(*I); |
| 433 | Out << "@end\n"; |
Fariborz Jahanian | ab0aeb0 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 434 | // FIXME: implement the rest... |
| 435 | } |
| 436 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 437 | void DeclPrinter::PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 438 | Out << "@implementation " |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 439 | << PID->getClassInterface()->getNameAsString() |
| 440 | << '(' << PID->getNameAsString() << ");\n"; |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 441 | for (ObjCCategoryImplDecl::propimpl_iterator I = PID->propimpl_begin(), |
| 442 | E = PID->propimpl_end(); I != E; ++I) |
| 443 | PrintObjCPropertyImplDecl(*I); |
| 444 | Out << "@end\n"; |
Fariborz Jahanian | ab0aeb0 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 445 | // FIXME: implement the rest... |
| 446 | } |
| 447 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 448 | void DeclPrinter::PrintObjCCategoryDecl(ObjCCategoryDecl *PID) { |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 449 | // FIXME: Should not use a NULL DeclContext! |
| 450 | ASTContext *Context = 0; |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 451 | Out << "@interface " |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 452 | << PID->getClassInterface()->getNameAsString() |
| 453 | << '(' << PID->getNameAsString() << ");\n"; |
Fariborz Jahanian | 7e7e387 | 2008-04-16 21:08:45 +0000 | [diff] [blame] | 454 | // Output property declarations. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 455 | for (ObjCCategoryDecl::prop_iterator I = PID->prop_begin(*Context), |
| 456 | E = PID->prop_end(*Context); I != E; ++I) |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 457 | PrintObjCPropertyDecl(*I); |
Fariborz Jahanian | 7e7e387 | 2008-04-16 21:08:45 +0000 | [diff] [blame] | 458 | Out << "@end\n"; |
| 459 | |
Fariborz Jahanian | ab0aeb0 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 460 | // FIXME: implement the rest... |
| 461 | } |
| 462 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 463 | void DeclPrinter::PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 464 | Out << "@compatibility_alias " << AID->getNameAsString() |
| 465 | << ' ' << AID->getClassInterface()->getNameAsString() << ";\n"; |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 468 | /// PrintObjCPropertyDecl - print a property declaration. |
| 469 | /// |
| 470 | void DeclPrinter::PrintObjCPropertyDecl(ObjCPropertyDecl *PDecl) { |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 471 | if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required) |
| 472 | Out << "@required\n"; |
| 473 | else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 474 | Out << "@optional\n"; |
| 475 | |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 476 | Out << "@property"; |
| 477 | if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) { |
| 478 | bool first = true; |
| 479 | Out << " ("; |
| 480 | if (PDecl->getPropertyAttributes() & |
| 481 | ObjCPropertyDecl::OBJC_PR_readonly) { |
| 482 | Out << (first ? ' ' : ',') << "readonly"; |
| 483 | first = false; |
| 484 | } |
| 485 | |
| 486 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { |
| 487 | Out << (first ? ' ' : ',') << "getter = " |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 488 | << PDecl->getGetterName().getAsString(); |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 489 | first = false; |
| 490 | } |
| 491 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { |
| 492 | Out << (first ? ' ' : ',') << "setter = " |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 493 | << PDecl->getSetterName().getAsString(); |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 494 | first = false; |
| 495 | } |
| 496 | |
| 497 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) { |
| 498 | Out << (first ? ' ' : ',') << "assign"; |
| 499 | first = false; |
| 500 | } |
| 501 | |
| 502 | if (PDecl->getPropertyAttributes() & |
| 503 | ObjCPropertyDecl::OBJC_PR_readwrite) { |
| 504 | Out << (first ? ' ' : ',') << "readwrite"; |
| 505 | first = false; |
| 506 | } |
| 507 | |
| 508 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) { |
| 509 | Out << (first ? ' ' : ',') << "retain"; |
| 510 | first = false; |
| 511 | } |
| 512 | |
| 513 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) { |
| 514 | Out << (first ? ' ' : ',') << "copy"; |
| 515 | first = false; |
| 516 | } |
| 517 | |
| 518 | if (PDecl->getPropertyAttributes() & |
| 519 | ObjCPropertyDecl::OBJC_PR_nonatomic) { |
| 520 | Out << (first ? ' ' : ',') << "nonatomic"; |
| 521 | first = false; |
| 522 | } |
| 523 | Out << " )"; |
| 524 | } |
| 525 | Out << ' ' << PDecl->getType().getAsString() |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 526 | << ' ' << PDecl->getNameAsString(); |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 527 | |
| 528 | Out << ";\n"; |
| 529 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 530 | |
| 531 | /// PrintObjCPropertyImplDecl - Print an objective-c property implementation |
| 532 | /// declaration syntax. |
| 533 | /// |
| 534 | void DeclPrinter::PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) { |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 535 | if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 536 | Out << "\n@synthesize "; |
| 537 | else |
| 538 | Out << "\n@dynamic "; |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 539 | Out << PID->getPropertyDecl()->getNameAsString(); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 540 | if (PID->getPropertyIvarDecl()) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 541 | Out << "=" << PID->getPropertyIvarDecl()->getNameAsString(); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 542 | Out << ";\n"; |
| 543 | } |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 544 | |
| 545 | /// PrintTemplateParams - Print a template parameter list and recursively print |
| 546 | /// it's underlying top-level definition. |
| 547 | void DeclPrinter::PrintTemplateDecl(TemplateDecl *TD) { |
| 548 | // TODO: Write template parameters. |
| 549 | Out << "template <...> "; |
| 550 | PrintDecl(TD->getTemplatedDecl()); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 555 | //===----------------------------------------------------------------------===// |
| 556 | /// ASTPrinter - Pretty-printer of ASTs |
| 557 | |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 558 | namespace { |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 559 | class ASTPrinter : public ASTConsumer, public DeclPrinter { |
| 560 | public: |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 561 | ASTPrinter(llvm::raw_ostream* o = NULL) : DeclPrinter(o) {} |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 562 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 563 | virtual void HandleTopLevelDecl(DeclGroupRef D) { |
| 564 | for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) |
| 565 | PrintDecl(*I); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 566 | } |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 567 | }; |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 568 | } // end anonymous namespace |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 569 | |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 570 | ASTConsumer *clang::CreateASTPrinter(llvm::raw_ostream* out) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 571 | return new ASTPrinter(out); |
| 572 | } |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 573 | |
| 574 | //===----------------------------------------------------------------------===// |
| 575 | /// ASTDumper - Low-level dumper of ASTs |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 576 | |
| 577 | namespace { |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 578 | class ASTDumper : public ASTConsumer, public DeclPrinter { |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 579 | SourceManager *SM; |
| 580 | public: |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 581 | ASTDumper() : DeclPrinter() {} |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 582 | |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 583 | void Initialize(ASTContext &Context) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 584 | SM = &Context.getSourceManager(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 585 | } |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 586 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 587 | virtual void HandleTopLevelDecl(DeclGroupRef D) { |
| 588 | for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) |
| 589 | HandleTopLevelSingleDecl(*I); |
| 590 | } |
| 591 | void HandleTopLevelSingleDecl(Decl *D); |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 592 | }; |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 593 | } // end anonymous namespace |
| 594 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 595 | void ASTDumper::HandleTopLevelSingleDecl(Decl *D) { |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 596 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 597 | PrintFunctionDeclStart(FD); |
| 598 | |
| 599 | if (FD->getBody()) { |
| 600 | Out << '\n'; |
| 601 | // FIXME: convert dumper to use std::ostream? |
| 602 | FD->getBody()->dumpAll(*SM); |
| 603 | Out << '\n'; |
| 604 | } |
| 605 | } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { |
| 606 | PrintTypeDefDecl(TD); |
| 607 | } else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 608 | Out << "Read objc interface '" << OID->getNameAsString() << "'\n"; |
| 609 | } else if (ObjCProtocolDecl *OPD = dyn_cast<ObjCProtocolDecl>(D)) { |
| 610 | Out << "Read objc protocol '" << OPD->getNameAsString() << "'\n"; |
| 611 | } else if (ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(D)) { |
| 612 | Out << "Read objc category '" << OCD->getNameAsString() << "'\n"; |
| 613 | } else if (isa<ObjCForwardProtocolDecl>(D)) { |
| 614 | Out << "Read objc fwd protocol decl\n"; |
| 615 | } else if (isa<ObjCClassDecl>(D)) { |
| 616 | Out << "Read objc fwd class decl\n"; |
| 617 | } else if (isa<FileScopeAsmDecl>(D)) { |
| 618 | Out << "Read file scope asm decl\n"; |
| 619 | } else if (ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(D)) { |
| 620 | Out << "Read objc method decl: '" << MD->getSelector().getAsString() |
| 621 | << "'\n"; |
| 622 | if (MD->getBody()) { |
| 623 | // FIXME: convert dumper to use std::ostream? |
| 624 | MD->getBody()->dumpAll(*SM); |
| 625 | Out << '\n'; |
| 626 | } |
| 627 | } else if (isa<ObjCImplementationDecl>(D)) { |
| 628 | Out << "Read objc implementation decl\n"; |
| 629 | } else if (isa<ObjCCategoryImplDecl>(D)) { |
| 630 | Out << "Read objc category implementation decl\n"; |
| 631 | } else if (isa<LinkageSpecDecl>(D)) { |
| 632 | Out << "Read linkage spec decl\n"; |
| 633 | } else if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) { |
| 634 | Out << "Read top-level variable decl: '" << ND->getNameAsString() |
| 635 | << "'\n"; |
| 636 | } else { |
| 637 | assert(0 && "Unknown decl type!"); |
| 638 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 641 | ASTConsumer *clang::CreateASTDumper() { return new ASTDumper(); } |
| 642 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 643 | //===----------------------------------------------------------------------===// |
| 644 | /// ASTViewer - AST Visualization |
| 645 | |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 646 | namespace { |
| 647 | class ASTViewer : public ASTConsumer { |
| 648 | SourceManager *SM; |
| 649 | public: |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 650 | void Initialize(ASTContext &Context) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 651 | SM = &Context.getSourceManager(); |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 652 | } |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 653 | |
| 654 | virtual void HandleTopLevelDecl(DeclGroupRef D) { |
| 655 | for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) |
| 656 | HandleTopLevelSingleDecl(*I); |
| 657 | } |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 658 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 659 | void HandleTopLevelSingleDecl(Decl *D); |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 660 | }; |
| 661 | } |
| 662 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 663 | void ASTViewer::HandleTopLevelSingleDecl(Decl *D) { |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 664 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 665 | DeclPrinter().PrintFunctionDeclStart(FD); |
| 666 | |
| 667 | if (FD->getBody()) { |
| 668 | llvm::cerr << '\n'; |
| 669 | FD->getBody()->viewAST(); |
| 670 | llvm::cerr << '\n'; |
| 671 | } |
| 672 | return; |
| 673 | } |
| 674 | |
| 675 | if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { |
| 676 | DeclPrinter().PrintObjCMethodDecl(MD); |
| 677 | |
| 678 | if (MD->getBody()) { |
| 679 | llvm::cerr << '\n'; |
| 680 | MD->getBody()->viewAST(); |
| 681 | llvm::cerr << '\n'; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 687 | ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); } |
| 688 | |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 689 | //===----------------------------------------------------------------------===// |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 690 | /// DeclContextPrinter - Decl and DeclContext Visualization |
| 691 | |
| 692 | namespace { |
| 693 | |
| 694 | class DeclContextPrinter : public ASTConsumer { |
| 695 | llvm::raw_ostream& Out; |
| 696 | public: |
| 697 | DeclContextPrinter() : Out(llvm::errs()) {} |
| 698 | |
Chris Lattner | dacbc5d | 2009-03-28 04:11:33 +0000 | [diff] [blame] | 699 | void HandleTranslationUnit(ASTContext &C) { |
| 700 | PrintDeclContext(C.getTranslationUnitDecl(), 4); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | void PrintDeclContext(const DeclContext* DC, unsigned Indentation); |
| 704 | }; |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 705 | } // end anonymous namespace |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 706 | |
| 707 | void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, |
| 708 | unsigned Indentation) { |
| 709 | // Print DeclContext name. |
Argyrios Kyrtzidis | 9b9ca01 | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 710 | switch (DC->getDeclKind()) { |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 711 | case Decl::TranslationUnit: |
| 712 | Out << "[translation unit] " << DC; |
| 713 | break; |
| 714 | case Decl::Namespace: { |
| 715 | Out << "[namespace] "; |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 716 | const NamespaceDecl* ND = cast<NamespaceDecl>(DC); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 717 | Out << ND->getNameAsString(); |
| 718 | break; |
| 719 | } |
Zhongxing Xu | 867c39e | 2009-01-13 02:41:08 +0000 | [diff] [blame] | 720 | case Decl::Enum: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 721 | const EnumDecl* ED = cast<EnumDecl>(DC); |
Zhongxing Xu | 867c39e | 2009-01-13 02:41:08 +0000 | [diff] [blame] | 722 | if (ED->isDefinition()) |
| 723 | Out << "[enum] "; |
| 724 | else |
| 725 | Out << "<enum> "; |
| 726 | Out << ED->getNameAsString(); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 727 | break; |
Zhongxing Xu | 867c39e | 2009-01-13 02:41:08 +0000 | [diff] [blame] | 728 | } |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 729 | case Decl::Record: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 730 | const RecordDecl* RD = cast<RecordDecl>(DC); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 731 | if (RD->isDefinition()) |
| 732 | Out << "[struct] "; |
| 733 | else |
| 734 | Out << "<struct> "; |
| 735 | Out << RD->getNameAsString(); |
| 736 | break; |
| 737 | } |
| 738 | case Decl::CXXRecord: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 739 | const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 740 | if (RD->isDefinition()) |
| 741 | Out << "[class] "; |
| 742 | else |
| 743 | Out << "<class> "; |
| 744 | Out << RD->getNameAsString() << " " << DC; |
| 745 | break; |
| 746 | } |
| 747 | case Decl::ObjCMethod: |
| 748 | Out << "[objc method]"; |
| 749 | break; |
| 750 | case Decl::ObjCInterface: |
| 751 | Out << "[objc interface]"; |
| 752 | break; |
| 753 | case Decl::ObjCCategory: |
| 754 | Out << "[objc category]"; |
| 755 | break; |
| 756 | case Decl::ObjCProtocol: |
| 757 | Out << "[objc protocol]"; |
| 758 | break; |
| 759 | case Decl::ObjCImplementation: |
| 760 | Out << "[objc implementation]"; |
| 761 | break; |
| 762 | case Decl::ObjCCategoryImpl: |
| 763 | Out << "[objc categoryimpl]"; |
| 764 | break; |
| 765 | case Decl::LinkageSpec: |
| 766 | Out << "[linkage spec]"; |
| 767 | break; |
| 768 | case Decl::Block: |
| 769 | Out << "[block]"; |
| 770 | break; |
| 771 | case Decl::Function: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 772 | const FunctionDecl* FD = cast<FunctionDecl>(DC); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 773 | if (FD->isThisDeclarationADefinition()) |
| 774 | Out << "[function] "; |
| 775 | else |
| 776 | Out << "<function> "; |
| 777 | Out << FD->getNameAsString(); |
Zhongxing Xu | ca04ce4 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 778 | // Print the parameters. |
| 779 | Out << "("; |
| 780 | bool PrintComma = false; |
| 781 | for (FunctionDecl::param_const_iterator I = FD->param_begin(), |
| 782 | E = FD->param_end(); I != E; ++I) { |
| 783 | if (PrintComma) |
| 784 | Out << ", "; |
| 785 | else |
| 786 | PrintComma = true; |
| 787 | Out << (*I)->getNameAsString(); |
| 788 | } |
| 789 | Out << ")"; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 790 | break; |
| 791 | } |
| 792 | case Decl::CXXMethod: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 793 | const CXXMethodDecl* D = cast<CXXMethodDecl>(DC); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 794 | if (D->isOutOfLineDefinition()) |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 795 | Out << "[c++ method] "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 796 | else if (D->isImplicit()) |
| 797 | Out << "(c++ method) "; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 798 | else |
| 799 | Out << "<c++ method> "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 800 | Out << D->getNameAsString(); |
Zhongxing Xu | ca04ce4 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 801 | // Print the parameters. |
| 802 | Out << "("; |
| 803 | bool PrintComma = false; |
| 804 | for (FunctionDecl::param_const_iterator I = D->param_begin(), |
| 805 | E = D->param_end(); I != E; ++I) { |
| 806 | if (PrintComma) |
| 807 | Out << ", "; |
| 808 | else |
| 809 | PrintComma = true; |
| 810 | Out << (*I)->getNameAsString(); |
| 811 | } |
| 812 | Out << ")"; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 813 | |
| 814 | // Check the semantic DeclContext. |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 815 | const DeclContext* SemaDC = D->getDeclContext(); |
| 816 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 817 | if (SemaDC != LexicalDC) |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 818 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 819 | |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 820 | break; |
| 821 | } |
| 822 | case Decl::CXXConstructor: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 823 | const CXXConstructorDecl* D = cast<CXXConstructorDecl>(DC); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 824 | if (D->isOutOfLineDefinition()) |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 825 | Out << "[c++ ctor] "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 826 | else if (D->isImplicit()) |
| 827 | Out << "(c++ ctor) "; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 828 | else |
| 829 | Out << "<c++ ctor> "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 830 | Out << D->getNameAsString(); |
Zhongxing Xu | ca04ce4 | 2009-01-13 06:25:33 +0000 | [diff] [blame] | 831 | // Print the parameters. |
| 832 | Out << "("; |
| 833 | bool PrintComma = false; |
| 834 | for (FunctionDecl::param_const_iterator I = D->param_begin(), |
| 835 | E = D->param_end(); I != E; ++I) { |
| 836 | if (PrintComma) |
| 837 | Out << ", "; |
| 838 | else |
| 839 | PrintComma = true; |
| 840 | Out << (*I)->getNameAsString(); |
| 841 | } |
| 842 | Out << ")"; |
| 843 | |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 844 | // Check the semantic DC. |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 845 | const DeclContext* SemaDC = D->getDeclContext(); |
| 846 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 847 | if (SemaDC != LexicalDC) |
| 848 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 849 | break; |
| 850 | } |
| 851 | case Decl::CXXDestructor: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 852 | const CXXDestructorDecl* D = cast<CXXDestructorDecl>(DC); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 853 | if (D->isOutOfLineDefinition()) |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 854 | Out << "[c++ dtor] "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 855 | else if (D->isImplicit()) |
| 856 | Out << "(c++ dtor) "; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 857 | else |
| 858 | Out << "<c++ dtor> "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 859 | Out << D->getNameAsString(); |
| 860 | // Check the semantic DC. |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 861 | const DeclContext* SemaDC = D->getDeclContext(); |
| 862 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 863 | if (SemaDC != LexicalDC) |
| 864 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 865 | break; |
| 866 | } |
| 867 | case Decl::CXXConversion: { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 868 | const CXXConversionDecl* D = cast<CXXConversionDecl>(DC); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 869 | if (D->isOutOfLineDefinition()) |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 870 | Out << "[c++ conversion] "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 871 | else if (D->isImplicit()) |
| 872 | Out << "(c++ conversion) "; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 873 | else |
| 874 | Out << "<c++ conversion> "; |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 875 | Out << D->getNameAsString(); |
| 876 | // Check the semantic DC. |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 877 | const DeclContext* SemaDC = D->getDeclContext(); |
| 878 | const DeclContext* LexicalDC = D->getLexicalDeclContext(); |
Zhongxing Xu | 2a3eb0e | 2009-01-13 03:26:38 +0000 | [diff] [blame] | 879 | if (SemaDC != LexicalDC) |
| 880 | Out << " [[" << SemaDC << "]]"; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 881 | break; |
| 882 | } |
| 883 | |
| 884 | default: |
| 885 | assert(0 && "a decl that inherits DeclContext isn't handled"); |
| 886 | } |
| 887 | |
| 888 | Out << "\n"; |
| 889 | |
| 890 | // Print decls in the DeclContext. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 891 | // FIXME: Should not use a NULL DeclContext! |
| 892 | ASTContext *Context = 0; |
| 893 | for (DeclContext::decl_iterator I = DC->decls_begin(*Context), |
| 894 | E = DC->decls_end(*Context); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 895 | I != E; ++I) { |
| 896 | for (unsigned i = 0; i < Indentation; ++i) |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 897 | Out << " "; |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 898 | |
| 899 | Decl::Kind DK = I->getKind(); |
| 900 | switch (DK) { |
| 901 | case Decl::Namespace: |
| 902 | case Decl::Enum: |
| 903 | case Decl::Record: |
| 904 | case Decl::CXXRecord: |
| 905 | case Decl::ObjCMethod: |
| 906 | case Decl::ObjCInterface: |
| 907 | case Decl::ObjCCategory: |
| 908 | case Decl::ObjCProtocol: |
| 909 | case Decl::ObjCImplementation: |
| 910 | case Decl::ObjCCategoryImpl: |
| 911 | case Decl::LinkageSpec: |
| 912 | case Decl::Block: |
| 913 | case Decl::Function: |
| 914 | case Decl::CXXMethod: |
| 915 | case Decl::CXXConstructor: |
| 916 | case Decl::CXXDestructor: |
| 917 | case Decl::CXXConversion: |
| 918 | { |
Argyrios Kyrtzidis | 7ad5bf3 | 2009-02-16 14:29:59 +0000 | [diff] [blame] | 919 | DeclContext* DC = cast<DeclContext>(*I); |
Mike Stump | 071e4da | 2009-02-10 20:16:46 +0000 | [diff] [blame] | 920 | PrintDeclContext(DC, Indentation+2); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 921 | break; |
| 922 | } |
| 923 | case Decl::Field: { |
| 924 | FieldDecl* FD = cast<FieldDecl>(*I); |
| 925 | Out << "<field> " << FD->getNameAsString() << "\n"; |
| 926 | break; |
| 927 | } |
| 928 | case Decl::Typedef: { |
| 929 | TypedefDecl* TD = cast<TypedefDecl>(*I); |
| 930 | Out << "<typedef> " << TD->getNameAsString() << "\n"; |
| 931 | break; |
| 932 | } |
| 933 | case Decl::EnumConstant: { |
| 934 | EnumConstantDecl* ECD = cast<EnumConstantDecl>(*I); |
| 935 | Out << "<enum constant> " << ECD->getNameAsString() << "\n"; |
| 936 | break; |
| 937 | } |
| 938 | case Decl::Var: { |
| 939 | VarDecl* VD = cast<VarDecl>(*I); |
| 940 | Out << "<var> " << VD->getNameAsString() << "\n"; |
| 941 | break; |
| 942 | } |
| 943 | case Decl::ImplicitParam: { |
| 944 | ImplicitParamDecl* IPD = cast<ImplicitParamDecl>(*I); |
| 945 | Out << "<implicit parameter> " << IPD->getNameAsString() << "\n"; |
| 946 | break; |
| 947 | } |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 948 | case Decl::ParmVar: { |
| 949 | ParmVarDecl* PVD = cast<ParmVarDecl>(*I); |
| 950 | Out << "<parameter> " << PVD->getNameAsString() << "\n"; |
| 951 | break; |
| 952 | } |
Zhongxing Xu | ba16be9 | 2009-04-05 02:04:38 +0000 | [diff] [blame] | 953 | case Decl::OriginalParmVar: { |
| 954 | OriginalParmVarDecl* OPVD = cast<OriginalParmVarDecl>(*I); |
| 955 | Out << "<original parameter> " << OPVD->getNameAsString() << "\n"; |
| 956 | break; |
| 957 | } |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 958 | case Decl::ObjCProperty: { |
| 959 | ObjCPropertyDecl* OPD = cast<ObjCPropertyDecl>(*I); |
| 960 | Out << "<objc property> " << OPD->getNameAsString() << "\n"; |
| 961 | break; |
| 962 | } |
| 963 | default: |
Zhongxing Xu | ba16be9 | 2009-04-05 02:04:38 +0000 | [diff] [blame] | 964 | fprintf(stderr, "DeclKind: %d \"%s\"\n", DK, I->getDeclKindName()); |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 965 | assert(0 && "decl unhandled"); |
| 966 | } |
| 967 | } |
| 968 | } |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 969 | ASTConsumer *clang::CreateDeclContextPrinter() { |
| 970 | return new DeclContextPrinter(); |
| 971 | } |
| 972 | |
| 973 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 974 | /// InheritanceViewer - C++ Inheritance Visualization |
| 975 | |
| 976 | namespace { |
| 977 | class InheritanceViewer : public ASTConsumer { |
| 978 | const std::string clsname; |
| 979 | public: |
| 980 | InheritanceViewer(const std::string& cname) : clsname(cname) {} |
| 981 | |
Chris Lattner | dacbc5d | 2009-03-28 04:11:33 +0000 | [diff] [blame] | 982 | void HandleTranslationUnit(ASTContext &C) { |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 983 | for (ASTContext::type_iterator I=C.types_begin(),E=C.types_end(); I!=E; ++I) |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 984 | if (RecordType *T = dyn_cast<RecordType>(*I)) { |
| 985 | if (CXXRecordDecl *D = dyn_cast<CXXRecordDecl>(T->getDecl())) { |
| 986 | // FIXME: This lookup needs to be generalized to handle namespaces and |
| 987 | // (when we support them) templates. |
| 988 | if (D->getNameAsString() == clsname) { |
| 989 | D->viewInheritance(C); |
| 990 | } |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | } |
| 994 | }; |
| 995 | } |
| 996 | |
| 997 | ASTConsumer *clang::CreateInheritanceViewer(const std::string& clsname) { |
| 998 | return new InheritanceViewer(clsname); |
| 999 | } |
| 1000 | |
| 1001 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 1002 | // AST Serializer |
| 1003 | |
| 1004 | namespace { |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1005 | |
| 1006 | class ASTSerializer : public ASTConsumer { |
| 1007 | protected: |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 1008 | Diagnostic& Diags; |
Ted Kremenek | c1e9dea | 2008-04-23 16:25:39 +0000 | [diff] [blame] | 1009 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1010 | public: |
Nico Weber | be1eb5c | 2008-08-10 19:20:05 +0000 | [diff] [blame] | 1011 | ASTSerializer(Diagnostic& diags) : Diags(diags) {} |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1012 | }; |
Eli Friedman | d8a65c1 | 2008-06-09 20:02:51 +0000 | [diff] [blame] | 1013 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1014 | class SingleFileSerializer : public ASTSerializer { |
| 1015 | const llvm::sys::Path FName; |
| 1016 | public: |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 1017 | SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags) |
| 1018 | : ASTSerializer(diags), FName(F) {} |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1019 | |
Chris Lattner | dacbc5d | 2009-03-28 04:11:33 +0000 | [diff] [blame] | 1020 | virtual void HandleTranslationUnit(ASTContext &Ctx) { |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 1021 | if (Diags.hasErrorOccurred()) |
| 1022 | return; |
Chris Lattner | 80a0333 | 2009-03-28 03:53:02 +0000 | [diff] [blame] | 1023 | |
| 1024 | // Reserve 256K for bitstream buffer. |
| 1025 | std::vector<unsigned char> Buffer; |
| 1026 | Buffer.reserve(256*1024); |
| 1027 | |
Chris Lattner | 557c5b1 | 2009-03-28 04:27:18 +0000 | [diff] [blame] | 1028 | Ctx.EmitASTBitcodeBuffer(Buffer); |
Chris Lattner | 80a0333 | 2009-03-28 03:53:02 +0000 | [diff] [blame] | 1029 | |
| 1030 | // Write the bits to disk. |
| 1031 | if (FILE* fp = fopen(FName.c_str(),"wb")) { |
| 1032 | fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp); |
| 1033 | fclose(fp); |
| 1034 | } |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1035 | } |
| 1036 | }; |
| 1037 | |
| 1038 | class BuildSerializer : public ASTSerializer { |
| 1039 | llvm::sys::Path EmitDir; |
| 1040 | public: |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 1041 | BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags) |
| 1042 | : ASTSerializer(diags), EmitDir(dir) {} |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1043 | |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 1044 | virtual void HandleTranslationUnit(ASTContext &Ctx); |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1045 | }; |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 1046 | } // end anonymous namespace |
| 1047 | |
| 1048 | |
Chris Lattner | b23ff6b | 2009-03-28 05:44:17 +0000 | [diff] [blame] | 1049 | void BuildSerializer::HandleTranslationUnit(ASTContext &Ctx) { |
| 1050 | if (Diags.hasErrorOccurred()) |
| 1051 | return; |
| 1052 | |
| 1053 | SourceManager& SourceMgr = Ctx.getSourceManager(); |
| 1054 | FileID ID = SourceMgr.getMainFileID(); |
| 1055 | assert(!ID.isInvalid() && "MainFileID not set!"); |
| 1056 | const FileEntry* FE = SourceMgr.getFileEntryForID(ID); |
| 1057 | assert(FE && "No FileEntry for main file."); |
| 1058 | |
| 1059 | // FIXME: This is not portable to Windows. |
| 1060 | // FIXME: This logic should probably be moved elsewhere later. |
| 1061 | |
| 1062 | llvm::sys::Path FName(EmitDir); |
| 1063 | |
| 1064 | std::vector<char> buf; |
| 1065 | buf.reserve(strlen(FE->getName())+100); |
| 1066 | |
| 1067 | sprintf(&buf[0], "dev_%llx", (unsigned long long) FE->getDevice()); |
| 1068 | FName.appendComponent(&buf[0]); |
| 1069 | FName.createDirectoryOnDisk(true); |
| 1070 | if (!FName.canWrite() || !FName.isDirectory()) { |
| 1071 | assert (false && "Could not create 'device' serialization directory."); |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | sprintf(&buf[0], "%s-%llX.ast", FE->getName(), |
| 1076 | (unsigned long long) FE->getInode()); |
| 1077 | FName.appendComponent(&buf[0]); |
| 1078 | |
| 1079 | |
| 1080 | // Reserve 256K for bitstream buffer. |
| 1081 | std::vector<unsigned char> Buffer; |
| 1082 | Buffer.reserve(256*1024); |
| 1083 | |
| 1084 | Ctx.EmitASTBitcodeBuffer(Buffer); |
| 1085 | |
| 1086 | // Write the bits to disk. |
| 1087 | if (FILE* fp = fopen(FName.c_str(),"wb")) { |
| 1088 | fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp); |
| 1089 | fclose(fp); |
| 1090 | } |
| 1091 | |
| 1092 | // Now emit the sources. |
| 1093 | |
| 1094 | } |
| 1095 | |
| 1096 | |
Ted Kremenek | fdfc198 | 2007-12-19 22:24:34 +0000 | [diff] [blame] | 1097 | ASTConsumer* clang::CreateASTSerializer(const std::string& InFile, |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1098 | const std::string& OutputFile, |
Ted Kremenek | e7d07d1 | 2008-06-04 15:55:15 +0000 | [diff] [blame] | 1099 | Diagnostic &Diags) { |
Ted Kremenek | 3910c7c | 2007-12-19 17:25:59 +0000 | [diff] [blame] | 1100 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1101 | if (OutputFile.size()) { |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 1102 | if (InFile == "-") { |
| 1103 | llvm::cerr << |
| 1104 | "error: Cannot use --serialize with -o for source read from STDIN.\n"; |
| 1105 | return NULL; |
| 1106 | } |
| 1107 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1108 | // The user specified an AST-emission directory. Determine if the path |
| 1109 | // is absolute. |
| 1110 | llvm::sys::Path EmitDir(OutputFile); |
| 1111 | |
| 1112 | if (!EmitDir.isAbsolute()) { |
| 1113 | llvm::cerr << |
| 1114 | "error: Output directory for --serialize must be an absolute path.\n"; |
| 1115 | |
| 1116 | return NULL; |
| 1117 | } |
| 1118 | |
| 1119 | // Create the directory if it does not exist. |
| 1120 | EmitDir.createDirectoryOnDisk(true); |
| 1121 | if (!EmitDir.canWrite() || !EmitDir.isDirectory()) { |
| 1122 | llvm::cerr << |
| 1123 | "error: Could not create output directory for --serialize.\n"; |
| 1124 | |
| 1125 | return NULL; |
| 1126 | } |
| 1127 | |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 1128 | // FIXME: We should probably only allow using BuildSerializer when |
| 1129 | // the ASTs come from parsed source files, and not from .ast files. |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 1130 | return new BuildSerializer(EmitDir, Diags); |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | // The user did not specify an output directory for serialized ASTs. |
| 1134 | // Serialize the translation to a single file whose name is the same |
| 1135 | // as the input file with the ".ast" extension appended. |
Ted Kremenek | 63ea863 | 2007-12-19 19:27:38 +0000 | [diff] [blame] | 1136 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 1137 | llvm::sys::Path FName(InFile.c_str()); |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 1138 | FName.appendSuffix("ast"); |
Nico Weber | dae8696 | 2008-08-09 18:32:11 +0000 | [diff] [blame] | 1139 | return new SingleFileSerializer(FName, Diags); |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 1140 | } |