Skip to content

Commit 299df93

Browse files
authored
Merge pull request #36807 from bnbarham/use-original-locs
Replace uses of presumed locations where they do not make sense
2 parents 501c716 + 20f45ec commit 299df93

File tree

13 files changed

+54
-28
lines changed

13 files changed

+54
-28
lines changed

lib/AST/RawComment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SingleRawComment::SingleRawComment(CharSourceRange Range,
6262
: Range(Range), RawText(SourceMgr.extractText(Range)),
6363
Kind(static_cast<unsigned>(getCommentKind(RawText))) {
6464
auto StartLineAndColumn =
65-
SourceMgr.getPresumedLineAndColumnForLoc(Range.getStart());
65+
SourceMgr.getLineAndColumnInBuffer(Range.getStart());
6666
StartLine = StartLineAndColumn.first;
6767
StartColumn = StartLineAndColumn.second;
6868
EndLine = SourceMgr.getLineAndColumnInBuffer(Range.getEnd()).first;

lib/IDE/Formatting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class FormatContext {
333333

334334
std::pair<unsigned, unsigned> indentLineAndColumn() {
335335
if (InnermostCtx)
336-
return SM.getPresumedLineAndColumnForLoc(InnermostCtx->ContextLoc);
336+
return SM.getLineAndColumnInBuffer(InnermostCtx->ContextLoc);
337337
return std::make_pair(0, 0);
338338
}
339339

lib/IDE/IDERequests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void swift::simple_display(llvm::raw_ostream &out, const CursorInfoOwner &owner)
340340
return;
341341
auto &SM = owner.File->getASTContext().SourceMgr;
342342
out << SM.getIdentifierForBuffer(*owner.File->getBufferID());
343-
auto LC = SM.getPresumedLineAndColumnForLoc(owner.Loc);
343+
auto LC = SM.getLineAndColumnInBuffer(owner.Loc);
344344
out << ":" << LC.first << ":" << LC.second;
345345
}
346346

@@ -351,7 +351,7 @@ void swift::ide::simple_display(llvm::raw_ostream &out,
351351
out << "Resolved cursor info at ";
352352
auto &SM = info.SF->getASTContext().SourceMgr;
353353
out << SM.getIdentifierForBuffer(*info.SF->getBufferID());
354-
auto LC = SM.getPresumedLineAndColumnForLoc(info.Loc);
354+
auto LC = SM.getLineAndColumnInBuffer(info.Loc);
355355
out << ":" << LC.first << ":" << LC.second;
356356
}
357357

@@ -1098,8 +1098,8 @@ void swift::simple_display(llvm::raw_ostream &out,
10981098
return;
10991099
auto &SM = owner.File->getASTContext().SourceMgr;
11001100
out << SM.getIdentifierForBuffer(*owner.File->getBufferID());
1101-
auto SLC = SM.getPresumedLineAndColumnForLoc(owner.StartLoc);
1102-
auto ELC = SM.getPresumedLineAndColumnForLoc(owner.EndLoc);
1101+
auto SLC = SM.getLineAndColumnInBuffer(owner.StartLoc);
1102+
auto ELC = SM.getLineAndColumnInBuffer(owner.EndLoc);
11031103
out << ": (" << SLC.first << ":" << SLC.second << ", "
11041104
<< ELC.first << ":" << ELC.second << ")";
11051105
}

lib/IDE/Refactoring.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ getNotableRegions(StringRef SourceText, unsigned NameOffset, StringRef Name,
11891189
unsigned BufferId = Instance->getPrimarySourceFile()->getBufferID().getValue();
11901190
SourceManager &SM = Instance->getSourceMgr();
11911191
SourceLoc NameLoc = SM.getLocForOffset(BufferId, NameOffset);
1192-
auto LineAndCol = SM.getPresumedLineAndColumnForLoc(NameLoc);
1192+
auto LineAndCol = SM.getLineAndColumnInBuffer(NameLoc);
11931193

11941194
UnresolvedLoc UnresoledName{NameLoc, true};
11951195

@@ -1210,8 +1210,8 @@ getNotableRegions(StringRef SourceText, unsigned NameOffset, StringRef Name,
12101210
llvm::transform(
12111211
Ranges, NoteRegions.begin(),
12121212
[&SM](RenameRangeDetail &Detail) -> NoteRegion {
1213-
auto Start = SM.getPresumedLineAndColumnForLoc(Detail.Range.getStart());
1214-
auto End = SM.getPresumedLineAndColumnForLoc(Detail.Range.getEnd());
1213+
auto Start = SM.getLineAndColumnInBuffer(Detail.Range.getStart());
1214+
auto End = SM.getLineAndColumnInBuffer(Detail.Range.getEnd());
12151215
return {Detail.RangeKind, Start.first, Start.second,
12161216
End.first, End.second, Detail.Index};
12171217
});

lib/Index/Index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
603603
getLineColAndOffset(SourceLoc Loc) {
604604
if (Loc.isInvalid())
605605
return std::make_tuple(0, 0, None);
606-
auto lineAndColumn = SrcMgr.getPresumedLineAndColumnForLoc(Loc, BufferID);
606+
auto lineAndColumn = SrcMgr.getLineAndColumnInBuffer(Loc, BufferID);
607607
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
608608
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
609609
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -print-indexed-symbols -source-filename %s | %FileCheck %s
3+
4+
// The index should probably use the presumed location, but for now just check
5+
// that the indexed location isn't a mixture of both.
6+
7+
#sourceLocation(file: "some_file.swift", line: 1)
8+
func testFunc() {}
9+
// CHECK: [[@LINE-1]]:6 | function/Swift | testFunc() | s:14swift_ide_test0C4FuncyyF | Def | rel: 0
10+
#sourceLocation()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#sourceLocation(file: "someFile.swift", line: 10)
2+
3+
func foo() {
4+
// RUN: %sourcekitd-test -req=format -pos=%(line+1):1 %s | %FileCheck %s
5+
let test = 1
6+
// CHECK: key.sourcetext: " let test = 1"
7+
}
8+
#sourceLocation()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#sourceLocation(file: "someFile.swift", line: 10)
2+
func test() {}
3+
#sourceLocation()
4+
5+
// RUN: %sourcekitd-test -req=find-local-rename-ranges -pos=2:6 %s -- %s | %FileCheck %s
6+
// CHECK: 2:6-2:10 source.refactoring.range.kind.basename
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
// REQUIRES: OS=macosx || OS=linux-gnu
2+
13
func foo() -> String {
4+
// RUN: %sourcekitd-test -req=localize-string -pos=%(line+1):10 %s -- %s | %FileCheck %s --check-prefix=CHECK-BASIC
25
return "abc"
6+
// CHECK-BASIC: source.edit.kind.active:
7+
// CHECK-BASIC: [[# @LINE-2]]:10-[[# @LINE-2]]:10 "NSLocalizedString("
8+
// CHECK-BASIC: source.edit.kind.active:
9+
// CHECK-BASIC: [[# @LINE-4]]:15-[[# @LINE-4]]:15 ", comment: "")"
310
}
411

5-
// RUN: %empty-directory(%t.result)
6-
// RUN: %sourcekitd-test -req=localize-string -pos=2:10 %s -- %s > %t.result/localize-string.swift.expected
7-
// RUN: %diff -u %S/localize-string.swift.expected %t.result/localize-string.swift.expected
8-
9-
// REQUIRES: OS=macosx || OS=linux-gnu
12+
#sourceLocation(file: "someFile.swift", line: 20)
13+
func bar() -> String {
14+
// RUN: %sourcekitd-test -req=localize-string -pos=%(line+1):10 %s -- %s | %FileCheck %s --check-prefix=CHECK-DIRECTIVE
15+
return "abc"
16+
// CHECK-DIRECTIVE: [[# @LINE-1]]:10-[[# @LINE-1]]:10
17+
}
18+
#sourceLocation()

test/SourceKit/Refactoring/semantic-refactoring/localize-string.swift.expected

Lines changed: 0 additions & 4 deletions
This file was deleted.

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,8 @@ class RequestRefactoringEditConsumer::Implementation {
12331233
llvm::transform(
12341234
Replacements, std::back_inserter(AllEdits),
12351235
[&](const Replacement &R) -> Edit {
1236-
std::pair<unsigned, unsigned> Start =
1237-
SM.getPresumedLineAndColumnForLoc(
1238-
R.Range.getStart()),
1239-
End = SM.getPresumedLineAndColumnForLoc(
1240-
R.Range.getEnd());
1236+
auto Start = SM.getLineAndColumnInBuffer(R.Range.getStart());
1237+
auto End = SM.getLineAndColumnInBuffer(R.Range.getEnd());
12411238
SmallVector<NoteRegion, 4> SubRanges;
12421239
auto RawRanges = R.RegionsWorthNote;
12431240
llvm::transform(
@@ -1305,9 +1302,9 @@ class RequestRenameRangeConsumer::Implementation {
13051302
for (const auto &R : Ranges) {
13061303
SourceKit::RenameRangeDetail Result;
13071304
std::tie(Result.StartLine, Result.StartColumn) =
1308-
SM.getPresumedLineAndColumnForLoc(R.Range.getStart());
1305+
SM.getLineAndColumnInBuffer(R.Range.getStart());
13091306
std::tie(Result.EndLine, Result.EndColumn) =
1310-
SM.getPresumedLineAndColumnForLoc(R.Range.getEnd());
1307+
SM.getLineAndColumnInBuffer(R.Range.getEnd());
13111308
Result.ArgIndex = R.Index;
13121309
Result.Kind =
13131310
SwiftLangSupport::getUIDForRefactoringRangeKind(R.RangeKind);

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ static void resolveCursor(
13561356
SmallVector<RefactoringKind, 8> Kinds;
13571357
RangeConfig Range;
13581358
Range.BufferId = BufferID;
1359-
auto Pair = SM.getPresumedLineAndColumnForLoc(Loc);
1359+
auto Pair = SM.getLineAndColumnInBuffer(Loc);
13601360
Range.Line = Pair.first;
13611361
Range.Column = Pair.second;
13621362
Range.Length = Length;

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ int doDumpRawTokenSyntax(const StringRef InputFile) {
696696
SourceLoc Loc =
697697
SourceMgr.getLocForOffset(BufferID, TokAndPos.second.getOffset());
698698
unsigned Line, Column;
699-
std::tie(Line, Column) = SourceMgr.getPresumedLineAndColumnForLoc(Loc);
699+
std::tie(Line, Column) = SourceMgr.getLineAndColumnInBuffer(Loc);
700700
llvm::outs() << Line << ":" << Column << "\n";
701701
TokAndPos.first->dump(llvm::outs());
702702
llvm::outs() << "\n";

0 commit comments

Comments
 (0)