Skip to content

Re-generate gyb for primary associated types -- https://github.com/apple/swift/pull/41640 #366

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
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
16 changes: 16 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,18 @@ extension SyntaxNode {
return GenericParameterSyntax(asSyntaxData)
}

public var isPrimaryAssociatedTypeList: Bool { return raw.kind == .primaryAssociatedTypeList }
public var asPrimaryAssociatedTypeList: PrimaryAssociatedTypeListSyntax? {
guard isPrimaryAssociatedTypeList else { return nil }
return PrimaryAssociatedTypeListSyntax(asSyntaxData)
}

public var isPrimaryAssociatedType: Bool { return raw.kind == .primaryAssociatedType }
public var asPrimaryAssociatedType: PrimaryAssociatedTypeSyntax? {
guard isPrimaryAssociatedType else { return nil }
return PrimaryAssociatedTypeSyntax(asSyntaxData)
}

public var isGenericParameterClause: Bool { return raw.kind == .genericParameterClause }
public var asGenericParameterClause: GenericParameterClauseSyntax? {
guard isGenericParameterClause else { return nil }
Expand Down Expand Up @@ -1897,6 +1909,10 @@ extension Syntax {
return node
case .genericParameter(let node):
return node
case .primaryAssociatedTypeList(let node):
return node
case .primaryAssociatedType(let node):
return node
case .genericParameterClause(let node):
return node
case .conformanceRequirement(let node):
Expand Down
14 changes: 14 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,20 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
override open func visitPost(_ node: GenericParameterSyntax) {
visitAnyPost(node._syntaxNode)
}
override open func visit(_ node: PrimaryAssociatedTypeListSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

override open func visitPost(_ node: PrimaryAssociatedTypeListSyntax) {
visitAnyPost(node._syntaxNode)
}
override open func visit(_ node: PrimaryAssociatedTypeSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

override open func visitPost(_ node: PrimaryAssociatedTypeSyntax) {
visitAnyPost(node._syntaxNode)
}
override open func visit(_ node: GenericParameterClauseSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}
Expand Down
69 changes: 69 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9066,6 +9066,75 @@ extension GenericParameterSyntax {
}
}

public struct PrimaryAssociatedTypeSyntaxBuilder {
private var layout =
Array<RawSyntax?>(repeating: nil, count: 6)

internal init() {}

public mutating func addAttribute(_ elt: Syntax) {
let idx = PrimaryAssociatedTypeSyntax.Cursor.attributes.rawValue
if let list = layout[idx] {
layout[idx] = list.appending(elt.raw)
} else {
layout[idx] = RawSyntax.create(kind: SyntaxKind.attributeList,
layout: [elt.raw], length: elt.raw.totalLength,
presence: SourcePresence.present)
}
}

public mutating func useName(_ node: TokenSyntax) {
let idx = PrimaryAssociatedTypeSyntax.Cursor.name.rawValue
layout[idx] = node.raw
}

public mutating func useColon(_ node: TokenSyntax) {
let idx = PrimaryAssociatedTypeSyntax.Cursor.colon.rawValue
layout[idx] = node.raw
}

public mutating func useInheritedType(_ node: TypeSyntax) {
let idx = PrimaryAssociatedTypeSyntax.Cursor.inheritedType.rawValue
layout[idx] = node.raw
}

public mutating func useInitializer(_ node: TypeInitializerClauseSyntax) {
let idx = PrimaryAssociatedTypeSyntax.Cursor.initializer.rawValue
layout[idx] = node.raw
}

public mutating func useTrailingComma(_ node: TokenSyntax) {
let idx = PrimaryAssociatedTypeSyntax.Cursor.trailingComma.rawValue
layout[idx] = node.raw
}

internal mutating func buildData() -> SyntaxData {
if (layout[1] == nil) {
layout[1] = RawSyntax.missingToken(TokenKind.identifier(""))
}

return .forRoot(RawSyntax.createAndCalcLength(kind: .primaryAssociatedType,
layout: layout, presence: .present))
}
}

extension PrimaryAssociatedTypeSyntax {
/// Creates a `PrimaryAssociatedTypeSyntax` using the provided build function.
/// - Parameter:
/// - build: A closure that will be invoked in order to initialize
/// the fields of the syntax node.
/// This closure is passed a `PrimaryAssociatedTypeSyntaxBuilder` which you can use to
/// incrementally build the structure of the node.
/// - Returns: A `PrimaryAssociatedTypeSyntax` with all the fields populated in the builder
/// closure.
public init(_ build: (inout PrimaryAssociatedTypeSyntaxBuilder) -> Void) {
var builder = PrimaryAssociatedTypeSyntaxBuilder()
build(&builder)
let data = builder.buildData()
self.init(data)
}
}

public struct GenericParameterClauseSyntaxBuilder {
private var layout =
Array<RawSyntax?>(repeating: nil, count: 3)
Expand Down
254 changes: 254 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8978,6 +8978,255 @@ extension GenericParameterListSyntax: BidirectionalCollection {
}
}

/// `PrimaryAssociatedTypeListSyntax` represents a collection of one or more
/// `PrimaryAssociatedTypeSyntax` nodes. PrimaryAssociatedTypeListSyntax behaves
/// as a regular Swift collection, and has accessors that return new
/// versions of the collection with different children.
public struct PrimaryAssociatedTypeListSyntax: SyntaxCollection, SyntaxHashable {
public let _syntaxNode: Syntax

/// Converts the given `Syntax` node to a `PrimaryAssociatedTypeListSyntax` if possible. Returns
/// `nil` if the conversion is not possible.
public init?(_ syntax: Syntax) {
guard syntax.raw.kind == .primaryAssociatedTypeList else { return nil }
self._syntaxNode = syntax
}

/// Creates a Syntax node from the provided root and data. This assumes
/// that the `SyntaxData` is of the correct kind. If it is not, the behaviour
/// is undefined.
internal init(_ data: SyntaxData) {
assert(data.raw.kind == .primaryAssociatedTypeList)
self._syntaxNode = Syntax(data)
}

public var syntaxNodeType: SyntaxProtocol.Type {
return Swift.type(of: self)
}

/// The number of elements, `present` or `missing`, in this collection.
public var count: Int { return raw.numberOfChildren }

/// Creates a new `PrimaryAssociatedTypeListSyntax` by replacing the underlying layout with
/// a different set of raw syntax nodes.
///
/// - Parameter layout: The new list of raw syntax nodes underlying this
/// collection.
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the new layout underlying it.
internal func replacingLayout(
_ layout: [RawSyntax?]) -> PrimaryAssociatedTypeListSyntax {
let newRaw = data.raw.replacingLayout(layout)
let newData = data.replacingSelf(newRaw)
return PrimaryAssociatedTypeListSyntax(newData)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by appending the provided syntax element
/// to the children.
///
/// - Parameter syntax: The element to append.
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with that element appended to the end.
public func appending(
_ syntax: PrimaryAssociatedTypeSyntax) -> PrimaryAssociatedTypeListSyntax {
var newLayout = data.raw.formLayoutArray()
newLayout.append(syntax.raw)
return replacingLayout(newLayout)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by prepending the provided syntax element
/// to the children.
///
/// - Parameter syntax: The element to prepend.
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with that element prepended to the
/// beginning.
public func prepending(
_ syntax: PrimaryAssociatedTypeSyntax) -> PrimaryAssociatedTypeListSyntax {
return inserting(syntax, at: 0)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by inserting the provided syntax element
/// at the provided index in the children.
///
/// - Parameters:
/// - syntax: The element to insert.
/// - index: The index at which to insert the element in the collection.
///
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with that element appended to the end.
public func inserting(_ syntax: PrimaryAssociatedTypeSyntax,
at index: Int) -> PrimaryAssociatedTypeListSyntax {
var newLayout = data.raw.formLayoutArray()
/// Make sure the index is a valid insertion index (0 to 1 past the end)
precondition((newLayout.startIndex...newLayout.endIndex).contains(index),
"inserting node at invalid index \(index)")
newLayout.insert(syntax.raw, at: index)
return replacingLayout(newLayout)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by replacing the syntax element
/// at the provided index.
///
/// - Parameters:
/// - index: The index at which to replace the element in the collection.
/// - syntax: The element to replace with.
///
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the new element at the provided index.
public func replacing(childAt index: Int,
with syntax: PrimaryAssociatedTypeSyntax) -> PrimaryAssociatedTypeListSyntax {
var newLayout = data.raw.formLayoutArray()
/// Make sure the index is a valid index for replacing
precondition((newLayout.startIndex..<newLayout.endIndex).contains(index),
"replacing node at invalid index \(index)")
newLayout[index] = syntax.raw
return replacingLayout(newLayout)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by removing the syntax element at the
/// provided index.
///
/// - Parameter index: The index of the element to remove from the collection.
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the element at the provided index
/// removed.
public func removing(childAt index: Int) -> PrimaryAssociatedTypeListSyntax {
var newLayout = data.raw.formLayoutArray()
newLayout.remove(at: index)
return replacingLayout(newLayout)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by removing the first element.
///
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the first element removed.
public func removingFirst() -> PrimaryAssociatedTypeListSyntax {
var newLayout = data.raw.formLayoutArray()
newLayout.removeFirst()
return replacingLayout(newLayout)
}

/// Creates a new `PrimaryAssociatedTypeListSyntax` by removing the last element.
///
/// - Returns: A new `PrimaryAssociatedTypeListSyntax` with the last element removed.
public func removingLast() -> PrimaryAssociatedTypeListSyntax {
var newLayout = data.raw.formLayoutArray()
newLayout.removeLast()
return replacingLayout(newLayout)
}

/// Returns a new `PrimaryAssociatedTypeListSyntax` with its leading trivia replaced
/// by the provided trivia.
public func withLeadingTrivia(_ leadingTrivia: Trivia) -> PrimaryAssociatedTypeListSyntax {
return PrimaryAssociatedTypeListSyntax(data.withLeadingTrivia(leadingTrivia))
}

/// Returns a new `PrimaryAssociatedTypeListSyntax` with its trailing trivia replaced
/// by the provided trivia.
public func withTrailingTrivia(_ trailingTrivia: Trivia) -> PrimaryAssociatedTypeListSyntax {
return PrimaryAssociatedTypeListSyntax(data.withTrailingTrivia(trailingTrivia))
}

/// Returns a new `PrimaryAssociatedTypeListSyntax` with its leading trivia removed.
public func withoutLeadingTrivia() -> PrimaryAssociatedTypeListSyntax {
return withLeadingTrivia([])
}

/// Returns a new `PrimaryAssociatedTypeListSyntax` with its trailing trivia removed.
public func withoutTrailingTrivia() -> PrimaryAssociatedTypeListSyntax {
return withTrailingTrivia([])
}

/// Returns a new `PrimaryAssociatedTypeListSyntax` with all trivia removed.
public func withoutTrivia() -> PrimaryAssociatedTypeListSyntax {
return withoutLeadingTrivia().withoutTrailingTrivia()
}

/// The leading trivia (spaces, newlines, etc.) associated with this `PrimaryAssociatedTypeListSyntax`.
public var leadingTrivia: Trivia? {
get {
return raw.formLeadingTrivia()
}
set {
self = withLeadingTrivia(newValue ?? [])
}
}

/// The trailing trivia (spaces, newlines, etc.) associated with this `PrimaryAssociatedTypeListSyntax`.
public var trailingTrivia: Trivia? {
get {
return raw.formTrailingTrivia()
}
set {
self = withTrailingTrivia(newValue ?? [])
}
}

public func _validateLayout() {
// Check that all children match the expected element type
assert(self.allSatisfy { node in
return Syntax(node).is(PrimaryAssociatedTypeSyntax.self)
})
}
}

/// Conformance for `PrimaryAssociatedTypeListSyntax` to the `BidirectionalCollection` protocol.
extension PrimaryAssociatedTypeListSyntax: BidirectionalCollection {
public typealias Element = PrimaryAssociatedTypeSyntax
public typealias Index = SyntaxChildrenIndex

public struct Iterator: IteratorProtocol {
private let parent: Syntax
private var iterator: RawSyntaxChildren.Iterator

init(parent: Syntax, rawChildren: RawSyntaxChildren) {
self.parent = parent
self.iterator = rawChildren.makeIterator()
}

public mutating func next() -> PrimaryAssociatedTypeSyntax? {
guard let (raw, info) = self.iterator.next() else {
return nil
}
let absoluteRaw = AbsoluteRawSyntax(raw: raw!, info: info)
let data = SyntaxData(absoluteRaw, parent: parent)
return PrimaryAssociatedTypeSyntax(data)
}
}

public func makeIterator() -> Iterator {
return Iterator(parent: Syntax(self), rawChildren: rawChildren)
}

private var rawChildren: RawSyntaxChildren {
// We know children in a syntax collection cannot be missing. So we can
// use the low-level and faster RawSyntaxChildren collection instead of
// PresentRawSyntaxChildren.
return RawSyntaxChildren(self.data.absoluteRaw)
}

public var startIndex: SyntaxChildrenIndex {
return rawChildren.startIndex
}
public var endIndex: SyntaxChildrenIndex {
return rawChildren.endIndex
}

public func index(after index: SyntaxChildrenIndex) -> SyntaxChildrenIndex {
return rawChildren.index(after: index)
}

public func index(before index: SyntaxChildrenIndex) -> SyntaxChildrenIndex {
return rawChildren.index(before: index)
}

public func distance(from start: SyntaxChildrenIndex, to end: SyntaxChildrenIndex)
-> Int {
return rawChildren.distance(from: start, to: end)
}

public subscript(position: SyntaxChildrenIndex) -> PrimaryAssociatedTypeSyntax {
let (raw, info) = rawChildren[position]
let absoluteRaw = AbsoluteRawSyntax(raw: raw!, info: info)
let data = SyntaxData(absoluteRaw, parent: Syntax(self))
return PrimaryAssociatedTypeSyntax(data)
}
}

/// `CompositionTypeElementListSyntax` represents a collection of one or more
/// `CompositionTypeElementSyntax` nodes. CompositionTypeElementListSyntax behaves
/// as a regular Swift collection, and has accessors that return new
Expand Down Expand Up @@ -10403,6 +10652,11 @@ extension GenericParameterListSyntax: CustomReflectable {
return Mirror(self, unlabeledChildren: self.map{ $0 })
}
}
extension PrimaryAssociatedTypeListSyntax: CustomReflectable {
public var customMirror: Mirror {
return Mirror(self, unlabeledChildren: self.map{ $0 })
}
}
extension CompositionTypeElementListSyntax: CustomReflectable {
public var customMirror: Mirror {
return Mirror(self, unlabeledChildren: self.map{ $0 })
Expand Down
Loading