Skip to content

Commit c1221ab

Browse files
committed
Add dedicated node for @_originallyDefinedIn arguments
This moves @_originallyDEfinedIn away from using TokenList for its arguments.
1 parent 8c66cd6 commit c1221ab

File tree

23 files changed

+968
-231
lines changed

23 files changed

+968
-231
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public let ATTRIBUTE_NODES: [Node] = [
113113
kind: "OpaqueReturnTypeOfAttributeArguments"),
114114
Child(name: "ExposeAttributeArguments",
115115
kind: "ExposeAttributeArguments"),
116+
Child(name: "OriginallyDefinedInArguments",
117+
kind: "OriginallyDefinedInArguments"),
116118
Child(name: "TokenList",
117119
kind: "TokenList",
118120
collectionElementName: "Token")
@@ -564,19 +566,19 @@ public let ATTRIBUTE_NODES: [Node] = [
564566
"Colon"
565567
]),
566568
Child(name: "VersionList",
567-
kind: "BackDeployVersionList",
569+
kind: "AvailabilityVersionRestrictionList",
568570
description: "The list of OS versions in which the declaration became ABIstable.",
569571
collectionElementName: "Availability")
570572
]),
571573

572-
Node(name: "BackDeployVersionList",
574+
Node(name: "AvailabilityVersionRestrictionList",
573575
nameForDiagnostics: "version list",
574576
kind: "SyntaxCollection",
575-
element: "BackDeployVersionArgument"),
577+
element: "AvailabilityVersionRestrictionListEntry"),
576578

577-
Node(name: "BackDeployVersionArgument",
579+
Node(name: "AvailabilityVersionRestrictionListEntry",
578580
nameForDiagnostics: "version",
579-
description: "A single platform/version pair in a `@_backDeploy` attribute,e.g. `iOS 10.1`.",
581+
description: "A single platform/version pair in an attribute, e.g. `iOS 10.1`.",
580582
kind: "Syntax",
581583
children: [
582584
Child(name: "AvailabilityVersionRestriction",
@@ -705,4 +707,37 @@ public let ATTRIBUTE_NODES: [Node] = [
705707
])
706708
]),
707709

710+
Node(name: "OriginallyDefinedInArguments",
711+
nameForDiagnostics: "@_originallyDefinedIn arguments",
712+
description: "The arguments for the '@_originallyDefinedIn' attribute",
713+
kind: "Syntax",
714+
children: [
715+
Child(name: "ModuleLabel",
716+
kind: "IdentifierToken",
717+
tokenChoices: [
718+
"Identifier"
719+
],
720+
textChoices: [
721+
"module"
722+
]),
723+
Child(name: "Colon",
724+
kind: "ColonToken",
725+
tokenChoices: [
726+
"Colon"
727+
]),
728+
Child(name: "ModuleName",
729+
kind: "StringLiteralToken",
730+
tokenChoices: [
731+
"StringLiteral"
732+
]),
733+
Child(name: "Comma",
734+
kind: "CommaToken",
735+
tokenChoices: [
736+
"Comma"
737+
]),
738+
Child(name: "Platforms",
739+
kind: "AvailabilityVersionRestrictionList",
740+
collectionElementName: "Platform")
741+
]),
742+
708743
]

