CompilerInstance.h revision dc24572a44575e07a5d8bb6de52641a69f1bab27
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 98dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \brief Holds information about the output file. 99dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// 100dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// If TempFilename is not empty we must rename it to Filename at the end. 101dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// TempFilename may be empty and Filename non empty if creating the temporary 102dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// failed. 103dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis struct OutputFile { 104dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string Filename; 105dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string TempFilename; 106dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis llvm::raw_ostream *OS; 107dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 108dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis OutputFile(const std::string &filename, const std::string &tempFilename, 109dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis llvm::raw_ostream *os) 110dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis : Filename(filename), TempFilename(tempFilename), OS(os) { } 111dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis }; 112dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 113a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// The list of active output files. 114dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::list<OutputFile> OutputFiles; 115a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 11642e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar void operator=(const CompilerInstance &); // DO NOT IMPLEMENT 11742e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT 1182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 11942e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(); 1202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 1212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1220397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// @name High-Level Operations 1230397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// { 1240397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1250397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// ExecuteAction - Execute the provided action against the compiler's 1260397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// CompilerInvocation object. 1270397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1280397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// This function makes the following assumptions: 1290397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1300397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The invocation options should be initialized. This function does not 1310397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// handle the '-help' or '-version' options, clients should handle those 1320397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// directly. 1330397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1340397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The diagnostics engine should have already been created by the client. 1350397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - No other CompilerInstance state should have been initialized (this is 1370397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// an unchecked error). 1380397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1390397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should have initialized any LLVM target features that may be 1400397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// required. 1410397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1420397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should eventually call llvm_shutdown() upon the completion of 1430397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// this routine to ensure that any managed objects are properly destroyed. 1440397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1450397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// Note that this routine may write output to 'stderr'. 1460397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1470397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \param Act - The action to execute. 1480397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \return - True on success. 1490397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1500397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: This function should take the stream to write any debugging / 1510397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // verbose output to as an argument. 1520397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1530397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: Eliminate the llvm_shutdown requirement, that should either be part 1540397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // of the context or else not CompilerInstance specific. 1550397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar bool ExecuteAction(FrontendAction &Act); 1560397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1570397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// } 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name LLVM Context 1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 161704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasLLVMContext() const { return LLVMContext != 0; } 162704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 163704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar llvm::LLVMContext &getLLVMContext() const { 16422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(LLVMContext && "Compiler instance has no LLVM context!"); 16522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *LLVMContext; 16622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 1672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 16842e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); } 16942e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar 1702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setLLVMContext - Replace the current LLVM context and take ownership of 1712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// \arg Value. 17242e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar void setLLVMContext(llvm::LLVMContext *Value); 1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1786228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar bool hasInvocation() const { return Invocation != 0; } 1796228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1806228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation &getInvocation() { 1816228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar assert(Invocation && "Compiler instance has no invocation!"); 1826228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return *Invocation; 1836228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar } 1846228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1856228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation *takeInvocation() { return Invocation.take(); } 1866228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1876228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar /// setInvocation - Replace the current invocation; the compiler instance 1886228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar /// takes ownership of \arg Value. 1896228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar void setInvocation(CompilerInvocation *Value); 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1966228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1996228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 2002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 2036228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 2042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 2066228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 2072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 2106228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 2112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 2136228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 2142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 2176228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 2206228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 2246228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 2276228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 2316228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 2346228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 2386228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 2416228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 2456228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 2486228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 2526228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 2556228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 258d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar TargetOptions &getTargetOpts() { 2596228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 260d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 261d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar const TargetOptions &getTargetOpts() const { 2626228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 263d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 264d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar 2652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 2672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 269704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 270704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 27122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 27222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 27322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 27422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setDiagnostics - Replace the current diagnostics engine; the compiler 2772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 2788a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnostics(Diagnostic *Value); 2792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 28081f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar DiagnosticClient &getDiagnosticClient() const { 281bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor assert(Diagnostics && Diagnostics->getClient() && 282bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor "Compiler instance has no diagnostic client!"); 283bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor return *Diagnostics->getClient(); 28481f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 2852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 290704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 291704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 29222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 29322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 29422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 29522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// takeTarget - Remove the current diagnostics engine and give ownership 2982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// to the caller. 2992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar TargetInfo *takeTarget() { return Target.take(); } 3002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// setTarget - Replace the current diagnostics engine; the compiler 3022a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// instance takes ownership of \arg Value. 3038a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 3042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 30616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 30716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 30816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 309704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 310704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 31122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 31222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 31322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 31422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 31516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 31616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeFileManager - Remove the current file manager and give ownership to 31716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// the caller. 31816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar FileManager *takeFileManager() { return FileMgr.take(); } 31916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setFileManager - Replace the current file manager; the compiler instance 32116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takes ownership of \arg Value. 3228a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 32316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 32516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 32616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 32716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 328704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 329704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 33022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 33122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 33222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 33322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 33416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 33516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// takeSourceManager - Remove the current source manager and give ownership 33616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// to the caller. 33716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar SourceManager *takeSourceManager() { return SourceMgr.take(); } 33816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 33916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// setSourceManager - Replace the current source manager; the compiler 34016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// instance takes ownership of \arg Value. 3418a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 34216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 34316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 34422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 34522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 34622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 347704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 348704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 34922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 35022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 35122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 35222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 35322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 35422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takePreprocessor - Remove the current preprocessor and give ownership to 35522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// the caller. 35622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor *takePreprocessor() { return PP.take(); } 35722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 35822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// setPreprocessor - Replace the current preprocessor; the compiler instance 35922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// takes ownership of \arg Value. 3608a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 36122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 36222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 3635eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 3645eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 3655eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 366704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 367704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3685eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 3695eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 3705eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 3715eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 3725eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3735eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takeASTContext - Remove the current AST context and give ownership to the 3745eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// caller. 3755eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext *takeASTContext() { return Context.take(); } 3765eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3775eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// setASTContext - Replace the current AST context; the compiler instance 3785eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// takes ownership of \arg Value. 3798a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 3805eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 381f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Replace the current Sema; the compiler instance takes ownership 382f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// of S. 383f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void setSema(Sema *S); 384f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 3855eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 38612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 38712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 38812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 38912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar bool hasASTConsumer() const { return Consumer != 0; } 39012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 39112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 39212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 39312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 39412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 39512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 39612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 39712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 39812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer *takeASTConsumer() { return Consumer.take(); } 39912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 40012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 40112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takes ownership of \arg Value. 40212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar void setASTConsumer(ASTConsumer *Value); 40312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 40412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 405f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// @name Semantic analysis 406f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// { 407f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor bool hasSema() const { return TheSema != 0; } 408f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 409f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema &getSema() const { 410f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor assert(TheSema && "Compiler instance has no Sema object!"); 411f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor return *TheSema; 412f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 413f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 414f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema *takeSema() { return TheSema.take(); } 415f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 416f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// } 417c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 418c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 419c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 420c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 421c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 422c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 423c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 424c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 425c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 426c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 427c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 428c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// takeCodeCompletionConsumer - Remove the current code completion consumer 429c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// and give ownership to the caller. 430c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer *takeCodeCompletionConsumer() { 431c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return CompletionConsumer.take(); 432c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 433c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 434c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 435c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// the compiler instance takes ownership of \arg Value. 4368a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 437c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 438c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 439f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// @name Frontend timer 440f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// { 441f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 442f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam bool hasFrontendTimer() const { return FrontendTimer != 0; } 443f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 444f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::Timer &getFrontendTimer() const { 445f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam assert(FrontendTimer && "Compiler instance has no frontend timer!"); 446f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam return *FrontendTimer; 447f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 448f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 449f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// } 450a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 451a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 452a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 453a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// getOutputFileList - Get the list of (path, output stream) pairs of output 454a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// files; the path may be empty but the stream will always be non-null. 455a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar const std::list< std::pair<std::string, 456a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar llvm::raw_ostream*> > &getOutputFileList() const; 457a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 458a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 459a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 460dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param OutFile - The output file info. 461dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis void addOutputFile(const OutputFile &OutFile); 462a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 463e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam /// clearOutputFiles - Clear the output file list, destroying the contained 464a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 465a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 466a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 467e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam void clearOutputFiles(bool EraseFiles); 468a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 469a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 47016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 47116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 47216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4730fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 4740fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 4750fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4760fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Note that this routine also replaces the diagnostic client. 4770fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar void createDiagnostics(int Argc, char **Argv); 4780fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 4790fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 4800fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4810fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 4820fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 4830fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 4840fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4855eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Note that this creates an unowned DiagnosticClient, if using directly the 486bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// caller is responsible for releasing the returned Diagnostic's client 4875eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// eventually. 4885eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 489bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// \param Opts - The diagnostic options; note that the created text 490bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// diagnostic object contains a reference to these options and its lifetime 491bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// must extend past that of the diagnostic engine. 492bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// 4930fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 49428019772db70d4547be05a042eb950bc910f134fDouglas Gregor static llvm::IntrusiveRefCntPtr<Diagnostic> 49528019772db70d4547be05a042eb950bc910f134fDouglas Gregor createDiagnostics(const DiagnosticOptions &Opts, int Argc, char **Argv); 4960fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 49716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 49816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 49916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 50016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 50116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createSourceManager(); 50216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 50322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 50422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 50522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 50622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 50722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create a Preprocessor object. 50822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 50922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Note that this also creates a new HeaderSearch object which will be owned 51022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// by the resulting Preprocessor. 51122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 51222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// \return The new object on success, or null on failure. 51322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, 51422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const PreprocessorOptions &, 51522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const HeaderSearchOptions &, 51622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const DependencyOutputOptions &, 51722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const TargetInfo &, 5187d957472ef9a09048c03d8a11028536f908c18b9Fariborz Jahanian const FrontendOptions &, 51922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &, FileManager &); 52022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 5215eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 5225eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 5235eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 5240f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 5250f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 526fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor void createPCHExternalASTSource(llvm::StringRef Path, 527ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl bool DisablePCHValidation, 528ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl void *DeserializationListener); 5290f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 5300f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 5310f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 5320f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 5330f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 5340f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot, 535fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor bool DisablePCHValidation, 536ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Preprocessor &PP, ASTContext &Context, 537ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl void *DeserializationListener); 538a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl 539c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 540c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 541c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 542c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 543c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 544c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 545c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg 546c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// OS. 547c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar static CodeCompleteConsumer * 548c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 549c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar unsigned Line, unsigned Column, 550c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool UseDebugPrinter, bool ShowMacros, 5518071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor bool ShowCodePatterns, bool ShowGlobals, 5528071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor llvm::raw_ostream &OS); 553c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 554f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Create the Sema object to be used for parsing. 555f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void createSema(bool CompleteTranslationUnit, 556f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CodeCompleteConsumer *CompletionConsumer); 557f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 558f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// Create the frontend timer and replace any existing one with it. 559f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam void createFrontendTimer(); 560f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 561f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 562f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 563360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 564360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 565f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 566f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "", 567f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 568f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 569f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 570f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 571360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 572360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 573f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 574f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, bool Binary = true, 575f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef BaseInput = "", 576f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = ""); 577f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 578f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 579f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 580f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// If \arg OutputPath is empty, then createOutputFile will derive an output 581f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// path location as \arg BaseInput, with any suffix removed, and \arg 582dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// Extension appended. If OutputPath is not stdout createOutputFile will 583dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// create a new temporary file that must be renamed to OutputPath in the end. 584f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 585f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 586f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Error [out] - On failure, the error message. 587f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param BaseInput - If \arg OutputPath is empty, the input path name to use 588f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 589f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 590f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 591f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 592f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 593dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param TempPathName [out] - If given, the temporary file path name 594dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// will be stored here on success. 595f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar static llvm::raw_fd_ostream * 596f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar createOutputFile(llvm::StringRef OutputPath, std::string &Error, 597f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar bool Binary = true, llvm::StringRef BaseInput = "", 598f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::StringRef Extension = "", 599dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string *ResultPathName = 0, 600dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string *TempPathName = 0); 601f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 60216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 603ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 604ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 605ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 606ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 607ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 608ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 609ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 610ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar bool InitializeSourceManager(llvm::StringRef InputFile); 611ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 612ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 613ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 614ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 615ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 616ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar static bool InitializeSourceManager(llvm::StringRef InputFile, 617ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar Diagnostic &Diags, 618ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar FileManager &FileMgr, 619ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar SourceManager &SourceMgr, 620ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar const FrontendOptions &Opts); 621ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 622ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 6232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 6242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 6262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 628