@@ -4,13 +4,13 @@ import SwiftSyntax
4
4
5
5
extension ASTGenVisitor {
6
6
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)
9
9
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 )
12
12
}
13
- let nameLoc = self . base . advanced ( by : node. identifier. position . utf8Offset ) . raw
13
+ let nameLoc = bridgedSourceLoc ( for : node. identifier)
14
14
let genericParams = node. genericParameterClause. map { self . visit ( $0) . rawValue }
15
15
let out = TypeAliasDecl_create (
16
16
self . ctx, self . declContext, aliasLoc, equalLoc, name, nameLoc, genericParams)
@@ -26,10 +26,10 @@ extension ASTGenVisitor {
26
26
}
27
27
28
28
public func visit( _ node: StructDeclSyntax ) -> ASTNode {
29
- let loc = self . base . advanced ( by : node. position . utf8Offset ) . raw
29
+ let loc = bridgedSourceLoc ( for : node)
30
30
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 )
33
33
}
34
34
35
35
let genericParams = node. genericParameterClause
@@ -49,10 +49,10 @@ extension ASTGenVisitor {
49
49
}
50
50
51
51
public func visit( _ node: ClassDeclSyntax ) -> ASTNode {
52
- let loc = self . base . advanced ( by : node. position . utf8Offset ) . raw
52
+ let loc = bridgedSourceLoc ( for : node)
53
53
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 )
56
56
}
57
57
58
58
let out = ClassDecl_create ( ctx, loc, name, loc, declContext)
@@ -73,38 +73,38 @@ extension ASTGenVisitor {
73
73
let pattern = visit ( node. bindings. first!. pattern) . rawValue
74
74
let initializer = visit ( node. bindings. first!. initializer!) . rawValue
75
75
76
- let loc = self . base . advanced ( by : node. position . utf8Offset ) . raw
76
+ let loc = bridgedSourceLoc ( for : node)
77
77
let isStatic = false // TODO: compute this
78
78
let isLet = node. bindingKeyword. tokenKind == . keyword( . let)
79
79
80
80
// TODO: don't drop "initializer" on the floor.
81
81
return . decl(
82
- SwiftVarDecl_create (
82
+ VarDecl_create (
83
83
ctx, pattern, initializer, loc, isStatic,
84
84
isLet, declContext) )
85
85
}
86
86
87
87
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
89
92
90
- let firstName : UnsafeMutableRawPointer ?
91
- let secondName : UnsafeMutableRawPointer ?
92
-
93
93
let nodeFirstName = node. firstName
94
94
if nodeFirstName. text != " _ " {
95
95
// Swift AST represents "_" as nil.
96
96
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 )
99
99
}
100
100
} else {
101
101
firstName = nil
102
102
}
103
103
104
104
if let nodeSecondName = node. secondName {
105
105
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 )
108
108
}
109
109
} else {
110
110
secondName = nil
@@ -116,15 +116,15 @@ extension ASTGenVisitor {
116
116
}
117
117
118
118
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)
124
124
125
125
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 )
128
128
}
129
129
130
130
let returnType : ASTNode ?
0 commit comments