@@ -4,35 +4,37 @@ import SwiftSyntax
44import CASTBridging
55
66extension ASTGenVisitor {
7- public func visit( _ node: TypealiasDeclSyntax ) -> UnsafeMutableRawPointer {
7+ public func visit( _ node: TypealiasDeclSyntax ) -> ASTNode {
88 let aliasLoc = self . base. advanced ( by: node. typealiasKeyword. position. utf8Offset) . raw
99 let equalLoc = self . base. advanced ( by: node. initializer. equal. position. utf8Offset) . raw
1010 var nameText = node. identifier. text
1111 let name = nameText. withUTF8 { buf in
1212 return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
1313 }
1414 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 }
1616 let out = TypeAliasDecl_create ( self . ctx, self . declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
1717
1818 let oldDeclContext = declContext
1919 declContext = out. declContext
2020 defer { declContext = oldDeclContext }
2121
22- let underlying = self . visit ( node. initializer. value)
22+ let underlying = self . visit ( node. initializer. value) . rawValue
2323 TypeAliasDecl_setUnderlyingTypeRepr ( out. nominalDecl, underlying)
2424
25- return out. decl
25+ return . decl ( out. decl)
2626 }
2727
28- public func visit( _ node: StructDeclSyntax ) -> UnsafeMutableRawPointer {
28+ public func visit( _ node: StructDeclSyntax ) -> ASTNode {
2929 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
3030 var nameText = node. identifier. text
3131 let name = nameText. withUTF8 { buf in
3232 return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
3333 }
3434
35- let genericParams = node. genericParameterClause. map ( self . visit)
35+ let genericParams = node. genericParameterClause
36+ . map ( self . visit)
37+ . map { $0. rawValue }
3638 let out = StructDecl_create ( ctx, loc, name, loc, genericParams, declContext)
3739 let oldDeclContext = declContext
3840 declContext = out. declContext
@@ -42,10 +44,10 @@ extension ASTGenVisitor {
4244 NominalTypeDecl_setMembers ( out. nominalDecl, ref)
4345 }
4446
45- return out. decl
47+ return . decl ( out. decl)
4648 }
4749
48- public func visit( _ node: ClassDeclSyntax ) -> UnsafeMutableRawPointer {
50+ public func visit( _ node: ClassDeclSyntax ) -> ASTNode {
4951 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
5052 var nameText = node. identifier. text
5153 let name = nameText. withUTF8 { buf in
@@ -61,31 +63,22 @@ extension ASTGenVisitor {
6163 NominalTypeDecl_setMembers ( out. nominalDecl, ref)
6264 }
6365
64- return out. decl
66+ return . decl ( out. decl)
6567 }
6668
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
7072
7173 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
7274 let isStateic = false // TODO: compute this
7375 let isLet = node. letOrVarKeyword. tokenKind == . letKeyword
7476
7577 // 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) )
7779 }
7880
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 {
8982 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
9083
9184 let firstName : UnsafeMutableRawPointer ?
@@ -109,34 +102,34 @@ extension ASTGenVisitor {
109102 secondName = nil
110103 }
111104
112- return ParamDecl_create ( ctx, loc, loc, firstName, loc, secondName, declContext)
105+ return . decl ( ParamDecl_create ( ctx, loc, loc, firstName, loc, secondName, declContext) )
113106 }
114107
115- public func visit( _ node: FunctionDeclSyntax ) -> UnsafeMutableRawPointer {
108+ public func visit( _ node: FunctionDeclSyntax ) -> ASTNode {
116109 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
117110
118111 var nameText = node. identifier. text
119112 let name = nameText. withUTF8 { buf in
120113 return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
121114 }
122115
123- let body : UnsafeMutableRawPointer ?
116+ let body : ASTNode ?
124117 if let nodeBody = node. body {
125118 body = visit ( nodeBody)
126119 } else {
127120 body = nil
128121 }
129122
130- let returnType : UnsafeMutableRawPointer ?
123+ let returnType : ASTNode ?
131124 if let output = node. signature. output {
132125 returnType = visit ( output. returnType)
133126 } else {
134127 returnType = nil
135128 }
136129
137130 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+ } )
141134 }
142135}
0 commit comments