Skip to content

Commit 7a81af9

Browse files
committed
Re-generate gyb for primary associated types -- swiftlang/swift#41640
1 parent 71cc83f commit 7a81af9

16 files changed

+960
-1
lines changed

Sources/SwiftSyntax/gyb_generated/Misc.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,18 @@ extension SyntaxNode {
12311231
return GenericParameterSyntax(asSyntaxData)
12321232
}
12331233

1234+
public var isPrimaryAssociatedTypeList: Bool { return raw.kind == .primaryAssociatedTypeList }
1235+
public var asPrimaryAssociatedTypeList: PrimaryAssociatedTypeListSyntax? {
1236+
guard isPrimaryAssociatedTypeList else { return nil }
1237+
return PrimaryAssociatedTypeListSyntax(asSyntaxData)
1238+
}
1239+
1240+
public var isPrimaryAssociatedType: Bool { return raw.kind == .primaryAssociatedType }
1241+
public var asPrimaryAssociatedType: PrimaryAssociatedTypeSyntax? {
1242+
guard isPrimaryAssociatedType else { return nil }
1243+
return PrimaryAssociatedTypeSyntax(asSyntaxData)
1244+
}
1245+
12341246
public var isGenericParameterClause: Bool { return raw.kind == .genericParameterClause }
12351247
public var asGenericParameterClause: GenericParameterClauseSyntax? {
12361248
guard isGenericParameterClause else { return nil }
@@ -1897,6 +1909,10 @@ extension Syntax {
18971909
return node
18981910
case .genericParameter(let node):
18991911
return node
1912+
case .primaryAssociatedTypeList(let node):
1913+
return node
1914+
case .primaryAssociatedType(let node):
1915+
return node
19001916
case .genericParameterClause(let node):
19011917
return node
19021918
case .conformanceRequirement(let node):

Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,20 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
14781478
override open func visitPost(_ node: GenericParameterSyntax) {
14791479
visitAnyPost(node._syntaxNode)
14801480
}
1481+
override open func visit(_ node: PrimaryAssociatedTypeListSyntax) -> SyntaxVisitorContinueKind {
1482+
return visitAny(node._syntaxNode)
1483+
}
1484+
1485+
override open func visitPost(_ node: PrimaryAssociatedTypeListSyntax) {
1486+
visitAnyPost(node._syntaxNode)
1487+
}
1488+
override open func visit(_ node: PrimaryAssociatedTypeSyntax) -> SyntaxVisitorContinueKind {
1489+
return visitAny(node._syntaxNode)
1490+
}
1491+
1492+
override open func visitPost(_ node: PrimaryAssociatedTypeSyntax) {
1493+
visitAnyPost(node._syntaxNode)
1494+
}
14811495
override open func visit(_ node: GenericParameterClauseSyntax) -> SyntaxVisitorContinueKind {
14821496
return visitAny(node._syntaxNode)
14831497
}

Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9066,6 +9066,75 @@ extension GenericParameterSyntax {
90669066
}
90679067
}
90689068

9069+
public struct PrimaryAssociatedTypeSyntaxBuilder {
9070+
private var layout =
9071+
Array<RawSyntax?>(repeating: nil, count: 6)
9072+
9073+
internal init() {}
9074+
9075+
public mutating func addAttribute(_ elt: Syntax) {
9076+
let idx = PrimaryAssociatedTypeSyntax.Cursor.attributes.rawValue
9077+
if let list = layout[idx] {
9078+
layout[idx] = list.appending(elt.raw)
9079+
} else {
9080+
layout[idx] = RawSyntax.create(kind: SyntaxKind.attributeList,
9081+
layout: [elt.raw], length: elt.raw.totalLength,
9082+
presence: SourcePresence.present)
9083+
}
9084+
}
9085+
9086+
public mutating func useName(_ node: TokenSyntax) {
9087+
let idx = PrimaryAssociatedTypeSyntax.Cursor.name.rawValue
9088+
layout[idx] = node.raw
9089+
}
9090+
9091+
public mutating func useColon(_ node: TokenSyntax) {
9092+
let idx = PrimaryAssociatedTypeSyntax.Cursor.colon.rawValue
9093+
layout[idx] = node.raw
9094+
}
9095+
9096+
public mutating func useInheritedType(_ node: TypeSyntax) {
9097+
let idx = PrimaryAssociatedTypeSyntax.Cursor.inheritedType.rawValue
9098+
layout[idx] = node.raw
9099+
}
9100+
9101+
public mutating func useInitializer(_ node: TypeInitializerClauseSyntax) {
9102+
let idx = PrimaryAssociatedTypeSyntax.Cursor.initializer.rawValue
9103+
layout[idx] = node.raw
9104+
}
9105+
9106+
public mutating func useTrailingComma(_ node: TokenSyntax) {
9107+
let idx = PrimaryAssociatedTypeSyntax.Cursor.trailingComma.rawValue
9108+
layout[idx] = node.raw
9109+
}
9110+
9111+
internal mutating func buildData() -> SyntaxData {
9112+
if (layout[1] == nil) {
9113+
layout[1] = RawSyntax.missingToken(TokenKind.identifier(""))
9114+
}
9115+
9116+
return .forRoot(RawSyntax.createAndCalcLength(kind: .primaryAssociatedType,
9117+
layout: layout, presence: .present))
9118+
}
9119+
}
9120+
9121+
extension PrimaryAssociatedTypeSyntax {
9122+
/// Creates a `PrimaryAssociatedTypeSyntax` using the provided build function.
9123+
/// - Parameter:
9124+
/// - build: A closure that will be invoked in order to initialize
9125+
/// the fields of the syntax node.
9126+
/// This closure is passed a `PrimaryAssociatedTypeSyntaxBuilder` which you can use to
9127+
/// incrementally build the structure of the node.
9128+
/// - Returns: A `PrimaryAssociatedTypeSyntax` with all the fields populated in the builder
9129+
/// closure.
9130+
public init(_ build: (inout PrimaryAssociatedTypeSyntaxBuilder) -> Void) {
9131+
var builder = PrimaryAssociatedTypeSyntaxBuilder()
9132+
build(&builder)
9133+
let data = builder.buildData()
9134+
self.init(data)
9135+
}
9136+
}
9137+
90699138
public struct GenericParameterClauseSyntaxBuilder {
90709139
private var layout =
90719140
Array<RawSyntax?>(repeating: nil, count: 3)

Sources/SwiftSyntax/gyb_generated/SyntaxCollections.swift

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8978,6 +8978,255 @@ extension GenericParameterListSyntax: BidirectionalCollection {
89788978
}
89798979
}
89808980

8981+
/// `PrimaryAssociatedTypeListSyntax` represents a collection of one or more
8982+
/// `PrimaryAssociatedTypeSyntax` nodes. PrimaryAssociatedTypeListSyntax behaves
8983+
/// as a regular Swift collection, and has accessors that return new
8984+
/// versions of the collection with different children.
8985+
public struct PrimaryAssociatedTypeListSyntax: SyntaxCollection, SyntaxHashable {
8986+
public let _syntaxNode: Syntax
8987+
8988+
/// Converts the given `Syntax` node to a `PrimaryAssociatedTypeListSyntax` if possible. Returns
8989+
/// `nil` if the conversion is not possible.
8990+
public init?(_ syntax: Syntax) {
8991+
guard syntax.raw.kind == .primaryAssociatedTypeList else { return nil }
8992+
self._syntaxNode = syntax
8993+
}
8994+
8995+
/// Creates a Syntax node from the provided root and data. This assumes
8996+
/// that the `SyntaxData` is of the correct kind. If it is not, the behaviour
8997+
/// is undefined.
8998+
internal init(_ data: SyntaxData) {
8999+
assert(data.raw.kind == .primaryAssociatedTypeList)
9000+
self._syntaxNode = Syntax(data)
9001+
}
9002+
9003+
public var syntaxNodeType: SyntaxProtocol.Type {
9004+
return Swift.type(of: self)
9005+
}
9006+
9007+
/// The number of elements, `present` or `missing`, in this collection.
9008+
public var count: Int { return raw.numberOfChildren }
9009+
9010+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by replacing the underlying layout with
9011+
/// a different set of raw syntax nodes.
9012+
///
9013+
/// - Parameter layout: The new list of raw syntax nodes underlying this
9014+
/// collection.
9015+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the new layout underlying it.
9016+
internal func replacingLayout(
9017+
_ layout: [RawSyntax?]) -> PrimaryAssociatedTypeListSyntax {
9018+
let newRaw = data.raw.replacingLayout(layout)
9019+
let newData = data.replacingSelf(newRaw)
9020+
return PrimaryAssociatedTypeListSyntax(newData)
9021+
}
9022+
9023+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by appending the provided syntax element
9024+
/// to the children.
9025+
///
9026+
/// - Parameter syntax: The element to append.
9027+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with that element appended to the end.
9028+
public func appending(
9029+
_ syntax: PrimaryAssociatedTypeSyntax) -> PrimaryAssociatedTypeListSyntax {
9030+
var newLayout = data.raw.formLayoutArray()
9031+
newLayout.append(syntax.raw)
9032+
return replacingLayout(newLayout)
9033+
}
9034+
9035+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by prepending the provided syntax element
9036+
/// to the children.
9037+
///
9038+
/// - Parameter syntax: The element to prepend.
9039+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with that element prepended to the
9040+
/// beginning.
9041+
public func prepending(
9042+
_ syntax: PrimaryAssociatedTypeSyntax) -> PrimaryAssociatedTypeListSyntax {
9043+
return inserting(syntax, at: 0)
9044+
}
9045+
9046+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by inserting the provided syntax element
9047+
/// at the provided index in the children.
9048+
///
9049+
/// - Parameters:
9050+
/// - syntax: The element to insert.
9051+
/// - index: The index at which to insert the element in the collection.
9052+
///
9053+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with that element appended to the end.
9054+
public func inserting(_ syntax: PrimaryAssociatedTypeSyntax,
9055+
at index: Int) -> PrimaryAssociatedTypeListSyntax {
9056+
var newLayout = data.raw.formLayoutArray()
9057+
/// Make sure the index is a valid insertion index (0 to 1 past the end)
9058+
precondition((newLayout.startIndex...newLayout.endIndex).contains(index),
9059+
"inserting node at invalid index \(index)")
9060+
newLayout.insert(syntax.raw, at: index)
9061+
return replacingLayout(newLayout)
9062+
}
9063+
9064+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by replacing the syntax element
9065+
/// at the provided index.
9066+
///
9067+
/// - Parameters:
9068+
/// - index: The index at which to replace the element in the collection.
9069+
/// - syntax: The element to replace with.
9070+
///
9071+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the new element at the provided index.
9072+
public func replacing(childAt index: Int,
9073+
with syntax: PrimaryAssociatedTypeSyntax) -> PrimaryAssociatedTypeListSyntax {
9074+
var newLayout = data.raw.formLayoutArray()
9075+
/// Make sure the index is a valid index for replacing
9076+
precondition((newLayout.startIndex..<newLayout.endIndex).contains(index),
9077+
"replacing node at invalid index \(index)")
9078+
newLayout[index] = syntax.raw
9079+
return replacingLayout(newLayout)
9080+
}
9081+
9082+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by removing the syntax element at the
9083+
/// provided index.
9084+
///
9085+
/// - Parameter index: The index of the element to remove from the collection.
9086+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the element at the provided index
9087+
/// removed.
9088+
public func removing(childAt index: Int) -> PrimaryAssociatedTypeListSyntax {
9089+
var newLayout = data.raw.formLayoutArray()
9090+
newLayout.remove(at: index)
9091+
return replacingLayout(newLayout)
9092+
}
9093+
9094+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by removing the first element.
9095+
///
9096+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the first element removed.
9097+
public func removingFirst() -> PrimaryAssociatedTypeListSyntax {
9098+
var newLayout = data.raw.formLayoutArray()
9099+
newLayout.removeFirst()
9100+
return replacingLayout(newLayout)
9101+
}
9102+
9103+
/// Creates a new `PrimaryAssociatedTypeListSyntax` by removing the last element.
9104+
///
9105+
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the last element removed.
9106+
public func removingLast() -> PrimaryAssociatedTypeListSyntax {
9107+
var newLayout = data.raw.formLayoutArray()
9108+
newLayout.removeLast()
9109+
return replacingLayout(newLayout)
9110+
}
9111+
9112+
/// Returns a new `PrimaryAssociatedTypeListSyntax` with its leading trivia replaced
9113+
/// by the provided trivia.
9114+
public func withLeadingTrivia(_ leadingTrivia: Trivia) -> PrimaryAssociatedTypeListSyntax {
9115+
return PrimaryAssociatedTypeListSyntax(data.withLeadingTrivia(leadingTrivia))
9116+
}
9117+
9118+
/// Returns a new `PrimaryAssociatedTypeListSyntax` with its trailing trivia replaced
9119+
/// by the provided trivia.
9120+
public func withTrailingTrivia(_ trailingTrivia: Trivia) -> PrimaryAssociatedTypeListSyntax {
9121+
return PrimaryAssociatedTypeListSyntax(data.withTrailingTrivia(trailingTrivia))
9122+
}
9123+
9124+
/// Returns a new `PrimaryAssociatedTypeListSyntax` with its leading trivia removed.
9125+
public func withoutLeadingTrivia() -> PrimaryAssociatedTypeListSyntax {
9126+
return withLeadingTrivia([])
9127+
}
9128+
9129+
/// Returns a new `PrimaryAssociatedTypeListSyntax` with its trailing trivia removed.
9130+
public func withoutTrailingTrivia() -> PrimaryAssociatedTypeListSyntax {
9131+
return withTrailingTrivia([])
9132+
}
9133+
9134+
/// Returns a new `PrimaryAssociatedTypeListSyntax` with all trivia removed.
9135+
public func withoutTrivia() -> PrimaryAssociatedTypeListSyntax {
9136+
return withoutLeadingTrivia().withoutTrailingTrivia()
9137+
}
9138+
9139+
/// The leading trivia (spaces, newlines, etc.) associated with this `PrimaryAssociatedTypeListSyntax`.
9140+
public var leadingTrivia: Trivia? {
9141+
get {
9142+
return raw.formLeadingTrivia()
9143+
}
9144+
set {
9145+
self = withLeadingTrivia(newValue ?? [])
9146+
}
9147+
}
9148+
9149+
/// The trailing trivia (spaces, newlines, etc.) associated with this `PrimaryAssociatedTypeListSyntax`.
9150+
public var trailingTrivia: Trivia? {
9151+
get {
9152+
return raw.formTrailingTrivia()
9153+
}
9154+
set {
9155+
self = withTrailingTrivia(newValue ?? [])
9156+
}
9157+
}
9158+
9159+
public func _validateLayout() {
9160+
// Check that all children match the expected element type
9161+
assert(self.allSatisfy { node in
9162+
return Syntax(node).is(PrimaryAssociatedTypeSyntax.self)
9163+
})
9164+
}
9165+
}
9166+
9167+
/// Conformance for `PrimaryAssociatedTypeListSyntax` to the `BidirectionalCollection` protocol.
9168+
extension PrimaryAssociatedTypeListSyntax: BidirectionalCollection {
9169+
public typealias Element = PrimaryAssociatedTypeSyntax
9170+
public typealias Index = SyntaxChildrenIndex
9171+
9172+
public struct Iterator: IteratorProtocol {
9173+
private let parent: Syntax
9174+
private var iterator: RawSyntaxChildren.Iterator
9175+
9176+
init(parent: Syntax, rawChildren: RawSyntaxChildren) {
9177+
self.parent = parent
9178+
self.iterator = rawChildren.makeIterator()
9179+
}
9180+
9181+
public mutating func next() -> PrimaryAssociatedTypeSyntax? {
9182+
guard let (raw, info) = self.iterator.next() else {
9183+
return nil
9184+
}
9185+
let absoluteRaw = AbsoluteRawSyntax(raw: raw!, info: info)
9186+
let data = SyntaxData(absoluteRaw, parent: parent)
9187+
return PrimaryAssociatedTypeSyntax(data)
9188+
}
9189+
}
9190+
9191+
public func makeIterator() -> Iterator {
9192+
return Iterator(parent: Syntax(self), rawChildren: rawChildren)
9193+
}
9194+
9195+
private var rawChildren: RawSyntaxChildren {
9196+
// We know children in a syntax collection cannot be missing. So we can
9197+
// use the low-level and faster RawSyntaxChildren collection instead of
9198+
// PresentRawSyntaxChildren.
9199+
return RawSyntaxChildren(self.data.absoluteRaw)
9200+
}
9201+
9202+
public var startIndex: SyntaxChildrenIndex {
9203+
return rawChildren.startIndex
9204+
}
9205+
public var endIndex: SyntaxChildrenIndex {
9206+
return rawChildren.endIndex
9207+
}
9208+
9209+
public func index(after index: SyntaxChildrenIndex) -> SyntaxChildrenIndex {
9210+
return rawChildren.index(after: index)
9211+
}
9212+
9213+
public func index(before index: SyntaxChildrenIndex) -> SyntaxChildrenIndex {
9214+
return rawChildren.index(before: index)
9215+
}
9216+
9217+
public func distance(from start: SyntaxChildrenIndex, to end: SyntaxChildrenIndex)
9218+
-> Int {
9219+
return rawChildren.distance(from: start, to: end)
9220+
}
9221+
9222+
public subscript(position: SyntaxChildrenIndex) -> PrimaryAssociatedTypeSyntax {
9223+
let (raw, info) = rawChildren[position]
9224+
let absoluteRaw = AbsoluteRawSyntax(raw: raw!, info: info)
9225+
let data = SyntaxData(absoluteRaw, parent: Syntax(self))
9226+
return PrimaryAssociatedTypeSyntax(data)
9227+
}
9228+
}
9229+
89819230
/// `CompositionTypeElementListSyntax` represents a collection of one or more
89829231
/// `CompositionTypeElementSyntax` nodes. CompositionTypeElementListSyntax behaves
89839232
/// as a regular Swift collection, and has accessors that return new
@@ -10403,6 +10652,11 @@ extension GenericParameterListSyntax: CustomReflectable {
1040310652
return Mirror(self, unlabeledChildren: self.map{ $0 })
1040410653
}
1040510654
}
10655+
extension PrimaryAssociatedTypeListSyntax: CustomReflectable {
10656+
public var customMirror: Mirror {
10657+
return Mirror(self, unlabeledChildren: self.map{ $0 })
10658+
}
10659+
}
1040610660
extension CompositionTypeElementListSyntax: CustomReflectable {
1040710661
public var customMirror: Mirror {
1040810662
return Mirror(self, unlabeledChildren: self.map{ $0 })

0 commit comments

Comments
 (0)