@@ -14,69 +14,57 @@ import ASTBridging
1414import BasicBridging
1515import SwiftSyntax
1616
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 ? )
2120}
22-
23- extension BridgedIdentifier : ExpressibleByNilLiteral {
21+ extension BridgedNullable {
2422 public init ( nilLiteral: ( ) ) {
2523 self . init ( raw: nil )
2624 }
2725}
2826
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+
2937/// Protocol that declares that there's a "Nullable" variation of the type.
3038///
3139/// 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 }
3743}
38-
39- extension Optional where Wrapped: HasNullable {
44+ extension Optional where Wrapped: BridgedHasNullable {
4045 /// Convert an Optional to Nullable variation of the wrapped type.
4146 var asNullable : Wrapped . Nullable {
42- Wrapped . asNullable ( self )
47+ Wrapped . Nullable ( raw : self ? . raw )
4348 }
4449}
4550
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
5053}
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
5656}
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
6259}
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
6862}
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
7465}
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
8068}
8169
8270public extension BridgedSourceLoc {
0 commit comments