Skip to content

Commit 2ee8211

Browse files
committed
[DiagnosticBridge] NFC: Refactor addQueuedDiagnostic to use BridgedStringRef instead of plain pointers
1 parent f6c9177 commit 2ee8211

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

include/swift/Bridging/ASTGen.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ void swift_ASTGen_addQueuedSourceFile(
2727
intptr_t displayNameLength, ssize_t parentID, ssize_t positionInParent);
2828
void swift_ASTGen_addQueuedDiagnostic(
2929
void *_Nonnull queued, void *_Nonnull state,
30-
const char *_Nonnull text, ptrdiff_t textLength,
30+
BridgedStringRef text,
3131
BridgedDiagnosticSeverity severity, const void *_Nullable sourceLoc,
32-
const char *_Nullable categoryName, ptrdiff_t categoryNameLength,
33-
const char *_Nullable documentationPath,
34-
ptrdiff_t documentationPathLength,
32+
BridgedStringRef categoryName,
33+
BridgedStringRef documentationPath,
3534
const void *_Nullable *_Nullable highlightRanges,
3635
ptrdiff_t numHighlightRanges);
3736
void swift_ASTGen_renderQueuedDiagnostics(

lib/AST/DiagnosticBridge.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
7171

7272
// FIXME: Translate Fix-Its.
7373
swift_ASTGen_addQueuedDiagnostic(queuedDiagnostics, perFrontendState,
74-
text.data(), text.size(),
74+
text.str(),
7575
severity, info.Loc.getOpaquePointerValue(),
76-
info.Category.data(),
77-
info.Category.size(),
78-
documentationPath.data(),
79-
documentationPath.size(),
76+
info.Category,
77+
documentationPath,
8078
highlightRanges.data(),
8179
highlightRanges.size() / 2);
8280

lib/ASTGen/Sources/ASTGen/DiagnosticsBridge.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,11 @@ public func addQueuedSourceFile(
241241
public func addQueuedDiagnostic(
242242
queuedDiagnosticsPtr: UnsafeMutableRawPointer,
243243
perFrontendDiagnosticStatePtr: UnsafeMutableRawPointer,
244-
text: UnsafePointer<UInt8>,
245-
textLength: Int,
244+
text: BridgedStringRef,
246245
severity: BridgedDiagnosticSeverity,
247246
cLoc: BridgedSourceLoc,
248-
categoryName: UnsafePointer<UInt8>?,
249-
categoryLength: Int,
250-
documentationPath: UnsafePointer<UInt8>?,
251-
documentationPathLength: Int,
247+
categoryName: BridgedStringRef,
248+
documentationPath: BridgedStringRef,
252249
highlightRangesPtr: UnsafePointer<BridgedSourceLoc>?,
253250
numHighlightRanges: Int
254251
) {
@@ -349,10 +346,10 @@ public func addQueuedDiagnostic(
349346
}
350347
}
351348

352-
let category: DiagnosticCategory? = categoryName.flatMap { categoryNamePtr in
349+
let category: DiagnosticCategory? = categoryName.data.flatMap { categoryNamePtr in
353350
let categoryNameBuffer = UnsafeBufferPointer(
354351
start: categoryNamePtr,
355-
count: categoryLength
352+
count: categoryName.count
356353
)
357354
let categoryName = String(decoding: categoryNameBuffer, as: UTF8.self)
358355

@@ -363,10 +360,10 @@ public func addQueuedDiagnostic(
363360
return nil
364361
}
365362

366-
let documentationURL = documentationPath.map { documentationPathPtr in
363+
let documentationURL = documentationPath.data.map { documentationPathPtr in
367364
let documentationPathBuffer = UnsafeBufferPointer(
368365
start: documentationPathPtr,
369-
count: documentationPathLength
366+
count: documentationPath.count
370367
)
371368

372369
let documentationPath = String(decoding: documentationPathBuffer, as: UTF8.self)
@@ -390,7 +387,11 @@ public func addQueuedDiagnostic(
390387
diagnosticState.pointee.referencedCategories.insert(category)
391388
}
392389

393-
let textBuffer = UnsafeBufferPointer(start: text, count: textLength)
390+
guard let textPtr = text.data, !text.isEmpty else {
391+
return
392+
}
393+
394+
let textBuffer = UnsafeBufferPointer(start: textPtr, count: text.count)
394395
let diagnostic = Diagnostic(
395396
node: node,
396397
position: position,

0 commit comments

Comments
 (0)