clang  6.0.0svn
MemoryBufferCache.cpp
Go to the documentation of this file.
1 //===- MemoryBufferCache.cpp - Cache for loaded memory buffers ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Support/MemoryBuffer.h"
12 
13 using namespace clang;
14 
15 llvm::MemoryBuffer &
17  std::unique_ptr<llvm::MemoryBuffer> Buffer) {
18  auto Insertion =
19  Buffers.insert({Filename, BufferEntry{std::move(Buffer), NextIndex++}});
20  assert(Insertion.second && "Already has a buffer");
21  return *Insertion.first->second.Buffer;
22 }
23 
24 llvm::MemoryBuffer *MemoryBufferCache::lookupBuffer(llvm::StringRef Filename) {
25  auto I = Buffers.find(Filename);
26  if (I == Buffers.end())
27  return nullptr;
28  return I->second.Buffer.get();
29 }
30 
32  auto I = Buffers.find(Filename);
33  if (I == Buffers.end())
34  return false;
35  return I->second.Index < FirstRemovableIndex;
36 }
37 
39  auto I = Buffers.find(Filename);
40  assert(I != Buffers.end() && "No buffer to remove...");
41  if (I->second.Index < FirstRemovableIndex)
42  return true;
43 
44  Buffers.erase(I);
45  return false;
46 }
47 
48 void MemoryBufferCache::finalizeCurrentBuffers() { FirstRemovableIndex = NextIndex; }
StringRef Filename
Definition: Format.cpp:1316
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.