diff options
author | Chris Lattner <clattner@nondot.org> | 2020-04-25 14:39:31 -0700 |
---|---|---|
committer | Chris Lattner <clattner@nondot.org> | 2020-04-25 21:18:59 -0700 |
commit | 919dcc7f6858cf0d9a7442673acafdf495e46c7a (patch) | |
tree | 217b104d11d6c451ef42ea38d4d85f720e8e8211 /llvm/lib/Support/SourceMgr.cpp | |
parent | 7016a4b5c34a87e2051b66259141ac7483d0f68b (diff) | |
download | llvm-919dcc7f6858cf0d9a7442673acafdf495e46c7a.zip llvm-919dcc7f6858cf0d9a7442673acafdf495e46c7a.tar.gz llvm-919dcc7f6858cf0d9a7442673acafdf495e46c7a.tar.bz2 |
[SourceMgr] Tidy up the SourceMgr header file to include less stuff.
Summary:
Specifically make some simple refactorings to get PointerUnion.h and
Twine.h out of the public includes. While here, trim out a lot of
transitive includes as well.
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78870
Diffstat (limited to 'llvm/lib/Support/SourceMgr.cpp')
-rw-r--r-- | llvm/lib/Support/SourceMgr.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp index 5fe95ba..db5f7ad 100644 --- a/llvm/lib/Support/SourceMgr.cpp +++ b/llvm/lib/Support/SourceMgr.cpp @@ -69,16 +69,13 @@ unsigned SourceMgr::FindBufferContainingLoc(SMLoc Loc) const { } template <typename T> -static std::vector<T> &GetOrCreateOffsetCache( - PointerUnion<std::vector<uint8_t> *, std::vector<uint16_t> *, - std::vector<uint32_t> *, std::vector<uint64_t> *> &OffsetCache, - MemoryBuffer *Buffer) { - if (!OffsetCache.isNull()) - return *OffsetCache.get<std::vector<T> *>(); +static std::vector<T> &GetOrCreateOffsetCache(void *&OffsetCache, + MemoryBuffer *Buffer) { + if (OffsetCache) + return *static_cast<std::vector<T> *>(OffsetCache); // Lazily fill in the offset cache. auto *Offsets = new std::vector<T>(); - OffsetCache = Offsets; size_t Sz = Buffer->getBufferSize(); assert(Sz <= std::numeric_limits<T>::max()); StringRef S = Buffer->getBuffer(); @@ -87,6 +84,7 @@ static std::vector<T> &GetOrCreateOffsetCache( Offsets->push_back(static_cast<T>(N)); } + OffsetCache = Offsets; return *Offsets; } @@ -164,15 +162,16 @@ SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other) } SourceMgr::SrcBuffer::~SrcBuffer() { - if (!OffsetCache.isNull()) { - if (OffsetCache.is<std::vector<uint8_t> *>()) - delete OffsetCache.get<std::vector<uint8_t> *>(); - else if (OffsetCache.is<std::vector<uint16_t> *>()) - delete OffsetCache.get<std::vector<uint16_t> *>(); - else if (OffsetCache.is<std::vector<uint32_t> *>()) - delete OffsetCache.get<std::vector<uint32_t> *>(); + if (OffsetCache) { + size_t Sz = Buffer->getBufferSize(); + if (Sz <= std::numeric_limits<uint8_t>::max()) + delete static_cast<std::vector<uint8_t> *>(OffsetCache); + else if (Sz <= std::numeric_limits<uint16_t>::max()) + delete static_cast<std::vector<uint16_t> *>(OffsetCache); + else if (Sz <= std::numeric_limits<uint32_t>::max()) + delete static_cast<std::vector<uint32_t> *>(OffsetCache); else - delete OffsetCache.get<std::vector<uint64_t> *>(); + delete static_cast<std::vector<uint64_t> *>(OffsetCache); OffsetCache = nullptr; } } @@ -329,6 +328,15 @@ void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, } //===----------------------------------------------------------------------===// +// SMFixIt Implementation +//===----------------------------------------------------------------------===// + +SMFixIt::SMFixIt(SMRange R, const Twine &Replacement) + : Range(R), Text(Replacement.str()) { + assert(R.isValid()); +} + +//===----------------------------------------------------------------------===// // SMDiagnostic Implementation //===----------------------------------------------------------------------===// |