Skip to content

Commit 1aa235d

Browse files
committed
Validate that we don’t use abbreviations in child names
1 parent 431c77b commit 1aa235d

File tree

9 files changed

+207
-65
lines changed

9 files changed

+207
-65
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,8 @@ public let DECL_NODES: [Node] = [
17781778
kind: .token(choices: [.token(tokenKind: "LeftParenToken")])
17791779
),
17801780
Child(
1781-
name: "Args",
1781+
name: "Arguments",
1782+
deprecatedName: "Args",
17821783
kind: .node(kind: .poundSourceLocationArgs),
17831784
nameForDiagnostics: "arguments",
17841785
isOptional: true

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,8 @@ public let EXPR_NODES: [Node] = [
13201320
kind: .token(choices: [.keyword(text: "each")])
13211321
),
13221322
Child(
1323-
name: "PackRefExpr",
1323+
name: "PackReference",
1324+
deprecatedName: "PackRefExpr",
13241325
kind: .node(kind: .expr)
13251326
),
13261327
]

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,26 @@ class ValidateSyntaxNodes: XCTestCase {
621621
]
622622
)
623623
}
624+
625+
func testNoAbbreviationsInChildNames() {
626+
var failures: [ValidationFailure] = []
627+
628+
for node in SYNTAX_NODES.compactMap(\.layoutNode) {
629+
for child in node.nonUnexpectedChildren {
630+
if child.name.contains("Args") {
631+
failures.append(
632+
ValidationFailure(
633+
node: node.kind,
634+
message: "child '\(child.name)' should not contain abbreviations"
635+
)
636+
)
637+
}
638+
}
639+
}
640+
641+
assertFailuresMatchXFails(
642+
failures,
643+
expectedFailures: []
644+
)
645+
}
624646
}

Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? {
270270
return "file name"
271271
case \PoundSourceLocationArgsSyntax.lineNumber:
272272
return "line number"
273-
case \PoundSourceLocationSyntax.args:
273+
case \PoundSourceLocationSyntax.arguments:
274274
return "arguments"
275275
case \PrecedenceGroupDeclSyntax.attributes:
276276
return "attributes"

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,12 +2445,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
24452445
return "unexpectedBeforeEachKeyword"
24462446
case \PackElementExprSyntax.eachKeyword:
24472447
return "eachKeyword"
2448-
case \PackElementExprSyntax.unexpectedBetweenEachKeywordAndPackRefExpr:
2449-
return "unexpectedBetweenEachKeywordAndPackRefExpr"
2450-
case \PackElementExprSyntax.packRefExpr:
2451-
return "packRefExpr"
2452-
case \PackElementExprSyntax.unexpectedAfterPackRefExpr:
2453-
return "unexpectedAfterPackRefExpr"
2448+
case \PackElementExprSyntax.unexpectedBetweenEachKeywordAndPackReference:
2449+
return "unexpectedBetweenEachKeywordAndPackReference"
2450+
case \PackElementExprSyntax.packReference:
2451+
return "packReference"
2452+
case \PackElementExprSyntax.unexpectedAfterPackReference:
2453+
return "unexpectedAfterPackReference"
24542454
case \PackExpansionExprSyntax.unexpectedBeforeRepeatKeyword:
24552455
return "unexpectedBeforeRepeatKeyword"
24562456
case \PackExpansionExprSyntax.repeatKeyword:
@@ -2575,12 +2575,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
25752575
return "unexpectedBetweenPoundSourceLocationAndLeftParen"
25762576
case \PoundSourceLocationSyntax.leftParen:
25772577
return "leftParen"
2578-
case \PoundSourceLocationSyntax.unexpectedBetweenLeftParenAndArgs:
2579-
return "unexpectedBetweenLeftParenAndArgs"
2580-
case \PoundSourceLocationSyntax.args:
2581-
return "args"
2582-
case \PoundSourceLocationSyntax.unexpectedBetweenArgsAndRightParen:
2583-
return "unexpectedBetweenArgsAndRightParen"
2578+
case \PoundSourceLocationSyntax.unexpectedBetweenLeftParenAndArguments:
2579+
return "unexpectedBetweenLeftParenAndArguments"
2580+
case \PoundSourceLocationSyntax.arguments:
2581+
return "arguments"
2582+
case \PoundSourceLocationSyntax.unexpectedBetweenArgumentsAndRightParen:
2583+
return "unexpectedBetweenArgumentsAndRightParen"
25842584
case \PoundSourceLocationSyntax.rightParen:
25852585
return "rightParen"
25862586
case \PoundSourceLocationSyntax.unexpectedAfterRightParen:

Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,6 +4403,61 @@ extension OptionalBindingConditionSyntax {
44034403
}
44044404
}
44054405

