CompilerInstance.h revision 7e90985df09855dc309ed888a5b16a0ae684f8e3
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 { 22f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream; 23f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer; 242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 275eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 2812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer; 29f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTReader; 30c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer; 312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass Diagnostic; 322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass DiagnosticClient; 330f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 3416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 350397af277e3bba16da1fd125ddba07415686b429Daniel Dunbarclass FrontendAction; 360f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 37f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregorclass Sema; 3816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass CompilerInstance { 602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 614f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation; 622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 6428019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics; 652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The target being compiled for. 674f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<TargetInfo> Target; 682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The file manager. 704f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<FileManager> FileMgr; 7116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The source manager. 734f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr; 7416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 7522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// The preprocessor. 764f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<Preprocessor> PP; 7722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 785eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// The AST context. 794f32786ac45210143654390177105eb749b614e9Ted Kremenek llvm::IntrusiveRefCntPtr<ASTContext> Context; 805eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 8112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// The AST consumer. 8212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar llvm::OwningPtr<ASTConsumer> Consumer; 8312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 84c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// The code completion consumer. 85c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer; 86c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 87f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief The semantic analysis object. 88f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor llvm::OwningPtr<Sema> TheSema; 89f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 90f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// \brief The frontend timer 91f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::OwningPtr<llvm::Timer> FrontendTimer; 92f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 93f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// \brief Non-owning reference to the ASTReader, if one exists. 94f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor ASTReader *ModuleManager; 95f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 96dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \brief Holds information about the output file. 97dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// 98dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// If TempFilename is not empty we must rename it to Filename at the end. 99dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// TempFilename may be empty and Filename non empty if creating the temporary 100dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// failed. 101dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis struct OutputFile { 102dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string Filename; 103dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string TempFilename; 1048cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream *OS; 105dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 106dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis OutputFile(const std::string &filename, const std::string &tempFilename, 1078cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream *os) 108dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis : Filename(filename), TempFilename(tempFilename), OS(os) { } 109dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis }; 110dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 111a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// The list of active output files. 112dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::list<OutputFile> OutputFiles; 113a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 11442e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar void operator=(const CompilerInstance &); // DO NOT IMPLEMENT 11542e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT 1162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 11742e9f8e4983d50f896ec716207817b9d96e7e79cDaniel Dunbar CompilerInstance(); 1182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar ~CompilerInstance(); 1192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1200397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// @name High-Level Operations 1210397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// { 1220397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1230397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// ExecuteAction - Execute the provided action against the compiler's 1240397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// CompilerInvocation object. 1250397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1260397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// This function makes the following assumptions: 1270397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1280397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The invocation options should be initialized. This function does not 1290397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// handle the '-help' or '-version' options, clients should handle those 1300397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// directly. 1310397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1320397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The diagnostics engine should have already been created by the client. 1330397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1340397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - No other CompilerInstance state should have been initialized (this is 1350397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// an unchecked error). 1360397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1370397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should have initialized any LLVM target features that may be 1380397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// required. 1390397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1400397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should eventually call llvm_shutdown() upon the completion of 1410397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// this routine to ensure that any managed objects are properly destroyed. 1420397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1430397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// Note that this routine may write output to 'stderr'. 1440397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1450397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \param Act - The action to execute. 1460397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \return - True on success. 1470397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1480397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: This function should take the stream to write any debugging / 1490397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // verbose output to as an argument. 1500397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 1510397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: Eliminate the llvm_shutdown requirement, that should either be part 1520397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // of the context or else not CompilerInstance specific. 1530397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar bool ExecuteAction(FrontendAction &Act); 1540397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1550397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// } 1562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 1572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1596228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar bool hasInvocation() const { return Invocation != 0; } 1606228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1616228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation &getInvocation() { 1626228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar assert(Invocation && "Compiler instance has no invocation!"); 1636228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return *Invocation; 1646228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar } 1656228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 1664f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setInvocation - Replace the current invocation. 1676228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar void setInvocation(CompilerInvocation *Value); 1682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 1702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 1712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 1722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar AnalyzerOptions &getAnalyzerOpts() { 1746228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const AnalyzerOptions &getAnalyzerOpts() const { 1776228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 1782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 1816228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 1822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 1846228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 1852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 1886228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 1892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 1916228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 1922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 1956228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 1962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 1972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 1986228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 1992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 201389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis const FileSystemOptions &getFileSystemOpts() const { 202389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis return Invocation->getFileSystemOpts(); 203389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis } 204389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 2052a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 2066228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 2096228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2122a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 2136228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 2166228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 2206228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 2236228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getLangOpts(); 2242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 2276228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 2306228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 2312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 2346228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 2376228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 2382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2392a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 240d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar TargetOptions &getTargetOpts() { 2416228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 242d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 243d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar const TargetOptions &getTargetOpts() const { 2446228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 245d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 246d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar 2472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 2492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 251704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasDiagnostics() const { return Diagnostics != 0; } 252704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 2534f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Get the current diagnostics engine. 25422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Diagnostic &getDiagnostics() const { 25522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 25622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 25722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2594f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setDiagnostics - Replace the current diagnostics engine. 2608a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setDiagnostics(Diagnostic *Value); 2612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 26281f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar DiagnosticClient &getDiagnosticClient() const { 263bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor assert(Diagnostics && Diagnostics->getClient() && 264bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor "Compiler instance has no diagnostic client!"); 265bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor return *Diagnostics->getClient(); 26681f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 2672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 2702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 272704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasTarget() const { return Target != 0; } 273704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 27422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 27522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 27622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 27722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2794f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Replace the current diagnostics engine. 2808a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 2812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 28316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 28416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 28516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 286704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasFileManager() const { return FileMgr != 0; } 287704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 2884f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current file manager to the caller. 28922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 29022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 29122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 29222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 2934f32786ac45210143654390177105eb749b614e9Ted Kremenek 2944f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakFileManager() { 2954f32786ac45210143654390177105eb749b614e9Ted Kremenek FileMgr.resetWithoutRelease(); 2964f32786ac45210143654390177105eb749b614e9Ted Kremenek } 29716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 2984f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setFileManager - Replace the current file manager. 2998a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 30016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 30116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 30216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 30316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 30416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 305704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasSourceManager() const { return SourceMgr != 0; } 306704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3074f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current source manager. 30822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 30922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 31022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 31122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 3124f32786ac45210143654390177105eb749b614e9Ted Kremenek 3134f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakSourceManager() { 3144f32786ac45210143654390177105eb749b614e9Ted Kremenek SourceMgr.resetWithoutRelease(); 3154f32786ac45210143654390177105eb749b614e9Ted Kremenek } 31616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 3174f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setSourceManager - Replace the current source manager. 3188a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 31916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 32016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 32122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 32222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 32322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 324704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasPreprocessor() const { return PP != 0; } 325704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3264f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current preprocessor. 32722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 32822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 32922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 33022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 33122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 3324f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakPreprocessor() { 3334f32786ac45210143654390177105eb749b614e9Ted Kremenek PP.resetWithoutRelease(); 3344f32786ac45210143654390177105eb749b614e9Ted Kremenek } 33522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 3364f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Replace the current preprocessor. 3378a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 33822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 33922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 3405eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 3415eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 3425eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 343704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar bool hasASTContext() const { return Context != 0; } 344704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3455eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 3465eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 3475eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 3485eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 3494f32786ac45210143654390177105eb749b614e9Ted Kremenek 3504f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakASTContext() { 3514f32786ac45210143654390177105eb749b614e9Ted Kremenek Context.resetWithoutRelease(); 3524f32786ac45210143654390177105eb749b614e9Ted Kremenek } 3535eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 3544f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setASTContext - Replace the current AST context. 3558a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 3565eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 357f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Replace the current Sema; the compiler instance takes ownership 358f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// of S. 359f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void setSema(Sema *S); 360f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 3615eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 36212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 36312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 36412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 36512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar bool hasASTConsumer() const { return Consumer != 0; } 36612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 36712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 36812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 36912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 37012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 37112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 37212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 37312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 37412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer *takeASTConsumer() { return Consumer.take(); } 37512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 37612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 37712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takes ownership of \arg Value. 37812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar void setASTConsumer(ASTConsumer *Value); 37912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 38012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 381f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// @name Semantic analysis 382f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// { 383f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor bool hasSema() const { return TheSema != 0; } 384f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 385f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema &getSema() const { 386f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor assert(TheSema && "Compiler instance has no Sema object!"); 387f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor return *TheSema; 388f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 389f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 390f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema *takeSema() { return TheSema.take(); } 391f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 392f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// } 393f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// @name Module Management 394f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// { 395f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 396f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor ASTReader *getModuleManager() const { return ModuleManager; } 397f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 398f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// } 399c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 400c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 401c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 402c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 403c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 404c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 405c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 406c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 407c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 408c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 409c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 410c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// takeCodeCompletionConsumer - Remove the current code completion consumer 411c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// and give ownership to the caller. 412c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer *takeCodeCompletionConsumer() { 413c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return CompletionConsumer.take(); 414c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 415c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 416c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 417c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// the compiler instance takes ownership of \arg Value. 4188a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 419c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 420c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 421f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// @name Frontend timer 422f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// { 423f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 424f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam bool hasFrontendTimer() const { return FrontendTimer != 0; } 425f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 426f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::Timer &getFrontendTimer() const { 427f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam assert(FrontendTimer && "Compiler instance has no frontend timer!"); 428f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam return *FrontendTimer; 429f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 430f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 431f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// } 432a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 433a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 434a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 435a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 436a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 437dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param OutFile - The output file info. 438dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis void addOutputFile(const OutputFile &OutFile); 439a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 440e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam /// clearOutputFiles - Clear the output file list, destroying the contained 441a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 442a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 443a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 444e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam void clearOutputFiles(bool EraseFiles); 445a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 446a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 44716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 44816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 44916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4500fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 4510fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 4520fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 453e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// Note that this routine also replaces the diagnostic client, 454e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// allocating one if one is not provided. 455e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// 456e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// \param Client If non-NULL, a diagnostic client that will be 457e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// attached to (and, then, owned by) the Diagnostic inside this AST 458e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// unit. 459e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor void createDiagnostics(int Argc, const char* const *Argv, 460e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor DiagnosticClient *Client = 0); 4610fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 4620fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create a Diagnostic object with a the TextDiagnosticPrinter. 4630fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 4640fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// The \arg Argc and \arg Argv arguments are used only for logging purposes, 4650fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// when the diagnostic options indicate that the compiler should output 4660fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// logging information. 4670fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 468e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// If no diagnostic client is provided, this creates a 469e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// DiagnosticClient that is owned by the returned diagnostic 470e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// object, if using directly the caller is responsible for 471e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// releasing the returned Diagnostic's client eventually. 4725eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 473bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// \param Opts - The diagnostic options; note that the created text 474bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// diagnostic object contains a reference to these options and its lifetime 475bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// must extend past that of the diagnostic engine. 476bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// 477e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// \param Client If non-NULL, a diagnostic client that will be 478e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// attached to (and, then, owned by) the returned Diagnostic 479e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// object. 480e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// 481b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be 482b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// used by some diagnostics printers (for logging purposes only). 483b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// 4840fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 48528019772db70d4547be05a042eb950bc910f134fDouglas Gregor static llvm::IntrusiveRefCntPtr<Diagnostic> 4867d0c4ccd65b4549283c55e4923602e234f3811c5Axel Naumann createDiagnostics(const DiagnosticOptions &Opts, int Argc, 487e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor const char* const *Argv, 488b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar DiagnosticClient *Client = 0, 489b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar const CodeGenOptions *CodeGenOpts = 0); 4900fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 49116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 49216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 49316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 49416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 49539b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner void createSourceManager(FileManager &FileMgr); 49616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 49722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 49822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 49922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar void createPreprocessor(); 50022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 50122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create a Preprocessor object. 50222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 50322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Note that this also creates a new HeaderSearch object which will be owned 50422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// by the resulting Preprocessor. 50522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// 50622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// \return The new object on success, or null on failure. 50722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &, 50822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const PreprocessorOptions &, 50922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const HeaderSearchOptions &, 51022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const DependencyOutputOptions &, 51122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar const TargetInfo &, 5127d957472ef9a09048c03d8a11028536f908c18b9Fariborz Jahanian const FrontendOptions &, 51322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &, FileManager &); 51422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 5155eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 5165eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 5175eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 5180f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 5190f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 520686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void createPCHExternalASTSource(StringRef Path, 521ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl bool DisablePCHValidation, 5228ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor bool DisableStatCache, 523ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl void *DeserializationListener); 5240f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 5250f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 5260f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 5270f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 5280f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar static ExternalASTSource * 529686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createPCHExternalASTSource(StringRef Path, const std::string &Sysroot, 530fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor bool DisablePCHValidation, 5318ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor bool DisableStatCache, 532ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Preprocessor &PP, ASTContext &Context, 5331d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl void *DeserializationListener, bool Preamble); 534a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl 535c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 536c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 537c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 538c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 539c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 540c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 541c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg 542c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// OS. 543c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar static CodeCompleteConsumer * 544c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 545c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar unsigned Line, unsigned Column, 546a9f4f620daf073805b89e893afcdc5eb7a9bdc50Douglas Gregor bool ShowMacros, 5478071e4212ae08f8014e0c3ae6d18b7388003a5ccDouglas Gregor bool ShowCodePatterns, bool ShowGlobals, 5488cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream &OS); 549c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 550f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Create the Sema object to be used for parsing. 551f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void createSema(bool CompleteTranslationUnit, 552f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CodeCompleteConsumer *CompletionConsumer); 553f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 554f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// Create the frontend timer and replace any existing one with it. 555f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam void createFrontendTimer(); 556f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 557f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 558f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 559360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 560360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 561f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 562686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "", 563686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Extension = ""); 564f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 565f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 566f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 567360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 568360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 569f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar llvm::raw_fd_ostream * 570686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createOutputFile(StringRef OutputPath, 571ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar bool Binary = true, bool RemoveFileOnSignal = true, 572686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef BaseInput = "", 5737e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis StringRef Extension = "", 5747e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis bool UseTemporary = false); 575f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 576f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 577f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 578f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// If \arg OutputPath is empty, then createOutputFile will derive an output 579f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// path location as \arg BaseInput, with any suffix removed, and \arg 5807e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// Extension appended. If OutputPath is not stdout and \arg UseTemporary 5817e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// is true, createOutputFile will create a new temporary file that must be 5827e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// renamed to OutputPath in the end. 583f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 584f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 585f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Error [out] - On failure, the error message. 586f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param BaseInput - If \arg OutputPath is empty, the input path name to use 587f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 588f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 589f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 590ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// \param RemoveFileOnSignal - Whether the file should be registered with 591ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for 592ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// multithreaded use, as the underlying signal mechanism is not reentrant 5937e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// \param UseTemporary - Create a new temporary file that must be renamed to 5947e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// OutputPath in the end 595f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 596f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 597dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param TempPathName [out] - If given, the temporary file path name 598dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// will be stored here on success. 599f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar static llvm::raw_fd_ostream * 600686775deca8b8685eb90801495880e3abdd844c2Chris Lattner createOutputFile(StringRef OutputPath, std::string &Error, 601ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar bool Binary = true, bool RemoveFileOnSignal = true, 602686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef BaseInput = "", 603686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Extension = "", 6047e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis bool UseTemporary = false, 605dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string *ResultPathName = 0, 606dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string *TempPathName = 0); 607f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 60816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 609ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 610ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 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. 616686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool InitializeSourceManager(StringRef InputFile); 617ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 618ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 619ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 620ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 621ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 622686775deca8b8685eb90801495880e3abdd844c2Chris Lattner static bool InitializeSourceManager(StringRef InputFile, 623ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar Diagnostic &Diags, 624ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar FileManager &FileMgr, 625ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar SourceManager &SourceMgr, 626ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar const FrontendOptions &Opts); 627ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 628ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 6292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 6302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 6322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 6332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 634