Skip to content

Commit f905feb

Browse files
authored
Merge pull request #696 from slavapestov/pack-expansion-type-repr
Add syntax node for PackExpansionTypeRepr
2 parents bb8e06c + a6217bb commit f905feb

File tree

21 files changed

+393
-4
lines changed

21 files changed

+393
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
173173
- <doc:SwiftSyntax/ConstrainedSugarTypeSyntax>
174174
- <doc:SwiftSyntax/ImplicitlyUnwrappedOptionalTypeSyntax>
175175
- <doc:SwiftSyntax/CompositionTypeSyntax>
176+
- <doc:SwiftSyntax/PackExpansionTypeSyntax>
176177
- <doc:SwiftSyntax/TupleTypeSyntax>
177178
- <doc:SwiftSyntax/FunctionTypeSyntax>
178179
- <doc:SwiftSyntax/AttributedTypeSyntax>

Sources/SwiftSyntax/Raw/gyb_generated/RawSyntaxNodes.swift

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public struct RawTypeSyntax: RawTypeSyntaxNodeProtocol {
119119

120120
public static func isKindOf(_ raw: RawSyntax) -> Bool {
121121
switch raw.kind {
122-
case .unknownType, .missingType, .simpleTypeIdentifier, .memberTypeIdentifier, .classRestrictionType, .arrayType, .dictionaryType, .metatypeType, .optionalType, .constrainedSugarType, .implicitlyUnwrappedOptionalType, .compositionType, .tupleType, .functionType, .attributedType: return true
122+
case .unknownType, .missingType, .simpleTypeIdentifier, .memberTypeIdentifier, .classRestrictionType, .arrayType, .dictionaryType, .metatypeType, .optionalType, .constrainedSugarType, .implicitlyUnwrappedOptionalType, .compositionType, .packExpansionType, .tupleType, .functionType, .attributedType: return true
123123
default: return false
124124
}
125125
}
@@ -14268,6 +14268,59 @@ public struct RawCompositionTypeSyntax: RawTypeSyntaxNodeProtocol {
1426814268
}
1426914269
}
1427014270

