Skip to content

Commit ea619f4

Browse files
authored
Merge pull request #1950 from ahoppen/ahoppen/identifierexpr
Use `IdentifierExpr` in a couple more places instead of `DeclNameArguments`
2 parents e0ee126 + 8d40a59 commit ea619f4

File tree

51 files changed

+817
-1403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+817
-1403
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -295,35 +295,6 @@ public let ATTRIBUTE_NODES: [Node] = [
295295
]
296296
),
297297

298-
Node(
299-
kind: .declName,
300-
base: .syntax,
301-
nameForDiagnostics: "declaration name",
302-
children: [
303-
Child(
304-
name: "BaseName",
305-
deprecatedName: "DeclBaseName",
306-
kind: .token(choices: [
307-
.token(tokenKind: "IdentifierToken"),
308-
.token(tokenKind: "BinaryOperatorToken"),
309-
.keyword(text: "init"),
310-
.keyword(text: "self"),
311-
.keyword(text: "Self"),
312-
]),
313-
nameForDiagnostics: "base name",
314-
documentation: "The base name of the protocol's requirement."
315-
),
316-
Child(
317-
name: "Arguments",
318-
deprecatedName: "DeclNameArguments",
319-
kind: .node(kind: .declNameArguments),
320-
nameForDiagnostics: "arguments",
321-
documentation: "The argument labels of the protocol's requirement if it is a function requirement.",
322-
isOptional: true
323-
),
324-
]
325-
),
326-
327298
// The argument of the derivative registration attribute
328299
// '@derivative(of: ...)' and the transpose registration attribute
329300
// '@transpose(of: ...)'.
@@ -591,7 +562,7 @@ public let ATTRIBUTE_NODES: [Node] = [
591562
Child(
592563
name: "DeclName",
593564
deprecatedName: "Declname",
594-
kind: .node(kind: .declName)
565+
kind: .node(kind: .declReferenceExpr)
595566
),
596567
]
597568
),
@@ -648,17 +619,11 @@ public let ATTRIBUTE_NODES: [Node] = [
648619
documentation: "The comma separating the type and method name"
649620
),
650621
Child(
651-
name: "DeclBaseName",
652-
kind: .node(kind: .token),
653-
nameForDiagnostics: "declaration base name",
654-
documentation: "The base name of the protocol's requirement."
655-
),
656-
Child(
657-
name: "DeclNameArguments",
658-
kind: .node(kind: .declNameArguments),
659-
nameForDiagnostics: "declaration name arguments",
660-
documentation: "The argument labels of the protocol's requirement if it is a function requirement.",
661-
isOptional: true
622+
name: "DeclName",
623+
deprecatedName: "Declname",
624+
kind: .node(kind: .declReferenceExpr),
625+
nameForDiagnostics: "declaration name",
626+
documentation: "The value for this argument"
662627
),
663628
]
664629
),
@@ -812,23 +777,10 @@ public let ATTRIBUTE_NODES: [Node] = [
812777
isOptional: true
813778
),
814779
Child(
815-
name: "Name",
816-
kind: .token(choices: [
817-
.token(tokenKind: "IdentifierToken"),
818-
.keyword(text: "self"),
819-
.keyword(text: "Self"),
820-
.keyword(text: "init"),
821-
.token(tokenKind: "BinaryOperatorToken"),
822-
]),
823-
nameForDiagnostics: "base name",
824-
documentation: "The base name of the referenced function."
825-
),
826-
Child(
827-
name: "Arguments",
828-
kind: .node(kind: .declNameArguments),
829-
nameForDiagnostics: "arguments",
830-
documentation: "The argument labels of the referenced function, optionally specified.",
831-
isOptional: true
780+
name: "DeclName",
781+
kind: .node(kind: .declReferenceExpr),
782+
nameForDiagnostics: "name",
783+
documentation: "The name of the referenced function."
832784
),
833785
]
834786
),
@@ -872,7 +824,7 @@ public let ATTRIBUTE_NODES: [Node] = [
872824
Child(
873825
name: "DeclName",
874826
deprecatedName: "Declname",
875-
kind: .node(kind: .declName),
827+
kind: .node(kind: .declReferenceExpr),
876828
nameForDiagnostics: "declaration name",
877829
documentation: "The value for this argument"
878830
),

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -837,23 +837,26 @@ public let EXPR_NODES: [Node] = [
837837

838838
// An identifier expression.
839839
Node(
840-
kind: .identifierExpr,
840+
kind: .declReferenceExpr,
841841
base: .expr,
842842
nameForDiagnostics: nil,
843843
children: [
844844
Child(
845-
name: "Identifier",
845+
name: "BaseName",
846+
deprecatedName: "Identifier",
846847
kind: .token(choices: [
847848
.token(tokenKind: "IdentifierToken"),
848849
.keyword(text: "self"),
849850
.keyword(text: "Self"),
850851
.keyword(text: "init"),
851852
.token(tokenKind: "DollarIdentifierToken"),
852853
.token(tokenKind: "BinaryOperatorToken"),
854+
.token(tokenKind: "IntegerLiteralToken"),
853855
])
854856
),
855857
Child(
856-
name: "DeclNameArguments",
858+
name: "ArgumentNames",
859+
deprecatedName: "DeclNameArguments",
857860
kind: .node(kind: .declNameArguments),
858861
isOptional: true
859862
),
@@ -1089,22 +1092,9 @@ public let EXPR_NODES: [Node] = [
10891092
nameForDiagnostics: "key path property component",
10901093
children: [
10911094
Child(
1092-
name: "Property",
1095+
name: "DeclName",
10931096
deprecatedName: "Identifier",
1094-
kind: .token(choices: [
1095-
.token(tokenKind: "IdentifierToken"),
1096-
.keyword(text: "self"),
1097-
.keyword(text: "Self"),
1098-
.keyword(text: "init"),
1099-
.token(tokenKind: "DollarIdentifierToken"),
1100-
.token(tokenKind: "BinaryOperatorToken"),
1101-
.token(tokenKind: "IntegerLiteralToken"),
1102-
])
1103-
),
1104-
Child(
1105-
name: "DeclNameArguments",
1106-
kind: .node(kind: .declNameArguments),
1107-
isOptional: true
1097+
kind: .node(kind: .declReferenceExpr)
11081098
),
11091099
Child(
11101100
name: "GenericArgumentClause",
@@ -1211,15 +1201,10 @@ public let EXPR_NODES: [Node] = [
12111201
kind: .token(choices: [.token(tokenKind: "PeriodToken")])
12121202
),
12131203
Child(
1214-
name: "Name",
1215-
kind: .node(kind: .token),
1204+
name: "DeclName",
1205+
kind: .node(kind: .declReferenceExpr),
12161206
nameForDiagnostics: "name"
12171207
),
1218-
Child(
1219-
name: "DeclNameArguments",
1220-
kind: .node(kind: .declNameArguments),
1221-
isOptional: true
1222-
),
12231208
]
12241209
),
12251210

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public enum SyntaxNodeKind: String, CaseIterable {
8484
case declModifier
8585
case declModifierDetail
8686
case declModifierList
87-
case declName
8887
case declNameArgument
8988
case declNameArgumentList
9089
case declNameArguments
90+
case declReferenceExpr
9191
case deferStmt
9292
case deinitializerDecl
9393
case deinitializerEffectSpecifiers
@@ -149,7 +149,6 @@ public enum SyntaxNodeKind: String, CaseIterable {
149149
case genericSpecializationExpr
150150
case genericWhereClause
151151
case guardStmt
152-
case identifierExpr
153152
case identifierPattern
154153
case identifierType
155154
case ifConfigClause
@@ -384,6 +383,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
384383
case .closureShorthandParameterList: return "closureParamList"
385384
case .consumeExpr: return "moveExpr"
386385
case .declModifierList: return "modifierList"
386+
case .declReferenceExpr: return "identifierExpr"
387387
case .deinitializerEffectSpecifiers: return "deinitEffectSpecifiers"
388388
case .derivativeAttributeArguments: return "derivativeRegistrationAttributeArguments"
389389
case .designatedType: return "designatedTypeElement"

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public extension Child {
131131
preconditionChoices.append(
132132
ExprSyntax(
133133
SequenceExprSyntax {
134-
IdentifierExprSyntax(identifier: .identifier(varName))
134+
DeclReferenceExprSyntax(baseName: .identifier(varName))
135135
BinaryOperatorExprSyntax(text: "==")
136136
NilLiteralExprSyntax()
137137
}
@@ -142,7 +142,7 @@ public extension Child {
142142
preconditionChoices.append(
143143
ExprSyntax(
144144
SequenceExprSyntax {
145-
MemberAccessExprSyntax(base: type.forceUnwrappedIfNeeded(expr: IdentifierExprSyntax(identifier: .identifier(varName))), name: "text")
145+
MemberAccessExprSyntax(base: type.forceUnwrappedIfNeeded(expr: DeclReferenceExprSyntax(baseName: .identifier(varName))), name: "text")
146146
BinaryOperatorExprSyntax(text: "==")
147147
StringLiteralExprSyntax(content: textChoice)
148148
}

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RenamedChildrenCompatibilityFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let renamedChildrenCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copy
7676
LabeledExprSyntax(
7777
label: child.varOrCaseName,
7878
colon: .colonToken(),
79-
expression: IdentifierExprSyntax(identifier: child.deprecatedVarName ?? child.varOrCaseName)
79+
expression: DeclReferenceExprSyntax(baseName: child.deprecatedVarName ?? child.varOrCaseName)
8080
)
8181
}
8282
}

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -457,18 +457,6 @@ class ValidateSyntaxNodes: XCTestCase {
457457
assertFailuresMatchXFails(
458458
failures,
459459
expectedFailures: [
460-
// MARK: DeclNameArguments
461-
// FIXME: IdentifierExprSyntax etc. should probably use DeclName as child instead of Name and Arguments
462-
ValidationFailure(
463-
node: .qualifiedDeclName,
464-
message:
465-
"child 'Arguments' is named inconsistently with 'IdentifierExprSyntax.DeclNameArguments', which has the same type ('DeclNameArgumentsSyntax')"
466-
),
467-
ValidationFailure(
468-
node: .declName,
469-
message:
470-
"child 'Arguments' is named inconsistently with 'IdentifierExprSyntax.DeclNameArguments', which has the same type ('DeclNameArgumentsSyntax')"
471-
),
472460
// MARK: Alternate names for InitializerClauseSyntax
473461
// The cases below don’t have intializers but just a syntactic element that happens to be spelled the same
474462
ValidationFailure(
@@ -633,8 +621,7 @@ class ValidateSyntaxNodes: XCTestCase {
633621
failures,
634622
expectedFailures: [
635623
// The identifier expr / pattern nodes do actually have a child that’s the identifier
636-
ValidationFailure(node: .identifierExpr, message: "child 'Identifier' should generally not contain 'Identifier'"),
637-
ValidationFailure(node: .identifierPattern, message: "child 'Identifier' should generally not contain 'Identifier'"),
624+
ValidationFailure(node: .identifierPattern, message: "child 'Identifier' should generally not contain 'Identifier'")
638625
]
639626
)
640627
}

Sources/SwiftParser/Attributes.swift

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ extension Parser {
353353
label: nil,
354354
colon: nil,
355355
expression: RawExprSyntax(
356-
RawIdentifierExprSyntax(
356+
RawDeclReferenceExprSyntax(
357357
unexpectedBeforeRole,
358-
identifier: role,
359-
declNameArguments: nil,
358+
baseName: role,
359+
argumentNames: nil,
360360
arena: self.arena
361361
)
362362
),
@@ -681,12 +681,7 @@ extension Parser {
681681
case (.target, let handle)?:
682682
let ident = self.eat(handle)
683683
let (unexpectedBeforeColon, colon) = self.expect(.colon)
684-
let (targetFunction, args) = self.parseDeclNameRef([.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators])
685-
let declName = RawDeclNameSyntax(
686-
baseName: targetFunction,
687-
arguments: args,
688-
arena: self.arena
689-
)
684+
let declName = self.parseDeclReferenceExpr([.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators])
690685
let comma = self.consume(if: .comma)
691686
elements.append(
692687
.specializeTargetFunctionArgument(
@@ -823,16 +818,15 @@ extension Parser {
823818
mutating func parseImplementsAttributeArguments() -> RawImplementsAttributeArgumentsSyntax {
824819
let type = self.parseType()
825820
let (unexpectedBeforeComma, comma) = self.expect(.comma)
826-
let (name, args) = self.parseDeclNameRef([
821+
let declName = self.parseDeclReferenceExpr([
827822
.zeroArgCompoundNames,
828823
.operators,
829824
])
830825
return RawImplementsAttributeArgumentsSyntax(
831826
type: type,
832827
unexpectedBeforeComma,
833828
comma: comma,
834-
declBaseName: name,
835-
declNameArguments: args,
829+
declName: declName,
836830
arena: self.arena
837831
)
838832
}
@@ -1021,23 +1015,24 @@ extension Parser {
10211015
mutating func parseDynamicReplacementAttributeArguments() -> RawDynamicReplacementAttributeArgumentsSyntax {
10221016
let (unexpectedBeforeLabel, label) = self.expect(.keyword(.for))
10231017
let (unexpectedBeforeColon, colon) = self.expect(.colon)
1024-
let base: RawTokenSyntax
1025-
let args: RawDeclNameArgumentsSyntax?
1018+
let declName: RawDeclReferenceExprSyntax
10261019
if label.isMissing && colon.isMissing && self.atStartOfLine {
1027-
base = RawTokenSyntax(missing: .identifier, arena: self.arena)
1028-
args = nil
1020+
declName = RawDeclReferenceExprSyntax(
1021+
baseName: RawTokenSyntax(missing: .identifier, arena: self.arena),
1022+
argumentNames: nil,
1023+
arena: self.arena
1024+
)
10291025
} else {
1030-
(base, args) = self.parseDeclNameRef([
1026+
declName = self.parseDeclReferenceExpr([
10311027
.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators,
10321028
])
10331029
}
1034-
let method = RawDeclNameSyntax(baseName: base, arguments: args, arena: self.arena)
10351030
return RawDynamicReplacementAttributeArgumentsSyntax(
10361031
unexpectedBeforeLabel,
10371032
forLabel: label,
10381033
unexpectedBeforeColon,
10391034
colon: colon,
1040-
declName: method,
1035+
declName: declName,
10411036
arena: self.arena
10421037
)
10431038
}

0 commit comments

Comments
 (0)