diff options
Diffstat (limited to 'include/clang/Frontend/ASTUnit.h')
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 42dc69ab4a15..634224d08bbf 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -272,12 +272,12 @@ private: /// \brief When non-NULL, this is the buffer used to store the contents of /// the main file when it has been padded for use with the precompiled /// preamble. - llvm::MemoryBuffer *SavedMainFileBuffer; + std::unique_ptr<llvm::MemoryBuffer> SavedMainFileBuffer; /// \brief When non-NULL, this is the buffer used to store the /// contents of the preamble when it has been padded to build the /// precompiled preamble. - llvm::MemoryBuffer *PreambleBuffer; + std::unique_ptr<llvm::MemoryBuffer> PreambleBuffer; /// \brief The number of warnings that occurred while parsing the preamble. /// @@ -305,8 +305,7 @@ private: /// \brief The language options used when we load an AST file. LangOptions ASTFileLangOpts; - static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> &Diags, - const char **ArgBegin, const char **ArgEnd, + static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags, ASTUnit &AST, bool CaptureDiagnostics); void TranslateStoredDiagnostics(FileManager &FileMgr, @@ -423,16 +422,28 @@ private: explicit ASTUnit(bool MainFileIsAST); void CleanTemporaryFiles(); - bool Parse(llvm::MemoryBuffer *OverrideMainBuffer); - - std::pair<llvm::MemoryBuffer *, std::pair<unsigned, bool> > - ComputePreamble(CompilerInvocation &Invocation, - unsigned MaxLines, bool &CreatedBuffer); - - llvm::MemoryBuffer *getMainBufferWithPrecompiledPreamble( - const CompilerInvocation &PreambleInvocationIn, - bool AllowRebuild = true, - unsigned MaxLines = 0); + bool Parse(std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer); + + struct ComputedPreamble { + llvm::MemoryBuffer *Buffer; + std::unique_ptr<llvm::MemoryBuffer> Owner; + unsigned Size; + bool PreambleEndsAtStartOfLine; + ComputedPreamble(llvm::MemoryBuffer *Buffer, + std::unique_ptr<llvm::MemoryBuffer> Owner, unsigned Size, + bool PreambleEndsAtStartOfLine) + : Buffer(Buffer), Owner(std::move(Owner)), Size(Size), + PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {} + ComputedPreamble(ComputedPreamble &&C) + : Buffer(C.Buffer), Owner(std::move(C.Owner)), Size(C.Size), + PreambleEndsAtStartOfLine(C.PreambleEndsAtStartOfLine) {} + }; + ComputedPreamble ComputePreamble(CompilerInvocation &Invocation, + unsigned MaxLines); + + std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble( + const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild = true, + unsigned MaxLines = 0); void RealizeTopLevelDeclsFromPreamble(); /// \brief Transfers ownership of the objects (like SourceManager) from @@ -684,8 +695,8 @@ public: /// module file. bool isModuleFile(); - llvm::MemoryBuffer *getBufferForFile(StringRef Filename, - std::string *ErrorStr = nullptr); + std::unique_ptr<llvm::MemoryBuffer> + getBufferForFile(StringRef Filename, std::string *ErrorStr = nullptr); /// \brief Determine what kind of translation unit this AST represents. TranslationUnitKind getTranslationUnitKind() const { return TUKind; } @@ -708,14 +719,12 @@ public: /// lifetime is expected to extend past that of the returned ASTUnit. /// /// \returns - The initialized ASTUnit or null if the AST failed to load. - static ASTUnit *LoadFromASTFile(const std::string &Filename, - IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - const FileSystemOptions &FileSystemOpts, - bool OnlyLocalDecls = false, - ArrayRef<RemappedFile> RemappedFiles = None, - bool CaptureDiagnostics = false, - bool AllowPCHWithCompilerErrors = false, - bool UserFilesAreVolatile = false); + static std::unique_ptr<ASTUnit> LoadFromASTFile( + const std::string &Filename, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, + const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls = false, + ArrayRef<RemappedFile> RemappedFiles = None, + bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false, + bool UserFilesAreVolatile = false); private: /// \brief Helper function for \c LoadFromCompilerInvocation() and |