diff --git a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift index 31b8c5b2a36..e97a36685fa 100644 --- a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift @@ -1805,6 +1805,63 @@ public let DECL_NODES: [Node] = [ Node( name: "StructDecl", nameForDiagnostics: "struct", + description: """ + A struct declaration like the following. + + ```swift + struct SomeStruct { + let someMember: String + var anotherMember: Int + + func foo() { + print(someMember) + } + + mutating func bar() { + anotherMember = 42 + } + } + ``` + + A struct declaration may be declared without any members. + + ```swift + struct EmptyStruct { + + } + ``` + + A struct declaration may include a type inheritance clause listing + one or more protocols the struct conforms to. + + The example below uses Hashable and Equatable protocols whose members + are automatically synthesized by the compiler if the struct contains + stored members that are themselves `Hashable` and `Equatable`. + + ```swift + struct AdvancedStruct: Hashable, Equatable { + let someMember: String + var anotherMember: Int + } + ``` + + A struct declaration may include a generic parameter clause as well + as a generic where clause. + + ```swift + struct Stack { + var items: [Element] = [] + + mutating func push(_ item: Element) { + items.append(item) + } + + mutating func pop() -> Element { + return items.removeLast() + } + } + ``` + """, kind: "Decl", traits: [ "DeclGroup", @@ -1816,43 +1873,51 @@ public let DECL_NODES: [Node] = [ name: "Attributes", kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), nameForDiagnostics: "attributes", + description: "Attributes that are attached to the struct declaration.", isOptional: true ), Child( name: "Modifiers", kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), nameForDiagnostics: "modifiers", + description: "Modifiers that are attached to the struct declaration.", isOptional: true ), Child( name: "StructKeyword", - kind: .token(choices: [.keyword(text: "struct")]) + kind: .token(choices: [.keyword(text: "struct")]), + description: "The `struct` keyword for this declaration." ), Child( name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + description: "Declares the name of this struct. If the name matches a reserved keyword use backticks to escape it." ), Child( name: "GenericParameterClause", kind: .node(kind: "GenericParameterClause"), nameForDiagnostics: "generic parameter clause", + description: "The generic parameters, if any, of the struct declaration.", isOptional: true ), Child( name: "InheritanceClause", kind: .node(kind: "TypeInheritanceClause"), nameForDiagnostics: "type inheritance clause", + description: "The struct declaration inheritance clause describing one or more conformances for this struct declaration.", isOptional: true ), Child( name: "GenericWhereClause", kind: .node(kind: "GenericWhereClause"), nameForDiagnostics: "generic where clause", + description: "The `where` clause that applies to the generic parameters of this struct declaration.", isOptional: true ), Child( name: "MemberBlock", - kind: .node(kind: "MemberDeclBlock") + kind: .node(kind: "MemberDeclBlock"), + description: "The members of the struct declaration. Because struct extension declarations may declare additional members the contents of this member block isn't guaranteed to be a complete list of members for this type." ), ] ), diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift index 7c222d03f1a..d351f68cf4c 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift @@ -5117,7 +5117,61 @@ public struct ProtocolDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { // MARK: - StructDeclSyntax - +/// A struct declaration like the following. +/// +/// ```swift +/// struct SomeStruct { +/// let someMember: String +/// var anotherMember: Int +/// +/// func foo() { +/// print(someMember) +/// } +/// +/// mutating func bar() { +/// anotherMember = 42 +/// } +/// } +/// ``` +/// +/// A struct declaration may be declared without any members. +/// +/// ```swift +/// struct EmptyStruct { +/// +/// } +/// ``` +/// +/// A struct declaration may include a type inheritance clause listing +/// one or more protocols the struct conforms to. +/// +/// The example below uses Hashable and Equatable protocols whose members +/// are automatically synthesized by the compiler if the struct contains +/// stored members that are themselves `Hashable` and `Equatable`. +/// +/// ```swift +/// struct AdvancedStruct: Hashable, Equatable { +/// let someMember: String +/// var anotherMember: Int +/// } +/// ``` +/// +/// A struct declaration may include a generic parameter clause as well +/// as a generic where clause. +/// +/// ```swift +/// struct Stack { +/// var items: [Element] = [] +/// +/// mutating func push(_ item: Element) { +/// items.append(item) +/// } +/// +/// mutating func pop() -> Element { +/// return items.removeLast() +/// } +/// } +/// ``` public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { public let _syntaxNode: Syntax @@ -5220,6 +5274,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// Attributes that are attached to the struct declaration. public var attributes: AttributeListSyntax? { get { return data.child(at: 1, parent: Syntax(self)).map(AttributeListSyntax.init) @@ -5257,6 +5312,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// Modifiers that are attached to the struct declaration. public var modifiers: ModifierListSyntax? { get { return data.child(at: 3, parent: Syntax(self)).map(ModifierListSyntax.init) @@ -5294,6 +5350,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// The `struct` keyword for this declaration. public var structKeyword: TokenSyntax { get { return TokenSyntax(data.child(at: 5, parent: Syntax(self))!) @@ -5312,6 +5369,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// Declares the name of this struct. If the name matches a reserved keyword use backticks to escape it. public var identifier: TokenSyntax { get { return TokenSyntax(data.child(at: 7, parent: Syntax(self))!) @@ -5330,6 +5388,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// The generic parameters, if any, of the struct declaration. public var genericParameterClause: GenericParameterClauseSyntax? { get { return data.child(at: 9, parent: Syntax(self)).map(GenericParameterClauseSyntax.init) @@ -5348,6 +5407,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// The struct declaration inheritance clause describing one or more conformances for this struct declaration. public var inheritanceClause: TypeInheritanceClauseSyntax? { get { return data.child(at: 11, parent: Syntax(self)).map(TypeInheritanceClauseSyntax.init) @@ -5366,6 +5426,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// The `where` clause that applies to the generic parameters of this struct declaration. public var genericWhereClause: GenericWhereClauseSyntax? { get { return data.child(at: 13, parent: Syntax(self)).map(GenericWhereClauseSyntax.init) @@ -5384,6 +5445,7 @@ public struct StructDeclSyntax: DeclSyntaxProtocol, SyntaxHashable { } } + /// The members of the struct declaration. Because struct extension declarations may declare additional members the contents of this member block isn't guaranteed to be a complete list of members for this type. public var memberBlock: MemberDeclBlockSyntax { get { return MemberDeclBlockSyntax(data.child(at: 15, parent: Syntax(self))!) diff --git a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift index 6c6984730d8..d430a028291 100644 --- a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift +++ b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift @@ -1171,6 +1171,61 @@ extension SourceFileSyntax { } } +/// A struct declaration like the following. +/// +/// ```swift +/// struct SomeStruct { +/// let someMember: String +/// var anotherMember: Int +/// +/// func foo() { +/// print(someMember) +/// } +/// +/// mutating func bar() { +/// anotherMember = 42 +/// } +/// } +/// ``` +/// +/// A struct declaration may be declared without any members. +/// +/// ```swift +/// struct EmptyStruct { +/// +/// } +/// ``` +/// +/// A struct declaration may include a type inheritance clause listing +/// one or more protocols the struct conforms to. +/// +/// The example below uses Hashable and Equatable protocols whose members +/// are automatically synthesized by the compiler if the struct contains +/// stored members that are themselves `Hashable` and `Equatable`. +/// +/// ```swift +/// struct AdvancedStruct: Hashable, Equatable { +/// let someMember: String +/// var anotherMember: Int +/// } +/// ``` +/// +/// A struct declaration may include a generic parameter clause as well +/// as a generic where clause. +/// +/// ```swift +/// struct Stack { +/// var items: [Element] = [] +/// +/// mutating func push(_ item: Element) { +/// items.append(item) +/// } +/// +/// mutating func pop() -> Element { +/// return items.removeLast() +/// } +/// } +/// ``` extension StructDeclSyntax { /// A convenience initializer that allows initializing syntax collections using result builders public init(