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