clang  9.0.0svn
MemoryBufferCache.cpp
Go to the documentation of this file.
1 //===- MemoryBufferCache.cpp - Cache for loaded memory buffers ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/Support/MemoryBuffer.h"
11 
12 using namespace clang;
13 
14 llvm::MemoryBuffer &
16  std::unique_ptr<llvm::MemoryBuffer> Buffer) {
17  auto Insertion =
18  Buffers.insert({Filename, BufferEntry{std::move(Buffer), NextIndex++}});
19  assert(Insertion.second && "Already has a buffer");
20  return *Insertion.first->second.Buffer;
21 }
22 
23 llvm::MemoryBuffer *MemoryBufferCache::lookupBuffer(llvm::StringRef Filename) {
24  auto I = Buffers.find(Filename);
25  if (I == Buffers.end())
26  return nullptr;
27  return I->second.Buffer.get();
28 }
29 
31  auto I = Buffers.find(Filename);
32  if (I == Buffers.end())
33  return false;
34  return I->second.Index < FirstRemovableIndex;
35 }
36 
38  auto I = Buffers.find(Filename);
39  assert(I != Buffers.end() && "No buffer to remove...");
40  if (I->second.Index < FirstRemovableIndex)
41  return true;
42 
43  Buffers.erase(I);
44  return false;
45 }
46 
47 void MemoryBufferCache::finalizeCurrentBuffers() { FirstRemovableIndex = NextIndex; }
StringRef Filename
Definition: Format.cpp:1628
llvm::MemoryBuffer & addBuffer(llvm::StringRef Filename, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Store the Buffer under the Filename.
void finalizeCurrentBuffers()
Finalize the current buffers in the cache.
bool isBufferFinal(llvm::StringRef Filename)
Check whether the buffer is final.
Dataflow Directional Tag Classes.
llvm::MemoryBuffer * lookupBuffer(llvm::StringRef Filename)
Get a pointer to the buffer if it exists; else nullptr.
bool tryToRemoveBuffer(llvm::StringRef Filename)
Try to remove a buffer from the cache.