CompilerInstance.h revision ccb6cb6fd9e48697564d536b07397b95dfc28d5b
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; 242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 275eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 2812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer; 29c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer; 302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic; 312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient; 320f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 3316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 340f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 350f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Source; 3616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass CompilerInstance { 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The LLVM context used for this instance. 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::LLVMContext *LLVMContext; 602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar bool OwnsLLVMContext; 612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInvocation Invocation; 642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<Diagnostic> Diagnostics; 672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics client instance. 692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<DiagnosticClient> DiagClient; 702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The target being compiled for. 722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar llvm::OwningPtr<TargetInfo> Target; 732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 7416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The file manager. 7516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar llvm::OwningPtr<FileManager> FileMgr; 7616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The source manager. 7816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar llvm::OwningPtr<SourceManager> SourceMgr; 7916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 8022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// The preprocessor. 8122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar llvm::OwningPtr<Preprocessor> PP; 8222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 835eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// The AST context. 845eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar llvm::OwningPtr<ASTContext> Context; 855eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 8612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// The AST consumer. 8712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar llvm::OwningPtr<ASTConsumer> Consumer; 8812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 89c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// The code completion consumer. 90c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer; 91c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 92a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// The list of active output files. 93a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles; 94a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// Create a new compiler instance with the given LLVM context, optionally 972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// taking ownership of it. 982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInstance(llvm::LLVMContext *_LLVMContext = 0, 992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar bool _OwnsLLVMContext = true); 1002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 1012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name LLVM Context 1032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 105704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasLLVMContext() const { return LLVMContext != 0; } 106704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 107704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar llvm::LLVMContext &getLLVMContext() const { 10822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(LLVMContext && "Compiler instance has no LLVM context!"); 10922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *LLVMContext; 11022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 1112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setLLVMContext - Replace the current LLVM context and take ownership of 1132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// \arg Value. 1142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setLLVMContext(llvm::LLVMContext *Value, bool TakeOwnership = true) { 1152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LLVMContext = Value; 1162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar OwnsLLVMContext = TakeOwnership; 1172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CompilerInvocation &getInvocation() { return Invocation; } 1242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CompilerInvocation &getInvocation() const { return Invocation; } 1252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar void setInvocation(const CompilerInvocation &Value) { Invocation = Value; } 1262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getAnalyzerOpts(); 1332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getAnalyzerOpts(); 1362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 1392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getCodeGenOpts(); 1402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 1422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getCodeGenOpts(); 1432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 1462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDependencyOutputOpts(); 1472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 1492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDependencyOutputOpts(); 1502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 1532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDiagnosticOpts(); 1542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 1562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getDiagnosticOpts(); 1572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getFrontendOpts(); 1612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 1632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getFrontendOpts(); 1642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 1672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getHeaderSearchOpts(); 1682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 1702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getHeaderSearchOpts(); 1712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 1742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getLangOpts(); 1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getLangOpts(); 1782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 1812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOpts(); 1822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 1842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOpts(); 1852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 1882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOutputOpts(); 1892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 1912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar return Invocation.getPreprocessorOutputOpts(); 1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 1962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 198704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 199704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 20022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 20122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 20222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 20322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeDiagnostics - Remove the current diagnostics engine and give ownership 2062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar Diagnostic *takeDiagnostics() { return Diagnostics.take(); } 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnostics - Replace the current diagnostics engine; the compiler 2102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2118a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnostics(Diagnostic *Value); 2122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 21381f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar DiagnosticClient &getDiagnosticClient() const { 21481f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar assert(Target && "Compiler instance has no diagnostic client!"); 21581f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar return *DiagClient; 21681f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 2172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeDiagnosticClient - Remove the current diagnostics client and give 2192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// ownership to the caller. 2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticClient *takeDiagnosticClient() { return DiagClient.take(); } 2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnosticClient - Replace the current diagnostics client; the compiler 2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2248a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnosticClient(DiagnosticClient *Value); 2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 230704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 231704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 23222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 23322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 23422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 23522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeTarget - Remove the current diagnostics engine and give ownership 2382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar TargetInfo *takeTarget() { return Target.take(); } 2402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setTarget - Replace the current diagnostics engine; the compiler 2422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2438a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 2442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 24616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 24716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 24816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 249704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 250704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 25122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 25222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 25322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 25422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 25516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 25616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeFileManager - Remove the current file manager and give ownership to 25716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// the caller. 25816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar FileManager *takeFileManager() { return FileMgr.take(); } 25916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 26016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setFileManager - Replace the current file manager; the compiler instance 26116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takes ownership of \arg Value. 2628a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 26316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 26416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 26516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 26616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 26716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 268704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 269704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 27022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 27122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 27222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 27322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 27416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 27516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeSourceManager - Remove the current source manager and give ownership 27616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// to the caller. 27716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar SourceManager *takeSourceManager() { return SourceMgr.take(); } 27816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 27916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setSourceManager - Replace the current source manager; the compiler 28016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// instance takes ownership of \arg Value. 2818a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 28216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 28316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 28422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 28522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 28622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 287704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 288704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 28922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 29022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 29122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 29222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 29322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 29422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takePreprocessor - Remove the current preprocessor and give ownership to 29522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// the caller. 29622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor *takePreprocessor() { return PP.take(); } 29722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 29822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// setPreprocessor - Replace the current preprocessor; the compiler instance 29922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takes ownership of \arg Value. 3008a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 30122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 30222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 3035eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 3045eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 3055eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 306704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 307704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3085eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 3095eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 3105eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 3115eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 3125eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3135eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takeASTContext - Remove the current AST context and give ownership to the 3145eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller. 3155eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext *takeASTContext() { return Context.take(); } 3165eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3175eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// setASTContext - Replace the current AST context; the compiler instance 3185eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takes ownership of \arg Value. 3198a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 3205eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3215eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 32212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 32312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 32412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 32512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar bool hasASTConsumer() const { return Consumer != 0; } 32612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 32712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 32812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 32912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 33012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 33112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 33212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 33312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 33412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer *takeASTConsumer() { return Consumer.take(); } 33512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 33612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 33712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takes ownership of \arg Value. 33812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar void setASTConsumer(ASTConsumer *Value); 33912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 34012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 341c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 342c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 343c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 344c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 345c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 346c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 347c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 348c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 349c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 350c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 351c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 352c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// takeCodeCompletionConsumer - Remove the current code completion consumer 353c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// and give ownership to the caller. 354c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer *takeCodeCompletionConsumer() { 355c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return CompletionConsumer.take(); 356c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 357c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 358c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 359c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// the compiler instance takes ownership of \arg Value. 3608a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 361c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 362c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 363a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 364a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 365a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 366a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// getOutputFileList - Get the list of (path, output stream) pairs of output 367a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// files; the path may be empty but the stream will always be non-null. 368a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar const std::list< std::pair<std::string, 369a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar llvm::raw_ostream*> > &getOutputFileList() const; 370a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 371a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 372a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 373a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param Path - The path to the output file, or empty. 374a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param OS - The output stream, which should be non-null. 375a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar void addOutputFile(llvm::StringRef Path, llvm::raw_ostream *OS); 376a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 377a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// ClearOutputFiles - Clear the output file list, destroying the contained 378a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 379a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 380a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 381a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar void ClearOutputFiles(bool EraseFiles); 382a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 383a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 38416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 38516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 38616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 3870fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 3880fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 3890fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 3900fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Note that this routine also replaces the diagnostic client. 3910fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar void createDiagnostics(int Argc, char **Argv); 3920fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 3930fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 3940fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 3950fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 3960fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 3970fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 3980fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 3995eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Note that this creates an unowned DiagnosticClient, if using directly the 4005eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller is responsible for releaseing the returned Diagnostic's client 4015eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// eventually. 4025eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 4030fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 4040fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar static Diagnostic *createDiagnostics(const DiagnosticOptions &Opts, 4050fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar int Argc, char **Argv); 4060fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 40716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 40816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 40916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 41016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 41116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createSourceManager(); 41216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 41322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 41422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 41522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 41622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 41722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create a Preprocessor object. 41822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 41922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Note that this also creates a new HeaderSearch object which will be owned 42022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// by the resulting Preprocessor. 42122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 42222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// \return The new object on success, or null on failure. 42322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, 42422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const PreprocessorOptions &, 42522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const HeaderSearchOptions &, 42622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const DependencyOutputOptions &, 42722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const TargetInfo &, 42822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &, FileManager &); 42922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 4305eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 4315eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 4325eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 4330f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 4340f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 4350f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar void createPCHExternalASTSource(llvm::StringRef Path); 4360f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 4370f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 4380f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 4390f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 4400f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 4410f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot, 4420f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar Preprocessor &PP, ASTContext &Context); 4430f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 444c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 445c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 446c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 447c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 448c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 449c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 450c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg 451c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// OS. 452c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar static CodeCompleteConsumer * 453c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 454c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar unsigned Line, unsigned Column, 455c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool UseDebugPrinter, bool ShowMacros, 456c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar llvm::raw_ostream &OS); 457c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 458f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 459f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 460f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 461f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "", 462f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 463f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 464f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 465f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 466f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 467f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, bool Binary = true, 468f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef BaseInput = "", 469f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 470f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 471f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 472f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 473f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// If \arg OutputPath is empty, then createOutputFile will derive an output 474f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// path location as \arg BaseInput, with any suffix removed, and \arg 475f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Extension appended. 476f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 477f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 478f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Error [out] - On failure, the error message. 479f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param BaseInput - If \arg OutputPath is empty, the input path name to use 480f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 481f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 482f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 483f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 484f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 485f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar static llvm::raw_fd_ostream * 486f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, std::string &Error, 487f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar bool Binary = true, llvm::StringRef BaseInput = "", 488f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = "", 489f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar std::string *ResultPathName = 0); 490f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 49116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 492ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 493ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 494ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 495ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 496ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 497ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 498ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 499ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar bool InitializeSourceManager(llvm::StringRef InputFile); 500ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 501ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 502ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 503ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 504ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 505ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar static bool InitializeSourceManager(llvm::StringRef InputFile, 506ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar Diagnostic &Diags, 507ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar FileManager &FileMgr, 508ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar SourceManager &SourceMgr, 509ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar const FrontendOptions &Opts); 510ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 511ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 5122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 5132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 5142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 5152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 5162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 517