@@ -14,69 +14,57 @@ import ASTBridging
14
14
import BasicBridging
15
15
import SwiftSyntax
16
16
17
- extension BridgedSourceLoc : ExpressibleByNilLiteral {
18
- public init ( nilLiteral: ( ) ) {
19
- self . init ( raw: nil )
20
- }
17
+ protocol BridgedNullable : ExpressibleByNilLiteral {
18
+ associatedtype RawPtr
19
+ init ( raw: RawPtr ? )
21
20
}
22
-
23
- extension BridgedIdentifier : ExpressibleByNilLiteral {
21
+ extension BridgedNullable {
24
22
public init ( nilLiteral: ( ) ) {
25
23
self . init ( raw: nil )
26
24
}
27
25
}
28
26
27
+ extension BridgedSourceLoc : BridgedNullable { }
28
+ extension BridgedIdentifier : BridgedNullable { }
29
+ extension BridgedNullableExpr : BridgedNullable { }
30
+ extension BridgedNullableStmt : BridgedNullable { }
31
+ extension BridgedNullableTypeRepr : BridgedNullable { }
32
+ extension BridgedNullablePattern : BridgedNullable { }
33
+ extension BridgedNullableGenericParamList : BridgedNullable { }
34
+ extension BridgedNullableTrailingWhereClause : BridgedNullable { }
35
+ extension BridgedNullableParameterList : BridgedNullable { }
36
+
29
37
/// Protocol that declares that there's a "Nullable" variation of the type.
30
38
///
31
39
/// E.g. BridgedExpr vs BridgedNullableExpr.
32
- protocol HasNullable {
33
- associatedtype Nullable
34
-
35
- /// Convert an `Optional<Self>` to `Nullable`.
36
- static func asNullable( _ node: Self ? ) -> Nullable
40
+ protocol BridgedHasNullable {
41
+ associatedtype Nullable : BridgedNullable
42
+ var raw : Nullable . RawPtr { get }
37
43
}
38
-
39
- extension Optional where Wrapped: HasNullable {
44
+ extension Optional where Wrapped: BridgedHasNullable {
40
45
/// Convert an Optional to Nullable variation of the wrapped type.
41
46
var asNullable : Wrapped . Nullable {
42
- Wrapped . asNullable ( self )
47
+ Wrapped . Nullable ( raw : self ? . raw )
43
48
}
44
49
}
45
50
46
- extension BridgedStmt : HasNullable {
47
- static func asNullable( _ node: Self ? ) -> BridgedNullableStmt {
48
- . init( raw: node? . raw)
49
- }
51
+ extension BridgedStmt : BridgedHasNullable {
52
+ typealias Nullable = BridgedNullableStmt
50
53
}
51
-
52
- extension BridgedExpr : HasNullable {
53
- static func asNullable( _ node: Self ? ) -> BridgedNullableExpr {
54
- . init( raw: node? . raw)
55
- }
54
+ extension BridgedExpr : BridgedHasNullable {
55
+ typealias Nullable = BridgedNullableExpr
56
56
}
57
-
58
- extension BridgedTypeRepr : HasNullable {
59
- static func asNullable( _ node: Self ? ) -> BridgedNullableTypeRepr {
60
- . init( raw: node? . raw)
61
- }
57
+ extension BridgedTypeRepr : BridgedHasNullable {
58
+ typealias Nullable = BridgedNullableTypeRepr
62
59
}
63
-
64
- extension BridgedGenericParamList : HasNullable {
65
- static func asNullable( _ node: Self ? ) -> BridgedNullableGenericParamList {
66
- . init( raw: node? . raw)
67
- }
60
+ extension BridgedGenericParamList : BridgedHasNullable {
61
+ typealias Nullable = BridgedNullableGenericParamList
68
62
}
69
-
70
- extension BridgedTrailingWhereClause : HasNullable {
71
- static func asNullable( _ node: Self ? ) -> BridgedNullableTrailingWhereClause {
72
- . init( raw: node? . raw)
73
- }
63
+ extension BridgedTrailingWhereClause : BridgedHasNullable {
64
+ typealias Nullable = BridgedNullableTrailingWhereClause
74
65
}
75
-
76
- extension BridgedParameterList : HasNullable {
77
- static func asNullable( _ node: Self ? ) -> BridgedNullableParameterList {
78
- . init( raw: node? . raw)
79
- }
66
+ extension BridgedParameterList : BridgedHasNullable {
67
+ typealias Nullable = BridgedNullableParameterList
80
68
}
81
69
82
70
public extension BridgedSourceLoc {
0 commit comments