@@ -241,15 +241,12 @@ public func addQueuedSourceFile(
241241public 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 ,
252- highlightRangesPtr: UnsafePointer < BridgedSourceLoc > ? ,
247+ categoryName: BridgedStringRef ,
248+ documentationPath: BridgedStringRef ,
249+ highlightRangesPtr: UnsafePointer < BridgedCharSourceRange > ? ,
253250 numHighlightRanges: Int
254251) {
255252 let queuedDiagnostics = queuedDiagnosticsPtr. assumingMemoryBound (
@@ -302,14 +299,16 @@ public func addQueuedDiagnostic(
302299
303300 // Map the highlights.
304301 var highlights : [ Syntax ] = [ ]
305- let highlightRanges = UnsafeBufferPointer < BridgedSourceLoc > (
302+ let highlightRanges = UnsafeBufferPointer < BridgedCharSourceRange > (
306303 start: highlightRangesPtr,
307- count: numHighlightRanges * 2
304+ count: numHighlightRanges
308305 )
309306 for index in 0 ..< numHighlightRanges {
307+ let range = highlightRanges [ index]
308+
310309 // Make sure both the start and the end land within this source file.
311- guard let start = highlightRanges [ index * 2 ] . getOpaquePointerValue ( ) ,
312- let end = highlightRanges [ index * 2 + 1 ] . getOpaquePointerValue ( )
310+ guard let start = range . start . getOpaquePointerValue ( ) ,
311+ let end = range . start . advanced ( by : range . byteLength ) . getOpaquePointerValue ( )
313312 else {
314313 continue
315314 }
@@ -349,53 +348,37 @@ public func addQueuedDiagnostic(
349348 }
350349 }
351350
352- let category : DiagnosticCategory ? = categoryName. flatMap { categoryNamePtr in
353- let categoryNameBuffer = UnsafeBufferPointer (
354- start: categoryNamePtr,
355- count: categoryLength
356- )
357- let categoryName = String ( decoding: categoryNameBuffer, as: UTF8 . self)
358-
359- // If the data comes from serialized diagnostics, it's possible that
360- // the category name is empty because StringRef() is serialized into
361- // an empty string.
362- guard !categoryName. isEmpty else {
363- return nil
351+ let documentationPath = String ( bridged: documentationPath)
352+ let documentationURL : String ? = if !documentationPath. isEmpty {
353+ // If this looks doesn't look like a URL, prepend file://.
354+ documentationPath. looksLikeURL ? documentationPath : " file:// \( documentationPath) "
355+ } else {
356+ nil
364357 }
365358
366- let documentationURL = documentationPath. map { documentationPathPtr in
367- let documentationPathBuffer = UnsafeBufferPointer (
368- start: documentationPathPtr,
369- count: documentationPathLength
359+ let categoryName = String ( bridged: categoryName)
360+ // If the data comes from serialized diagnostics, it's possible that
361+ // the category name is empty because StringRef() is serialized into
362+ // an empty string.
363+ let category : DiagnosticCategory ? = if !categoryName. isEmpty {
364+ DiagnosticCategory (
365+ name: categoryName,
366+ documentationURL: documentationURL
370367 )
371-
372- let documentationPath = String ( decoding: documentationPathBuffer, as: UTF8 . self)
373-
374- // If this looks doesn't look like a URL, prepend file://.
375- if !documentationPath. looksLikeURL {
376- return " file:// \( documentationPath) "
377- }
378-
379- return documentationPath
368+ } else {
369+ nil
380370 }
381371
382- return DiagnosticCategory (
383- name: categoryName,
384- documentationURL: documentationURL
385- )
386- }
387-
388372 // Note that we referenced this category.
389373 if let category {
390374 diagnosticState. pointee. referencedCategories. insert ( category)
391375 }
392376
393- let textBuffer = UnsafeBufferPointer ( start: text, count: textLength)
394377 let diagnostic = Diagnostic (
395378 node: node,
396379 position: position,
397380 message: SimpleDiagnostic (
398- message: String ( decoding : textBuffer , as : UTF8 . self ) ,
381+ message: String ( bridged : text ) ,
399382 severity: severity. asSeverity,
400383 category: category
401384 ) ,
0 commit comments