13
13
import ASTBridging
14
14
import BasicBridging
15
15
import ParseBridging
16
+ import SwiftIfConfig
16
17
// Needed to use BumpPtrAllocator
17
18
@_spi ( BumpPtrAllocator) @_spi ( RawSyntax) import SwiftSyntax
18
19
@@ -76,7 +77,7 @@ struct ASTGenVisitor {
76
77
77
78
let ctx : BridgedASTContext
78
79
79
- let buildConfiguration : CompilerBuildConfiguration
80
+ let configuredRegions : ConfiguredRegions
80
81
81
82
fileprivate let allocator : SwiftSyntax . BumpPtrAllocator = . init( initialSlabSize: 256 )
82
83
@@ -89,17 +90,15 @@ struct ASTGenVisitor {
89
90
sourceBuffer: UnsafeBufferPointer < UInt8 > ,
90
91
declContext: BridgedDeclContext ,
91
92
astContext: BridgedASTContext ,
93
+ configuredRegions: ConfiguredRegions ,
92
94
legacyParser: BridgedLegacyParser
93
95
) {
94
96
self . diagnosticEngine = diagnosticEngine
95
97
self . base = sourceBuffer
96
98
self . declContext = declContext
97
99
self . ctx = astContext
100
+ self . configuredRegions = configuredRegions
98
101
self . legacyParse = legacyParser
99
- self . buildConfiguration = CompilerBuildConfiguration (
100
- ctx: ctx,
101
- sourceBuffer: sourceBuffer
102
- )
103
102
}
104
103
105
104
func generate( sourceFile node: SourceFileSyntax ) -> [ BridgedDecl ] {
@@ -423,31 +422,36 @@ extension TokenSyntax {
423
422
@_cdecl ( " swift_ASTGen_buildTopLevelASTNodes " )
424
423
public func buildTopLevelASTNodes(
425
424
diagEngine: BridgedDiagnosticEngine ,
426
- sourceFilePtr: UnsafeRawPointer ,
425
+ sourceFilePtr: UnsafeMutableRawPointer ,
427
426
dc: BridgedDeclContext ,
428
427
ctx: BridgedASTContext ,
429
428
legacyParser: BridgedLegacyParser ,
430
429
outputContext: UnsafeMutableRawPointer ,
431
430
callback: @convention ( c) ( UnsafeMutableRawPointer , UnsafeMutableRawPointer ) -> Void
432
431
) {
433
432
let sourceFile = sourceFilePtr. assumingMemoryBound ( to: ExportedSourceFile . self)
434
- ASTGenVisitor (
433
+ let visitor = ASTGenVisitor (
435
434
diagnosticEngine: diagEngine,
436
435
sourceBuffer: sourceFile. pointee. buffer,
437
436
declContext: dc,
438
437
astContext: ctx,
438
+ configuredRegions: sourceFile. pointee. configuredRegions ( astContext: ctx) ,
439
439
legacyParser: legacyParser
440
440
)
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)
443
447
}
444
448
445
449
/// Generate an AST node at the given source location. Returns the generated
446
450
/// ASTNode and mutate the pointee of `endLocPtr` to the end of the node.
447
451
private func _build< Node: SyntaxProtocol , Result> (
448
452
generator: ( ASTGenVisitor ) -> ( Node ) -> Result ,
449
453
diagEngine: BridgedDiagnosticEngine ,
450
- sourceFilePtr: UnsafeRawPointer ,
454
+ sourceFilePtr: UnsafeMutableRawPointer ,
451
455
sourceLoc: BridgedSourceLoc ,
452
456
declContext: BridgedDeclContext ,
453
457
astContext: BridgedASTContext ,
@@ -480,6 +484,7 @@ private func _build<Node: SyntaxProtocol, Result>(
480
484
sourceBuffer: sourceFile. pointee. buffer,
481
485
declContext: declContext,
482
486
astContext: astContext,
487
+ configuredRegions: sourceFile. pointee. configuredRegions ( astContext: astContext) ,
483
488
legacyParser: legacyParser
484
489
)
485
490
) ( node)
@@ -489,7 +494,7 @@ private func _build<Node: SyntaxProtocol, Result>(
489
494
@usableFromInline
490
495
func buildTypeRepr(
491
496
diagEngine: BridgedDiagnosticEngine ,
492
- sourceFilePtr: UnsafeRawPointer ,
497
+ sourceFilePtr: UnsafeMutableRawPointer ,
493
498
sourceLoc: BridgedSourceLoc ,
494
499
declContext: BridgedDeclContext ,
495
500
astContext: BridgedASTContext ,
@@ -512,7 +517,7 @@ func buildTypeRepr(
512
517
@usableFromInline
513
518
func buildDecl(
514
519
diagEngine: BridgedDiagnosticEngine ,
515
- sourceFilePtr: UnsafeRawPointer ,
520
+ sourceFilePtr: UnsafeMutableRawPointer ,
516
521
sourceLoc: BridgedSourceLoc ,
517
522
declContext: BridgedDeclContext ,
518
523
astContext: BridgedASTContext ,
@@ -535,7 +540,7 @@ func buildDecl(
535
540
@usableFromInline
536
541
func buildExpr(
537
542
diagEngine: BridgedDiagnosticEngine ,
538
- sourceFilePtr: UnsafeRawPointer ,
543
+ sourceFilePtr: UnsafeMutableRawPointer ,
539
544
sourceLoc: BridgedSourceLoc ,
540
545
declContext: BridgedDeclContext ,
541
546
astContext: BridgedASTContext ,
@@ -558,7 +563,7 @@ func buildExpr(
558
563
@usableFromInline
559
564
func buildStmt(
560
565
diagEngine: BridgedDiagnosticEngine ,
561
- sourceFilePtr: UnsafeRawPointer ,
566
+ sourceFilePtr: UnsafeMutableRawPointer ,
562
567
sourceLoc: BridgedSourceLoc ,
563
568
declContext: BridgedDeclContext ,
564
569
astContext: BridgedASTContext ,
0 commit comments