Skip to content

Commit 1ae44e7

Browse files
committed
[cxx-interop][SwiftCompilerSources] Use DiagnosticInfo::FixIt instead of BridgedDiagnosticFixIt
This removes some of the bridging code and replaces it with C++ calls. rdar://83361087
1 parent f4c26c3 commit 1ae44e7

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public struct DiagnosticFixIt {
5050
self.text = text
5151
}
5252

53-
func withBridgedDiagnosticFixIt(_ fn: (BridgedDiagnosticFixIt) -> Void) {
53+
func withBridgedDiagnosticFixIt(_ fn: (swift.DiagnosticInfo.FixIt) -> Void) {
5454
text.withBridgedStringRef { bridgedTextRef in
55-
let bridgedDiagnosticFixIt = BridgedDiagnosticFixIt(
56-
start: start.bridged,
57-
byteLength: byteLength,
58-
text: bridgedTextRef)
55+
let bridgedDiagnosticFixIt = swift.DiagnosticInfo.FixIt(
56+
swift.CharSourceRange(start.bridged, UInt32(byteLength)),
57+
llvm.StringRef(bridgedTextRef),
58+
llvm.ArrayRef<swift.DiagnosticArgument>())
5959
fn(bridgedDiagnosticFixIt)
6060
}
6161
}
@@ -83,7 +83,7 @@ public struct DiagnosticEngine {
8383
let bridgedSourceLoc: swift.SourceLoc = position.bridged
8484
let bridgedHighlightRange: swift.CharSourceRange = highlight.bridged
8585
var bridgedArgs: [BridgedDiagnosticArgument] = []
86-
var bridgedFixIts: [BridgedDiagnosticFixIt] = []
86+
var bridgedFixIts: [swift.DiagnosticInfo.FixIt] = []
8787

8888
// Build a higher-order function to wrap every 'withBridgedXXX { ... }'
8989
// calls, so we don't escape anything from the closure. 'bridgedArgs' and

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ extension BridgedStringRef {
4848
}
4949
}
5050

51+
extension llvm.StringRef {
52+
public init(_ bridged: BridgedStringRef) {
53+
self.init(bridged.data, bridged.length)
54+
}
55+
}
56+
5157
extension String {
5258
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
5359
var str = self

include/swift/AST/ASTBridging.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ typedef struct {
5151
} value;
5252
} BridgedDiagnosticArgument;
5353

54-
typedef struct {
55-
swift::SourceLoc start;
56-
SwiftInt byteLength;
57-
BridgedStringRef text;
58-
} BridgedDiagnosticFixIt;
59-
6054
typedef struct {
6155
void * _Nonnull object;
6256
} BridgedDiagnosticEngine;

include/swift/module.modulemap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module BasicBridging {
66

77
module ASTBridging {
88
header "AST/ASTBridging.h"
9+
header "AST/DiagnosticEngine.h"
10+
header "AST/DiagnosticConsumer.h"
11+
requires cplusplus
912
export *
1013
}
1114

lib/AST/ASTBridging.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void DiagnosticEngine_diagnose(
4242
BridgedDiagID bridgedDiagID,
4343
BridgedArrayRef /*BridgedDiagnosticArgument*/ bridgedArguments,
4444
CharSourceRange highlight,
45-
BridgedArrayRef /*BridgedDiagnosticFixIt*/ bridgedFixIts) {
45+
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
4646
auto *D = getDiagnosticEngine(bridgedEngine);
4747

4848
auto diagID = static_cast<DiagID>(bridgedDiagID);
@@ -59,10 +59,9 @@ void DiagnosticEngine_diagnose(
5959
}
6060

6161
// Add fix-its.
62-
for (auto bridgedFixIt : getArrayRef<BridgedDiagnosticFixIt>(bridgedFixIts)) {
63-
auto range = CharSourceRange(bridgedFixIt.start,
64-
bridgedFixIt.byteLength);
65-
auto text = getStringRef(bridgedFixIt.text);
62+
for (auto bridgedFixIt : getArrayRef<DiagnosticInfo::FixIt>(bridgedFixIts)) {
63+
auto range = bridgedFixIt.getRange();
64+
auto text = bridgedFixIt.getText();
6665
inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text);
6766
}
6867
}

0 commit comments

Comments
 (0)