1+ import CASTBridging
12import SwiftParser
23import SwiftSyntax
34
4- import CASTBridging
5-
65extension ASTGenVisitor {
76 public func visit( _ node: TypealiasDeclSyntax ) -> ASTNode {
87 let aliasLoc = self . base. advanced ( by: node. typealiasKeyword. position. utf8Offset) . raw
@@ -13,7 +12,8 @@ extension ASTGenVisitor {
1312 }
1413 let nameLoc = self . base. advanced ( by: node. identifier. position. utf8Offset) . raw
1514 let genericParams = node. genericParameterClause. map ( self . visit) . map { $0. rawValue }
16- let out = TypeAliasDecl_create ( self . ctx, self . declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
15+ let out = TypeAliasDecl_create (
16+ self . ctx, self . declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
1717
1818 let oldDeclContext = declContext
1919 declContext = out. declContext
@@ -43,10 +43,10 @@ extension ASTGenVisitor {
4343 node. members. members. map ( self . visit) . withBridgedArrayRef { ref in
4444 NominalTypeDecl_setMembers ( out. nominalDecl, ref)
4545 }
46-
46+
4747 return . decl( out. decl)
4848 }
49-
49+
5050 public func visit( _ node: ClassDeclSyntax ) -> ASTNode {
5151 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
5252 var nameText = node. identifier. text
@@ -62,16 +62,16 @@ extension ASTGenVisitor {
6262 node. members. members. map ( self . visit) . withBridgedArrayRef { ref in
6363 NominalTypeDecl_setMembers ( out. nominalDecl, ref)
6464 }
65-
65+
6666 return . decl( out. decl)
6767 }
68-
68+
6969 public func visit( _ node: VariableDeclSyntax ) -> ASTNode {
7070 let pattern = visit ( node. bindings. first!. pattern) . rawValue
7171 let initializer = visit ( node. bindings. first!. initializer!) . rawValue
72-
72+
7373 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
74- let isStateic = false // TODO: compute this
74+ let isStateic = false // TODO: compute this
7575 let isLet = node. letOrVarKeyword. tokenKind == . letKeyword
7676
7777 // TODO: don't drop "initializer" on the floor.
@@ -80,10 +80,10 @@ extension ASTGenVisitor {
8080
8181 public func visit( _ node: FunctionParameterSyntax ) -> ASTNode {
8282 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
83-
83+
8484 let firstName : UnsafeMutableRawPointer ?
8585 let secondName : UnsafeMutableRawPointer ?
86-
86+
8787 if let nodeFirstName = node. firstName {
8888 var text = nodeFirstName. text
8989 firstName = text. withUTF8 { buf in
@@ -92,7 +92,7 @@ extension ASTGenVisitor {
9292 } else {
9393 firstName = nil
9494 }
95-
95+
9696 if let nodeSecondName = node. secondName {
9797 var text = nodeSecondName. text
9898 secondName = text. withUTF8 { buf in
@@ -101,18 +101,18 @@ extension ASTGenVisitor {
101101 } else {
102102 secondName = nil
103103 }
104-
104+
105105 return . decl( ParamDecl_create ( ctx, loc, loc, firstName, loc, secondName, declContext) )
106106 }
107107
108108 public func visit( _ node: FunctionDeclSyntax ) -> ASTNode {
109109 let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
110-
110+
111111 var nameText = node. identifier. text
112112 let name = nameText. withUTF8 { buf in
113113 return SwiftASTContext_getIdentifier ( ctx, buf. baseAddress, buf. count)
114114 }
115-
115+
116116 let body : ASTNode ?
117117 if let nodeBody = node. body {
118118 body = visit ( nodeBody)
@@ -126,10 +126,13 @@ extension ASTGenVisitor {
126126 } else {
127127 returnType = nil
128128 }
129-
129+
130130 let params = node. signature. input. parameterList. map { visit ( $0) }
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- } )
131+ return . decl(
132+ params. withBridgedArrayRef { ref in
133+ FuncDecl_create (
134+ ctx, loc, false , loc, name, loc, false , nil , false , nil , loc, ref, loc, body? . rawValue,
135+ returnType? . rawValue, declContext)
136+ } )
134137 }
135138}
0 commit comments