@@ -46,16 +46,16 @@ func isExprMigrated(_ node: ExprSyntax) -> Bool {
4646 . discardAssignmentExpr, . declReferenceExpr, . dictionaryExpr, . doExpr,
4747 . editorPlaceholderExpr, . floatLiteralExpr, . forceUnwrapExpr, . functionCallExpr,
4848 . genericSpecializationExpr, . ifExpr, . infixOperatorExpr, . inOutExpr,
49- . integerLiteralExpr, . isExpr, . memberAccessExpr , . nilLiteralExpr , . optionalChainingExpr ,
50- . packElementExpr, . packExpansionExpr, . patternExpr, . postfixIfConfigExpr,
49+ . integerLiteralExpr, . isExpr, . macroExpansionExpr , . memberAccessExpr , . nilLiteralExpr ,
50+ . optionalChainingExpr , . packElementExpr, . packExpansionExpr, . patternExpr, . postfixIfConfigExpr,
5151 . postfixOperatorExpr, . prefixOperatorExpr, . regexLiteralExpr, . sequenceExpr,
5252 . simpleStringLiteralExpr, . subscriptCallExpr, . stringLiteralExpr, . superExpr,
5353 . switchExpr, . tryExpr, . tupleExpr, . typeExpr, . unresolvedAsExpr, . unresolvedIsExpr,
5454 . unresolvedTernaryExpr, . ternaryExpr:
5555 break
5656
5757 // Known unimplemented kinds.
58- case . keyPathExpr, . macroExpansionExpr :
58+ case . keyPathExpr:
5959 return false
6060
6161 // Unknown expr kinds.
@@ -131,8 +131,8 @@ extension ASTGenVisitor {
131131 preconditionFailure ( " IsExprSyntax only appear after operator folding " )
132132 case . keyPathExpr:
133133 break
134- case . macroExpansionExpr:
135- break
134+ case . macroExpansionExpr( let node ) :
135+ return self . generate ( macroExpansionExpr : node ) . asExpr
136136 case . memberAccessExpr( let node) :
137137 return self . generate ( memberAccessExpr: node)
138138 case . missingExpr:
@@ -535,6 +535,73 @@ extension ASTGenVisitor {
535535 )
536536 }
537537
538+ struct FreestandingMacroExpansionInfo {
539+ var poundLoc : BridgedSourceLoc
540+ var macroNameRef : BridgedDeclNameRef
541+ var macroNameLoc : BridgedDeclNameLoc
542+ var leftAngleLoc : BridgedSourceLoc
543+ var genericArgs : BridgedArrayRef
544+ var rightAngleLoc : BridgedSourceLoc
545+ var arguments : BridgedNullableArgumentList
546+ }
547+
548+ func generate( freestandingMacroExpansion node: some FreestandingMacroExpansionSyntax ) -> FreestandingMacroExpansionInfo {
549+ let poundLoc = self . generateSourceLoc ( node. pound)
550+ let nameLoc = self . generateIdentifierAndSourceLoc ( node. macroName)
551+
552+ let leftAngleLoc : BridgedSourceLoc
553+ let genericArgs : [ BridgedTypeRepr ]
554+ let rightAngleLoc : BridgedSourceLoc
555+ if let generics = node. genericArgumentClause {
556+ leftAngleLoc = self . generateSourceLoc ( generics. leftAngle)
557+ genericArgs = generics. arguments. map {
558+ self . generate ( type: $0. argument)
559+ }
560+ rightAngleLoc = self . generateSourceLoc ( generics. rightAngle)
561+ } else {
562+ leftAngleLoc = nil
563+ genericArgs = [ ]
564+ rightAngleLoc = nil
565+ }
566+
567+ let arguments : BridgedArgumentList ?
568+ if ( node. leftParen != nil || node. trailingClosure != nil ) {
569+ arguments = self . generateArgumentList (
570+ leftParen: node. leftParen,
571+ labeledExprList: node. arguments,
572+ rightParen: node. rightParen,
573+ trailingClosure: node. trailingClosure,
574+ additionalTrailingClosures: node. additionalTrailingClosures
575+ )
576+ } else {
577+ arguments = nil
578+ }
579+
580+ return FreestandingMacroExpansionInfo (
581+ poundLoc: poundLoc,
582+ macroNameRef: . createParsed( . createIdentifier( nameLoc. identifier) ) ,
583+ macroNameLoc: . createParsed( nameLoc. sourceLoc) ,
584+ leftAngleLoc: leftAngleLoc,
585+ genericArgs: genericArgs. lazy. bridgedArray ( in: self ) ,
586+ rightAngleLoc: rightAngleLoc,
587+ arguments: arguments. asNullable
588+ )
589+ }
590+
591+ func generate( macroExpansionExpr node: MacroExpansionExprSyntax ) -> BridgedMacroExpansionExpr {
592+ let info = self . generate ( freestandingMacroExpansion: node)
593+ return . createParsed(
594+ self . declContext,
595+ poundLoc: info. poundLoc,
596+ macroNameRef: info. macroNameRef,
597+ macroNameLoc: info. macroNameLoc,
598+ leftAngleLoc: info. leftAngleLoc,
599+ genericArgs: info. genericArgs,
600+ rightAngleLoc: info. rightAngleLoc,
601+ args: info. arguments
602+ )
603+ }
604+
538605 func generate( memberAccessExpr node: MemberAccessExprSyntax , postfixIfConfigBaseExpr: BridgedExpr ? = nil ) -> BridgedExpr {
539606 let baseExpr : BridgedExpr ?
540607 if let base = node. base {
0 commit comments