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" |
Ted Kremenek | 77cda50 | 2007-12-18 21:34:28 +0000 | [diff] [blame] | 15 | #include "clang/AST/TranslationUnit.h" |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 16 | #include "clang/Basic/SourceManager.h" |
| 17 | #include "clang/Basic/FileManager.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "clang/AST/AST.h" |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTConsumer.h" |
Ted Kremenek | fddd518 | 2007-08-21 21:42:03 +0000 | [diff] [blame] | 20 | #include "clang/AST/CFG.h" |
Ted Kremenek | cf6e41b | 2007-12-21 21:42:19 +0000 | [diff] [blame] | 21 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 22 | #include "clang/Analysis/Analyses/GRConstants.h" |
Ted Kremenek | 055c275 | 2007-09-06 23:00:42 +0000 | [diff] [blame] | 23 | #include "clang/Analysis/LocalCheckers.h" |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Streams.h" |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 25 | using namespace clang; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 26 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | /// DeclPrinter - Utility class for printing top-level decls. |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 29 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 30 | namespace { |
| 31 | class DeclPrinter { |
| 32 | public: |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 33 | std::ostream& Out; |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 34 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 35 | DeclPrinter(std::ostream* out) : Out(out ? *out : *llvm::cerr.stream()) {} |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 36 | DeclPrinter() : Out(*llvm::cerr.stream()) {} |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 37 | |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 38 | void PrintDecl(Decl *D); |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 39 | void PrintFunctionDeclStart(FunctionDecl *FD); |
| 40 | void PrintTypeDefDecl(TypedefDecl *TD); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 41 | void PrintLinkageSpec(LinkageSpecDecl *LS); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 42 | void PrintObjCMethodDecl(ObjCMethodDecl *OMD); |
| 43 | void PrintObjCImplementationDecl(ObjCImplementationDecl *OID); |
| 44 | void PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID); |
| 45 | void PrintObjCProtocolDecl(ObjCProtocolDecl *PID); |
| 46 | void PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID); |
| 47 | void PrintObjCCategoryDecl(ObjCCategoryDecl *PID); |
| 48 | void PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID); |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 49 | }; |
| 50 | } // end anonymous namespace |
| 51 | |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 52 | void DeclPrinter:: PrintDecl(Decl *D) { |
| 53 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 54 | PrintFunctionDeclStart(FD); |
| 55 | |
| 56 | if (FD->getBody()) { |
| 57 | Out << ' '; |
| 58 | FD->getBody()->printPretty(Out); |
| 59 | Out << '\n'; |
| 60 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 61 | } else if (isa<ObjCMethodDecl>(D)) { |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 62 | // Do nothing, methods definitions are printed in |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 63 | // PrintObjCImplementationDecl. |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 64 | } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { |
| 65 | PrintTypeDefDecl(TD); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 66 | } else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 67 | PrintObjCInterfaceDecl(OID); |
| 68 | } else if (ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(D)) { |
| 69 | PrintObjCProtocolDecl(PID); |
| 70 | } else if (ObjCForwardProtocolDecl *OFPD = |
| 71 | dyn_cast<ObjCForwardProtocolDecl>(D)) { |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 72 | Out << "@protocol "; |
| 73 | for (unsigned i = 0, e = OFPD->getNumForwardDecls(); i != e; ++i) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 74 | const ObjCProtocolDecl *D = OFPD->getForwardProtocolDecl(i); |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 75 | if (i) Out << ", "; |
| 76 | Out << D->getName(); |
| 77 | } |
| 78 | Out << ";\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 79 | } else if (ObjCImplementationDecl *OID = |
| 80 | dyn_cast<ObjCImplementationDecl>(D)) { |
| 81 | PrintObjCImplementationDecl(OID); |
| 82 | } else if (ObjCCategoryImplDecl *OID = |
| 83 | dyn_cast<ObjCCategoryImplDecl>(D)) { |
| 84 | PrintObjCCategoryImplDecl(OID); |
| 85 | } else if (ObjCCategoryDecl *OID = |
| 86 | dyn_cast<ObjCCategoryDecl>(D)) { |
| 87 | PrintObjCCategoryDecl(OID); |
| 88 | } else if (ObjCCompatibleAliasDecl *OID = |
| 89 | dyn_cast<ObjCCompatibleAliasDecl>(D)) { |
| 90 | PrintObjCCompatibleAliasDecl(OID); |
| 91 | } else if (isa<ObjCClassDecl>(D)) { |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 92 | Out << "@class [printing todo]\n"; |
| 93 | } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 94 | Out << "Read top-level tag decl: '" << TD->getName() << "'\n"; |
| 95 | } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) { |
| 96 | Out << "Read top-level variable decl: '" << SD->getName() << "'\n"; |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 97 | } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) { |
| 98 | PrintLinkageSpec(LSD); |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 99 | } else { |
| 100 | assert(0 && "Unknown decl type!"); |
| 101 | } |
| 102 | } |
| 103 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 104 | void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 105 | bool HasBody = FD->getBody(); |
| 106 | |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 107 | Out << '\n'; |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 108 | |
| 109 | switch (FD->getStorageClass()) { |
| 110 | default: assert(0 && "Unknown storage class"); |
| 111 | case FunctionDecl::None: break; |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 112 | case FunctionDecl::Extern: Out << "extern "; break; |
| 113 | case FunctionDecl::Static: Out << "static "; break; |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | if (FD->isInline()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 117 | Out << "inline "; |
Chris Lattner | 70c8b2e | 2007-08-26 04:02:13 +0000 | [diff] [blame] | 118 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 119 | std::string Proto = FD->getName(); |
Chris Lattner | 0d6ca11 | 2007-12-03 21:43:25 +0000 | [diff] [blame] | 120 | const FunctionType *AFT = FD->getType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 0d6ca11 | 2007-12-03 21:43:25 +0000 | [diff] [blame] | 122 | if (const FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(AFT)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 123 | Proto += "("; |
| 124 | for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { |
| 125 | if (i) Proto += ", "; |
| 126 | std::string ParamStr; |
| 127 | if (HasBody) ParamStr = FD->getParamDecl(i)->getName(); |
| 128 | |
| 129 | FT->getArgType(i).getAsStringInternal(ParamStr); |
| 130 | Proto += ParamStr; |
| 131 | } |
| 132 | |
| 133 | if (FT->isVariadic()) { |
| 134 | if (FD->getNumParams()) Proto += ", "; |
| 135 | Proto += "..."; |
| 136 | } |
| 137 | Proto += ")"; |
| 138 | } else { |
| 139 | assert(isa<FunctionTypeNoProto>(AFT)); |
| 140 | Proto += "()"; |
| 141 | } |
| 142 | |
| 143 | AFT->getResultType().getAsStringInternal(Proto); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 144 | Out << Proto; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 145 | |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 146 | if (!FD->getBody()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 147 | Out << ";\n"; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 148 | // Doesn't print the body. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 151 | void DeclPrinter::PrintTypeDefDecl(TypedefDecl *TD) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 152 | std::string S = TD->getName(); |
| 153 | TD->getUnderlyingType().getAsStringInternal(S); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 154 | Out << "typedef " << S << ";\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 157 | void DeclPrinter::PrintLinkageSpec(LinkageSpecDecl *LS) { |
| 158 | const char *l; |
| 159 | if (LS->getLanguage() == LinkageSpecDecl::lang_c) |
| 160 | l = "C"; |
| 161 | else if (LS->getLanguage() == LinkageSpecDecl::lang_cxx) |
| 162 | l = "C++"; |
| 163 | else assert(0 && "unknown language in linkage specification"); |
| 164 | Out << "extern \"" << l << "\" { "; |
| 165 | PrintDecl(LS->getDecl()); |
| 166 | Out << "}\n"; |
| 167 | } |
| 168 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 169 | void DeclPrinter::PrintObjCMethodDecl(ObjCMethodDecl *OMD) { |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 170 | if (OMD->isInstance()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 171 | Out << "\n- "; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 172 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 173 | Out << "\n+ "; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 174 | if (!OMD->getResultType().isNull()) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 175 | Out << '(' << OMD->getResultType().getAsString() << ") "; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 176 | // FIXME: just print original selector name! |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 177 | Out << OMD->getSelector().getName(); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 178 | |
| 179 | for (int i = 0; i < OMD->getNumParams(); i++) { |
| 180 | ParmVarDecl *PDecl = OMD->getParamDecl(i); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 181 | // FIXME: selector is missing here! |
| 182 | Out << " :(" << PDecl->getType().getAsString() << ") " << PDecl->getName(); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 186 | void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) { |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 187 | std::string I = OID->getName(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 188 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 189 | |
| 190 | if (SID) |
| 191 | Out << "@implementation " << I << " : " << SID->getName(); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 192 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 193 | Out << "@implementation " << I; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 194 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 195 | for (ObjCImplementationDecl::instmeth_iterator I = OID->instmeth_begin(), |
Chris Lattner | ab4c4d5 | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 196 | E = OID->instmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 197 | ObjCMethodDecl *OMD = *I; |
| 198 | PrintObjCMethodDecl(OMD); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 199 | if (OMD->getBody()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 200 | Out << ' '; |
| 201 | OMD->getBody()->printPretty(Out); |
| 202 | Out << '\n'; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 206 | for (ObjCImplementationDecl::classmeth_iterator I = OID->classmeth_begin(), |
Chris Lattner | ab4c4d5 | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 207 | E = OID->classmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 208 | ObjCMethodDecl *OMD = *I; |
| 209 | PrintObjCMethodDecl(OMD); |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 210 | if (OMD->getBody()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 211 | Out << ' '; |
| 212 | OMD->getBody()->printPretty(Out); |
| 213 | Out << '\n'; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 217 | Out << "@end\n"; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 221 | void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) { |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 222 | std::string I = OID->getName(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 223 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 224 | |
| 225 | if (SID) |
| 226 | Out << "@interface " << I << " : " << SID->getName(); |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 227 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 228 | Out << "@interface " << I; |
| 229 | |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 230 | // Protocols? |
| 231 | int count = OID->getNumIntfRefProtocols(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 232 | |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 233 | if (count > 0) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 234 | ObjCProtocolDecl **refProtocols = OID->getReferencedProtocols(); |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 235 | for (int i = 0; i < count; i++) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 236 | Out << (i == 0 ? '<' : ',') << refProtocols[i]->getName(); |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 237 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 238 | |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 239 | if (count > 0) |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 240 | Out << ">\n"; |
Fariborz Jahanian | e37882a | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 241 | else |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 242 | Out << '\n'; |
Fariborz Jahanian | edcfb42 | 2007-10-26 16:29:12 +0000 | [diff] [blame] | 243 | |
Chris Lattner | be6df08 | 2007-12-12 07:56:42 +0000 | [diff] [blame] | 244 | if (OID->getNumInstanceVariables() > 0) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 245 | Out << '{'; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 246 | for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(), |
Chris Lattner | be6df08 | 2007-12-12 07:56:42 +0000 | [diff] [blame] | 247 | E = OID->ivar_end(); I != E; ++I) { |
| 248 | Out << '\t' << (*I)->getType().getAsString() |
| 249 | << ' ' << (*I)->getName() << ";\n"; |
Fariborz Jahanian | edcfb42 | 2007-10-26 16:29:12 +0000 | [diff] [blame] | 250 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 251 | Out << "}\n"; |
Fariborz Jahanian | edcfb42 | 2007-10-26 16:29:12 +0000 | [diff] [blame] | 252 | } |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 253 | |
| 254 | int NumProperties = OID->getNumPropertyDecl(); |
| 255 | if (NumProperties > 0) { |
| 256 | for (int i = 0; i < NumProperties; i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 257 | ObjCPropertyDecl *PDecl = OID->getPropertyDecl()[i]; |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 258 | Out << "@property"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 259 | if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) { |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 260 | bool first = true; |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 261 | Out << " ("; |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 262 | if (PDecl->getPropertyAttributes() & |
| 263 | ObjCPropertyDecl::OBJC_PR_readonly) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 264 | Out << (first ? ' ' : ',') << "readonly"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 265 | first = false; |
| 266 | } |
| 267 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 268 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 269 | Out << (first ? ' ' : ',') << "getter = " |
| 270 | << PDecl->getGetterName()->getName(); |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 271 | first = false; |
| 272 | } |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 273 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 274 | Out << (first ? ' ' : ',') << "setter = " |
| 275 | << PDecl->getSetterName()->getName(); |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 276 | first = false; |
| 277 | } |
| 278 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 279 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 280 | Out << (first ? ' ' : ',') << "assign"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 281 | first = false; |
| 282 | } |
| 283 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 284 | if (PDecl->getPropertyAttributes() & |
| 285 | ObjCPropertyDecl::OBJC_PR_readwrite) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 286 | Out << (first ? ' ' : ',') << "readwrite"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 287 | first = false; |
| 288 | } |
| 289 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 290 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 291 | Out << (first ? ' ' : ',') << "retain"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 292 | first = false; |
| 293 | } |
| 294 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 295 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 296 | Out << (first ? ' ' : ',') << "copy"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 297 | first = false; |
| 298 | } |
| 299 | |
Chris Lattner | 4b1daf0 | 2008-01-10 01:43:14 +0000 | [diff] [blame] | 300 | if (PDecl->getPropertyAttributes() & |
| 301 | ObjCPropertyDecl::OBJC_PR_nonatomic) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 302 | Out << (first ? ' ' : ',') << "nonatomic"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 303 | first = false; |
| 304 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 305 | Out << " )"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 306 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 308 | ObjCIvarDecl **IDecl = PDecl->getPropertyDecls(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 309 | |
| 310 | Out << ' ' << IDecl[0]->getType().getAsString() |
| 311 | << ' ' << IDecl[0]->getName(); |
| 312 | |
| 313 | for (int j = 1; j < PDecl->getNumPropertyDecls(); j++) |
| 314 | Out << ", " << IDecl[j]->getName(); |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 315 | |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 316 | Out << ";\n"; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 319 | |
| 320 | Out << "@end\n"; |
Steve Naroff | 2bd42fa | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 321 | // FIXME: implement the rest... |
| 322 | } |
| 323 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 324 | void DeclPrinter::PrintObjCProtocolDecl(ObjCProtocolDecl *PID) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 325 | Out << "@protocol " << PID->getName() << '\n'; |
Fariborz Jahanian | ab0aeb0 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 326 | // FIXME: implement the rest... |
| 327 | } |
| 328 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 329 | void DeclPrinter::PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 330 | Out << "@implementation " |
| 331 | << PID->getClassInterface()->getName() |
| 332 | << '(' << PID->getName() << ");\n"; |
| 333 | |
Fariborz Jahanian | ab0aeb0 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 334 | // FIXME: implement the rest... |
| 335 | } |
| 336 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 337 | void DeclPrinter::PrintObjCCategoryDecl(ObjCCategoryDecl *PID) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 338 | Out << "@interface " |
| 339 | << PID->getClassInterface()->getName() |
| 340 | << '(' << PID->getName() << ");\n"; |
Fariborz Jahanian | ab0aeb0 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 341 | // FIXME: implement the rest... |
| 342 | } |
| 343 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 344 | void DeclPrinter::PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 345 | Out << "@compatibility_alias " << AID->getName() |
| 346 | << ' ' << AID->getClassInterface()->getName() << ";\n"; |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 349 | //===----------------------------------------------------------------------===// |
| 350 | /// ASTPrinter - Pretty-printer of ASTs |
| 351 | |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 352 | namespace { |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 353 | class ASTPrinter : public ASTConsumer, public DeclPrinter { |
| 354 | public: |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 355 | ASTPrinter(std::ostream* o = NULL) : DeclPrinter(o) {} |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 356 | |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 357 | virtual void HandleTopLevelDecl(Decl *D) { |
Chris Lattner | ef5a85d | 2008-01-02 21:04:16 +0000 | [diff] [blame] | 358 | PrintDecl(D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 359 | } |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 360 | }; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 361 | } |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 362 | |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 363 | ASTConsumer *clang::CreateASTPrinter(std::ostream* out) { |
| 364 | return new ASTPrinter(out); |
| 365 | } |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 366 | |
| 367 | //===----------------------------------------------------------------------===// |
| 368 | /// ASTDumper - Low-level dumper of ASTs |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 369 | |
| 370 | namespace { |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 371 | class ASTDumper : public ASTConsumer, public DeclPrinter { |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 372 | SourceManager *SM; |
| 373 | public: |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 374 | ASTDumper() : DeclPrinter() {} |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 375 | |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 376 | void Initialize(ASTContext &Context) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 377 | SM = &Context.getSourceManager(); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 378 | } |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 379 | |
| 380 | virtual void HandleTopLevelDecl(Decl *D) { |
| 381 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 382 | PrintFunctionDeclStart(FD); |
| 383 | |
| 384 | if (FD->getBody()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 385 | Out << '\n'; |
| 386 | // FIXME: convert dumper to use std::ostream? |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 387 | FD->getBody()->dumpAll(*SM); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 388 | Out << '\n'; |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 389 | } |
| 390 | } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { |
| 391 | PrintTypeDefDecl(TD); |
| 392 | } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 393 | Out << "Read top-level variable decl: '" << SD->getName() << "'\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 394 | } else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 395 | Out << "Read objc interface '" << OID->getName() << "'\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 396 | } else if (ObjCProtocolDecl *OPD = dyn_cast<ObjCProtocolDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 397 | Out << "Read objc protocol '" << OPD->getName() << "'\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 398 | } else if (ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 399 | Out << "Read objc category '" << OCD->getName() << "'\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 400 | } else if (isa<ObjCForwardProtocolDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 401 | Out << "Read objc fwd protocol decl\n"; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 402 | } else if (isa<ObjCClassDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 403 | Out << "Read objc fwd class decl\n"; |
Chris Lattner | 9fa5e65 | 2007-10-06 18:52:10 +0000 | [diff] [blame] | 404 | } else { |
| 405 | assert(0 && "Unknown decl type!"); |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | }; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Chris Lattner | 3d4997d | 2007-09-15 23:02:28 +0000 | [diff] [blame] | 411 | ASTConsumer *clang::CreateASTDumper() { return new ASTDumper(); } |
| 412 | |
Ted Kremenek | 1b5a4bd | 2007-11-27 21:46:50 +0000 | [diff] [blame] | 413 | //===----------------------------------------------------------------------===// |
| 414 | /// ASTViewer - AST Visualization |
| 415 | |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 416 | namespace { |
| 417 | class ASTViewer : public ASTConsumer { |
| 418 | SourceManager *SM; |
| 419 | public: |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 420 | void Initialize(ASTContext &Context) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 421 | SM = &Context.getSourceManager(); |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | virtual void HandleTopLevelDecl(Decl *D) { |
| 425 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 426 | DeclPrinter().PrintFunctionDeclStart(FD); |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 427 | |
| 428 | if (FD->getBody()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 429 | llvm::cerr << '\n'; |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 430 | FD->getBody()->viewAST(); |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 431 | llvm::cerr << '\n'; |
Ted Kremenek | 80de08f | 2007-09-19 21:29:43 +0000 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | } |
| 435 | }; |
| 436 | } |
| 437 | |
| 438 | ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); } |
| 439 | |
| 440 | |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 441 | //===----------------------------------------------------------------------===// |
| 442 | // CFGVisitor & VisitCFGs - Boilerplate interface and logic to visit |
| 443 | // the CFGs for all function definitions. |
| 444 | |
| 445 | namespace { |
| 446 | |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 447 | class CFGVisitor : public ASTConsumer { |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 448 | public: |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 449 | // CFG Visitor interface to be implemented by subclass. |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 450 | virtual void VisitCFG(CFG& C, FunctionDecl& FD) = 0; |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 451 | virtual bool printFuncDeclStart() { return true; } |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 452 | |
| 453 | virtual void HandleTopLevelDecl(Decl *D); |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | } // end anonymous namespace |
| 457 | |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 458 | void CFGVisitor::HandleTopLevelDecl(Decl *D) { |
| 459 | FunctionDecl *FD = dyn_cast<FunctionDecl>(D); |
| 460 | if (!FD || !FD->getBody()) |
| 461 | return; |
| 462 | |
| 463 | if (printFuncDeclStart()) { |
Ted Kremenek | ea75c55 | 2007-11-28 21:32:21 +0000 | [diff] [blame] | 464 | DeclPrinter().PrintFunctionDeclStart(FD); |
| 465 | llvm::cerr << '\n'; |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 466 | } |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 467 | |
Ted Kremenek | 1225966 | 2007-09-17 17:10:02 +0000 | [diff] [blame] | 468 | CFG *C = CFG::buildCFG(FD->getBody()); |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 469 | VisitCFG(*C, *FD); |
Ted Kremenek | 1225966 | 2007-09-17 17:10:02 +0000 | [diff] [blame] | 470 | delete C; |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | //===----------------------------------------------------------------------===// |
| 474 | // DumpCFGs - Dump CFGs to stderr or visualize with Graphviz |
| 475 | |
| 476 | namespace { |
| 477 | class CFGDumper : public CFGVisitor { |
| 478 | const bool UseGraphviz; |
| 479 | public: |
| 480 | CFGDumper(bool use_graphviz) : UseGraphviz(use_graphviz) {} |
| 481 | |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 482 | virtual void VisitCFG(CFG& C, FunctionDecl&) { |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 483 | if (UseGraphviz) |
| 484 | C.viewCFG(); |
| 485 | else |
| 486 | C.dump(); |
| 487 | } |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 488 | }; |
| 489 | } // end anonymous namespace |
| 490 | |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 491 | ASTConsumer *clang::CreateCFGDumper(bool ViewGraphs) { |
| 492 | return new CFGDumper(ViewGraphs); |
Ted Kremenek | fddd518 | 2007-08-21 21:42:03 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 495 | //===----------------------------------------------------------------------===// |
| 496 | // AnalyzeLiveVariables - perform live variable analysis and dump results |
| 497 | |
| 498 | namespace { |
| 499 | class LivenessVisitor : public CFGVisitor { |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 500 | SourceManager *SM; |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 501 | public: |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 502 | virtual void Initialize(ASTContext &Context) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 503 | SM = &Context.getSourceManager(); |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 506 | virtual void VisitCFG(CFG& C, FunctionDecl& FD) { |
| 507 | LiveVariables L(C, FD); |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 508 | L.runOnCFG(C); |
Ted Kremenek | fdd225e | 2007-09-25 04:31:27 +0000 | [diff] [blame] | 509 | L.dumpBlockLiveness(*SM); |
Ted Kremenek | e4e6334 | 2007-09-06 00:17:54 +0000 | [diff] [blame] | 510 | } |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 511 | }; |
| 512 | } // end anonymous namespace |
| 513 | |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 514 | ASTConsumer *clang::CreateLiveVarAnalyzer() { |
| 515 | return new LivenessVisitor(); |
Ted Kremenek | e4e6334 | 2007-09-06 00:17:54 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 518 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 519 | // DeadStores - run checker to locate dead stores in a function |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 520 | |
| 521 | namespace { |
| 522 | class DeadStoreVisitor : public CFGVisitor { |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 523 | Diagnostic &Diags; |
| 524 | ASTContext *Ctx; |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 525 | public: |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 526 | DeadStoreVisitor(Diagnostic &diags) : Diags(diags) {} |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 527 | virtual void Initialize(ASTContext &Context) { |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 528 | Ctx = &Context; |
| 529 | } |
| 530 | |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 531 | virtual void VisitCFG(CFG& C, FunctionDecl& FD) { |
| 532 | CheckDeadStores(C, FD, *Ctx, Diags); |
| 533 | } |
| 534 | |
Ted Kremenek | 567a7e6 | 2007-09-07 23:54:15 +0000 | [diff] [blame] | 535 | virtual bool printFuncDeclStart() { return false; } |
Ted Kremenek | 74bf2c9 | 2007-09-07 23:47:56 +0000 | [diff] [blame] | 536 | }; |
| 537 | } // end anonymous namespace |
| 538 | |
Chris Lattner | c0508f9 | 2007-09-15 23:21:08 +0000 | [diff] [blame] | 539 | ASTConsumer *clang::CreateDeadStoreChecker(Diagnostic &Diags) { |
| 540 | return new DeadStoreVisitor(Diags); |
Ted Kremenek | 055c275 | 2007-09-06 23:00:42 +0000 | [diff] [blame] | 541 | } |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 542 | |
| 543 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 544 | // Unitialized Values - run checker to flag potential uses of uninitalized |
| 545 | // variables. |
| 546 | |
| 547 | namespace { |
| 548 | class UninitValsVisitor : public CFGVisitor { |
| 549 | Diagnostic &Diags; |
| 550 | ASTContext *Ctx; |
| 551 | public: |
| 552 | UninitValsVisitor(Diagnostic &diags) : Diags(diags) {} |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 553 | virtual void Initialize(ASTContext &Context) { |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 554 | Ctx = &Context; |
| 555 | } |
| 556 | |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 557 | virtual void VisitCFG(CFG& C, FunctionDecl&) { |
| 558 | CheckUninitializedValues(C, *Ctx, Diags); |
| 559 | } |
| 560 | |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 561 | virtual bool printFuncDeclStart() { return false; } |
| 562 | }; |
| 563 | } // end anonymous namespace |
| 564 | |
| 565 | ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) { |
| 566 | return new UninitValsVisitor(Diags); |
| 567 | } |
| 568 | |
| 569 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 570 | // GRConstants - Perform intra-procedural, path-sensitive constant propagation. |
Ted Kremenek | e603df4 | 2008-01-08 18:04:06 +0000 | [diff] [blame] | 571 | |
| 572 | namespace { |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 573 | class GRConstantsVisitor : public CFGVisitor { |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 574 | ASTContext* Ctx; |
Ted Kremenek | e603df4 | 2008-01-08 18:04:06 +0000 | [diff] [blame] | 575 | public: |
Ted Kremenek | e603df4 | 2008-01-08 18:04:06 +0000 | [diff] [blame] | 576 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 577 | virtual void Initialize(ASTContext &Context) { Ctx = &Context; } |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 578 | virtual void VisitCFG(CFG& C, FunctionDecl&); |
Ted Kremenek | e603df4 | 2008-01-08 18:04:06 +0000 | [diff] [blame] | 579 | }; |
| 580 | } // end anonymous namespace |
| 581 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 582 | ASTConsumer* clang::CreateGRConstants() { |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 583 | return new GRConstantsVisitor(); |
Ted Kremenek | e603df4 | 2008-01-08 18:04:06 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 586 | void GRConstantsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) { |
| 587 | RunGRConstants(C, FD, *Ctx); |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Ted Kremenek | e603df4 | 2008-01-08 18:04:06 +0000 | [diff] [blame] | 590 | //===----------------------------------------------------------------------===// |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 591 | // LLVM Emitter |
| 592 | |
| 593 | #include "clang/Basic/Diagnostic.h" |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 594 | #include "clang/Basic/TargetInfo.h" |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 595 | #include "clang/CodeGen/ModuleBuilder.h" |
| 596 | #include "llvm/Module.h" |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 597 | #include "llvm/Target/TargetData.h" |
| 598 | #include "llvm/Target/TargetMachine.h" |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 599 | #include "llvm/Bitcode/ReaderWriter.h" |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 600 | |
| 601 | namespace { |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 602 | class CodeGenerator : public ASTConsumer { |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 603 | Diagnostic &Diags; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 604 | const llvm::TargetData *TD; |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 605 | ASTContext *Ctx; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 606 | const LangOptions &Features; |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 607 | protected: |
Chris Lattner | e66b65c | 2008-02-06 01:42:25 +0000 | [diff] [blame^] | 608 | llvm::Module *&M; |
Chris Lattner | a36c486 | 2007-11-13 18:16:41 +0000 | [diff] [blame] | 609 | CodeGen::CodeGenModule *Builder; |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 610 | public: |
Chris Lattner | e66b65c | 2008-02-06 01:42:25 +0000 | [diff] [blame^] | 611 | CodeGenerator(Diagnostic &diags, const LangOptions &LO, |
| 612 | llvm::Module *&DestModule) |
| 613 | : Diags(diags), Features(LO), M(DestModule) {} |
| 614 | |
| 615 | ~CodeGenerator() { |
| 616 | CodeGen::Terminate(Builder); |
| 617 | } |
| 618 | |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 619 | virtual void Initialize(ASTContext &Context) { |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 620 | Ctx = &Context; |
Chris Lattner | e66b65c | 2008-02-06 01:42:25 +0000 | [diff] [blame^] | 621 | |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 622 | M->setTargetTriple(Ctx->Target.getTargetTriple()); |
Chris Lattner | 0404cd8 | 2007-12-13 17:34:31 +0000 | [diff] [blame] | 623 | M->setDataLayout(Ctx->Target.getTargetDescription()); |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 624 | TD = new llvm::TargetData(Ctx->Target.getTargetDescription()); |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 625 | Builder = CodeGen::Init(Context, Features, *M, *TD, Diags); |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | virtual void HandleTopLevelDecl(Decl *D) { |
| 629 | // If an error occurred, stop code generation, but continue parsing and |
| 630 | // semantic analysis (to ensure all warnings and errors are emitted). |
| 631 | if (Diags.hasErrorOccurred()) |
| 632 | return; |
| 633 | |
| 634 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 635 | CodeGen::CodeGenFunction(Builder, FD); |
| 636 | } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) { |
| 637 | CodeGen::CodeGenGlobalVar(Builder, FVD); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 638 | } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) { |
| 639 | CodeGen::CodeGenLinkageSpec(Builder, LSD); |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 640 | } else { |
Chris Lattner | d86e6bc | 2008-02-05 08:06:13 +0000 | [diff] [blame] | 641 | CodeGen::CodeGenTypeDecl(Builder, cast<TypeDecl>(D)); |
Chris Lattner | 580980b | 2007-09-16 19:46:59 +0000 | [diff] [blame] | 642 | } |
| 643 | } |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 644 | }; |
| 645 | } |
| 646 | |
Chris Lattner | e66b65c | 2008-02-06 01:42:25 +0000 | [diff] [blame^] | 647 | ASTConsumer *clang::CreateLLVMCodeGen(Diagnostic &Diags, |
| 648 | const LangOptions &Features, |
| 649 | llvm::Module *&DestModule) { |
| 650 | return new CodeGenerator(Diags, Features, DestModule); |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 653 | //===----------------------------------------------------------------------===// |
| 654 | // AST Serializer |
| 655 | |
| 656 | namespace { |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 657 | |
| 658 | class ASTSerializer : public ASTConsumer { |
| 659 | protected: |
| 660 | Diagnostic &Diags; |
| 661 | TranslationUnit TU; |
| 662 | public: |
| 663 | ASTSerializer(Diagnostic& diags, const LangOptions& LO) |
| 664 | : Diags(diags), TU(LO) {} |
| 665 | |
| 666 | virtual void Initialize(ASTContext &Context) { |
| 667 | TU.setContext(&Context); |
| 668 | } |
| 669 | |
| 670 | virtual void HandleTopLevelDecl(Decl *D) { |
| 671 | if (Diags.hasErrorOccurred()) |
| 672 | return; |
| 673 | |
| 674 | TU.AddTopLevelDecl(D); |
| 675 | } |
| 676 | }; |
| 677 | |
| 678 | class SingleFileSerializer : public ASTSerializer { |
| 679 | const llvm::sys::Path FName; |
| 680 | public: |
| 681 | SingleFileSerializer(const llvm::sys::Path& F, Diagnostic &diags, |
| 682 | const LangOptions &LO) |
| 683 | : ASTSerializer(diags,LO), FName(F) {} |
| 684 | |
| 685 | ~SingleFileSerializer() { |
| 686 | EmitASTBitcodeFile(TU,FName); |
| 687 | } |
| 688 | }; |
| 689 | |
| 690 | class BuildSerializer : public ASTSerializer { |
| 691 | llvm::sys::Path EmitDir; |
| 692 | public: |
| 693 | BuildSerializer(const llvm::sys::Path& dir, Diagnostic &diags, |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 694 | const LangOptions &LO) |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 695 | : ASTSerializer(diags,LO), EmitDir(dir) {} |
| 696 | |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 697 | ~BuildSerializer() { |
| 698 | SourceManager& SourceMgr = TU.getASTContext()->getSourceManager(); |
| 699 | unsigned ID = SourceMgr.getMainFileID(); |
| 700 | assert (ID && "MainFileID not set!"); |
| 701 | const FileEntry* FE = SourceMgr.getFileEntryForID(ID); |
| 702 | assert (FE && "No FileEntry for main file."); |
| 703 | |
| 704 | // FIXME: This is not portable to Windows. |
| 705 | // FIXME: This logic should probably be moved elsewhere later. |
| 706 | |
Ted Kremenek | ee53364 | 2007-12-20 19:47:16 +0000 | [diff] [blame] | 707 | llvm::sys::Path FName(EmitDir); |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 708 | |
| 709 | std::vector<char> buf; |
| 710 | buf.reserve(strlen(FE->getName())+100); |
| 711 | |
| 712 | sprintf(&buf[0], "dev_%llx", (uint64_t) FE->getDevice()); |
Ted Kremenek | ee53364 | 2007-12-20 19:47:16 +0000 | [diff] [blame] | 713 | FName.appendComponent(&buf[0]); |
| 714 | FName.createDirectoryOnDisk(true); |
| 715 | if (!FName.canWrite() || !FName.isDirectory()) { |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 716 | assert (false && "Could not create 'device' serialization directory."); |
| 717 | return; |
| 718 | } |
Ted Kremenek | ee53364 | 2007-12-20 19:47:16 +0000 | [diff] [blame] | 719 | |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 720 | sprintf(&buf[0], "%s-%llX.ast", FE->getName(), (uint64_t) FE->getInode()); |
Ted Kremenek | ee53364 | 2007-12-20 19:47:16 +0000 | [diff] [blame] | 721 | FName.appendComponent(&buf[0]); |
| 722 | EmitASTBitcodeFile(TU,FName); |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 723 | |
Ted Kremenek | ee53364 | 2007-12-20 19:47:16 +0000 | [diff] [blame] | 724 | // Now emit the sources. |
| 725 | |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 726 | } |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 727 | }; |
| 728 | |
| 729 | |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 730 | } // end anonymous namespace |
| 731 | |
| 732 | |
Ted Kremenek | fdfc198 | 2007-12-19 22:24:34 +0000 | [diff] [blame] | 733 | ASTConsumer* clang::CreateASTSerializer(const std::string& InFile, |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 734 | const std::string& OutputFile, |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 735 | Diagnostic &Diags, |
| 736 | const LangOptions &Features) { |
Ted Kremenek | 3910c7c | 2007-12-19 17:25:59 +0000 | [diff] [blame] | 737 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 738 | if (OutputFile.size()) { |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 739 | if (InFile == "-") { |
| 740 | llvm::cerr << |
| 741 | "error: Cannot use --serialize with -o for source read from STDIN.\n"; |
| 742 | return NULL; |
| 743 | } |
| 744 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 745 | // The user specified an AST-emission directory. Determine if the path |
| 746 | // is absolute. |
| 747 | llvm::sys::Path EmitDir(OutputFile); |
| 748 | |
| 749 | if (!EmitDir.isAbsolute()) { |
| 750 | llvm::cerr << |
| 751 | "error: Output directory for --serialize must be an absolute path.\n"; |
| 752 | |
| 753 | return NULL; |
| 754 | } |
| 755 | |
| 756 | // Create the directory if it does not exist. |
| 757 | EmitDir.createDirectoryOnDisk(true); |
| 758 | if (!EmitDir.canWrite() || !EmitDir.isDirectory()) { |
| 759 | llvm::cerr << |
| 760 | "error: Could not create output directory for --serialize.\n"; |
| 761 | |
| 762 | return NULL; |
| 763 | } |
| 764 | |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 765 | // FIXME: We should probably only allow using BuildSerializer when |
| 766 | // the ASTs come from parsed source files, and not from .ast files. |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 767 | return new BuildSerializer(EmitDir, Diags, Features); |
| 768 | } |
| 769 | |
| 770 | // The user did not specify an output directory for serialized ASTs. |
| 771 | // Serialize the translation to a single file whose name is the same |
| 772 | // as the input file with the ".ast" extension appended. |
Ted Kremenek | 63ea863 | 2007-12-19 19:27:38 +0000 | [diff] [blame] | 773 | |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 774 | llvm::sys::Path FName(InFile.c_str()); |
Ted Kremenek | 5411772 | 2007-12-20 00:34:58 +0000 | [diff] [blame] | 775 | FName.appendSuffix("ast"); |
Ted Kremenek | f06c928 | 2007-12-19 23:49:37 +0000 | [diff] [blame] | 776 | return new SingleFileSerializer(FName, Diags, Features); |
Ted Kremenek | a1fa3a1 | 2007-12-13 00:37:31 +0000 | [diff] [blame] | 777 | } |