@@ -70,19 +70,6 @@ enum ASTNode {
70
70
fatalError ( " Must be expr, stmt, or decl. " )
71
71
}
72
72
}
73
-
74
- var raw : UnsafeMutableRawPointer {
75
- switch self {
76
- case . expr( let e) :
77
- return e. raw
78
- case . stmt( let s) :
79
- return s. raw
80
- case . decl( let d) :
81
- return d. raw
82
- case . type( let t) :
83
- return t. raw
84
- }
85
- }
86
73
}
87
74
88
75
/// Little utility wrapper that lets us have some mutable state within
@@ -428,16 +415,16 @@ public func buildTopLevelASTNodes(
428
415
429
416
/// Generate an AST node at the given source location. Returns the generated
430
417
/// ASTNode and mutate the pointee of `endLocPtr` to the end of the node.
431
- private func _build< Node: SyntaxProtocol > (
432
- kind : Node . Type ,
418
+ private func _build< Node: SyntaxProtocol , Result > (
419
+ generator : ( ASTGenVisitor ) -> ( Node ) -> Result ,
433
420
diagEngine: BridgedDiagnosticEngine ,
434
421
sourceFilePtr: UnsafeRawPointer ,
435
422
sourceLoc: BridgedSourceLoc ,
436
423
declContext: BridgedDeclContext ,
437
424
astContext: BridgedASTContext ,
438
425
legacyParser: BridgedLegacyParser ,
439
426
endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
440
- ) -> UnsafeMutableRawPointer ? {
427
+ ) -> Result ? {
441
428
let sourceFile = sourceFilePtr. assumingMemoryBound ( to: ExportedSourceFile . self)
442
429
443
430
// Find the type syntax node.
@@ -458,13 +445,13 @@ private func _build<Node: SyntaxProtocol>(
458
445
endLocPtr. pointee = sourceLoc. advanced ( by: node. totalLength. utf8Length)
459
446
460
447
// Convert the syntax node.
461
- return ASTGenVisitor (
448
+ return generator ( ASTGenVisitor (
462
449
diagnosticEngine: diagEngine,
463
450
sourceBuffer: sourceFile. pointee. buffer,
464
451
declContext: declContext,
465
452
astContext: astContext,
466
453
legacyParser: legacyParser
467
- ) . generate ( Syntax ( node) ) . raw
454
+ ) ) ( node)
468
455
}
469
456
470
457
@_cdecl ( " swift_ASTGen_buildTypeRepr " )
@@ -479,15 +466,15 @@ func buildTypeRepr(
479
466
endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
480
467
) -> UnsafeMutableRawPointer ? {
481
468
return _build (
482
- kind : TypeSyntax . self ,
469
+ generator : ASTGenVisitor . generate ( type : ) ,
483
470
diagEngine: diagEngine,
484
471
sourceFilePtr: sourceFilePtr,
485
472
sourceLoc: sourceLoc,
486
473
declContext: declContext,
487
474
astContext: astContext,
488
475
legacyParser: legacyParser,
489
476
endLocPtr: endLocPtr
490
- )
477
+ ) ? . raw
491
478
}
492
479
493
480
@_cdecl ( " swift_ASTGen_buildDecl " )
@@ -502,15 +489,15 @@ func buildDecl(
502
489
endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
503
490
) -> UnsafeMutableRawPointer ? {
504
491
return _build (
505
- kind : DeclSyntax . self ,
492
+ generator : ASTGenVisitor . generate ( decl : ) ,
506
493
diagEngine: diagEngine,
507
494
sourceFilePtr: sourceFilePtr,
508
495
sourceLoc: sourceLoc,
509
496
declContext: declContext,
510
497
astContext: astContext,
511
498
legacyParser: legacyParser,
512
499
endLocPtr: endLocPtr
513
- )
500
+ ) ? . raw
514
501
}
515
502
516
503
@_cdecl ( " swift_ASTGen_buildExpr " )
@@ -525,15 +512,15 @@ func buildExpr(
525
512
endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
526
513
) -> UnsafeMutableRawPointer ? {
527
514
return _build (
528
- kind : ExprSyntax . self ,
515
+ generator : ASTGenVisitor . generate ( expr : ) ,
529
516
diagEngine: diagEngine,
530
517
sourceFilePtr: sourceFilePtr,
531
518
sourceLoc: sourceLoc,
532
519
declContext: declContext,
533
520
astContext: astContext,
534
521
legacyParser: legacyParser,
535
522
endLocPtr: endLocPtr
536
- )
523
+ ) ? . raw
537
524
}
538
525
539
526
@_cdecl ( " swift_ASTGen_buildStmt " )
@@ -548,13 +535,13 @@ func buildStmt(
548
535
endLocPtr: UnsafeMutablePointer < BridgedSourceLoc >
549
536
) -> UnsafeMutableRawPointer ? {
550
537
return _build (
551
- kind : StmtSyntax . self ,
538
+ generator : ASTGenVisitor . generate ( stmt : ) ,
552
539
diagEngine: diagEngine,
553
540
sourceFilePtr: sourceFilePtr,
554
541
sourceLoc: sourceLoc,
555
542
declContext: declContext,
556
543
astContext: astContext,
557
544
legacyParser: legacyParser,
558
545
endLocPtr: endLocPtr
559
- )
546
+ ) ? . raw
560
547
}
0 commit comments