@@ -34,12 +34,16 @@ extension Syntax {
34
34
/// - flags: Flags that indicate what checks should be performed.
35
35
/// 0x01: Perform round-trip checking.
36
36
/// 0x02: Check for parser diagnostics.
37
+ /// - hookCtx: A caller-provided context parameter to be passed back in the diagnostic hook.
38
+ /// - diagnosticHook: A callback invoked once per diagnostic emitted by the parser.
37
39
/// - Returns: 0 if all requested consistency checks passed, nonzero otherwise.
38
40
@_cdecl ( " swift_parser_consistencyCheck " )
39
41
@_spi ( SwiftCompiler)
40
42
public func _parserConsistencyCheck(
41
43
bufferPtr: UnsafePointer < UInt8 > , bufferLength: Int ,
42
- filename: UnsafePointer < UInt8 > , flags: CUnsignedInt
44
+ filename: UnsafePointer < UInt8 > , flags: CUnsignedInt ,
45
+ hookCtx: OpaquePointer ,
46
+ diagnosticHook: @convention ( c) ( Int , UnsafePointer < Int8 > , OpaquePointer ) -> Void
43
47
) -> CInt {
44
48
let buffer = UnsafeBufferPointer < UInt8 > (
45
49
start: bufferPtr, count: bufferLength)
@@ -62,7 +66,6 @@ public func _parserConsistencyCheck(
62
66
var anyDiags = false
63
67
64
68
let sourceFile = Syntax ( raw: rawSourceFile. raw) . as ( SourceFileSyntax . self) !
65
-
66
69
let diags = ParseDiagnosticsGenerator . diagnostics (
67
70
for: sourceFile)
68
71
for diag in diags {
@@ -73,7 +76,9 @@ public func _parserConsistencyCheck(
73
76
continue
74
77
}
75
78
76
- print ( " \( String ( cString: filename) ) : error: \( diag. debugDescription) " )
79
+ diag. message. withCString { diagText in
80
+ diagnosticHook ( diag. position. utf8Offset, diagText, hookCtx)
81
+ }
77
82
anyDiags = true
78
83
}
79
84
0 commit comments