CompilerInstance.h revision 0f800391ffbfe3820e1c60246a09a97e5f065179
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> 172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm { 192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass LLVMContext; 202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 235eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic; 252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient; 260f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 2716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 280f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 290f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Source; 3016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass CompilerInstance { 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The LLVM context used for this instance. 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::LLVMContext *LLVMContext; 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar bool OwnsLLVMContext; 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInvocation Invocation; 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<Diagnostic> Diagnostics; 612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics client instance. 632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<DiagnosticClient> DiagClient; 642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The target being compiled for. 662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<TargetInfo> Target; 672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The file manager. 6916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar llvm::OwningPtr<FileManager> FileMgr; 7016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The source manager. 7216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar llvm::OwningPtr<SourceManager> SourceMgr; 7316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// The preprocessor. 7522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar llvm::OwningPtr<Preprocessor> PP; 7622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 775eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// The AST context. 785eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar llvm::OwningPtr<ASTContext> Context; 795eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// Create a new compiler instance with the given LLVM context, optionally 822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// taking ownership of it. 832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInstance(llvm::LLVMContext *_LLVMContext = 0, 842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar bool _OwnsLLVMContext = true); 852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name LLVM Context 882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 90704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasLLVMContext() const { return LLVMContext != 0; } 91704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 92704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar llvm::LLVMContext &getLLVMContext() const { 9322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(LLVMContext && "Compiler instance has no LLVM context!"); 9422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *LLVMContext; 9522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setLLVMContext - Replace the current LLVM context and take ownership of 982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// \arg Value. 992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setLLVMContext(llvm::LLVMContext *Value, bool TakeOwnership = true) { 1002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LLVMContext = Value; 1012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar OwnsLLVMContext = TakeOwnership; 1022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInvocation &getInvocation() { return Invocation; } 1092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CompilerInvocation &getInvocation() const { return Invocation; } 1102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setInvocation(const CompilerInvocation &Value) { Invocation = Value; } 1112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getAnalyzerOpts(); 1182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getAnalyzerOpts(); 1212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 1242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getCodeGenOpts(); 1252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 1272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getCodeGenOpts(); 1282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 1312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDependencyOutputOpts(); 1322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 1342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDependencyOutputOpts(); 1352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 1382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDiagnosticOpts(); 1392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 1412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDiagnosticOpts(); 1422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 1452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getFrontendOpts(); 1462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 1482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getFrontendOpts(); 1492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 1522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getHeaderSearchOpts(); 1532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 1552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getHeaderSearchOpts(); 1562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getLangOpts(); 1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 1622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getLangOpts(); 1632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 1662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOpts(); 1672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 1692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOpts(); 1702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOutputOpts(); 1742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOutputOpts(); 1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 1812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 183704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 184704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 18522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 18622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 18722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 18822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 1892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeDiagnostics - Remove the current diagnostics engine and give ownership 1912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar Diagnostic *takeDiagnostics() { return Diagnostics.take(); } 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnostics - Replace the current diagnostics engine; the compiler 1952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 1962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setDiagnostics(Diagnostic *Value) { Diagnostics.reset(Value); } 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticClient &getDiagnosticClient() const { return *DiagClient; } 1992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeDiagnosticClient - Remove the current diagnostics client and give 2012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// ownership to the caller. 2022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticClient *takeDiagnosticClient() { return DiagClient.take(); } 2032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnosticClient - Replace the current diagnostics client; the compiler 2052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setDiagnosticClient(DiagnosticClient *Value) { 2072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagClient.reset(Value); 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 214704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 215704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 21622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 21722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 21822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 21922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeTarget - Remove the current diagnostics engine and give ownership 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar TargetInfo *takeTarget() { return Target.take(); } 2242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setTarget - Replace the current diagnostics engine; the compiler 2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setTarget(TargetInfo *Value) { Target.reset(Value); } 2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 23016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 23116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 23216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 233704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 234704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 23522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 23622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 23722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 23822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 23916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 24016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeFileManager - Remove the current file manager and give ownership to 24116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// the caller. 24216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar FileManager *takeFileManager() { return FileMgr.take(); } 24316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 24416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setFileManager - Replace the current file manager; the compiler instance 24516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takes ownership of \arg Value. 24616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void setFileManager(FileManager *Value) { FileMgr.reset(Value); } 24716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 24816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 24916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 25016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 25116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 252704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 253704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 25422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 25522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 25622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 25722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 25816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 25916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeSourceManager - Remove the current source manager and give ownership 26016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// to the caller. 26116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar SourceManager *takeSourceManager() { return SourceMgr.take(); } 26216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 26316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setSourceManager - Replace the current source manager; the compiler 26416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// instance takes ownership of \arg Value. 26516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void setSourceManager(SourceManager *Value) { SourceMgr.reset(Value); } 26616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 26716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 26822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 26922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 27022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 271704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 272704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 27322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 27422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 27522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 27622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 27722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 27822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takePreprocessor - Remove the current preprocessor and give ownership to 27922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// the caller. 28022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor *takePreprocessor() { return PP.take(); } 28122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 28222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// setPreprocessor - Replace the current preprocessor; the compiler instance 28322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takes ownership of \arg Value. 28422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void setPreprocessor(Preprocessor *Value) { PP.reset(Value); } 28522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 28622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 2875eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 2885eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 2895eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 290704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 291704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 2925eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 2935eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 2945eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 2955eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 2965eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 2975eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takeASTContext - Remove the current AST context and give ownership to the 2985eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller. 2995eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext *takeASTContext() { return Context.take(); } 3005eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3015eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// setASTContext - Replace the current AST context; the compiler instance 3025eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takes ownership of \arg Value. 3035eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void setASTContext(ASTContext *Value) { Context.reset(Value); } 3045eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3055eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 30616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 30716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 30816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 3090fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 3100fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 3110fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 3120fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Note that this routine also replaces the diagnostic client. 3130fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar void createDiagnostics(int Argc, char **Argv); 3140fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 3150fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 3160fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 3170fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 3180fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 3190fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 3200fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 3215eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Note that this creates an unowned DiagnosticClient, if using directly the 3225eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller is responsible for releaseing the returned Diagnostic's client 3235eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// eventually. 3245eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 3250fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 3260fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar static Diagnostic *createDiagnostics(const DiagnosticOptions &Opts, 3270fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar int Argc, char **Argv); 3280fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 32916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 33016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 33116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 33216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 33316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createSourceManager(); 33416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 33522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 33622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 33722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 33822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 33922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create a Preprocessor object. 34022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 34122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Note that this also creates a new HeaderSearch object which will be owned 34222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// by the resulting Preprocessor. 34322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 34422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// \return The new object on success, or null on failure. 34522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, 34622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const PreprocessorOptions &, 34722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const HeaderSearchOptions &, 34822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const DependencyOutputOptions &, 34922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const TargetInfo &, 35022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &, FileManager &); 35122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 3525eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 3535eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 3545eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3550f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 3560f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 3570f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar void createPCHExternalASTSource(llvm::StringRef Path); 3580f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 3590f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 3600f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 3610f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 3620f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 3630f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot, 3640f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar Preprocessor &PP, ASTContext &Context); 3650f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 36616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 3672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 3682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 3702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 372