blob: a630486688e401e074ae71b06a4e29d4f8b65742 [file] [log] [blame]
Daniel Dunbar2a79e162009-11-13 03:51:44 +00001//===--- 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"
Daniel Dunbar12ce6942009-11-14 02:47:17 +000011#include "clang/AST/ASTConsumer.h"
Daniel Dunbar5eb81002009-11-13 08:20:47 +000012#include "clang/AST/ASTContext.h"
Daniel Dunbar2a79e162009-11-13 03:51:44 +000013#include "clang/Basic/Diagnostic.h"
Daniel Dunbar16b74492009-11-13 04:12:06 +000014#include "clang/Basic/FileManager.h"
15#include "clang/Basic/SourceManager.h"
Daniel Dunbar2a79e162009-11-13 03:51:44 +000016#include "clang/Basic/TargetInfo.h"
Daniel Dunbar0397af22010-01-13 00:48:06 +000017#include "clang/Basic/Version.h"
Daniel Dunbar22dacfa2009-11-13 05:52:11 +000018#include "clang/Lex/HeaderSearch.h"
19#include "clang/Lex/Preprocessor.h"
20#include "clang/Lex/PTHManager.h"
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +000021#include "clang/Frontend/ChainedDiagnosticClient.h"
Daniel Dunbar0397af22010-01-13 00:48:06 +000022#include "clang/Frontend/FrontendAction.h"
Daniel Dunbar0f800392009-11-13 08:21:10 +000023#include "clang/Frontend/PCHReader.h"
Daniel Dunbarc2f484f2009-11-13 09:36:05 +000024#include "clang/Frontend/FrontendDiagnostic.h"
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +000025#include "clang/Frontend/TextDiagnosticPrinter.h"
Daniel Dunbarf79dced2009-11-14 03:24:39 +000026#include "clang/Frontend/VerifyDiagnosticsClient.h"
Daniel Dunbar22dacfa2009-11-13 05:52:11 +000027#include "clang/Frontend/Utils.h"
Daniel Dunbarc2f484f2009-11-13 09:36:05 +000028#include "clang/Sema/CodeCompleteConsumer.h"
Daniel Dunbar2a79e162009-11-13 03:51:44 +000029#include "llvm/LLVMContext.h"
Daniel Dunbarccb6cb62009-11-14 07:53:04 +000030#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +000031#include "llvm/Support/raw_ostream.h"
Kovarththanan Rajaratnamf79bafa2009-11-29 09:57:35 +000032#include "llvm/Support/Timer.h"
Daniel Dunbar0397af22010-01-13 00:48:06 +000033#include "llvm/System/Host.h"
Daniel Dunbara9204832009-11-13 10:37:48 +000034#include "llvm/System/Path.h"
Douglas Gregor2b4074f2009-12-01 05:55:20 +000035#include "llvm/System/Program.h"
Daniel Dunbar2a79e162009-11-13 03:51:44 +000036using namespace clang;
37
38CompilerInstance::CompilerInstance(llvm::LLVMContext *_LLVMContext,
39 bool _OwnsLLVMContext)
40 : LLVMContext(_LLVMContext),
Daniel Dunbar6228ca02010-01-30 21:47:07 +000041 OwnsLLVMContext(_OwnsLLVMContext),
42 Invocation(new CompilerInvocation) {
43}
Daniel Dunbar2a79e162009-11-13 03:51:44 +000044
45CompilerInstance::~CompilerInstance() {
46 if (OwnsLLVMContext)
47 delete LLVMContext;
48}
Daniel Dunbar16b74492009-11-13 04:12:06 +000049
Daniel Dunbar6228ca02010-01-30 21:47:07 +000050void CompilerInstance::setInvocation(CompilerInvocation *Value) {
51 Invocation.reset(Value);
52}
53
Daniel Dunbar8a9f5692009-11-14 01:20:40 +000054void CompilerInstance::setDiagnostics(Diagnostic *Value) {
55 Diagnostics.reset(Value);
56}
57
58void CompilerInstance::setDiagnosticClient(DiagnosticClient *Value) {
59 DiagClient.reset(Value);
60}
61
62void CompilerInstance::setTarget(TargetInfo *Value) {
63 Target.reset(Value);
64}
65
66void CompilerInstance::setFileManager(FileManager *Value) {
67 FileMgr.reset(Value);
68}
69
70void CompilerInstance::setSourceManager(SourceManager *Value) {
71 SourceMgr.reset(Value);
72}
73
74void CompilerInstance::setPreprocessor(Preprocessor *Value) {
75 PP.reset(Value);
76}
77
78void CompilerInstance::setASTContext(ASTContext *Value) {
79 Context.reset(Value);
80}
81
Daniel Dunbar12ce6942009-11-14 02:47:17 +000082void CompilerInstance::setASTConsumer(ASTConsumer *Value) {
83 Consumer.reset(Value);
84}
85
Daniel Dunbar8a9f5692009-11-14 01:20:40 +000086void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) {
87 CompletionConsumer.reset(Value);
88}
89
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +000090// Diagnostics
Douglas Gregord93256e2010-01-28 06:00:51 +000091namespace {
92 class BinaryDiagnosticSerializer : public DiagnosticClient {
93 llvm::raw_ostream &OS;
94 SourceManager *SourceMgr;
95 public:
96 explicit BinaryDiagnosticSerializer(llvm::raw_ostream &OS)
97 : OS(OS), SourceMgr(0) { }
98
99 virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
100 const DiagnosticInfo &Info);
101 };
102}
103
104void BinaryDiagnosticSerializer::HandleDiagnostic(Diagnostic::Level DiagLevel,
105 const DiagnosticInfo &Info) {
106 Info.Serialize(DiagLevel, OS);
107}
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000108
109static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
110 unsigned argc, char **argv,
111 llvm::OwningPtr<DiagnosticClient> &DiagClient) {
112 std::string ErrorInfo;
113 llvm::raw_ostream *OS =
114 new llvm::raw_fd_ostream(DiagOpts.DumpBuildInformation.c_str(), ErrorInfo);
115 if (!ErrorInfo.empty()) {
116 // FIXME: Do not fail like this.
117 llvm::errs() << "error opening -dump-build-information file '"
118 << DiagOpts.DumpBuildInformation << "', option ignored!\n";
119 delete OS;
120 return;
121 }
122
Daniel Dunbardd63b282009-12-11 23:04:35 +0000123 (*OS) << "clang -cc1 command line arguments: ";
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000124 for (unsigned i = 0; i != argc; ++i)
125 (*OS) << argv[i] << ' ';
126 (*OS) << '\n';
127
128 // Chain in a diagnostic client which will log the diagnostics.
129 DiagnosticClient *Logger =
130 new TextDiagnosticPrinter(*OS, DiagOpts, /*OwnsOutputStream=*/true);
131 DiagClient.reset(new ChainedDiagnosticClient(DiagClient.take(), Logger));
132}
133
134void CompilerInstance::createDiagnostics(int Argc, char **Argv) {
135 Diagnostics.reset(createDiagnostics(getDiagnosticOpts(), Argc, Argv));
136
137 if (Diagnostics)
138 DiagClient.reset(Diagnostics->getClient());
139}
140
141Diagnostic *CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
142 int Argc, char **Argv) {
Daniel Dunbar221c7212009-11-14 07:53:24 +0000143 llvm::OwningPtr<Diagnostic> Diags(new Diagnostic());
144
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000145 // Create the diagnostic client for reporting errors or for
146 // implementing -verify.
Douglas Gregord93256e2010-01-28 06:00:51 +0000147 llvm::OwningPtr<DiagnosticClient> DiagClient;
148 if (Opts.BinaryOutput) {
149 if (llvm::sys::Program::ChangeStderrToBinary()) {
150 // We weren't able to set standard error to binary, which is a
151 // bit of a problem. So, just create a text diagnostic printer
152 // to complain about this problem, and pretend that the user
153 // didn't try to use binary output.
154 DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), Opts));
155 Diags->setClient(DiagClient.take());
156 Diags->Report(diag::err_fe_stderr_binary);
157 return Diags.take();
158 } else {
159 DiagClient.reset(new BinaryDiagnosticSerializer(llvm::errs()));
160 }
161 } else {
162 DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), Opts));
163 }
Daniel Dunbarf79dced2009-11-14 03:24:39 +0000164
165 // Chain in -verify checker, if requested.
166 if (Opts.VerifyDiagnostics)
Daniel Dunbar221c7212009-11-14 07:53:24 +0000167 DiagClient.reset(new VerifyDiagnosticsClient(*Diags, DiagClient.take()));
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000168
169 if (!Opts.DumpBuildInformation.empty())
170 SetUpBuildDumpLog(Opts, Argc, Argv, DiagClient);
171
172 // Configure our handling of diagnostics.
Daniel Dunbar221c7212009-11-14 07:53:24 +0000173 Diags->setClient(DiagClient.take());
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000174 if (ProcessWarningOptions(*Diags, Opts))
175 return 0;
176
Daniel Dunbar221c7212009-11-14 07:53:24 +0000177 return Diags.take();
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000178}
179
180// File Manager
181
Daniel Dunbar16b74492009-11-13 04:12:06 +0000182void CompilerInstance::createFileManager() {
183 FileMgr.reset(new FileManager());
184}
185
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000186// Source Manager
187
Daniel Dunbar16b74492009-11-13 04:12:06 +0000188void CompilerInstance::createSourceManager() {
189 SourceMgr.reset(new SourceManager());
190}
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000191
Daniel Dunbar0fbb3d92009-11-13 05:52:34 +0000192// Preprocessor
193
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000194void CompilerInstance::createPreprocessor() {
195 PP.reset(createPreprocessor(getDiagnostics(), getLangOpts(),
196 getPreprocessorOpts(), getHeaderSearchOpts(),
197 getDependencyOutputOpts(), getTarget(),
Fariborz Jahanian7d957472010-01-13 18:51:17 +0000198 getFrontendOpts(), getSourceManager(),
199 getFileManager()));
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000200}
201
202Preprocessor *
203CompilerInstance::createPreprocessor(Diagnostic &Diags,
204 const LangOptions &LangInfo,
205 const PreprocessorOptions &PPOpts,
206 const HeaderSearchOptions &HSOpts,
207 const DependencyOutputOptions &DepOpts,
208 const TargetInfo &Target,
Fariborz Jahanian7d957472010-01-13 18:51:17 +0000209 const FrontendOptions &FEOpts,
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000210 SourceManager &SourceMgr,
211 FileManager &FileMgr) {
212 // Create a PTH manager if we are using some form of a token cache.
213 PTHManager *PTHMgr = 0;
Daniel Dunbar049d3a02009-11-17 05:52:41 +0000214 if (!PPOpts.TokenCache.empty())
215 PTHMgr = PTHManager::Create(PPOpts.TokenCache, Diags);
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000216
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000217 // Create the Preprocessor.
218 HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr);
219 Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target,
220 SourceMgr, *HeaderInfo, PTHMgr,
221 /*OwnsHeaderSearch=*/true);
222
223 // Note that this is different then passing PTHMgr to Preprocessor's ctor.
224 // That argument is used as the IdentifierInfoLookup argument to
225 // IdentifierTable's ctor.
226 if (PTHMgr) {
227 PTHMgr->setPreprocessor(PP);
228 PP->setPTHManager(PTHMgr);
229 }
230
Fariborz Jahanian7d957472010-01-13 18:51:17 +0000231 InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts);
Daniel Dunbar22dacfa2009-11-13 05:52:11 +0000232
233 // Handle generating dependencies, if requested.
234 if (!DepOpts.OutputFile.empty())
235 AttachDependencyFileGen(*PP, DepOpts);
236
237 return PP;
238}
Daniel Dunbar5eb81002009-11-13 08:20:47 +0000239
240// ASTContext
241
242void CompilerInstance::createASTContext() {
243 Preprocessor &PP = getPreprocessor();
244 Context.reset(new ASTContext(getLangOpts(), PP.getSourceManager(),
245 getTarget(), PP.getIdentifierTable(),
246 PP.getSelectorTable(), PP.getBuiltinInfo(),
247 /*FreeMemory=*/ !getFrontendOpts().DisableFree,
248 /*size_reserve=*/ 0));
249}
Daniel Dunbar0f800392009-11-13 08:21:10 +0000250
251// ExternalASTSource
252
253void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path) {
254 llvm::OwningPtr<ExternalASTSource> Source;
255 Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
256 getPreprocessor(), getASTContext()));
257 getASTContext().setExternalSource(Source);
258}
259
260ExternalASTSource *
261CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
262 const std::string &Sysroot,
263 Preprocessor &PP,
264 ASTContext &Context) {
265 llvm::OwningPtr<PCHReader> Reader;
266 Reader.reset(new PCHReader(PP, &Context,
267 Sysroot.empty() ? 0 : Sysroot.c_str()));
268
269 switch (Reader->ReadPCH(Path)) {
270 case PCHReader::Success:
271 // Set the predefines buffer as suggested by the PCH reader. Typically, the
272 // predefines buffer will be empty.
273 PP.setPredefines(Reader->getSuggestedPredefines());
274 return Reader.take();
275
276 case PCHReader::Failure:
277 // Unrecoverable failure: don't even try to process the input file.
278 break;
279
280 case PCHReader::IgnorePCH:
281 // No suitable PCH file could be found. Return an error.
282 break;
283 }
284
285 return 0;
286}
Daniel Dunbarc2f484f2009-11-13 09:36:05 +0000287
288// Code Completion
289
290void CompilerInstance::createCodeCompletionConsumer() {
291 const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt;
292 CompletionConsumer.reset(
293 createCodeCompletionConsumer(getPreprocessor(),
294 Loc.FileName, Loc.Line, Loc.Column,
295 getFrontendOpts().DebugCodeCompletionPrinter,
296 getFrontendOpts().ShowMacrosInCodeCompletion,
297 llvm::outs()));
Douglas Gregor2b4074f2009-12-01 05:55:20 +0000298
299 if (CompletionConsumer->isOutputBinary() &&
300 llvm::sys::Program::ChangeStdoutToBinary()) {
301 getPreprocessor().getDiagnostics().Report(diag::err_fe_stdout_binary);
302 CompletionConsumer.reset();
303 }
Daniel Dunbarc2f484f2009-11-13 09:36:05 +0000304}
305
Kovarththanan Rajaratnamf79bafa2009-11-29 09:57:35 +0000306void CompilerInstance::createFrontendTimer() {
307 FrontendTimer.reset(new llvm::Timer("Clang front-end timer"));
308}
309
Daniel Dunbarc2f484f2009-11-13 09:36:05 +0000310CodeCompleteConsumer *
311CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
312 const std::string &Filename,
313 unsigned Line,
314 unsigned Column,
315 bool UseDebugPrinter,
316 bool ShowMacros,
317 llvm::raw_ostream &OS) {
318 // Tell the source manager to chop off the given file at a specific
319 // line and column.
320 const FileEntry *Entry = PP.getFileManager().getFile(Filename);
321 if (!Entry) {
322 PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file)
323 << Filename;
324 return 0;
325 }
326
327 // Truncate the named file at the given line/column.
Douglas Gregor29684422009-12-02 06:49:09 +0000328 PP.SetCodeCompletionPoint(Entry, Line, Column);
Daniel Dunbarc2f484f2009-11-13 09:36:05 +0000329
330 // Set up the creation routine for code-completion.
331 if (UseDebugPrinter)
332 return new PrintingCodeCompleteConsumer(ShowMacros, OS);
333 else
334 return new CIndexCodeCompleteConsumer(ShowMacros, OS);
335}
Daniel Dunbara9204832009-11-13 10:37:48 +0000336
337// Output Files
338
339void CompilerInstance::addOutputFile(llvm::StringRef Path,
340 llvm::raw_ostream *OS) {
341 assert(OS && "Attempt to add empty stream to output list!");
342 OutputFiles.push_back(std::make_pair(Path, OS));
343}
344
345void CompilerInstance::ClearOutputFiles(bool EraseFiles) {
346 for (std::list< std::pair<std::string, llvm::raw_ostream*> >::iterator
347 it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) {
348 delete it->second;
349 if (EraseFiles && !it->first.empty())
350 llvm::sys::Path(it->first).eraseFromDisk();
351 }
352 OutputFiles.clear();
353}
354
Daniel Dunbarf482d592009-11-13 18:32:08 +0000355llvm::raw_fd_ostream *
356CompilerInstance::createDefaultOutputFile(bool Binary,
357 llvm::StringRef InFile,
358 llvm::StringRef Extension) {
359 return createOutputFile(getFrontendOpts().OutputFile, Binary,
360 InFile, Extension);
361}
362
363llvm::raw_fd_ostream *
364CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
365 bool Binary,
366 llvm::StringRef InFile,
367 llvm::StringRef Extension) {
368 std::string Error, OutputPathName;
369 llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
370 InFile, Extension,
371 &OutputPathName);
372 if (!OS) {
Daniel Dunbar36043592009-12-03 09:13:30 +0000373 getDiagnostics().Report(diag::err_fe_unable_to_open_output)
374 << OutputPath << Error;
375 return 0;
Daniel Dunbarf482d592009-11-13 18:32:08 +0000376 }
377
378 // Add the output file -- but don't try to remove "-", since this means we are
379 // using stdin.
380 addOutputFile((OutputPathName != "-") ? OutputPathName : "", OS);
381
382 return OS;
383}
384
385llvm::raw_fd_ostream *
386CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
387 std::string &Error,
388 bool Binary,
389 llvm::StringRef InFile,
390 llvm::StringRef Extension,
391 std::string *ResultPathName) {
392 std::string OutFile;
393 if (!OutputPath.empty()) {
394 OutFile = OutputPath;
395 } else if (InFile == "-") {
396 OutFile = "-";
397 } else if (!Extension.empty()) {
398 llvm::sys::Path Path(InFile);
399 Path.eraseSuffix();
400 Path.appendSuffix(Extension);
401 OutFile = Path.str();
402 } else {
403 OutFile = "-";
404 }
405
Daniel Dunbarfc971022009-11-20 22:32:38 +0000406 llvm::OwningPtr<llvm::raw_fd_ostream> OS(
Daniel Dunbarf482d592009-11-13 18:32:08 +0000407 new llvm::raw_fd_ostream(OutFile.c_str(), Error,
Daniel Dunbarfc971022009-11-20 22:32:38 +0000408 (Binary ? llvm::raw_fd_ostream::F_Binary : 0)));
409 if (!Error.empty())
Daniel Dunbarf482d592009-11-13 18:32:08 +0000410 return 0;
411
412 if (ResultPathName)
413 *ResultPathName = OutFile;
414
Daniel Dunbarfc971022009-11-20 22:32:38 +0000415 return OS.take();
Daniel Dunbarf482d592009-11-13 18:32:08 +0000416}
Daniel Dunbarccb6cb62009-11-14 07:53:04 +0000417
418// Initialization Utilities
419
420bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile) {
421 return InitializeSourceManager(InputFile, getDiagnostics(), getFileManager(),
422 getSourceManager(), getFrontendOpts());
423}
424
425bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
426 Diagnostic &Diags,
427 FileManager &FileMgr,
428 SourceManager &SourceMgr,
429 const FrontendOptions &Opts) {
430 // Figure out where to get and map in the main file.
431 if (Opts.EmptyInputOnly) {
432 const char *EmptyStr = "";
433 llvm::MemoryBuffer *SB =
434 llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<empty input>");
435 SourceMgr.createMainFileIDForMemBuffer(SB);
436 } else if (InputFile != "-") {
437 const FileEntry *File = FileMgr.getFile(InputFile);
438 if (File) SourceMgr.createMainFileID(File, SourceLocation());
439 if (SourceMgr.getMainFileID().isInvalid()) {
440 Diags.Report(diag::err_fe_error_reading) << InputFile;
441 return false;
442 }
443 } else {
444 llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
445 SourceMgr.createMainFileIDForMemBuffer(SB);
446 if (SourceMgr.getMainFileID().isInvalid()) {
447 Diags.Report(diag::err_fe_error_reading_stdin);
448 return false;
449 }
450 }
451
452 return true;
453}
Daniel Dunbar0397af22010-01-13 00:48:06 +0000454
455// High-Level Operations
456
457bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
458 assert(hasDiagnostics() && "Diagnostics engine is not initialized!");
459 assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!");
460 assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!");
461
462 // FIXME: Take this as an argument, once all the APIs we used have moved to
463 // taking it as an input instead of hard-coding llvm::errs.
464 llvm::raw_ostream &OS = llvm::errs();
465
466 // Create the target instance.
467 setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), getTargetOpts()));
468 if (!hasTarget())
469 return false;
470
471 // Inform the target of the language options.
472 //
473 // FIXME: We shouldn't need to do this, the target should be immutable once
474 // created. This complexity should be lifted elsewhere.
475 getTarget().setForcedLangOptions(getLangOpts());
476
477 // Validate/process some options.
478 if (getHeaderSearchOpts().Verbose)
479 OS << "clang -cc1 version " CLANG_VERSION_STRING
480 << " based upon " << PACKAGE_STRING
481 << " hosted on " << llvm::sys::getHostTriple() << "\n";
482
483 if (getFrontendOpts().ShowTimers)
484 createFrontendTimer();
485
486 for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) {
487 const std::string &InFile = getFrontendOpts().Inputs[i].second;
488
489 // If we aren't using an AST file, setup the file and source managers and
490 // the preprocessor.
491 bool IsAST = getFrontendOpts().Inputs[i].first == FrontendOptions::IK_AST;
492 if (!IsAST) {
493 if (!i) {
494 // Create a file manager object to provide access to and cache the
495 // filesystem.
496 createFileManager();
497
498 // Create the source manager.
499 createSourceManager();
500 } else {
501 // Reset the ID tables if we are reusing the SourceManager.
502 getSourceManager().clearIDTables();
503 }
504
505 // Create the preprocessor.
506 createPreprocessor();
507 }
508
509 if (Act.BeginSourceFile(*this, InFile, IsAST)) {
510 Act.Execute();
511 Act.EndSourceFile();
512 }
513 }
514
515 if (getDiagnosticOpts().ShowCarets)
516 if (unsigned NumDiagnostics = getDiagnostics().getNumDiagnostics())
517 OS << NumDiagnostics << " diagnostic"
518 << (NumDiagnostics == 1 ? "" : "s")
519 << " generated.\n";
520
521 if (getFrontendOpts().ShowStats) {
522 getFileManager().PrintStats();
523 OS << "\n";
524 }
525
526 // Return the appropriate status when verifying diagnostics.
527 //
528 // FIXME: If we could make getNumErrors() do the right thing, we wouldn't need
529 // this.
530 if (getDiagnosticOpts().VerifyDiagnostics)
531 return !static_cast<VerifyDiagnosticsClient&>(
532 getDiagnosticClient()).HadErrors();
533
534 return !getDiagnostics().getNumErrors();
535}
536
537