Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 1 | //===--- FrontendAction.cpp -----------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/FrontendAction.h" |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTConsumer.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 12 | #include "clang/AST/ASTContext.h" |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame^] | 13 | #include "clang/AST/DeclGroup.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 14 | #include "clang/Lex/HeaderSearch.h" |
| 15 | #include "clang/Lex/Preprocessor.h" |
| 16 | #include "clang/Frontend/ASTUnit.h" |
| 17 | #include "clang/Frontend/CompilerInstance.h" |
| 18 | #include "clang/Frontend/FrontendDiagnostic.h" |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame^] | 19 | #include "clang/Frontend/FrontendPluginRegistry.h" |
| 20 | #include "clang/Frontend/MultiplexConsumer.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 21 | #include "clang/Parse/ParseAST.h" |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 22 | #include "clang/Serialization/ASTDeserializationListener.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryBuffer.h" |
| 24 | #include "llvm/Support/Timer.h" |
| 25 | #include "llvm/Support/ErrorHandling.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
| 27 | using namespace clang; |
| 28 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | |
| 31 | /// \brief Dumps deserialized declarations. |
| 32 | class DeserializedDeclsDumper : public ASTDeserializationListener { |
| 33 | ASTDeserializationListener *Previous; |
| 34 | |
| 35 | public: |
| 36 | DeserializedDeclsDumper(ASTDeserializationListener *Previous) |
| 37 | : Previous(Previous) { } |
| 38 | |
| 39 | virtual void DeclRead(serialization::DeclID ID, const Decl *D) { |
| 40 | llvm::outs() << "PCH DECL: " << D->getDeclKindName(); |
| 41 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
| 42 | llvm::outs() << " - " << ND->getNameAsString(); |
| 43 | llvm::outs() << "\n"; |
| 44 | |
| 45 | if (Previous) |
| 46 | Previous->DeclRead(ID, D); |
| 47 | } |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 50 | /// \brief Checks deserialized declarations and emits error if a name |
| 51 | /// matches one given in command-line using -error-on-deserialized-decl. |
| 52 | class DeserializedDeclsChecker : public ASTDeserializationListener { |
| 53 | ASTContext &Ctx; |
| 54 | std::set<std::string> NamesToCheck; |
| 55 | ASTDeserializationListener *Previous; |
| 56 | |
| 57 | public: |
| 58 | DeserializedDeclsChecker(ASTContext &Ctx, |
| 59 | const std::set<std::string> &NamesToCheck, |
| 60 | ASTDeserializationListener *Previous) |
| 61 | : Ctx(Ctx), NamesToCheck(NamesToCheck), Previous(Previous) { } |
| 62 | |
| 63 | virtual void DeclRead(serialization::DeclID ID, const Decl *D) { |
| 64 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
| 65 | if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) { |
| 66 | unsigned DiagID |
| 67 | = Ctx.getDiagnostics().getCustomDiagID(Diagnostic::Error, |
| 68 | "%0 was deserialized"); |
| 69 | Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID) |
| 70 | << ND->getNameAsString(); |
| 71 | } |
| 72 | |
| 73 | if (Previous) |
| 74 | Previous->DeclRead(ID, D); |
| 75 | } |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 78 | } // end anonymous namespace |
| 79 | |
Kovarththanan Rajaratnam | f79bafa | 2009-11-29 09:57:35 +0000 | [diff] [blame] | 80 | FrontendAction::FrontendAction() : Instance(0) {} |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 81 | |
| 82 | FrontendAction::~FrontendAction() {} |
| 83 | |
Daniel Dunbar | 685ac66 | 2010-06-07 23:25:49 +0000 | [diff] [blame] | 84 | void FrontendAction::setCurrentFile(llvm::StringRef Value, InputKind Kind, |
| 85 | ASTUnit *AST) { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 86 | CurrentFile = Value; |
Daniel Dunbar | 685ac66 | 2010-06-07 23:25:49 +0000 | [diff] [blame] | 87 | CurrentFileKind = Kind; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 88 | CurrentASTUnit.reset(AST); |
| 89 | } |
| 90 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame^] | 91 | ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, |
| 92 | llvm::StringRef InFile) { |
| 93 | ASTConsumer* Consumer = CreateASTConsumer(CI, InFile); |
| 94 | if (!Consumer) |
| 95 | return 0; |
| 96 | |
| 97 | if (CI.getFrontendOpts().AddPluginActions.size() == 0) |
| 98 | return Consumer; |
| 99 | |
| 100 | // Make sure the non-plugin consumer is first, so that plugins can't |
| 101 | // modifiy the AST. |
| 102 | std::vector<ASTConsumer*> Consumers(1, Consumer); |
| 103 | |
| 104 | for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); |
| 105 | i != e; ++i) { |
| 106 | // This is O(|plugins| * |add_plugins|), but since both numbers are |
| 107 | // way below 50 in practice, that's ok. |
| 108 | for (FrontendPluginRegistry::iterator |
| 109 | it = FrontendPluginRegistry::begin(), |
| 110 | ie = FrontendPluginRegistry::end(); |
| 111 | it != ie; ++it) { |
| 112 | if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { |
| 113 | llvm::OwningPtr<PluginASTAction> P(it->instantiate()); |
| 114 | FrontendAction* c = P.get(); |
| 115 | if (P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs)) |
| 116 | Consumers.push_back(c->CreateASTConsumer(CI, InFile)); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return new MultiplexConsumer(Consumers); |
| 122 | } |
| 123 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 124 | bool FrontendAction::BeginSourceFile(CompilerInstance &CI, |
| 125 | llvm::StringRef Filename, |
Daniel Dunbar | d3598a6 | 2010-06-07 23:23:06 +0000 | [diff] [blame] | 126 | InputKind InputKind) { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 127 | assert(!Instance && "Already processing a source file!"); |
| 128 | assert(!Filename.empty() && "Unexpected empty filename!"); |
Daniel Dunbar | 685ac66 | 2010-06-07 23:25:49 +0000 | [diff] [blame] | 129 | setCurrentFile(Filename, InputKind); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 130 | setCompilerInstance(&CI); |
| 131 | |
| 132 | // AST files follow a very different path, since they share objects via the |
| 133 | // AST unit. |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 134 | if (InputKind == IK_AST) { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 135 | assert(!usesPreprocessorOnly() && |
| 136 | "Attempt to pass AST file to preprocessor only action!"); |
Daniel Dunbar | eb58d83 | 2010-06-07 23:24:43 +0000 | [diff] [blame] | 137 | assert(hasASTFileSupport() && |
| 138 | "This action does not have AST file support!"); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | 2801977 | 2010-04-05 23:52:57 +0000 | [diff] [blame] | 140 | llvm::IntrusiveRefCntPtr<Diagnostic> Diags(&CI.getDiagnostics()); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 141 | std::string Error; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 142 | ASTUnit *AST = ASTUnit::LoadFromASTFile(Filename, Diags, |
| 143 | CI.getFileSystemOpts()); |
Daniel Dunbar | 5262fda | 2009-12-03 01:45:44 +0000 | [diff] [blame] | 144 | if (!AST) |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 145 | goto failure; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 146 | |
Daniel Dunbar | 685ac66 | 2010-06-07 23:25:49 +0000 | [diff] [blame] | 147 | setCurrentFile(Filename, InputKind, AST); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 148 | |
| 149 | // Set the shared objects, these are reset when we finish processing the |
| 150 | // file, otherwise the CompilerInstance will happily destroy them. |
| 151 | CI.setFileManager(&AST->getFileManager()); |
| 152 | CI.setSourceManager(&AST->getSourceManager()); |
| 153 | CI.setPreprocessor(&AST->getPreprocessor()); |
| 154 | CI.setASTContext(&AST->getASTContext()); |
| 155 | |
| 156 | // Initialize the action. |
| 157 | if (!BeginSourceFileAction(CI, Filename)) |
| 158 | goto failure; |
| 159 | |
| 160 | /// Create the AST consumer. |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame^] | 161 | CI.setASTConsumer(CreateWrappedASTConsumer(CI, Filename)); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 162 | if (!CI.hasASTConsumer()) |
| 163 | goto failure; |
| 164 | |
| 165 | return true; |
| 166 | } |
| 167 | |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 168 | // Set up the file and source managers, if needed. |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 169 | if (!CI.hasFileManager()) |
| 170 | CI.createFileManager(); |
| 171 | if (!CI.hasSourceManager()) |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 172 | CI.createSourceManager(CI.getFileManager()); |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 173 | |
| 174 | // IR files bypass the rest of initialization. |
| 175 | if (InputKind == IK_LLVM_IR) { |
| 176 | assert(hasIRSupport() && |
| 177 | "This action does not have IR file support!"); |
| 178 | |
| 179 | // Inform the diagnostic client we are processing a source file. |
| 180 | CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 0); |
| 181 | |
| 182 | // Initialize the action. |
| 183 | if (!BeginSourceFileAction(CI, Filename)) |
| 184 | goto failure; |
| 185 | |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | // Set up the preprocessor. |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 190 | CI.createPreprocessor(); |
| 191 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 192 | // Inform the diagnostic client we are processing a source file. |
| 193 | CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), |
| 194 | &CI.getPreprocessor()); |
| 195 | |
| 196 | // Initialize the action. |
| 197 | if (!BeginSourceFileAction(CI, Filename)) |
| 198 | goto failure; |
| 199 | |
| 200 | /// Create the AST context and consumer unless this is a preprocessor only |
| 201 | /// action. |
| 202 | if (!usesPreprocessorOnly()) { |
| 203 | CI.createASTContext(); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 204 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame^] | 205 | llvm::OwningPtr<ASTConsumer> Consumer( |
| 206 | CreateWrappedASTConsumer(CI, Filename)); |
Fariborz Jahanian | d305719 | 2010-10-29 19:49:13 +0000 | [diff] [blame] | 207 | if (!Consumer) |
| 208 | goto failure; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 209 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 210 | CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); |
| 211 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 212 | /// Use PCH? |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 213 | if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 214 | assert(hasPCHSupport() && "This action does not have PCH support!"); |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 215 | ASTDeserializationListener *DeserialListener |
| 216 | = CI.getInvocation().getFrontendOpts().ChainedPCH ? |
| 217 | Consumer->GetASTDeserializationListener() : 0; |
| 218 | if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) |
| 219 | DeserialListener = new DeserializedDeclsDumper(DeserialListener); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 220 | if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) |
| 221 | DeserialListener = new DeserializedDeclsChecker(CI.getASTContext(), |
| 222 | CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn, |
| 223 | DeserialListener); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 224 | CI.createPCHExternalASTSource( |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 225 | CI.getPreprocessorOpts().ImplicitPCHInclude, |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 226 | CI.getPreprocessorOpts().DisablePCHValidation, |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 227 | DeserialListener); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 228 | if (!CI.getASTContext().getExternalSource()) |
| 229 | goto failure; |
| 230 | } |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 231 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 232 | CI.setASTConsumer(Consumer.take()); |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 233 | if (!CI.hasASTConsumer()) |
| 234 | goto failure; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | // Initialize builtin info as long as we aren't using an external AST |
| 238 | // source. |
| 239 | if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) { |
| 240 | Preprocessor &PP = CI.getPreprocessor(); |
| 241 | PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(), |
Fariborz Jahanian | 67aba81 | 2010-11-30 17:35:24 +0000 | [diff] [blame] | 242 | PP.getLangOptions()); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | return true; |
| 246 | |
| 247 | // If we failed, reset state since the client will not end up calling the |
| 248 | // matching EndSourceFile(). |
| 249 | failure: |
| 250 | if (isCurrentFileAST()) { |
| 251 | CI.takeASTContext(); |
| 252 | CI.takePreprocessor(); |
| 253 | CI.takeSourceManager(); |
| 254 | CI.takeFileManager(); |
| 255 | } |
| 256 | |
| 257 | CI.getDiagnosticClient().EndSourceFile(); |
Daniel Dunbar | 685ac66 | 2010-06-07 23:25:49 +0000 | [diff] [blame] | 258 | setCurrentFile("", IK_None); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 259 | setCompilerInstance(0); |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | void FrontendAction::Execute() { |
| 264 | CompilerInstance &CI = getCompilerInstance(); |
| 265 | |
| 266 | // Initialize the main file entry. This needs to be delayed until after PCH |
| 267 | // has loaded. |
| 268 | if (isCurrentFileAST()) { |
| 269 | // Set the main file ID to an empty file. |
| 270 | // |
| 271 | // FIXME: We probably shouldn't need this, but for now this is the |
| 272 | // simplest way to reuse the logic in ParseAST. |
| 273 | const char *EmptyStr = ""; |
| 274 | llvm::MemoryBuffer *SB = |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 275 | llvm::MemoryBuffer::getMemBuffer(EmptyStr, "<dummy input>"); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 276 | CI.getSourceManager().createMainFileIDForMemBuffer(SB); |
| 277 | } else { |
| 278 | if (!CI.InitializeSourceManager(getCurrentFile())) |
| 279 | return; |
| 280 | } |
| 281 | |
Kovarththanan Rajaratnam | f79bafa | 2009-11-29 09:57:35 +0000 | [diff] [blame] | 282 | if (CI.hasFrontendTimer()) { |
| 283 | llvm::TimeRegion Timer(CI.getFrontendTimer()); |
| 284 | ExecuteAction(); |
| 285 | } |
| 286 | else ExecuteAction(); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void FrontendAction::EndSourceFile() { |
| 290 | CompilerInstance &CI = getCompilerInstance(); |
| 291 | |
| 292 | // Finalize the action. |
| 293 | EndSourceFileAction(); |
| 294 | |
| 295 | // Release the consumer and the AST, in that order since the consumer may |
| 296 | // perform actions in its destructor which require the context. |
| 297 | // |
| 298 | // FIXME: There is more per-file stuff we could just drop here? |
| 299 | if (CI.getFrontendOpts().DisableFree) { |
| 300 | CI.takeASTConsumer(); |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 301 | if (!isCurrentFileAST()) { |
| 302 | CI.takeSema(); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 303 | CI.takeASTContext(); |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 304 | } |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 305 | } else { |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 306 | if (!isCurrentFileAST()) { |
| 307 | CI.setSema(0); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 308 | CI.setASTContext(0); |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 309 | } |
| 310 | CI.setASTConsumer(0); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Daniel Dunbar | dbd8209 | 2010-03-23 05:09:10 +0000 | [diff] [blame] | 313 | // Inform the preprocessor we are done. |
| 314 | if (CI.hasPreprocessor()) |
| 315 | CI.getPreprocessor().EndSourceFile(); |
| 316 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 317 | if (CI.getFrontendOpts().ShowStats) { |
| 318 | llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n"; |
| 319 | CI.getPreprocessor().PrintStats(); |
| 320 | CI.getPreprocessor().getIdentifierTable().PrintStats(); |
| 321 | CI.getPreprocessor().getHeaderSearchInfo().PrintStats(); |
| 322 | CI.getSourceManager().PrintStats(); |
| 323 | llvm::errs() << "\n"; |
| 324 | } |
| 325 | |
| 326 | // Cleanup the output streams, and erase the output files if we encountered |
| 327 | // an error. |
Argyrios Kyrtzidis | be3aab6 | 2010-11-18 21:47:07 +0000 | [diff] [blame] | 328 | CI.clearOutputFiles(/*EraseFiles=*/CI.getDiagnostics().hasErrorOccurred()); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 329 | |
| 330 | // Inform the diagnostic client we are done with this source file. |
| 331 | CI.getDiagnosticClient().EndSourceFile(); |
| 332 | |
| 333 | if (isCurrentFileAST()) { |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 334 | CI.takeSema(); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 335 | CI.takeASTContext(); |
| 336 | CI.takePreprocessor(); |
| 337 | CI.takeSourceManager(); |
| 338 | CI.takeFileManager(); |
| 339 | } |
| 340 | |
| 341 | setCompilerInstance(0); |
Daniel Dunbar | 685ac66 | 2010-06-07 23:25:49 +0000 | [diff] [blame] | 342 | setCurrentFile("", IK_None); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | //===----------------------------------------------------------------------===// |
| 346 | // Utility Actions |
| 347 | //===----------------------------------------------------------------------===// |
| 348 | |
| 349 | void ASTFrontendAction::ExecuteAction() { |
| 350 | CompilerInstance &CI = getCompilerInstance(); |
| 351 | |
| 352 | // FIXME: Move the truncation aspect of this into Sema, we delayed this till |
| 353 | // here so the source manager would be initialized. |
| 354 | if (hasCodeCompletionSupport() && |
| 355 | !CI.getFrontendOpts().CodeCompletionAt.FileName.empty()) |
| 356 | CI.createCodeCompletionConsumer(); |
| 357 | |
| 358 | // Use a code completion consumer? |
| 359 | CodeCompleteConsumer *CompletionConsumer = 0; |
| 360 | if (CI.hasCodeCompletionConsumer()) |
| 361 | CompletionConsumer = &CI.getCodeCompletionConsumer(); |
| 362 | |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 363 | if (!CI.hasSema()) |
| 364 | CI.createSema(usesCompleteTranslationUnit(), CompletionConsumer); |
| 365 | |
| 366 | ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | ASTConsumer * |
| 370 | PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, |
| 371 | llvm::StringRef InFile) { |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 372 | llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 373 | } |