Skip to content

Commit 5b83f5e

Browse files
committed
Eliminate NamedAttributeString
1 parent 70b4fa4 commit 5b83f5e

File tree

19 files changed

+1572
-630
lines changed

19 files changed

+1572
-630
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public let ATTRIBUTE_NODES: [Node] = [
9999
kind: "DifferentiableAttributeArguments"),
100100
Child(name: "DerivativeRegistrationArguments",
101101
kind: "DerivativeRegistrationAttributeArguments"),
102-
Child(name: "NamedAttributeString",
103-
kind: "NamedAttributeStringArgument"),
104102
Child(name: "BackDeployArguments",
105103
kind: "BackDeployAttributeSpecList"),
106104
Child(name: "ConventionArguments",
@@ -112,7 +110,13 @@ public let ATTRIBUTE_NODES: [Node] = [
112110
Child(name: "ExposeAttributeArguments",
113111
kind: "ExposeAttributeArguments"),
114112
Child(name: "OriginallyDefinedInArguments",
115-
kind: "OriginallyDefinedInArguments")
113+
kind: "OriginallyDefinedInArguments"),
114+
Child(name: "UnderscorePrivateAttributeArguments",
115+
kind: "UnderscorePrivateAttributeArguments"),
116+
Child(name: "DynamicReplacementArguments",
117+
kind: "DynamicReplacementArguments"),
118+
Child(name: "UnavailableFromAsyncArguments",
119+
kind: "UnavailableFromAsyncArguments")
116120
]),
117121
Child(name: "RightParen",
118122
kind: "RightParenToken",
@@ -230,33 +234,6 @@ public let ATTRIBUTE_NODES: [Node] = [
230234
])
231235
]),
232236

233-
Node(name: "NamedAttributeStringArgument",
234-
nameForDiagnostics: "attribute argument",
235-
description: "The argument for the `@_dynamic_replacement` or `@_private`attribute of the form `for: \"function()\"` or `sourceFile:\"Src.swift\"`",
236-
kind: "Syntax",
237-
children: [
238-
Child(name: "NameTok",
239-
kind: "Token",
240-
description: "The label of the argument"),
241-
Child(name: "Colon",
242-
kind: "ColonToken",
243-
description: "The colon separating the label and the value",
244-
tokenChoices: [
245-
"Colon"
246-
]),
247-
Child(name: "StringOrDeclname",
248-
kind: "Syntax",
249-
nodeChoices: [
250-
Child(name: "String",
251-
kind: "StringLiteralToken",
252-
tokenChoices: [
253-
"StringLiteral"
254-
]),
255-
Child(name: "Declname",
256-
kind: "DeclName")
257-
])
258-
]),
259-
260237
Node(name: "DeclName",
261238
nameForDiagnostics: "declaration name",
262239
kind: "Syntax",
@@ -735,4 +712,76 @@ public let ATTRIBUTE_NODES: [Node] = [
735712
collectionElementName: "Platform")
736713
]),
737714

715+
Node(name: "UnderscorePrivateAttributeArguments",
716+
nameForDiagnostics: "@_private argument",
717+
description: "The arguments for the '@_private' attribute",
718+
kind: "Syntax",
719+
children: [
720+
Child(name: "SourceFileLabel",
721+
kind: "IdentifierToken",
722+
tokenChoices: [
723+
"Identifier"
724+
],
725+
textChoices: [
726+
"sourceFile"
727+
]),
728+
Child(name: "Colon",
729+
kind: "ColonToken",
730+
tokenChoices: [
731+
"Colon"
732+
]),
733+
Child(name: "Filename",
734+
kind: "StringLiteralToken",
735+
tokenChoices: [
736+
"StringLiteral"
737+
])
738+
]),
739+
740+
Node(name: "DynamicReplacementArguments",
741+
nameForDiagnostics: "@_dynamicReplacement argument",
742+
description: "The arguments for the '@_dynamicReplacement' attribute",
743+
kind: "Syntax",
744+
children: [
745+
Child(name: "ForLabel",
746+
kind: "IdentifierToken",
747+
tokenChoices: [
748+
"Identifier"
749+
],
750+
textChoices: [
751+
"for"
752+
]),
753+
Child(name: "Colon",
754+
kind: "ColonToken",
755+
tokenChoices: [
756+
"Colon"
757+
]),
758+
Child(name: "Declname",
759+
kind: "DeclName")
760+
]),
761+
762+
Node(name: "UnavailableFromAsyncArguments",
763+
nameForDiagnostics: "@_unavailableFromAsync argument",
764+
description: "The arguments for the '@_unavailableFromAsync' attribute",
765+
kind: "Syntax",
766+
children: [
767+
Child(name: "MessageLabel",
768+
kind: "IdentifierToken",
769+
tokenChoices: [
770+
"Identifier"
771+
],
772+
textChoices: [
773+
"message"
774+
]),
775+
Child(name: "Colon",
776+
kind: "ColonToken",
777+
tokenChoices: [
778+
"Colon"
779+
]),
780+
Child(name: "Message",
781+
kind: "StringLiteralToken",
782+
tokenChoices: [
783+
"StringLiteral"
784+
])
785+
]),
786+
738787
]

