Skip to content

Commit f516223

Browse files
committed
[ASTGen] Do a little property-wrapper dance to move DeclContext into the visitor
1 parent 8d7f4df commit f516223

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/ASTGen/Sources/ASTGen/ASTGen.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ extension UnsafePointer {
1717
}
1818
}
1919

20-
// TODO: :(
21-
var declContext: UnsafeMutableRawPointer! = nil
20+
/// Little utility wrapper that lets us
21+
@propertyWrapper
22+
class Boxed<Value> {
23+
var wrappedValue: Value
24+
25+
init(wrappedValue: Value) {
26+
self.wrappedValue = wrappedValue
27+
}
28+
}
2229

2330
struct ASTGenVisitor: SyntaxTransformVisitor {
2431
let ctx: UnsafeMutableRawPointer
2532
let base: UnsafePointer<CChar>
2633

27-
// TOOD: we need to be up updating this.
28-
// var declContext: UnsafeMutableRawPointer
34+
@Boxed var declContext: UnsafeMutableRawPointer
2935

3036
// TODO: this some how messes up the witness table when I uncomment it locally :/
3137
// public func visit<T>(_ node: T?) -> [UnsafeMutableRawPointer]? {
@@ -70,8 +76,7 @@ public func parseTopLevelSwift(
7076
callback: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void
7177
) {
7278
let syntax = try! Parser.parse(source: String(cString: buffer))
73-
declContext = dc
74-
ASTGenVisitor(ctx: ctx, base: buffer)
79+
ASTGenVisitor(ctx: ctx, base: buffer, declContext: dc)
7580
.visit(syntax)
7681
.forEach { callback($0, outputContext) }
7782
}

0 commit comments

Comments
 (0)