mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Introduce SourceManager::getDisplayNameForLoc
Add an abstraction to retrieve a name suitable for display for a given source location for use with diagnostics, debug locations, and magic file literals.
This commit is contained in:
@@ -39,6 +39,27 @@ SourceLoc SourceManager::getCodeCompletionLoc() const {
|
||||
.getAdvancedLoc(CodeCompletionOffset);
|
||||
}
|
||||
|
||||
StringRef SourceManager::getDisplayNameForLoc(SourceLoc Loc) const {
|
||||
// Respect #line first
|
||||
if (auto VFile = getVirtualFile(Loc))
|
||||
return VFile->Name;
|
||||
|
||||
// Next, try the stat cache
|
||||
auto Ident = getIdentifierForBuffer(findBufferContainingLoc(Loc));
|
||||
auto found = StatusCache.find(Ident);
|
||||
if (found != StatusCache.end()) {
|
||||
return found->second.getName();
|
||||
}
|
||||
|
||||
// Populate the cache with a (virtual) stat.
|
||||
if (auto Status = FileSystem->status(Ident)) {
|
||||
return (StatusCache[Ident] = Status.get()).getName();
|
||||
}
|
||||
|
||||
// Finally, fall back to the buffer identifier.
|
||||
return Ident;
|
||||
}
|
||||
|
||||
unsigned
|
||||
SourceManager::addNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
assert(Buffer);
|
||||
|
||||
Reference in New Issue
Block a user