Sources/SwiftParser/Attributes.swift

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -126,45 +126,11 @@ extension Parser {
126126
}
127127
case ._private:
128128
return parseAttribute(hasRequiredArguments: true) { parser in
129-
let (unexpectedBeforeLabel, label) = parser.expectIdentifier(keywordRecovery: true)
130-
let (unexpectedBeforeColon, colon) = parser.expect(.colon)
131-
let filename = parser.consumeAnyToken()
132-
return .namedAttributeString(
133-
RawNamedAttributeStringArgumentSyntax(
134-
unexpectedBeforeLabel,
135-
nameTok: label,
136-
unexpectedBeforeColon,
137-
colon: colon,
138-
stringOrDeclname: .string(filename),
139-
arena: parser.arena
140-
)
141-
)
129+
return .underscorePrivateAttributeArguments(parser.parseUnderscorePrivateAttributeArguments())
142130
}
143131
case ._dynamicReplacement:
144132
return parseAttribute(hasRequiredArguments: true) { parser in
145-
let (unexpectedBeforeLabel, label) = parser.expect(.forKeyword, remapping: .identifier)
146-
let (unexpectedBeforeColon, colon) = parser.expect(.colon)
147-
let base: RawTokenSyntax
148-
let args: RawDeclNameArgumentsSyntax?
149-
if label.isMissing && colon.isMissing && parser.currentToken.isAtStartOfLine {
150-
base = RawTokenSyntax(missing: .identifier, arena: parser.arena)
151-
args = nil
152-
} else {
153-
(base, args) = parser.parseDeclNameRef([
154-
.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators,
155-
])
156-
}
157-
let method = RawDeclNameSyntax(declBaseName: base, declNameArguments: args, arena: parser.arena)
158-
return .namedAttributeString(
159-
RawNamedAttributeStringArgumentSyntax(
160-
unexpectedBeforeLabel,
161-
nameTok: label,
162-
unexpectedBeforeColon,
163-
colon: colon,
164-
stringOrDeclname: .declname(method),
165-
arena: parser.arena
166-
)
167-
)
133+
return .dynamicReplacementArguments(parser.parseDynamicReplacementArguments())
168134
}
169135
case ._spi, ._effects, ._objcRuntimeName, ._projectedValueProperty, ._swift_native_objc_runtime_base, ._typeEraser, ._documentation, ._optimize, ._nonSendable, .exclusivity, .inline, ._alignment:
170136
// Attributes that take a single token as argument. Some examples of these include:
@@ -219,20 +185,7 @@ extension Parser {
219185
}
220186
case ._unavailableFromAsync:
221187
return parseAttribute(hasRequiredArguments: false) { parser in
222-
let (unexpectedBeforeLabel, label) = parser.expectContextualKeyword("message")
223-
let (unexpectedBeforeColon, colon) = parser.expect(.colon)
224-
let (unexpectedBeforeMessage, message) = parser.expect(.stringLiteral)
225-
return .namedAttributeString(
226-
RawNamedAttributeStringArgumentSyntax(
227-
unexpectedBeforeLabel,
228-
nameTok: label,
229-
unexpectedBeforeColon,
230-
colon: colon,
231-
unexpectedBeforeMessage,
232-
stringOrDeclname: .string(message),
233-
arena: parser.arena
234-
)
235-
)
188+
return .unavailableFromAsyncArguments(parser.parseUnavailableFromAsyncArguments())
236189
}
237190
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,
238191
.NSManaged, .objcMembers, .preconcurrency, .propertyWrapper, .requires_stored_property_inits, .resultBuilder, .runtimeMetadata, .Sendable, .testable, .typeWrapper, .typeWrapperIgnored, .UIApplicationMain, .unsafe_no_objc_tagged_pointer, .usableFromInline, .warn_unqualified_access,
@@ -926,6 +879,66 @@ extension Parser {
926879
}
927880
}
928881

