CompilerInstance.h revision 6aa52ec6b969faabf3764baf79d89810b8249a7e
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" 146aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor#include "clang/Lex/ModuleLoader.h" 1528019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 160f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar#include "llvm/ADT/StringRef.h" 172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#include "llvm/ADT/OwningPtr.h" 1822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar#include <cassert> 19a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <list> 20a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <string> 212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm { 23f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream; 24f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer; 252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 285eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 2912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer; 30f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTReader; 31c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer; 322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic; 332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient; 340f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 3516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbarclass FrontendAction; 370f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 38f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregorclass Sema; 3916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 606aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregorclass CompilerInstance : public ModuleLoader { 612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 624f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation; 632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 6528019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics; 662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The target being compiled for. 684f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<TargetInfo> Target; 692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 7016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The file manager. 714f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<FileManager> FileMgr; 7216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The source manager. 744f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr; 7516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// The preprocessor. 774f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<Preprocessor> PP; 7822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 795eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// The AST context. 804f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<ASTContext> Context; 815eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 8212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// The AST consumer. 8312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar llvm::OwningPtr<ASTConsumer> Consumer; 8412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 85c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// The code completion consumer. 86c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer; 87c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 88f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief The semantic analysis object. 89f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor llvm::OwningPtr<Sema> TheSema; 90f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 91f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// \brief The frontend timer 92f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::OwningPtr<llvm::Timer> FrontendTimer; 93f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 94f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// \brief Non-owning reference to the ASTReader, if one exists. 95f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor ASTReader *ModuleManager; 96f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 97dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \brief Holds information about the output file. 98dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// 99dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// If TempFilename is not empty we must rename it to Filename at the end. 100dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// TempFilename may be empty and Filename non empty if creating the temporary 101dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// failed. 102dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis struct OutputFile { 103dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string Filename; 104dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string TempFilename; 1058cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream *OS; 106dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 107dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis OutputFile(const std::string &filename, const std::string &tempFilename, 1088cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream *os) 109dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis : Filename(filename), TempFilename(tempFilename), OS(os) { } 110dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis }; 111dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 112a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// The list of active output files. 113dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::list<OutputFile> OutputFiles; 114a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 11542e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar void operator=(const CompilerInstance &); // DO NOT IMPLEMENT 11642e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT 1172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 11842e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(); 1192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 1202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1210397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// @name High-Level Operations 1220397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// { 1230397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1240397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// ExecuteAction - Execute the provided action against the compiler's 1250397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// CompilerInvocation object. 1260397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1270397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// This function makes the following assumptions: 1280397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1290397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The invocation options should be initialized. This function does not 1300397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// handle the '-help' or '-version' options, clients should handle those 1310397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// directly. 1320397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1330397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The diagnostics engine should have already been created by the client. 1340397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1350397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - No other CompilerInstance state should have been initialized (this is 1360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// an unchecked error). 1370397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1380397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should have initialized any LLVM target features that may be 1390397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// required. 1400397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1410397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should eventually call llvm_shutdown() upon the completion of 1420397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// this routine to ensure that any managed objects are properly destroyed. 1430397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1440397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// Note that this routine may write output to 'stderr'. 1450397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1460397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \param Act - The action to execute. 1470397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \return - True on success. 1480397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1490397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: This function should take the stream to write any debugging / 1500397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // verbose output to as an argument. 1510397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1520397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: Eliminate the llvm_shutdown requirement, that should either be part 1530397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // of the context or else not CompilerInstance specific. 1540397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar bool ExecuteAction(FrontendAction &Act); 1550397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1560397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// } 1572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1606228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar bool hasInvocation() const { return Invocation != 0; } 1616228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1626228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation &getInvocation() { 1636228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar assert(Invocation && "Compiler instance has no invocation!"); 1646228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return *Invocation; 1656228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar } 1666228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1674f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setInvocation - Replace the current invocation. 1686228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar void setInvocation(CompilerInvocation *Value); 1692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1756228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1786228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 1826228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 1832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 1856228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 1862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1882a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 1896228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1912a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 1926228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 1966228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 1996228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 202389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis const FileSystemOptions &getFileSystemOpts() const { 203389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis return Invocation->getFileSystemOpts(); 204389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis } 205389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 2062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 2076228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 2106228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 2146228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 2176228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 2216228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 2246228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 2286228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 2316228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 2356228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 2386228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 241d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar TargetOptions &getTargetOpts() { 2426228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 243d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 244d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar const TargetOptions &getTargetOpts() const { 2456228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 246d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 247d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar 2482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 252704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 253704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 2544f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Get the current diagnostics engine. 25522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 25622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 25722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 25822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2604f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setDiagnostics - Replace the current diagnostics engine. 2618a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnostics(Diagnostic *Value); 2622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 26381f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar DiagnosticClient &getDiagnosticClient() const { 264bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor assert(Diagnostics && Diagnostics->getClient() && 265bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor "Compiler instance has no diagnostic client!"); 266bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor return *Diagnostics->getClient(); 26781f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 2682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 273704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 274704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 27522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 27622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 27722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 27822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2804f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Replace the current diagnostics engine. 2818a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 2822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 28416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 28516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 28616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 287704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 288704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 2894f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current file manager to the caller. 29022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 29122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 29222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 29322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2944f32786ac45210143654390177105eb749b614e9Ted Kremenek 2954f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakFileManager() { 2964f32786ac45210143654390177105eb749b614e9Ted Kremenek FileMgr.resetWithoutRelease(); 2974f32786ac45210143654390177105eb749b614e9Ted Kremenek } 29816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 2994f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setFileManager - Replace the current file manager. 3008a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 30116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 30216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 30316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 30416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 30516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 306704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 307704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3084f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current source manager. 30922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 31022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 31122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 31222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 3134f32786ac45210143654390177105eb749b614e9Ted Kremenek 3144f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakSourceManager() { 3154f32786ac45210143654390177105eb749b614e9Ted Kremenek SourceMgr.resetWithoutRelease(); 3164f32786ac45210143654390177105eb749b614e9Ted Kremenek } 31716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 3184f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setSourceManager - Replace the current source manager. 3198a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 32016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 32222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 32322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 32422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 325704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 326704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3274f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current preprocessor. 32822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 32922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 33022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 33122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 33222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 3334f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakPreprocessor() { 3344f32786ac45210143654390177105eb749b614e9Ted Kremenek PP.resetWithoutRelease(); 3354f32786ac45210143654390177105eb749b614e9Ted Kremenek } 33622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 3374f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Replace the current preprocessor. 3388a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 33922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 34022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 3415eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 3425eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 3435eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 344704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 345704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3465eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 3475eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 3485eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 3495eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 3504f32786ac45210143654390177105eb749b614e9Ted Kremenek 3514f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakASTContext() { 3524f32786ac45210143654390177105eb749b614e9Ted Kremenek Context.resetWithoutRelease(); 3534f32786ac45210143654390177105eb749b614e9Ted Kremenek } 3545eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3554f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setASTContext - Replace the current AST context. 3568a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 3575eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 358f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Replace the current Sema; the compiler instance takes ownership 359f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// of S. 360f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void setSema(Sema *S); 361f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 3625eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 36312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 36412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 36512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 36612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar bool hasASTConsumer() const { return Consumer != 0; } 36712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 36812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 36912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 37012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 37112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 37212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 37312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 37412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 37512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer *takeASTConsumer() { return Consumer.take(); } 37612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 37712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 37812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takes ownership of \arg Value. 37912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar void setASTConsumer(ASTConsumer *Value); 38012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 38112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 382f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// @name Semantic analysis 383f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// { 384f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor bool hasSema() const { return TheSema != 0; } 385f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 386f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema &getSema() const { 387f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor assert(TheSema && "Compiler instance has no Sema object!"); 388f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor return *TheSema; 389f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 390f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 391f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema *takeSema() { return TheSema.take(); } 392f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 393f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// } 394f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// @name Module Management 395f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// { 396f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 397f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor ASTReader *getModuleManager() const { return ModuleManager; } 398f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 399f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// } 400c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 401c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 402c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 403c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 404c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 405c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 406c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 407c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 408c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 409c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 410c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 411c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// takeCodeCompletionConsumer - Remove the current code completion consumer 412c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// and give ownership to the caller. 413c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer *takeCodeCompletionConsumer() { 414c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return CompletionConsumer.take(); 415c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 416c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 417c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 418c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// the compiler instance takes ownership of \arg Value. 4198a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 420c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 421c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 422f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// @name Frontend timer 423f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// { 424f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 425f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam bool hasFrontendTimer() const { return FrontendTimer != 0; } 426f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 427f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::Timer &getFrontendTimer() const { 428f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam assert(FrontendTimer && "Compiler instance has no frontend timer!"); 429f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam return *FrontendTimer; 430f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 431f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 432f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// } 433a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 434a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 435a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 436a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 437a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 438dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param OutFile - The output file info. 439dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis void addOutputFile(const OutputFile &OutFile); 440a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 441e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam /// clearOutputFiles - Clear the output file list, destroying the contained 442a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 443a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 444a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 445e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam void clearOutputFiles(bool EraseFiles); 446a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 447a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 44816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 44916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 45016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4510fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 4520fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 4530fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 454e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// Note that this routine also replaces the diagnostic client, 455e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// allocating one if one is not provided. 456e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// 457e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// \param Client If non-NULL, a diagnostic client that will be 458e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// attached to (and, then, owned by) the Diagnostic inside this AST 459e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// unit. 460e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor void createDiagnostics(int Argc, const char* const *Argv, 461e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor DiagnosticClient *Client = 0); 4620fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 4630fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 4640fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4650fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 4660fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 4670fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 4680fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 469e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// If no diagnostic client is provided, this creates a 470e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// DiagnosticClient that is owned by the returned diagnostic 471e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// object, if using directly the caller is responsible for 472e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// releasing the returned Diagnostic's client eventually. 4735eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 474bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// \param Opts - The diagnostic options; note that the created text 475bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// diagnostic object contains a reference to these options and its lifetime 476bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// must extend past that of the diagnostic engine. 477bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// 478e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// \param Client If non-NULL, a diagnostic client that will be 479e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// attached to (and, then, owned by) the returned Diagnostic 480e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// object. 481e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// 482b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be 483b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// used by some diagnostics printers (for logging purposes only). 484b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// 4850fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 48628019772db70d4547be05a042eb950bc910f134fDouglas Gregor static llvm::IntrusiveRefCntPtr<Diagnostic> 4877d0c4ccd65b4549283c55e4923602e234f3811c5Axel Naumann createDiagnostics(const DiagnosticOptions &Opts, int Argc, 488e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor const char* const *Argv, 489b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar DiagnosticClient *Client = 0, 490b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar const CodeGenOptions *CodeGenOpts = 0); 4910fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 49216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 49316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 49416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 49516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 49639b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner void createSourceManager(FileManager &FileMgr); 49716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 49822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 49922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 50022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 50122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 5025eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 5035eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 5045eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 5050f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 5060f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 507686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void createPCHExternalASTSource(StringRef Path, 508ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl bool DisablePCHValidation, 5098ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor bool DisableStatCache, 510ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl void *DeserializationListener); 5110f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 5120f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 5130f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 5140f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 5150f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 516686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createPCHExternalASTSource(StringRef Path, const std::string &Sysroot, 517fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor bool DisablePCHValidation, 5188ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor bool DisableStatCache, 519ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Preprocessor &PP, ASTContext &Context, 5201d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl void *DeserializationListener, bool Preamble); 521a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl 522c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 523c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 524c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 525c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 526c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 527c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 528c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg 529c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// OS. 530c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar static CodeCompleteConsumer * 531c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 532c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar unsigned Line, unsigned Column, 533a9f4f620daf073805b89e893afcdc5eb7a9bdc50Douglas Gregor bool ShowMacros, 5348071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor bool ShowCodePatterns, bool ShowGlobals, 5358cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream &OS); 536c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 537f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Create the Sema object to be used for parsing. 538467dc88512b4ba4bb16e274ea3771dc1415d31daDouglas Gregor void createSema(TranslationUnitKind TUKind, 539f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CodeCompleteConsumer *CompletionConsumer); 540f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 541f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// Create the frontend timer and replace any existing one with it. 542f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam void createFrontendTimer(); 543f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 544f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 545f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 546360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 547360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 548f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 549686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "", 550686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Extension = ""); 551f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 552f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 553f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 554360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 555360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 556f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 557686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createOutputFile(StringRef OutputPath, 558ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar bool Binary = true, bool RemoveFileOnSignal = true, 559686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef BaseInput = "", 5607e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis StringRef Extension = "", 5617e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis bool UseTemporary = false); 562f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 563f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 564f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 565f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// If \arg OutputPath is empty, then createOutputFile will derive an output 566f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// path location as \arg BaseInput, with any suffix removed, and \arg 5677e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// Extension appended. If OutputPath is not stdout and \arg UseTemporary 5687e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// is true, createOutputFile will create a new temporary file that must be 5697e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// renamed to OutputPath in the end. 570f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 571f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 572f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Error [out] - On failure, the error message. 573f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param BaseInput - If \arg OutputPath is empty, the input path name to use 574f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 575f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 576f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 577ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// \param RemoveFileOnSignal - Whether the file should be registered with 578ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for 579ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// multithreaded use, as the underlying signal mechanism is not reentrant 5807e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// \param UseTemporary - Create a new temporary file that must be renamed to 5817e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// OutputPath in the end 582f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 583f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 584dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param TempPathName [out] - If given, the temporary file path name 585dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// will be stored here on success. 586f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar static llvm::raw_fd_ostream * 587686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createOutputFile(StringRef OutputPath, std::string &Error, 588ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar bool Binary = true, bool RemoveFileOnSignal = true, 589686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef BaseInput = "", 590686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Extension = "", 5917e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis bool UseTemporary = false, 592dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string *ResultPathName = 0, 593dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string *TempPathName = 0); 594f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 59516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 596ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 597ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 598ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 599ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 600ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 601ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 602ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 603686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool InitializeSourceManager(StringRef InputFile); 604ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 605ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 606ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 607ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 608ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 609686775deca8b8685eb90801495880e3abdd844c2Chris Lattner static bool InitializeSourceManager(StringRef InputFile, 610ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar Diagnostic &Diags, 611ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar FileManager &FileMgr, 612ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar SourceManager &SourceMgr, 613ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar const FrontendOptions &Opts); 614ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 615ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 6166aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor 6176aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor virtual ModuleKey loadModule(SourceLocation ImportLoc, 6186aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor IdentifierInfo &ModuleName, 6196aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor SourceLocation ModuleNameLoc); 6202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 6212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 6232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 625