1313import ASTBridging
1414
1515import Basic
16- import SIL
1716
18- typealias DiagID = BridgedDiagID
17+ public typealias DiagID = BridgedDiagID
1918
20- protocol DiagnosticArgument {
19+ public protocol DiagnosticArgument {
2120 func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void )
2221}
2322extension String : DiagnosticArgument {
24- func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
23+ public func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
2524 _withBridgedStringRef { fn ( BridgedDiagnosticArgument ( $0) ) }
2625 }
2726}
2827extension StringRef : DiagnosticArgument {
29- func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
28+ public func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
3029 fn ( BridgedDiagnosticArgument ( _bridged) )
3130 }
3231}
3332extension Int : DiagnosticArgument {
34- func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
33+ public func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
3534 fn ( BridgedDiagnosticArgument ( self ) )
3635 }
3736}
3837extension Type : DiagnosticArgument {
39- func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
40- fn ( bridged. asDiagnosticArgument ( ) )
41- }
42- }
43- extension DeclRef : DiagnosticArgument {
44- func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
38+ public func _withBridgedDiagnosticArgument( _ fn: ( BridgedDiagnosticArgument ) -> Void ) {
4539 fn ( bridged. asDiagnosticArgument ( ) )
4640 }
4741}
4842
49- struct DiagnosticFixIt {
43+ public struct DiagnosticFixIt {
5044 let start : SourceLoc
5145 let byteLength : Int
5246 let text : String
@@ -67,10 +61,10 @@ struct DiagnosticFixIt {
6761 }
6862}
6963
70- struct DiagnosticEngine {
64+ public struct DiagnosticEngine {
7165 private let bridged : BridgedDiagnosticEngine
7266
73- init ( bridged: BridgedDiagnosticEngine ) {
67+ public init ( bridged: BridgedDiagnosticEngine ) {
7468 self . bridged = bridged
7569 }
7670 init ? ( bridged: BridgedNullableDiagnosticEngine ) {
@@ -80,9 +74,9 @@ struct DiagnosticEngine {
8074 self . bridged = BridgedDiagnosticEngine ( raw: raw)
8175 }
8276
83- func diagnose( _ position: SourceLoc ? ,
84- _ id: DiagID ,
77+ public func diagnose( _ id: DiagID ,
8578 _ args: [ DiagnosticArgument ] ,
79+ at position: SourceLoc ? ,
8680 highlight: CharSourceRange ? = nil ,
8781 fixIts: [ DiagnosticFixIt ] = [ ] ) {
8882
@@ -136,11 +130,32 @@ struct DiagnosticEngine {
136130 closure ( )
137131 }
138132
139- func diagnose( _ position: SourceLoc ? ,
140- _ id: DiagID ,
133+ public func diagnose( _ id: DiagID ,
141134 _ args: DiagnosticArgument ... ,
135+ at position: SourceLoc ? ,
142136 highlight: CharSourceRange ? = nil ,
143137 fixIts: DiagnosticFixIt ... ) {
144- diagnose ( position, id, args, highlight: highlight, fixIts: fixIts)
138+ diagnose ( id, args, at: position, highlight: highlight, fixIts: fixIts)
139+ }
140+
141+ public func diagnose( _ diagnostic: Diagnostic ) {
142+ diagnose ( diagnostic. id, diagnostic. arguments, at: diagnostic. position)
143+ }
144+ }
145+
146+ /// A utility struct which allows throwing a Diagnostic.
147+ public struct Diagnostic : Error {
148+ public let id : DiagID
149+ public let arguments : [ DiagnosticArgument ]
150+ public let position : SourceLoc ?
151+
152+ public init ( _ id: DiagID , _ arguments: DiagnosticArgument ... , at position: SourceLoc ? ) {
153+ self . init ( id, arguments, at: position)
154+ }
155+
156+ public init ( _ id: DiagID , _ arguments: [ DiagnosticArgument ] , at position: SourceLoc ? ) {
157+ self . id = id
158+ self . arguments = arguments
159+ self . position = position
145160 }
146161}
0 commit comments