CompilerInstance.h revision 249423
1105197Ssam//===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===// 2105197Ssam// 3105197Ssam// The LLVM Compiler Infrastructure 4139823Simp// 5105197Ssam// This file is distributed under the University of Illinois Open Source 6105197Ssam// License. See LICENSE.TXT for details. 7105197Ssam// 8105197Ssam//===----------------------------------------------------------------------===// 9105197Ssam 10105197Ssam#ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ 11105197Ssam#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ 12105197Ssam 13105197Ssam#include "clang/Basic/Diagnostic.h" 14105197Ssam#include "clang/Basic/SourceManager.h" 15105197Ssam#include "clang/Frontend/CompilerInvocation.h" 16105197Ssam#include "clang/Lex/ModuleLoader.h" 17105197Ssam#include "llvm/ADT/ArrayRef.h" 18105197Ssam#include "llvm/ADT/DenseMap.h" 19105197Ssam#include "llvm/ADT/IntrusiveRefCntPtr.h" 20105197Ssam#include "llvm/ADT/OwningPtr.h" 21105197Ssam#include "llvm/ADT/StringRef.h" 22105197Ssam#include <cassert> 23105197Ssam#include <list> 24105197Ssam#include <string> 25105197Ssam#include <utility> 26105197Ssam 27105197Ssamnamespace llvm { 28105197Ssamclass raw_fd_ostream; 29105197Ssamclass Timer; 30105197Ssam} 31105197Ssam 32105197Ssamnamespace clang { 33105197Ssamclass ASTContext; 34105197Ssamclass ASTConsumer; 35105197Ssamclass ASTReader; 36105197Ssamclass CodeCompleteConsumer; 37105197Ssamclass DiagnosticsEngine; 38105197Ssamclass DiagnosticConsumer; 39105197Ssamclass ExternalASTSource; 40105197Ssamclass FileEntry; 41105197Ssamclass FileManager; 42105197Ssamclass FrontendAction; 43105197Ssamclass Module; 44105197Ssamclass Preprocessor; 45119643Ssamclass Sema; 46119643Ssamclass SourceManager; 47105197Ssamclass TargetInfo; 48105197Ssam 49105197Ssam/// CompilerInstance - Helper class for managing a single instance of the Clang 50105197Ssam/// compiler. 51105197Ssam/// 52105197Ssam/// The CompilerInstance serves two purposes: 53105197Ssam/// (1) It manages the various objects which are necessary to run the compiler, 54105197Ssam/// for example the preprocessor, the target information, and the AST 55105197Ssam/// context. 56105197Ssam/// (2) It provides utility routines for constructing and manipulating the 57158767Spjd/// common Clang objects. 58105197Ssam/// 59105197Ssam/// The compiler instance generally owns the instance of all the objects that it 60105197Ssam/// manages. However, clients can still share objects by manually setting the 61105197Ssam/// object and retaking ownership prior to destroying the CompilerInstance. 62105197Ssam/// 63195699Srwatson/// The compiler instance is intended to simplify clients, but not to lock them 64105197Ssam/// in to the compiler instance for everything. When possible, utility functions 65105197Ssam/// come in two forms; a short form that reuses the CompilerInstance objects, 66105197Ssam/// and a long form that takes explicit instances of any required objects. 67105197Ssamclass CompilerInstance : public ModuleLoader { 68105197Ssam /// The options used in this compiler instance. 69105197Ssam IntrusiveRefCntPtr<CompilerInvocation> Invocation; 70105197Ssam 71105197Ssam /// The diagnostics engine instance. 72105197Ssam IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics; 73105197Ssam 74105197Ssam /// The target being compiled for. 75105197Ssam IntrusiveRefCntPtr<TargetInfo> Target; 76105197Ssam 77105197Ssam /// The file manager. 78105197Ssam IntrusiveRefCntPtr<FileManager> FileMgr; 79105197Ssam 80105197Ssam /// The source manager. 81105197Ssam IntrusiveRefCntPtr<SourceManager> SourceMgr; 82105197Ssam 83105197Ssam /// The preprocessor. 84105197Ssam IntrusiveRefCntPtr<Preprocessor> PP; 85105197Ssam 86105197Ssam /// The AST context. 87105197Ssam IntrusiveRefCntPtr<ASTContext> Context; 88105197Ssam 89105197Ssam /// The AST consumer. 90105197Ssam OwningPtr<ASTConsumer> Consumer; 91105197Ssam 92105197Ssam /// The code completion consumer. 93105197Ssam OwningPtr<CodeCompleteConsumer> CompletionConsumer; 94105197Ssam 95105197Ssam /// \brief The semantic analysis object. 96105197Ssam OwningPtr<Sema> TheSema; 97105197Ssam 98105197Ssam /// \brief The frontend timer 99105197Ssam OwningPtr<llvm::Timer> FrontendTimer; 100105197Ssam 101105197Ssam /// \brief Non-owning reference to the ASTReader, if one exists. 102105197Ssam ASTReader *ModuleManager; 103105197Ssam 104105197Ssam /// \brief The set of top-level modules that has already been loaded, 105105197Ssam /// along with the module map 106105197Ssam llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules; 107105197Ssam 108105197Ssam /// \brief The location of the module-import keyword for the last module 109105197Ssam /// import. 110105197Ssam SourceLocation LastModuleImportLoc; 111105197Ssam 112105197Ssam /// \brief The result of the last module import. 113105197Ssam /// 114105197Ssam ModuleLoadResult LastModuleImportResult; 115195699Srwatson 116195699Srwatson /// \brief Whether we should (re)build the global module index once we 117195727Srwatson /// have finished with this translation unit. 118195699Srwatson bool BuildGlobalModuleIndex; 119195727Srwatson 120195699Srwatson /// \brief One or more modules failed to build. 121195727Srwatson bool ModuleBuildFailed; 122195699Srwatson 123195727Srwatson /// \brief Holds information about the output file. 124195699Srwatson /// 125195699Srwatson /// If TempFilename is not empty we must rename it to Filename at the end. 126195727Srwatson /// TempFilename may be empty and Filename non empty if creating the temporary 127195699Srwatson /// failed. 128195699Srwatson struct OutputFile { 129195727Srwatson std::string Filename; 130195699Srwatson std::string TempFilename; 131195699Srwatson raw_ostream *OS; 132195727Srwatson 133195699Srwatson OutputFile(const std::string &filename, const std::string &tempFilename, 134195699Srwatson raw_ostream *os) 135195727Srwatson : Filename(filename), TempFilename(tempFilename), OS(os) { } 136195699Srwatson }; 137195699Srwatson 138195727Srwatson /// The list of active output files. 139105197Ssam std::list<OutputFile> OutputFiles; 140195699Srwatson 141195727Srwatson CompilerInstance(const CompilerInstance &) LLVM_DELETED_FUNCTION; 142105197Ssam void operator=(const CompilerInstance &) LLVM_DELETED_FUNCTION; 143195699Srwatsonpublic: 144195699Srwatson CompilerInstance(); 145195727Srwatson ~CompilerInstance(); 146119643Ssam 147120585Ssam /// @name High-Level Operations 148120585Ssam /// { 149120585Ssam 150120585Ssam /// ExecuteAction - Execute the provided action against the compiler's 151120585Ssam /// CompilerInvocation object. 152120585Ssam /// 153120585Ssam /// This function makes the following assumptions: 154120585Ssam /// 155195699Srwatson /// - The invocation options should be initialized. This function does not 156195727Srwatson /// handle the '-help' or '-version' options, clients should handle those 157119643Ssam /// directly. 158120585Ssam /// 159120585Ssam /// - The diagnostics engine should have already been created by the client. 160120585Ssam /// 161120585Ssam /// - No other CompilerInstance state should have been initialized (this is 162120585Ssam /// an unchecked error). 163120585Ssam /// 164120585Ssam /// - Clients should have initialized any LLVM target features that may be 165120585Ssam /// required. 166119643Ssam /// 167195699Srwatson /// - Clients should eventually call llvm_shutdown() upon the completion of 168195727Srwatson /// this routine to ensure that any managed objects are properly destroyed. 169119643Ssam /// 170120585Ssam /// Note that this routine may write output to 'stderr'. 171120585Ssam /// 172120585Ssam /// \param Act - The action to execute. 173120585Ssam /// \return - True on success. 174120585Ssam // 175120585Ssam // FIXME: This function should take the stream to write any debugging / 176120585Ssam // verbose output to as an argument. 177195699Srwatson // 178195727Srwatson // FIXME: Eliminate the llvm_shutdown requirement, that should either be part 179119643Ssam // of the context or else not CompilerInstance specific. 180120585Ssam bool ExecuteAction(FrontendAction &Act); 181120585Ssam 182120585Ssam /// } 183120585Ssam /// @name Compiler Invocation and Options 184120585Ssam /// { 185120585Ssam 186120585Ssam bool hasInvocation() const { return Invocation != 0; } 187195699Srwatson 188195699Srwatson CompilerInvocation &getInvocation() { 189195727Srwatson assert(Invocation && "Compiler instance has no invocation!"); 190119643Ssam return *Invocation; 191120585Ssam } 192120585Ssam 193120585Ssam /// setInvocation - Replace the current invocation. 194120585Ssam void setInvocation(CompilerInvocation *Value); 195120585Ssam 196120585Ssam /// \brief Indicates whether we should (re)build the global module index. 197120585Ssam bool shouldBuildGlobalModuleIndex() const; 198105197Ssam 199105197Ssam /// \brief Set the flag indicating whether we should (re)build the global 200128856Ssam /// module index. 201105197Ssam void setBuildGlobalModuleIndex(bool Build) { 202105197Ssam BuildGlobalModuleIndex = Build; 203128856Ssam } 204128856Ssam 205128856Ssam /// } 206185348Szec /// @name Forwarding Methods 207105197Ssam /// { 208105197Ssam 209105197Ssam AnalyzerOptionsRef getAnalyzerOpts() { 210185348Szec return Invocation->getAnalyzerOpts(); 211105197Ssam } 212105197Ssam 213105197Ssam CodeGenOptions &getCodeGenOpts() { 214105197Ssam return Invocation->getCodeGenOpts(); 215105197Ssam } 216105197Ssam const CodeGenOptions &getCodeGenOpts() const { 217105197Ssam return Invocation->getCodeGenOpts(); 218105197Ssam } 219105197Ssam 220105197Ssam DependencyOutputOptions &getDependencyOutputOpts() { 221105197Ssam return Invocation->getDependencyOutputOpts(); 222105197Ssam } 223105197Ssam const DependencyOutputOptions &getDependencyOutputOpts() const { 224105197Ssam return Invocation->getDependencyOutputOpts(); 225105197Ssam } 226105197Ssam 227105197Ssam DiagnosticOptions &getDiagnosticOpts() { 228105197Ssam return Invocation->getDiagnosticOpts(); 229105197Ssam } 230105197Ssam const DiagnosticOptions &getDiagnosticOpts() const { 231105197Ssam return Invocation->getDiagnosticOpts(); 232105197Ssam } 233105197Ssam 234105197Ssam const FileSystemOptions &getFileSystemOpts() const { 235105197Ssam return Invocation->getFileSystemOpts(); 236194062Svanhu } 237194062Svanhu 238194062Svanhu FrontendOptions &getFrontendOpts() { 239194062Svanhu return Invocation->getFrontendOpts(); 240194062Svanhu } 241194062Svanhu const FrontendOptions &getFrontendOpts() const { 242105197Ssam return Invocation->getFrontendOpts(); 243105197Ssam } 244105197Ssam 245105197Ssam HeaderSearchOptions &getHeaderSearchOpts() { 246105197Ssam return Invocation->getHeaderSearchOpts(); 247105197Ssam } 248105197Ssam const HeaderSearchOptions &getHeaderSearchOpts() const { 249105197Ssam return Invocation->getHeaderSearchOpts(); 250105197Ssam } 251105197Ssam 252105197Ssam LangOptions &getLangOpts() { 253105197Ssam return *Invocation->getLangOpts(); 254105197Ssam } 255105197Ssam const LangOptions &getLangOpts() const { 256105197Ssam return *Invocation->getLangOpts(); 257105197Ssam } 258105197Ssam 259105197Ssam PreprocessorOptions &getPreprocessorOpts() { 260105197Ssam return Invocation->getPreprocessorOpts(); 261105197Ssam } 262105197Ssam const PreprocessorOptions &getPreprocessorOpts() const { 263105197Ssam return Invocation->getPreprocessorOpts(); 264194062Svanhu } 265194062Svanhu 266194062Svanhu PreprocessorOutputOptions &getPreprocessorOutputOpts() { 267194062Svanhu return Invocation->getPreprocessorOutputOpts(); 268194062Svanhu } 269194062Svanhu const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { 270105197Ssam return Invocation->getPreprocessorOutputOpts(); 271105197Ssam } 272195699Srwatson 273195727Srwatson TargetOptions &getTargetOpts() { 274195699Srwatson return Invocation->getTargetOpts(); 275195727Srwatson } 276195699Srwatson const TargetOptions &getTargetOpts() const { 277195727Srwatson return Invocation->getTargetOpts(); 278195699Srwatson } 279105197Ssam 280105197Ssam /// } 281105197Ssam /// @name Diagnostics Engine 282105197Ssam /// { 283195699Srwatson 284195699Srwatson bool hasDiagnostics() const { return Diagnostics != 0; } 285105197Ssam 286105197Ssam /// Get the current diagnostics engine. 287195699Srwatson DiagnosticsEngine &getDiagnostics() const { 288195699Srwatson assert(Diagnostics && "Compiler instance has no diagnostics!"); 289105197Ssam return *Diagnostics; 290105197Ssam } 291195699Srwatson 292195699Srwatson /// setDiagnostics - Replace the current diagnostics engine. 293105197Ssam void setDiagnostics(DiagnosticsEngine *Value); 294105197Ssam 295195699Srwatson DiagnosticConsumer &getDiagnosticClient() const { 296195699Srwatson assert(Diagnostics && Diagnostics->getClient() && 297105197Ssam "Compiler instance has no diagnostic client!"); 298105197Ssam return *Diagnostics->getClient(); 299195699Srwatson } 300195699Srwatson 301105197Ssam /// } 302105197Ssam /// @name Target Info 303195699Srwatson /// { 304195699Srwatson 305105197Ssam bool hasTarget() const { return Target != 0; } 306105197Ssam 307195699Srwatson TargetInfo &getTarget() const { 308195699Srwatson assert(Target && "Compiler instance has no target!"); 309105197Ssam return *Target; 310105197Ssam } 311195699Srwatson 312195699Srwatson /// Replace the current diagnostics engine. 313105197Ssam void setTarget(TargetInfo *Value); 314105197Ssam 315195699Srwatson /// } 316195699Srwatson /// @name File Manager 317105197Ssam /// { 318105197Ssam 319195699Srwatson bool hasFileManager() const { return FileMgr != 0; } 320195699Srwatson 321105197Ssam /// Return the current file manager to the caller. 322105197Ssam FileManager &getFileManager() const { 323195699Srwatson assert(FileMgr && "Compiler instance has no file manager!"); 324195699Srwatson return *FileMgr; 325105197Ssam } 326105197Ssam 327195699Srwatson void resetAndLeakFileManager() { 328195699Srwatson FileMgr.resetWithoutRelease(); 329105197Ssam } 330105197Ssam 331105197Ssam /// setFileManager - Replace the current file manager. 332105197Ssam void setFileManager(FileManager *Value); 333105197Ssam 334105197Ssam /// } 335105197Ssam /// @name Source Manager 336105197Ssam /// { 337105197Ssam 338105197Ssam bool hasSourceManager() const { return SourceMgr != 0; } 339105197Ssam 340105197Ssam /// Return the current source manager. 341105197Ssam SourceManager &getSourceManager() const { 342105197Ssam assert(SourceMgr && "Compiler instance has no source manager!"); 343105197Ssam return *SourceMgr; 344105197Ssam } 345105197Ssam 346105197Ssam void resetAndLeakSourceManager() { 347105197Ssam SourceMgr.resetWithoutRelease(); 348105197Ssam } 349105197Ssam 350105197Ssam /// setSourceManager - Replace the current source manager. 351105197Ssam void setSourceManager(SourceManager *Value); 352105197Ssam 353105197Ssam /// } 354105197Ssam /// @name Preprocessor 355105197Ssam /// { 356105197Ssam 357105197Ssam bool hasPreprocessor() const { return PP != 0; } 358105197Ssam 359105197Ssam /// Return the current preprocessor. 360105197Ssam Preprocessor &getPreprocessor() const { 361105197Ssam assert(PP && "Compiler instance has no preprocessor!"); 362119643Ssam return *PP; 363119643Ssam } 364119643Ssam 365119643Ssam void resetAndLeakPreprocessor() { 366119643Ssam PP.resetWithoutRelease(); 367119643Ssam } 368119643Ssam 369105197Ssam /// Replace the current preprocessor. 370105197Ssam void setPreprocessor(Preprocessor *Value); 371105197Ssam 372105197Ssam /// } 373105197Ssam /// @name ASTContext 374105197Ssam /// { 375105197Ssam 376105197Ssam bool hasASTContext() const { return Context != 0; } 377105197Ssam 378105197Ssam ASTContext &getASTContext() const { 379105197Ssam assert(Context && "Compiler instance has no AST context!"); 380105197Ssam return *Context; 381105197Ssam } 382105197Ssam 383105197Ssam void resetAndLeakASTContext() { 384105197Ssam Context.resetWithoutRelease(); 385105197Ssam } 386105197Ssam 387105197Ssam /// setASTContext - Replace the current AST context. 388105197Ssam void setASTContext(ASTContext *Value); 389105197Ssam 390105197Ssam /// \brief Replace the current Sema; the compiler instance takes ownership 391105197Ssam /// of S. 392105197Ssam void setSema(Sema *S); 393105197Ssam 394105197Ssam /// } 395105197Ssam /// @name ASTConsumer 396105197Ssam /// { 397105197Ssam 398105197Ssam bool hasASTConsumer() const { return Consumer != 0; } 399105197Ssam 400105197Ssam ASTConsumer &getASTConsumer() const { 401105197Ssam assert(Consumer && "Compiler instance has no AST consumer!"); 402105197Ssam return *Consumer; 403105197Ssam } 404105197Ssam 405105197Ssam /// takeASTConsumer - Remove the current AST consumer and give ownership to 406105197Ssam /// the caller. 407105197Ssam ASTConsumer *takeASTConsumer() { return Consumer.take(); } 408105197Ssam 409105197Ssam /// setASTConsumer - Replace the current AST consumer; the compiler instance 410105197Ssam /// takes ownership of \p Value. 411105197Ssam void setASTConsumer(ASTConsumer *Value); 412105197Ssam 413105197Ssam /// } 414105197Ssam /// @name Semantic analysis 415105197Ssam /// { 416119643Ssam bool hasSema() const { return TheSema != 0; } 417105197Ssam 418105197Ssam Sema &getSema() const { 419105197Ssam assert(TheSema && "Compiler instance has no Sema object!"); 420105197Ssam return *TheSema; 421105197Ssam } 422105197Ssam 423105197Ssam Sema *takeSema() { return TheSema.take(); } 424105197Ssam 425105197Ssam /// } 426105197Ssam /// @name Module Management 427105197Ssam /// { 428105197Ssam 429105197Ssam ASTReader *getModuleManager() const { return ModuleManager; } 430105197Ssam 431105197Ssam /// } 432105197Ssam /// @name Code Completion 433105197Ssam /// { 434105197Ssam 435105197Ssam bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; } 436105197Ssam 437105197Ssam CodeCompleteConsumer &getCodeCompletionConsumer() const { 438105197Ssam assert(CompletionConsumer && 439105197Ssam "Compiler instance has no code completion consumer!"); 440105197Ssam return *CompletionConsumer; 441105197Ssam } 442105197Ssam 443105197Ssam /// takeCodeCompletionConsumer - Remove the current code completion consumer 444105197Ssam /// and give ownership to the caller. 445105197Ssam CodeCompleteConsumer *takeCodeCompletionConsumer() { 446105197Ssam return CompletionConsumer.take(); 447105197Ssam } 448105197Ssam 449105197Ssam /// setCodeCompletionConsumer - Replace the current code completion consumer; 450105197Ssam /// the compiler instance takes ownership of \p Value. 451105197Ssam void setCodeCompletionConsumer(CodeCompleteConsumer *Value); 452105197Ssam 453105197Ssam /// } 454105197Ssam /// @name Frontend timer 455105197Ssam /// { 456105197Ssam 457105197Ssam bool hasFrontendTimer() const { return FrontendTimer != 0; } 458105197Ssam 459194062Svanhu llvm::Timer &getFrontendTimer() const { 460194062Svanhu assert(FrontendTimer && "Compiler instance has no frontend timer!"); 461194062Svanhu return *FrontendTimer; 462194062Svanhu } 463194062Svanhu 464194062Svanhu /// } 465194062Svanhu /// @name Output Files 466105197Ssam /// { 467105197Ssam 468105197Ssam /// addOutputFile - Add an output file onto the list of tracked output files. 469157123Sgnn /// 470157123Sgnn /// \param OutFile - The output file info. 471157123Sgnn void addOutputFile(const OutputFile &OutFile); 472157123Sgnn 473105197Ssam /// clearOutputFiles - Clear the output file list, destroying the contained 474105197Ssam /// output streams. 475105197Ssam /// 476105197Ssam /// \param EraseFiles - If true, attempt to erase the files from disk. 477105197Ssam void clearOutputFiles(bool EraseFiles); 478105197Ssam 479105197Ssam /// } 480105197Ssam /// @name Construction Utility Methods 481105197Ssam /// { 482105197Ssam 483105197Ssam /// Create the diagnostics engine using the invocation's diagnostic options 484105197Ssam /// and replace any existing one with it. 485105197Ssam /// 486105197Ssam /// Note that this routine also replaces the diagnostic client, 487105197Ssam /// allocating one if one is not provided. 488105197Ssam /// 489105197Ssam /// \param Client If non-NULL, a diagnostic client that will be 490105197Ssam /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST 491105197Ssam /// unit. 492105197Ssam /// 493105197Ssam /// \param ShouldOwnClient If Client is non-NULL, specifies whether 494105197Ssam /// the diagnostic object should take ownership of the client. 495105197Ssam /// 496105197Ssam /// \param ShouldCloneClient If Client is non-NULL, specifies whether that 497105197Ssam /// client should be cloned. 498105197Ssam void createDiagnostics(DiagnosticConsumer *Client = 0, 499105197Ssam bool ShouldOwnClient = true, 500105197Ssam bool ShouldCloneClient = true); 501105197Ssam 502105197Ssam /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter. 503105197Ssam /// 504105197Ssam /// If no diagnostic client is provided, this creates a 505105197Ssam /// DiagnosticConsumer that is owned by the returned diagnostic 506105197Ssam /// object, if using directly the caller is responsible for 507105197Ssam /// releasing the returned DiagnosticsEngine's client eventually. 508105197Ssam /// 509105197Ssam /// \param Opts - The diagnostic options; note that the created text 510105197Ssam /// diagnostic object contains a reference to these options. 511105197Ssam /// 512105197Ssam /// \param Client If non-NULL, a diagnostic client that will be 513105197Ssam /// attached to (and, then, owned by) the returned DiagnosticsEngine 514105197Ssam /// object. 515105197Ssam /// 516105197Ssam /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be 517105197Ssam /// used by some diagnostics printers (for logging purposes only). 518105197Ssam /// 519105197Ssam /// \return The new object on success, or null on failure. 520105197Ssam static IntrusiveRefCntPtr<DiagnosticsEngine> 521105197Ssam createDiagnostics(DiagnosticOptions *Opts, 522105197Ssam DiagnosticConsumer *Client = 0, 523105197Ssam bool ShouldOwnClient = true, 524105197Ssam bool ShouldCloneClient = true, 525105197Ssam const CodeGenOptions *CodeGenOpts = 0); 526105197Ssam 527105197Ssam /// Create the file manager and replace any existing one with it. 528105197Ssam void createFileManager(); 529105197Ssam 530105197Ssam /// Create the source manager and replace any existing one with it. 531105197Ssam void createSourceManager(FileManager &FileMgr); 532105197Ssam 533105197Ssam /// Create the preprocessor, using the invocation, file, and source managers, 534105197Ssam /// and replace any existing one with it. 535105197Ssam void createPreprocessor(); 536105197Ssam 537105197Ssam /// Create the AST context. 538105197Ssam void createASTContext(); 539105197Ssam 540157123Sgnn /// Create an external AST source to read a PCH file and attach it to the AST 541157123Sgnn /// context. 542157123Sgnn void createPCHExternalASTSource(StringRef Path, 543157123Sgnn bool DisablePCHValidation, 544105197Ssam bool AllowPCHWithCompilerErrors, 545105197Ssam void *DeserializationListener); 546105197Ssam 547105197Ssam /// Create an external AST source to read a PCH file. 548105197Ssam /// 549105197Ssam /// \return - The new object on success, or null on failure. 550105197Ssam static ExternalASTSource * 551158767Spjd createPCHExternalASTSource(StringRef Path, const std::string &Sysroot, 552158767Spjd bool DisablePCHValidation, 553158767Spjd bool AllowPCHWithCompilerErrors, 554105197Ssam Preprocessor &PP, ASTContext &Context, 555158767Spjd void *DeserializationListener, bool Preamble, 556158767Spjd bool UseGlobalModuleIndex); 557158767Spjd 558158767Spjd /// Create a code completion consumer using the invocation; note that this 559158767Spjd /// will cause the source manager to truncate the input source file at the 560158767Spjd /// completion point. 561158767Spjd void createCodeCompletionConsumer(); 562158767Spjd 563158767Spjd /// Create a code completion consumer to print code completion results, at 564158767Spjd /// \p Filename, \p Line, and \p Column, to the given output stream \p OS. 565158767Spjd static CodeCompleteConsumer * 566158767Spjd createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, 567158767Spjd unsigned Line, unsigned Column, 568158767Spjd const CodeCompleteOptions &Opts, 569158767Spjd raw_ostream &OS); 570158767Spjd 571158767Spjd /// \brief Create the Sema object to be used for parsing. 572105197Ssam void createSema(TranslationUnitKind TUKind, 573105197Ssam CodeCompleteConsumer *CompletionConsumer); 574120585Ssam 575105197Ssam /// Create the frontend timer and replace any existing one with it. 576105197Ssam void createFrontendTimer(); 577120585Ssam 578105197Ssam /// Create the default output file (from the invocation's options) and add it 579105197Ssam /// to the list of tracked output files. 580135947Ssam /// 581105197Ssam /// The files created by this function always use temporary files to write to 582105197Ssam /// their result (that is, the data is written to a temporary file which will 583135947Ssam /// atomically replace the target output on success). 584135947Ssam /// 585135947Ssam /// \return - Null on error. 586135947Ssam llvm::raw_fd_ostream * 587135947Ssam createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "", 588135947Ssam StringRef Extension = ""); 589135947Ssam 590135947Ssam /// Create a new output file and add it to the list of tracked output files, 591135947Ssam /// optionally deriving the output path name. 592135947Ssam /// 593135947Ssam /// \return - Null on error. 594105197Ssam llvm::raw_fd_ostream * 595105197Ssam createOutputFile(StringRef OutputPath, 596105197Ssam bool Binary = true, bool RemoveFileOnSignal = true, 597105197Ssam StringRef BaseInput = "", 598105197Ssam StringRef Extension = "", 599105197Ssam bool UseTemporary = false, 600105197Ssam bool CreateMissingDirectories = false); 601183550Szec 602105197Ssam /// Create a new output file, optionally deriving the output path name. 603181803Sbz /// 604105197Ssam /// If \p OutputPath is empty, then createOutputFile will derive an output 605105197Ssam /// path location as \p BaseInput, with any suffix removed, and \p Extension 606105197Ssam /// appended. If \p OutputPath is not stdout and \p UseTemporary 607105197Ssam /// is true, createOutputFile will create a new temporary file that must be 608105197Ssam /// renamed to \p OutputPath in the end. 609105197Ssam /// 610105197Ssam /// \param OutputPath - If given, the path to the output file. 611105197Ssam /// \param Error [out] - On failure, the error message. 612105197Ssam /// \param BaseInput - If \p OutputPath is empty, the input path name to use 613105197Ssam /// for deriving the output path. 614105197Ssam /// \param Extension - The extension to use for derived output names. 615105197Ssam /// \param Binary - The mode to open the file in. 616105197Ssam /// \param RemoveFileOnSignal - Whether the file should be registered with 617105197Ssam /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for 618120585Ssam /// multithreaded use, as the underlying signal mechanism is not reentrant 619120585Ssam /// \param UseTemporary - Create a new temporary file that must be renamed to 620120585Ssam /// OutputPath in the end. 621105197Ssam /// \param CreateMissingDirectories - When \p UseTemporary is true, create 622105197Ssam /// missing directories in the output path. 623120585Ssam /// \param ResultPathName [out] - If given, the result path name will be 624105197Ssam /// stored here on success. 625105197Ssam /// \param TempPathName [out] - If given, the temporary file path name 626105197Ssam /// will be stored here on success. 627105197Ssam static llvm::raw_fd_ostream * 628105197Ssam createOutputFile(StringRef OutputPath, std::string &Error, 629105197Ssam bool Binary = true, bool RemoveFileOnSignal = true, 630120585Ssam StringRef BaseInput = "", 631181803Sbz StringRef Extension = "", 632105197Ssam bool UseTemporary = false, 633105197Ssam bool CreateMissingDirectories = false, 634105197Ssam std::string *ResultPathName = 0, 635105197Ssam std::string *TempPathName = 0); 636105197Ssam 637105197Ssam /// } 638105197Ssam /// @name Initialization Utility Methods 639105197Ssam /// { 640105197Ssam 641105197Ssam /// InitializeSourceManager - Initialize the source manager to set InputFile 642105197Ssam /// as the main file. 643105197Ssam /// 644105197Ssam /// \return True on success. 645120585Ssam bool InitializeSourceManager(const FrontendInputFile &Input); 646105197Ssam 647105197Ssam /// InitializeSourceManager - Initialize the source manager to set InputFile 648105197Ssam /// as the main file. 649105197Ssam /// 650105197Ssam /// \return True on success. 651120585Ssam static bool InitializeSourceManager(const FrontendInputFile &Input, 652105197Ssam DiagnosticsEngine &Diags, 653105197Ssam FileManager &FileMgr, 654120585Ssam SourceManager &SourceMgr, 655105197Ssam const FrontendOptions &Opts); 656105197Ssam 657105197Ssam /// } 658105197Ssam 659105197Ssam virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, 660105197Ssam ModuleIdPath Path, 661105197Ssam Module::NameVisibilityKind Visibility, 662105197Ssam bool IsInclusionDirective); 663105197Ssam 664105197Ssam virtual void makeModuleVisible(Module *Mod, 665105197Ssam Module::NameVisibilityKind Visibility, 666105197Ssam SourceLocation ImportLoc, 667105197Ssam bool Complain); 668105197Ssam 669105197Ssam}; 670105197Ssam 671105197Ssam} // end namespace clang 672105197Ssam 673105197Ssam#endif 674120585Ssam