CompilerInstance.h revision c43b54cbc10654ed59de797898042e1a05265246
12a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===// 22a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// 32a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// The LLVM Compiler Infrastructure 42a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// 52a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// This file is distributed under the University of Illinois Open Source 62a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// License. See LICENSE.TXT for details. 72a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar// 82a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar//===----------------------------------------------------------------------===// 92a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ 112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ 122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#include "clang/Frontend/CompilerInvocation.h" 1428019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 150f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar#include "llvm/ADT/StringRef.h" 162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#include "llvm/ADT/OwningPtr.h" 1722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar#include <cassert> 18a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <list> 19a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <string> 202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm { 222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass LLVMContext; 23c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass raw_ostream; 24f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream; 25f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer; 262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 295eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 3012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer; 31c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer; 322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic; 332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient; 340f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 3516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbarclass FrontendAction; 37c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader; 380f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 39f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregorclass Sema; 4016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass CompilerInstance { 622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The LLVM context used for this instance. 6342e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar llvm::OwningPtr<llvm::LLVMContext> LLVMContext; 642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 666228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar llvm::OwningPtr<CompilerInvocation> Invocation; 672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 6928019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics; 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 92f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief The semantic analysis object. 93f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor llvm::OwningPtr<Sema> TheSema; 94f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 95f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// The frontend timer 96f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::OwningPtr<llvm::Timer> FrontendTimer; 97f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 98a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// The list of active output files. 99a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles; 100a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 10142e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar void operator=(const CompilerInstance &); // DO NOT IMPLEMENT 10242e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT 1032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 10442e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(); 1052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 1062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1070397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// @name High-Level Operations 1080397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// { 1090397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1100397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// ExecuteAction - Execute the provided action against the compiler's 1110397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// CompilerInvocation object. 1120397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1130397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// This function makes the following assumptions: 1140397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1150397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The invocation options should be initialized. This function does not 1160397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// handle the '-help' or '-version' options, clients should handle those 1170397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// directly. 1180397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1190397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The diagnostics engine should have already been created by the client. 1200397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1210397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - No other CompilerInstance state should have been initialized (this is 1220397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// an unchecked error). 1230397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1240397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should have initialized any LLVM target features that may be 1250397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// required. 1260397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1270397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should eventually call llvm_shutdown() upon the completion of 1280397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// this routine to ensure that any managed objects are properly destroyed. 1290397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1300397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// Note that this routine may write output to 'stderr'. 1310397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1320397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \param Act - The action to execute. 1330397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \return - True on success. 1340397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1350397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: This function should take the stream to write any debugging / 1360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // verbose output to as an argument. 1370397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1380397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: Eliminate the llvm_shutdown requirement, that should either be part 1390397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // of the context or else not CompilerInstance specific. 1400397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar bool ExecuteAction(FrontendAction &Act); 1410397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1420397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// } 1432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name LLVM Context 1442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 146704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasLLVMContext() const { return LLVMContext != 0; } 147704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 148704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar llvm::LLVMContext &getLLVMContext() const { 14922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(LLVMContext && "Compiler instance has no LLVM context!"); 15022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *LLVMContext; 15122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 1522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 15342e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); } 15442e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar 1552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setLLVMContext - Replace the current LLVM context and take ownership of 1562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// \arg Value. 15742e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar void setLLVMContext(llvm::LLVMContext *Value); 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1636228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar bool hasInvocation() const { return Invocation != 0; } 1646228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1656228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation &getInvocation() { 1666228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar assert(Invocation && "Compiler instance has no invocation!"); 1676228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return *Invocation; 1686228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar } 1696228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1706228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation *takeInvocation() { return Invocation.take(); } 1716228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1726228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar /// setInvocation - Replace the current invocation; the compiler instance 1736228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar /// takes ownership of \arg Value. 1746228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar void setInvocation(CompilerInvocation *Value); 1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1816228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1846228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 1886228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 1892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 1916228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 1956228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 1962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 1986228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 1992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 2026228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 2056228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 2096228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 2126228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 2166228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 2196228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 2236228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 2266228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 2306228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 2336228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 2376228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 2406228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 243d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar TargetOptions &getTargetOpts() { 2446228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 245d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 246d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar const TargetOptions &getTargetOpts() const { 2476228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 248d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 249d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar 2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 2522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 254704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 255704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 25622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 25722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 25822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 25922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnostics - Replace the current diagnostics engine; the compiler 2622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2638a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnostics(Diagnostic *Value); 2642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 26581f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar DiagnosticClient &getDiagnosticClient() const { 266bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor assert(Diagnostics && Diagnostics->getClient() && 267bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor "Compiler instance has no diagnostic client!"); 268bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor return *Diagnostics->getClient(); 26981f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 2702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 275704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 276704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 27722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 27822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 27922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 28022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeTarget - Remove the current diagnostics engine and give ownership 2832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar TargetInfo *takeTarget() { return Target.take(); } 2852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setTarget - Replace the current diagnostics engine; the compiler 2872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2888a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 2892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 29116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 29216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 29316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 294704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 295704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 29622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 29722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 29822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 29922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 30016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 30116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeFileManager - Remove the current file manager and give ownership to 30216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// the caller. 30316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar FileManager *takeFileManager() { return FileMgr.take(); } 30416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 30516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setFileManager - Replace the current file manager; the compiler instance 30616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takes ownership of \arg Value. 3078a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 30816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 30916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 31016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 31116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 31216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 313704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 314704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 31522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 31622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 31722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 31822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 31916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeSourceManager - Remove the current source manager and give ownership 32116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// to the caller. 32216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar SourceManager *takeSourceManager() { return SourceMgr.take(); } 32316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setSourceManager - Replace the current source manager; the compiler 32516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// instance takes ownership of \arg Value. 3268a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 32716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 32922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 33022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 33122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 332704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 333704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 33422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 33522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 33622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 33722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 33822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 33922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takePreprocessor - Remove the current preprocessor and give ownership to 34022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// the caller. 34122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor *takePreprocessor() { return PP.take(); } 34222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 34322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// setPreprocessor - Replace the current preprocessor; the compiler instance 34422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takes ownership of \arg Value. 3458a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 34622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 34722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 3485eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 3495eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 3505eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 351704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 352704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3535eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 3545eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 3555eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 3565eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 3575eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3585eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takeASTContext - Remove the current AST context and give ownership to the 3595eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller. 3605eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext *takeASTContext() { return Context.take(); } 3615eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3625eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// setASTContext - Replace the current AST context; the compiler instance 3635eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takes ownership of \arg Value. 3648a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 3655eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 366f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Replace the current Sema; the compiler instance takes ownership 367f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// of S. 368f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void setSema(Sema *S); 369f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 3705eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 37112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 37212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 37312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 37412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar bool hasASTConsumer() const { return Consumer != 0; } 37512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 37612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 37712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 37812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 37912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 38012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 38112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 38212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 38312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer *takeASTConsumer() { return Consumer.take(); } 38412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 38512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 38612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takes ownership of \arg Value. 38712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar void setASTConsumer(ASTConsumer *Value); 38812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 38912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 390f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// @name Semantic analysis 391f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// { 392f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor bool hasSema() const { return TheSema != 0; } 393f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 394f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema &getSema() const { 395f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor assert(TheSema && "Compiler instance has no Sema object!"); 396f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor return *TheSema; 397f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 398f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 399f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema *takeSema() { return TheSema.take(); } 400f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 401f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// } 402c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 403c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 404c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 405c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 406c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 407c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 408c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 409c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 410c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 411c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 412c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 413c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// takeCodeCompletionConsumer - Remove the current code completion consumer 414c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// and give ownership to the caller. 415c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer *takeCodeCompletionConsumer() { 416c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return CompletionConsumer.take(); 417c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 418c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 419c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 420c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// the compiler instance takes ownership of \arg Value. 4218a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 422c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 423c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 424f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// @name Frontend timer 425f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// { 426f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 427f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam bool hasFrontendTimer() const { return FrontendTimer != 0; } 428f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 429f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::Timer &getFrontendTimer() const { 430f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam assert(FrontendTimer && "Compiler instance has no frontend timer!"); 431f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam return *FrontendTimer; 432f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 433f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 434f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// } 435a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 436a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 437a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 438a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// getOutputFileList - Get the list of (path, output stream) pairs of output 439a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// files; the path may be empty but the stream will always be non-null. 440a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar const std::list< std::pair<std::string, 441a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar llvm::raw_ostream*> > &getOutputFileList() const; 442a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 443a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 444a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 445a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param Path - The path to the output file, or empty. 446a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param OS - The output stream, which should be non-null. 447a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar void addOutputFile(llvm::StringRef Path, llvm::raw_ostream *OS); 448a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 449e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam /// clearOutputFiles - Clear the output file list, destroying the contained 450a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 451a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 452a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 453e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam void clearOutputFiles(bool EraseFiles); 454a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 455a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 45616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 45716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 45816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4590fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 4600fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 4610fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4620fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Note that this routine also replaces the diagnostic client. 4630fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar void createDiagnostics(int Argc, char **Argv); 4640fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 4650fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 4660fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4670fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 4680fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 4690fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 4700fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4715eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Note that this creates an unowned DiagnosticClient, if using directly the 472bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// caller is responsible for releasing the returned Diagnostic's client 4735eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// eventually. 4745eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 475bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// \param Opts - The diagnostic options; note that the created text 476bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// diagnostic object contains a reference to these options and its lifetime 477bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// must extend past that of the diagnostic engine. 478bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// 4790fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 48028019772db70d4547be05a042eb950bc910f134fDouglas Gregor static llvm::IntrusiveRefCntPtr<Diagnostic> 48128019772db70d4547be05a042eb950bc910f134fDouglas Gregor createDiagnostics(const DiagnosticOptions &Opts, int Argc, char **Argv); 4820fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 48316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 48416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 48516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 48616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 48716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createSourceManager(); 48816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 48922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 49022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 49122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 49222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 49322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create a Preprocessor object. 49422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 49522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Note that this also creates a new HeaderSearch object which will be owned 49622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// by the resulting Preprocessor. 49722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 49822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// \return The new object on success, or null on failure. 49922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, 50022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const PreprocessorOptions &, 50122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const HeaderSearchOptions &, 50222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const DependencyOutputOptions &, 50322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const TargetInfo &, 5047d957472ef9a09048c03d8a11028536f908c18b9Fariborz Jahanian const FrontendOptions &, 50522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &, FileManager &); 50622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 5075eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 5085eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 5095eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 5100f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 5110f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 512fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor void createPCHExternalASTSource(llvm::StringRef Path, 513ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl bool DisablePCHValidation, 514ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl void *DeserializationListener); 5150f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 5160f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 5170f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 5180f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 5190f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 5200f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot, 521fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor bool DisablePCHValidation, 522ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Preprocessor &PP, ASTContext &Context, 523ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl void *DeserializationListener); 524a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl 525c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 526c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 527c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 528c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 529c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 530c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 531c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg 532c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// OS. 533c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar static CodeCompleteConsumer * 534c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 535c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar unsigned Line, unsigned Column, 536c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool UseDebugPrinter, bool ShowMacros, 5378071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor bool ShowCodePatterns, bool ShowGlobals, 5388071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor llvm::raw_ostream &OS); 539c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 540f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Create the Sema object to be used for parsing. 541f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void createSema(bool CompleteTranslationUnit, 542f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CodeCompleteConsumer *CompletionConsumer); 543f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 544f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// Create the frontend timer and replace any existing one with it. 545f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam void createFrontendTimer(); 546f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 547f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 548f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 549360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 550360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 551f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 552f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "", 553f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 554f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 555f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 556f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 557360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 558360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 559f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 560f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, bool Binary = true, 561f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef BaseInput = "", 562f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 563f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 564f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 565f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 566f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// If \arg OutputPath is empty, then createOutputFile will derive an output 567f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// path location as \arg BaseInput, with any suffix removed, and \arg 568f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Extension appended. 569f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 570f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 571f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Error [out] - On failure, the error message. 572f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param BaseInput - If \arg OutputPath is empty, the input path name to use 573f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 574f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 575f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 576f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 577f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 578f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar static llvm::raw_fd_ostream * 579f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, std::string &Error, 580f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar bool Binary = true, llvm::StringRef BaseInput = "", 581f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = "", 582f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar std::string *ResultPathName = 0); 583f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 58416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 585ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 586ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 587ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 588ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 589ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 590ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 591ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 592ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar bool InitializeSourceManager(llvm::StringRef InputFile); 593ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 594ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 595ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 596ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 597ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 598ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar static bool InitializeSourceManager(llvm::StringRef InputFile, 599ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar Diagnostic &Diags, 600ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar FileManager &FileMgr, 601ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar SourceManager &SourceMgr, 602ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar const FrontendOptions &Opts); 603ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 604ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 6052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 6062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 6082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 610