@@ -4,35 +4,37 @@ import SwiftSyntax
4
4
import CASTBridging
5
5
6
6
extension ASTGenVisitor {
7
- public func visit( _ node: TypealiasDeclSyntax ) -> UnsafeMutableRawPointer {
7
+ public func visit( _ node: TypealiasDeclSyntax ) -> ASTNode {
8
8
let aliasLoc = self . base. advanced ( by: node. typealiasKeyword. position. utf8Offset) . raw
9
9
let equalLoc = self . base. advanced ( by: node. initializer. equal. position. utf8Offset) . raw
10
10
var nameText = node. identifier. text
11
11
let name = nameText. withUTF8 { buf in
12
12
return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
13
13
}
14
14
let nameLoc = self . base. advanced ( by: node. identifier. position. utf8Offset) . raw
15
- let genericParams = node. genericParameterClause. map ( self . visit)
15
+ let genericParams = node. genericParameterClause. map ( self . visit) . map { $0 . rawValue }
16
16
let out = TypeAliasDecl_create ( self . ctx, self . declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
17
17
18
18
let oldDeclContext = declContext
19
19
declContext = out. declContext
20
20
defer { declContext = oldDeclContext }
21
21
22
- let underlying = self . visit ( node. initializer. value)
22
+ let underlying = self . visit ( node. initializer. value) . rawValue
23
23
TypeAliasDecl_setUnderlyingTypeRepr ( out. nominalDecl, underlying)
24
24
25
- return out. decl
25
+ return . decl ( out. decl)
26
26
}
27
27
28
- public func visit( _ node: StructDeclSyntax ) -> UnsafeMutableRawPointer {
28
+ public func visit( _ node: StructDeclSyntax ) -> ASTNode {
29
29
let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
30
30
var nameText = node. identifier. text
31
31
let name = nameText. withUTF8 { buf in
32
32
return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
33
33
}
34
34
35
- let genericParams = node. genericParameterClause. map ( self . visit)
35
+ let genericParams = node. genericParameterClause
36
+ . map ( self . visit)
37
+ . map { $0. rawValue }
36
38
let out = StructDecl_create ( ctx, loc, name, loc, genericParams, declContext)
37
39
let oldDeclContext = declContext
38
40
declContext = out. declContext
@@ -42,10 +44,10 @@ extension ASTGenVisitor {
42
44
NominalTypeDecl_setMembers ( out. nominalDecl, ref)
43
45
}
44
46
45
- return out. decl
47
+ return . decl ( out. decl)
46
48
}
47
49
48
- public func visit( _ node: ClassDeclSyntax ) -> UnsafeMutableRawPointer {
50
+ public func visit( _ node: ClassDeclSyntax ) -> ASTNode {
49
51
let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
50
52
var nameText = node. identifier. text
51
53
let name = nameText. withUTF8 { buf in
@@ -61,31 +63,22 @@ extension ASTGenVisitor {
61
63
NominalTypeDecl_setMembers ( out. nominalDecl, ref)
62
64
}
63
65
64
- return out. decl
66
+ return . decl ( out. decl)
65
67
}
66
68
67
- public func visit( _ node: VariableDeclSyntax ) -> UnsafeMutableRawPointer {
68
- let pattern = visit ( node. bindings. first!. pattern)
69
- let initializer = visit ( node. bindings. first!. initializer!)
69
+ public func visit( _ node: VariableDeclSyntax ) -> ASTNode {
70
+ let pattern = visit ( node. bindings. first!. pattern) . rawValue
71
+ let initializer = visit ( node. bindings. first!. initializer!) . rawValue
70
72
71
73
let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
72
74
let isStateic = false // TODO: compute this
73
75
let isLet = node. letOrVarKeyword. tokenKind == . letKeyword
74
76
75
77
// TODO: don't drop "initializer" on the floor.
76
- return SwiftVarDecl_create ( ctx, nil , loc, isStateic, isLet, declContext)
78
+ return . decl ( SwiftVarDecl_create ( ctx, nil , loc, isStateic, isLet, declContext) )
77
79
}
78
80
79
- public func visit( _ node: CodeBlockSyntax ) -> UnsafeMutableRawPointer {
80
- let statements = node. statements. map ( self . visit)
81
- let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
82
-
83
- return statements. withBridgedArrayRef { ref in
84
- BraceStmt_createStmt ( ctx, loc, ref, loc)
85
- }
86
- }
87
-
88
- public func visit( _ node: FunctionParameterSyntax ) -> UnsafeMutableRawPointer {
81
+ public func visit( _ node: FunctionParameterSyntax ) -> ASTNode {
89
82
let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
90
83
91
84
let firstName : UnsafeMutableRawPointer ?
@@ -109,34 +102,34 @@ extension ASTGenVisitor {
109
102
secondName = nil
110
103
}
111
104
112
- return ParamDecl_create ( ctx, loc, loc, firstName, loc, secondName, declContext)
105
+ return . decl ( ParamDecl_create ( ctx, loc, loc, firstName, loc, secondName, declContext) )
113
106
}
114
107
115
- public func visit( _ node: FunctionDeclSyntax ) -> UnsafeMutableRawPointer {
108
+ public func visit( _ node: FunctionDeclSyntax ) -> ASTNode {
116
109
let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
117
110
118
111
var nameText = node. identifier. text
119
112
let name = nameText. withUTF8 { buf in
120
113
return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
121
114
}
122
115
123
- let body : UnsafeMutableRawPointer ?
116
+ let body : ASTNode ?
124
117
if let nodeBody = node. body {
125
118
body = visit ( nodeBody)
126
119
} else {
127
120
body = nil
128
121
}
129
122
130
- let returnType : UnsafeMutableRawPointer ?
123
+ let returnType : ASTNode ?
131
124
if let output = node. signature. output {
132
125
returnType = visit ( output. returnType)
133
126
} else {
134
127
returnType = nil
135
128
}
136
129
137
130
let params = node. signature. input. parameterList. map { visit ( $0) }
138
- return params. withBridgedArrayRef { ref in
139
- FuncDecl_create ( ctx, loc, false , loc, name, loc, false , nil , false , nil , loc, ref, loc, body, returnType, declContext)
140
- }
131
+ return . decl ( params. withBridgedArrayRef { ref in
132
+ FuncDecl_create ( ctx, loc, false , loc, name, loc, false , nil , false , nil , loc, ref, loc, body? . rawValue , returnType? . rawValue , declContext)
133
+ } )
141
134
}
142
135
}
0 commit comments