882+
extension Parser {
883+
mutating func parseUnderscorePrivateAttributeArguments() -> RawUnderscorePrivateAttributeArgumentsSyntax {
884+
let (unexpectedBeforeLabel, label) = self.expectContextualKeyword("sourceFile")
885+
let (unexpectedBeforeColon, colon) = self.expect(.colon)
886+
let (unexpectedBeforeFilename, filename) = self.expect(.stringLiteral)
887+
return RawUnderscorePrivateAttributeArgumentsSyntax(
888+
unexpectedBeforeLabel,
889+
sourceFileLabel: label,
890+
unexpectedBeforeColon,
891+
colon: colon,
892+
unexpectedBeforeFilename,
893+
filename: filename,
894+
arena: self.arena
895+
)
896+
}
897+
}
898+
899+
extension Parser {
900+
mutating func parseDynamicReplacementArguments() -> RawDynamicReplacementArgumentsSyntax {
901+
let (unexpectedBeforeLabel, label) = self.expect(.forKeyword, remapping: .identifier)
902+
let (unexpectedBeforeColon, colon) = self.expect(.colon)
903+
let base: RawTokenSyntax
904+
let args: RawDeclNameArgumentsSyntax?
905+
if label.isMissing && colon.isMissing && self.currentToken.isAtStartOfLine {
906+
base = RawTokenSyntax(missing: .identifier, arena: self.arena)
907+
args = nil
908+
} else {
909+
(base, args) = self.parseDeclNameRef([
910+
.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators,
911+
])
912+
}
913+
let method = RawDeclNameSyntax(declBaseName: base, declNameArguments: args, arena: self.arena)
914+
return RawDynamicReplacementArgumentsSyntax(
915+
unexpectedBeforeLabel,
916+
forLabel: label,
917+
unexpectedBeforeColon,
918+
colon: colon,
919+
declname: method,
920+
arena: self.arena
921+
)
922+
}
923+
}
924+
925+
extension Parser {
926+
mutating func parseUnavailableFromAsyncArguments() -> RawUnavailableFromAsyncArgumentsSyntax {
927+
let (unexpectedBeforeLabel, label) = self.expectContextualKeyword("message")
928+
let (unexpectedBeforeColon, colon) = self.expect(.colon)
929+
let (unexpectedBeforeMessage, message) = self.expect(.stringLiteral)
930+
return RawUnavailableFromAsyncArgumentsSyntax(
931+
unexpectedBeforeLabel,
932+
messageLabel: label,
933+
unexpectedBeforeColon,
934+
colon: colon,
935+
unexpectedBeforeMessage,
936+
message: message,
937+
arena: self.arena
938+
)
939+
}
940+
}
941+
929942
// MARK: Lookahead
930943

931944
extension Parser.Lookahead {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
345345
- <doc:SwiftSyntax/AvailabilityEntrySyntax>
346346
- <doc:SwiftSyntax/LabeledSpecializeEntrySyntax>
347347
- <doc:SwiftSyntax/TargetFunctionEntrySyntax>
348-
- <doc:SwiftSyntax/NamedAttributeStringArgumentSyntax>
349348
- <doc:SwiftSyntax/DeclNameSyntax>
350349
- <doc:SwiftSyntax/ImplementsAttributeArgumentsSyntax>
351350
- <doc:SwiftSyntax/ObjCSelectorPieceSyntax>
@@ -366,6 +365,9 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
366365
- <doc:SwiftSyntax/ConventionWitnessMethodAttributeArgumentsSyntax>
367366
- <doc:SwiftSyntax/ExposeAttributeArgumentsSyntax>
368367
- <doc:SwiftSyntax/OriginallyDefinedInArgumentsSyntax>
368+
- <doc:SwiftSyntax/UnderscorePrivateAttributeArgumentsSyntax>
369+
- <doc:SwiftSyntax/DynamicReplacementArgumentsSyntax>
370+
- <doc:SwiftSyntax/UnavailableFromAsyncArgumentsSyntax>
369371
- <doc:SwiftSyntax/SwitchCaseListSyntax>
370372
- <doc:SwiftSyntax/WhereClauseSyntax>
371373
- <doc:SwiftSyntax/CatchClauseListSyntax>

0 commit comments

Comments
 (0)