diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-21 17:48:28 -0400 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-10-23 13:22:47 -0400 |
commit | 5431c37b55e2c2952b6b56c9690bd1ce05b23c7e (patch) | |
tree | 605644437826af22b3381282e2d7e76ef37f2852 /clang/lib/Basic/SourceManager.cpp | |
parent | 0f0fd383b487e004fd616ac941307422bd09c261 (diff) | |
download | llvm-5431c37b55e2c2952b6b56c9690bd1ce05b23c7e.zip llvm-5431c37b55e2c2952b6b56c9690bd1ce05b23c7e.tar.gz llvm-5431c37b55e2c2952b6b56c9690bd1ce05b23c7e.tar.bz2 |
SourceManager: Make LastLineNoContentCache and ContentCache::SourceLineCache mutable, NFC
Avoid some noisy `const_cast`s by making `ContentCache::SourceLineCache`
and `SourceManager::LastLineNoContentCache` both mutable.
Differential Revision: https://reviews.llvm.org/D89914
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 778fd0d..f8607b0d 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -1261,20 +1261,20 @@ unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc, #endif static LLVM_ATTRIBUTE_NOINLINE void -ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, +ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI, llvm::BumpPtrAllocator &Alloc, const SourceManager &SM, bool &Invalid); -static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, +static void ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI, llvm::BumpPtrAllocator &Alloc, const SourceManager &SM, bool &Invalid) { // Note that calling 'getBuffer()' may lazily page in the file. llvm::Optional<llvm::MemoryBufferRef> Buffer = - FI->getBufferOrNone(Diag, SM.getFileManager(), SourceLocation()); + FI.getBufferOrNone(Diag, SM.getFileManager(), SourceLocation()); Invalid = !Buffer; if (Invalid) return; - FI->SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc); + FI.SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc); } LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer, @@ -1324,7 +1324,7 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos, return 1; } - ContentCache *Content; + const ContentCache *Content; if (LastLineNoFileIDQuery == FID) Content = LastLineNoContentCache; else { @@ -1336,14 +1336,14 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos, return 1; } - Content = const_cast<ContentCache *>(&Entry.getFile().getContentCache()); + Content = &Entry.getFile().getContentCache(); } // If this is the first use of line information for this buffer, compute the /// SourceLineCache for it on demand. if (!Content->SourceLineCache) { bool MyInvalid = false; - ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid); + ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid); if (Invalid) *Invalid = MyInvalid; if (MyInvalid) @@ -1685,14 +1685,13 @@ SourceLocation SourceManager::translateLineCol(FileID FID, if (Line == 1 && Col == 1) return FileLoc; - ContentCache *Content = - const_cast<ContentCache *>(&Entry.getFile().getContentCache()); + const ContentCache *Content = &Entry.getFile().getContentCache(); // If this is the first use of line information for this buffer, compute the // SourceLineCache for it on demand. if (!Content->SourceLineCache) { bool MyInvalid = false; - ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid); + ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid); if (MyInvalid) return SourceLocation(); } |