Skip to content

Change children naming inconsistencies between similar/dual syntax nodes #1730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public let ATTRIBUTE_NODES: [Node] = [
documentation: "The colon separating the label and the value"
),
Child(
name: "AvailabilityList",
kind: .collection(kind: .availabilitySpecList, collectionElementName: "Availability")
name: "AvailabilityArguments",
kind: .collection(kind: .availabilitySpecList, collectionElementName: "AvailabilityArgument")
),
Child(
name: "Semicolon",
Expand Down Expand Up @@ -227,8 +227,8 @@ public let ATTRIBUTE_NODES: [Node] = [
documentation: "The colon separating \"before\" and the parameter list."
),
Child(
name: "VersionList",
kind: .collection(kind: .availabilityVersionRestrictionList, collectionElementName: "Availability"),
name: "Platforms",
kind: .collection(kind: .availabilityVersionRestrictionList, collectionElementName: "Platform"),
documentation: "The list of OS versions in which the declaration became ABI stable."
),
]
Expand Down
4 changes: 2 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public let GENERIC_NODES: [Node] = [
kind: .token(choices: [.token(tokenKind: "LeftAngleToken")])
),
Child(
name: "GenericParameterList",
kind: .collection(kind: .genericParameterList, collectionElementName: "GenericParameter")
name: "Parameters",
kind: .collection(kind: .genericParameterList, collectionElementName: "Parameter")
),
Child(
name: "GenericWhereClause",
Expand Down
2 changes: 1 addition & 1 deletion CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public let STMT_NODES: [Node] = [
kind: .token(choices: [.token(tokenKind: "LeftParenToken")])
),
Child(
name: "AvailabilitySpec",
name: "AvailabilityArguments",
kind: .collection(kind: .availabilitySpecList, collectionElementName: "AvailabilityArgument")
),
Child(
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ extension Parser {
label: ident,
unexpectedBeforeColon,
colon: colon,
availabilityList: availability,
availabilityArguments: availability,
unexpectedBeforeSemi,
semicolon: semi,
arena: self.arena
Expand Down Expand Up @@ -949,7 +949,7 @@ extension Parser {
beforeLabel: label,
unexpectedBeforeColon,
colon: colon,
versionList: RawAvailabilityVersionRestrictionListSyntax(elements: elements, arena: self.arena),
platforms: RawAvailabilityVersionRestrictionListSyntax(elements: elements, arena: self.arena),
arena: self.arena
)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ extension Parser {
return RawGenericParameterClauseSyntax(
remainingTokens,
leftAngleBracket: missingToken(.leftAngle),
genericParameterList: RawGenericParameterListSyntax(elements: [], arena: self.arena),
parameters: RawGenericParameterListSyntax(elements: [], arena: self.arena),
genericWhereClause: nil,
rightAngleBracket: missingToken(.rightAngle),
arena: self.arena
Expand Down Expand Up @@ -574,7 +574,7 @@ extension Parser {
}
return RawGenericParameterClauseSyntax(
leftAngleBracket: langle,
genericParameterList: parameters,
parameters: parameters,
genericWhereClause: whereClause,
rightAngleBracket: rangle,
arena: self.arena
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ extension Parser {
precondition(self.at(.poundAvailableKeyword, .poundUnavailableKeyword))
let keyword = self.consumeAnyToken()
let (unexpectedBeforeLParen, lparen) = self.expect(.leftParen)
let spec = self.parseAvailabilitySpecList()
let arguments = self.parseAvailabilitySpecList()
let (unexpectedBeforeRParen, rparen) = self.expect(.rightParen)
let unexpectedAfterRParen: RawUnexpectedNodesSyntax?
if let (equalOperator, falseKeyword) = self.consume(if: { $0.isContextualPunctuator("==") }, followedBy: { TokenSpec.keyword(.false) ~= $0 }) {
Expand All @@ -349,7 +349,7 @@ extension Parser {
availabilityKeyword: keyword,
unexpectedBeforeLParen,
leftParen: lparen,
availabilitySpec: spec,
availabilityArguments: arguments,
unexpectedBeforeRParen,
rightParen: rparen,
unexpectedAfterRParen,
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftRefactor/OpaqueParameterToGeneric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public struct OpaqueParameterToGeneric: RefactoringProvider {

var newGenericParams: [GenericParameterSyntax] = []
if let genericParams {
newGenericParams.append(contentsOf: genericParams.genericParameterList)
newGenericParams.append(contentsOf: genericParams.parameters)
}

for rewritten in rewriter.rewrittenSomeParameters {
Expand All @@ -154,13 +154,13 @@ public struct OpaqueParameterToGeneric: RefactoringProvider {
let newGenericParamClause: GenericParameterClauseSyntax
if let genericParams {
newGenericParamClause = genericParams.with(
\.genericParameterList,
\.parameters,
newGenericParamSyntax
)
} else {
newGenericParamClause = GenericParameterClauseSyntax(
leftAngleBracket: .leftAngleToken(),
genericParameterList: newGenericParamSyntax,
parameters: newGenericParamSyntax,
genericWhereClause: nil,
rightAngleBracket: .rightAngleToken()
)
Expand Down
230 changes: 230 additions & 0 deletions Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,171 @@ public typealias AccessPathComponentSyntax = ImportPathComponentSyntax
@available(*, deprecated, renamed: "WithAttributesSyntax")
public typealias AttributedSyntax = WithAttributesSyntax

public extension AvailabilityConditionSyntax {
@available(*, deprecated, renamed: "unexpectedBetweenLeftParenAndAvailabilityArguments")
var unexpectedBetweenLeftParenAndAvailabilitySpec: UnexpectedNodesSyntax? {
get { unexpectedBetweenLeftParenAndAvailabilityArguments }
set { unexpectedBetweenLeftParenAndAvailabilityArguments = newValue }
}

@available(*, deprecated, renamed: "availabilityArguments")
var availabilitySpec: AvailabilitySpecListSyntax {
get { availabilityArguments }
set { availabilityArguments = newValue }
}

@available(*, deprecated, renamed: "unexpectedBetweenAvailabilityArgumentsAndRightParen")
var unexpectedBetweenAvailabilitySpecAndRightParen: UnexpectedNodesSyntax? {
get { unexpectedBetweenAvailabilityArgumentsAndRightParen }
set { unexpectedBetweenAvailabilityArgumentsAndRightParen = newValue }
}

@available(*, deprecated, message: "Use an initializer with an availabilityArguments argument")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeAvailabilityKeyword: UnexpectedNodesSyntax? = nil,
availabilityKeyword: TokenSyntax,
_ unexpectedBetweenAvailabilityKeywordAndLeftParen: UnexpectedNodesSyntax? = nil,
leftParen: TokenSyntax = .leftParenToken(),
_ unexpectedBetweenLeftParenAndAvailabilitySpec: UnexpectedNodesSyntax? = nil,
availabilitySpec: AvailabilitySpecListSyntax,
_ unexpectedBetweenAvailabilitySpecAndRightParen: UnexpectedNodesSyntax? = nil,
rightParen: TokenSyntax = .rightParenToken(),
_ unexpectedAfterRightParen: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeAvailabilityKeyword,
availabilityKeyword: availabilityKeyword,
unexpectedBetweenAvailabilityKeywordAndLeftParen,
leftParen: leftParen,
unexpectedBetweenLeftParenAndAvailabilitySpec,
availabilityArguments: availabilitySpec,
unexpectedBetweenAvailabilitySpecAndRightParen,
rightParen: rightParen,
unexpectedAfterRightParen,
trailingTrivia: trailingTrivia
)
}
}

public extension AvailabilityEntrySyntax {
@available(*, deprecated, renamed: "unexpectedBetweenColonAndAvailabilityArguments")
var unexpectedBetweenColonAndAvailabilityList: UnexpectedNodesSyntax? {
get { unexpectedBetweenColonAndAvailabilityArguments }
set { unexpectedBetweenColonAndAvailabilityArguments = newValue }
}

@available(*, deprecated, renamed: "availabilityArguments")
var availabilityList: AvailabilitySpecListSyntax {
get { availabilityArguments }
set { availabilityArguments = newValue }
}

@available(*, deprecated, renamed: "unexpectedBetweenAvailabilityArgumentsAndSemicolon")
var unexpectedBetweenAvailabilityListAndSemicolon: UnexpectedNodesSyntax? {
get { unexpectedBetweenAvailabilityArgumentsAndSemicolon }
set { unexpectedBetweenAvailabilityArgumentsAndSemicolon = newValue }
}

/// Adds the provided `element` to the node's `availabilityList`
/// collection.
/// - param element: The new `Availability` to add to the node's
/// `availabilityList` collection.
/// - returns: A copy of the receiver with the provided `Availability`
/// appended to its `availabilityList` collection.
@available(*, deprecated, renamed: "addAvailabilityArgument")
func addAvailability(_ element: AvailabilityArgumentSyntax) -> AvailabilityEntrySyntax {
addAvailabilityArgument(element)
}

@available(*, deprecated, message: "Use an initializer with an availabilityArguments argument")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeLabel: UnexpectedNodesSyntax? = nil,
label: TokenSyntax = .keyword(.availability),
_ unexpectedBetweenLabelAndColon: UnexpectedNodesSyntax? = nil,
colon: TokenSyntax = .colonToken(),
_ unexpectedBetweenColonAndAvailabilityList: UnexpectedNodesSyntax? = nil,
availabilityList: AvailabilitySpecListSyntax,
_ unexpectedBetweenAvailabilityListAndSemicolon: UnexpectedNodesSyntax? = nil,
semicolon: TokenSyntax = .semicolonToken(),
_ unexpectedAfterSemicolon: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeLabel,
label: label,
unexpectedBetweenLabelAndColon,
colon: colon,
unexpectedBetweenColonAndAvailabilityList,
availabilityArguments: availabilityList,
unexpectedBetweenAvailabilityListAndSemicolon,
semicolon: semicolon,
unexpectedAfterSemicolon,
trailingTrivia: trailingTrivia
)
}
}

public extension BackDeployedAttributeSpecListSyntax {
@available(*, deprecated, renamed: "unexpectedBetweenColonAndPlatforms")
var unexpectedBetweenColonAndVersionList: UnexpectedNodesSyntax? {
get { unexpectedBetweenColonAndPlatforms }
set { unexpectedBetweenColonAndPlatforms = newValue }
}

@available(*, deprecated, renamed: "platforms")
var versionList: AvailabilityVersionRestrictionListSyntax {
get { platforms }
set { platforms = newValue }
}

@available(*, deprecated, renamed: "unexpectedAfterPlatforms")
var unexpectedAfterVersionList: UnexpectedNodesSyntax? {
get { unexpectedAfterPlatforms }
set { unexpectedAfterPlatforms = newValue }
}

/// Adds the provided `element` to the node's `versionList`
/// collection.
/// - param element: The new `Availability` to add to the node's
/// `versionList` collection.
/// - returns: A copy of the receiver with the provided `Availability`
/// appended to its `versionList` collection.
@available(*, deprecated, renamed: "addPlatform")
func addAvailability(_ element: AvailabilityVersionRestrictionListEntrySyntax) -> BackDeployedAttributeSpecListSyntax {
addPlatform(element)
}

@available(*, deprecated, message: "Use an initializer with a platforms argument")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeBeforeLabel: UnexpectedNodesSyntax? = nil,
beforeLabel: TokenSyntax = .keyword(.before),
_ unexpectedBetweenBeforeLabelAndColon: UnexpectedNodesSyntax? = nil,
colon: TokenSyntax = .colonToken(),
_ unexpectedBetweenColonAndVersionList: UnexpectedNodesSyntax? = nil,
versionList: AvailabilityVersionRestrictionListSyntax,
_ unexpectedAfterVersionList: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeBeforeLabel,
beforeLabel: beforeLabel,
unexpectedBetweenBeforeLabelAndColon,
colon: colon,
unexpectedBetweenColonAndVersionList,
platforms: versionList,
unexpectedAfterVersionList,
trailingTrivia: trailingTrivia
)
}
}

public extension DeclGroupSyntax {
@available(*, deprecated, renamed: "memberBlock")
var members: MemberDeclBlockSyntax {
Expand Down Expand Up @@ -209,6 +374,66 @@ public extension FunctionTypeSyntax {
}
}

public extension GenericParameterClauseSyntax {
@available(*, deprecated, renamed: "unexpectedBetweenLeftAngleBracketAndParameters")
var unexpectedBetweenLeftAngleBracketAndGenericParameterList: UnexpectedNodesSyntax? {
get { unexpectedBetweenLeftAngleBracketAndParameters }
set { unexpectedBetweenLeftAngleBracketAndParameters = newValue }
}

@available(*, deprecated, renamed: "parameters")
var genericParameterList: GenericParameterListSyntax {
get { parameters }
set { parameters = newValue }
}

@available(*, deprecated, renamed: "unexpectedBetweenParametersAndGenericWhereClause")
var unexpectedBetweenGenericParameterListAndGenericWhereClause: UnexpectedNodesSyntax? {
get { unexpectedBetweenParametersAndGenericWhereClause }
set { unexpectedBetweenParametersAndGenericWhereClause = newValue }
}

/// Adds the provided `element` to the node's `genericParameterList`
/// collection.
/// - param element: The new `GenericParameter` to add to the node's
/// `genericParameterList` collection.
/// - returns: A copy of the receiver with the provided `GenericParameter`
/// appended to its `genericParameterList` collection.
@available(*, deprecated, renamed: "addParameter")
func addGenericParameter(_ element: GenericParameterSyntax) -> GenericParameterClauseSyntax {
addParameter(element)
}

@available(*, deprecated, message: "Use an initializer with a parameters argument")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeLeftAngleBracket: UnexpectedNodesSyntax? = nil,
leftAngleBracket: TokenSyntax = .leftAngleToken(),
_ unexpectedBetweenLeftAngleBracketAndGenericParameterList: UnexpectedNodesSyntax? = nil,
genericParameterList: GenericParameterListSyntax,
_ unexpectedBetweenGenericParameterListAndGenericWhereClause: UnexpectedNodesSyntax? = nil,
genericWhereClause: GenericWhereClauseSyntax? = nil,
_ unexpectedBetweenGenericWhereClauseAndRightAngleBracket: UnexpectedNodesSyntax? = nil,
rightAngleBracket: TokenSyntax = .rightAngleToken(),
_ unexpectedAfterRightAngleBracket: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeLeftAngleBracket,
leftAngleBracket: leftAngleBracket,
unexpectedBetweenLeftAngleBracketAndGenericParameterList,
parameters: genericParameterList,
unexpectedBetweenGenericParameterListAndGenericWhereClause,
genericWhereClause: genericWhereClause,
unexpectedBetweenGenericWhereClauseAndRightAngleBracket,
rightAngleBracket: rightAngleBracket,
unexpectedAfterRightAngleBracket,
trailingTrivia: trailingTrivia
)
}
}

public extension ImportDeclSyntax {
@available(*, deprecated, renamed: "unexpectedBetweenModifiersAndImportKeyword")
var unexpectedBetweenModifiersAndImportTok: UnexpectedNodesSyntax? {
Expand Down Expand Up @@ -386,3 +611,8 @@ public extension TupleExprSyntax {
)
}
}

//==========================================================================//
// IMPORTANT: If you are tempted to add a compatiblity layer code here //
// please insert it in alphabetical order above //
//==========================================================================//
Loading