CompilerInstance.h revision ef8225444452a1486bd721f3285301fe84643b00
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
13dc7b641574a733624489bd87fc7061771edf2113Douglas Gregor#include "clang/Basic/Diagnostic.h"
14a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor#include "clang/Basic/SourceManager.h"
1530a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Frontend/CompilerInvocation.h"
16651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "clang/Frontend/Utils.h"
176aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor#include "clang/Lex/ModuleLoader.h"
183d3589db579f7695667b913c5043dd264ebe546fDouglas Gregor#include "llvm/ADT/ArrayRef.h"
1949009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor#include "llvm/ADT/DenseMap.h"
2028019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h"
2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/StringRef.h"
2222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar#include <cassert>
23a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <list>
24651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include <memory>
25a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar#include <string>
263d3589db579f7695667b913c5043dd264ebe546fDouglas Gregor#include <utility>
272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace llvm {
29f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbarclass raw_fd_ostream;
30f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnamclass Timer;
312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar}
322a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarnamespace clang {
345eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbarclass ASTContext;
3512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbarclass ASTConsumer;
36f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTReader;
37c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbarclass CodeCompleteConsumer;
38d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieclass DiagnosticsEngine;
3978ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikieclass DiagnosticConsumer;
400f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass ExternalASTSource;
4149009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregorclass FileEntry;
4216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass FileManager;
430397af277e3bba16da1fd125ddba07415686b429Daniel Dunbarclass FrontendAction;
441a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregorclass Module;
450f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbarclass Preprocessor;
46f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregorclass Sema;
4716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbarclass SourceManager;
482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarclass TargetInfo;
492a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
502a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// CompilerInstance - Helper class for managing a single instance of the Clang
512a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// compiler.
522a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///
532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The CompilerInstance serves two purposes:
542a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///  (1) It manages the various objects which are necessary to run the compiler,
552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///      for example the preprocessor, the target information, and the AST
562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///      context.
572a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///  (2) It provides utility routines for constructing and manipulating the
582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///      common Clang objects.
592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///
602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance generally owns the instance of all the objects that it
612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// manages. However, clients can still share objects by manually setting the
622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// object and retaking ownership prior to destroying the CompilerInstance.
632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar///
642a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// The compiler instance is intended to simplify clients, but not to lock them
652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// in to the compiler instance for everything. When possible, utility functions
662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// come in two forms; a short form that reuses the CompilerInstance objects,
672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar/// and a long form that takes explicit instances of any required objects.
686aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregorclass CompilerInstance : public ModuleLoader {
692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The options used in this compiler instance.
70c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<CompilerInvocation> Invocation;
712a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The diagnostics engine instance.
73c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
752a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// The target being compiled for.
76c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<TargetInfo> Target;
772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
78651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// The virtual file system.
79651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  IntrusiveRefCntPtr<vfs::FileSystem> VirtualFileSystem;
80651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
8116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// The file manager.
82c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<FileManager> FileMgr;
8316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
8416b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// The source manager.
85c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<SourceManager> SourceMgr;
8616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
8722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// The preprocessor.
88c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<Preprocessor> PP;
8922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
905eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// The AST context.
91c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<ASTContext> Context;
925eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
9312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// The AST consumer.
94651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<ASTConsumer> Consumer;
9512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
96c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// The code completion consumer.
97651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
98c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
99f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// \brief The semantic analysis object.
100651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<Sema> TheSema;
101463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor
102f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief The frontend timer
103651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<llvm::Timer> FrontendTimer;
104651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
105651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \brief The ASTReader, if one exists.
106651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  IntrusiveRefCntPtr<ASTReader> ModuleManager;
107f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
108ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  /// \brief The module dependency collector for crashdumps
109ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
110ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
111651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \brief The dependency file generator.
112651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
113f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
114ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
115ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
11649009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor  /// \brief The set of top-level modules that has already been loaded,
11749009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor  /// along with the module map
1181a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
11949009ec701feb3009450e57e40c656e2ad7c1f41Douglas Gregor
120b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor  /// \brief The location of the module-import keyword for the last module
121b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor  /// import.
122b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor  SourceLocation LastModuleImportLoc;
123b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor
124b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor  /// \brief The result of the last module import.
125b514c792821a8f053027d88444e13bfaa8efef76Douglas Gregor  ///
126463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor  ModuleLoadResult LastModuleImportResult;
127a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor
128a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  /// \brief Whether we should (re)build the global module index once we
129a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  /// have finished with this translation unit.
130a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  bool BuildGlobalModuleIndex;
131a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor
1326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// \brief We have a full global module index, with all modules.
1336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool HaveFullGlobalModuleIndex;
1346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
135f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor  /// \brief One or more modules failed to build.
136f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor  bool ModuleBuildFailed;
137f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor
138dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  /// \brief Holds information about the output file.
139dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  ///
140dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  /// If TempFilename is not empty we must rename it to Filename at the end.
141651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// TempFilename may be empty and Filename non-empty if creating the temporary
142dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  /// failed.
143dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  struct OutputFile {
144dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis    std::string Filename;
145dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis    std::string TempFilename;
1468cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner    raw_ostream *OS;
147dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis
148dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis    OutputFile(const std::string &filename, const std::string &tempFilename,
1498cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner               raw_ostream *os)
150dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis      : Filename(filename), TempFilename(tempFilename), OS(os) { }
151dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  };
152dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis
153a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// The list of active output files.
154dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  std::list<OutputFile> OutputFiles;
155a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
156f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  CompilerInstance(const CompilerInstance &) LLVM_DELETED_FUNCTION;
157f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  void operator=(const CompilerInstance &) LLVM_DELETED_FUNCTION;
1582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbarpublic:
1596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  explicit CompilerInstance(bool BuildingModule = false);
1602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  ~CompilerInstance();
1612a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
1620397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// @name High-Level Operations
1630397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// {
1640397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar
1650397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// ExecuteAction - Execute the provided action against the compiler's
1660397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// CompilerInvocation object.
1670397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1680397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// This function makes the following assumptions:
1690397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1700397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - The invocation options should be initialized. This function does not
1710397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    handle the '-help' or '-version' options, clients should handle those
1720397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    directly.
1730397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1740397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - The diagnostics engine should have already been created by the client.
1750397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1760397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - No other CompilerInstance state should have been initialized (this is
1770397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    an unchecked error).
1780397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1790397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - Clients should have initialized any LLVM target features that may be
1800397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    required.
1810397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1820397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///  - Clients should eventually call llvm_shutdown() upon the completion of
1830397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///    this routine to ensure that any managed objects are properly destroyed.
1840397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1850397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// Note that this routine may write output to 'stderr'.
1860397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  ///
1870397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// \param Act - The action to execute.
1880397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// \return - True on success.
1890397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  //
1900397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // FIXME: This function should take the stream to write any debugging /
1910397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // verbose output to as an argument.
1920397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  //
1930397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
1940397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  // of the context or else not CompilerInstance specific.
1950397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  bool ExecuteAction(FrontendAction &Act);
1960397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar
1970397af277e3bba16da1fd125ddba07415686b429Daniel Dunbar  /// }
1982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Compiler Invocation and Options
1992a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
2002a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasInvocation() const { return Invocation != nullptr; }
2026228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar
2036228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  CompilerInvocation &getInvocation() {
2046228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    assert(Invocation && "Compiler instance has no invocation!");
2056228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return *Invocation;
2066228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  }
2076228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar
2084f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// setInvocation - Replace the current invocation.
2096228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar  void setInvocation(CompilerInvocation *Value);
2102a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
211a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  /// \brief Indicates whether we should (re)build the global module index.
212f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor  bool shouldBuildGlobalModuleIndex() const;
213f575d6e7c3b887ea4c5394d2c7e322c7a929a57eDouglas Gregor
214a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  /// \brief Set the flag indicating whether we should (re)build the global
215a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  /// module index.
216a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  void setBuildGlobalModuleIndex(bool Build) {
217a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor    BuildGlobalModuleIndex = Build;
218a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor  }
219a6b00fc97669aa25d89ae9f202b05dfadfd0e324Douglas Gregor
2202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
2212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Forwarding Methods
2222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
2232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
22445796b10d11869e86c6b85e24df165410536b313Ted Kremenek  AnalyzerOptionsRef getAnalyzerOpts() {
2256228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getAnalyzerOpts();
2262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2272a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2282a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  CodeGenOptions &getCodeGenOpts() {
2296228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getCodeGenOpts();
2302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2312a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const CodeGenOptions &getCodeGenOpts() const {
2326228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getCodeGenOpts();
2332a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2342a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2352a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  DependencyOutputOptions &getDependencyOutputOpts() {
2366228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDependencyOutputOpts();
2372a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2382a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const DependencyOutputOptions &getDependencyOutputOpts() const {
2396228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDependencyOutputOpts();
2402a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2412a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2422a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  DiagnosticOptions &getDiagnosticOpts() {
2436228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDiagnosticOpts();
2442a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2452a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const DiagnosticOptions &getDiagnosticOpts() const {
2466228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getDiagnosticOpts();
2472a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2482a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
249389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis  const FileSystemOptions &getFileSystemOpts() const {
250389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis    return Invocation->getFileSystemOpts();
251389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis  }
252389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis
2532a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  FrontendOptions &getFrontendOpts() {
2546228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getFrontendOpts();
2552a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2562a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const FrontendOptions &getFrontendOpts() const {
2576228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getFrontendOpts();
2582a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2592a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2602a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  HeaderSearchOptions &getHeaderSearchOpts() {
2616228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getHeaderSearchOpts();
2622a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2632a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const HeaderSearchOptions &getHeaderSearchOpts() const {
2646228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getHeaderSearchOpts();
2652a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2662a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2672a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  LangOptions &getLangOpts() {
268d3b74d9ca4f239a7a90ad193378c494306c57352Ted Kremenek    return *Invocation->getLangOpts();
2692a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2702a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const LangOptions &getLangOpts() const {
271d3b74d9ca4f239a7a90ad193378c494306c57352Ted Kremenek    return *Invocation->getLangOpts();
2722a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2732a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2742a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  PreprocessorOptions &getPreprocessorOpts() {
2756228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOpts();
2762a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2772a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const PreprocessorOptions &getPreprocessorOpts() const {
2786228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOpts();
2792a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2802a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2812a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  PreprocessorOutputOptions &getPreprocessorOutputOpts() {
2826228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOutputOpts();
2832a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2842a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
2856228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getPreprocessorOutputOpts();
2862a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  }
2872a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
288d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  TargetOptions &getTargetOpts() {
2896228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getTargetOpts();
290d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  }
291d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  const TargetOptions &getTargetOpts() const {
2926228ca00121669ec06a19df4fad87d5049c097cfDaniel Dunbar    return Invocation->getTargetOpts();
293d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar  }
294d58c03f42ebb4e548c2b53fa25b1cfe02ebb9ac0Daniel Dunbar
2952a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
2962a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Diagnostics Engine
2972a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
2982a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
2996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasDiagnostics() const { return Diagnostics != nullptr; }
300704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
3014f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// Get the current diagnostics engine.
302d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &getDiagnostics() const {
30322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(Diagnostics && "Compiler instance has no diagnostics!");
30422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *Diagnostics;
30522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
3062a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
3074f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// setDiagnostics - Replace the current diagnostics engine.
308d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  void setDiagnostics(DiagnosticsEngine *Value);
3092a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
31078ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  DiagnosticConsumer &getDiagnosticClient() const {
311bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor    assert(Diagnostics && Diagnostics->getClient() &&
312bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor           "Compiler instance has no diagnostic client!");
313bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor    return *Diagnostics->getClient();
31481f5a1e699b2eefa4a5e50b5dfc06df600748f59Daniel Dunbar  }
3152a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
3162a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
3172a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// @name Target Info
3182a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// {
3192a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
3206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasTarget() const { return Target != nullptr; }
321704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
32222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  TargetInfo &getTarget() const {
32322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(Target && "Compiler instance has no target!");
32422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *Target;
32522dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
3262a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
3274f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// Replace the current diagnostics engine.
3288a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setTarget(TargetInfo *Value);
3292a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
3302a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar  /// }
331651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// @name Virtual File System
332651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// {
333651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
3346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasVirtualFileSystem() const { return VirtualFileSystem != nullptr; }
335651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
336651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  vfs::FileSystem &getVirtualFileSystem() const {
337651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    assert(hasVirtualFileSystem() &&
338651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines           "Compiler instance has no virtual file system");
339651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return *VirtualFileSystem;
340651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
341651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
342651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \brief Replace the current virtual file system.
343651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
344651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \note Most clients should use setFileManager, which will implicitly reset
345651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// the virtual file system to the one contained in the file manager.
346651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void setVirtualFileSystem(IntrusiveRefCntPtr<vfs::FileSystem> FS) {
347651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    VirtualFileSystem = FS;
348651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  }
349651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
350651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// }
35116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// @name File Manager
35216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// {
35316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
3546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasFileManager() const { return FileMgr != nullptr; }
355704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
3564f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// Return the current file manager to the caller.
35722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  FileManager &getFileManager() const {
35822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(FileMgr && "Compiler instance has no file manager!");
35922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *FileMgr;
36022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
3614f32786ac45210143654390177105eb749b614e9Ted Kremenek
3624f32786ac45210143654390177105eb749b614e9Ted Kremenek  void resetAndLeakFileManager() {
363ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    BuryPointer(FileMgr.get());
3644f32786ac45210143654390177105eb749b614e9Ted Kremenek    FileMgr.resetWithoutRelease();
3654f32786ac45210143654390177105eb749b614e9Ted Kremenek  }
36616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
367651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \brief Replace the current file manager and virtual file system.
3688a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setFileManager(FileManager *Value);
36916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
37016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// }
37116b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// @name Source Manager
37216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// {
37316b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
3746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasSourceManager() const { return SourceMgr != nullptr; }
375704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
3764f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// Return the current source manager.
37722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  SourceManager &getSourceManager() const {
37822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(SourceMgr && "Compiler instance has no source manager!");
37922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *SourceMgr;
38022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
3814f32786ac45210143654390177105eb749b614e9Ted Kremenek
3824f32786ac45210143654390177105eb749b614e9Ted Kremenek  void resetAndLeakSourceManager() {
383ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    BuryPointer(SourceMgr.get());
3844f32786ac45210143654390177105eb749b614e9Ted Kremenek    SourceMgr.resetWithoutRelease();
3854f32786ac45210143654390177105eb749b614e9Ted Kremenek  }
38616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
3874f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// setSourceManager - Replace the current source manager.
3888a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setSourceManager(SourceManager *Value);
38916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
39016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// }
39122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// @name Preprocessor
39222dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// {
39322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
3946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasPreprocessor() const { return PP != nullptr; }
395704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
3964f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// Return the current preprocessor.
39722dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  Preprocessor &getPreprocessor() const {
39822dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    assert(PP && "Compiler instance has no preprocessor!");
39922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar    return *PP;
40022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  }
40122dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
4024f32786ac45210143654390177105eb749b614e9Ted Kremenek  void resetAndLeakPreprocessor() {
403ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    BuryPointer(PP.get());
4044f32786ac45210143654390177105eb749b614e9Ted Kremenek    PP.resetWithoutRelease();
4054f32786ac45210143654390177105eb749b614e9Ted Kremenek  }
40622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
4074f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// Replace the current preprocessor.
4088a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setPreprocessor(Preprocessor *Value);
40922dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
41022dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// }
4115eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// @name ASTContext
4125eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// {
4135eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
4146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool hasASTContext() const { return Context != nullptr; }
415704e48ae75111072eecaa20a365dff46fb49d2beDaniel Dunbar
4165eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  ASTContext &getASTContext() const {
4175eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar    assert(Context && "Compiler instance has no AST context!");
4185eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar    return *Context;
4195eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  }
4204f32786ac45210143654390177105eb749b614e9Ted Kremenek
4214f32786ac45210143654390177105eb749b614e9Ted Kremenek  void resetAndLeakASTContext() {
422ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    BuryPointer(Context.get());
4234f32786ac45210143654390177105eb749b614e9Ted Kremenek    Context.resetWithoutRelease();
4244f32786ac45210143654390177105eb749b614e9Ted Kremenek  }
4255eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
4264f32786ac45210143654390177105eb749b614e9Ted Kremenek  /// setASTContext - Replace the current AST context.
4278a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setASTContext(ASTContext *Value);
4285eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
429f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// \brief Replace the current Sema; the compiler instance takes ownership
430f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// of S.
431f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  void setSema(Sema *S);
432f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor
4335eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// }
43412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// @name ASTConsumer
43512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// {
43612ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
437651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  bool hasASTConsumer() const { return (bool)Consumer; }
43812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
43912ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  ASTConsumer &getASTConsumer() const {
44012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar    assert(Consumer && "Compiler instance has no AST consumer!");
44112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar    return *Consumer;
44212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  }
44312ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
44412ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// takeASTConsumer - Remove the current AST consumer and give ownership to
44512ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// the caller.
446651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ASTConsumer *takeASTConsumer() { return Consumer.release(); }
44712ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
44812ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// setASTConsumer - Replace the current AST consumer; the compiler instance
4491824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// takes ownership of \p Value.
45012ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  void setASTConsumer(ASTConsumer *Value);
45112ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar
45212ce6943aae499225708ecf364c5a8b0a3269c87Daniel Dunbar  /// }
453f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// @name Semantic analysis
454f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// {
455651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  bool hasSema() const { return (bool)TheSema; }
456651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
457f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  Sema &getSema() const {
458f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor    assert(TheSema && "Compiler instance has no Sema object!");
459f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor    return *TheSema;
460f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  }
461651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
462651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Sema *takeSema() { return TheSema.release(); }
4636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  void resetAndLeakSema() { BuryPointer(TheSema.release()); }
464651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
465f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// }
466f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// @name Module Management
467f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// {
468f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
469651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  IntrusiveRefCntPtr<ASTReader> getModuleManager() const;
470651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader);
471f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
472ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
473ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  void setModuleDepCollector(
474ef8225444452a1486bd721f3285301fe84643b00Stephen Hines      std::shared_ptr<ModuleDependencyCollector> Collector);
475ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
476f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// }
477c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// @name Code Completion
478c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// {
479c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
480651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
481c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
482c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  CodeCompleteConsumer &getCodeCompletionConsumer() const {
483c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar    assert(CompletionConsumer &&
484c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar           "Compiler instance has no code completion consumer!");
485c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar    return *CompletionConsumer;
486c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  }
487c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
488c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// takeCodeCompletionConsumer - Remove the current code completion consumer
489c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// and give ownership to the caller.
490c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  CodeCompleteConsumer *takeCodeCompletionConsumer() {
491651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return CompletionConsumer.release();
492c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  }
493c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
494c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// setCodeCompletionConsumer - Replace the current code completion consumer;
4951824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// the compiler instance takes ownership of \p Value.
4968a9f569262860b8d03203327afd6047be2a9b5a6Daniel Dunbar  void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
497c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
498c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// }
499f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// @name Frontend timer
500f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// {
501f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
502651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  bool hasFrontendTimer() const { return (bool)FrontendTimer; }
503f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
504f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  llvm::Timer &getFrontendTimer() const {
505f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam    assert(FrontendTimer && "Compiler instance has no frontend timer!");
506f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam    return *FrontendTimer;
507f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  }
508f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
509f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// }
510a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// @name Output Files
511a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// {
512a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
513a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// addOutputFile - Add an output file onto the list of tracked output files.
514a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  ///
515dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  /// \param OutFile - The output file info.
516dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  void addOutputFile(const OutputFile &OutFile);
517a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
518e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam  /// clearOutputFiles - Clear the output file list, destroying the contained
519a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// output streams.
520a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  ///
521a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// \param EraseFiles - If true, attempt to erase the files from disk.
522e51dd7be67808d52c80c09b832d875e9655ce6e0Kovarththanan Rajaratnam  void clearOutputFiles(bool EraseFiles);
523a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar
524a9204831639e31474b927681b97c46781b758a1aDaniel Dunbar  /// }
52516b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// @name Construction Utility Methods
52616b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// {
52716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
5280fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// Create the diagnostics engine using the invocation's diagnostic options
5290fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// and replace any existing one with it.
5300fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  ///
531e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// Note that this routine also replaces the diagnostic client,
532e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// allocating one if one is not provided.
533e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  ///
534e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// \param Client If non-NULL, a diagnostic client that will be
535d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
536e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// unit.
53778243658c533168d51fd076fba328437932ba6f1Douglas Gregor  ///
53878243658c533168d51fd076fba328437932ba6f1Douglas Gregor  /// \param ShouldOwnClient If Client is non-NULL, specifies whether
53978243658c533168d51fd076fba328437932ba6f1Douglas Gregor  /// the diagnostic object should take ownership of the client.
5406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  void createDiagnostics(DiagnosticConsumer *Client = nullptr,
541cc2b653c319599f502425d2c3de29865d47bb9e4Douglas Gregor                         bool ShouldOwnClient = true);
5420fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar
543d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
5440fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  ///
545e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// If no diagnostic client is provided, this creates a
54678ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  /// DiagnosticConsumer that is owned by the returned diagnostic
547e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// object, if using directly the caller is responsible for
548d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// releasing the returned DiagnosticsEngine's client eventually.
5495eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  ///
550bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  /// \param Opts - The diagnostic options; note that the created text
55102c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor  /// diagnostic object contains a reference to these options.
552bb3503a146f5eee6393a8b7542f38d9f5fce6583Daniel Dunbar  ///
553e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// \param Client If non-NULL, a diagnostic client that will be
554d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// attached to (and, then, owned by) the returned DiagnosticsEngine
555e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  /// object.
556e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor  ///
557b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar  /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
558b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar  /// used by some diagnostics printers (for logging purposes only).
559b6534bbee90bf73f364072051d10b60352d43c3eDaniel Dunbar  ///
5600fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar  /// \return The new object on success, or null on failure.
561c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  static IntrusiveRefCntPtr<DiagnosticsEngine>
562d47afb96a3f988e6d21a92fe4dfe875ab227c7c0Sean Silva  createDiagnostics(DiagnosticOptions *Opts,
5636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                    DiagnosticConsumer *Client = nullptr,
56478243658c533168d51fd076fba328437932ba6f1Douglas Gregor                    bool ShouldOwnClient = true,
5656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                    const CodeGenOptions *CodeGenOpts = nullptr);
5660fbb3d9a9cdd2201848be9eb017c54cd78538122Daniel Dunbar
56716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// Create the file manager and replace any existing one with it.
56816b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  void createFileManager();
56916b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
57016b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// Create the source manager and replace any existing one with it.
57139b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner  void createSourceManager(FileManager &FileMgr);
57216b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar
57322dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// Create the preprocessor, using the invocation, file, and source managers,
57422dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar  /// and replace any existing one with it.
575651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void createPreprocessor(TranslationUnitKind TUKind);
57622dacfacacf5559028550ba6ddfbaa4ea6cb3944Daniel Dunbar
5775eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  /// Create the AST context.
5785eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar  void createASTContext();
5795eb810024dc8a1d12d5f066c02c978f07c4fcb00Daniel Dunbar
5800f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// Create an external AST source to read a PCH file and attach it to the AST
5810f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// context.
5826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation,
583bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis                                  bool AllowPCHWithCompilerErrors,
5846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                                  void *DeserializationListener,
5856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                                  bool OwnDeserializationListener);
5860f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar
5870f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// Create an external AST source to read a PCH file.
5880f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  ///
5890f800391ffbfe3820e1c60246a09a97e5f065179Daniel Dunbar  /// \return - The new object on success, or null on failure.
5906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  static ExternalASTSource *createPCHExternalASTSource(
5916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,
5926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
5936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      void *DeserializationListener, bool OwnDeserializationListener,
5946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      bool Preamble, bool UseGlobalModuleIndex);
595a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl
596c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// Create a code completion consumer using the invocation; note that this
597c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// will cause the source manager to truncate the input source file at the
598c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// completion point.
599c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  void createCodeCompletionConsumer();
600c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
601c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  /// Create a code completion consumer to print code completion results, at
6021824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
603c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  static CodeCompleteConsumer *
604c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar  createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
605c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar                               unsigned Line, unsigned Column,
606d99ef536b241071b6f4c01db6525dc03242ac30bDmitri Gribenko                               const CodeCompleteOptions &Opts,
6078cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner                               raw_ostream &OS);
608c2f484f1f05216a9a427ac84b5773789a4661111Daniel Dunbar
609f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor  /// \brief Create the Sema object to be used for parsing.
610467dc88512b4ba4bb16e274ea3771dc1415d31daDouglas Gregor  void createSema(TranslationUnitKind TUKind,
611f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor                  CodeCompleteConsumer *CompletionConsumer);
612f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor
613f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  /// Create the frontend timer and replace any existing one with it.
614f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam  void createFrontendTimer();
615f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam
616f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Create the default output file (from the invocation's options) and add it
617f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// to the list of tracked output files.
618360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  ///
619e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar  /// The files created by this function always use temporary files to write to
620e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar  /// their result (that is, the data is written to a temporary file which will
621e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar  /// atomically replace the target output on success).
622e21dd284d8209a89137a03a0d63f2bd57be9e660Daniel Dunbar  ///
623360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  /// \return - Null on error.
624f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  llvm::raw_fd_ostream *
625686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "",
626686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                          StringRef Extension = "");
627f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar
628f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Create a new output file and add it to the list of tracked output files,
629f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// optionally deriving the output path name.
630360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  ///
631360435908c9b90429cfe192fab22854af1d4497cDaniel Dunbar  /// \return - Null on error.
632f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  llvm::raw_fd_ostream *
633686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  createOutputFile(StringRef OutputPath,
634375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   bool Binary, bool RemoveFileOnSignal,
635375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   StringRef BaseInput,
636375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   StringRef Extension,
637375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   bool UseTemporary,
63812f28ab8a53d7743081d607617309891fa8156f3Daniel Dunbar                   bool CreateMissingDirectories = false);
639f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar
640f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// Create a new output file, optionally deriving the output path name.
641f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  ///
6421824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// If \p OutputPath is empty, then createOutputFile will derive an output
6431824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// path location as \p BaseInput, with any suffix removed, and \p Extension
6441824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// appended. If \p OutputPath is not stdout and \p UseTemporary
6457e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis  /// is true, createOutputFile will create a new temporary file that must be
6461824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// renamed to \p OutputPath in the end.
647f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  ///
648f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param OutputPath - If given, the path to the output file.
649f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param Error [out] - On failure, the error message.
6501824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \param BaseInput - If \p OutputPath is empty, the input path name to use
651f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// for deriving the output path.
652f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param Extension - The extension to use for derived output names.
653f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param Binary - The mode to open the file in.
654ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar  /// \param RemoveFileOnSignal - Whether the file should be registered with
655ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar  /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for
656ff9cd968cd5b623e3ec7e5f862b598cd22f7ec79Daniel Dunbar  /// multithreaded use, as the underlying signal mechanism is not reentrant
6577e90985df09855dc309ed888a5b16a0ae684f8e3Argyrios Kyrtzidis  /// \param UseTemporary - Create a new temporary file that must be renamed to
65812f28ab8a53d7743081d607617309891fa8156f3Daniel Dunbar  /// OutputPath in the end.
6591824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \param CreateMissingDirectories - When \p UseTemporary is true, create
66012f28ab8a53d7743081d607617309891fa8156f3Daniel Dunbar  /// missing directories in the output path.
661f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// \param ResultPathName [out] - If given, the result path name will be
662f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  /// stored here on success.
663dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  /// \param TempPathName [out] - If given, the temporary file path name
664dc24572a44575e07a5d8bb6de52641a69f1bab27Argyrios Kyrtzidis  /// will be stored here on success.
665f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar  static llvm::raw_fd_ostream *
666686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  createOutputFile(StringRef OutputPath, std::string &Error,
667375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   bool Binary, bool RemoveFileOnSignal,
668375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   StringRef BaseInput,
669375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   StringRef Extension,
670375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   bool UseTemporary,
671375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   bool CreateMissingDirectories,
672375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   std::string *ResultPathName,
673375a4f519eb85d37e702c90498ef9816aeda4c3eRafael Espindola                   std::string *TempPathName);
674f482d59386dbc70716f7a5f65adb37ff86b501e6Daniel Dunbar
675ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  llvm::raw_null_ostream *createNullOutputFile();
676ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
67716b7449d86b843d0926b04f87104cf3fff7149feDaniel Dunbar  /// }
678ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// @name Initialization Utility Methods
679ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// {
680ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar
681ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// InitializeSourceManager - Initialize the source manager to set InputFile
682ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// as the main file.
683ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  ///
684ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// \return True on success.
6858e1fbbc492bc1f4833136d9b55e1aaf478565d32Argyrios Kyrtzidis  bool InitializeSourceManager(const FrontendInputFile &Input);
686ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar
687ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// InitializeSourceManager - Initialize the source manager to set InputFile
688ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// as the main file.
689ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  ///
690ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// \return True on success.
6918e1fbbc492bc1f4833136d9b55e1aaf478565d32Argyrios Kyrtzidis  static bool InitializeSourceManager(const FrontendInputFile &Input,
692a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor                DiagnosticsEngine &Diags,
693a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor                FileManager &FileMgr,
694a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor                SourceManager &SourceMgr,
695a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor                const FrontendOptions &Opts);
696ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar
697ccb6cb6fd9e48697564d536b07397b95dfc28d5bDaniel Dunbar  /// }
698651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
6996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  // Create module manager.
7006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  void createModuleManager();
7016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
702651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
703651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                              Module::NameVisibilityKind Visibility,
704651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                              bool IsInclusionDirective) override;
705651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
706651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility,
707651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                         SourceLocation ImportLoc, bool Complain) override;
708ca2ab45341c448284cf93770018c717810575f86Douglas Gregor
7093b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis  bool hadModuleLoaderFatalFailure() const {
7103b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis    return ModuleLoader::HadFatalFailure;
7113b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis  }
7123b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis
7136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override;
7146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
7156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
716ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
717ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) {
718ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    DependencyCollectors.push_back(std::move(Listener));
719ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  }
7202a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar};
7212a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
7222a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar} // end namespace clang
7232a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar
7242a79e162a3fde25c1941151a67966830d873f2dbDaniel Dunbar#endif
725