@@ -436,24 +436,25 @@ extension ASTGenVisitor {
436436 /// @_alignment(8)
437437 /// ```
438438 func generateAlignmentAttr( attribute node: AttributeSyntax ) -> BridgedAlignmentAttr ? {
439- guard
440- let arg = node. arguments? . as ( TokenSyntax . self)
441- else {
442- print ( " Not a token " )
443- // TODO: Diagnose.
444- return nil
445- }
446- let value : Int ? = Int ( String ( syntaxText: arg. rawText) )
447- guard let value, value > 0 else {
448- // TODO: Diagnose.
449- return nil
439+ self . generateWithLabeledExprListArguments ( attribute: node) { args in
440+ let value : Int ? = self . generateConsumingAttrOption ( args: & args, label: nil ) { expr in
441+ guard let intExpr = expr. as ( IntegerLiteralExprSyntax . self) else {
442+ return nil
443+ }
444+ return intExpr. representedLiteralValue
445+ }
446+ guard let value, value > 0 else {
447+ // TODO: Diagnose.
448+ return nil
449+ }
450+
451+ return . createParsed(
452+ self . ctx,
453+ atLoc: self . generateSourceLoc ( node. atSign) ,
454+ range: self . generateAttrSourceRange ( node) ,
455+ value: value
456+ )
450457 }
451- return . createParsed(
452- self . ctx,
453- atLoc: self . generateSourceLoc ( node. atSign) ,
454- range: self . generateAttrSourceRange ( node) ,
455- value: value
456- )
457458 }
458459
459460 /// E.g.:
@@ -557,25 +558,18 @@ extension ASTGenVisitor {
557558 /// @_cdecl("c_function_name")
558559 /// ```
559560 func generateCDeclAttr( attribute node: AttributeSyntax ) -> BridgedCDeclAttr ? {
560- guard
561- // `@_cdecl` attribute has `.string(StringLiteralExprSyntax)` arguments.
562- let arg = node. arguments? . as ( StringLiteralExprSyntax . self)
563- else {
564- // TODO: Diagnose.
565- return nil
566- }
567- guard
568- let name = self . generateStringLiteralTextIfNotInterpolated ( expr: arg)
569- else {
570- // TODO: Diagnose.
571- return nil
561+ self . generateWithLabeledExprListArguments ( attribute: node) { args in
562+ guard let name = self . generateConsumingSimpleStringLiteralAttrOption ( args: & args) else {
563+ return nil
564+ }
565+
566+ return . createParsed(
567+ self . ctx,
568+ atLoc: self . generateSourceLoc ( node. atSign) ,
569+ range: self . generateAttrSourceRange ( node) ,
570+ name: name
571+ )
572572 }
573- return . createParsed(
574- self . ctx,
575- atLoc: self . generateSourceLoc ( node. atSign) ,
576- range: self . generateAttrSourceRange ( node) ,
577- name: name
578- )
579573 }
580574
581575 struct GeneratedDerivativeOriginalDecl {
@@ -940,13 +934,21 @@ extension ASTGenVisitor {
940934 }
941935
942936 // Name.
943- let name = self . generateConsumingSimpleStringLiteralAttrOption ( args: & args) ?? " "
937+ let name : BridgedStringRef ?
938+ if !args. isEmpty {
939+ name = self . generateConsumingSimpleStringLiteralAttrOption ( args: & args) ?? " "
940+ guard name != nil else {
941+ return nil
942+ }
943+ } else {
944+ name = nil
945+ }
944946
945947 return . createParsed(
946948 self . ctx,
947949 atLoc: self . generateSourceLoc ( node. atSign) ,
948950 range: self . generateAttrSourceRange ( node) ,
949- name: name,
951+ name: name ?? BridgedStringRef ( ) ,
950952 kind: kind
951953 )
952954 }
@@ -1605,27 +1607,21 @@ extension ASTGenVisitor {
16051607 }
16061608
16071609 func generatePrivateImportAttr( attribute node: AttributeSyntax ) -> BridgedPrivateImportAttr ? {
1608- guard
1609- // `@_private` has special argument list syntax
1610- let args = node. arguments? . as ( UnderscorePrivateAttributeArgumentsSyntax . self)
1611- else {
1612- // TODO: Diagnose
1613- return nil
1614- }
1610+ self . generateWithLabeledExprListArguments ( attribute: node) { args in
1611+ let fileName = self . generateConsumingSimpleStringLiteralAttrOption ( args: & args, label: " sourceFile " )
1612+ guard let fileName else {
1613+ return nil
1614+ }
16151615
1616- guard let fileName = self . generateStringLiteralTextIfNotInterpolated ( expr: args. filename) else {
1617- // TODO: Diagnose
1618- return nil
1616+ return . createParsed(
1617+ self . ctx,
1618+ atLoc: self . generateSourceLoc ( node. atSign) ,
1619+ attrNameLoc: self . generateSourceLoc ( node. attributeName) ,
1620+ lParenLoc: self . generateSourceLoc ( node. leftParen) ,
1621+ fileName: fileName,
1622+ rParenLoc: self . generateSourceLoc ( node. rightParen)
1623+ )
16191624 }
1620-
1621- return . createParsed(
1622- self . ctx,
1623- atLoc: self . generateSourceLoc ( node. atSign) ,
1624- attrNameLoc: self . generateSourceLoc ( node. attributeName) ,
1625- lParenLoc: self . generateSourceLoc ( node. leftParen) ,
1626- fileName: fileName,
1627- rParenLoc: self . generateSourceLoc ( node. rightParen)
1628- )
16291625 }
16301626
16311627 /// E.g.:
@@ -1820,24 +1816,18 @@ extension ASTGenVisitor {
18201816 /// ```
18211817 /// @semantics("semantics_name")
18221818 func generateSemanticsAttr( attribute node: AttributeSyntax ) -> BridgedSemanticsAttr ? {
1823- guard
1824- let arg = node . arguments ? . as ( StringLiteralExprSyntax . self )
1825- else {
1826- // TODO: Diagnose.
1827- return nil
1828- }
1829- guard
1830- let value = self . generateStringLiteralTextIfNotInterpolated ( expr : arg )
1831- else {
1832- // TODO: Diagnose.
1833- return nil
1819+ self . generateWithLabeledExprListArguments ( attribute : node ) { args in
1820+ guard let value = self . generateConsumingSimpleStringLiteralAttrOption ( args : & args ) else {
1821+ return nil
1822+ }
1823+
1824+ return . createParsed (
1825+ self . ctx ,
1826+ atLoc : self . generateSourceLoc ( node . atSign ) ,
1827+ range : self . generateAttrSourceRange ( node ) ,
1828+ value : value
1829+ )
18341830 }
1835- return . createParsed(
1836- self . ctx,
1837- atLoc: self . generateSourceLoc ( node. atSign) ,
1838- range: self . generateAttrSourceRange ( node) ,
1839- value: value
1840- )
18411831 }
18421832
18431833 /// E.g.:
@@ -2160,15 +2150,15 @@ extension ASTGenVisitor {
21602150 /// @_unavailableFromAsync(message: "use fooBar(_:) instead")
21612151 /// ```
21622152 func generateUnavailableFromAsyncAttr( attribute node: AttributeSyntax ) -> BridgedUnavailableFromAsyncAttr ? {
2153+
21632154 var message : BridgedStringRef ? = nil
21642155 if node. arguments != nil {
2165- // FIXME: Should be normal LabeledExprListSyntax arguments.
2166-
2167- guard let args = node . arguments ? . as ( UnavailableFromAsyncAttributeArgumentsSyntax . self ) else {
2168- // TODO: Diagnose.
2156+ message = self . generateWithLabeledExprListArguments ( attribute : node ) { args in
2157+ self . generateConsumingSimpleStringLiteralAttrOption ( args : & args , label : " message " )
2158+ }
2159+ guard message != nil else {
21692160 return nil
21702161 }
2171- message = self . generateStringLiteralTextIfNotInterpolated ( expr: args. message)
21722162 }
21732163 return . createParsed(
21742164 self . ctx,
@@ -2309,14 +2299,13 @@ extension ASTGenVisitor {
23092299 _ valueGeneratorFunction: ( TokenSyntax ) -> R ?
23102300 ) -> R ? {
23112301 return generateConsumingAttrOption ( args: & args, label: nil ) {
2312- guard
2313- let declRefExpr = $0. as ( DeclReferenceExprSyntax . self) ,
2314- declRefExpr. argumentNames == nil
2315- else {
2316- // TODO: Diagnose.
2317- return nil
2302+ if let declRefExpr = $0. as ( DeclReferenceExprSyntax . self) , declRefExpr. argumentNames == nil {
2303+ return valueGeneratorFunction ( declRefExpr. baseName)
2304+ } else if let discardExpr = $0. as ( DiscardAssignmentExprSyntax . self) {
2305+ return valueGeneratorFunction ( discardExpr. wildcard)
23182306 }
2319- return valueGeneratorFunction ( declRefExpr. baseName)
2307+ // TODO: Diagnose.
2308+ return nil
23202309 }
23212310 }
23222311
@@ -2341,19 +2330,14 @@ extension ASTGenVisitor {
23412330 _ valueGeneratorFunction: ( TokenSyntax ) -> Result ? ,
23422331 valueIfOmitted: Result ? = nil
23432332 ) -> Result ? {
2344- guard node. leftParen != nil , let arguments = node . arguments else {
2333+ guard node. arguments != nil else {
23452334 if let valueIfOmitted {
23462335 return valueIfOmitted
23472336 }
23482337 self . diagnose ( . expectedArgumentsInAttribute( node) )
23492338 return nil
23502339 }
23512340
2352- if case . token( let tok) = arguments {
2353- // Special case: was parsed as a token, not an an argument list
2354- return valueGeneratorFunction ( tok)
2355- }
2356-
23572341 return self . generateWithLabeledExprListArguments ( attribute: node) { args in
23582342 self . generateConsumingPlainIdentifierAttrOption (
23592343 args: & args,
0 commit comments