CompilerInstance.h revision 360435908c9b90429cfe192fab22854af1d4497c
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" 140f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar#include "llvm/ADT/StringRef.h" 152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#include "llvm/ADT/OwningPtr.h" 1622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar#include <cassert> 17a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <list> 18a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <string> 192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm { 212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass LLVMContext; 22c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass raw_ostream; 23f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream; 24f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer; 252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 285eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 2912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer; 30c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer; 312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic; 322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient; 330f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 3416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 350f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 360f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Source; 3716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass CompilerInstance { 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The LLVM context used for this instance. 602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::LLVMContext *LLVMContext; 612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar bool OwnsLLVMContext; 622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInvocation Invocation; 652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<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 992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 1002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// Create a new compiler instance with the given LLVM context, optionally 1012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// taking ownership of it. 1022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInstance(llvm::LLVMContext *_LLVMContext = 0, 1032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar bool _OwnsLLVMContext = true); 1042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 1052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name LLVM Context 1072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 109704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasLLVMContext() const { return LLVMContext != 0; } 110704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 111704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar llvm::LLVMContext &getLLVMContext() const { 11222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(LLVMContext && "Compiler instance has no LLVM context!"); 11322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *LLVMContext; 11422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 1152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setLLVMContext - Replace the current LLVM context and take ownership of 1172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// \arg Value. 1182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setLLVMContext(llvm::LLVMContext *Value, bool TakeOwnership = true) { 1192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LLVMContext = Value; 1202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar OwnsLLVMContext = TakeOwnership; 1212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInvocation &getInvocation() { return Invocation; } 1282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CompilerInvocation &getInvocation() const { return Invocation; } 1292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setInvocation(const CompilerInvocation &Value) { Invocation = Value; } 1302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getAnalyzerOpts(); 1372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getAnalyzerOpts(); 1402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 1432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getCodeGenOpts(); 1442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 1462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getCodeGenOpts(); 1472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 1502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDependencyOutputOpts(); 1512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 1532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDependencyOutputOpts(); 1542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 1572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDiagnosticOpts(); 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDiagnosticOpts(); 1612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 1642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getFrontendOpts(); 1652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 1672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getFrontendOpts(); 1682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 1712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getHeaderSearchOpts(); 1722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 1742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getHeaderSearchOpts(); 1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 1782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getLangOpts(); 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 1812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getLangOpts(); 1822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 1852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOpts(); 1862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 1882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOpts(); 1892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOutputOpts(); 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 1952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOutputOpts(); 1962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 198d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar TargetOptions &getTargetOpts() { 199d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar return Invocation.getTargetOpts(); 200d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 201d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar const TargetOptions &getTargetOpts() const { 202d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar return Invocation.getTargetOpts(); 203d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 204d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar 2052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 2072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 209704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 210704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 21122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 21222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 21322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 21422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeDiagnostics - Remove the current diagnostics engine and give ownership 2172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar Diagnostic *takeDiagnostics() { return Diagnostics.take(); } 2192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnostics - Replace the current diagnostics engine; the compiler 2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2228a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnostics(Diagnostic *Value); 2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 22481f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar DiagnosticClient &getDiagnosticClient() const { 225c4e265f67e63d870b4a188be5af1bcd848214802Daniel Dunbar assert(DiagClient && "Compiler instance has no diagnostic client!"); 22681f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar return *DiagClient; 22781f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeDiagnosticClient - Remove the current diagnostics client and give 2302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// ownership to the caller. 2312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticClient *takeDiagnosticClient() { return DiagClient.take(); } 2322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnosticClient - Replace the current diagnostics client; the compiler 2342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2358a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnosticClient(DiagnosticClient *Value); 2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 241704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 242704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 24322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 24422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 24522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 24622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeTarget - Remove the current diagnostics engine and give ownership 2492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar TargetInfo *takeTarget() { return Target.take(); } 2512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setTarget - Replace the current diagnostics engine; the compiler 2532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2548a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 2552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 25716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 25816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 25916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 260704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 261704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 26222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 26322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 26422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 26522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 26616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 26716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeFileManager - Remove the current file manager and give ownership to 26816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// the caller. 26916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar FileManager *takeFileManager() { return FileMgr.take(); } 27016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 27116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setFileManager - Replace the current file manager; the compiler instance 27216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takes ownership of \arg Value. 2738a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 27416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 27516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 27616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 27716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 27816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 279704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 280704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 28122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 28222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 28322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 28422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 28516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 28616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeSourceManager - Remove the current source manager and give ownership 28716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// to the caller. 28816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar SourceManager *takeSourceManager() { return SourceMgr.take(); } 28916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 29016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setSourceManager - Replace the current source manager; the compiler 29116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// instance takes ownership of \arg Value. 2928a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 29316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 29416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 29522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 29622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 29722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 298704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 299704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 30022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 30122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 30222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 30322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 30422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 30522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takePreprocessor - Remove the current preprocessor and give ownership to 30622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// the caller. 30722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor *takePreprocessor() { return PP.take(); } 30822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 30922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// setPreprocessor - Replace the current preprocessor; the compiler instance 31022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takes ownership of \arg Value. 3118a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 31222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 31322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 3145eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 3155eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 3165eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 317704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 318704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3195eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 3205eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 3215eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 3225eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 3235eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3245eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takeASTContext - Remove the current AST context and give ownership to the 3255eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller. 3265eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext *takeASTContext() { return Context.take(); } 3275eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3285eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// setASTContext - Replace the current AST context; the compiler instance 3295eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takes ownership of \arg Value. 3308a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 3315eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3325eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 33312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 33412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 33512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 33612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar bool hasASTConsumer() const { return Consumer != 0; } 33712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 33812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 33912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 34012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 34112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 34212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 34312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 34412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 34512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer *takeASTConsumer() { return Consumer.take(); } 34612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 34712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 34812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takes ownership of \arg Value. 34912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar void setASTConsumer(ASTConsumer *Value); 35012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 35112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 352c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 353c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 354c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 355c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 356c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 357c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 358c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 359c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 360c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 361c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 362c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 363c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// takeCodeCompletionConsumer - Remove the current code completion consumer 364c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// and give ownership to the caller. 365c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer *takeCodeCompletionConsumer() { 366c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return CompletionConsumer.take(); 367c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 368c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 369c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 370c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// the compiler instance takes ownership of \arg Value. 3718a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 372c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 373c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 374f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// @name Frontend timer 375f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// { 376f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 377f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam bool hasFrontendTimer() const { return FrontendTimer != 0; } 378f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 379f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::Timer &getFrontendTimer() const { 380f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam assert(FrontendTimer && "Compiler instance has no frontend timer!"); 381f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam return *FrontendTimer; 382f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 383f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 384f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// } 385a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 386a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 387a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 388a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// getOutputFileList - Get the list of (path, output stream) pairs of output 389a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// files; the path may be empty but the stream will always be non-null. 390a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar const std::list< std::pair<std::string, 391a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar llvm::raw_ostream*> > &getOutputFileList() const; 392a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 393a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 394a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 395a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param Path - The path to the output file, or empty. 396a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param OS - The output stream, which should be non-null. 397a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar void addOutputFile(llvm::StringRef Path, llvm::raw_ostream *OS); 398a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 399a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// ClearOutputFiles - Clear the output file list, destroying the contained 400a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 401a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 402a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 403a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar void ClearOutputFiles(bool EraseFiles); 404a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 405a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 40616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 40716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 40816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4090fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 4100fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 4110fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4120fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Note that this routine also replaces the diagnostic client. 4130fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar void createDiagnostics(int Argc, char **Argv); 4140fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 4150fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 4160fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4170fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 4180fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 4190fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 4200fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4215eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Note that this creates an unowned DiagnosticClient, if using directly the 4225eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller is responsible for releaseing the returned Diagnostic's client 4235eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// eventually. 4245eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 4250fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 4260fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar static Diagnostic *createDiagnostics(const DiagnosticOptions &Opts, 4270fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar int Argc, char **Argv); 4280fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 42916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 43016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 43116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 43216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 43316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createSourceManager(); 43416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 43522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 43622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 43722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 43822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 43922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create a Preprocessor object. 44022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 44122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Note that this also creates a new HeaderSearch object which will be owned 44222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// by the resulting Preprocessor. 44322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 44422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// \return The new object on success, or null on failure. 44522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, 44622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const PreprocessorOptions &, 44722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const HeaderSearchOptions &, 44822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const DependencyOutputOptions &, 44922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const TargetInfo &, 45022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &, FileManager &); 45122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 4525eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 4535eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 4545eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 4550f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 4560f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 4570f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar void createPCHExternalASTSource(llvm::StringRef Path); 4580f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 4590f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 4600f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 4610f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 4620f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 4630f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot, 4640f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar Preprocessor &PP, ASTContext &Context); 4650f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 466c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 467c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 468c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 469c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 470c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 471c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 472c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg 473c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// OS. 474c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar static CodeCompleteConsumer * 475c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 476c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar unsigned Line, unsigned Column, 477c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool UseDebugPrinter, bool ShowMacros, 478c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar llvm::raw_ostream &OS); 479c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 480f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// Create the frontend timer and replace any existing one with it. 481f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam void createFrontendTimer(); 482f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 483f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 484f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 485360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 486360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 487f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 488f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "", 489f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 490f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 491f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 492f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 493360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 494360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 495f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 496f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, bool Binary = true, 497f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef BaseInput = "", 498f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 499f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 500f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 501f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 502f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// If \arg OutputPath is empty, then createOutputFile will derive an output 503f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// path location as \arg BaseInput, with any suffix removed, and \arg 504f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Extension appended. 505f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 506f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 507f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Error [out] - On failure, the error message. 508f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param BaseInput - If \arg OutputPath is empty, the input path name to use 509f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 510f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 511f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 512f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 513f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 514f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar static llvm::raw_fd_ostream * 515f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, std::string &Error, 516f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar bool Binary = true, llvm::StringRef BaseInput = "", 517f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = "", 518f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar std::string *ResultPathName = 0); 519f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 52016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 521ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 522ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 523ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 524ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 525ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 526ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 527ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 528ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar bool InitializeSourceManager(llvm::StringRef InputFile); 529ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 530ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 531ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 532ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 533ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 534ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar static bool InitializeSourceManager(llvm::StringRef InputFile, 535ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar Diagnostic &Diags, 536ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar FileManager &FileMgr, 537ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar SourceManager &SourceMgr, 538ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar const FrontendOptions &Opts); 539ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 540ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 5412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 5422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 5432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 5442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 5452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 546