Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cxx-interop][SwiftCompilerSources] Use DiagnosticInfo::FixIt instead of BridgedDiagnosticFixIt #60018

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public struct DiagnosticFixIt {
self.text = text
}

func withBridgedDiagnosticFixIt(_ fn: (BridgedDiagnosticFixIt) -> Void) {
func withBridgedDiagnosticFixIt(_ fn: (swift.DiagnosticInfo.FixIt) -> Void) {
text.withBridgedStringRef { bridgedTextRef in
let bridgedDiagnosticFixIt = BridgedDiagnosticFixIt(
start: start.bridged,
byteLength: byteLength,
text: bridgedTextRef)
let bridgedDiagnosticFixIt = swift.DiagnosticInfo.FixIt(
swift.CharSourceRange(start.bridged, UInt32(byteLength)),
llvm.StringRef(bridgedTextRef),
llvm.ArrayRef<swift.DiagnosticArgument>())
fn(bridgedDiagnosticFixIt)
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public struct DiagnosticEngine {
let bridgedSourceLoc: swift.SourceLoc = position.bridged
let bridgedHighlightRange: swift.CharSourceRange = highlight.bridged
var bridgedArgs: [BridgedDiagnosticArgument] = []
var bridgedFixIts: [BridgedDiagnosticFixIt] = []
var bridgedFixIts: [swift.DiagnosticInfo.FixIt] = []

// Build a higher-order function to wrap every 'withBridgedXXX { ... }'
// calls, so we don't escape anything from the closure. 'bridgedArgs' and
Expand Down
6 changes: 6 additions & 0 deletions SwiftCompilerSources/Sources/Basic/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ extension BridgedStringRef {
}
}

extension llvm.StringRef {
public init(_ bridged: BridgedStringRef) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will go away once we use llvm.StringRef instead of BridgedStringRef.

self.init(bridged.data, bridged.length)
}
}

extension String {
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
var str = self
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ typedef struct {
} value;
} BridgedDiagnosticArgument;

typedef struct {
swift::SourceLoc start;
SwiftInt byteLength;
BridgedStringRef text;
} BridgedDiagnosticFixIt;

typedef struct {
void * _Nonnull object;
} BridgedDiagnosticEngine;
Expand Down
3 changes: 3 additions & 0 deletions include/swift/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module BasicBridging {

module ASTBridging {
header "AST/ASTBridging.h"
header "AST/DiagnosticEngine.h"
header "AST/DiagnosticConsumer.h"
requires cplusplus
export *
}

Expand Down
9 changes: 4 additions & 5 deletions lib/AST/ASTBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DiagnosticEngine_diagnose(
BridgedDiagID bridgedDiagID,
BridgedArrayRef /*BridgedDiagnosticArgument*/ bridgedArguments,
CharSourceRange highlight,
BridgedArrayRef /*BridgedDiagnosticFixIt*/ bridgedFixIts) {
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
auto *D = getDiagnosticEngine(bridgedEngine);

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

// Add fix-its.
for (auto bridgedFixIt : getArrayRef<BridgedDiagnosticFixIt>(bridgedFixIts)) {
auto range = CharSourceRange(bridgedFixIt.start,
bridgedFixIt.byteLength);
auto text = getStringRef(bridgedFixIt.text);
for (auto bridgedFixIt : getArrayRef<DiagnosticInfo::FixIt>(bridgedFixIts)) {
auto range = bridgedFixIt.getRange();
auto text = bridgedFixIt.getText();
inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text);
}
}
Expand Down