12
12
13
13
import ASTBridging
14
14
import BasicBridging
15
- import ParseBridging
16
15
import SwiftIfConfig
17
16
// Needed to use BumpPtrAllocator
18
17
@_spi ( BumpPtrAllocator) @_spi ( RawSyntax) import SwiftSyntax
@@ -81,24 +80,18 @@ struct ASTGenVisitor {
81
80
82
81
fileprivate let allocator : SwiftSyntax . BumpPtrAllocator = . init( initialSlabSize: 256 )
83
82
84
- /// Fallback legacy parser used when ASTGen doesn't have the generate(_:)
85
- /// implementation for the AST node kind.
86
- let legacyParse : BridgedLegacyParser
87
-
88
83
init (
89
84
diagnosticEngine: BridgedDiagnosticEngine ,
90
85
sourceBuffer: UnsafeBufferPointer < UInt8 > ,
91
86
declContext: BridgedDeclContext ,
92
87
astContext: BridgedASTContext ,
93
- configuredRegions: ConfiguredRegions ,
94
- legacyParser: BridgedLegacyParser
88
+ configuredRegions: ConfiguredRegions
95
89
) {
96
90
self . diagnosticEngine = diagnosticEngine
97
91
self . base = sourceBuffer
98
92
self . declContext = declContext
99
93
self . ctx = astContext
100
94
self . configuredRegions = configuredRegions
101
- self . legacyParse = legacyParser
102
95
}
103
96
104
97
func generate( sourceFile node: SourceFileSyntax ) -> [ ASTNode ] {
@@ -431,7 +424,6 @@ public func buildTopLevelASTNodes(
431
424
sourceFilePtr: UnsafeMutableRawPointer ,
432
425
dc: BridgedDeclContext ,
433
426
ctx: BridgedASTContext ,
434
- legacyParser: BridgedLegacyParser ,
435
427
outputContext: UnsafeMutableRawPointer ,
436
428
callback: @convention ( c) ( BridgedASTNode , UnsafeMutableRawPointer ) -> Void
437
429
) {
@@ -441,8 +433,7 @@ public func buildTopLevelASTNodes(
441
433
sourceBuffer: sourceFile. pointee. buffer,
442
434
declContext: dc,
443
435
astContext: ctx,
444
- configuredRegions: sourceFile. pointee. configuredRegions ( astContext: ctx) ,
445
- legacyParser: legacyParser
436
+ configuredRegions: sourceFile. pointee. configuredRegions ( astContext: ctx)
446
437
)
447
438
448
439
switch sourceFile. pointee. syntax. as ( SyntaxEnum . self) {
@@ -461,139 +452,3 @@ public func buildTopLevelASTNodes(
461
452
// Diagnose any errors from evaluating #ifs.
462
453
visitor. diagnoseAll ( visitor. configuredRegions. diagnostics)
463
454
}
464
-
465
- /// Generate an AST node at the given source location. Returns the generated
466
- /// ASTNode and mutate the pointee of `endLocPtr` to the end of the node.
467
- private func _build< Node: SyntaxProtocol , Result> (
468
- generator: ( ASTGenVisitor ) -> ( Node ) -> Result ? ,
469
- diagEngine: BridgedDiagnosticEngine ,
470
- sourceFilePtr: UnsafeMutableRawPointer ,
471
- sourceLoc: BridgedSourceLoc ,
472
- declContext: BridgedDeclContext ,
473
- astContext: BridgedASTContext ,
474
- legacyParser: BridgedLegacyParser ,
475
- endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
476
- ) -> Result ? {
477
- let sourceFile = sourceFilePtr. assumingMemoryBound ( to: ExportedSourceFile . self)
478
-
479
- // Find the type syntax node.
480
- guard
481
- let node = findSyntaxNodeInSourceFile (
482
- sourceFilePtr: sourceFilePtr,
483
- // FIXME: findSyntaxNodeInSourceFile should receive `BridgedSourceLoc`.
484
- sourceLocationPtr: sourceLoc. getOpaquePointerValue ( ) ? . assumingMemoryBound ( to: UInt8 . self) ,
485
- type: Node . self,
486
- wantOutermost: true
487
- )
488
- else {
489
- // FIXME: Produce an error
490
- return nil
491
- }
492
-
493
- // Fill in the end location.
494
- endLocPtr. pointee = sourceLoc. advanced ( by: node. totalLength. utf8Length)
495
-
496
- // Convert the syntax node.
497
- return generator (
498
- ASTGenVisitor (
499
- diagnosticEngine: diagEngine,
500
- sourceBuffer: sourceFile. pointee. buffer,
501
- declContext: declContext,
502
- astContext: astContext,
503
- configuredRegions: sourceFile. pointee. configuredRegions ( astContext: astContext) ,
504
- legacyParser: legacyParser
505
- )
506
- ) ( node)
507
- }
508
-
509
- @_cdecl ( " swift_ASTGen_buildTypeRepr " )
510
- @usableFromInline
511
- func buildTypeRepr(
512
- diagEngine: BridgedDiagnosticEngine ,
513
- sourceFilePtr: UnsafeMutableRawPointer ,
514
- sourceLoc: BridgedSourceLoc ,
515
- declContext: BridgedDeclContext ,
516
- astContext: BridgedASTContext ,
517
- legacyParser: BridgedLegacyParser ,
518
- endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
519
- ) -> UnsafeMutableRawPointer ? {
520
- return _build (
521
- generator: ASTGenVisitor . generate ( type: ) ,
522
- diagEngine: diagEngine,
523
- sourceFilePtr: sourceFilePtr,
524
- sourceLoc: sourceLoc,
525
- declContext: declContext,
526
- astContext: astContext,
527
- legacyParser: legacyParser,
528
- endLocPtr: endLocPtr
529
- ) ? . raw
530
- }
531
-
532
- @_cdecl ( " swift_ASTGen_buildDecl " )
533
- @usableFromInline
534
- func buildDecl(
535
- diagEngine: BridgedDiagnosticEngine ,
536
- sourceFilePtr: UnsafeMutableRawPointer ,
537
- sourceLoc: BridgedSourceLoc ,
538
- declContext: BridgedDeclContext ,
539
- astContext: BridgedASTContext ,
540
- legacyParser: BridgedLegacyParser ,
541
- endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
542
- ) -> UnsafeMutableRawPointer ? {
543
- return _build (
544
- generator: ASTGenVisitor . generate ( decl: ) ,
545
- diagEngine: diagEngine,
546
- sourceFilePtr: sourceFilePtr,
547
- sourceLoc: sourceLoc,
548
- declContext: declContext,
549
- astContext: astContext,
550
- legacyParser: legacyParser,
551
- endLocPtr: endLocPtr
552
- ) ? . raw
553
- }
554
-
555
- @_cdecl ( " swift_ASTGen_buildExpr " )
556
- @usableFromInline
557
- func buildExpr(
558
- diagEngine: BridgedDiagnosticEngine ,
559
- sourceFilePtr: UnsafeMutableRawPointer ,
560
- sourceLoc: BridgedSourceLoc ,
561
- declContext: BridgedDeclContext ,
562
- astContext: BridgedASTContext ,
563
- legacyParser: BridgedLegacyParser ,
564
- endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
565
- ) -> UnsafeMutableRawPointer ? {
566
- return _build (
567
- generator: ASTGenVisitor . generate ( expr: ) ,
568
- diagEngine: diagEngine,
569
- sourceFilePtr: sourceFilePtr,
570
- sourceLoc: sourceLoc,
571
- declContext: declContext,
572
- astContext: astContext,
573
- legacyParser: legacyParser,
574
- endLocPtr: endLocPtr
575
- ) ? . raw
576
- }
577
-
578
- @_cdecl ( " swift_ASTGen_buildStmt " )
579
- @usableFromInline
580
- func buildStmt(
581
- diagEngine: BridgedDiagnosticEngine ,
582
- sourceFilePtr: UnsafeMutableRawPointer ,
583
- sourceLoc: BridgedSourceLoc ,
584
- declContext: BridgedDeclContext ,
585
- astContext: BridgedASTContext ,
586
- legacyParser: BridgedLegacyParser ,
587
- endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
588
- ) -> UnsafeMutableRawPointer ? {
589
- return _build (
590
- generator: ASTGenVisitor . generate ( stmt: ) ,
591
- diagEngine: diagEngine,
592
- sourceFilePtr: sourceFilePtr,
593
- sourceLoc: sourceLoc,
594
- declContext: declContext,
595
- astContext: astContext,
596
- legacyParser: legacyParser,
597
- endLocPtr: endLocPtr
598
- ) ? . raw
599
- }
0 commit comments