diff options
author | Eric Liu <ioeric@google.com> | 2018-05-09 21:35:52 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-05-09 21:35:52 +0000 |
commit | 617cf1a3b9bfef2c31efb67deb91d9d886e72615 (patch) | |
tree | edc1aab452ab4e5c887db602db5b6b32a947bb60 /include/clang/Basic/SourceManager.h | |
parent | 6a37651bb30339e60ea617d510b4703bcd2e89e8 (diff) |
Add SourceManagerForFile helper which sets up SourceManager and dependencies for a single file with code snippet
Summary: This can be used to create a virtual environment (incl. VFS, source manager) for code snippets.
Reviewers: sammccall, klimek
Reviewed By: sammccall
Subscribers: klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D46176
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331923 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 25acdd2600..33e63d9d40 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -35,6 +35,7 @@ #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H #define LLVM_CLANG_BASIC_SOURCEMANAGER_H +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" @@ -60,7 +61,6 @@ namespace clang { class ASTReader; class ASTWriter; -class DiagnosticsEngine; class LineTableInfo; class SourceManager; @@ -1815,6 +1815,28 @@ public: } }; +/// SourceManager and necessary depdencies (e.g. VFS, FileManager) for a single +/// in-memorty file. +class SourceManagerForFile { +public: + /// Creates SourceManager and necessary depdencies (e.g. VFS, FileManager). + /// The main file in the SourceManager will be \p FileName with \p Content. + SourceManagerForFile(StringRef FileName, StringRef Content); + + SourceManager &get() { + assert(SourceMgr); + return *SourceMgr; + } + +private: + // The order of these fields are important - they should be in the same order + // as they are created in `createSourceManagerForFile` so that they can be + // deleted in the reverse order as they are created. + std::unique_ptr<FileManager> FileMgr; + std::unique_ptr<DiagnosticsEngine> Diagnostics; + std::unique_ptr<SourceManager> SourceMgr; +}; + } // namespace clang #endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H |