Skip to content

Commit 7f9e39c

Browse files
authored
Merge pull request swiftlang#59907 from apple/egorzhdan/scs-charsourcerange
[cxx-interop][SwiftCompilerSources] Use `swift::CharSourceRange` instead of `BridgedCharSourceRange`
2 parents b9ef3e8 + 220d95e commit 7f9e39c

File tree

6 files changed

+12
-32
lines changed

6 files changed

+12
-32
lines changed

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public struct DiagnosticEngine {
8181
fixIts: [DiagnosticFixIt] = []) {
8282

8383
let bridgedSourceLoc: swift.SourceLoc = position.bridged
84-
let bridgedHighlightRange: BridgedCharSourceRange = highlight.bridged
84+
let bridgedHighlightRange: swift.CharSourceRange = highlight.bridged
8585
var bridgedArgs: [BridgedDiagnosticArgument] = []
8686
var bridgedFixIts: [BridgedDiagnosticFixIt] = []
8787

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@ extension Optional where Wrapped == SourceLoc {
4949

5050
public struct CharSourceRange {
5151
private let start: SourceLoc
52-
private let byteLength: Int
52+
private let byteLength: UInt32
5353

54-
public init(start: SourceLoc, byteLength: Int) {
54+
public init(start: SourceLoc, byteLength: UInt32) {
5555
self.start = start
5656
self.byteLength = byteLength
5757
}
5858

59-
public init?(bridged: BridgedCharSourceRange) {
60-
guard let start = SourceLoc(bridged: bridged.start) else {
59+
public init?(bridged: swift.CharSourceRange) {
60+
guard let start = SourceLoc(bridged: bridged.getStart()) else {
6161
return nil
6262
}
63-
self.init(start: start, byteLength: bridged.byteLength)
63+
self.init(start: start, byteLength: bridged.getByteLength())
6464
}
6565

66-
public var bridged: BridgedCharSourceRange {
67-
.init(start: start.bridged, byteLength: byteLength)
66+
public var bridged: swift.CharSourceRange {
67+
.init(start.bridged, byteLength)
6868
}
6969
}
7070

7171
extension Optional where Wrapped == CharSourceRange {
72-
public var bridged: BridgedCharSourceRange {
73-
self?.bridged ?? .init(start: .init(), byteLength: 0)
72+
public var bridged: swift.CharSourceRange {
73+
self?.bridged ?? .init(.init(), 0)
7474
}
7575
}

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ typedef struct {
6868
// FIXME: Can we bridge InFlightDiagnostic?
6969
void DiagnosticEngine_diagnose(BridgedDiagnosticEngine, swift::SourceLoc loc,
7070
BridgedDiagID diagID, BridgedArrayRef arguments,
71-
BridgedCharSourceRange highlight,
71+
swift::CharSourceRange highlight,
7272
BridgedArrayRef fixIts);
7373

7474
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);

include/swift/Basic/BasicBridging.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ void OStream_write(BridgedOStream os, BridgedStringRef str);
4040

4141
void freeBridgedStringRef(BridgedStringRef str);
4242

43-
//===----------------------------------------------------------------------===//
44-
// Source location
45-
//===----------------------------------------------------------------------===//
46-
47-
typedef struct {
48-
swift::SourceLoc start;
49-
SwiftInt byteLength;
50-
} BridgedCharSourceRange;
51-
5243
SWIFT_END_NULLABILITY_ANNOTATIONS
5344

5445
#endif

include/swift/Basic/BridgingUtils.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ inline llvm::ArrayRef<T> getArrayRef(BridgedArrayRef bridged) {
3636
return {static_cast<const T *>(bridged.data), bridged.numElements};
3737
}
3838

39-
inline CharSourceRange
40-
getCharSourceRange(const BridgedCharSourceRange &bridged) {
41-
return CharSourceRange(bridged.start, bridged.byteLength);
42-
}
43-
44-
inline BridgedCharSourceRange
45-
getBridgedCharSourceRange(const CharSourceRange &range) {
46-
return {range.getStart(), range.getByteLength()};
47-
}
48-
4939
} // namespace swift
5040

5141
#endif

lib/AST/ASTBridging.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void DiagnosticEngine_diagnose(
4141
BridgedDiagnosticEngine bridgedEngine, SourceLoc loc,
4242
BridgedDiagID bridgedDiagID,
4343
BridgedArrayRef /*BridgedDiagnosticArgument*/ bridgedArguments,
44-
BridgedCharSourceRange bridgedHighlight,
44+
CharSourceRange highlight,
4545
BridgedArrayRef /*BridgedDiagnosticFixIt*/ bridgedFixIts) {
4646
auto *D = getDiagnosticEngine(bridgedEngine);
4747

@@ -54,7 +54,6 @@ void DiagnosticEngine_diagnose(
5454
auto inflight = D->diagnose(loc, diagID, arguments);
5555

5656
// Add highlight.
57-
auto highlight = getCharSourceRange(bridgedHighlight);
5857
if (highlight.isValid()) {
5958
inflight.highlightChars(highlight.getStart(), highlight.getEnd());
6059
}

0 commit comments

Comments
 (0)