@@ -4,13 +4,13 @@ import SwiftSyntax
44
55extension ASTGenVisitor {
66 public func visit( _ node: TypealiasDeclSyntax ) -> ASTNode {
7- let aliasLoc = self . base . advanced ( by : node. typealiasKeyword. position . utf8Offset ) . raw
8- let equalLoc = self . base . advanced ( by : node. initializer. equal. position . utf8Offset ) . raw
7+ let aliasLoc = bridgedSourceLoc ( for : node. typealiasKeyword)
8+ let equalLoc = bridgedSourceLoc ( for : node. initializer. equal)
99 var nameText = node. identifier. text
10- let name = nameText. withUTF8 { buf in
11- return SwiftASTContext_getIdentifier ( ctx, buf . baseAddress , buf . count )
10+ let name = nameText. withBridgedString { bridgedName in
11+ return ASTContext_getIdentifier ( ctx, bridgedName )
1212 }
13- let nameLoc = self . base . advanced ( by : node. identifier. position . utf8Offset ) . raw
13+ let nameLoc = bridgedSourceLoc ( for : node. identifier)
1414 let genericParams = node. genericParameterClause. map { self . visit ( $0) . rawValue }
1515 let out = TypeAliasDecl_create (
1616 self . ctx, self . declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
@@ -26,10 +26,10 @@ extension ASTGenVisitor {
2626 }
2727
2828 public func visit( _ node: StructDeclSyntax ) -> ASTNode {
29- let loc = self . base . advanced ( by : node. position . utf8Offset ) . raw
29+ let loc = bridgedSourceLoc ( for : node)
3030 var nameText = node. identifier. text
31- let name = nameText. withUTF8 { buf in
32- return SwiftASTContext_getIdentifier ( ctx, buf . baseAddress , buf . count )
31+ let name = nameText. withBridgedString { bridgedName in
32+ return ASTContext_getIdentifier ( ctx, bridgedName )
3333 }
3434
3535 let genericParams = node. genericParameterClause
@@ -49,10 +49,10 @@ extension ASTGenVisitor {
4949 }
5050
5151 public func visit( _ node: ClassDeclSyntax ) -> ASTNode {
52- let loc = self . base . advanced ( by : node. position . utf8Offset ) . raw
52+ let loc = bridgedSourceLoc ( for : node)
5353 var nameText = node. identifier. text
54- let name = nameText. withUTF8 { buf in
55- return SwiftASTContext_getIdentifier ( ctx, buf . baseAddress , buf . count )
54+ let name = nameText. withBridgedString { bridgedName in
55+ return ASTContext_getIdentifier ( ctx, bridgedName )
5656 }
5757
5858 let out = ClassDecl_create ( ctx, loc, name, loc, declContext)
@@ -73,38 +73,38 @@ extension ASTGenVisitor {
7373 let pattern = visit ( node. bindings. first!. pattern) . rawValue
7474 let initializer = visit ( node. bindings. first!. initializer!) . rawValue
7575
76- let loc = self . base . advanced ( by : node. position . utf8Offset ) . raw
76+ let loc = bridgedSourceLoc ( for : node)
7777 let isStatic = false // TODO: compute this
7878 let isLet = node. bindingKeyword. tokenKind == . keyword( . let)
7979
8080 // TODO: don't drop "initializer" on the floor.
8181 return . decl(
82- SwiftVarDecl_create (
82+ VarDecl_create (
8383 ctx, pattern, initializer, loc, isStatic,
8484 isLet, declContext) )
8585 }
8686
8787 public func visit( _ node: FunctionParameterSyntax ) -> ASTNode {
88- let loc = self . base. advanced ( by: node. position. utf8Offset) . raw
88+ let loc = bridgedSourceLoc ( for: node)
89+
90+ let firstName : BridgedIdentifier
91+ let secondName : BridgedIdentifier
8992
90- let firstName : UnsafeMutableRawPointer ?
91- let secondName : UnsafeMutableRawPointer ?
92-
9393 let nodeFirstName = node. firstName
9494 if nodeFirstName. text != " _ " {
9595 // Swift AST represents "_" as nil.
9696 var text = nodeFirstName. text
97- firstName = text. withUTF8 { buf in
98- SwiftASTContext_getIdentifier ( ctx, buf . baseAddress , buf . count )
97+ firstName = text. withBridgedString { bridgedName in
98+ ASTContext_getIdentifier ( ctx, bridgedName )
9999 }
100100 } else {
101101 firstName = nil
102102 }
103103
104104 if let nodeSecondName = node. secondName {
105105 var text = nodeSecondName. text
106- secondName = text. withUTF8 { buf in
107- SwiftASTContext_getIdentifier ( ctx, buf . baseAddress , buf . count )
106+ secondName = text. withBridgedString { bridgedName in
107+ ASTContext_getIdentifier ( ctx, bridgedName )
108108 }
109109 } else {
110110 secondName = nil
@@ -116,15 +116,15 @@ extension ASTGenVisitor {
116116 }
117117
118118 public func visit( _ node: FunctionDeclSyntax ) -> ASTNode {
119- let staticLoc = self . base . advanced ( by : node. position . utf8Offset ) . raw
120- let funcLoc = self . base . advanced ( by : node. funcKeyword. position . utf8Offset ) . raw
121- let nameLoc = self . base . advanced ( by : node. identifier. position . utf8Offset ) . raw
122- let rParamLoc = self . base . advanced ( by : node. signature. input. leftParen. position . utf8Offset ) . raw
123- let lParamLoc = self . base . advanced ( by : node. signature. input. rightParen. position . utf8Offset ) . raw
119+ let staticLoc = bridgedSourceLoc ( for : node)
120+ let funcLoc = bridgedSourceLoc ( for : node. funcKeyword)
121+ let nameLoc = bridgedSourceLoc ( for : node. identifier)
122+ let rParamLoc = bridgedSourceLoc ( for : node. signature. input. leftParen)
123+ let lParamLoc = bridgedSourceLoc ( for : node. signature. input. rightParen)
124124
125125 var nameText = node. identifier. text
126- let name = nameText. withUTF8 { buf in
127- return SwiftASTContext_getIdentifier ( ctx, buf . baseAddress , buf . count )
126+ let name = nameText. withBridgedString { bridgedName in
127+ return ASTContext_getIdentifier ( ctx, bridgedName )
128128 }
129129
130130 let returnType : ASTNode ?
0 commit comments