Skip to content

Commit

Permalink
Update code generation for type specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
meg-gupta committed Oct 16, 2024
1 parent 7a531bc commit 783b3c8
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 1,074 deletions.
61 changes: 0 additions & 61 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2679,67 +2679,6 @@ extension LayoutRequirementSyntax {
}
}

extension LifetimeSpecifierArgumentSyntax {
@_spi(Diagnostics)
public enum ParameterOptions: TokenSpecSet {
case identifier
case `self`
case integerLiteral

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.identifier):
self = .identifier
case TokenSpec(.self):
self = .self
case TokenSpec(.integerLiteral):
self = .integerLiteral
default:
return nil
}
}

public init?(token: TokenSyntax) {
switch token {
case TokenSpec(.identifier):
self = .identifier
case TokenSpec(.self):
self = .self
case TokenSpec(.integerLiteral):
self = .integerLiteral
default:
return nil
}
}

var spec: TokenSpec {
switch self {
case .identifier:
return .identifier
case .self:
return .keyword(.self)
case .integerLiteral:
return .integerLiteral
}
}

/// Returns a token that satisfies the `TokenSpec` of this case.
///
/// If the token kind of this spec has variable text, e.g. for an identifier, this returns a token with empty text.
@_spi(Diagnostics)
public var tokenSyntax: TokenSyntax {
switch self {
case .identifier:
return .identifier("")
case .self:
return .keyword(.self)
case .integerLiteral:
return .integerLiteral("")
}
}
}
}