14271+
@_spi(RawSyntax)
14272+
public struct RawPackExpansionTypeSyntax: RawTypeSyntaxNodeProtocol {
14273+
var layoutView: RawSyntaxLayoutView {
14274+
return raw.layoutView!
14275+
}
14276+
14277+
public static func isKindOf(_ raw: RawSyntax) -> Bool {
14278+
return raw.kind == .packExpansionType
14279+
}
14280+
14281+
public var raw: RawSyntax
14282+
init(raw: RawSyntax) {
14283+
assert(Self.isKindOf(raw))
14284+
self.raw = raw
14285+
}
14286+
14287+
public init?<Node: RawSyntaxNodeProtocol>(_ other: Node) {
14288+
guard Self.isKindOf(other.raw) else { return nil }
14289+
self.init(raw: other.raw)
14290+
}
14291+
14292+
public init(
14293+
_ unexpectedBeforePatternType: RawUnexpectedNodesSyntax? = nil,
14294+
patternType: RawTypeSyntax,
14295+
_ unexpectedBetweenPatternTypeAndEllipsis: RawUnexpectedNodesSyntax? = nil,
14296+
ellipsis: RawTokenSyntax,
14297+
arena: __shared SyntaxArena
14298+
) {
14299+
let raw = RawSyntax.makeLayout(
14300+
kind: .packExpansionType, uninitializedCount: 4, arena: arena) { layout in
14301+
layout.initialize(repeating: nil)
14302+
layout[0] = unexpectedBeforePatternType?.raw
14303+
layout[1] = patternType.raw
14304+
layout[2] = unexpectedBetweenPatternTypeAndEllipsis?.raw
14305+
layout[3] = ellipsis.raw
14306+
}
14307+
self.init(raw: raw)
14308+
}
14309+
14310+
public var unexpectedBeforePatternType: RawUnexpectedNodesSyntax? {
14311+
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
14312+
}
14313+
public var patternType: RawTypeSyntax {
14314+
layoutView.children[1].map(RawTypeSyntax.init(raw:))!
14315+
}
14316+
public var unexpectedBetweenPatternTypeAndEllipsis: RawUnexpectedNodesSyntax? {
14317+
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
14318+
}
14319+
public var ellipsis: RawTokenSyntax {
14320+
layoutView.children[3].map(RawTokenSyntax.init(raw:))!
14321+
}
14322+
}
14323+
1427114324
@_spi(RawSyntax)
1427214325
public struct RawTupleTypeElementSyntax: RawSyntaxNodeProtocol {
1427314326
var layoutView: RawSyntaxLayoutView {

Sources/SwiftSyntax/Raw/gyb_generated/RawSyntaxValidation.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,13 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
20422042
_verify(layout[0], as: RawUnexpectedNodesSyntax?.self)
20432043
_verify(layout[1], as: RawCompositionTypeElementListSyntax.self)
20442044
break
2045+
case .packExpansionType:
2046+
assert(layout.count == 4)
2047+
_verify(layout[0], as: RawUnexpectedNodesSyntax?.self)
2048+
_verify(layout[1], as: RawTypeSyntax.self)
2049+
_verify(layout[2], as: RawUnexpectedNodesSyntax?.self)
2050+
_verify(layout[3], as: RawTokenSyntax.self)
2051+
break
20452052
case .tupleTypeElement:
20462053
assert(layout.count == 16)
20472054
_verify(layout[0], as: RawUnexpectedNodesSyntax?.self)

Sources/SwiftSyntax/gyb_generated/Misc.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ extension Syntax {
505505
return node
506506
case .compositionType(let node):
507507
return node
508+
case .packExpansionType(let node):
509+
return node
508510
case .tupleTypeElement(let node):
509511
return node
510512
case .tupleTypeElementList(let node):
@@ -802,6 +804,7 @@ extension SyntaxKind {
802804
case .compositionTypeElement: return CompositionTypeElementSyntax.self
803805
case .compositionTypeElementList: return CompositionTypeElementListSyntax.self
804806
case .compositionType: return CompositionTypeSyntax.self
807+
case .packExpansionType: return PackExpansionTypeSyntax.self
805808
case .tupleTypeElement: return TupleTypeElementSyntax.self
806809
case .tupleTypeElementList: return TupleTypeElementListSyntax.self
807810
case .tupleType: return TupleTypeSyntax.self

Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
17271727
override open func visitPost(_ node: CompositionTypeSyntax) {
17281728
visitAnyPost(node._syntaxNode)
17291729
}
1730+
override open func visit(_ node: PackExpansionTypeSyntax) -> SyntaxVisitorContinueKind {
1731+
return visitAny(node._syntaxNode)
1732+
}
1733+
1734+
override open func visitPost(_ node: PackExpansionTypeSyntax) {
1735+
visitAnyPost(node._syntaxNode)
1736+
}
17301737
override open func visit(_ node: TupleTypeElementSyntax) -> SyntaxVisitorContinueKind {
17311738
return visitAny(node._syntaxNode)
17321739
}

Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
353353
/// `nil` if the conversion is not possible.
354354
public init?(_ syntax: Syntax) {
355355
switch syntax.raw.kind {
356-
case .unknownType, .missingType, .simpleTypeIdentifier, .memberTypeIdentifier, .classRestrictionType, .arrayType, .dictionaryType, .metatypeType, .optionalType, .constrainedSugarType, .implicitlyUnwrappedOptionalType, .compositionType, .tupleType, .functionType, .attributedType:
356+
case .unknownType, .missingType, .simpleTypeIdentifier, .memberTypeIdentifier, .classRestrictionType, .arrayType, .dictionaryType, .metatypeType, .optionalType, .constrainedSugarType, .implicitlyUnwrappedOptionalType, .compositionType, .packExpansionType, .tupleType, .functionType, .attributedType:
357357
self._syntaxNode = syntax
358358
default:
359359
return nil
@@ -367,7 +367,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
367367
// Assert that the kind of the given data matches in debug builds.
368368
#if DEBUG
369369
switch data.raw.kind {
370-
case .unknownType, .missingType, .simpleTypeIdentifier, .memberTypeIdentifier, .classRestrictionType, .arrayType, .dictionaryType, .metatypeType, .optionalType, .constrainedSugarType, .implicitlyUnwrappedOptionalType, .compositionType, .tupleType, .functionType, .attributedType:
370+
case .unknownType, .missingType, .simpleTypeIdentifier, .memberTypeIdentifier, .classRestrictionType, .arrayType, .dictionaryType, .metatypeType, .optionalType, .constrainedSugarType, .implicitlyUnwrappedOptionalType, .compositionType, .packExpansionType, .tupleType, .functionType, .attributedType:
371371
break
372372
default:
373373
fatalError("Unable to create TypeSyntax from \(data.raw.kind)")

Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public enum SyntaxEnum {
254254
case compositionTypeElement(CompositionTypeElementSyntax)
255255
case compositionTypeElementList(CompositionTypeElementListSyntax)
256256
case compositionType(CompositionTypeSyntax)
257+
case packExpansionType(PackExpansionTypeSyntax)
257258
case tupleTypeElement(TupleTypeElementSyntax)
258259
case tupleTypeElementList(TupleTypeElementListSyntax)
259260
case tupleType(TupleTypeSyntax)
@@ -762,6 +763,8 @@ public enum SyntaxEnum {
762763
return nil
763764
case .compositionType:
764765
return "type composition"
766+
case .packExpansionType:
767+
return "variadic expansion"
765768
case .tupleTypeElement:
766769
return nil
767770
case .tupleTypeElementList:
@@ -1300,6 +1303,8 @@ public extension Syntax {
13001303
return .compositionTypeElementList(CompositionTypeElementListSyntax(self)!)
13011304
case .compositionType:
13021305
return .compositionType(CompositionTypeSyntax(self)!)
1306+
case .packExpansionType:
1307+
return .packExpansionType(PackExpansionTypeSyntax(self)!)
13031308
case .tupleTypeElement:
13041309
return .tupleTypeElement(TupleTypeElementSyntax(self)!)
13051310
case .tupleTypeElementList:

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6408,6 +6408,31 @@ public enum SyntaxFactory {
64086408
], arena: .default))
64096409
return CompositionTypeSyntax(data)
64106410
}
6411+
@available(*, deprecated, message: "Use initializer on PackExpansionTypeSyntax")
6412+
public static func makePackExpansionType(_ unexpectedBeforePatternType: UnexpectedNodesSyntax? = nil, patternType: TypeSyntax, _ unexpectedBetweenPatternTypeAndEllipsis: UnexpectedNodesSyntax? = nil, ellipsis: TokenSyntax) -> PackExpansionTypeSyntax {
6413+
let layout: [RawSyntax?] = [
6414+
unexpectedBeforePatternType?.raw,
6415+
patternType.raw,
6416+
unexpectedBetweenPatternTypeAndEllipsis?.raw,
6417+
ellipsis.raw,
6418+
]
6419+
let raw = RawSyntax.makeLayout(kind: SyntaxKind.packExpansionType,
6420+
from: layout, arena: .default)
6421+
let data = SyntaxData.forRoot(raw)
6422+
return PackExpansionTypeSyntax(data)
6423+
}
6424+
6425+
@available(*, deprecated, message: "Use initializer on PackExpansionTypeSyntax")
6426+
public static func makeBlankPackExpansionType(presence: SourcePresence = .present) -> PackExpansionTypeSyntax {
6427+
let data = SyntaxData.forRoot(RawSyntax.makeLayout(kind: .packExpansionType,
6428+
from: [
6429+
nil,
6430+
RawSyntax.makeEmptyLayout(kind: SyntaxKind.missingType, arena: .default),
6431+
nil,
6432+
RawSyntax.makeMissingToken(kind: TokenKind.ellipsis, arena: .default),
6433+
], arena: .default))
6434+
return PackExpansionTypeSyntax(data)
6435+
}
64116436
@available(*, deprecated, message: "Use initializer on TupleTypeElementSyntax")
64126437
public static func makeTupleTypeElement(_ unexpectedBeforeInOut: UnexpectedNodesSyntax? = nil, inOut: TokenSyntax?, _ unexpectedBetweenInOutAndName: UnexpectedNodesSyntax? = nil, name: TokenSyntax?, _ unexpectedBetweenNameAndSecondName: UnexpectedNodesSyntax? = nil, secondName: TokenSyntax?, _ unexpectedBetweenSecondNameAndColon: UnexpectedNodesSyntax? = nil, colon: TokenSyntax?, _ unexpectedBetweenColonAndType: UnexpectedNodesSyntax? = nil, type: TypeSyntax, _ unexpectedBetweenTypeAndEllipsis: UnexpectedNodesSyntax? = nil, ellipsis: TokenSyntax?, _ unexpectedBetweenEllipsisAndInitializer: UnexpectedNodesSyntax? = nil, initializer: InitializerClauseSyntax?, _ unexpectedBetweenInitializerAndTrailingComma: UnexpectedNodesSyntax? = nil, trailingComma: TokenSyntax?) -> TupleTypeElementSyntax {
64136438
let layout: [RawSyntax?] = [

Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public enum SyntaxKind {
255255
case compositionTypeElement
256256
case compositionTypeElementList
257257
case compositionType
258+
case packExpansionType
258259
case tupleTypeElement
259260
case tupleTypeElementList
260261
case tupleType

Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,13 @@ open class SyntaxRewriter {
16891689
return TypeSyntax(visitChildren(node))
16901690
}
16911691

1692+
/// Visit a `PackExpansionTypeSyntax`.
1693+
/// - Parameter node: the node that is being visited
1694+
/// - Returns: the rewritten node
1695+
open func visit(_ node: PackExpansionTypeSyntax) -> TypeSyntax {
1696+
return TypeSyntax(visitChildren(node))
1697+
}
1698+
16921699
/// Visit a `TupleTypeElementSyntax`.
16931700
/// - Parameter node: the node that is being visited
16941701
/// - Returns: the rewritten node
@@ -4335,6 +4342,16 @@ open class SyntaxRewriter {
43354342
return Syntax(visit(node))
43364343
}
43374344

4345+
/// Implementation detail of visit(_:). Do not call directly.
4346+
private func visitImplPackExpansionTypeSyntax(_ data: SyntaxData) -> Syntax {
4347+
let node = PackExpansionTypeSyntax(data)
4348+
// Accessing _syntaxNode directly is faster than calling Syntax(node)
4349+
visitPre(node._syntaxNode)
4350+
defer { visitPost(node._syntaxNode) }
4351+
if let newNode = visitAny(node._syntaxNode) { return newNode }
4352+
return Syntax(visit(node))
4353+
}
4354+
43384355
/// Implementation detail of visit(_:). Do not call directly.
43394356
private func visitImplTupleTypeElementSyntax(_ data: SyntaxData) -> Syntax {
43404357
let node = TupleTypeElementSyntax(data)
@@ -5113,6 +5130,8 @@ open class SyntaxRewriter {
51135130
return visitImplCompositionTypeElementListSyntax
51145131
case .compositionType:
51155132
return visitImplCompositionTypeSyntax
5133+
case .packExpansionType:
5134+
return visitImplPackExpansionTypeSyntax
51165135
case .tupleTypeElement:
51175136
return visitImplTupleTypeElementSyntax
51185137
case .tupleTypeElementList:
@@ -5654,6 +5673,8 @@ open class SyntaxRewriter {
56545673
return visitImplCompositionTypeElementListSyntax(data)
56555674
case .compositionType:
56565675
return visitImplCompositionTypeSyntax(data)
5676+
case .packExpansionType:
5677+
return visitImplPackExpansionTypeSyntax(data)
56575678
case .tupleTypeElement:
56585679
return visitImplTupleTypeElementSyntax(data)
56595680
case .tupleTypeElementList:

Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,16 @@ open class SyntaxVisitor {
24212421
/// The function called after visiting `CompositionTypeSyntax` and its descendents.
24222422
/// - node: the node we just finished visiting.
24232423
open func visitPost(_ node: CompositionTypeSyntax) {}
2424+
/// Visiting `PackExpansionTypeSyntax` specifically.
2425+
/// - Parameter node: the node we are visiting.
2426+
/// - Returns: how should we continue visiting.
2427+
open func visit(_ node: PackExpansionTypeSyntax) -> SyntaxVisitorContinueKind {
2428+
return .visitChildren
2429+
}
2430+
2431+
/// The function called after visiting `PackExpansionTypeSyntax` and its descendents.
2432+
/// - node: the node we just finished visiting.
2433+
open func visitPost(_ node: PackExpansionTypeSyntax) {}
24242434
/// Visiting `TupleTypeElementSyntax` specifically.
24252435
/// - Parameter node: the node we are visiting.
24262436
/// - Returns: how should we continue visiting.
@@ -5367,6 +5377,17 @@ open class SyntaxVisitor {
53675377
visitPost(node)
53685378
}
53695379

5380+
/// Implementation detail of doVisit(_:_:). Do not call directly.
5381+
private func visitImplPackExpansionTypeSyntax(_ data: SyntaxData) {
5382+
let node = PackExpansionTypeSyntax(data)
5383+
let needsChildren = (visit(node) == .visitChildren)
5384+
// Avoid calling into visitChildren if possible.
5385+
if needsChildren && !node.raw.layoutView!.children.isEmpty {
5386+
visitChildren(node)
5387+
}
5388+
visitPost(node)
5389+
}
5390+
53705391
/// Implementation detail of doVisit(_:_:). Do not call directly.
53715392
private func visitImplTupleTypeElementSyntax(_ data: SyntaxData) {
53725393
let node = TupleTypeElementSyntax(data)
@@ -6138,6 +6159,8 @@ open class SyntaxVisitor {
61386159
visitImplCompositionTypeElementListSyntax(data)
61396160
case .compositionType:
61406161
visitImplCompositionTypeSyntax(data)
6162+
case .packExpansionType:
6163+
visitImplPackExpansionTypeSyntax(data)
61416164
case .tupleTypeElement:
61426165
visitImplTupleTypeElementSyntax(data)
61436166
case .tupleTypeElementList:

0 commit comments

Comments
 (0)