1313import ASTBridging
1414import BasicBridging
1515import ParseBridging
16+ import SwiftIfConfig
1617// Needed to use BumpPtrAllocator
1718@_spi ( BumpPtrAllocator) @_spi ( RawSyntax) import SwiftSyntax
1819
@@ -76,7 +77,7 @@ struct ASTGenVisitor {
7677
7778 let ctx : BridgedASTContext
7879
79- let buildConfiguration : CompilerBuildConfiguration
80+ let configuredRegions : ConfiguredRegions
8081
8182 fileprivate let allocator : SwiftSyntax . BumpPtrAllocator = . init( initialSlabSize: 256 )
8283
@@ -89,17 +90,15 @@ struct ASTGenVisitor {
8990 sourceBuffer: UnsafeBufferPointer < UInt8 > ,
9091 declContext: BridgedDeclContext ,
9192 astContext: BridgedASTContext ,
93+ configuredRegions: ConfiguredRegions ,
9294 legacyParser: BridgedLegacyParser
9395 ) {
9496 self . diagnosticEngine = diagnosticEngine
9597 self . base = sourceBuffer
9698 self . declContext = declContext
9799 self . ctx = astContext
100+ self . configuredRegions = configuredRegions
98101 self . legacyParse = legacyParser
99- self . buildConfiguration = CompilerBuildConfiguration (
100- ctx: ctx,
101- sourceBuffer: sourceBuffer
102- )
103102 }
104103
105104 func generate( sourceFile node: SourceFileSyntax ) -> [ BridgedDecl ] {
@@ -423,31 +422,36 @@ extension TokenSyntax {
423422@_cdecl ( " swift_ASTGen_buildTopLevelASTNodes " )
424423public func buildTopLevelASTNodes(
425424 diagEngine: BridgedDiagnosticEngine ,
426- sourceFilePtr: UnsafeRawPointer ,
425+ sourceFilePtr: UnsafeMutableRawPointer ,
427426 dc: BridgedDeclContext ,
428427 ctx: BridgedASTContext ,
429428 legacyParser: BridgedLegacyParser ,
430429 outputContext: UnsafeMutableRawPointer ,
431430 callback: @convention ( c) ( UnsafeMutableRawPointer , UnsafeMutableRawPointer ) -> Void
432431) {
433432 let sourceFile = sourceFilePtr. assumingMemoryBound ( to: ExportedSourceFile . self)
434- ASTGenVisitor (
433+ let visitor = ASTGenVisitor (
435434 diagnosticEngine: diagEngine,
436435 sourceBuffer: sourceFile. pointee. buffer,
437436 declContext: dc,
438437 astContext: ctx,
438+ configuredRegions: sourceFile. pointee. configuredRegions ( astContext: ctx) ,
439439 legacyParser: legacyParser
440440 )
441- . generate ( sourceFile: sourceFile. pointee. syntax)
442- . forEach { callback ( $0. raw, outputContext) }
441+
442+ visitor. generate ( sourceFile: sourceFile. pointee. syntax)
443+ . forEach { callback ( $0. raw, outputContext) }
444+
445+ // Diagnose any errors from evaluating #ifs.
446+ visitor. diagnoseAll ( visitor. configuredRegions. diagnostics)
443447}
444448
445449/// Generate an AST node at the given source location. Returns the generated
446450/// ASTNode and mutate the pointee of `endLocPtr` to the end of the node.
447451private func _build< Node: SyntaxProtocol , Result> (
448452 generator: ( ASTGenVisitor ) -> ( Node ) -> Result ,
449453 diagEngine: BridgedDiagnosticEngine ,
450- sourceFilePtr: UnsafeRawPointer ,
454+ sourceFilePtr: UnsafeMutableRawPointer ,
451455 sourceLoc: BridgedSourceLoc ,
452456 declContext: BridgedDeclContext ,
453457 astContext: BridgedASTContext ,
@@ -480,6 +484,7 @@ private func _build<Node: SyntaxProtocol, Result>(
480484 sourceBuffer: sourceFile. pointee. buffer,
481485 declContext: declContext,
482486 astContext: astContext,
487+ configuredRegions: sourceFile. pointee. configuredRegions ( astContext: astContext) ,
483488 legacyParser: legacyParser
484489 )
485490 ) ( node)
@@ -489,7 +494,7 @@ private func _build<Node: SyntaxProtocol, Result>(
489494@usableFromInline
490495func buildTypeRepr(
491496 diagEngine: BridgedDiagnosticEngine ,
492- sourceFilePtr: UnsafeRawPointer ,
497+ sourceFilePtr: UnsafeMutableRawPointer ,
493498 sourceLoc: BridgedSourceLoc ,
494499 declContext: BridgedDeclContext ,
495500 astContext: BridgedASTContext ,
@@ -512,7 +517,7 @@ func buildTypeRepr(
512517@usableFromInline
513518func buildDecl(
514519 diagEngine: BridgedDiagnosticEngine ,
515- sourceFilePtr: UnsafeRawPointer ,
520+ sourceFilePtr: UnsafeMutableRawPointer ,
516521 sourceLoc: BridgedSourceLoc ,
517522 declContext: BridgedDeclContext ,
518523 astContext: BridgedASTContext ,
@@ -535,7 +540,7 @@ func buildDecl(
535540@usableFromInline
536541func buildExpr(
537542 diagEngine: BridgedDiagnosticEngine ,
538- sourceFilePtr: UnsafeRawPointer ,
543+ sourceFilePtr: UnsafeMutableRawPointer ,
539544 sourceLoc: BridgedSourceLoc ,
540545 declContext: BridgedDeclContext ,
541546 astContext: BridgedASTContext ,
@@ -558,7 +563,7 @@ func buildExpr(
558563@usableFromInline
559564func buildStmt(
560565 diagEngine: BridgedDiagnosticEngine ,
561- sourceFilePtr: UnsafeRawPointer ,
566+ sourceFilePtr: UnsafeMutableRawPointer ,
562567 sourceLoc: BridgedSourceLoc ,
563568 declContext: BridgedDeclContext ,
564569 astContext: BridgedASTContext ,
0 commit comments