Sources/IDEUtils/generated/SyntaxClassification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ extension SyntaxClassification {
122122
}
123123
} else {
124124
switch (parentKind, indexInParent) {
125-
case (.backDeployVersionArgument, 1):
125+
case (.availabilityVersionRestrictionListEntry, 1):
126126
return (.keyword, false)
127127
case (.customAttribute, 3):
128128
return (.attribute, false)

Sources/SwiftParser/Attributes.swift

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ extension Parser {
209209
return parseAttribute(hasRequiredArguments: true) { parser in
210210
return .exposeAttributeArguments(parser.parseExposeArguments())
211211
}
212+
case ._originallyDefinedIn:
213+
return parseAttribute(hasRequiredArguments: true) { parser in
214+
return .originallyDefinedInArguments(parser.parseOriginallyDefinedInArguments())
215+
}
212216
case .__objc_bridged, .__raw_doc_comment, ._alwaysEmitConformanceMetadata, ._alwaysEmitIntoClient, ._assemblyVision, ._borrowed, ._compilerInitialized, ._custom, ._disfavoredOverload, ._eagerMove, ._exported, ._fixed_layout, ._frozen, ._hasInitialValue, ._hasMissingDesignatedInitializers, ._hasStorage, ._implementationOnly, ._implicitSelfCapture, ._inheritActorContext, ._inheritsConvenienceInitializers, ._marker, ._moveOnly, ._noAllocation, ._noEagerMove, ._noImplicitCopy, ._noLocks, ._noMetadata, ._nonEphemeral, ._nonoverride, ._objc_non_lazy_realization, ._show_in_interface, ._specializeExtension, ._spiOnly, ._staticInitializeObjCMetadata, ._transparent, ._unsafeInheritExecutor, ._weakLinked, .atReasync, .atRethrows, .discardableResult, .dynamicCallable, .dynamicMemberLookup, .frozen, .GKInspectable, .globalActor, .IBAction, .IBDesignable, .IBInspectable, .IBOutlet, .IBSegueAction, .inlinable, .LLDBDebuggerFunction, .main, .noDerivative, .nonobjc, .NSApplicationMain, .NSCopying,
213217
.NSManaged, .objcMembers, .preconcurrency, .propertyWrapper, .requires_stored_property_inits, .resultBuilder, .runtimeMetadata, .Sendable, .testable, .typeWrapper, .typeWrapperIgnored, .UIApplicationMain, .unsafe_no_objc_tagged_pointer, .usableFromInline, .warn_unqualified_access:
214218
// No arguments
@@ -217,9 +221,6 @@ extension Parser {
217221
// Virtual attributes that should not be parsed
218222
break
219223
// MARK: - Other
220-
case ._originallyDefinedIn:
221-
// @_originallyDefinedIn(module: "HighLevel", OSX 10.9, iOS 13.0)
222-
break
223224
case ._unavailableFromAsync:
224225
// @_unavailableFromAsync(message: "Use Task.runInline from a sync context to begin an async context.")
225226
break
@@ -839,13 +840,13 @@ extension Parser {
839840
mutating func parseBackDeployArguments() -> RawBackDeployAttributeSpecListSyntax {
840841
let (unexpectedBeforeLabel, label) = self.expectContextualKeyword("before")
841842
let (unexpectedBeforeColon, colon) = self.expect(.colon)
842-
var elements: [RawBackDeployVersionArgumentSyntax] = []
843+
var elements: [RawAvailabilityVersionRestrictionListEntrySyntax] = []
843844
var keepGoing: RawTokenSyntax? = nil
844845
repeat {
845846
let versionRestriction = self.parsePlatformVersionConstraintSpec()
846847
keepGoing = self.consume(if: .comma)
847848
elements.append(
848-
RawBackDeployVersionArgumentSyntax(
849+
RawAvailabilityVersionRestrictionListEntrySyntax(
849850
availabilityVersionRestriction: versionRestriction,
850851
trailingComma: keepGoing,
851852
arena: self.arena
@@ -857,7 +858,7 @@ extension Parser {
857858
beforeLabel: label,
858859
unexpectedBeforeColon,
859860
colon: colon,
860-
versionList: RawBackDeployVersionListSyntax(elements: elements, arena: self.arena),
861+
versionList: RawAvailabilityVersionRestrictionListSyntax(elements: elements, arena: self.arena),
861862
arena: self.arena
862863
)
863864
}
@@ -895,6 +896,42 @@ extension Parser {
895896
}
896897
}
897898

899+
extension Parser {
900+
mutating func parseOriginallyDefinedInArguments() -> RawOriginallyDefinedInArgumentsSyntax {
901+
let (unexpectedBeforeModuleLabel, moduleLabel) = self.expectContextualKeyword("module")
902+
let (unexpectedBeforeColon, colon) = self.expect(.colon)
903+
let (unexpectedBeforeModuleName, moduleName) = self.expect(.stringLiteral)
904+
let (unexpectedBeforeComma, comma) = self.expect(.comma)
905+
906+
var platforms: [RawAvailabilityVersionRestrictionListEntrySyntax] = []
907+
var keepGoing: RawTokenSyntax?
908+
repeat {
909+
let restriction = self.parseAvailabilityMacro()
910+
keepGoing = self.consume(if: .comma)
911+
platforms.append(
912+
RawAvailabilityVersionRestrictionListEntrySyntax(
913+
availabilityVersionRestriction: restriction,
914+
trailingComma: keepGoing,
915+
arena: self.arena
916+
)
917+
)
918+
} while keepGoing != nil
919+
920+
return RawOriginallyDefinedInArgumentsSyntax(
921+
unexpectedBeforeModuleLabel,
922+
moduleLabel: moduleLabel,
923+
unexpectedBeforeColon,
924+
colon: colon,
925+
unexpectedBeforeModuleName,
926+
moduleName: moduleName,
927+
unexpectedBeforeComma,
928+
comma: comma,
929+
platforms: RawAvailabilityVersionRestrictionListSyntax(elements: platforms, arena: self.arena),
930+
arena: self.arena
931+
)
932+
}
933+
}
934+
898935
// MARK: Lookahead
899936

900937
extension Parser.Lookahead {

Sources/SwiftSyntax/Documentation.docc/gyb_generated/SwiftSyntax.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
234234
- <doc:SwiftSyntax/ObjCSelectorPieceSyntax>
235235
- <doc:SwiftSyntax/DifferentiabilityParamListSyntax>
236236
- <doc:SwiftSyntax/DifferentiabilityParamSyntax>
237-
- <doc:SwiftSyntax/BackDeployVersionListSyntax>
238-
- <doc:SwiftSyntax/BackDeployVersionArgumentSyntax>
237+
- <doc:SwiftSyntax/AvailabilityVersionRestrictionListSyntax>
238+
- <doc:SwiftSyntax/AvailabilityVersionRestrictionListEntrySyntax>
239239
- <doc:SwiftSyntax/CatchClauseListSyntax>
240240
- <doc:SwiftSyntax/CatchClauseSyntax>
241241
- <doc:SwiftSyntax/CaseItemListSyntax>
@@ -359,12 +359,13 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
359359
- <doc:SwiftSyntax/QualifiedDeclNameSyntax>
360360
- <doc:SwiftSyntax/FunctionDeclNameSyntax>
361361
- <doc:SwiftSyntax/BackDeployAttributeSpecListSyntax>
362-
- <doc:SwiftSyntax/BackDeployVersionListSyntax>
363-
- <doc:SwiftSyntax/BackDeployVersionArgumentSyntax>
362+
- <doc:SwiftSyntax/AvailabilityVersionRestrictionListSyntax>
363+
- <doc:SwiftSyntax/AvailabilityVersionRestrictionListEntrySyntax>
364364
- <doc:SwiftSyntax/OpaqueReturnTypeOfAttributeArgumentsSyntax>
365365
- <doc:SwiftSyntax/ConventionAttributeArgumentsSyntax>
366366
- <doc:SwiftSyntax/ConventionWitnessMethodAttributeArgumentsSyntax>
367367
- <doc:SwiftSyntax/ExposeAttributeArgumentsSyntax>
368+
- <doc:SwiftSyntax/OriginallyDefinedInArgumentsSyntax>
368369
- <doc:SwiftSyntax/SwitchCaseListSyntax>
369370
- <doc:SwiftSyntax/WhereClauseSyntax>
370371
- <doc:SwiftSyntax/CatchClauseListSyntax>

0 commit comments

Comments
 (0)