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