@@ -22,6 +22,7 @@ extension ASTGenVisitor {
2222 var attributes : BridgedDeclAttributes
2323 var staticSpelling : BridgedStaticSpelling
2424 var staticLoc : BridgedSourceLoc
25+ var initContext : BridgedPatternBindingInitializer ?
2526 }
2627
2728 func generateDeclAttributes( _ node: some WithAttributesSyntax & WithModifiersSyntax , allowStatic: Bool ) -> DeclAttributesResult {
@@ -54,6 +55,7 @@ extension ASTGenVisitor {
5455 }
5556
5657 // '@' attributes.
58+ var initContext : BridgedPatternBindingInitializer ? = nil
5759 visitIfConfigElements ( node. attributes, of: AttributeSyntax . self) { element in
5860 switch element {
5961 case . ifConfigDecl( let ifConfigDecl) :
@@ -62,7 +64,7 @@ extension ASTGenVisitor {
6264 return . underlying( attribute)
6365 }
6466 } body: { attribute in
65- addAttribute ( self . generateDeclAttribute ( attribute: attribute) )
67+ addAttribute ( self . generateDeclAttribute ( attribute: attribute, initContext : & initContext ) )
6668 }
6769
6870 func genStatic( node: DeclModifierSyntax , spelling: BridgedStaticSpelling ) {
@@ -89,14 +91,15 @@ extension ASTGenVisitor {
8991 return DeclAttributesResult (
9092 attributes: attrs,
9193 staticSpelling: staticSpelling,
92- staticLoc: staticLoc
94+ staticLoc: staticLoc,
95+ initContext: initContext
9396 )
9497 }
9598}
9699
97100// MARK: - Decl attributes
98101extension ASTGenVisitor {
99- func generateDeclAttribute( attribute node: AttributeSyntax ) -> BridgedDeclAttribute ? {
102+ func generateDeclAttribute( attribute node: AttributeSyntax , initContext : inout BridgedPatternBindingInitializer ? ) -> BridgedDeclAttribute ? {
100103 if let identTy = node. attributeName. as ( IdentifierTypeSyntax . self) {
101104 let attrName = identTy. name. rawText
102105 let attrKind = BridgedDeclAttrKind ( from: attrName. bridged)
@@ -319,7 +322,7 @@ extension ASTGenVisitor {
319322 }
320323 }
321324
322- return self . generateCustomAttr ( attribute: node) ? . asDeclAttribute
325+ return self . generateCustomAttr ( attribute: node, initContext : & initContext ) ? . asDeclAttribute
323326 }
324327
325328 func generateAlignmentAttr( attribute node: AttributeSyntax ) -> BridgedAlignmentAttr ? {
@@ -1163,16 +1166,39 @@ extension ASTGenVisitor {
11631166 )
11641167 }
11651168
1166- func generateCustomAttr( attribute node: AttributeSyntax ) -> BridgedCustomAttr ? {
1167- guard
1168- let args = node. arguments? . as ( LabeledExprListSyntax . self) ? [ ... ]
1169- else {
1170- // TODO: Diagnose.
1171- return nil
1169+ func generateCustomAttr( attribute node: AttributeSyntax , initContext: inout BridgedPatternBindingInitializer ? ) -> BridgedCustomAttr ? {
1170+ let type = self . generate ( type: node. attributeName)
1171+
1172+ let argList : BridgedArgumentList ?
1173+ if let args = node. arguments {
1174+ guard let args = args. as ( LabeledExprListSyntax . self) else {
1175+ // TODO: Diagnose?
1176+ return nil
1177+ }
1178+
1179+ if !self . declContext. isLocalContext && initContext == nil {
1180+ initContext = BridgedPatternBindingInitializer . create ( declContext: self . declContext)
1181+ }
1182+ argList = withDeclContext ( initContext? . asDeclContext ?? self . declContext) {
1183+ self . generateArgumentList (
1184+ leftParen: node. leftParen,
1185+ labeledExprList: args,
1186+ rightParen: node. rightParen,
1187+ trailingClosure: nil ,
1188+ additionalTrailingClosures: nil
1189+ )
1190+ }
1191+ } else {
1192+ argList = nil
11721193 }
11731194
1174- _ = args
1175- fatalError ( " unimplemented " )
1195+ return . createParsed(
1196+ self . ctx,
1197+ atLoc: self . generateSourceLoc ( node. atSign) ,
1198+ type: type,
1199+ initContext: initContext. asNullable,
1200+ argumentList: argList. asNullable
1201+ )
11761202 }
11771203
11781204 func generateStringLiteralTextIfNotInterpolated( expr node: some ExprSyntaxProtocol ) -> BridgedStringRef ? {
0 commit comments