diff --git a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift index 7e644aca816..56c5e75db2b 100644 --- a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift @@ -182,4 +182,29 @@ public let AVAILABILITY_NODES: [Node] = [ ] ), + Node( + kind: .availabilityMacroDefinition, + base: .syntax, + spi: "Compiler", + nameForDiagnostics: "availability macro definition", + documentation: "Syntax for '-define-availability' compiler arguments, never appear in Swift source code", + parserFunction: "parseAvailabilityMacroDefinition", + children: [ + Child( + name: "platformVersion", + kind: .node(kind: .platformVersion) + ), + Child( + name: "colon", + kind: .token(choices: [.token(.colon)]) + ), + Child( + name: "specs", + kind: .collection( + kind: .availabilityArgumentList, + collectionElementName: "AvailabilityArgument" + ) + ), + ] + ), ] diff --git a/CodeGeneration/Sources/SyntaxSupport/Node.swift b/CodeGeneration/Sources/SyntaxSupport/Node.swift index 5c7aba135fa..98b52b3d1d8 100644 --- a/CodeGeneration/Sources/SyntaxSupport/Node.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Node.swift @@ -42,6 +42,9 @@ public class Node: NodeChoiceConvertible { public let experimentalFeature: ExperimentalFeature? + /// SPI name if this node is only available for the SPI. + public let spi: TokenSyntax? + /// When the node name is printed for diagnostics, this name is used. /// If `nil`, `nameForDiagnostics` will print the parent node’s name. public let nameForDiagnostics: String? @@ -103,6 +106,14 @@ public class Node: NodeChoiceConvertible { """ experimentalSPI.with(\.trailingTrivia, .newline) } + if let spi = self.spi { + let spiAttr: AttributeListSyntax = """ + #if compiler(>=5.8) + @_spi(\(spi)) + #endif + """ + spiAttr.with(\.trailingTrivia, .newline) + } if forRaw { "@_spi(RawSyntax)" } @@ -119,6 +130,7 @@ public class Node: NodeChoiceConvertible { kind: SyntaxNodeKind, base: SyntaxNodeKind, experimentalFeature: ExperimentalFeature? = nil, + spi: TokenSyntax? = nil, nameForDiagnostics: String?, documentation: String? = nil, parserFunction: TokenSyntax? = nil, @@ -132,6 +144,7 @@ public class Node: NodeChoiceConvertible { self.kind = kind self.base = base self.experimentalFeature = experimentalFeature + self.spi = spi self.nameForDiagnostics = nameForDiagnostics self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) self.parserFunction = parserFunction @@ -141,6 +154,10 @@ public class Node: NodeChoiceConvertible { self.data = .layout(children: childrenWithUnexpected, childHistory: childHistory, traits: traits) } + public var hiddenInDocumentation: Bool { + self.isExperimental || self.spi != nil || self.kind.isDeprecated + } + /// A doc comment that lists all the nodes in which this node occurs as a child in. public var containedIn: SwiftSyntax.Trivia { if kind == .unexpectedNodes { @@ -149,7 +166,10 @@ public class Node: NodeChoiceConvertible { return [] } var childIn: [(node: SyntaxNodeKind, child: Child?)] = [] - for node in SYNTAX_NODES where !node.isExperimental { + for node in SYNTAX_NODES { + if !self.hiddenInDocumentation && node.hiddenInDocumentation { + continue + } if let layout = node.layoutNode { for child in layout.children { if child.kinds.contains(self.kind) { @@ -202,7 +222,7 @@ public class Node: NodeChoiceConvertible { let list = SYNTAX_NODES - .filter { $0.base == self.kind && !$0.isExperimental && !$0.kind.isDeprecated } + .filter { $0.base == self.kind && (!$0.hiddenInDocumentation || self.hiddenInDocumentation) } .map { "- \($0.kind.doccLink)" } .joined(separator: "\n") @@ -226,6 +246,7 @@ public class Node: NodeChoiceConvertible { kind: SyntaxNodeKind, base: SyntaxNodeKind, experimentalFeature: ExperimentalFeature? = nil, + spi: TokenSyntax? = nil, nameForDiagnostics: String?, documentation: String? = nil, parserFunction: TokenSyntax? = nil, @@ -235,6 +256,7 @@ public class Node: NodeChoiceConvertible { precondition(base == .syntaxCollection) self.base = base self.experimentalFeature = experimentalFeature + self.spi = spi self.nameForDiagnostics = nameForDiagnostics self.documentation = SwiftSyntax.Trivia.docCommentTrivia(from: documentation) self.parserFunction = parserFunction diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift index 5038fa3d39c..99274e5f59c 100644 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift +++ b/CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift @@ -44,6 +44,7 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon case availabilityArgumentList case availabilityCondition case availabilityLabeledArgument + case availabilityMacroDefinition case awaitExpr case backDeployedAttributeArguments case binaryOperatorExpr diff --git a/CodeGeneration/Sources/generate-swift-syntax/ImportSwiftSyntax.swift b/CodeGeneration/Sources/generate-swift-syntax/ImportSwiftSyntax.swift new file mode 100644 index 00000000000..c3fa1ae9c4a --- /dev/null +++ b/CodeGeneration/Sources/generate-swift-syntax/ImportSwiftSyntax.swift @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftSyntax +import SwiftSyntaxBuilder +import SyntaxSupport + +enum ImportAccessLevel { + case `public` + case `internal` +} + +func importSwiftSyntax(accessLevel: ImportAccessLevel = .internal) -> DeclSyntax { + // Import all '@_spi'. + let importingAttrs = AttributeListSyntax { + var seen: Set = [] + AttributeSyntax("@_spi(RawSyntax)").with(\.trailingTrivia, .space) + AttributeSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .space) + for node in NON_BASE_SYNTAX_NODES { + if let spi = node.spi, seen.insert(spi.text).inserted { + AttributeSyntax("@_spi(\(spi))").with(\.trailingTrivia, .space) + } + } + } + let visibilityKeyword: TokenSyntax + switch accessLevel { + case .internal: + visibilityKeyword = "internal" + case .public: + visibilityKeyword = "public" + } + + return DeclSyntax( + """ + #if compiler(>=6) + \(importingAttrs)\(visibilityKeyword) import SwiftSyntax + #else + \(importingAttrs)import SwiftSyntax + #endif + """ + ) +} diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/IsLexerClassifiedFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/IsLexerClassifiedFile.swift index f3272c851db..2be0865dd0c 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/IsLexerClassifiedFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/IsLexerClassifiedFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let isLexerClassifiedFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - public import SwiftSyntax - #else - import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .public) try! ExtensionDeclSyntax( """ diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/LayoutNodesParsableFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/LayoutNodesParsableFile.swift index 0166ff9db5a..7f4f9e41169 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/LayoutNodesParsableFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/LayoutNodesParsableFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let layoutNodesParsableFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(RawSyntax) public import SwiftSyntax - #else - @_spi(RawSyntax) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .public) DeclSyntax( """ diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift index 934018885cf..e5ef05c07c2 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift @@ -27,15 +27,7 @@ func tokenCaseMatch( } let parserTokenSpecSetFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) public import SwiftSyntax - #else - @_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .public) for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode) { for child in layoutNode.children { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift index 3638ba4eba9..7422418b037 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let tokenSpecStaticMembersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(RawSyntax) internal import SwiftSyntax - #else - @_spi(RawSyntax) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax() try! ExtensionDeclSyntax("extension TokenSpec") { for tokenSpec in Token.allCases.map(\.spec) where tokenSpec.kind != .keyword { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift index 11cc8d4585a..3ce953293ac 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let childNameForDiagnosticFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(ExperimentalLanguageFeatures) internal import SwiftSyntax - #else - @_spi(ExperimentalLanguageFeatures) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .internal) try! FunctionDeclSyntax( "private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String?" diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift index 0b460cd0b66..ce6ddb90796 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let syntaxKindNameForDiagnosticFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(ExperimentalLanguageFeatures) internal import SwiftSyntax - #else - @_spi(ExperimentalLanguageFeatures) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax() try! ExtensionDeclSyntax("extension SyntaxKind") { try VariableDeclSyntax("var nameForDiagnostics: String?") { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift index b93f0f30627..da95c6cb4d2 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let tokenNameForDiagnosticFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(RawSyntax) internal import SwiftSyntax - #else - @_spi(RawSyntax) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax() try! ExtensionDeclSyntax("extension TokenKind") { try! VariableDeclSyntax("var nameForDiagnostics: String") { diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift index de3061ffd0d..223664b7f40 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndex.swift @@ -39,7 +39,7 @@ let nodesSections: String = { let baseTypes = ["\(baseKind.syntaxType)", "\(baseKind.syntaxType)Protocol", "Missing\(baseKind.syntaxType)"] let leafTypes = SYNTAX_NODES - .filter({ $0.base == baseKind && !$0.kind.isMissing && !$0.isExperimental && !$0.kind.isDeprecated }) + .filter({ $0.base == baseKind && !$0.kind.isMissing && !$0.hiddenInDocumentation }) .map(\.kind.syntaxType.description) addSection(heading: heading, types: baseTypes + leafTypes) } @@ -51,12 +51,12 @@ let nodesSections: String = { "SyntaxChildrenIndex", ] + SYNTAX_NODES.flatMap({ (node: Node) -> [String] in - guard let node = node.collectionNode, !node.isExperimental else { + guard let node = node.collectionNode, !node.hiddenInDocumentation else { return [] } return [node.kind.syntaxType.description] + node.elementChoices - .filter { SYNTAX_NODE_MAP[$0] != nil && !SYNTAX_NODE_MAP[$0]!.isExperimental && !$0.isDeprecated } + .filter { SYNTAX_NODE_MAP[$0] != nil && !SYNTAX_NODE_MAP[$0]!.hiddenInDocumentation } .map(\.syntaxType.description) .filter { !handledSyntaxTypes.contains($0) } }) @@ -64,13 +64,13 @@ let nodesSections: String = { addSection( heading: "Attributes", - types: ATTRIBUTE_NODES.filter({ !$0.isExperimental && !$0.kind.isDeprecated }).map(\.kind.syntaxType.description) + types: ATTRIBUTE_NODES.filter({ !$0.hiddenInDocumentation }).map(\.kind.syntaxType.description) .sorted() ) addSection( heading: "Miscellaneous Syntax", - types: SYNTAX_NODES.filter({ !$0.isExperimental && !$0.kind.isDeprecated }).map(\.kind.syntaxType.description) + types: SYNTAX_NODES.filter({ !$0.hiddenInDocumentation }).map(\.kind.syntaxType.description) .filter({ !handledSyntaxTypes.contains($0) }) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift index 30224e759f2..ee1956af57f 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/BuildableNodesFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let buildableNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(ExperimentalLanguageFeatures) public import SwiftSyntax - #else - @_spi(ExperimentalLanguageFeatures) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .public) for node in SYNTAX_NODES.compactMap(\.layoutNode) { let type = node.type diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift index 148c6486739..3f08259a46c 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/RenamedChildrenBuilderCompatibilityFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let renamedChildrenBuilderCompatibilityFile = try! SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - public import SwiftSyntax - #else - import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .public) for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode).filter({ !$0.childHistory.isEmpty }) { let deprecatedMembers = SYNTAX_COMPATIBILITY_LAYER.deprecatedMembers(for: layoutNode) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift index 2cba4281108..be6d4fd692b 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/ResultBuildersFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let resultBuildersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - @_spi(ExperimentalLanguageFeatures) public import SwiftSyntax - #else - @_spi(ExperimentalLanguageFeatures) import SwiftSyntax - #endif - """ - ) + importSwiftSyntax(accessLevel: .public) for node in SYNTAX_NODES.compactMap(\.collectionNode) { let type = SyntaxBuildableType(kind: .node(kind: node.kind)) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift index 88d7a8096c8..ba5909e2b00 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift @@ -16,15 +16,7 @@ import SyntaxSupport import Utils let syntaxExpressibleByStringInterpolationConformancesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - #if compiler(>=6) - internal import SwiftSyntax - #else - import SwiftSyntax - #endif - """ - ) + importSwiftSyntax() let typesExpressibleByStringInterpolation = SYNTAX_NODES diff --git a/Sources/SwiftParser/Availability.swift b/Sources/SwiftParser/Availability.swift index fc0979937a2..c18e97b0348 100644 --- a/Sources/SwiftParser/Availability.swift +++ b/Sources/SwiftParser/Availability.swift @@ -304,3 +304,20 @@ extension Parser { } } } + +extension Parser { + /// Parse an argument for '-define-availability' compiler option. + mutating func parseAvailabilityMacroDefinition() -> RawAvailabilityMacroDefinitionSyntax { + let namedAndVersion = self.parsePlatformVersion(allowStarAsVersionNumber: false) + let (unexpectedBetweenPlatformVersionAndColon, colon) = self.expect(.colon) + let specs = self.parseAvailabilitySpecList() + + return RawAvailabilityMacroDefinitionSyntax( + platformVersion: namedAndVersion, + unexpectedBetweenPlatformVersionAndColon, + colon: colon, + specs: specs, + arena: self.arena + ) + } +} diff --git a/Sources/SwiftParser/CollectionNodes+Parsable.swift b/Sources/SwiftParser/CollectionNodes+Parsable.swift index b10b857bd98..91b7e29fbb9 100644 --- a/Sources/SwiftParser/CollectionNodes+Parsable.swift +++ b/Sources/SwiftParser/CollectionNodes+Parsable.swift @@ -72,6 +72,7 @@ extension AccessorDeclListSyntax: SyntaxParseable { parameters: nil, effectSpecifiers: nil, body: nil, + RawUnexpectedNodesSyntax(remainingTokens, arena: arena), arena: arena ) } @@ -89,6 +90,7 @@ extension AttributeListSyntax: SyntaxParseable { leftParen: nil, arguments: nil, rightParen: nil, + RawUnexpectedNodesSyntax(remainingTokens, arena: arena), arena: arena ) } @@ -104,6 +106,7 @@ extension CodeBlockItemListSyntax: SyntaxParseable { RawCodeBlockItemSyntax( item: .init(expr: RawMissingExprSyntax(arena: arena)), semicolon: nil, + RawUnexpectedNodesSyntax(remainingTokens, arena: arena), arena: arena ) } diff --git a/Sources/SwiftParser/generated/IsLexerClassified.swift b/Sources/SwiftParser/generated/IsLexerClassified.swift index 5c7539364fc..2dd640eb70c 100644 --- a/Sources/SwiftParser/generated/IsLexerClassified.swift +++ b/Sources/SwiftParser/generated/IsLexerClassified.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -public import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) public import SwiftSyntax #else -import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension Keyword { diff --git a/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift b/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift index 3f500d283c3..6bc3fda40ee 100644 --- a/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift +++ b/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(RawSyntax) public import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) public import SwiftSyntax #else -@_spi(RawSyntax) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif public protocol SyntaxParseable: SyntaxProtocol { @@ -76,6 +76,24 @@ extension AttributeSyntax: SyntaxParseable { } } +extension AvailabilityMacroDefinitionSyntax: SyntaxParseable { + public static func parse(from parser: inout Parser) -> Self { + // Keep the parser alive so that the arena in which `raw` is allocated + // doesn’t get deallocated before we have a chance to create a syntax node + // from it. We can’t use `parser.arena` as the parameter to + // `Syntax(raw:arena:)` because the node might have been re-used during an + // incremental parse and would then live in a different arena than + // `parser.arena`. + defer { + withExtendedLifetime(parser) { + } + } + let node = parser.parseAvailabilityMacroDefinition() + let raw = RawSyntax(parser.parseRemainder(into: node)) + return Syntax(raw: raw, rawNodeArena: parser.arena).cast(Self.self) + } +} + extension CatchClauseSyntax: SyntaxParseable { public static func parse(from parser: inout Parser) -> Self { // Keep the parser alive so that the arena in which `raw` is allocated diff --git a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift index a36fe84b9df..4fbc92fa67d 100644 --- a/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift +++ b/Sources/SwiftParser/generated/Parser+TokenSpecSet.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) public import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) public import SwiftSyntax #else -@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension AccessorDeclSyntax { diff --git a/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift b/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift index 8a4aed50302..4f9ade357d9 100644 --- a/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift +++ b/Sources/SwiftParser/generated/TokenSpecStaticMembers.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(RawSyntax) internal import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) internal import SwiftSyntax #else -@_spi(RawSyntax) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension TokenSpec { diff --git a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift index bc48ad45b7f..8491eafd390 100644 --- a/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(ExperimentalLanguageFeatures) internal import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) internal import SwiftSyntax #else -@_spi(ExperimentalLanguageFeatures) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? { diff --git a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift index 3bab4943b4f..a254a205b59 100644 --- a/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(ExperimentalLanguageFeatures) internal import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) internal import SwiftSyntax #else -@_spi(ExperimentalLanguageFeatures) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension SyntaxKind { @@ -55,6 +55,8 @@ extension SyntaxKind { return "availability condition" case .availabilityLabeledArgument: return "availability argument" + case .availabilityMacroDefinition: + return "availability macro definition" case .awaitExpr: return "'await' expression" case .backDeployedAttributeArguments: diff --git a/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift b/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift index bea05d8e9d1..7ab068f357b 100644 --- a/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift +++ b/Sources/SwiftParserDiagnostics/generated/TokenNameForDiagnostics.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(RawSyntax) internal import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) internal import SwiftSyntax #else -@_spi(RawSyntax) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension TokenKind { diff --git a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift index 566b0142125..4829d69a06a 100644 --- a/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift +++ b/Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift @@ -301,6 +301,20 @@ public func childName(_ keyPath: AnyKeyPath) -> String? { return "value" case \AvailabilityLabeledArgumentSyntax.unexpectedAfterValue: return "unexpectedAfterValue" + case \AvailabilityMacroDefinitionSyntax.unexpectedBeforePlatformVersion: + return "unexpectedBeforePlatformVersion" + case \AvailabilityMacroDefinitionSyntax.platformVersion: + return "platformVersion" + case \AvailabilityMacroDefinitionSyntax.unexpectedBetweenPlatformVersionAndColon: + return "unexpectedBetweenPlatformVersionAndColon" + case \AvailabilityMacroDefinitionSyntax.colon: + return "colon" + case \AvailabilityMacroDefinitionSyntax.unexpectedBetweenColonAndSpecs: + return "unexpectedBetweenColonAndSpecs" + case \AvailabilityMacroDefinitionSyntax.specs: + return "specs" + case \AvailabilityMacroDefinitionSyntax.unexpectedAfterSpecs: + return "unexpectedAfterSpecs" case \AwaitExprSyntax.unexpectedBeforeAwaitKeyword: return "unexpectedBeforeAwaitKeyword" case \AwaitExprSyntax.awaitKeyword: diff --git a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift index 7289ed7f8e2..640cbf20308 100644 --- a/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift @@ -238,6 +238,20 @@ open class SyntaxAnyVisitor: SyntaxVisitor { visitAnyPost(node._syntaxNode) } + #if compiler(>=5.8) + @_spi(Compiler) + #endif + override open func visit(_ node: AvailabilityMacroDefinitionSyntax) -> SyntaxVisitorContinueKind { + return visitAny(node._syntaxNode) + } + + #if compiler(>=5.8) + @_spi(Compiler) + #endif + override open func visitPost(_ node: AvailabilityMacroDefinitionSyntax) { + visitAnyPost(node._syntaxNode) + } + override open func visit(_ node: AwaitExprSyntax) -> SyntaxVisitorContinueKind { return visitAny(node._syntaxNode) } diff --git a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift index 210d83d4fea..989f9a4aada 100644 --- a/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift +++ b/Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift @@ -1540,6 +1540,7 @@ extension Syntax { .node(AvailabilityArgumentSyntax.self), .node(AvailabilityConditionSyntax.self), .node(AvailabilityLabeledArgumentSyntax.self), + .node(AvailabilityMacroDefinitionSyntax.self), .node(AwaitExprSyntax.self), .node(BackDeployedAttributeArgumentsSyntax.self), .node(BinaryOperatorExprSyntax.self), diff --git a/Sources/SwiftSyntax/generated/SyntaxCollections.swift b/Sources/SwiftSyntax/generated/SyntaxCollections.swift index f265a19a16c..43b043fcae8 100644 --- a/Sources/SwiftSyntax/generated/SyntaxCollections.swift +++ b/Sources/SwiftSyntax/generated/SyntaxCollections.swift @@ -1044,6 +1044,10 @@ public struct LabeledExprListSyntax: SyntaxCollection, SyntaxHashable { /// ### Children /// /// `LifetimeSpecifierArgumentSyntax` `*` +/// +/// ### Contained in +/// +/// - `LifetimeTypeSpecifierSyntax`.`LifetimeTypeSpecifierSyntax/arguments` #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif diff --git a/Sources/SwiftSyntax/generated/SyntaxEnum.swift b/Sources/SwiftSyntax/generated/SyntaxEnum.swift index b801ba4011b..b7c7f1ee883 100644 --- a/Sources/SwiftSyntax/generated/SyntaxEnum.swift +++ b/Sources/SwiftSyntax/generated/SyntaxEnum.swift @@ -40,6 +40,10 @@ public enum SyntaxEnum: Sendable { case availabilityArgument(AvailabilityArgumentSyntax) case availabilityCondition(AvailabilityConditionSyntax) case availabilityLabeledArgument(AvailabilityLabeledArgumentSyntax) + #if compiler(>=5.8) + @_spi(Compiler) + #endif + case availabilityMacroDefinition(AvailabilityMacroDefinitionSyntax) case awaitExpr(AwaitExprSyntax) case backDeployedAttributeArguments(BackDeployedAttributeArgumentsSyntax) case binaryOperatorExpr(BinaryOperatorExprSyntax) @@ -373,6 +377,8 @@ extension Syntax { return .availabilityCondition(AvailabilityConditionSyntax(self)!) case .availabilityLabeledArgument: return .availabilityLabeledArgument(AvailabilityLabeledArgumentSyntax(self)!) + case .availabilityMacroDefinition: + return .availabilityMacroDefinition(AvailabilityMacroDefinitionSyntax(self)!) case .awaitExpr: return .awaitExpr(AwaitExprSyntax(self)!) case .backDeployedAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index b3bd4e49111..9453e146193 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -40,6 +40,10 @@ public enum SyntaxKind: Sendable { case availabilityArgument case availabilityCondition case availabilityLabeledArgument + #if compiler(>=5.8) + @_spi(Compiler) + #endif + case availabilityMacroDefinition case awaitExpr case backDeployedAttributeArguments case binaryOperatorExpr @@ -498,6 +502,8 @@ public enum SyntaxKind: Sendable { return AvailabilityConditionSyntax.self case .availabilityLabeledArgument: return AvailabilityLabeledArgumentSyntax.self + case .availabilityMacroDefinition: + return AvailabilityMacroDefinitionSyntax.self case .awaitExpr: return AwaitExprSyntax.self case .backDeployedAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift index e91d2adb0c8..4321a3c282a 100644 --- a/Sources/SwiftSyntax/generated/SyntaxRewriter.swift +++ b/Sources/SwiftSyntax/generated/SyntaxRewriter.swift @@ -255,6 +255,16 @@ open class SyntaxRewriter { return AvailabilityLabeledArgumentSyntax(unsafeCasting: visitChildren(node._syntaxNode)) } + /// Visit a ``AvailabilityMacroDefinitionSyntax``. + /// - Parameter node: the node that is being visited + /// - Returns: the rewritten node + #if compiler(>=5.8) + @_spi(Compiler) + #endif + open func visit(_ node: AvailabilityMacroDefinitionSyntax) -> AvailabilityMacroDefinitionSyntax { + return AvailabilityMacroDefinitionSyntax(unsafeCasting: visitChildren(node._syntaxNode)) + } + /// Visit a ``AwaitExprSyntax``. /// - Parameter node: the node that is being visited /// - Returns: the rewritten node @@ -2264,6 +2274,11 @@ open class SyntaxRewriter { Syntax(visit(AvailabilityLabeledArgumentSyntax(unsafeCasting: node))) } + @inline(never) + private func visitAvailabilityMacroDefinitionSyntaxImpl(_ node: Syntax) -> Syntax { + Syntax(visit(AvailabilityMacroDefinitionSyntax(unsafeCasting: node))) + } + @inline(never) private func visitAwaitExprSyntaxImpl(_ node: Syntax) -> Syntax { Syntax(visit(AwaitExprSyntax(unsafeCasting: node))) @@ -3651,6 +3666,8 @@ open class SyntaxRewriter { return self.visitAvailabilityConditionSyntaxImpl(_:) case .availabilityLabeledArgument: return self.visitAvailabilityLabeledArgumentSyntaxImpl(_:) + case .availabilityMacroDefinition: + return self.visitAvailabilityMacroDefinitionSyntaxImpl(_:) case .awaitExpr: return self.visitAwaitExprSyntaxImpl(_:) case .backDeployedAttributeArguments: @@ -4231,6 +4248,8 @@ open class SyntaxRewriter { return visitAvailabilityConditionSyntaxImpl(node) case .availabilityLabeledArgument: return visitAvailabilityLabeledArgumentSyntaxImpl(node) + case .availabilityMacroDefinition: + return visitAvailabilityMacroDefinitionSyntaxImpl(node) case .awaitExpr: return visitAwaitExprSyntaxImpl(node) case .backDeployedAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift index 89dbf80a3ad..8d318ccd176 100644 --- a/Sources/SwiftSyntax/generated/SyntaxVisitor.swift +++ b/Sources/SwiftSyntax/generated/SyntaxVisitor.swift @@ -304,6 +304,24 @@ open class SyntaxVisitor { open func visitPost(_ node: AvailabilityLabeledArgumentSyntax) { } + /// Visiting ``AvailabilityMacroDefinitionSyntax`` specifically. + /// - Parameter node: the node we are visiting. + /// - Returns: how should we continue visiting. + #if compiler(>=5.8) + @_spi(Compiler) + #endif + open func visit(_ node: AvailabilityMacroDefinitionSyntax) -> SyntaxVisitorContinueKind { + return .visitChildren + } + + /// The function called after visiting ``AvailabilityMacroDefinitionSyntax`` and its descendants. + /// - node: the node we just finished visiting. + #if compiler(>=5.8) + @_spi(Compiler) + #endif + open func visitPost(_ node: AvailabilityMacroDefinitionSyntax) { + } + /// Visiting ``AwaitExprSyntax`` specifically. /// - Parameter node: the node we are visiting. /// - Returns: how should we continue visiting. @@ -3691,6 +3709,14 @@ open class SyntaxVisitor { visitPost(AvailabilityLabeledArgumentSyntax(unsafeCasting: node)) } + @inline(never) + private func visitAvailabilityMacroDefinitionSyntaxImpl(_ node: Syntax) { + if visit(AvailabilityMacroDefinitionSyntax(unsafeCasting: node)) == .visitChildren { + visitChildren(node) + } + visitPost(AvailabilityMacroDefinitionSyntax(unsafeCasting: node)) + } + @inline(never) private func visitAwaitExprSyntaxImpl(_ node: Syntax) { if visit(AwaitExprSyntax(unsafeCasting: node)) == .visitChildren { @@ -5867,6 +5893,8 @@ open class SyntaxVisitor { return self.visitAvailabilityConditionSyntaxImpl(_:) case .availabilityLabeledArgument: return self.visitAvailabilityLabeledArgumentSyntaxImpl(_:) + case .availabilityMacroDefinition: + return self.visitAvailabilityMacroDefinitionSyntaxImpl(_:) case .awaitExpr: return self.visitAwaitExprSyntaxImpl(_:) case .backDeployedAttributeArguments: @@ -6447,6 +6475,8 @@ open class SyntaxVisitor { self.visitAvailabilityConditionSyntaxImpl(node) case .availabilityLabeledArgument: self.visitAvailabilityLabeledArgumentSyntaxImpl(node) + case .availabilityMacroDefinition: + self.visitAvailabilityMacroDefinitionSyntaxImpl(node) case .awaitExpr: self.visitAwaitExprSyntaxImpl(node) case .backDeployedAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift index e25bab64ee6..9a854415677 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxNodesAB.swift @@ -2098,6 +2098,91 @@ public struct RawAvailabilityLabeledArgumentSyntax: RawSyntaxNodeProtocol { } } +#if compiler(>=5.8) +@_spi(Compiler) +#endif +@_spi(RawSyntax) +public struct RawAvailabilityMacroDefinitionSyntax: RawSyntaxNodeProtocol { + @_spi(RawSyntax) + public var layoutView: RawSyntaxLayoutView { + return raw.layoutView! + } + + public static func isKindOf(_ raw: RawSyntax) -> Bool { + return raw.kind == .availabilityMacroDefinition + } + + public var raw: RawSyntax + + init(raw: RawSyntax) { + precondition(Self.isKindOf(raw)) + self.raw = raw + } + + private init(unchecked raw: RawSyntax) { + self.raw = raw + } + + public init?(_ other: some RawSyntaxNodeProtocol) { + guard Self.isKindOf(other.raw) else { + return nil + } + self.init(unchecked: other.raw) + } + + public init( + _ unexpectedBeforePlatformVersion: RawUnexpectedNodesSyntax? = nil, + platformVersion: RawPlatformVersionSyntax, + _ unexpectedBetweenPlatformVersionAndColon: RawUnexpectedNodesSyntax? = nil, + colon: RawTokenSyntax, + _ unexpectedBetweenColonAndSpecs: RawUnexpectedNodesSyntax? = nil, + specs: RawAvailabilityArgumentListSyntax, + _ unexpectedAfterSpecs: RawUnexpectedNodesSyntax? = nil, + arena: __shared SyntaxArena + ) { + let raw = RawSyntax.makeLayout( + kind: .availabilityMacroDefinition, uninitializedCount: 7, arena: arena) { layout in + layout.initialize(repeating: nil) + layout[0] = unexpectedBeforePlatformVersion?.raw + layout[1] = platformVersion.raw + layout[2] = unexpectedBetweenPlatformVersionAndColon?.raw + layout[3] = colon.raw + layout[4] = unexpectedBetweenColonAndSpecs?.raw + layout[5] = specs.raw + layout[6] = unexpectedAfterSpecs?.raw + } + self.init(unchecked: raw) + } + + public var unexpectedBeforePlatformVersion: RawUnexpectedNodesSyntax? { + layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var platformVersion: RawPlatformVersionSyntax { + layoutView.children[1].map(RawPlatformVersionSyntax.init(raw:))! + } + + public var unexpectedBetweenPlatformVersionAndColon: RawUnexpectedNodesSyntax? { + layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var colon: RawTokenSyntax { + layoutView.children[3].map(RawTokenSyntax.init(raw:))! + } + + public var unexpectedBetweenColonAndSpecs: RawUnexpectedNodesSyntax? { + layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) + } + + public var specs: RawAvailabilityArgumentListSyntax { + layoutView.children[5].map(RawAvailabilityArgumentListSyntax.init(raw:))! + } + + public var unexpectedAfterSpecs: RawUnexpectedNodesSyntax? { + layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:)) + } +} + @_spi(RawSyntax) public struct RawAwaitExprSyntax: RawExprSyntaxNodeProtocol { @_spi(RawSyntax) diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index c46645b2dc1..883699003c3 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -451,6 +451,16 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { verify(layout[5], as: RawSyntax.self)]) assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) } + func validateAvailabilityMacroDefinitionSyntax(kind: SyntaxKind, layout: RawSyntaxBuffer) { + assert(layout.count == 7) + assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 1, verify(layout[1], as: RawPlatformVersionSyntax.self)) + assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.colon)])) + assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) + assertNoError(kind, 5, verify(layout[5], as: RawAvailabilityArgumentListSyntax.self)) + assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) + } func validateAwaitExprSyntax(kind: SyntaxKind, layout: RawSyntaxBuffer) { assert(layout.count == 5) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) @@ -3140,6 +3150,8 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { validateAvailabilityConditionSyntax(kind: kind, layout: layout) case .availabilityLabeledArgument: validateAvailabilityLabeledArgumentSyntax(kind: kind, layout: layout) + case .availabilityMacroDefinition: + validateAvailabilityMacroDefinitionSyntax(kind: kind, layout: layout) case .awaitExpr: validateAwaitExprSyntax(kind: kind, layout: layout) case .backDeployedAttributeArguments: diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift index 8d16c8b8715..12fff476fe6 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift @@ -4564,6 +4564,182 @@ public struct AvailabilityLabeledArgumentSyntax: SyntaxProtocol, SyntaxHashable, ]) } +// MARK: - AvailabilityMacroDefinitionSyntax + +/// Syntax for '-define-availability' compiler arguments, never appear in Swift source code +/// +/// ### Children +/// +/// - `platformVersion`: ``PlatformVersionSyntax`` +/// - `colon`: `:` +/// - `specs`: ``AvailabilityArgumentListSyntax`` +#if compiler(>=5.8) +@_spi(Compiler) +#endif +public struct AvailabilityMacroDefinitionSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { + public let _syntaxNode: Syntax + + public init?(_ node: __shared some SyntaxProtocol) { + guard node.raw.kind == .availabilityMacroDefinition else { + return nil + } + self._syntaxNode = node._syntaxNode + } + + @_transparent + init(unsafeCasting node: Syntax) { + self._syntaxNode = node + } + + /// - Parameters: + /// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + /// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored. + public init( + leadingTrivia: Trivia? = nil, + _ unexpectedBeforePlatformVersion: UnexpectedNodesSyntax? = nil, + platformVersion: PlatformVersionSyntax, + _ unexpectedBetweenPlatformVersionAndColon: UnexpectedNodesSyntax? = nil, + colon: TokenSyntax = .colonToken(), + _ unexpectedBetweenColonAndSpecs: UnexpectedNodesSyntax? = nil, + specs: AvailabilityArgumentListSyntax, + _ unexpectedAfterSpecs: UnexpectedNodesSyntax? = nil, + trailingTrivia: Trivia? = nil + ) { + // Extend the lifetime of all parameters so their arenas don't get destroyed + // before they can be added as children of the new arena. + self = withExtendedLifetime((SyntaxArena(), ( + unexpectedBeforePlatformVersion, + platformVersion, + unexpectedBetweenPlatformVersionAndColon, + colon, + unexpectedBetweenColonAndSpecs, + specs, + unexpectedAfterSpecs + ))) { (arena, _) in + let layout: [RawSyntax?] = [ + unexpectedBeforePlatformVersion?.raw, + platformVersion.raw, + unexpectedBetweenPlatformVersionAndColon?.raw, + colon.raw, + unexpectedBetweenColonAndSpecs?.raw, + specs.raw, + unexpectedAfterSpecs?.raw + ] + let raw = RawSyntax.makeLayout( + kind: SyntaxKind.availabilityMacroDefinition, + from: layout, + arena: arena, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia + ) + return Syntax.forRoot(raw, rawNodeArena: arena).cast(Self.self) + } + } + + public var unexpectedBeforePlatformVersion: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 0)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 0, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + public var platformVersion: PlatformVersionSyntax { + get { + return Syntax(self).child(at: 1)!.cast(PlatformVersionSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 1, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + public var unexpectedBetweenPlatformVersionAndColon: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 2, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + /// ### Tokens + /// + /// For syntax trees generated by the parser, this is guaranteed to be `:`. + public var colon: TokenSyntax { + get { + return Syntax(self).child(at: 3)!.cast(TokenSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + public var unexpectedBetweenColonAndSpecs: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + public var specs: AvailabilityArgumentListSyntax { + get { + return Syntax(self).child(at: 5)!.cast(AvailabilityArgumentListSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 5, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + /// Adds the provided `element` to the node's `specs` + /// collection. + /// + /// - param element: The new `AvailabilityArgument` to add to the node's + /// `specs` collection. + /// - returns: A copy of the receiver with the provided `AvailabilityArgument` + /// appended to its `specs` collection. + @available(*, deprecated, message: "Use node.specs.append(newElement) instead") + public func addAvailabilityArgument(_ element: AvailabilityArgumentSyntax) -> AvailabilityMacroDefinitionSyntax { + var collection: RawSyntax + let arena = SyntaxArena() + if let col = raw.layoutView!.children[5] { + collection = col.layoutView!.appending(element.raw, arena: arena) + } else { + collection = RawSyntax.makeLayout(kind: SyntaxKind.availabilityArgumentList, + from: [element.raw], arena: arena) + } + return Syntax(self) + .replacingChild( + at: 5, + with: collection, + rawNodeArena: arena, + allocationArena: arena + ) + .cast(AvailabilityMacroDefinitionSyntax.self) + } + + public var unexpectedAfterSpecs: UnexpectedNodesSyntax? { + get { + return Syntax(self).child(at: 6)?.cast(UnexpectedNodesSyntax.self) + } + set(value) { + self = Syntax(self).replacingChild(at: 6, with: Syntax(value), arena: SyntaxArena()).cast(AvailabilityMacroDefinitionSyntax.self) + } + } + + public static let structure: SyntaxNodeStructure = .layout([ + \Self.unexpectedBeforePlatformVersion, + \Self.platformVersion, + \Self.unexpectedBetweenPlatformVersionAndColon, + \Self.colon, + \Self.unexpectedBetweenColonAndSpecs, + \Self.specs, + \Self.unexpectedAfterSpecs + ]) +} + // MARK: - AwaitExprSyntax /// ### Children diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift index 9adb3c93d27..466a330a760 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesJKLMN.swift @@ -1670,6 +1670,10 @@ public struct LayoutRequirementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynt /// /// - `parameter`: (`` | `self` | ``) /// - `trailingComma`: `,`? +/// +/// ### Contained in +/// +/// - `LifetimeSpecifierArgumentListSyntax` #if compiler(>=5.8) @_spi(ExperimentalLanguageFeatures) #endif diff --git a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift index 2c9705a89c0..ab70d141759 100644 --- a/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift +++ b/Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift @@ -3942,7 +3942,6 @@ public struct VersionComponentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta /// ### Contained in /// /// - ``AvailabilityLabeledArgumentSyntax``.``AvailabilityLabeledArgumentSyntax/value`` -/// - `_CanImportVersionInfoSyntax`.`_CanImportVersionInfoSyntax/version` /// - ``PlatformVersionSyntax``.``PlatformVersionSyntax/version`` public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol { public let _syntaxNode: Syntax diff --git a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift index fae1d39d232..49072c3ed42 100644 --- a/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift +++ b/Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(ExperimentalLanguageFeatures) public import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) public import SwiftSyntax #else -@_spi(ExperimentalLanguageFeatures) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension AccessorDeclSyntax { diff --git a/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift b/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift index f7f344ef9a9..e25c4145558 100644 --- a/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift +++ b/Sources/SwiftSyntaxBuilder/generated/RenamedChildrenBuilderCompatibility.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -public import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) public import SwiftSyntax #else -import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension AccessorDeclSyntax { diff --git a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift index 910d130b624..75fca9efdfa 100644 --- a/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift +++ b/Sources/SwiftSyntaxBuilder/generated/ResultBuilders.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -@_spi(ExperimentalLanguageFeatures) public import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) public import SwiftSyntax #else -@_spi(ExperimentalLanguageFeatures) import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif // MARK: - AccessorDeclListBuilder diff --git a/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift b/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift index 0fcb2d2be9c..146370fbeb6 100644 --- a/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift +++ b/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if compiler(>=6) -internal import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) internal import SwiftSyntax #else -import SwiftSyntax +@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) @_spi(Compiler) import SwiftSyntax #endif extension AccessorBlockSyntax: SyntaxExpressibleByStringInterpolation {} @@ -36,6 +36,12 @@ extension AttributeSyntax: SyntaxExpressibleByStringInterpolation {} extension AttributeSyntax: Swift.ExpressibleByStringInterpolation {} #endif +extension AvailabilityMacroDefinitionSyntax: SyntaxExpressibleByStringInterpolation {} + +#if compiler(>=6) +extension AvailabilityMacroDefinitionSyntax: Swift.ExpressibleByStringInterpolation {} +#endif + extension CatchClauseSyntax: SyntaxExpressibleByStringInterpolation {} #if compiler(>=6)