Skip to content

Commit 4a93ab5

Browse files
committed
Remove SourceManager::getBufferIdentifierForLoc
And tidy up doc comments for other methods that do or don't respect '#sourceLocation'. 'getBufferIdentifierForLoc' is no longer useful: it doesn't consistently return either the name of an actual buffer or the name of a file suitable for diagnostics. As seen in the previous commit, all remaining uses of it were wrong anyway. Remove it.
1 parent 63cd125 commit 4a93ab5

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SourceManager {
3939
/// to speed up stats.
4040
mutable llvm::StringMap<clang::vfs::Status> StatusCache;
4141

42-
// #line directive handling.
42+
// \c #sourceLocation directive handling.
4343
struct VirtualFile {
4444
CharSourceRange Range;
4545
std::string Name;
@@ -112,17 +112,17 @@ class SourceManager {
112112
/// Adds a memory buffer to the SourceManager, taking ownership of it.
113113
unsigned addNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer);
114114

115-
/// Add a #line-defined virtual file region.
115+
/// Add a \c #sourceLocation-defined virtual file region.
116116
///
117117
/// By default, this region continues to the end of the buffer.
118118
///
119119
/// \returns True if the new file was added, false if the file already exists.
120120
/// The name and line offset must match exactly in that case.
121121
///
122-
/// \sa closeVirtualFile.
122+
/// \sa closeVirtualFile
123123
bool openVirtualFile(SourceLoc loc, StringRef name, int lineOffset);
124124

125-
/// Close a #line-defined virtual file region.
125+
/// Close a \c #sourceLocation-defined virtual file region.
126126
void closeVirtualFile(SourceLoc end);
127127

128128
/// Creates a copy of a \c MemoryBuffer and adds it to the \c SourceManager,
@@ -143,6 +143,11 @@ class SourceManager {
143143
/// Returns the identifier for the buffer with the given ID.
144144
///
145145
/// \p BufferID must be a valid buffer ID.
146+
///
147+
/// This should not be used for displaying information about the \e contents
148+
/// of a buffer, since lines within the buffer may be marked as coming from
149+
/// other files using \c #sourceLocation. Use #getDisplayNameForLoc instead
150+
/// in that case.
146151
StringRef getIdentifierForBuffer(unsigned BufferID) const;
147152

148153
/// \brief Returns a SourceRange covering the entire specified buffer.
@@ -175,26 +180,16 @@ class SourceManager {
175180
/// Returns a buffer identifier suitable for display to the user containing
176181
/// the given source location.
177182
///
178-
/// This respects #line directives and the 'use-external-names' directive in
179-
/// VFS overlay files.
183+
/// This respects \c #sourceLocation directives and the 'use-external-names'
184+
/// directive in VFS overlay files. If you need an on-disk file name, use
185+
/// #getIdentifierForBuffer instead.
180186
StringRef getDisplayNameForLoc(SourceLoc Loc) const;
181187

182-
/// Returns the identifier string for the buffer containing the given source
183-
/// location.
184-
///
185-
/// This respects #line directives.
186-
StringRef getBufferIdentifierForLoc(SourceLoc Loc) const {
187-
if (auto VFile = getVirtualFile(Loc))
188-
return VFile->Name;
189-
else
190-
return getIdentifierForBuffer(findBufferContainingLoc(Loc));
191-
}
192-
193188
/// Returns the line and column represented by the given source location.
194189
///
195190
/// If \p BufferID is provided, \p Loc must come from that source buffer.
196191
///
197-
/// This respects #line directives.
192+
/// This respects \c #sourceLocation directives.
198193
std::pair<unsigned, unsigned>
199194
getLineAndColumn(SourceLoc Loc, unsigned BufferID = 0) const {
200195
assert(Loc.isValid());
@@ -209,7 +204,7 @@ class SourceManager {
209204
///
210205
/// If \p BufferID is provided, \p Loc must come from that source buffer.
211206
///
212-
/// This does not respect #line directives.
207+
/// This does not respect \c #sourceLocation directives.
213208
unsigned getLineNumber(SourceLoc Loc, unsigned BufferID = 0) const {
214209
assert(Loc.isValid());
215210
return LLVMSourceMgr.FindLineNumber(Loc.Value, BufferID);

0 commit comments

Comments
 (0)