4406+
extension PackElementExprSyntax {
4407+
@available(*, deprecated, renamed: "unexpectedBetweenEachKeywordAndPackReference")
4408+
public var unexpectedBetweenEachKeywordAndPackRefExpr: UnexpectedNodesSyntax? {
4409+
get {
4410+
return unexpectedBetweenEachKeywordAndPackReference
4411+
}
4412+
set {
4413+
unexpectedBetweenEachKeywordAndPackReference = newValue
4414+
}
4415+
}
4416+
4417+
@available(*, deprecated, renamed: "packReference")
4418+
public var packRefExpr: ExprSyntax {
4419+
get {
4420+
return packReference
4421+
}
4422+
set {
4423+
packReference = newValue
4424+
}
4425+
}
4426+
4427+
@available(*, deprecated, renamed: "unexpectedAfterPackReference")
4428+
public var unexpectedAfterPackRefExpr: UnexpectedNodesSyntax? {
4429+
get {
4430+
return unexpectedAfterPackReference
4431+
}
4432+
set {
4433+
unexpectedAfterPackReference = newValue
4434+
}
4435+
}
4436+
4437+
@available(*, deprecated, message: "Use an initializer with packReference argument(s).")
4438+
@_disfavoredOverload
4439+
public init(
4440+
leadingTrivia: Trivia? = nil,
4441+
_ unexpectedBeforeEachKeyword: UnexpectedNodesSyntax? = nil,
4442+
eachKeyword: TokenSyntax = .keyword(.each),
4443+
_ unexpectedBetweenEachKeywordAndPackRefExpr: UnexpectedNodesSyntax? = nil,
4444+
packRefExpr: some ExprSyntaxProtocol,
4445+
_ unexpectedAfterPackRefExpr: UnexpectedNodesSyntax? = nil,
4446+
trailingTrivia: Trivia? = nil
4447+
4448+
) {
4449+
self.init(
4450+
leadingTrivia: leadingTrivia,
4451+
unexpectedBeforeEachKeyword,
4452+
eachKeyword: eachKeyword,
4453+
unexpectedBetweenEachKeywordAndPackRefExpr,
4454+
packReference: packRefExpr,
4455+
unexpectedAfterPackRefExpr,
4456+
trailingTrivia: trailingTrivia
4457+
)
4458+
}
4459+
}
4460+
44064461
extension ParameterClauseSyntax {
44074462
@available(*, deprecated, renamed: "unexpectedBetweenLeftParenAndParameters")
44084463
public var unexpectedBetweenLeftParenAndParameterList: UnexpectedNodesSyntax? {
@@ -4662,6 +4717,69 @@ extension PoundSourceLocationArgsSyntax {
46624717
}
46634718
}
46644719

4720+
extension PoundSourceLocationSyntax {
4721+
@available(*, deprecated, renamed: "unexpectedBetweenLeftParenAndArguments")
4722+
public var unexpectedBetweenLeftParenAndArgs: UnexpectedNodesSyntax? {
4723+
get {
4724+
return unexpectedBetweenLeftParenAndArguments
4725+
}
4726+
set {
4727+
unexpectedBetweenLeftParenAndArguments = newValue
4728+
}
4729+
}
4730+
4731+
@available(*, deprecated, renamed: "arguments")
4732+
public var args: PoundSourceLocationArgsSyntax? {
4733+
get {
4734+
return arguments
4735+
}
4736+
set {
4737+
arguments = newValue
4738+
}
4739+
}
4740+
4741+
@available(*, deprecated, renamed: "unexpectedBetweenArgumentsAndRightParen")
4742+
public var unexpectedBetweenArgsAndRightParen: UnexpectedNodesSyntax? {
4743+
get {
4744+
return unexpectedBetweenArgumentsAndRightParen
4745+
}
4746+
set {
4747+
unexpectedBetweenArgumentsAndRightParen = newValue
4748+
}
4749+
}
4750+
4751+
@available(*, deprecated, message: "Use an initializer with arguments argument(s).")
4752+
@_disfavoredOverload
4753+
public init(
4754+
leadingTrivia: Trivia? = nil,
4755+
_ unexpectedBeforePoundSourceLocation: UnexpectedNodesSyntax? = nil,
4756+
poundSourceLocation: TokenSyntax = .poundSourceLocationToken(),
4757+
_ unexpectedBetweenPoundSourceLocationAndLeftParen: UnexpectedNodesSyntax? = nil,
4758+
leftParen: TokenSyntax = .leftParenToken(),
4759+
_ unexpectedBetweenLeftParenAndArgs: UnexpectedNodesSyntax? = nil,
4760+
args: PoundSourceLocationArgsSyntax? = nil,
4761+
_ unexpectedBetweenArgsAndRightParen: UnexpectedNodesSyntax? = nil,
4762+
rightParen: TokenSyntax = .rightParenToken(),
4763+
_ unexpectedAfterRightParen: UnexpectedNodesSyntax? = nil,
4764+
trailingTrivia: Trivia? = nil
4765+
4766+
) {
4767+
self.init(
4768+
leadingTrivia: leadingTrivia,
4769+
unexpectedBeforePoundSourceLocation,
4770+
poundSourceLocation: poundSourceLocation,
4771+
unexpectedBetweenPoundSourceLocationAndLeftParen,
4772+
leftParen: leftParen,
4773+
unexpectedBetweenLeftParenAndArgs,
4774+
arguments: args,
4775+
unexpectedBetweenArgsAndRightParen,
4776+
rightParen: rightParen,
4777+
unexpectedAfterRightParen,
4778+
trailingTrivia: trailingTrivia
4779+
)
4780+
}
4781+
}
4782+
46654783
extension PrecedenceGroupAssignmentSyntax {
46664784
@available(*, deprecated, renamed: "unexpectedBeforeAssignmentLabel")
46674785
public var unexpectedBeforeAssignmentKeyword: UnexpectedNodesSyntax? {

Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16088,19 +16088,19 @@ public struct RawPackElementExprSyntax: RawExprSyntaxNodeProtocol {
1608816088
public init(
1608916089
_ unexpectedBeforeEachKeyword: RawUnexpectedNodesSyntax? = nil,
1609016090
eachKeyword: RawTokenSyntax,
16091-
_ unexpectedBetweenEachKeywordAndPackRefExpr: RawUnexpectedNodesSyntax? = nil,
16092-
packRefExpr: RawExprSyntax,
16093-
_ unexpectedAfterPackRefExpr: RawUnexpectedNodesSyntax? = nil,
16091+
_ unexpectedBetweenEachKeywordAndPackReference: RawUnexpectedNodesSyntax? = nil,
16092+
packReference: RawExprSyntax,
16093+
_ unexpectedAfterPackReference: RawUnexpectedNodesSyntax? = nil,
1609416094
arena: __shared SyntaxArena
1609516095
) {
1609616096
let raw = RawSyntax.makeLayout(
1609716097
kind: .packElementExpr, uninitializedCount: 5, arena: arena) { layout in
1609816098
layout.initialize(repeating: nil)
1609916099
layout[0] = unexpectedBeforeEachKeyword?.raw
1610016100
layout[1] = eachKeyword.raw
16101-
layout[2] = unexpectedBetweenEachKeywordAndPackRefExpr?.raw
16102-
layout[3] = packRefExpr.raw
16103-
layout[4] = unexpectedAfterPackRefExpr?.raw
16101+
layout[2] = unexpectedBetweenEachKeywordAndPackReference?.raw
16102+
layout[3] = packReference.raw
16103+
layout[4] = unexpectedAfterPackReference?.raw
1610416104
}
1610516105
self.init(unchecked: raw)
1610616106
}
@@ -16113,15 +16113,15 @@ public struct RawPackElementExprSyntax: RawExprSyntaxNodeProtocol {
1611316113
layoutView.children[1].map(RawTokenSyntax.init(raw:))!
1611416114
}
1611516115

16116-
public var unexpectedBetweenEachKeywordAndPackRefExpr: RawUnexpectedNodesSyntax? {
16116+
public var unexpectedBetweenEachKeywordAndPackReference: RawUnexpectedNodesSyntax? {
1611716117
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
1611816118
}
1611916119

16120-
public var packRefExpr: RawExprSyntax {
16120+
public var packReference: RawExprSyntax {
1612116121
layoutView.children[3].map(RawExprSyntax.init(raw:))!
1612216122
}
1612316123

16124-
public var unexpectedAfterPackRefExpr: RawUnexpectedNodesSyntax? {
16124+
public var unexpectedAfterPackReference: RawUnexpectedNodesSyntax? {
1612516125
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
1612616126
}
1612716127
}
@@ -16947,9 +16947,9 @@ public struct RawPoundSourceLocationSyntax: RawDeclSyntaxNodeProtocol {
1694716947
poundSourceLocation: RawTokenSyntax,
1694816948
_ unexpectedBetweenPoundSourceLocationAndLeftParen: RawUnexpectedNodesSyntax? = nil,
1694916949
leftParen: RawTokenSyntax,
16950-
_ unexpectedBetweenLeftParenAndArgs: RawUnexpectedNodesSyntax? = nil,
16951-
args: RawPoundSourceLocationArgsSyntax?,
16952-
_ unexpectedBetweenArgsAndRightParen: RawUnexpectedNodesSyntax? = nil,
16950+
_ unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? = nil,
16951+
arguments: RawPoundSourceLocationArgsSyntax?,
16952+
_ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil,
1695316953
rightParen: RawTokenSyntax,
1695416954
_ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil,
1695516955
arena: __shared SyntaxArena
@@ -16961,9 +16961,9 @@ public struct RawPoundSourceLocationSyntax: RawDeclSyntaxNodeProtocol {
1696116961
layout[1] = poundSourceLocation.raw
1696216962
layout[2] = unexpectedBetweenPoundSourceLocationAndLeftParen?.raw
1696316963
layout[3] = leftParen.raw
16964-
layout[4] = unexpectedBetweenLeftParenAndArgs?.raw
16965-
layout[5] = args?.raw
16966-
layout[6] = unexpectedBetweenArgsAndRightParen?.raw
16964+
layout[4] = unexpectedBetweenLeftParenAndArguments?.raw
16965+
layout[5] = arguments?.raw
16966+
layout[6] = unexpectedBetweenArgumentsAndRightParen?.raw
1696716967
layout[7] = rightParen.raw
1696816968
layout[8] = unexpectedAfterRightParen?.raw
1696916969
}
@@ -16986,15 +16986,15 @@ public struct RawPoundSourceLocationSyntax: RawDeclSyntaxNodeProtocol {
1698616986
layoutView.children[3].map(RawTokenSyntax.init(raw:))!
1698716987
}
1698816988

16989-
public var unexpectedBetweenLeftParenAndArgs: RawUnexpectedNodesSyntax? {
16989+
public var unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? {
1699016990
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
1699116991
}
1699216992

16993-
public var args: RawPoundSourceLocationArgsSyntax? {
16993+
public var arguments: RawPoundSourceLocationArgsSyntax? {
1699416994
layoutView.children[5].map(RawPoundSourceLocationArgsSyntax.init(raw:))
1699516995
}
1699616996

16997-
public var unexpectedBetweenArgsAndRightParen: RawUnexpectedNodesSyntax? {
16997+
public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? {
1699816998
layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:))
1699916999
}
1700017000

0 commit comments

Comments
 (0)