CompilerInstance.h revision 28019772db70d4547be05a042eb950bc910f134f
12a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
22a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//
32a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//                     The LLVM Compiler Infrastructure
42a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//
52a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// This file is distributed under the University of Illinois Open Source
62a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// License. See LICENSE.TXT for details.
72a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//
82a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//===----------------------------------------------------------------------===//
92a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#include "clang/Frontend/CompilerInvocation.h"
1428019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h"
150f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar#include "llvm/ADT/StringRef.h"
162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#include "llvm/ADT/OwningPtr.h"
1722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar#include <cassert>
18a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <list>
19a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <string>
202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm {
222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass LLVMContext;
23c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass raw_ostream;
24f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream;
25f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer;
262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}
272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang {
295eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext;
3012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer;
31c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer;
322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic;
332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient;
340f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource;
3516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager;
360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbarclass FrontendAction;
370f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor;
3816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager;
392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo;
402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang
422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler.
432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///
442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes:
452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///  (1) It manages the various objects which are necessary to run the compiler,
462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///      for example the preprocessor, the target information, and the AST
472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///      context.
482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///  (2) It provides utility routines for constructing and manipulating the
492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///      common Clang objects.
502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///
512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it
522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the
532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance.
542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///
552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them
562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions
572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects,
582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects.
592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass CompilerInstance {
602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The LLVM context used for this instance.
6142e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar  llvm::OwningPtr<llvm::LLVMContext> LLVMContext;
622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The options used in this compiler instance.
646228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  llvm::OwningPtr<CompilerInvocation> Invocation;
652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The diagnostics engine instance.
6728019772db70d4547be05a042eb950bc910f134fDouglas Gregor  llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics;
682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The diagnostics client instance.
702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  llvm::OwningPtr<DiagnosticClient> DiagClient;
712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The target being compiled for.
732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  llvm::OwningPtr<TargetInfo> Target;
742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
7516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// The file manager.
7616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  llvm::OwningPtr<FileManager> FileMgr;
7716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
7816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// The source manager.
7916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  llvm::OwningPtr<SourceManager> SourceMgr;
8016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
8122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// The preprocessor.
8222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  llvm::OwningPtr<Preprocessor> PP;
8322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
845eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// The AST context.
855eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  llvm::OwningPtr<ASTContext> Context;
865eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
8712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// The AST consumer.
8812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  llvm::OwningPtr<ASTConsumer> Consumer;
8912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
90c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// The code completion consumer.
91c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer;
92c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
93f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// The frontend timer
94f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  llvm::OwningPtr<llvm::Timer> FrontendTimer;
95f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
96a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// The list of active output files.
97a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles;
98a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
9942e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar  void operator=(const CompilerInstance &);  // DO NOT IMPLEMENT
10042e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar  CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT
1012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic:
10242e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar  CompilerInstance();
1032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  ~CompilerInstance();
1042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1050397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// @name High-Level Operations
1060397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// {
1070397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar
1080397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// ExecuteAction - Execute the provided action against the compiler's
1090397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// CompilerInvocation object.
1100397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1110397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// This function makes the following assumptions:
1120397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1130397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - The invocation options should be initialized. This function does not
1140397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    handle the '-help' or '-version' options, clients should handle those
1150397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    directly.
1160397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1170397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - The diagnostics engine should have already been created by the client.
1180397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1190397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - No other CompilerInstance state should have been initialized (this is
1200397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    an unchecked error).
1210397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1220397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - Clients should have initialized any LLVM target features that may be
1230397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    required.
1240397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1250397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - Clients should eventually call llvm_shutdown() upon the completion of
1260397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    this routine to ensure that any managed objects are properly destroyed.
1270397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1280397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// Note that this routine may write output to 'stderr'.
1290397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1300397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// \param Act - The action to execute.
1310397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// \return - True on success.
1320397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  //
1330397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // FIXME: This function should take the stream to write any debugging /
1340397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // verbose output to as an argument.
1350397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  //
1360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
1370397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // of the context or else not CompilerInstance specific.
1380397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  bool ExecuteAction(FrontendAction &Act);
1390397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar
1400397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// }
1412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name LLVM Context
1422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
1432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
144704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasLLVMContext() const { return LLVMContext != 0; }
145704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
146704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  llvm::LLVMContext &getLLVMContext() const {
14722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(LLVMContext && "Compiler instance has no LLVM context!");
14822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *LLVMContext;
14922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
1502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
15142e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar  llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); }
15242e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar
1532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// setLLVMContext - Replace the current LLVM context and take ownership of
1542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// \arg Value.
15542e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar  void setLLVMContext(llvm::LLVMContext *Value);
1562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Compiler Invocation and Options
1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1616228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  bool hasInvocation() const { return Invocation != 0; }
1626228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar
1636228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  CompilerInvocation &getInvocation() {
1646228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    assert(Invocation && "Compiler instance has no invocation!");
1656228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return *Invocation;
1666228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  }
1676228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar
1686228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  CompilerInvocation *takeInvocation() { return Invocation.take(); }
1696228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar
1706228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  /// setInvocation - Replace the current invocation; the compiler instance
1716228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  /// takes ownership of \arg Value.
1726228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  void setInvocation(CompilerInvocation *Value);
1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Forwarding Methods
1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  AnalyzerOptions &getAnalyzerOpts() {
1796228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getAnalyzerOpts();
1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
1812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const AnalyzerOptions &getAnalyzerOpts() const {
1826228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getAnalyzerOpts();
1832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
1842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  CodeGenOptions &getCodeGenOpts() {
1866228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getCodeGenOpts();
1872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
1882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const CodeGenOptions &getCodeGenOpts() const {
1896228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getCodeGenOpts();
1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
1912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  DependencyOutputOptions &getDependencyOutputOpts() {
1936228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDependencyOutputOpts();
1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
1952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const DependencyOutputOptions &getDependencyOutputOpts() const {
1966228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDependencyOutputOpts();
1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
1982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  DiagnosticOptions &getDiagnosticOpts() {
2006228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDiagnosticOpts();
2012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const DiagnosticOptions &getDiagnosticOpts() const {
2036228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDiagnosticOpts();
2042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  FrontendOptions &getFrontendOpts() {
2076228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getFrontendOpts();
2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const FrontendOptions &getFrontendOpts() const {
2106228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getFrontendOpts();
2112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  HeaderSearchOptions &getHeaderSearchOpts() {
2146228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getHeaderSearchOpts();
2152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const HeaderSearchOptions &getHeaderSearchOpts() const {
2176228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getHeaderSearchOpts();
2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  LangOptions &getLangOpts() {
2216228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getLangOpts();
2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const LangOptions &getLangOpts() const {
2246228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getLangOpts();
2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  PreprocessorOptions &getPreprocessorOpts() {
2286228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOpts();
2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const PreprocessorOptions &getPreprocessorOpts() const {
2316228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOpts();
2322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  PreprocessorOutputOptions &getPreprocessorOutputOpts() {
2356228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOutputOpts();
2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
2386228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOutputOpts();
2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
241d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  TargetOptions &getTargetOpts() {
2426228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getTargetOpts();
243d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  }
244d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  const TargetOptions &getTargetOpts() const {
2456228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getTargetOpts();
246d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  }
247d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar
2482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
2492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Diagnostics Engine
2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
2512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
252704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasDiagnostics() const { return Diagnostics != 0; }
253704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
25422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  Diagnostic &getDiagnostics() const {
25522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(Diagnostics && "Compiler instance has no diagnostics!");
25622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *Diagnostics;
25722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
2582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// setDiagnostics - Replace the current diagnostics engine; the compiler
2602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// instance takes ownership of \arg Value.
2618a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setDiagnostics(Diagnostic *Value);
2622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
26381f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar  DiagnosticClient &getDiagnosticClient() const {
264c4e265f67e63d870b4a188be5af1bcd848214802Daniel Dunbar    assert(DiagClient && "Compiler instance has no diagnostic client!");
26581f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar    return *DiagClient;
26681f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar  }
2672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// takeDiagnosticClient - Remove the current diagnostics client and give
2692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// ownership to the caller.
2702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  DiagnosticClient *takeDiagnosticClient() { return DiagClient.take(); }
2712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// setDiagnosticClient - Replace the current diagnostics client; the compiler
2732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// instance takes ownership of \arg Value.
2748a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setDiagnosticClient(DiagnosticClient *Value);
2752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
2772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Target Info
2782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
2792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
280704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasTarget() const { return Target != 0; }
281704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
28222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  TargetInfo &getTarget() const {
28322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(Target && "Compiler instance has no target!");
28422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *Target;
28522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
2862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// takeTarget - Remove the current diagnostics engine and give ownership
2882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// to the caller.
2892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  TargetInfo *takeTarget() { return Target.take(); }
2902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// setTarget - Replace the current diagnostics engine; the compiler
2922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// instance takes ownership of \arg Value.
2938a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setTarget(TargetInfo *Value);
2942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
29616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// @name File Manager
29716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// {
29816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
299704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasFileManager() const { return FileMgr != 0; }
300704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
30122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  FileManager &getFileManager() const {
30222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(FileMgr && "Compiler instance has no file manager!");
30322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *FileMgr;
30422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
30516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
30616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// takeFileManager - Remove the current file manager and give ownership to
30716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// the caller.
30816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  FileManager *takeFileManager() { return FileMgr.take(); }
30916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
31016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// setFileManager - Replace the current file manager; the compiler instance
31116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// takes ownership of \arg Value.
3128a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setFileManager(FileManager *Value);
31316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
31416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// }
31516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// @name Source Manager
31616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// {
31716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
318704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasSourceManager() const { return SourceMgr != 0; }
319704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
32022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  SourceManager &getSourceManager() const {
32122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(SourceMgr && "Compiler instance has no source manager!");
32222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *SourceMgr;
32322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
32416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
32516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// takeSourceManager - Remove the current source manager and give ownership
32616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// to the caller.
32716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  SourceManager *takeSourceManager() { return SourceMgr.take(); }
32816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
32916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// setSourceManager - Replace the current source manager; the compiler
33016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// instance takes ownership of \arg Value.
3318a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setSourceManager(SourceManager *Value);
33216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
33316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// }
33422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// @name Preprocessor
33522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// {
33622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
337704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasPreprocessor() const { return PP != 0; }
338704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
33922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  Preprocessor &getPreprocessor() const {
34022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(PP && "Compiler instance has no preprocessor!");
34122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *PP;
34222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
34322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
34422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// takePreprocessor - Remove the current preprocessor and give ownership to
34522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// the caller.
34622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  Preprocessor *takePreprocessor() { return PP.take(); }
34722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
34822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// setPreprocessor - Replace the current preprocessor; the compiler instance
34922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// takes ownership of \arg Value.
3508a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setPreprocessor(Preprocessor *Value);
35122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
35222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// }
3535eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// @name ASTContext
3545eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// {
3555eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
356704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar  bool hasASTContext() const { return Context != 0; }
357704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
3585eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  ASTContext &getASTContext() const {
3595eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar    assert(Context && "Compiler instance has no AST context!");
3605eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar    return *Context;
3615eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  }
3625eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
3635eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// takeASTContext - Remove the current AST context and give ownership to the
3645eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// caller.
3655eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  ASTContext *takeASTContext() { return Context.take(); }
3665eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
3675eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// setASTContext - Replace the current AST context; the compiler instance
3685eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// takes ownership of \arg Value.
3698a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setASTContext(ASTContext *Value);
3705eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
3715eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// }
37212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// @name ASTConsumer
37312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// {
37412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
37512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  bool hasASTConsumer() const { return Consumer != 0; }
37612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
37712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  ASTConsumer &getASTConsumer() const {
37812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar    assert(Consumer && "Compiler instance has no AST consumer!");
37912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar    return *Consumer;
38012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  }
38112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
38212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// takeASTConsumer - Remove the current AST consumer and give ownership to
38312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// the caller.
38412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  ASTConsumer *takeASTConsumer() { return Consumer.take(); }
38512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
38612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// setASTConsumer - Replace the current AST consumer; the compiler instance
38712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// takes ownership of \arg Value.
38812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  void setASTConsumer(ASTConsumer *Value);
38912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
39012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// }
391c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// @name Code Completion
392c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// {
393c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
394c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; }
395c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
396c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  CodeCompleteConsumer &getCodeCompletionConsumer() const {
397c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar    assert(CompletionConsumer &&
398c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar           "Compiler instance has no code completion consumer!");
399c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar    return *CompletionConsumer;
400c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  }
401c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
402c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// takeCodeCompletionConsumer - Remove the current code completion consumer
403c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// and give ownership to the caller.
404c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  CodeCompleteConsumer *takeCodeCompletionConsumer() {
405c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar    return CompletionConsumer.take();
406c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  }
407c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
408c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// setCodeCompletionConsumer - Replace the current code completion consumer;
409c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// the compiler instance takes ownership of \arg Value.
4108a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
411c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
412c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// }
413f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// @name Frontend timer
414f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// {
415f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
416f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  bool hasFrontendTimer() const { return FrontendTimer != 0; }
417f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
418f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  llvm::Timer &getFrontendTimer() const {
419f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam    assert(FrontendTimer && "Compiler instance has no frontend timer!");
420f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam    return *FrontendTimer;
421f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  }
422f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
423f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// }
424a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// @name Output Files
425a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// {
426a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
427a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// getOutputFileList - Get the list of (path, output stream) pairs of output
428a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// files; the path may be empty but the stream will always be non-null.
429a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  const std::list< std::pair<std::string,
430a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar                             llvm::raw_ostream*> > &getOutputFileList() const;
431a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
432a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// addOutputFile - Add an output file onto the list of tracked output files.
433a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  ///
434a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// \param Path - The path to the output file, or empty.
435a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// \param OS - The output stream, which should be non-null.
436a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  void addOutputFile(llvm::StringRef Path, llvm::raw_ostream *OS);
437a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
438e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam  /// clearOutputFiles - Clear the output file list, destroying the contained
439a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// output streams.
440a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  ///
441a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// \param EraseFiles - If true, attempt to erase the files from disk.
442e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam  void clearOutputFiles(bool EraseFiles);
443a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
444a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// }
44516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// @name Construction Utility Methods
44616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// {
44716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
4480fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// Create the diagnostics engine using the invocation's diagnostic options
4490fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// and replace any existing one with it.
4500fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  ///
4510fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// Note that this routine also replaces the diagnostic client.
4520fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  void createDiagnostics(int Argc, char **Argv);
4530fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar
4540fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// Create a Diagnostic object with a the TextDiagnosticPrinter.
4550fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  ///
4560fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// The \arg Argc and \arg Argv arguments are used only for logging purposes,
4570fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// when the diagnostic options indicate that the compiler should output
4580fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// logging information.
4590fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  ///
4605eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// Note that this creates an unowned DiagnosticClient, if using directly the
461bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  /// caller is responsible for releasing the returned Diagnostic's client
4625eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// eventually.
4635eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  ///
464bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  /// \param Opts - The diagnostic options; note that the created text
465bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  /// diagnostic object contains a reference to these options and its lifetime
466bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  /// must extend past that of the diagnostic engine.
467bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  ///
4680fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// \return The new object on success, or null on failure.
46928019772db70d4547be05a042eb950bc910f134fDouglas Gregor  static llvm::IntrusiveRefCntPtr<Diagnostic>
47028019772db70d4547be05a042eb950bc910f134fDouglas Gregor  createDiagnostics(const DiagnosticOptions &Opts, int Argc, char **Argv);
4710fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar
47216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// Create the file manager and replace any existing one with it.
47316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  void createFileManager();
47416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
47516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// Create the source manager and replace any existing one with it.
47616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  void createSourceManager();
47716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
47822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// Create the preprocessor, using the invocation, file, and source managers,
47922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// and replace any existing one with it.
48022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  void createPreprocessor();
48122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
48222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// Create a Preprocessor object.
48322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  ///
48422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// Note that this also creates a new HeaderSearch object which will be owned
48522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// by the resulting Preprocessor.
48622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  ///
48722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// \return The new object on success, or null on failure.
48822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &,
48922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar                                          const PreprocessorOptions &,
49022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar                                          const HeaderSearchOptions &,
49122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar                                          const DependencyOutputOptions &,
49222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar                                          const TargetInfo &,
4937d957472ef9a09048c03d8a11028536f908c18b9Fariborz Jahanian                                          const FrontendOptions &,
49422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar                                          SourceManager &, FileManager &);
49522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
4965eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// Create the AST context.
4975eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  void createASTContext();
4985eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
4990f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// Create an external AST source to read a PCH file and attach it to the AST
5000f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// context.
5010f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  void createPCHExternalASTSource(llvm::StringRef Path);
5020f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar
5030f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// Create an external AST source to read a PCH file.
5040f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  ///
5050f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// \return - The new object on success, or null on failure.
5060f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  static ExternalASTSource *
5070f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
5080f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar                             Preprocessor &PP, ASTContext &Context);
5090f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar
510c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// Create a code completion consumer using the invocation; note that this
511c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// will cause the source manager to truncate the input source file at the
512c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// completion point.
513c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  void createCodeCompletionConsumer();
514c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
515c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// Create a code completion consumer to print code completion results, at
516c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg
517c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// OS.
518c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  static CodeCompleteConsumer *
519c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
520c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar                               unsigned Line, unsigned Column,
521c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar                               bool UseDebugPrinter, bool ShowMacros,
522c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar                               llvm::raw_ostream &OS);
523c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
524f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// Create the frontend timer and replace any existing one with it.
525f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  void createFrontendTimer();
526f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
527f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Create the default output file (from the invocation's options) and add it
528f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// to the list of tracked output files.
529360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  ///
530360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  /// \return - Null on error.
531f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  llvm::raw_fd_ostream *
532f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "",
533f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar                          llvm::StringRef Extension = "");
534f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar
535f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Create a new output file and add it to the list of tracked output files,
536f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// optionally deriving the output path name.
537360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  ///
538360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  /// \return - Null on error.
539f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  llvm::raw_fd_ostream *
540f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  createOutputFile(llvm::StringRef OutputPath, bool Binary = true,
541f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar                   llvm::StringRef BaseInput = "",
542f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar                   llvm::StringRef Extension = "");
543f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar
544f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Create a new output file, optionally deriving the output path name.
545f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  ///
546f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// If \arg OutputPath is empty, then createOutputFile will derive an output
547f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// path location as \arg BaseInput, with any suffix removed, and \arg
548f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Extension appended.
549f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  ///
550f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param OutputPath - If given, the path to the output file.
551f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param Error [out] - On failure, the error message.
552f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param BaseInput - If \arg OutputPath is empty, the input path name to use
553f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// for deriving the output path.
554f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param Extension - The extension to use for derived output names.
555f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param Binary - The mode to open the file in.
556f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param ResultPathName [out] - If given, the result path name will be
557f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// stored here on success.
558f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  static llvm::raw_fd_ostream *
559f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  createOutputFile(llvm::StringRef OutputPath, std::string &Error,
560f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar                   bool Binary = true, llvm::StringRef BaseInput = "",
561f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar                   llvm::StringRef Extension = "",
562f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar                   std::string *ResultPathName = 0);
563f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar
56416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// }
565ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// @name Initialization Utility Methods
566ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// {
567ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar
568ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// InitializeSourceManager - Initialize the source manager to set InputFile
569ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// as the main file.
570ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  ///
571ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// \return True on success.
572ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  bool InitializeSourceManager(llvm::StringRef InputFile);
573ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar
574ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// InitializeSourceManager - Initialize the source manager to set InputFile
575ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// as the main file.
576ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  ///
577ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// \return True on success.
578ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  static bool InitializeSourceManager(llvm::StringRef InputFile,
579ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar                                      Diagnostic &Diags,
580ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar                                      FileManager &FileMgr,
581ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar                                      SourceManager &SourceMgr,
582ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar                                      const FrontendOptions &Opts);
583ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar
584ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// }
5852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar};
5862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
5872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang
5882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
5892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif
590