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 130e2c34f92f00628d48968dfea096d36381f494cbStephen Hines#include "clang/AST/ASTConsumer.h" 1487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#include "clang/Frontend/PCHContainerOperations.h" 15dc7b641574a733624489bd87fc7061771edf2113Douglas Gregor#include "clang/Basic/Diagnostic.h" 16a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor#include "clang/Basic/SourceManager.h" 1730a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Frontend/CompilerInvocation.h" 18651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "clang/Frontend/Utils.h" 196aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor#include "clang/Lex/ModuleLoader.h" 203d3589db579f7695667b913c5043dd264ebe546fDouglas Gregor#include "llvm/ADT/ArrayRef.h" 2149009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor#include "llvm/ADT/DenseMap.h" 2228019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 2330a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/StringRef.h" 2422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar#include <cassert> 25a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <list> 26651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include <memory> 27a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <string> 283d3589db579f7695667b913c5043dd264ebe546fDouglas Gregor#include <utility> 292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm { 31f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream; 32f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer; 3387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarclass TimerGroup; 342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} 352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang { 375eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext; 3812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer; 39f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTReader; 40c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer; 41d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieclass DiagnosticsEngine; 4278ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikieclass DiagnosticConsumer; 430f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource; 4449009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregorclass FileEntry; 4516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager; 460397af277e3bba16da1fd125ddba07415686b429Daniel Dunbarclass FrontendAction; 471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregorclass Module; 480f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor; 49f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregorclass Sema; 5016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager; 512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo; 522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang 542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler. 552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes: 572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (1) It manages the various objects which are necessary to run the compiler, 582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// for example the preprocessor, the target information, and the AST 592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// context. 602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// (2) It provides utility routines for constructing and manipulating the 612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// common Clang objects. 622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it 642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the 652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance. 662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// 672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them 682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions 692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects, 702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects. 716aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregorclass CompilerInstance : public ModuleLoader { 722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The options used in this compiler instance. 73c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<CompilerInvocation> Invocation; 742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The diagnostics engine instance. 76c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics; 772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 782a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// The target being compiled for. 79c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<TargetInfo> Target; 802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 8187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Auxiliary Target info. 8287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar IntrusiveRefCntPtr<TargetInfo> AuxTarget; 8387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 84651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// The virtual file system. 85651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IntrusiveRefCntPtr<vfs::FileSystem> VirtualFileSystem; 86651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 8716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The file manager. 88c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<FileManager> FileMgr; 8916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 9016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// The source manager. 91c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<SourceManager> SourceMgr; 9216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 9322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// The preprocessor. 94c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<Preprocessor> PP; 9522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 965eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// The AST context. 97c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<ASTContext> Context; 985eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 9912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// The AST consumer. 100651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<ASTConsumer> Consumer; 10112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 102c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// The code completion consumer. 103651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<CodeCompleteConsumer> CompletionConsumer; 104c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 105f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief The semantic analysis object. 106651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<Sema> TheSema; 107463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor 10887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief The frontend timer group. 10987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup; 11087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 11187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief The frontend timer. 112651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<llvm::Timer> FrontendTimer; 113651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 114651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief The ASTReader, if one exists. 115651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IntrusiveRefCntPtr<ASTReader> ModuleManager; 116f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 117c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines /// \brief The module dependency collector for crashdumps 118c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector; 119c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 12087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief The module provider. 12187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations; 12287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 123651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief The dependency file generator. 124651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator; 125f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 126c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors; 127c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 12849009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor /// \brief The set of top-level modules that has already been loaded, 12949009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor /// along with the module map 1301a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules; 131176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 132b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor /// \brief The location of the module-import keyword for the last module 133b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor /// import. 134b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor SourceLocation LastModuleImportLoc; 135b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor 136b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor /// \brief The result of the last module import. 137b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor /// 138463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor ModuleLoadResult LastModuleImportResult; 139a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor 140a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor /// \brief Whether we should (re)build the global module index once we 141a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor /// have finished with this translation unit. 142a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor bool BuildGlobalModuleIndex; 143a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor 1446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// \brief We have a full global module index, with all modules. 1456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool HaveFullGlobalModuleIndex; 1466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 147f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor /// \brief One or more modules failed to build. 148f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor bool ModuleBuildFailed; 149f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor 150dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \brief Holds information about the output file. 151dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// 152dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// If TempFilename is not empty we must rename it to Filename at the end. 153651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// TempFilename may be empty and Filename non-empty if creating the temporary 154dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// failed. 155dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis struct OutputFile { 156dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string Filename; 157dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::string TempFilename; 15858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar std::unique_ptr<raw_ostream> OS; 159dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 16087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar OutputFile(std::string filename, std::string tempFilename, 16158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar std::unique_ptr<raw_ostream> OS) 16287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar : Filename(std::move(filename)), TempFilename(std::move(tempFilename)), 16387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar OS(std::move(OS)) {} 16458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar OutputFile(OutputFile &&O) 16558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar : Filename(std::move(O.Filename)), 16658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)) {} 167dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis }; 168dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis 16958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// If the output doesn't support seeking (terminal, pipe). we switch 17058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// the stream to a buffer_ostream. These are the buffer and the original 17158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// stream. 17258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream; 17358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 174a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// The list of active output files. 175dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis std::list<OutputFile> OutputFiles; 176a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 1770e2c34f92f00628d48968dfea096d36381f494cbStephen Hines CompilerInstance(const CompilerInstance &) = delete; 1780e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void operator=(const CompilerInstance &) = delete; 1792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic: 18087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar explicit CompilerInstance( 18187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar std::shared_ptr<PCHContainerOperations> PCHContainerOps = 18287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar std::make_shared<PCHContainerOperations>(), 18387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool BuildingModule = false); 18458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar ~CompilerInstance() override; 1852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 1860397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// @name High-Level Operations 1870397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// { 1880397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 1890397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// ExecuteAction - Execute the provided action against the compiler's 1900397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// CompilerInvocation object. 1910397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1920397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// This function makes the following assumptions: 1930397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1940397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The invocation options should be initialized. This function does not 1950397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// handle the '-help' or '-version' options, clients should handle those 1960397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// directly. 1970397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 1980397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - The diagnostics engine should have already been created by the client. 1990397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 2000397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - No other CompilerInstance state should have been initialized (this is 2010397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// an unchecked error). 2020397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 2030397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should have initialized any LLVM target features that may be 2040397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// required. 2050397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 2060397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// - Clients should eventually call llvm_shutdown() upon the completion of 2070397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// this routine to ensure that any managed objects are properly destroyed. 2080397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 2090397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// Note that this routine may write output to 'stderr'. 2100397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// 2110397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \param Act - The action to execute. 2120397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// \return - True on success. 2130397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 2140397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: This function should take the stream to write any debugging / 2150397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // verbose output to as an argument. 2160397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // 2170397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // FIXME: Eliminate the llvm_shutdown requirement, that should either be part 2180397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar // of the context or else not CompilerInstance specific. 2190397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar bool ExecuteAction(FrontendAction &Act); 2200397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar 2210397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar /// } 2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Compiler Invocation and Options 2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasInvocation() const { return Invocation != nullptr; } 2266228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 2276228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar CompilerInvocation &getInvocation() { 2286228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar assert(Invocation && "Compiler instance has no invocation!"); 2296228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return *Invocation; 2306228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar } 2316228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar 2324f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setInvocation - Replace the current invocation. 2336228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar void setInvocation(CompilerInvocation *Value); 2342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 235a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor /// \brief Indicates whether we should (re)build the global module index. 236f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor bool shouldBuildGlobalModuleIndex() const; 237f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor 238a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor /// \brief Set the flag indicating whether we should (re)build the global 239a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor /// module index. 240a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor void setBuildGlobalModuleIndex(bool Build) { 241a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor BuildGlobalModuleIndex = Build; 242a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor } 243a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor 2442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 2452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Forwarding Methods 2462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 2472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 24845796b10d11869e86c6b85e24df165410536b313Ted Kremenek AnalyzerOptionsRef getAnalyzerOpts() { 2496228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getAnalyzerOpts(); 2502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar CodeGenOptions &getCodeGenOpts() { 2536228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 2542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const CodeGenOptions &getCodeGenOpts() const { 2566228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getCodeGenOpts(); 2572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DependencyOutputOptions &getDependencyOutputOpts() { 2606228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 2612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DependencyOutputOptions &getDependencyOutputOpts() const { 2636228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDependencyOutputOpts(); 2642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar DiagnosticOptions &getDiagnosticOpts() { 2676228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2682a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const DiagnosticOptions &getDiagnosticOpts() const { 2706228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getDiagnosticOpts(); 2712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2730e2c34f92f00628d48968dfea096d36381f494cbStephen Hines FileSystemOptions &getFileSystemOpts() { 2740e2c34f92f00628d48968dfea096d36381f494cbStephen Hines return Invocation->getFileSystemOpts(); 2750e2c34f92f00628d48968dfea096d36381f494cbStephen Hines } 276389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis const FileSystemOptions &getFileSystemOpts() const { 277389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis return Invocation->getFileSystemOpts(); 278389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis } 279389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 2802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar FrontendOptions &getFrontendOpts() { 2816228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2822a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const FrontendOptions &getFrontendOpts() const { 2846228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getFrontendOpts(); 2852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar HeaderSearchOptions &getHeaderSearchOpts() { 2886228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2892a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2902a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const HeaderSearchOptions &getHeaderSearchOpts() const { 2916228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getHeaderSearchOpts(); 2922a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2932a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 2942a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar LangOptions &getLangOpts() { 295d3b74d9ca4f239a7a90ad193378c494306c57352Ted Kremenek return *Invocation->getLangOpts(); 2962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 2972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const LangOptions &getLangOpts() const { 298d3b74d9ca4f239a7a90ad193378c494306c57352Ted Kremenek return *Invocation->getLangOpts(); 2992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 3002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3012a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOptions &getPreprocessorOpts() { 3026228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 3032a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 3042a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOptions &getPreprocessorOpts() const { 3056228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOpts(); 3062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 3072a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3082a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar PreprocessorOutputOptions &getPreprocessorOutputOpts() { 3096228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 3102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 3112a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 3126228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getPreprocessorOutputOpts(); 3132a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar } 3142a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 315d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar TargetOptions &getTargetOpts() { 3166228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 317d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 318d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar const TargetOptions &getTargetOpts() const { 3196228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar return Invocation->getTargetOpts(); 320d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar } 321d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar 3222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 3232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Diagnostics Engine 3242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 3252a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasDiagnostics() const { return Diagnostics != nullptr; } 327704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3284f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Get the current diagnostics engine. 329d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &getDiagnostics() const { 33022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Diagnostics && "Compiler instance has no diagnostics!"); 33122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Diagnostics; 33222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 3332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3344f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setDiagnostics - Replace the current diagnostics engine. 335d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie void setDiagnostics(DiagnosticsEngine *Value); 3362a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 33778ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer &getDiagnosticClient() const { 338bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor assert(Diagnostics && Diagnostics->getClient() && 339bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor "Compiler instance has no diagnostic client!"); 340bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor return *Diagnostics->getClient(); 34181f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar } 3422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3432a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 3442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// @name Target Info 3452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// { 3462a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasTarget() const { return Target != nullptr; } 348704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 34922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar TargetInfo &getTarget() const { 35022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(Target && "Compiler instance has no target!"); 35122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *Target; 35222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 3532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 35487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Replace the current Target. 3558a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setTarget(TargetInfo *Value); 3562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 3572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar /// } 35887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// @name AuxTarget Info 35987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// { 36087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 36187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar TargetInfo *getAuxTarget() const { return AuxTarget.get(); } 36287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 36387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Replace the current AuxTarget. 36487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void setAuxTarget(TargetInfo *Value); 36587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 36687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// } 367651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// @name Virtual File System 368651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// { 369651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 3706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasVirtualFileSystem() const { return VirtualFileSystem != nullptr; } 371651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 372651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vfs::FileSystem &getVirtualFileSystem() const { 373651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(hasVirtualFileSystem() && 374651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines "Compiler instance has no virtual file system"); 375651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return *VirtualFileSystem; 376651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 377651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 378651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Replace the current virtual file system. 379651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// 380651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \note Most clients should use setFileManager, which will implicitly reset 381651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// the virtual file system to the one contained in the file manager. 382651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void setVirtualFileSystem(IntrusiveRefCntPtr<vfs::FileSystem> FS) { 3834967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar VirtualFileSystem = std::move(FS); 384651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 385651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 386651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// } 38716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name File Manager 38816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 38916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 3906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasFileManager() const { return FileMgr != nullptr; } 391704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 3924f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current file manager to the caller. 39322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar FileManager &getFileManager() const { 39422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(FileMgr && "Compiler instance has no file manager!"); 39522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *FileMgr; 39622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 3974f32786ac45210143654390177105eb749b614e9Ted Kremenek 3984f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakFileManager() { 399c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines BuryPointer(FileMgr.get()); 4004f32786ac45210143654390177105eb749b614e9Ted Kremenek FileMgr.resetWithoutRelease(); 4014f32786ac45210143654390177105eb749b614e9Ted Kremenek } 40216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 403651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Replace the current file manager and virtual file system. 4048a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setFileManager(FileManager *Value); 40516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 40616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 40716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Source Manager 40816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 40916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasSourceManager() const { return SourceMgr != nullptr; } 411704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 4124f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current source manager. 41322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar SourceManager &getSourceManager() const { 41422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(SourceMgr && "Compiler instance has no source manager!"); 41522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *SourceMgr; 41622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 4174f32786ac45210143654390177105eb749b614e9Ted Kremenek 4184f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakSourceManager() { 419c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines BuryPointer(SourceMgr.get()); 4204f32786ac45210143654390177105eb749b614e9Ted Kremenek SourceMgr.resetWithoutRelease(); 4214f32786ac45210143654390177105eb749b614e9Ted Kremenek } 42216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 4234f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setSourceManager - Replace the current source manager. 4248a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setSourceManager(SourceManager *Value); 42516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 42616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 42722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// @name Preprocessor 42822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// { 42922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 4306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasPreprocessor() const { return PP != nullptr; } 431704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 4324f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Return the current preprocessor. 43322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar Preprocessor &getPreprocessor() const { 43422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar assert(PP && "Compiler instance has no preprocessor!"); 43522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar return *PP; 43622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar } 43722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 4384f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakPreprocessor() { 439c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines BuryPointer(PP.get()); 4404f32786ac45210143654390177105eb749b614e9Ted Kremenek PP.resetWithoutRelease(); 4414f32786ac45210143654390177105eb749b614e9Ted Kremenek } 44222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 4434f32786ac45210143654390177105eb749b614e9Ted Kremenek /// Replace the current preprocessor. 4448a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setPreprocessor(Preprocessor *Value); 44522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 44622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// } 4475eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// @name ASTContext 4485eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// { 4495eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 4506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool hasASTContext() const { return Context != nullptr; } 451704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar 4525eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar ASTContext &getASTContext() const { 4535eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar assert(Context && "Compiler instance has no AST context!"); 4545eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar return *Context; 4555eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar } 4564f32786ac45210143654390177105eb749b614e9Ted Kremenek 4574f32786ac45210143654390177105eb749b614e9Ted Kremenek void resetAndLeakASTContext() { 458c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines BuryPointer(Context.get()); 4594f32786ac45210143654390177105eb749b614e9Ted Kremenek Context.resetWithoutRelease(); 4604f32786ac45210143654390177105eb749b614e9Ted Kremenek } 4615eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 4624f32786ac45210143654390177105eb749b614e9Ted Kremenek /// setASTContext - Replace the current AST context. 4638a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setASTContext(ASTContext *Value); 4645eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 465f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Replace the current Sema; the compiler instance takes ownership 466f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// of S. 467f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor void setSema(Sema *S); 468f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 4695eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// } 47012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// @name ASTConsumer 47112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// { 47212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 473651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool hasASTConsumer() const { return (bool)Consumer; } 47412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 47512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar ASTConsumer &getASTConsumer() const { 47612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar assert(Consumer && "Compiler instance has no AST consumer!"); 47712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar return *Consumer; 47812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar } 47912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 48012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// takeASTConsumer - Remove the current AST consumer and give ownership to 48112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// the caller. 482176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); } 48312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 48412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// setASTConsumer - Replace the current AST consumer; the compiler instance 4851824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// takes ownership of \p Value. 486176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void setASTConsumer(std::unique_ptr<ASTConsumer> Value); 48712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar 48812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar /// } 489f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// @name Semantic analysis 490f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// { 491651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool hasSema() const { return (bool)TheSema; } 492651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 493f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor Sema &getSema() const { 494f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor assert(TheSema && "Compiler instance has no Sema object!"); 495f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor return *TheSema; 496f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 497651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 498176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines std::unique_ptr<Sema> takeSema(); 499176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void resetAndLeakSema(); 500651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 501f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// } 502f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// @name Module Management 503f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// { 504f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 505651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IntrusiveRefCntPtr<ASTReader> getModuleManager() const; 506651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader); 507f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 508c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const; 509c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void setModuleDepCollector( 510c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines std::shared_ptr<ModuleDependencyCollector> Collector); 511c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 51287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const { 51387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return ThePCHContainerOperations; 51487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 51587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 51687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Return the appropriate PCHContainerWriter depending on the 51787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// current CodeGenOptions. 51887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const PCHContainerWriter &getPCHContainerWriter() const { 51987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(Invocation && "cannot determine module format without invocation"); 52087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar StringRef Format = getHeaderSearchOpts().ModuleFormat; 52187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format); 52287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (!Writer) { 52387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (Diagnostics) 52487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Diagnostics->Report(diag::err_module_format_unhandled) << Format; 52587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::report_fatal_error("unknown module format"); 52687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 52787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return *Writer; 52887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 52987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 53087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Return the appropriate PCHContainerReader depending on the 53187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// current CodeGenOptions. 53287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const PCHContainerReader &getPCHContainerReader() const { 53387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(Invocation && "cannot determine module format without invocation"); 53487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar StringRef Format = getHeaderSearchOpts().ModuleFormat; 53587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format); 53687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (!Reader) { 53787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (Diagnostics) 53887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Diagnostics->Report(diag::err_module_format_unhandled) << Format; 53987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::report_fatal_error("unknown module format"); 54087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 54187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return *Reader; 54287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 54387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 544f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor /// } 545c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// @name Code Completion 546c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// { 547c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 548651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; } 549c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 550c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar CodeCompleteConsumer &getCodeCompletionConsumer() const { 551c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar assert(CompletionConsumer && 552c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar "Compiler instance has no code completion consumer!"); 553c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar return *CompletionConsumer; 554c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar } 555c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 556c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// setCodeCompletionConsumer - Replace the current code completion consumer; 5571824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// the compiler instance takes ownership of \p Value. 5588a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 559c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 560c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// } 561f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// @name Frontend timer 562f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// { 563f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 564651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool hasFrontendTimer() const { return (bool)FrontendTimer; } 565f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 566f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::Timer &getFrontendTimer() const { 567f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam assert(FrontendTimer && "Compiler instance has no frontend timer!"); 568f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam return *FrontendTimer; 569f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 570f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 571f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// } 572a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// @name Output Files 573a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// { 574a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 575a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// addOutputFile - Add an output file onto the list of tracked output files. 576a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 577dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param OutFile - The output file info. 57858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void addOutputFile(OutputFile &&OutFile); 579a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 580e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam /// clearOutputFiles - Clear the output file list, destroying the contained 581a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// output streams. 582a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// 583a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// \param EraseFiles - If true, attempt to erase the files from disk. 584e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam void clearOutputFiles(bool EraseFiles); 585a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar 586a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar /// } 58716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// @name Construction Utility Methods 58816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// { 58916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 5900fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// Create the diagnostics engine using the invocation's diagnostic options 5910fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// and replace any existing one with it. 5920fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 593e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// Note that this routine also replaces the diagnostic client, 594e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// allocating one if one is not provided. 595e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// 596e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// \param Client If non-NULL, a diagnostic client that will be 597d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST 598e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// unit. 59978243658c533168d51fd076fba328437932ba6f1Douglas Gregor /// 60078243658c533168d51fd076fba328437932ba6f1Douglas Gregor /// \param ShouldOwnClient If Client is non-NULL, specifies whether 60178243658c533168d51fd076fba328437932ba6f1Douglas Gregor /// the diagnostic object should take ownership of the client. 6026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void createDiagnostics(DiagnosticConsumer *Client = nullptr, 603cc2b653c319599f502425d2c3de29865d47bb9e4Douglas Gregor bool ShouldOwnClient = true); 6040fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 605d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter. 6060fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// 607e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// If no diagnostic client is provided, this creates a 60878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie /// DiagnosticConsumer that is owned by the returned diagnostic 609e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// object, if using directly the caller is responsible for 610d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// releasing the returned DiagnosticsEngine's client eventually. 6115eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// 612bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// \param Opts - The diagnostic options; note that the created text 61302c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor /// diagnostic object contains a reference to these options. 614bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar /// 615e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// \param Client If non-NULL, a diagnostic client that will be 616d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// attached to (and, then, owned by) the returned DiagnosticsEngine 617e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// object. 618e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// 619b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be 620b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// used by some diagnostics printers (for logging purposes only). 621b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar /// 6220fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar /// \return The new object on success, or null on failure. 623c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith static IntrusiveRefCntPtr<DiagnosticsEngine> 624d47afb96a3f988e6d21a92fe4dfe875ab227c7c0Sean Silva createDiagnostics(DiagnosticOptions *Opts, 6256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines DiagnosticConsumer *Client = nullptr, 62678243658c533168d51fd076fba328437932ba6f1Douglas Gregor bool ShouldOwnClient = true, 6276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines const CodeGenOptions *CodeGenOpts = nullptr); 6280fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar 62916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the file manager and replace any existing one with it. 63016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar void createFileManager(); 63116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 63216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// Create the source manager and replace any existing one with it. 63339b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner void createSourceManager(FileManager &FileMgr); 63416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar 63522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// Create the preprocessor, using the invocation, file, and source managers, 63622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar /// and replace any existing one with it. 637651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void createPreprocessor(TranslationUnitKind TUKind); 63822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar 6390e2c34f92f00628d48968dfea096d36381f494cbStephen Hines std::string getSpecificModuleCachePath(); 6400e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 6415eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar /// Create the AST context. 6425eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar void createASTContext(); 6435eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar 6440f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file and attach it to the AST 6450f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// context. 6466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, 647bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis bool AllowPCHWithCompilerErrors, 6486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void *DeserializationListener, 6496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool OwnDeserializationListener); 6500f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar 6510f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// Create an external AST source to read a PCH file. 6520f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// 6530f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar /// \return - The new object on success, or null on failure. 6540e2c34f92f00628d48968dfea096d36381f494cbStephen Hines static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource( 65587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar StringRef Path, StringRef Sysroot, bool DisablePCHValidation, 6566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, 65787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const PCHContainerReader &PCHContainerRdr, 65887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ArrayRef<IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, 6596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void *DeserializationListener, bool OwnDeserializationListener, 6606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool Preamble, bool UseGlobalModuleIndex); 661a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl 662c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer using the invocation; note that this 663c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// will cause the source manager to truncate the input source file at the 664c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// completion point. 665c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar void createCodeCompletionConsumer(); 666c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 667c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar /// Create a code completion consumer to print code completion results, at 6681824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \p Filename, \p Line, and \p Column, to the given output stream \p OS. 66987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static CodeCompleteConsumer *createCodeCompletionConsumer( 67087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column, 67187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CodeCompleteOptions &Opts, raw_ostream &OS); 672c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar 673f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor /// \brief Create the Sema object to be used for parsing. 674467dc88512b4ba4bb16e274ea3771dc1415d31daDouglas Gregor void createSema(TranslationUnitKind TUKind, 675f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CodeCompleteConsumer *CompletionConsumer); 676f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 677f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam /// Create the frontend timer and replace any existing one with it. 678f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam void createFrontendTimer(); 679f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam 680f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create the default output file (from the invocation's options) and add it 681f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// to the list of tracked output files. 682360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 683e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar /// The files created by this function always use temporary files to write to 684e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar /// their result (that is, the data is written to a temporary file which will 685e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar /// atomically replace the target output on success). 686e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar /// 687360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 68858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar raw_pwrite_stream *createDefaultOutputFile(bool Binary = true, 68958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar StringRef BaseInput = "", 69058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar StringRef Extension = ""); 691f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 692f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file and add it to the list of tracked output files, 693f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// optionally deriving the output path name. 694360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// 695360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar /// \return - Null on error. 69658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar raw_pwrite_stream *createOutputFile(StringRef OutputPath, bool Binary, 69758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool RemoveFileOnSignal, 69858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar StringRef BaseInput, StringRef Extension, 69958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool UseTemporary, 70058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool CreateMissingDirectories = false); 701f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 702f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// Create a new output file, optionally deriving the output path name. 703f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 7041824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// If \p OutputPath is empty, then createOutputFile will derive an output 7051824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// path location as \p BaseInput, with any suffix removed, and \p Extension 7061824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// appended. If \p OutputPath is not stdout and \p UseTemporary 7077e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// is true, createOutputFile will create a new temporary file that must be 7081824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// renamed to \p OutputPath in the end. 709f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// 710f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param OutputPath - If given, the path to the output file. 711176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \param Error [out] - On failure, the error. 7121824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \param BaseInput - If \p OutputPath is empty, the input path name to use 713f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// for deriving the output path. 714f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Extension - The extension to use for derived output names. 715f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param Binary - The mode to open the file in. 716ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// \param RemoveFileOnSignal - Whether the file should be registered with 717ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for 718ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar /// multithreaded use, as the underlying signal mechanism is not reentrant 7197e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis /// \param UseTemporary - Create a new temporary file that must be renamed to 72012f28ab8a53d7743081d607617309891fa8156f3Daniel Dunbar /// OutputPath in the end. 7211824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \param CreateMissingDirectories - When \p UseTemporary is true, create 72212f28ab8a53d7743081d607617309891fa8156f3Daniel Dunbar /// missing directories in the output path. 723f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// \param ResultPathName [out] - If given, the result path name will be 724f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar /// stored here on success. 725dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// \param TempPathName [out] - If given, the temporary file path name 726dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis /// will be stored here on success. 72758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar std::unique_ptr<raw_pwrite_stream> 728176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines createOutputFile(StringRef OutputPath, std::error_code &Error, bool Binary, 729176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool RemoveFileOnSignal, StringRef BaseInput, 730176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines StringRef Extension, bool UseTemporary, 731176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool CreateMissingDirectories, std::string *ResultPathName, 732375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola std::string *TempPathName); 733f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar 734c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines llvm::raw_null_ostream *createNullOutputFile(); 735c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 73616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar /// } 737ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// @name Initialization Utility Methods 738ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// { 739ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 740ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 741ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 742ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 743ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 7448e1fbbc492bc1f4833136d9b55e1aaf478565d32Argyrios Kyrtzidis bool InitializeSourceManager(const FrontendInputFile &Input); 745ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 746ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// InitializeSourceManager - Initialize the source manager to set InputFile 747ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// as the main file. 748ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// 749ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// \return True on success. 7508e1fbbc492bc1f4833136d9b55e1aaf478565d32Argyrios Kyrtzidis static bool InitializeSourceManager(const FrontendInputFile &Input, 7514967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar DiagnosticsEngine &Diags, 7524967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar FileManager &FileMgr, 7534967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar SourceManager &SourceMgr, 7544967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar HeaderSearch *HS, 7554967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar DependencyOutputOptions &DepOpts, 7564967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const FrontendOptions &Opts); 757ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar 758ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar /// } 759651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 7606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // Create module manager. 7616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void createModuleManager(); 7626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 763176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool loadModuleFile(StringRef FileName); 764176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 765651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, 766651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Module::NameVisibilityKind Visibility, 767651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool IsInclusionDirective) override; 768651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 769651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, 770b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar SourceLocation ImportLoc) override; 771ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 7723b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis bool hadModuleLoaderFatalFailure() const { 7733b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis return ModuleLoader::HadFatalFailure; 7743b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis } 7753b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis 7766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override; 7776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override; 779c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 780c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) { 781c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines DependencyCollectors.push_back(std::move(Listener)); 782c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines } 7832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}; 7842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 7852a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang 7862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar 7872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif 788