Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 1 | //===--- CompilerInstance.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/CompilerInstance.h" |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 11 | #include "clang/Sema/Sema.h" |
Daniel Dunbar | 12ce694 | 2009-11-14 02:47:17 +0000 | [diff] [blame] | 12 | #include "clang/AST/ASTConsumer.h" |
Daniel Dunbar | 5eb8100 | 2009-11-13 08:20:47 +0000 | [diff] [blame] | 13 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 14 | #include "clang/Basic/Diagnostic.h" |
Daniel Dunbar | 16b7449 | 2009-11-13 04:12:06 +0000 | [diff] [blame] | 15 | #include "clang/Basic/FileManager.h" |
| 16 | #include "clang/Basic/SourceManager.h" |
Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 17 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 18 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 19 | #include "clang/Lex/HeaderSearch.h" |
| 20 | #include "clang/Lex/Preprocessor.h" |
| 21 | #include "clang/Lex/PTHManager.h" |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 22 | #include "clang/Frontend/ChainedDiagnosticClient.h" |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 23 | #include "clang/Frontend/FrontendAction.h" |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 24 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 25 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
Daniel Dunbar | f79dced | 2009-11-14 03:24:39 +0000 | [diff] [blame] | 26 | #include "clang/Frontend/VerifyDiagnosticsClient.h" |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 27 | #include "clang/Frontend/Utils.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 28 | #include "clang/Serialization/ASTReader.h" |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 29 | #include "clang/Sema/CodeCompleteConsumer.h" |
Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 30 | #include "llvm/LLVMContext.h" |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MemoryBuffer.h" |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 95dd558 | 2010-03-30 17:33:59 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/Statistic.h" |
Kovarththanan Rajaratnam | f79bafa | 2009-11-29 09:57:35 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Timer.h" |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 35 | #include "llvm/System/Host.h" |
Daniel Dunbar | a920483 | 2009-11-13 10:37:48 +0000 | [diff] [blame] | 36 | #include "llvm/System/Path.h" |
Douglas Gregor | 2b4074f | 2009-12-01 05:55:20 +0000 | [diff] [blame] | 37 | #include "llvm/System/Program.h" |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 38 | #include "llvm/System/Signals.h" |
Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 39 | using namespace clang; |
| 40 | |
Daniel Dunbar | 42e9f8e4 | 2010-02-16 01:54:47 +0000 | [diff] [blame] | 41 | CompilerInstance::CompilerInstance() |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 42 | : Invocation(new CompilerInvocation()) { |
Daniel Dunbar | 6228ca0 | 2010-01-30 21:47:07 +0000 | [diff] [blame] | 43 | } |
Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 44 | |
| 45 | CompilerInstance::~CompilerInstance() { |
Daniel Dunbar | 42e9f8e4 | 2010-02-16 01:54:47 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void CompilerInstance::setLLVMContext(llvm::LLVMContext *Value) { |
| 49 | LLVMContext.reset(Value); |
Daniel Dunbar | 2a79e16 | 2009-11-13 03:51:44 +0000 | [diff] [blame] | 50 | } |
Daniel Dunbar | 16b7449 | 2009-11-13 04:12:06 +0000 | [diff] [blame] | 51 | |
Daniel Dunbar | 6228ca0 | 2010-01-30 21:47:07 +0000 | [diff] [blame] | 52 | void CompilerInstance::setInvocation(CompilerInvocation *Value) { |
| 53 | Invocation.reset(Value); |
| 54 | } |
| 55 | |
Daniel Dunbar | 8a9f569 | 2009-11-14 01:20:40 +0000 | [diff] [blame] | 56 | void CompilerInstance::setDiagnostics(Diagnostic *Value) { |
Douglas Gregor | 2801977 | 2010-04-05 23:52:57 +0000 | [diff] [blame] | 57 | Diagnostics = Value; |
Daniel Dunbar | 8a9f569 | 2009-11-14 01:20:40 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Daniel Dunbar | 8a9f569 | 2009-11-14 01:20:40 +0000 | [diff] [blame] | 60 | void CompilerInstance::setTarget(TargetInfo *Value) { |
| 61 | Target.reset(Value); |
| 62 | } |
| 63 | |
| 64 | void CompilerInstance::setFileManager(FileManager *Value) { |
| 65 | FileMgr.reset(Value); |
| 66 | } |
| 67 | |
| 68 | void CompilerInstance::setSourceManager(SourceManager *Value) { |
| 69 | SourceMgr.reset(Value); |
| 70 | } |
| 71 | |
| 72 | void CompilerInstance::setPreprocessor(Preprocessor *Value) { |
| 73 | PP.reset(Value); |
| 74 | } |
| 75 | |
| 76 | void CompilerInstance::setASTContext(ASTContext *Value) { |
| 77 | Context.reset(Value); |
| 78 | } |
| 79 | |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 80 | void CompilerInstance::setSema(Sema *S) { |
| 81 | TheSema.reset(S); |
| 82 | } |
| 83 | |
Daniel Dunbar | 12ce694 | 2009-11-14 02:47:17 +0000 | [diff] [blame] | 84 | void CompilerInstance::setASTConsumer(ASTConsumer *Value) { |
| 85 | Consumer.reset(Value); |
| 86 | } |
| 87 | |
Daniel Dunbar | 8a9f569 | 2009-11-14 01:20:40 +0000 | [diff] [blame] | 88 | void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { |
| 89 | CompletionConsumer.reset(Value); |
| 90 | } |
| 91 | |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 92 | // Diagnostics |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 93 | static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts, |
Axel Naumann | 7d0c4cc | 2010-10-11 09:13:46 +0000 | [diff] [blame] | 94 | unsigned argc, const char* const *argv, |
Kovarththanan Rajaratnam | 3d67b1e | 2010-03-17 09:24:48 +0000 | [diff] [blame] | 95 | Diagnostic &Diags) { |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 96 | std::string ErrorInfo; |
Kovarththanan Rajaratnam | 6924713 | 2010-03-17 09:47:30 +0000 | [diff] [blame] | 97 | llvm::OwningPtr<llvm::raw_ostream> OS( |
| 98 | new llvm::raw_fd_ostream(DiagOpts.DumpBuildInformation.c_str(), ErrorInfo)); |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 99 | if (!ErrorInfo.empty()) { |
Kovarththanan Rajaratnam | 3d67b1e | 2010-03-17 09:24:48 +0000 | [diff] [blame] | 100 | Diags.Report(diag::err_fe_unable_to_open_logfile) |
| 101 | << DiagOpts.DumpBuildInformation << ErrorInfo; |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 102 | return; |
| 103 | } |
| 104 | |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 105 | (*OS) << "clang -cc1 command line arguments: "; |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 106 | for (unsigned i = 0; i != argc; ++i) |
| 107 | (*OS) << argv[i] << ' '; |
| 108 | (*OS) << '\n'; |
| 109 | |
| 110 | // Chain in a diagnostic client which will log the diagnostics. |
| 111 | DiagnosticClient *Logger = |
Kovarththanan Rajaratnam | 6924713 | 2010-03-17 09:47:30 +0000 | [diff] [blame] | 112 | new TextDiagnosticPrinter(*OS.take(), DiagOpts, /*OwnsOutputStream=*/true); |
Douglas Gregor | bdbb004 | 2010-08-18 22:29:43 +0000 | [diff] [blame] | 113 | Diags.setClient(new ChainedDiagnosticClient(Diags.takeClient(), Logger)); |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Douglas Gregor | e47be3e | 2010-11-11 00:39:14 +0000 | [diff] [blame] | 116 | void CompilerInstance::createDiagnostics(int Argc, const char* const *Argv, |
| 117 | DiagnosticClient *Client) { |
| 118 | Diagnostics = createDiagnostics(getDiagnosticOpts(), Argc, Argv, Client); |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Douglas Gregor | 2801977 | 2010-04-05 23:52:57 +0000 | [diff] [blame] | 121 | llvm::IntrusiveRefCntPtr<Diagnostic> |
| 122 | CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts, |
Douglas Gregor | e47be3e | 2010-11-11 00:39:14 +0000 | [diff] [blame] | 123 | int Argc, const char* const *Argv, |
| 124 | DiagnosticClient *Client) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 125 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
| 126 | llvm::IntrusiveRefCntPtr<Diagnostic> Diags(new Diagnostic(DiagID)); |
Daniel Dunbar | 221c721 | 2009-11-14 07:53:24 +0000 | [diff] [blame] | 127 | |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 128 | // Create the diagnostic client for reporting errors or for |
| 129 | // implementing -verify. |
Douglas Gregor | e47be3e | 2010-11-11 00:39:14 +0000 | [diff] [blame] | 130 | if (Client) |
| 131 | Diags->setClient(Client); |
| 132 | else |
| 133 | Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); |
Daniel Dunbar | f79dced | 2009-11-14 03:24:39 +0000 | [diff] [blame] | 134 | |
| 135 | // Chain in -verify checker, if requested. |
| 136 | if (Opts.VerifyDiagnostics) |
Douglas Gregor | bdbb004 | 2010-08-18 22:29:43 +0000 | [diff] [blame] | 137 | Diags->setClient(new VerifyDiagnosticsClient(*Diags, Diags->takeClient())); |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 138 | |
| 139 | if (!Opts.DumpBuildInformation.empty()) |
Kovarththanan Rajaratnam | 3d67b1e | 2010-03-17 09:24:48 +0000 | [diff] [blame] | 140 | SetUpBuildDumpLog(Opts, Argc, Argv, *Diags); |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 141 | |
| 142 | // Configure our handling of diagnostics. |
Kovarththanan Rajaratnam | 5bf932b | 2010-03-17 09:36:02 +0000 | [diff] [blame] | 143 | ProcessWarningOptions(*Diags, Opts); |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 144 | |
Douglas Gregor | 2801977 | 2010-04-05 23:52:57 +0000 | [diff] [blame] | 145 | return Diags; |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // File Manager |
| 149 | |
Daniel Dunbar | 16b7449 | 2009-11-13 04:12:06 +0000 | [diff] [blame] | 150 | void CompilerInstance::createFileManager() { |
Chris Lattner | 7ad97ff | 2010-11-23 07:51:02 +0000 | [diff] [blame] | 151 | FileMgr.reset(new FileManager(getFileSystemOpts())); |
Daniel Dunbar | 16b7449 | 2009-11-13 04:12:06 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 154 | // Source Manager |
| 155 | |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 156 | void CompilerInstance::createSourceManager(FileManager &FileMgr) { |
| 157 | SourceMgr.reset(new SourceManager(getDiagnostics(), FileMgr)); |
Daniel Dunbar | 16b7449 | 2009-11-13 04:12:06 +0000 | [diff] [blame] | 158 | } |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 159 | |
Daniel Dunbar | 0fbb3d9 | 2009-11-13 05:52:34 +0000 | [diff] [blame] | 160 | // Preprocessor |
| 161 | |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 162 | void CompilerInstance::createPreprocessor() { |
| 163 | PP.reset(createPreprocessor(getDiagnostics(), getLangOpts(), |
| 164 | getPreprocessorOpts(), getHeaderSearchOpts(), |
| 165 | getDependencyOutputOpts(), getTarget(), |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 166 | getFrontendOpts(), getSourceManager(), |
| 167 | getFileManager())); |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | Preprocessor * |
| 171 | CompilerInstance::createPreprocessor(Diagnostic &Diags, |
| 172 | const LangOptions &LangInfo, |
| 173 | const PreprocessorOptions &PPOpts, |
| 174 | const HeaderSearchOptions &HSOpts, |
| 175 | const DependencyOutputOptions &DepOpts, |
| 176 | const TargetInfo &Target, |
Fariborz Jahanian | 7d95747 | 2010-01-13 18:51:17 +0000 | [diff] [blame] | 177 | const FrontendOptions &FEOpts, |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 178 | SourceManager &SourceMgr, |
| 179 | FileManager &FileMgr) { |
| 180 | // Create a PTH manager if we are using some form of a token cache. |
| 181 | PTHManager *PTHMgr = 0; |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 182 | if (!PPOpts.TokenCache.empty()) |
Chris Lattner | 681c74a | 2010-11-23 09:01:31 +0000 | [diff] [blame] | 183 | PTHMgr = PTHManager::Create(PPOpts.TokenCache, Diags); |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 184 | |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 185 | // Create the Preprocessor. |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 186 | HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr); |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 187 | Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target, |
| 188 | SourceMgr, *HeaderInfo, PTHMgr, |
| 189 | /*OwnsHeaderSearch=*/true); |
| 190 | |
| 191 | // Note that this is different then passing PTHMgr to Preprocessor's ctor. |
| 192 | // That argument is used as the IdentifierInfoLookup argument to |
| 193 | // IdentifierTable's ctor. |
| 194 | if (PTHMgr) { |
| 195 | PTHMgr->setPreprocessor(PP); |
| 196 | PP->setPTHManager(PTHMgr); |
| 197 | } |
| 198 | |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 199 | if (PPOpts.DetailedRecord) |
| 200 | PP->createPreprocessingRecord(); |
| 201 | |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 202 | InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts); |
Daniel Dunbar | 22dacfa | 2009-11-13 05:52:11 +0000 | [diff] [blame] | 203 | |
| 204 | // Handle generating dependencies, if requested. |
| 205 | if (!DepOpts.OutputFile.empty()) |
| 206 | AttachDependencyFileGen(*PP, DepOpts); |
| 207 | |
| 208 | return PP; |
| 209 | } |
Daniel Dunbar | 5eb8100 | 2009-11-13 08:20:47 +0000 | [diff] [blame] | 210 | |
| 211 | // ASTContext |
| 212 | |
| 213 | void CompilerInstance::createASTContext() { |
| 214 | Preprocessor &PP = getPreprocessor(); |
| 215 | Context.reset(new ASTContext(getLangOpts(), PP.getSourceManager(), |
| 216 | getTarget(), PP.getIdentifierTable(), |
| 217 | PP.getSelectorTable(), PP.getBuiltinInfo(), |
Daniel Dunbar | 5eb8100 | 2009-11-13 08:20:47 +0000 | [diff] [blame] | 218 | /*size_reserve=*/ 0)); |
| 219 | } |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 220 | |
| 221 | // ExternalASTSource |
| 222 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 223 | void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path, |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 224 | bool DisablePCHValidation, |
| 225 | void *DeserializationListener){ |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 226 | llvm::OwningPtr<ExternalASTSource> Source; |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 227 | bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 228 | Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot, |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 229 | DisablePCHValidation, |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 230 | getPreprocessor(), getASTContext(), |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 231 | DeserializationListener, |
| 232 | Preamble)); |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 233 | getASTContext().setExternalSource(Source); |
| 234 | } |
| 235 | |
| 236 | ExternalASTSource * |
| 237 | CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path, |
| 238 | const std::string &Sysroot, |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 239 | bool DisablePCHValidation, |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 240 | Preprocessor &PP, |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 241 | ASTContext &Context, |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 242 | void *DeserializationListener, |
| 243 | bool Preamble) { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 244 | llvm::OwningPtr<ASTReader> Reader; |
| 245 | Reader.reset(new ASTReader(PP, &Context, |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 246 | Sysroot.empty() ? 0 : Sysroot.c_str(), |
| 247 | DisablePCHValidation)); |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 248 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 249 | Reader->setDeserializationListener( |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 250 | static_cast<ASTDeserializationListener *>(DeserializationListener)); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 251 | switch (Reader->ReadAST(Path, |
| 252 | Preamble ? ASTReader::Preamble : ASTReader::PCH)) { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 253 | case ASTReader::Success: |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 254 | // Set the predefines buffer as suggested by the PCH reader. Typically, the |
| 255 | // predefines buffer will be empty. |
| 256 | PP.setPredefines(Reader->getSuggestedPredefines()); |
| 257 | return Reader.take(); |
| 258 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 259 | case ASTReader::Failure: |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 260 | // Unrecoverable failure: don't even try to process the input file. |
| 261 | break; |
| 262 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 263 | case ASTReader::IgnorePCH: |
Daniel Dunbar | 0f80039 | 2009-11-13 08:21:10 +0000 | [diff] [blame] | 264 | // No suitable PCH file could be found. Return an error. |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | return 0; |
| 269 | } |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 270 | |
| 271 | // Code Completion |
| 272 | |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 273 | static bool EnableCodeCompletion(Preprocessor &PP, |
| 274 | const std::string &Filename, |
| 275 | unsigned Line, |
| 276 | unsigned Column) { |
| 277 | // Tell the source manager to chop off the given file at a specific |
| 278 | // line and column. |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 279 | const FileEntry *Entry = PP.getFileManager().getFile(Filename); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 280 | if (!Entry) { |
| 281 | PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file) |
| 282 | << Filename; |
| 283 | return true; |
| 284 | } |
| 285 | |
| 286 | // Truncate the named file at the given line/column. |
| 287 | PP.SetCodeCompletionPoint(Entry, Line, Column); |
| 288 | return false; |
| 289 | } |
| 290 | |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 291 | void CompilerInstance::createCodeCompletionConsumer() { |
| 292 | const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 293 | if (!CompletionConsumer) { |
| 294 | CompletionConsumer.reset( |
| 295 | createCodeCompletionConsumer(getPreprocessor(), |
| 296 | Loc.FileName, Loc.Line, Loc.Column, |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 297 | getFrontendOpts().ShowMacrosInCodeCompletion, |
Douglas Gregor | d8e8a58 | 2010-05-25 21:41:55 +0000 | [diff] [blame] | 298 | getFrontendOpts().ShowCodePatternsInCodeCompletion, |
Douglas Gregor | 8071e42 | 2010-08-15 06:18:01 +0000 | [diff] [blame] | 299 | getFrontendOpts().ShowGlobalSymbolsInCodeCompletion, |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 300 | llvm::outs())); |
| 301 | if (!CompletionConsumer) |
| 302 | return; |
| 303 | } else if (EnableCodeCompletion(getPreprocessor(), Loc.FileName, |
| 304 | Loc.Line, Loc.Column)) { |
| 305 | CompletionConsumer.reset(); |
Douglas Gregor | c3d43b7 | 2010-03-16 06:04:47 +0000 | [diff] [blame] | 306 | return; |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 307 | } |
Douglas Gregor | 2b4074f | 2009-12-01 05:55:20 +0000 | [diff] [blame] | 308 | |
| 309 | if (CompletionConsumer->isOutputBinary() && |
| 310 | llvm::sys::Program::ChangeStdoutToBinary()) { |
| 311 | getPreprocessor().getDiagnostics().Report(diag::err_fe_stdout_binary); |
| 312 | CompletionConsumer.reset(); |
| 313 | } |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Kovarththanan Rajaratnam | f79bafa | 2009-11-29 09:57:35 +0000 | [diff] [blame] | 316 | void CompilerInstance::createFrontendTimer() { |
| 317 | FrontendTimer.reset(new llvm::Timer("Clang front-end timer")); |
| 318 | } |
| 319 | |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 320 | CodeCompleteConsumer * |
| 321 | CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP, |
| 322 | const std::string &Filename, |
| 323 | unsigned Line, |
| 324 | unsigned Column, |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 325 | bool ShowMacros, |
Douglas Gregor | d8e8a58 | 2010-05-25 21:41:55 +0000 | [diff] [blame] | 326 | bool ShowCodePatterns, |
Douglas Gregor | 8071e42 | 2010-08-15 06:18:01 +0000 | [diff] [blame] | 327 | bool ShowGlobals, |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 328 | llvm::raw_ostream &OS) { |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 329 | if (EnableCodeCompletion(PP, Filename, Line, Column)) |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 330 | return 0; |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 331 | |
| 332 | // Set up the creation routine for code-completion. |
Douglas Gregor | a9f4f62 | 2010-10-11 22:12:15 +0000 | [diff] [blame] | 333 | return new PrintingCodeCompleteConsumer(ShowMacros, ShowCodePatterns, |
Douglas Gregor | 8071e42 | 2010-08-15 06:18:01 +0000 | [diff] [blame] | 334 | ShowGlobals, OS); |
Daniel Dunbar | c2f484f | 2009-11-13 09:36:05 +0000 | [diff] [blame] | 335 | } |
Daniel Dunbar | a920483 | 2009-11-13 10:37:48 +0000 | [diff] [blame] | 336 | |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 337 | void CompilerInstance::createSema(bool CompleteTranslationUnit, |
| 338 | CodeCompleteConsumer *CompletionConsumer) { |
| 339 | TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(), |
| 340 | CompleteTranslationUnit, CompletionConsumer)); |
| 341 | } |
| 342 | |
Daniel Dunbar | a920483 | 2009-11-13 10:37:48 +0000 | [diff] [blame] | 343 | // Output Files |
| 344 | |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 345 | void CompilerInstance::addOutputFile(const OutputFile &OutFile) { |
| 346 | assert(OutFile.OS && "Attempt to add empty stream to output list!"); |
| 347 | OutputFiles.push_back(OutFile); |
Daniel Dunbar | a920483 | 2009-11-13 10:37:48 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Kovarththanan Rajaratnam | e51dd7b | 2010-03-06 12:07:48 +0000 | [diff] [blame] | 350 | void CompilerInstance::clearOutputFiles(bool EraseFiles) { |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 351 | for (std::list<OutputFile>::iterator |
Daniel Dunbar | a920483 | 2009-11-13 10:37:48 +0000 | [diff] [blame] | 352 | it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) { |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 353 | delete it->OS; |
| 354 | if (!it->TempFilename.empty()) { |
| 355 | llvm::sys::Path TempPath(it->TempFilename); |
| 356 | if (EraseFiles) |
| 357 | TempPath.eraseFromDisk(); |
| 358 | else { |
| 359 | std::string Error; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 360 | llvm::sys::Path NewOutFile(it->Filename); |
| 361 | // If '-working-directory' was passed, the output filename should be |
| 362 | // relative to that. |
| 363 | FileManager::FixupRelativePath(NewOutFile, getFileSystemOpts()); |
| 364 | if (TempPath.renamePathOnDisk(NewOutFile, &Error)) { |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 365 | getDiagnostics().Report(diag::err_fe_unable_to_rename_temp) |
| 366 | << it->TempFilename << it->Filename << Error; |
| 367 | TempPath.eraseFromDisk(); |
| 368 | } |
| 369 | } |
| 370 | } else if (!it->Filename.empty() && EraseFiles) |
| 371 | llvm::sys::Path(it->Filename).eraseFromDisk(); |
| 372 | |
Daniel Dunbar | a920483 | 2009-11-13 10:37:48 +0000 | [diff] [blame] | 373 | } |
| 374 | OutputFiles.clear(); |
| 375 | } |
| 376 | |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 377 | llvm::raw_fd_ostream * |
| 378 | CompilerInstance::createDefaultOutputFile(bool Binary, |
| 379 | llvm::StringRef InFile, |
| 380 | llvm::StringRef Extension) { |
| 381 | return createOutputFile(getFrontendOpts().OutputFile, Binary, |
| 382 | InFile, Extension); |
| 383 | } |
| 384 | |
| 385 | llvm::raw_fd_ostream * |
| 386 | CompilerInstance::createOutputFile(llvm::StringRef OutputPath, |
| 387 | bool Binary, |
| 388 | llvm::StringRef InFile, |
| 389 | llvm::StringRef Extension) { |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 390 | std::string Error, OutputPathName, TempPathName; |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 391 | llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary, |
| 392 | InFile, Extension, |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 393 | &OutputPathName, |
| 394 | &TempPathName); |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 395 | if (!OS) { |
Daniel Dunbar | 3604359 | 2009-12-03 09:13:30 +0000 | [diff] [blame] | 396 | getDiagnostics().Report(diag::err_fe_unable_to_open_output) |
| 397 | << OutputPath << Error; |
| 398 | return 0; |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | // Add the output file -- but don't try to remove "-", since this means we are |
| 402 | // using stdin. |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 403 | addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "", |
| 404 | TempPathName, OS)); |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 405 | |
| 406 | return OS; |
| 407 | } |
| 408 | |
| 409 | llvm::raw_fd_ostream * |
| 410 | CompilerInstance::createOutputFile(llvm::StringRef OutputPath, |
| 411 | std::string &Error, |
| 412 | bool Binary, |
| 413 | llvm::StringRef InFile, |
| 414 | llvm::StringRef Extension, |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 415 | std::string *ResultPathName, |
| 416 | std::string *TempPathName) { |
| 417 | std::string OutFile, TempFile; |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 418 | if (!OutputPath.empty()) { |
| 419 | OutFile = OutputPath; |
| 420 | } else if (InFile == "-") { |
| 421 | OutFile = "-"; |
| 422 | } else if (!Extension.empty()) { |
| 423 | llvm::sys::Path Path(InFile); |
| 424 | Path.eraseSuffix(); |
| 425 | Path.appendSuffix(Extension); |
| 426 | OutFile = Path.str(); |
| 427 | } else { |
| 428 | OutFile = "-"; |
| 429 | } |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 430 | |
| 431 | if (OutFile != "-") { |
| 432 | llvm::sys::Path OutPath(OutFile); |
| 433 | // Only create the temporary if we can actually write to OutPath, otherwise |
| 434 | // we want to fail early. |
| 435 | if (!OutPath.exists() || |
| 436 | (OutPath.isRegularFile() && OutPath.canWrite())) { |
| 437 | // Create a temporary file. |
| 438 | llvm::sys::Path TempPath(OutFile); |
| 439 | if (!TempPath.createTemporaryFileOnDisk()) |
| 440 | TempFile = TempPath.str(); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | std::string OSFile = OutFile; |
| 445 | if (!TempFile.empty()) |
| 446 | OSFile = TempFile; |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 447 | |
Daniel Dunbar | fc97102 | 2009-11-20 22:32:38 +0000 | [diff] [blame] | 448 | llvm::OwningPtr<llvm::raw_fd_ostream> OS( |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 449 | new llvm::raw_fd_ostream(OSFile.c_str(), Error, |
Daniel Dunbar | fc97102 | 2009-11-20 22:32:38 +0000 | [diff] [blame] | 450 | (Binary ? llvm::raw_fd_ostream::F_Binary : 0))); |
| 451 | if (!Error.empty()) |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 452 | return 0; |
| 453 | |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 454 | // Make sure the out stream file gets removed if we crash. |
| 455 | llvm::sys::RemoveFileOnSignal(llvm::sys::Path(OSFile)); |
| 456 | |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 457 | if (ResultPathName) |
| 458 | *ResultPathName = OutFile; |
Argyrios Kyrtzidis | dc24572 | 2010-09-17 17:38:48 +0000 | [diff] [blame] | 459 | if (TempPathName) |
| 460 | *TempPathName = TempFile; |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 461 | |
Daniel Dunbar | fc97102 | 2009-11-20 22:32:38 +0000 | [diff] [blame] | 462 | return OS.take(); |
Daniel Dunbar | f482d59 | 2009-11-13 18:32:08 +0000 | [diff] [blame] | 463 | } |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 464 | |
| 465 | // Initialization Utilities |
| 466 | |
| 467 | bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile) { |
| 468 | return InitializeSourceManager(InputFile, getDiagnostics(), getFileManager(), |
| 469 | getSourceManager(), getFrontendOpts()); |
| 470 | } |
| 471 | |
| 472 | bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile, |
| 473 | Diagnostic &Diags, |
| 474 | FileManager &FileMgr, |
| 475 | SourceManager &SourceMgr, |
| 476 | const FrontendOptions &Opts) { |
| 477 | // Figure out where to get and map in the main file. |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 478 | if (InputFile != "-") { |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 479 | const FileEntry *File = FileMgr.getFile(InputFile); |
Dan Gohman | 694137c | 2010-10-26 21:13:51 +0000 | [diff] [blame] | 480 | if (!File) { |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 481 | Diags.Report(diag::err_fe_error_reading) << InputFile; |
| 482 | return false; |
| 483 | } |
Dan Gohman | 694137c | 2010-10-26 21:13:51 +0000 | [diff] [blame] | 484 | SourceMgr.createMainFileID(File); |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 485 | } else { |
| 486 | llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(); |
Dan Gohman | 694137c | 2010-10-26 21:13:51 +0000 | [diff] [blame] | 487 | if (!SB) { |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 488 | Diags.Report(diag::err_fe_error_reading_stdin); |
| 489 | return false; |
| 490 | } |
Dan Gohman | 90d9081 | 2010-10-26 23:21:25 +0000 | [diff] [blame] | 491 | const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 492 | SB->getBufferSize(), 0); |
Dan Gohman | 90d9081 | 2010-10-26 23:21:25 +0000 | [diff] [blame] | 493 | SourceMgr.createMainFileID(File); |
| 494 | SourceMgr.overrideFileContents(File, SB); |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Dan Gohman | 694137c | 2010-10-26 21:13:51 +0000 | [diff] [blame] | 497 | assert(!SourceMgr.getMainFileID().isInvalid() && |
| 498 | "Couldn't establish MainFileID!"); |
Daniel Dunbar | ccb6cb6 | 2009-11-14 07:53:04 +0000 | [diff] [blame] | 499 | return true; |
| 500 | } |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 501 | |
| 502 | // High-Level Operations |
| 503 | |
| 504 | bool CompilerInstance::ExecuteAction(FrontendAction &Act) { |
| 505 | assert(hasDiagnostics() && "Diagnostics engine is not initialized!"); |
| 506 | assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!"); |
| 507 | assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!"); |
| 508 | |
| 509 | // FIXME: Take this as an argument, once all the APIs we used have moved to |
| 510 | // taking it as an input instead of hard-coding llvm::errs. |
| 511 | llvm::raw_ostream &OS = llvm::errs(); |
| 512 | |
| 513 | // Create the target instance. |
| 514 | setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), getTargetOpts())); |
| 515 | if (!hasTarget()) |
| 516 | return false; |
| 517 | |
| 518 | // Inform the target of the language options. |
| 519 | // |
| 520 | // FIXME: We shouldn't need to do this, the target should be immutable once |
| 521 | // created. This complexity should be lifted elsewhere. |
| 522 | getTarget().setForcedLangOptions(getLangOpts()); |
| 523 | |
| 524 | // Validate/process some options. |
| 525 | if (getHeaderSearchOpts().Verbose) |
| 526 | OS << "clang -cc1 version " CLANG_VERSION_STRING |
| 527 | << " based upon " << PACKAGE_STRING |
| 528 | << " hosted on " << llvm::sys::getHostTriple() << "\n"; |
| 529 | |
| 530 | if (getFrontendOpts().ShowTimers) |
| 531 | createFrontendTimer(); |
| 532 | |
Douglas Gregor | 95dd558 | 2010-03-30 17:33:59 +0000 | [diff] [blame] | 533 | if (getFrontendOpts().ShowStats) |
| 534 | llvm::EnableStatistics(); |
| 535 | |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 536 | for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) { |
| 537 | const std::string &InFile = getFrontendOpts().Inputs[i].second; |
| 538 | |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 539 | // Reset the ID tables if we are reusing the SourceManager. |
| 540 | if (hasSourceManager()) |
| 541 | getSourceManager().clearIDTables(); |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 542 | |
Daniel Dunbar | d3598a6 | 2010-06-07 23:23:06 +0000 | [diff] [blame] | 543 | if (Act.BeginSourceFile(*this, InFile, getFrontendOpts().Inputs[i].first)) { |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 544 | Act.Execute(); |
| 545 | Act.EndSourceFile(); |
| 546 | } |
| 547 | } |
| 548 | |
Chris Lattner | 53eee7b | 2010-04-07 18:47:42 +0000 | [diff] [blame] | 549 | if (getDiagnosticOpts().ShowCarets) { |
Argyrios Kyrtzidis | f2224d8 | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 550 | // We can have multiple diagnostics sharing one diagnostic client. |
| 551 | // Get the total number of warnings/errors from the client. |
| 552 | unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings(); |
| 553 | unsigned NumErrors = getDiagnostics().getClient()->getNumErrors(); |
Chris Lattner | 53eee7b | 2010-04-07 18:47:42 +0000 | [diff] [blame] | 554 | |
| 555 | if (NumWarnings) |
| 556 | OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s"); |
| 557 | if (NumWarnings && NumErrors) |
| 558 | OS << " and "; |
| 559 | if (NumErrors) |
| 560 | OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s"); |
| 561 | if (NumWarnings || NumErrors) |
| 562 | OS << " generated.\n"; |
| 563 | } |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 564 | |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 565 | if (getFrontendOpts().ShowStats && hasFileManager()) { |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 566 | getFileManager().PrintStats(); |
| 567 | OS << "\n"; |
| 568 | } |
| 569 | |
Argyrios Kyrtzidis | ab41b97 | 2010-11-18 21:13:57 +0000 | [diff] [blame] | 570 | return !getDiagnostics().getClient()->getNumErrors(); |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | |