diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-08-26 20:32:05 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-08-26 20:32:05 +0000 |
commit | f5848190854cb19280ae2fa465b6f199ed4f896f (patch) | |
tree | fc9d60369abb3b7776e21adf45b7027ccb67b95f /clang/lib/Basic/SourceManager.cpp | |
parent | 33d563e59ed97d03a7508c06bbff3967d687dede (diff) | |
download | bcm5719-llvm-f5848190854cb19280ae2fa465b6f199ed4f896f.tar.gz bcm5719-llvm-f5848190854cb19280ae2fa465b6f199ed4f896f.zip |
ContentCache: Drop getBuffer's dependency on SourceManager
Refactor ContentCache::IsSystemFile to IsFileVolatile, checking
SourceManager::userFilesAreVolatile at construction time. This is a
step toward lowering ContentCache down from SourceManager to
FileManager.
No functionality change intended.
https://reviews.llvm.org/D66713
llvm-svn: 369958
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index aea463aed7a..d49d594e290 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -96,7 +96,7 @@ void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree) { } const llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, - const SourceManager &SM, + FileManager &FM, SourceLocation Loc, bool *Invalid) const { // Lazily create the Buffer for ContentCaches that wrap files. If we already @@ -134,9 +134,7 @@ const llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, return Buffer.getPointer(); } - bool isVolatile = SM.userFilesAreVolatile() && !IsSystemFile; - auto BufferOrError = - SM.getFileManager().getBufferForFile(ContentsEntry, isVolatile); + auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile); // If we were unable to open the file, then we are in an inconsistent // situation where the content cache referenced a file which no longer @@ -389,7 +387,7 @@ void SourceManager::initializeForReplay(const SourceManager &Old) { Clone->OrigEntry = Cache->OrigEntry; Clone->ContentsEntry = Cache->ContentsEntry; Clone->BufferOverridden = Cache->BufferOverridden; - Clone->IsSystemFile = Cache->IsSystemFile; + Clone->IsFileVolatile = Cache->IsFileVolatile; Clone->IsTransient = Cache->IsTransient; Clone->replaceBuffer(Cache->getRawBuffer(), /*DoNotFree*/true); return Clone; @@ -438,7 +436,7 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, new (Entry) ContentCache(FileEnt); } - Entry->IsSystemFile = isSystemFile; + Entry->IsFileVolatile = UserFilesAreVolatile && !isSystemFile; Entry->IsTransient = FilesAreTransient; return Entry; @@ -645,7 +643,7 @@ const llvm::MemoryBuffer * SourceManager::getMemoryBufferForFile(const FileEntry *File, bool *Invalid) { const SrcMgr::ContentCache *IR = getOrCreateContentCache(File); assert(IR && "getOrCreateContentCache() cannot return NULL"); - return IR->getBuffer(Diag, *this, SourceLocation(), Invalid); + return IR->getBuffer(Diag, getFileManager(), SourceLocation(), Invalid); } void SourceManager::overrideFileContents(const FileEntry *SourceFile, @@ -699,7 +697,7 @@ StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { } const llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer( - Diag, *this, SourceLocation(), &MyInvalid); + Diag, getFileManager(), SourceLocation(), &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1130,7 +1128,7 @@ const char *SourceManager::getCharacterData(SourceLocation SL, } const llvm::MemoryBuffer *Buffer = Entry.getFile().getContentCache()->getBuffer( - Diag, *this, SourceLocation(), &CharDataInvalid); + Diag, getFileManager(), SourceLocation(), &CharDataInvalid); if (Invalid) *Invalid = CharDataInvalid; return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second); @@ -1227,7 +1225,7 @@ static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, const SourceManager &SM, bool &Invalid) { // Note that calling 'getBuffer()' may lazily page in the file. const MemoryBuffer *Buffer = - FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); + FI->getBuffer(Diag, SM.getFileManager(), SourceLocation(), &Invalid); if (Invalid) return; @@ -1458,7 +1456,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc, if (C->OrigEntry) Filename = C->OrigEntry->getName(); else - Filename = C->getBuffer(Diag, *this)->getBufferIdentifier(); + Filename = C->getBuffer(Diag, getFileManager())->getBufferIdentifier(); unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second, &Invalid); if (Invalid) @@ -1658,13 +1656,13 @@ SourceLocation SourceManager::translateLineCol(FileID FID, } if (Line > Content->NumLines) { - unsigned Size = Content->getBuffer(Diag, *this)->getBufferSize(); + unsigned Size = Content->getBuffer(Diag, getFileManager())->getBufferSize(); if (Size > 0) --Size; return FileLoc.getLocWithOffset(Size); } - const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); + const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, getFileManager()); unsigned FilePos = Content->SourceLineCache[Line - 1]; const char *Buf = Buffer->getBufferStart() + FilePos; unsigned BufLength = Buffer->getBufferSize() - FilePos; |