extension MemberTypeSyntax {
@_spi(Diagnostics)
public enum NameOptions: TokenSpecSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? {
return "size"
case \LayoutRequirementSyntax.alignment:
return "alignment"
case \LifetimeSpecifierArgumentSyntax.parameter:
return "parameter reference"
case \MacroDeclSyntax.attributes:
return "attributes"
case \MacroDeclSyntax.modifiers:
Expand Down
32 changes: 0 additions & 32 deletions Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1995,38 +1995,6 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
return "rightParen"
case \LayoutRequirementSyntax.unexpectedAfterRightParen:
return "unexpectedAfterRightParen"
case \LifetimeSpecifierArgumentSyntax.unexpectedBeforeParameter:
return "unexpectedBeforeParameter"
case \LifetimeSpecifierArgumentSyntax.parameter:
return "parameter"
case \LifetimeSpecifierArgumentSyntax.unexpectedBetweenParameterAndTrailingComma:
return "unexpectedBetweenParameterAndTrailingComma"
case \LifetimeSpecifierArgumentSyntax.trailingComma:
return "trailingComma"
case \LifetimeSpecifierArgumentSyntax.unexpectedAfterTrailingComma:
return "unexpectedAfterTrailingComma"
case \LifetimeTypeSpecifierSyntax.unexpectedBeforeDependsOnKeyword:
return "unexpectedBeforeDependsOnKeyword"
case \LifetimeTypeSpecifierSyntax.dependsOnKeyword:
return "dependsOnKeyword"
case \LifetimeTypeSpecifierSyntax.unexpectedBetweenDependsOnKeywordAndLeftParen:
return "unexpectedBetweenDependsOnKeywordAndLeftParen"
case \LifetimeTypeSpecifierSyntax.leftParen:
return "leftParen"
case \LifetimeTypeSpecifierSyntax.unexpectedBetweenLeftParenAndScopedKeyword:
return "unexpectedBetweenLeftParenAndScopedKeyword"
case \LifetimeTypeSpecifierSyntax.scopedKeyword:
return "scopedKeyword"
case \LifetimeTypeSpecifierSyntax.unexpectedBetweenScopedKeywordAndArguments:
return "unexpectedBetweenScopedKeywordAndArguments"
case \LifetimeTypeSpecifierSyntax.arguments:
return "arguments"
case \LifetimeTypeSpecifierSyntax.unexpectedBetweenArgumentsAndRightParen:
return "unexpectedBetweenArgumentsAndRightParen"
case \LifetimeTypeSpecifierSyntax.rightParen:
return "rightParen"
case \LifetimeTypeSpecifierSyntax.unexpectedAfterRightParen:
return "unexpectedAfterRightParen"
case \MacroDeclSyntax.unexpectedBeforeAttributes:
return "unexpectedBeforeAttributes"
case \MacroDeclSyntax.attributes:
Expand Down
14 changes: 0 additions & 14 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
case `default`
case `defer`
case `deinit`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case dependsOn
case deprecated
case derivative
case didSet
Expand Down Expand Up @@ -206,10 +202,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
case reverse
case right
case safe
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case scoped
case `self`
case sending
case `Self`
Expand Down Expand Up @@ -438,8 +430,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
self = .repeat
case "return":
self = .return
case "scoped":
self = .scoped
case "static":
self = .static
case "struct":
Expand Down Expand Up @@ -573,8 +563,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
self = .canImport
case "consuming":
self = .consuming
case "dependsOn":
self = .dependsOn
case "extension":
self = .extension
case "lowerThan":
Expand Down Expand Up @@ -907,7 +895,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
"default",
"defer",
"deinit",
"dependsOn",
"deprecated",
"derivative",
"didSet",
Expand Down Expand Up @@ -997,7 +984,6 @@ public enum Keyword: UInt8, Hashable, Sendable {
"reverse",
"right",
"safe",
"scoped",
"self",
"sending",
"Self",
Expand Down
42 changes: 0 additions & 42 deletions Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1342,48 +1342,6 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
visitAnyPost(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visit(_ node: LifetimeSpecifierArgumentListSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visitPost(_ node: LifetimeSpecifierArgumentListSyntax) {
visitAnyPost(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visit(_ node: LifetimeSpecifierArgumentSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visitPost(_ node: LifetimeSpecifierArgumentSyntax) {
visitAnyPost(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visit(_ node: LifetimeTypeSpecifierSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visitPost(_ node: LifetimeTypeSpecifierSyntax) {
visitAnyPost(node._syntaxNode)
}

override open func visit(_ node: MacroDeclSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,6 @@ extension Syntax {
.node(LabeledSpecializeArgumentSyntax.self),
.node(LabeledStmtSyntax.self),
.node(LayoutRequirementSyntax.self),
.node(LifetimeSpecifierArgumentListSyntax.self),
.node(LifetimeSpecifierArgumentSyntax.self),
.node(LifetimeTypeSpecifierSyntax.self),
.node(MacroDeclSyntax.self),
.node(MacroExpansionDeclSyntax.self),
.node(MacroExpansionExprSyntax.self),
Expand Down
79 changes: 2 additions & 77 deletions Sources/SwiftSyntax/generated/SyntaxCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -884,29 +884,6 @@ public struct LabeledExprListSyntax: SyntaxCollection, SyntaxHashable {
public static let syntaxKind = SyntaxKind.labeledExprList
}

/// - Note: Requires experimental feature `nonescapableTypes`.
///
/// ### Children
///
/// `LifetimeSpecifierArgumentSyntax` `*`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public struct LifetimeSpecifierArgumentListSyntax: SyntaxCollection, SyntaxHashable {
public typealias Element = LifetimeSpecifierArgumentSyntax

public let _syntaxNode: Syntax

public init?(_ node: some SyntaxProtocol) {
guard node.raw.kind == .lifetimeSpecifierArgumentList else {
return nil
}
self._syntaxNode = node._syntaxNode
}

public static let syntaxKind = SyntaxKind.lifetimeSpecifierArgumentList
}

/// ### Children
///
/// ``MemberBlockItemSyntax`` `*`
Expand Down Expand Up @@ -1675,7 +1652,7 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable {

/// ### Children
///
/// (``SimpleTypeSpecifierSyntax`` | `LifetimeTypeSpecifierSyntax`) `*`
/// ``SimpleTypeSpecifierSyntax`` `*`
///
/// ### Contained in
///
Expand All @@ -1684,46 +1661,28 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable {
public enum Element: SyntaxChildChoices, SyntaxHashable {
/// A specifier that can be attached to a type to eg. mark a parameter as `inout` or `consuming`
case simpleTypeSpecifier(SimpleTypeSpecifierSyntax)
/// A specifier that specifies function parameter on whose lifetime a type depends
/// - Note: Requires experimental feature `nonescapableTypes`.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax)

public var _syntaxNode: Syntax {
switch self {
case .simpleTypeSpecifier(let node):
return node._syntaxNode
case .lifetimeTypeSpecifier(let node):
return node._syntaxNode
}
}

public init(_ node: SimpleTypeSpecifierSyntax) {
self = .simpleTypeSpecifier(node)
}

/// - Note: Requires experimental feature `nonescapableTypes`.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public init(_ node: LifetimeTypeSpecifierSyntax) {
self = .lifetimeTypeSpecifier(node)
}

public init?(_ node: __shared some SyntaxProtocol) {
if let node = node.as(SimpleTypeSpecifierSyntax.self) {
self = .simpleTypeSpecifier(node)
} else if let node = node.as(LifetimeTypeSpecifierSyntax.self) {
self = .lifetimeTypeSpecifier(node)
} else {
return nil
}
}

public static var structure: SyntaxNodeStructure {
return .choices([.node(SimpleTypeSpecifierSyntax.self), .node(LifetimeTypeSpecifierSyntax.self)])
return .choices([.node(SimpleTypeSpecifierSyntax.self)])
}

/// Checks if the current syntax node can be cast to ``SimpleTypeSpecifierSyntax``.
Expand All @@ -1747,40 +1706,6 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable {
public func cast(_ syntaxType: SimpleTypeSpecifierSyntax.Type) -> SimpleTypeSpecifierSyntax {
return self.as(SimpleTypeSpecifierSyntax.self)!
}

/// Checks if the current syntax node can be cast to `LifetimeTypeSpecifierSyntax`.
///
/// - Returns: `true` if the node can be cast, `false` otherwise.
/// - Note: Requires experimental feature `nonescapableTypes`.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public func `is`(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> Bool {
return self.as(syntaxType) != nil
}

/// Attempts to cast the current syntax node to `LifetimeTypeSpecifierSyntax`.
///
/// - Returns: An instance of `LifetimeTypeSpecifierSyntax`, or `nil` if the cast fails.
/// - Note: Requires experimental feature `nonescapableTypes`.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public func `as`(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> LifetimeTypeSpecifierSyntax? {
return LifetimeTypeSpecifierSyntax.init(self)
}

/// Force-casts the current syntax node to `LifetimeTypeSpecifierSyntax`.
///
/// - Returns: An instance of `LifetimeTypeSpecifierSyntax`.
/// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast.
/// - Note: Requires experimental feature `nonescapableTypes`.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public func cast(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> LifetimeTypeSpecifierSyntax {
return self.as(LifetimeTypeSpecifierSyntax.self)!
}
}

public let _syntaxNode: Syntax
Expand Down
18 changes: 0 additions & 18 deletions Sources/SwiftSyntax/generated/SyntaxEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,6 @@ public enum SyntaxEnum: Sendable {
case labeledSpecializeArgument(LabeledSpecializeArgumentSyntax)
case labeledStmt(LabeledStmtSyntax)
case layoutRequirement(LayoutRequirementSyntax)
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax)
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax)
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax)
case macroDecl(MacroDeclSyntax)
case macroExpansionDecl(MacroExpansionDeclSyntax)
case macroExpansionExpr(MacroExpansionExprSyntax)
Expand Down Expand Up @@ -641,12 +629,6 @@ extension Syntax {
return .labeledStmt(LabeledStmtSyntax(self)!)
case .layoutRequirement:
return .layoutRequirement(LayoutRequirementSyntax(self)!)
case .lifetimeSpecifierArgumentList:
return .lifetimeSpecifierArgumentList(LifetimeSpecifierArgumentListSyntax(self)!)
case .lifetimeSpecifierArgument:
return .lifetimeSpecifierArgument(LifetimeSpecifierArgumentSyntax(self)!)
case .lifetimeTypeSpecifier:
return .lifetimeTypeSpecifier(LifetimeTypeSpecifierSyntax(self)!)
case .macroDecl:
return .macroDecl(MacroDeclSyntax(self)!)
case .macroExpansionDecl:
Expand Down
Loading

0 comments on commit 783b3c8

Please sign in to comment.