@@ -437,25 +437,25 @@ extension ASTGenVisitor {
437
437
/// @_alignment(8)
438
438
/// ```
439
439
func generateAlignmentAttr( attribute node: AttributeSyntax ) -> BridgedAlignmentAttr ? {
440
- // FIXME: Should be LabeledExprListSyntax arguments.
441
- guard
442
- let arg = node. arguments? . as ( TokenSyntax . self)
443
- else {
444
- print ( " Not a token " )
445
- // TODO: Diagnose.
446
- return nil
447
- }
448
- let value : Int ? = Int ( String ( syntaxText: arg. rawText) )
449
- guard let value, value > 0 else {
450
- // TODO: Diagnose.
451
- return nil
440
+ self . generateWithLabeledExprListArguments ( attribute: node) { args in
441
+ let value : Int ? = self . generateConsumingAttrOption ( attribute: node, args: & args, label: nil ) { expr in
442
+ guard let intExpr = expr. as ( IntegerLiteralExprSyntax . self) else {
443
+ return nil
444
+ }
445
+ return intExpr. representedLiteralValue
446
+ }
447
+ guard let value, value > 0 else {
448
+ // TODO: Diagnose.
449
+ return nil
450
+ }
451
+
452
+ return . createParsed(
453
+ self . ctx,
454
+ atLoc: self . generateSourceLoc ( node. atSign) ,
455
+ range: self . generateAttrSourceRange ( node) ,
456
+ value: value
457
+ )
452
458
}
453
- return . createParsed(
454
- self . ctx,
455
- atLoc: self . generateSourceLoc ( node. atSign) ,
456
- range: self . generateAttrSourceRange ( node) ,
457
- value: value
458
- )
459
459
}
460
460
461
461
/// E.g.:
@@ -560,25 +560,18 @@ extension ASTGenVisitor {
560
560
/// @_cdecl("c_function_name")
561
561
/// ```
562
562
func generateCDeclAttr( attribute node: AttributeSyntax ) -> BridgedCDeclAttr ? {
563
- guard
564
- // `@_cdecl` attribute has `.string(StringLiteralExprSyntax)` arguments.
565
- let arg = node. arguments? . as ( StringLiteralExprSyntax . self)
566
- else {
567
- // TODO: Diagnose.
568
- return nil
569
- }
570
- guard
571
- let name = self . generateStringLiteralTextIfNotInterpolated ( expr: arg)
572
- else {
573
- // TODO: Diagnose.
574
- return nil
563
+ self . generateWithLabeledExprListArguments ( attribute: node) { args in
564
+ guard let name = self . generateConsumingSimpleStringLiteralAttrOption ( attribute: node, args: & args) else {
565
+ return nil
566
+ }
567
+
568
+ return . createParsed(
569
+ self . ctx,
570
+ atLoc: self . generateSourceLoc ( node. atSign) ,
571
+ range: self . generateAttrSourceRange ( node) ,
572
+ name: name
573
+ )
575
574
}
576
- return . createParsed(
577
- self . ctx,
578
- atLoc: self . generateSourceLoc ( node. atSign) ,
579
- range: self . generateAttrSourceRange ( node) ,
580
- name: name
581
- )
582
575
}
583
576
584
577
struct GeneratedDerivativeOriginalDecl {
@@ -943,14 +936,21 @@ extension ASTGenVisitor {
943
936
}
944
937
945
938
// Name.
946
- let name = self . generateConsumingSimpleStringLiteralAttrOption ( attribute: node, args: & args) ?? " "
947
- // TODO: Diagnose if nil.
939
+ let name : BridgedStringRef ?
940
+ if !args. isEmpty {
941
+ name = self . generateConsumingSimpleStringLiteralAttrOption ( attribute: node, args: & args) ?? " "
942
+ guard name != nil else {
943
+ return nil
944
+ }
945
+ } else {
946
+ name = nil
947
+ }
948
948
949
949
return . createParsed(
950
950
self . ctx,
951
951
atLoc: self . generateSourceLoc ( node. atSign) ,
952
952
range: self . generateAttrSourceRange ( node) ,
953
- name: name,
953
+ name: name ?? BridgedStringRef ( ) ,
954
954
kind: kind
955
955
)
956
956
}
@@ -1610,27 +1610,21 @@ extension ASTGenVisitor {
1610
1610
}
1611
1611
1612
1612
func generatePrivateImportAttr( attribute node: AttributeSyntax ) -> BridgedPrivateImportAttr ? {
1613
- guard
1614
- // `@_private` has special argument list syntax
1615
- let args = node. arguments? . as ( UnderscorePrivateAttributeArgumentsSyntax . self)
1616
- else {
1617
- // TODO: Diagnose
1618
- return nil
1619
- }
1613
+ self . generateWithLabeledExprListArguments ( attribute: node) { args in
1614
+ let fileName = self . generateConsumingSimpleStringLiteralAttrOption ( attribute: node, args: & args, label: " sourceFile " )
1615
+ guard let fileName else {
1616
+ return nil
1617
+ }
1620
1618
1621
- guard let fileName = self . generateStringLiteralTextIfNotInterpolated ( expr: args. filename) else {
1622
- // TODO: Diagnose
1623
- return nil
1619
+ return . createParsed(
1620
+ self . ctx,
1621
+ atLoc: self . generateSourceLoc ( node. atSign) ,
1622
+ attrNameLoc: self . generateSourceLoc ( node. attributeName) ,
1623
+ lParenLoc: self . generateSourceLoc ( node. leftParen) ,
1624
+ fileName: fileName,
1625
+ rParenLoc: self . generateSourceLoc ( node. rightParen)
1626
+ )
1624
1627
}
1625
-
1626
- return . createParsed(
1627
- self . ctx,
1628
- atLoc: self . generateSourceLoc ( node. atSign) ,
1629
- attrNameLoc: self . generateSourceLoc ( node. attributeName) ,
1630
- lParenLoc: self . generateSourceLoc ( node. leftParen) ,
1631
- fileName: fileName,
1632
- rParenLoc: self . generateSourceLoc ( node. rightParen)
1633
- )
1634
1628
}
1635
1629
1636
1630
/// E.g.:
@@ -1825,24 +1819,18 @@ extension ASTGenVisitor {
1825
1819
/// ```
1826
1820
/// @semantics("semantics_name")
1827
1821
func generateSemanticsAttr( attribute node: AttributeSyntax ) -> BridgedSemanticsAttr ? {
1828
- guard
1829
- let arg = node . arguments ? . as ( StringLiteralExprSyntax . self )
1830
- else {
1831
- // TODO: Diagnose.
1832
- return nil
1833
- }
1834
- guard
1835
- let value = self . generateStringLiteralTextIfNotInterpolated ( expr : arg )
1836
- else {
1837
- // TODO: Diagnose.
1838
- return nil
1822
+ self . generateWithLabeledExprListArguments ( attribute : node ) { args in
1823
+ guard let value = self . generateConsumingSimpleStringLiteralAttrOption ( attribute : node , args : & args ) else {
1824
+ return nil
1825
+ }
1826
+
1827
+ return . createParsed (
1828
+ self . ctx ,
1829
+ atLoc : self . generateSourceLoc ( node . atSign ) ,
1830
+ range : self . generateAttrSourceRange ( node ) ,
1831
+ value : value
1832
+ )
1839
1833
}
1840
- return . createParsed(
1841
- self . ctx,
1842
- atLoc: self . generateSourceLoc ( node. atSign) ,
1843
- range: self . generateAttrSourceRange ( node) ,
1844
- value: value
1845
- )
1846
1834
}
1847
1835
1848
1836
/// E.g.:
@@ -2166,20 +2154,15 @@ extension ASTGenVisitor {
2166
2154
/// @_unavailableFromAsync(message: "use fooBar(_:) instead")
2167
2155
/// ```
2168
2156
func generateUnavailableFromAsyncAttr( attribute node: AttributeSyntax ) -> BridgedUnavailableFromAsyncAttr ? {
2157
+
2169
2158
var message : BridgedStringRef ? = nil
2170
2159
if node. arguments != nil {
2171
- // FIXME: Should be normal LabeledExprListSyntax arguments.
2172
-
2173
- guard let args = node. arguments else {
2174
- self . diagnose ( . expectedArgumentsInAttribute( node) )
2175
- return nil
2160
+ message = self . generateWithLabeledExprListArguments ( attribute: node) { args in
2161
+ self . generateConsumingSimpleStringLiteralAttrOption ( attribute: node, args: & args, label: " message " )
2176
2162
}
2177
- guard let args = args. as ( UnavailableFromAsyncAttributeArgumentsSyntax . self) else {
2178
- self . diagnose ( . unexpectedArgumentsTypeInAttribute( node, arguments: args, expected: UnavailableFromAsyncAttributeArgumentsSyntax . self) )
2163
+ guard message != nil else {
2179
2164
return nil
2180
2165
}
2181
- message = self . generateStringLiteralTextIfNotInterpolated ( expr: args. message)
2182
- // TODO: Diagnose if nil.
2183
2166
}
2184
2167
return . createParsed(
2185
2168
self . ctx,
@@ -2338,14 +2321,13 @@ extension ASTGenVisitor {
2338
2321
_ valueGeneratorFunction: ( TokenSyntax ) -> R ?
2339
2322
) -> R ? {
2340
2323
return generateConsumingAttrOption ( attribute: attribute, args: & args, label: nil , example: example) {
2341
- guard
2342
- let declRefExpr = $0. as ( DeclReferenceExprSyntax . self) ,
2343
- declRefExpr. argumentNames == nil
2344
- else {
2345
- self . diagnose ( . expectedIdentifierOptionForAttribute( attribute, at: $0) )
2346
- return nil
2324
+ if let declRefExpr = $0. as ( DeclReferenceExprSyntax . self) , declRefExpr. argumentNames == nil {
2325
+ return valueGeneratorFunction ( declRefExpr. baseName)
2326
+ } else if let discardExpr = $0. as ( DiscardAssignmentExprSyntax . self) {
2327
+ return valueGeneratorFunction ( discardExpr. wildcard)
2347
2328
}
2348
- return valueGeneratorFunction ( declRefExpr. baseName)
2329
+ self . diagnose ( . expectedIdentifierOptionForAttribute( attribute, at: $0) )
2330
+ return nil
2349
2331
}
2350
2332
}
2351
2333
@@ -2372,19 +2354,14 @@ extension ASTGenVisitor {
2372
2354
_ valueGeneratorFunction: ( TokenSyntax ) -> Result ? ,
2373
2355
valueIfOmitted: Result ? = nil
2374
2356
) -> Result ? {
2375
- guard node. leftParen != nil , let arguments = node . arguments else {
2357
+ guard node. arguments != nil else {
2376
2358
if let valueIfOmitted {
2377
2359
return valueIfOmitted
2378
2360
}
2379
2361
self . diagnose ( . expectedArgumentsInAttribute( node) )
2380
2362
return nil
2381
2363
}
2382
2364
2383
- if case . token( let tok) = arguments {
2384
- // Special case: was parsed as a token, not an an argument list
2385
- return valueGeneratorFunction ( tok)
2386
- }
2387
-
2388
2365
return self . generateWithLabeledExprListArguments ( attribute: node) { args in
2389
2366
self . generateConsumingPlainIdentifierAttrOption (
2390
2367
attribute: node,
0 commit comments