Skip to content

Commit 1de3d0d

Browse files
authored
Merge pull request swiftlang#31943 from owenv/line-and-col
2 parents 9eb22c0 + 45bc578 commit 1de3d0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+145
-117
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class SourceManager {
206206
///
207207
/// This respects \c #sourceLocation directives.
208208
std::pair<unsigned, unsigned>
209-
getLineAndColumn(SourceLoc Loc, unsigned BufferID = 0) const {
209+
getPresumedLineAndColumnForLoc(SourceLoc Loc, unsigned BufferID = 0) const {
210210
assert(Loc.isValid());
211211
int LineOffset = getLineOffset(Loc);
212212
int l, c;
@@ -215,14 +215,15 @@ class SourceManager {
215215
return { LineOffset + l, c };
216216
}
217217

218-
/// Returns the real line number for a source location.
218+
/// Returns the real line and column for a source location.
219219
///
220220
/// If \p BufferID is provided, \p Loc must come from that source buffer.
221221
///
222222
/// This does not respect \c #sourceLocation directives.
223-
unsigned getLineNumber(SourceLoc Loc, unsigned BufferID = 0) const {
223+
std::pair<unsigned, unsigned>
224+
getLineAndColumnInBuffer(SourceLoc Loc, unsigned BufferID = 0) const {
224225
assert(Loc.isValid());
225-
return LLVMSourceMgr.FindLineNumber(Loc.Value, BufferID);
226+
return LLVMSourceMgr.getLineAndColumn(Loc.Value, BufferID);
226227
}
227228

228229
StringRef getEntireTextForBuffer(unsigned BufferID) const;

include/swift/SIL/SILRemarkStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ toRemarkLocation(const SourceLoc &loc, const SourceManager &srcMgr) {
9494

9595
StringRef file = srcMgr.getDisplayNameForLoc(loc);
9696
unsigned line, col;
97-
std::tie(line, col) = srcMgr.getLineAndColumn(loc);
97+
std::tie(line, col) = srcMgr.getPresumedLineAndColumnForLoc(loc);
9898
return llvm::remarks::RemarkLocation{file, line, col};
9999
}
100100

lib/AST/ASTScopeCreation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ bool doesRangeableRangeMatch(const T *x, const SourceManager &SM,
120120
auto const r = getRangeableSourceRange(x);
121121
if (r.isInvalid())
122122
return false;
123-
if (start && SM.getLineNumber(r.Start) != start)
123+
if (start && SM.getLineAndColumnInBuffer(r.Start).first != start)
124124
return false;
125-
if (end && SM.getLineNumber(r.End) != end)
125+
if (end && SM.getLineAndColumnInBuffer(r.End).first != end)
126126
return false;
127127
if (file.empty())
128128
return true;
@@ -2122,7 +2122,7 @@ class LocalizableDeclContextCollector : public ASTWalker {
21222122
return;
21232123
auto bufID = SM.findBufferContainingLoc(loc);
21242124
auto f = SM.getIdentifierForBuffer(bufID);
2125-
auto lin = SM.getLineNumber(loc);
2125+
auto lin = SM.getLineAndColumnInBuffer(loc).first;
21262126
if (f.endswith(file) && lin == line)
21272127
if (isa<PatternBindingDecl>(D))
21282128
llvm::errs() << "*** catchForDebugging: " << lin << " ***\n";

lib/AST/ASTScopePrinting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ static void printSourceRange(llvm::raw_ostream &out, const SourceRange range,
118118
return;
119119
}
120120

121-
auto startLineAndCol = SM.getLineAndColumn(range.Start);
122-
auto endLineAndCol = SM.getLineAndColumn(range.End);
121+
auto startLineAndCol = SM.getPresumedLineAndColumnForLoc(range.Start);
122+
auto endLineAndCol = SM.getPresumedLineAndColumnForLoc(range.End);
123123

124124
out << "[" << startLineAndCol.first << ":" << startLineAndCol.second << " - "
125125
<< endLineAndCol.first << ":" << endLineAndCol.second << "]";

lib/AST/ASTScopeSourceRange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ bool ASTScopeImpl::doesRangeMatch(unsigned start, unsigned end, StringRef file,
176176
return false;
177177
const auto &SM = getSourceManager();
178178
const auto r = getSourceRangeOfScope(true);
179-
if (start && start != SM.getLineNumber(r.Start))
179+
if (start && start != SM.getLineAndColumnInBuffer(r.Start).first)
180180
return false;
181-
if (end && end != SM.getLineNumber(r.End))
181+
if (end && end != SM.getLineAndColumnInBuffer(r.End).first)
182182
return false;
183183
if (file.empty())
184184
return true;

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static unsigned getLineNumber(DCType *DC) {
613613
return 0;
614614

615615
const ASTContext &ctx = static_cast<const DeclContext *>(DC)->getASTContext();
616-
return ctx.SourceMgr.getLineAndColumn(loc).first;
616+
return ctx.SourceMgr.getPresumedLineAndColumnForLoc(loc).first;
617617
}
618618

619619
unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ void RequirementSource::print(llvm::raw_ostream &out,
14061406

14071407
unsigned bufferID = srcMgr->findBufferContainingLoc(loc);
14081408

1409-
auto lineAndCol = srcMgr->getLineAndColumn(loc, bufferID);
1409+
auto lineAndCol = srcMgr->getPresumedLineAndColumnForLoc(loc, bufferID);
14101410
out << " @ " << lineAndCol.first << ':' << lineAndCol.second;
14111411
};
14121412

lib/AST/IncrementalRanges.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace incremental_ranges;
3636

3737
SerializableSourceLocation::SerializableSourceLocation(
3838
const SourceLoc loc, const SourceManager &SM) {
39-
auto lc = SM.getLineAndColumn(loc);
39+
auto lc = SM.getPresumedLineAndColumnForLoc(loc);
4040
line = lc.first;
4141
column = lc.second;
4242
}

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ SourceFile::getBasicLocsForDecl(const Decl *D) const {
849849

850850
auto setLineColumn = [&SM](LineColumn &Home, SourceLoc Loc) {
851851
if (Loc.isValid()) {
852-
std::tie(Home.Line, Home.Column) = SM.getLineAndColumn(Loc);
852+
std::tie(Home.Line, Home.Column) = SM.getPresumedLineAndColumnForLoc(Loc);
853853
}
854854
};
855855
#define SET(X) setLineColumn(Result.X, D->get##X());

lib/AST/RawComment.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ SingleRawComment::SingleRawComment(CharSourceRange Range,
5959
const SourceManager &SourceMgr)
6060
: Range(Range), RawText(SourceMgr.extractText(Range)),
6161
Kind(static_cast<unsigned>(getCommentKind(RawText))) {
62-
auto StartLineAndColumn = SourceMgr.getLineAndColumn(Range.getStart());
62+
auto StartLineAndColumn =
63+
SourceMgr.getPresumedLineAndColumnForLoc(Range.getStart());
6364
StartLine = StartLineAndColumn.first;
6465
StartColumn = StartLineAndColumn.second;
65-
EndLine = SourceMgr.getLineNumber(Range.getEnd());
66+
EndLine = SourceMgr.getLineAndColumnInBuffer(Range.getEnd()).first;
6667
}
6768

6869
SingleRawComment::SingleRawComment(StringRef RawText, unsigned StartColumn)

0 commit comments

Comments
 (0)