1+ import CBasicBridging
2+ import CASTBridging
3+
14import SwiftDiagnostics
2- import SwiftParser
35import SwiftSyntax
46import SwiftParserDiagnostics
57
8+ @_spi ( ExperimentalLanguageFeatures)
9+ import SwiftParser
10+
611/// Describes a source file that has been "exported" to the C++ part of the
712/// compiler, with enough information to interface with the C++ layer.
813struct ExportedSourceFile {
@@ -20,15 +25,31 @@ struct ExportedSourceFile {
2025 let syntax : SourceFileSyntax
2126}
2227
28+ extension Parser . ExperimentalFeatures {
29+ init ( from context: BridgedASTContext ? ) {
30+ self = [ ]
31+ guard let context = context else { return }
32+
33+ func mapFeature( _ bridged: BridgedFeature , to feature: Self ) {
34+ if ASTContext_langOptsHasFeature ( context, bridged) {
35+ insert ( feature)
36+ }
37+ }
38+ }
39+ }
40+
2341/// Parses the given source file and produces a pointer to a new
2442/// ExportedSourceFile instance.
2543@_cdecl ( " swift_ASTGen_parseSourceFile " )
2644public func parseSourceFile(
2745 buffer: UnsafePointer < UInt8 > , bufferLength: Int ,
28- moduleName: UnsafePointer < UInt8 > , filename: UnsafePointer < UInt8 >
46+ moduleName: UnsafePointer < UInt8 > , filename: UnsafePointer < UInt8 > ,
47+ ctxPtr: UnsafeMutableRawPointer ?
2948) -> UnsafeRawPointer {
3049 let buffer = UnsafeBufferPointer ( start: buffer, count: bufferLength)
31- let sourceFile = Parser . parse ( source: buffer)
50+
51+ let ctx = ctxPtr. map { BridgedASTContext ( raw: $0) }
52+ let sourceFile = Parser . parse ( source: buffer, experimentalFeatures: . init( from: ctx) )
3253
3354 let exportedPtr = UnsafeMutablePointer< ExportedSourceFile> . allocate( capacity: 1 )
3455 exportedPtr. initialize (
0 commit comments