Skip to content

Commit dab15c3

Browse files
committed
Sync source file changes in CodeGeneration
1 parent e877a73 commit dab15c3

File tree

3 files changed

+95
-86
lines changed

3 files changed

+95
-86
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeKinds.swift

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,57 @@ public let DECL_ATTR_KINDS: [Attribute] = [
676676
///
677677
/// If you're adding a new kind of attribute that is spelled with a leading
678678
/// '@' symbol, add an entry to the `DECL_ATTR_KINDS` array instead.
679-
public let DECL_MODIFIER_KINDS: [Attribute] = [
680-
// These are not really attributes or modifiers in the C++ AST and they are
681-
// serialized directly into the ASTs they are attached to rather than using
682-
// the generic attribute serialization infrastructure.
679+
680+
// These are not really attributes or modifiers in the C++ AST and they are
681+
// serialized directly into the ASTs they are attached to rather than using
682+
// the generic attribute serialization infrastructure.
683+
public let DECL_MODIFIER_KINDS: [Attribute] = CONTEXTUAL_DECL_MODIFIER_KINDS + NONCONTEXTUAL_DECL_MODIFIER_KINDS
684+
685+
// Modifiers that not exclusively used for declarations
686+
public let CONTEXTUAL_DECL_MODIFIER_KINDS: [Attribute] = [
687+
ContextualDeclAttribute(
688+
name: "weak",
689+
className: "ReferenceOwnership"
690+
),
691+
ContextualDeclAttributeAlias(
692+
name: "unowned",
693+
className: "ReferenceOwnership",
694+
swiftName: "unowned"
695+
),
696+
SimpleDeclAttribute(
697+
name: "rethrows",
698+
className: "Rethrows",
699+
swiftName: "`rethrows`"
700+
),
701+
ContextualSimpleDeclAttribute(
702+
name: "isolated",
703+
className: "Isolated"
704+
),
705+
ContextualSimpleDeclAttribute(
706+
name: "async",
707+
className: "Async"
708+
),
709+
SimpleDeclAttribute(
710+
name: "reasync",
711+
className: "Reasync",
712+
swiftName: "reasync"
713+
),
714+
ContextualSimpleDeclAttribute(
715+
name: "consuming",
716+
className: "Consuming"
717+
),
718+
ContextualSimpleDeclAttribute(
719+
name: "borrowing",
720+
className: "Borrowing"
721+
),
722+
ContextualSimpleDeclAttribute(
723+
name: "_const",
724+
className: "CompileTimeConst"
725+
),
726+
]
727+
728+
// Modifiers that exclusively used for declarations
729+
public let NONCONTEXTUAL_DECL_MODIFIER_KINDS: [Attribute] = [
683730
BuiltinDeclModifier(
684731
name: "static",
685732
swiftName: "`static`"
@@ -775,37 +822,10 @@ public let DECL_MODIFIER_KINDS: [Attribute] = [
775822
className: "SetterAccess",
776823
swiftName: "__setter_access"
777824
),
778-
ContextualDeclAttribute(
779-
name: "weak",
780-
className: "ReferenceOwnership"
781-
),
782-
ContextualDeclAttributeAlias(
783-
name: "unowned",
784-
className: "ReferenceOwnership",
785-
swiftName: "unowned"
786-
),
787-
SimpleDeclAttribute(
788-
name: "rethrows",
789-
className: "Rethrows",
790-
swiftName: "`rethrows`"
791-
),
792825
ContextualSimpleDeclAttribute(
793826
name: "indirect",
794827
className: "Indirect"
795828
),
796-
ContextualSimpleDeclAttribute(
797-
name: "isolated",
798-
className: "Isolated"
799-
),
800-
ContextualSimpleDeclAttribute(
801-
name: "async",
802-
className: "Async"
803-
),
804-
SimpleDeclAttribute(
805-
name: "reasync",
806-
className: "Reasync",
807-
swiftName: "reasync"
808-
),
809829
ContextualSimpleDeclAttribute(
810830
name: "nonisolated",
811831
className: "Nonisolated"
@@ -814,22 +834,10 @@ public let DECL_MODIFIER_KINDS: [Attribute] = [
814834
name: "distributed",
815835
className: "DistributedActor"
816836
),
817-
ContextualSimpleDeclAttribute(
818-
name: "_const",
819-
className: "CompileTimeConst"
820-
),
821837
ContextualSimpleDeclAttribute(
822838
name: "_local",
823839
className: "KnownToBeLocal"
824840
),
825-
ContextualSimpleDeclAttribute(
826-
name: "consuming",
827-
className: "Consuming"
828-
),
829-
ContextualSimpleDeclAttribute(
830-
name: "borrowing",
831-
className: "Borrowing"
832-
),
833841
]
834842

835843
public let DEPRECATED_MODIFIER_KINDS: [Attribute] = [

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/DeclarationModifierFile.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ let declarationModifierFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3838

3939
try VariableDeclSyntax("var spec: TokenSpec") {
4040
try SwitchExprSyntax("switch self") {
41-
for attribute in DECL_MODIFIER_KINDS {
41+
for attribute in NONCONTEXTUAL_DECL_MODIFIER_KINDS {
42+
SwitchCaseSyntax("case .\(raw: attribute.swiftName):") {
43+
StmtSyntax("return .keyword(.\(raw: attribute.swiftName))")
44+
}
45+
}
46+
for attribute in CONTEXTUAL_DECL_MODIFIER_KINDS {
4247
SwitchCaseSyntax("case .\(raw: attribute.swiftName):") {
43-
if attribute.swiftName.hasSuffix("Keyword") {
44-
StmtSyntax("return .\(raw: attribute.swiftName)")
45-
} else {
46-
StmtSyntax("return .keyword(.\(raw: attribute.swiftName))")
47-
}
48+
StmtSyntax("return TokenSpec(.\(raw: attribute.swiftName), recoveryPrecedence: .declKeyword)")
4849
}
4950
}
5051
}

Sources/SwiftParser/generated/DeclarationModifier.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
@_spi(RawSyntax) import SwiftSyntax
1616

1717
enum DeclarationModifier: TokenSpecSet {
18+
case weak
19+
case unowned
20+
case `rethrows`
21+
case isolated
22+
case async
23+
case reasync
24+
case consuming
25+
case borrowing
26+
case _const
1827
case `static`
1928
case `class`
2029
case final
@@ -37,22 +46,31 @@ enum DeclarationModifier: TokenSpecSet {
3746
case package
3847
case open
3948
case __setter_access
40-
case weak
41-
case unowned
42-
case `rethrows`
4349
case indirect
44-
case isolated
45-
case async
46-
case reasync
4750
case nonisolated
4851
case distributed
49-
case _const
5052
case _local
51-
case consuming
52-
case borrowing
5353

5454
init?(lexeme: Lexer.Lexeme) {
5555
switch PrepareForKeywordMatch(lexeme) {
56+
case TokenSpec(.weak):
57+
self = .weak
58+
case TokenSpec(.unowned):
59+
self = .unowned
60+
case TokenSpec(.`rethrows`):
61+
self = .`rethrows`
62+
case TokenSpec(.isolated):
63+
self = .isolated
64+
case TokenSpec(.async):
65+
self = .async
66+
case TokenSpec(.reasync):
67+
self = .reasync
68+
case TokenSpec(.consuming):
69+
self = .consuming
70+
case TokenSpec(.borrowing):
71+
self = .borrowing
72+
case TokenSpec(._const):
73+
self = ._const
5674
case TokenSpec(.`static`):
5775
self = .`static`
5876
case TokenSpec(.`class`):
@@ -97,32 +115,14 @@ enum DeclarationModifier: TokenSpecSet {
97115
self = .open
98116
case TokenSpec(.__setter_access):
99117
self = .__setter_access
100-
case TokenSpec(.weak):
101-
self = .weak
102-
case TokenSpec(.unowned):
103-
self = .unowned
104-
case TokenSpec(.`rethrows`):
105-
self = .`rethrows`
106118
case TokenSpec(.indirect):
107119
self = .indirect
108-
case TokenSpec(.isolated):
109-
self = .isolated
110-
case TokenSpec(.async):
111-
self = .async
112-
case TokenSpec(.reasync):
113-
self = .reasync
114120
case TokenSpec(.nonisolated):
115121
self = .nonisolated
116122
case TokenSpec(.distributed):
117123
self = .distributed
118-
case TokenSpec(._const):
119-
self = ._const
120124
case TokenSpec(._local):
121125
self = ._local
122-
case TokenSpec(.consuming):
123-
self = .consuming
124-
case TokenSpec(.borrowing):
125-
self = .borrowing
126126
default:
127127
return nil
128128
}
@@ -174,32 +174,32 @@ enum DeclarationModifier: TokenSpecSet {
174174
return .keyword(.open)
175175
case .__setter_access:
176176
return .keyword(.__setter_access)
177+
case .indirect:
178+
return .keyword(.indirect)
179+
case .nonisolated:
180+
return .keyword(.nonisolated)
181+
case .distributed:
182+
return .keyword(.distributed)
183+
case ._local:
184+
return .keyword(._local)
177185
case .weak:
178186
return TokenSpec(.weak, recoveryPrecedence: .declKeyword)
179187
case .unowned:
180188
return TokenSpec(.unowned, recoveryPrecedence: .declKeyword)
181189
case .`rethrows`:
182190
return TokenSpec(.`rethrows`, recoveryPrecedence: .declKeyword)
183-
case .indirect:
184-
return .keyword(.indirect)
185191
case .isolated:
186192
return TokenSpec(.isolated, recoveryPrecedence: .declKeyword)
187193
case .async:
188194
return TokenSpec(.async, recoveryPrecedence: .declKeyword)
189195
case .reasync:
190196
return TokenSpec(.reasync, recoveryPrecedence: .declKeyword)
191-
case .nonisolated:
192-
return .keyword(.nonisolated)
193-
case .distributed:
194-
return .keyword(.distributed)
195-
case ._const:
196-
return TokenSpec(._const, recoveryPrecedence: .declKeyword)
197-
case ._local:
198-
return .keyword(._local)
199197
case .consuming:
200198
return TokenSpec(.consuming, recoveryPrecedence: .declKeyword)
201199
case .borrowing:
202200
return TokenSpec(.borrowing, recoveryPrecedence: .declKeyword)
201+
case ._const:
202+
return TokenSpec(._const, recoveryPrecedence: .declKeyword)
203203
}
204204
}
205205
}

0 commit comments

Comments
 (0)