diff options
Diffstat (limited to 'clang/include/clang')
-rw-r--r-- | clang/include/clang/ARCMigrate/ARCMT.h | 36 | ||||
-rw-r--r-- | clang/include/clang/Frontend/ASTUnit.h | 52 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CompilerInstance.h | 14 | ||||
-rw-r--r-- | clang/include/clang/Frontend/FrontendActions.h | 15 | ||||
-rw-r--r-- | clang/include/clang/Frontend/PCHContainerOperations.h | 76 | ||||
-rw-r--r-- | clang/include/clang/Frontend/Utils.h | 5 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ASTReader.h | 30 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ASTWriter.h | 13 | ||||
-rw-r--r-- | clang/include/clang/Serialization/GlobalModuleIndex.h | 8 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ModuleManager.h | 11 | ||||
-rw-r--r-- | clang/include/clang/Tooling/Refactoring.h | 4 | ||||
-rw-r--r-- | clang/include/clang/Tooling/Tooling.h | 63 |
12 files changed, 247 insertions, 80 deletions
diff --git a/clang/include/clang/ARCMigrate/ARCMT.h b/clang/include/clang/ARCMigrate/ARCMT.h index ad4f23c604b..74081867eeb 100644 --- a/clang/include/clang/ARCMigrate/ARCMT.h +++ b/clang/include/clang/ARCMigrate/ARCMT.h @@ -17,6 +17,7 @@ namespace clang { class ASTContext; class DiagnosticConsumer; + class PCHContainerOperations; namespace arcmt { class MigrationPass; @@ -37,19 +38,22 @@ namespace arcmt { /// the pre-migration ARC diagnostics. /// /// \returns false if no error is produced, true otherwise. -bool checkForManualIssues(CompilerInvocation &CI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient, - bool emitPremigrationARCErrors = false, - StringRef plistOut = StringRef()); +bool +checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient, + bool emitPremigrationARCErrors = false, + StringRef plistOut = StringRef()); /// \brief Works similar to checkForManualIssues but instead of checking, it /// applies automatic modifications to source files to conform to ARC. /// /// \returns false if no error is produced, true otherwise. -bool applyTransformations(CompilerInvocation &origCI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient); +bool +applyTransformations(CompilerInvocation &origCI, + const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient); /// \brief Applies automatic modifications and produces temporary files /// and metadata into the \p outputDir path. @@ -62,12 +66,11 @@ bool applyTransformations(CompilerInvocation &origCI, /// the pre-migration ARC diagnostics. /// /// \returns false if no error is produced, true otherwise. -bool migrateWithTemporaryFiles(CompilerInvocation &origCI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient, - StringRef outputDir, - bool emitPremigrationARCErrors, - StringRef plistOut); +bool migrateWithTemporaryFiles( + CompilerInvocation &origCI, const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient, StringRef outputDir, + bool emitPremigrationARCErrors, StringRef plistOut); /// \brief Get the set of file remappings from the \p outputDir path that /// migrateWithTemporaryFiles produced. @@ -93,13 +96,16 @@ std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode, class MigrationProcess { CompilerInvocation OrigCI; + std::shared_ptr<PCHContainerOperations> PCHContainerOps; DiagnosticConsumer *DiagClient; FileRemapper Remapper; public: bool HadARCErrors; - MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient, + MigrationProcess(const CompilerInvocation &CI, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *diagClient, StringRef outputDir = StringRef()); class RewriteListener { diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 405774b811c..2d38352d22a 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -56,6 +56,7 @@ class FileEntry; class FileManager; class HeaderSearch; class Preprocessor; +class PCHContainerOperations; class SourceManager; class TargetInfo; class ASTFrontendAction; @@ -422,7 +423,8 @@ private: explicit ASTUnit(bool MainFileIsAST); void CleanTemporaryFiles(); - bool Parse(std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer); + bool Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, + std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer); struct ComputedPreamble { llvm::MemoryBuffer *Buffer; @@ -442,6 +444,7 @@ private: unsigned MaxLines); std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble( + std::shared_ptr<PCHContainerOperations> PCHContainerOps, const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild = true, unsigned MaxLines = 0); void RealizeTopLevelDeclsFromPreamble(); @@ -715,12 +718,16 @@ public: /// /// \param Filename - The AST file to load. /// + /// \param PCHContainerOps - The PCHContainerOperations to use for loading and + /// creating modules. /// \param Diags - The diagnostics engine to use for reporting errors; its /// lifetime is expected to extend past that of the returned ASTUnit. /// /// \returns - The initialized ASTUnit or null if the AST failed to load. static std::unique_ptr<ASTUnit> LoadFromASTFile( - const std::string &Filename, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, + const std::string &Filename, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + IntrusiveRefCntPtr<DiagnosticsEngine> Diags, const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls = false, ArrayRef<RemappedFile> RemappedFiles = None, bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false, @@ -735,8 +742,10 @@ private: /// /// \returns \c true if a catastrophic failure occurred (which means that the /// \c ASTUnit itself is invalid), or \c false otherwise. - bool LoadFromCompilerInvocation(bool PrecompilePreamble); - + bool LoadFromCompilerInvocation( + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + bool PrecompilePreamble); + public: /// \brief Create an ASTUnit from a source file, via a CompilerInvocation @@ -745,6 +754,9 @@ public: /// \param CI - The compiler invocation to use; it must have exactly one input /// source file. The ASTUnit takes ownership of the CompilerInvocation object. /// + /// \param PCHContainerOps - The PCHContainerOperations to use for loading and + /// creating modules. + /// /// \param Diags - The diagnostics engine to use for reporting errors; its /// lifetime is expected to extend past that of the returned ASTUnit. /// @@ -765,7 +777,9 @@ public: /// created ASTUnit was passed in \p Unit then the caller can check that. /// static ASTUnit *LoadFromCompilerInvocationAction( - CompilerInvocation *CI, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, + CompilerInvocation *CI, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + IntrusiveRefCntPtr<DiagnosticsEngine> Diags, ASTFrontendAction *Action = nullptr, ASTUnit *Unit = nullptr, bool Persistent = true, StringRef ResourceFilesPath = StringRef(), bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, @@ -780,15 +794,20 @@ public: /// \param CI - The compiler invocation to use; it must have exactly one input /// source file. The ASTUnit takes ownership of the CompilerInvocation object. /// + /// \param PCHContainerOps - The PCHContainerOperations to use for loading and + /// creating modules. + /// /// \param Diags - The diagnostics engine to use for reporting errors; its /// lifetime is expected to extend past that of the returned ASTUnit. // // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we // shouldn't need to specify them at construction time. static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation( - CompilerInvocation *CI, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, - bool PrecompilePreamble = false, TranslationUnitKind TUKind = TU_Complete, + CompilerInvocation *CI, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + IntrusiveRefCntPtr<DiagnosticsEngine> Diags, bool OnlyLocalDecls = false, + bool CaptureDiagnostics = false, bool PrecompilePreamble = false, + TranslationUnitKind TUKind = TU_Complete, bool CacheCodeCompletionResults = false, bool IncludeBriefCommentsInCodeCompletion = false, bool UserFilesAreVolatile = false); @@ -800,6 +819,9 @@ public: /// /// \param ArgEnd - The end of the argument vector. /// + /// \param PCHContainerOps - The PCHContainerOperations to use for loading and + /// creating modules. + /// /// \param Diags - The diagnostics engine to use for reporting errors; its /// lifetime is expected to extend past that of the returned ASTUnit. /// @@ -813,6 +835,7 @@ public: // shouldn't need to specify them at construction time. static ASTUnit *LoadFromCommandLine( const char **ArgBegin, const char **ArgEnd, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, ArrayRef<RemappedFile> RemappedFiles = None, @@ -828,8 +851,9 @@ public: /// were originally used to produce this translation unit. /// /// \returns True if a failure occurred that causes the ASTUnit not to - /// contain any translation-unit information, false otherwise. - bool Reparse(ArrayRef<RemappedFile> RemappedFiles = None); + /// contain any translation-unit information, false otherwise. + bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, + ArrayRef<RemappedFile> RemappedFiles = None); /// \brief Perform code completion at the given file, line, and /// column within this translation unit. @@ -852,14 +876,14 @@ public: /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and /// OwnedBuffers parameters are all disgusting hacks. They will go away. void CodeComplete(StringRef File, unsigned Line, unsigned Column, - ArrayRef<RemappedFile> RemappedFiles, - bool IncludeMacros, bool IncludeCodePatterns, - bool IncludeBriefComments, + ArrayRef<RemappedFile> RemappedFiles, bool IncludeMacros, + bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, - SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers); + SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers); /// \brief Save this translation unit to a file with the given name. /// diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 8d0d939d781..9cd806c99b8 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ #include "clang/AST/ASTConsumer.h" +#include "clang/Frontend/PCHContainerOperations.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/CompilerInvocation.h" @@ -109,6 +110,9 @@ class CompilerInstance : public ModuleLoader { /// \brief The module dependency collector for crashdumps std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector; + /// \brief The module provider. + std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations; + /// \brief The dependency file generator. std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator; @@ -172,7 +176,10 @@ class CompilerInstance : public ModuleLoader { CompilerInstance(const CompilerInstance &) = delete; void operator=(const CompilerInstance &) = delete; public: - explicit CompilerInstance(bool BuildingModule = false); + explicit CompilerInstance( + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>(), + bool BuildingModule = false); ~CompilerInstance() override; /// @name High-Level Operations @@ -492,6 +499,10 @@ public: void setModuleDepCollector( std::shared_ptr<ModuleDependencyCollector> Collector); + std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const { + return ThePCHContainerOperations; + } + /// } /// @name Code Completion /// { @@ -605,6 +616,7 @@ public: static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource( StringRef Path, const std::string &Sysroot, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, + const PCHContainerOperations &PCHContainerOps, void *DeserializationListener, bool OwnDeserializationListener, bool Preamble, bool UseGlobalModuleIndex); diff --git a/clang/include/clang/Frontend/FrontendActions.h b/clang/include/clang/Frontend/FrontendActions.h index b1508287c85..f61775f014f 100644 --- a/clang/include/clang/Frontend/FrontendActions.h +++ b/clang/include/clang/Frontend/FrontendActions.h @@ -85,10 +85,9 @@ public: /// create the PCHGenerator instance returned by CreateASTConsumer. /// /// \returns true if an error occurred, false otherwise. - static raw_ostream *ComputeASTConsumerArguments(CompilerInstance &CI, - StringRef InFile, - std::string &Sysroot, - std::string &OutputFile); + static raw_pwrite_stream * + ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile, + std::string &Sysroot, std::string &OutputFile); }; class GenerateModuleAction : public ASTFrontendAction { @@ -118,10 +117,10 @@ public: /// create the PCHGenerator instance returned by CreateASTConsumer. /// /// \returns true if an error occurred, false otherwise. - raw_ostream *ComputeASTConsumerArguments(CompilerInstance &CI, - StringRef InFile, - std::string &Sysroot, - std::string &OutputFile); + raw_pwrite_stream *ComputeASTConsumerArguments(CompilerInstance &CI, + StringRef InFile, + std::string &Sysroot, + std::string &OutputFile); }; class SyntaxOnlyAction : public ASTFrontendAction { diff --git a/clang/include/clang/Frontend/PCHContainerOperations.h b/clang/include/clang/Frontend/PCHContainerOperations.h new file mode 100644 index 00000000000..949ee63c615 --- /dev/null +++ b/clang/include/clang/Frontend/PCHContainerOperations.h @@ -0,0 +1,76 @@ +//===--- Frontend/PCHContainerOperations.h - PCH Containers -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_PCH_CONTAINER_OPERATIONS_H +#define LLVM_CLANG_PCH_CONTAINER_OPERATIONS_H + +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/MemoryBuffer.h" +#include <memory> + +namespace llvm { +class raw_pwrite_stream; +class BitstreamReader; +} + +namespace clang { + +class ASTConsumer; +class CodeGenOptions; +class DiagnosticsEngine; +class HeaderSearchOptions; +class LangOptions; +class PreprocessorOptions; +class TargetOptions; + +struct PCHBuffer { + bool IsComplete; + llvm::SmallVector<char, 0> Data; +}; + +/// \brief This abstract interface provides operations for creating +/// and unwrapping containers for serialized ASTs (precompiled headers +/// and clang modules). +class PCHContainerOperations { +public: + virtual ~PCHContainerOperations(); + /// \brief Return an ASTConsumer that can be chained with a + /// PCHGenerator that produces a wrapper file format containing a + /// serialized AST bitstream. + virtual std::unique_ptr<ASTConsumer> CreatePCHContainerGenerator( + DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO, + const PreprocessorOptions &PPO, const TargetOptions &TO, + const LangOptions &LO, const std::string &MainFileName, + const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, + std::shared_ptr<PCHBuffer> Buffer) const = 0; + + /// \brief Initialize an llvm::BitstreamReader with the serialized AST inside + /// the PCH container Buffer. + virtual void ExtractPCH(llvm::MemoryBufferRef Buffer, + llvm::BitstreamReader &StreamFile) const = 0; +}; + +/// \brief Implements a raw pass-through PCH container. +class RawPCHContainerOperations : public PCHContainerOperations { + /// \brief Return an ASTConsumer that can be chained with a + /// PCHGenerator that writes the module to a flat file. + std::unique_ptr<ASTConsumer> CreatePCHContainerGenerator( + DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO, + const PreprocessorOptions &PPO, const TargetOptions &TO, + const LangOptions &LO, const std::string &MainFileName, + const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, + std::shared_ptr<PCHBuffer> Buffer) const override; + + /// \brief Initialize an llvm::BitstreamReader with Buffer. + void ExtractPCH(llvm::MemoryBufferRef Buffer, + llvm::BitstreamReader &StreamFile) const override; +}; +} + +#endif diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index cd0ebf61120..639965343c4 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -45,6 +45,7 @@ class HeaderSearch; class HeaderSearchOptions; class IdentifierTable; class LangOptions; +class PCHContainerOperations; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; @@ -61,8 +62,8 @@ void ApplyHeaderSearchOptions(HeaderSearch &HS, /// InitializePreprocessor - Initialize the preprocessor getting it and the /// environment ready to process a single file. -void InitializePreprocessor(Preprocessor &PP, - const PreprocessorOptions &PPOpts, +void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, + const PCHContainerOperations &PCHContainerOps, const FrontendOptions &FEOpts); /// DoPrintPreprocessedInput - Implement -E mode. diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index c7cc1be6e62..429f00f852b 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -362,6 +362,7 @@ private: SourceManager &SourceMgr; FileManager &FileMgr; + const PCHContainerOperations &PCHContainerOps; DiagnosticsEngine &Diags; /// \brief The semantic analysis object that will be processing the @@ -1237,6 +1238,9 @@ public: /// \param Context the AST context that this precompiled header will be /// loaded into. /// + /// \param PCHContainerOps the PCHContainerOperations to use for loading and + /// creating modules. + /// /// \param isysroot If non-NULL, the system include path specified by the /// user. This is only used with relocatable PCH files. If non-NULL, /// a relocatable PCH file will use the default path "/". @@ -1258,12 +1262,12 @@ public: /// /// \param UseGlobalIndex If true, the AST reader will try to load and use /// the global module index. - ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", - bool DisableValidation = false, + ASTReader(Preprocessor &PP, ASTContext &Context, + const PCHContainerOperations &PCHContainerOps, + StringRef isysroot = "", bool DisableValidation = false, bool AllowASTWithCompilerErrors = false, bool AllowConfigurationMismatch = false, - bool ValidateSystemInputs = false, - bool UseGlobalIndex = true); + bool ValidateSystemInputs = false, bool UseGlobalIndex = true); ~ASTReader() override; @@ -1425,21 +1429,23 @@ public: /// \brief Retrieve the name of the original source file name directly from /// the AST file, without actually loading the AST file. - static std::string getOriginalSourceFile(const std::string &ASTFileName, - FileManager &FileMgr, - DiagnosticsEngine &Diags); + static std::string + getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr, + const PCHContainerOperations &PCHContainerOps, + DiagnosticsEngine &Diags); /// \brief Read the control block for the named AST file. /// /// \returns true if an error occurred, false otherwise. - static bool readASTFileControlBlock(StringRef Filename, - FileManager &FileMgr, - ASTReaderListener &Listener); + static bool + readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, + const PCHContainerOperations &PCHContainerOps, + ASTReaderListener &Listener); /// \brief Determine whether the given AST file is acceptable to load into a /// translation unit with the given language and target options. - static bool isAcceptableASTFile(StringRef Filename, - FileManager &FileMgr, + static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, + const PCHContainerOperations &PCHContainerOps, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 297ee22dfa6..decd07a00ed 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -17,6 +17,7 @@ #include "clang/AST/ASTMutationListener.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclarationName.h" +#include "clang/Frontend/PCHContainerOperations.h" #include "clang/AST/TemplateBase.h" #include "clang/Sema/SemaConsumer.h" #include "clang/Serialization/ASTBitCodes.h" @@ -868,30 +869,28 @@ class PCHGenerator : public SemaConsumer { std::string OutputFile; clang::Module *Module; std::string isysroot; - raw_ostream *Out; Sema *SemaPtr; - SmallVector<char, 128> Buffer; + std::shared_ptr<PCHBuffer> Buffer; llvm::BitstreamWriter Stream; ASTWriter Writer; bool AllowASTWithErrors; - bool HasEmittedPCH; protected: ASTWriter &getWriter() { return Writer; } const ASTWriter &getWriter() const { return Writer; } + SmallVectorImpl<char> &getPCH() const { return Buffer->Data; } public: PCHGenerator(const Preprocessor &PP, StringRef OutputFile, - clang::Module *Module, - StringRef isysroot, raw_ostream *Out, + clang::Module *Module, StringRef isysroot, + std::shared_ptr<PCHBuffer> Buffer, bool AllowASTWithErrors = false); ~PCHGenerator() override; void InitializeSema(Sema &S) override { SemaPtr = &S; } void HandleTranslationUnit(ASTContext &Ctx) override; ASTMutationListener *GetASTMutationListener() override; ASTDeserializationListener *GetASTDeserializationListener() override; - - bool hasEmittedPCH() const { return HasEmittedPCH; } + bool hasEmittedPCH() const { return Buffer->IsComplete; } }; } // end namespace clang diff --git a/clang/include/clang/Serialization/GlobalModuleIndex.h b/clang/include/clang/Serialization/GlobalModuleIndex.h index 640c7bb3445..7e205106c4e 100644 --- a/clang/include/clang/Serialization/GlobalModuleIndex.h +++ b/clang/include/clang/Serialization/GlobalModuleIndex.h @@ -35,6 +35,7 @@ class DirectoryEntry; class FileEntry; class FileManager; class IdentifierIterator; +class PCHContainerOperations; namespace serialization { class ModuleFile; @@ -192,10 +193,13 @@ public: /// \brief Write a global index into the given /// /// \param FileMgr The file manager to use to load module files. - /// + /// \param PCHContainerOps - The PCHContainerOperations to use for loading and + /// creating modules. /// \param Path The path to the directory containing module files, into /// which the global index will be written. - static ErrorCode writeIndex(FileManager &FileMgr, StringRef Path); + static ErrorCode writeIndex(FileManager &FileMgr, + const PCHContainerOperations &PCHContainerOps, + StringRef Path); }; } diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h index 3de86feb66b..ea4b57fa3ac 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -24,6 +24,7 @@ namespace clang { class GlobalModuleIndex; class ModuleMap; +class PCHContainerOperations; namespace serialization { @@ -49,7 +50,10 @@ class ModuleManager { /// \brief FileManager that handles translating between filenames and /// FileEntry *. FileManager &FileMgr; - + + /// \brief Knows how to unwrap module containers. + const PCHContainerOperations &PCHContainerOps; + /// \brief A lookup of in-memory (virtual file) buffers llvm::DenseMap<const FileEntry *, std::unique_ptr<llvm::MemoryBuffer>> InMemoryBuffers; @@ -112,8 +116,9 @@ public: typedef SmallVectorImpl<ModuleFile*>::const_iterator ModuleConstIterator; typedef SmallVectorImpl<ModuleFile*>::reverse_iterator ModuleReverseIterator; typedef std::pair<uint32_t, StringRef> ModuleOffset; - - explicit ModuleManager(FileManager &FileMgr); + + explicit ModuleManager(FileManager &FileMgr, + const PCHContainerOperations &PCHContainerOps); ~ModuleManager(); /// \brief Forward iterator to traverse all loaded modules. This is reverse diff --git a/clang/include/clang/Tooling/Refactoring.h b/clang/include/clang/Tooling/Refactoring.h index e3e7f83c38c..944fd41f85c 100644 --- a/clang/include/clang/Tooling/Refactoring.h +++ b/clang/include/clang/Tooling/Refactoring.h @@ -38,7 +38,9 @@ class RefactoringTool : public ClangTool { public: /// \see ClangTool::ClangTool. RefactoringTool(const CompilationDatabase &Compilations, - ArrayRef<std::string> SourcePaths); + ArrayRef<std::string> SourcePaths, + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>()); /// \brief Returns the set of replacements to which replacements should /// be added during the run of the tool. diff --git a/clang/include/clang/Tooling/Tooling.h b/clang/include/clang/Tooling/Tooling.h index ca187b16844..fb887e1df9e 100644 --- a/clang/include/clang/Tooling/Tooling.h +++ b/clang/include/clang/Tooling/Tooling.h @@ -31,11 +31,13 @@ #define LLVM_CLANG_TOOLING_TOOLING_H #include "clang/AST/ASTConsumer.h" +#include "clang/Frontend/PCHContainerOperations.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/LLVM.h" #include "clang/Driver/Util.h" #include "clang/Frontend/FrontendAction.h" +#include "clang/Lex/ModuleLoader.h" #include "clang/Tooling/ArgumentsAdjusters.h" #include "clang/Tooling/CompilationDatabase.h" #include "llvm/ADT/StringMap.h" @@ -66,9 +68,10 @@ public: virtual ~ToolAction(); /// \brief Perform an action for an invocation. - virtual bool runInvocation(clang::CompilerInvocation *Invocation, - FileManager *Files, - DiagnosticConsumer *DiagConsumer) = 0; + virtual bool + runInvocation(clang::CompilerInvocation *Invocation, FileManager *Files, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagConsumer) = 0; }; /// \brief Interface to generate clang::FrontendActions. @@ -83,6 +86,7 @@ public: /// \brief Invokes the compiler with a FrontendAction created by create(). bool runInvocation(clang::CompilerInvocation *Invocation, FileManager *Files, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, DiagnosticConsumer *DiagConsumer) override; /// \brief Returns a new clang::FrontendAction. @@ -139,10 +143,14 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory( /// \param ToolAction The action to run over the code. /// \param Code C++ code. /// \param FileName The file name which 'Code' will be mapped as. +/// \param PCHContainerOps The PCHContainerOperations for loading and creating +/// clang modules. /// /// \return - True if 'ToolAction' was successfully executed. bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, - const Twine &FileName = "input.cc"); + const Twine &FileName = "input.cc", + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>()); /// The first part of the pair is the filename, the second part the /// file-content. @@ -155,37 +163,48 @@ typedef std::vector<std::pair<std::string, std::string>> FileContentMappings; /// \param Code C++ code. /// \param Args Additional flags to pass on. /// \param FileName The file name which 'Code' will be mapped as. +/// \param PCHContainerOps The PCHContainerOperations for loading and creating +/// clang modules. /// /// \return - True if 'ToolAction' was successfully executed. bool runToolOnCodeWithArgs( clang::FrontendAction *ToolAction, const Twine &Code, const std::vector<std::string> &Args, const Twine &FileName = "input.cc", + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>(), const FileContentMappings &VirtualMappedFiles = FileContentMappings()); /// \brief Builds an AST for 'Code'. /// /// \param Code C++ code. /// \param FileName The file name which 'Code' will be mapped as. +/// \param PCHContainerOps The PCHContainerOperations for loading and creating +/// clang modules. /// /// \return The resulting AST or null if an error occurred. -std::unique_ptr<ASTUnit> buildASTFromCode(const Twine &Code, - const Twine &FileName = "input.cc"); +std::unique_ptr<ASTUnit> +buildASTFromCode(const Twine &Code, const Twine &FileName = "input.cc", + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>()); /// \brief Builds an AST for 'Code' with additional flags. /// /// \param Code C++ code. /// \param Args Additional flags to pass on. /// \param FileName The file name which 'Code' will be mapped as. +/// \param PCHContainerOps The PCHContainerOperations for loading and creating +/// clang modules. /// /// \return The resulting AST or null if an error occurred. -std::unique_ptr<ASTUnit> -buildASTFromCodeWithArgs(const Twine &Code, - const std::vector<std::string> &Args, - const Twine &FileName = "input.cc"); +std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs( + const Twine &Code, const std::vector<std::string> &Args, + const Twine &FileName = "input.cc", + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>()); /// \brief Utility to run a FrontendAction in a single clang invocation. class ToolInvocation { - public: +public: /// \brief Create a tool invocation. /// /// \param CommandLine The command line arguments to clang. Note that clang @@ -195,16 +214,23 @@ class ToolInvocation { /// \param FAction The action to be executed. Class takes ownership. /// \param Files The FileManager used for the execution. Class does not take /// ownership. + /// \param PCHContainerOps The PCHContainerOperations for loading and creating + /// clang modules. ToolInvocation(std::vector<std::string> CommandLine, FrontendAction *FAction, - FileManager *Files); + FileManager *Files, + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>()); /// \brief Create a tool invocation. /// /// \param CommandLine The command line arguments to clang. /// \param Action The action to be executed. /// \param Files The FileManager used for the execution. + /// \param PCHContainerOps The PCHContainerOperations for loading and creating + /// clang modules. ToolInvocation(std::vector<std::string> CommandLine, ToolAction *Action, - FileManager *Files); + FileManager *Files, + std::shared_ptr<PCHContainerOperations> PCHContainerOps); ~ToolInvocation(); @@ -229,12 +255,14 @@ class ToolInvocation { bool runInvocation(const char *BinaryName, clang::driver::Compilation *Compilation, - clang::CompilerInvocation *Invocation); + clang::CompilerInvocation *Invocation, + std::shared_ptr<PCHContainerOperations> PCHContainerOps); std::vector<std::string> CommandLine; ToolAction *Action; bool OwnsAction; FileManager *Files; + std::shared_ptr<PCHContainerOperations> PCHContainerOps; // Maps <file name> -> <file content>. llvm::StringMap<StringRef> MappedFileContents; DiagnosticConsumer *DiagConsumer; @@ -255,8 +283,12 @@ class ClangTool { /// command lines for the given source paths. /// \param SourcePaths The source files to run over. If a source files is /// not found in Compilations, it is skipped. + /// \param PCHContainerOps The PCHContainerOperations for loading and creating + /// clang modules. ClangTool(const CompilationDatabase &Compilations, - ArrayRef<std::string> SourcePaths); + ArrayRef<std::string> SourcePaths, + std::shared_ptr<PCHContainerOperations> PCHContainerOps = + std::make_shared<RawPCHContainerOperations>()); ~ClangTool(); @@ -297,6 +329,7 @@ class ClangTool { private: const CompilationDatabase &Compilations; std::vector<std::string> SourcePaths; + std::shared_ptr<PCHContainerOperations> PCHContainerOps; llvm::IntrusiveRefCntPtr<FileManager> Files; // Contains a list of pairs (<file name>, <file content>). |