Skip to content

[5.5] Update for postfix '#if' expression #282

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
10 changes: 9 additions & 1 deletion Sources/SwiftSyntax/gyb_generated/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ extension SyntaxNode {
return ObjcSelectorExprSyntax(asSyntaxData)
}

public var isPostfixIfConfigExpr: Bool { return raw.kind == .postfixIfConfigExpr }
public var asPostfixIfConfigExpr: PostfixIfConfigExprSyntax? {
guard isPostfixIfConfigExpr else { return nil }
return PostfixIfConfigExprSyntax(asSyntaxData)
}

public var isEditorPlaceholderExpr: Bool { return raw.kind == .editorPlaceholderExpr }
public var asEditorPlaceholderExpr: EditorPlaceholderExprSyntax? {
guard isEditorPlaceholderExpr else { return nil }
Expand Down Expand Up @@ -1621,6 +1627,8 @@ extension Syntax {
return node
case .objcSelectorExpr(let node):
return node
case .postfixIfConfigExpr(let node):
return node
case .editorPlaceholderExpr(let node):
return node
case .objectLiteralExpr(let node):
Expand Down Expand Up @@ -1952,6 +1960,6 @@ extension Syntax {
extension SyntaxParser {
static func verifyNodeDeclarationHash() -> Bool {
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
"468bcd348ceb5f9281692e63d4c80e3333a18211"
"4f85168b3860f575ce60ac0d223fc89da37014df"
}
}
7 changes: 7 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
override open func visitPost(_ node: ObjcSelectorExprSyntax) {
visitAnyPost(node._syntaxNode)
}
override open func visit(_ node: PostfixIfConfigExprSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

override open func visitPost(_ node: PostfixIfConfigExprSyntax) {
visitAnyPost(node._syntaxNode)
}
override open func visit(_ node: EditorPlaceholderExprSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
/// `nil` if the conversion is not possible.
public init?(_ syntax: Syntax) {
switch syntax.raw.kind {
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .awaitExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .editorPlaceholderExpr, .objectLiteralExpr:
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .awaitExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .postfixIfConfigExpr, .editorPlaceholderExpr, .objectLiteralExpr:
self._syntaxNode = syntax
default:
return nil
Expand All @@ -178,7 +178,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
// Assert that the kind of the given data matches in debug builds.
#if DEBUG
switch data.raw.kind {
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .awaitExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .editorPlaceholderExpr, .objectLiteralExpr:
case .unknownExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .awaitExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .postfixIfConfigExpr, .editorPlaceholderExpr, .objectLiteralExpr:
break
default:
fatalError("Unable to create ExprSyntax from \(data.raw.kind)")
Expand Down
46 changes: 46 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,52 @@ extension ObjcSelectorExprSyntax {
}
}

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

internal init() {}

public mutating func useBase(_ node: ExprSyntax) {
let idx = PostfixIfConfigExprSyntax.Cursor.base.rawValue
layout[idx] = node.raw
}

public mutating func useConfig(_ node: IfConfigDeclSyntax) {
let idx = PostfixIfConfigExprSyntax.Cursor.config.rawValue
layout[idx] = node.raw
}

internal mutating func buildData() -> SyntaxData {
if (layout[0] == nil) {
layout[0] = RawSyntax.missing(SyntaxKind.expr)
}
if (layout[1] == nil) {
layout[1] = RawSyntax.missing(SyntaxKind.ifConfigDecl)
}

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

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

public struct EditorPlaceholderExprSyntaxBuilder {
private var layout =
Array<RawSyntax?>(repeating: nil, count: 1)
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public enum SyntaxEnum {
case objcName(ObjcNameSyntax)
case objcKeyPathExpr(ObjcKeyPathExprSyntax)
case objcSelectorExpr(ObjcSelectorExprSyntax)
case postfixIfConfigExpr(PostfixIfConfigExprSyntax)
case editorPlaceholderExpr(EditorPlaceholderExprSyntax)
case objectLiteralExpr(ObjectLiteralExprSyntax)
case typeInitializerClause(TypeInitializerClauseSyntax)
Expand Down Expand Up @@ -428,6 +429,8 @@ public extension Syntax {
return .objcKeyPathExpr(ObjcKeyPathExprSyntax(self)!)
case .objcSelectorExpr:
return .objcSelectorExpr(ObjcSelectorExprSyntax(self)!)
case .postfixIfConfigExpr:
return .postfixIfConfigExpr(PostfixIfConfigExprSyntax(self)!)
case .editorPlaceholderExpr:
return .editorPlaceholderExpr(EditorPlaceholderExprSyntax(self)!)
case .objectLiteralExpr:
Expand Down
19 changes: 19 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,25 @@ public enum SyntaxFactory {
], length: .zero, presence: .present))
return ObjcSelectorExprSyntax(data)
}
public static func makePostfixIfConfigExpr(base: ExprSyntax, config: IfConfigDeclSyntax) -> PostfixIfConfigExprSyntax {
let layout: [RawSyntax?] = [
base.raw,
config.raw,
]
let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.postfixIfConfigExpr,
layout: layout, presence: SourcePresence.present)
let data = SyntaxData.forRoot(raw)
return PostfixIfConfigExprSyntax(data)
}

public static func makeBlankPostfixIfConfigExpr() -> PostfixIfConfigExprSyntax {
let data = SyntaxData.forRoot(RawSyntax.create(kind: .postfixIfConfigExpr,
layout: [
RawSyntax.missing(SyntaxKind.expr),
RawSyntax.missing(SyntaxKind.ifConfigDecl),
], length: .zero, presence: .present))
return PostfixIfConfigExprSyntax(data)
}
public static func makeEditorPlaceholderExpr(identifier: TokenSyntax) -> EditorPlaceholderExprSyntax {
let layout: [RawSyntax?] = [
identifier.raw,
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal enum SyntaxKind: CSyntaxKind {
case objcName = 173
case objcKeyPathExpr = 67
case objcSelectorExpr = 68
case postfixIfConfigExpr = 250
case editorPlaceholderExpr = 69
case objectLiteralExpr = 70
case typeInitializerClause = 107
Expand Down
21 changes: 21 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ open class SyntaxRewriter {
return ExprSyntax(visitChildren(node))
}

/// Visit a `PostfixIfConfigExprSyntax`.
/// - Parameter node: the node that is being visited
/// - Returns: the rewritten node
open func visit(_ node: PostfixIfConfigExprSyntax) -> ExprSyntax {
return ExprSyntax(visitChildren(node))
}

/// Visit a `EditorPlaceholderExprSyntax`.
/// - Parameter node: the node that is being visited
/// - Returns: the rewritten node
Expand Down Expand Up @@ -2523,6 +2530,16 @@ open class SyntaxRewriter {
return Syntax(visit(node))
}

/// Implementation detail of visit(_:). Do not call directly.
private func visitImplPostfixIfConfigExprSyntax(_ data: SyntaxData) -> Syntax {
let node = PostfixIfConfigExprSyntax(data)
// Accessing _syntaxNode directly is faster than calling Syntax(node)
visitPre(node._syntaxNode)
defer { visitPost(node._syntaxNode) }
if let newNode = visitAny(node._syntaxNode) { return newNode }
return Syntax(visit(node))
}

/// Implementation detail of visit(_:). Do not call directly.
private func visitImplEditorPlaceholderExprSyntax(_ data: SyntaxData) -> Syntax {
let node = EditorPlaceholderExprSyntax(data)
Expand Down Expand Up @@ -4355,6 +4372,8 @@ open class SyntaxRewriter {
return visitImplObjcKeyPathExprSyntax
case .objcSelectorExpr:
return visitImplObjcSelectorExprSyntax
case .postfixIfConfigExpr:
return visitImplPostfixIfConfigExprSyntax
case .editorPlaceholderExpr:
return visitImplEditorPlaceholderExprSyntax
case .objectLiteralExpr:
Expand Down Expand Up @@ -4854,6 +4873,8 @@ open class SyntaxRewriter {
return visitImplObjcKeyPathExprSyntax(data)
case .objcSelectorExpr:
return visitImplObjcSelectorExprSyntax(data)
case .postfixIfConfigExpr:
return visitImplPostfixIfConfigExprSyntax(data)
case .editorPlaceholderExpr:
return visitImplEditorPlaceholderExprSyntax(data)
case .objectLiteralExpr:
Expand Down
23 changes: 23 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,16 @@ open class SyntaxVisitor {
/// The function called after visiting `ObjcSelectorExprSyntax` and its descendents.
/// - node: the node we just finished visiting.
open func visitPost(_ node: ObjcSelectorExprSyntax) {}
/// Visiting `PostfixIfConfigExprSyntax` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: how should we continue visiting.
open func visit(_ node: PostfixIfConfigExprSyntax) -> SyntaxVisitorContinueKind {
return .visitChildren
}

/// The function called after visiting `PostfixIfConfigExprSyntax` and its descendents.
/// - node: the node we just finished visiting.
open func visitPost(_ node: PostfixIfConfigExprSyntax) {}
/// Visiting `EditorPlaceholderExprSyntax` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: how should we continue visiting.
Expand Down Expand Up @@ -3305,6 +3315,17 @@ open class SyntaxVisitor {
visitPost(node)
}

/// Implementation detail of doVisit(_:_:). Do not call directly.
private func visitImplPostfixIfConfigExprSyntax(_ data: SyntaxData) {
let node = PostfixIfConfigExprSyntax(data)
let needsChildren = (visit(node) == .visitChildren)
// Avoid calling into visitChildren if possible.
if needsChildren && node.raw.numberOfChildren > 0 {
visitChildren(node)
}
visitPost(node)
}

/// Implementation detail of doVisit(_:_:). Do not call directly.
private func visitImplEditorPlaceholderExprSyntax(_ data: SyntaxData) {
let node = EditorPlaceholderExprSyntax(data)
Expand Down Expand Up @@ -5267,6 +5288,8 @@ open class SyntaxVisitor {
visitImplObjcKeyPathExprSyntax(data)
case .objcSelectorExpr:
visitImplObjcSelectorExprSyntax(data)
case .postfixIfConfigExpr:
visitImplPostfixIfConfigExprSyntax(data)
case .editorPlaceholderExpr:
visitImplEditorPlaceholderExprSyntax(data)
case .objectLiteralExpr:
Expand Down
105 changes: 105 additions & 0 deletions Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxExprNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5246,6 +5246,111 @@ extension ObjcSelectorExprSyntax: CustomReflectable {
}
}

// MARK: - PostfixIfConfigExprSyntax

public struct PostfixIfConfigExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
enum Cursor: Int {
case base
case config
}

public let _syntaxNode: Syntax

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

/// Creates a `PostfixIfConfigExprSyntax` node from the given `SyntaxData`. 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 == .postfixIfConfigExpr)
self._syntaxNode = Syntax(data)
}

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

public var base: ExprSyntax {
get {
let childData = data.child(at: Cursor.base,
parent: Syntax(self))
return ExprSyntax(childData!)
}
set(value) {
self = withBase(value)
}
}

/// Returns a copy of the receiver with its `base` replaced.
/// - param newChild: The new `base` to replace the node's
/// current `base`, if present.
public func withBase(
_ newChild: ExprSyntax?) -> PostfixIfConfigExprSyntax {
let raw = newChild?.raw ?? RawSyntax.missing(SyntaxKind.expr)
let newData = data.replacingChild(raw, at: Cursor.base)
return PostfixIfConfigExprSyntax(newData)
}

public var config: IfConfigDeclSyntax {
get {
let childData = data.child(at: Cursor.config,
parent: Syntax(self))
return IfConfigDeclSyntax(childData!)
}
set(value) {
self = withConfig(value)
}
}

/// Returns a copy of the receiver with its `config` replaced.
/// - param newChild: The new `config` to replace the node's
/// current `config`, if present.
public func withConfig(
_ newChild: IfConfigDeclSyntax?) -> PostfixIfConfigExprSyntax {
let raw = newChild?.raw ?? RawSyntax.missing(SyntaxKind.ifConfigDecl)
let newData = data.replacingChild(raw, at: Cursor.config)
return PostfixIfConfigExprSyntax(newData)
}


public func _validateLayout() {
let rawChildren = Array(RawSyntaxChildren(Syntax(self)))
assert(rawChildren.count == 2)
// Check child #0 child is ExprSyntax
assert(rawChildren[0].raw != nil)
if let raw = rawChildren[0].raw {
let info = rawChildren[0].syntaxInfo
let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info)
let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self))
let syntaxChild = Syntax(syntaxData)
assert(syntaxChild.is(ExprSyntax.self))
}
// Check child #1 child is IfConfigDeclSyntax
assert(rawChildren[1].raw != nil)
if let raw = rawChildren[1].raw {
let info = rawChildren[1].syntaxInfo
let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info)
let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self))
let syntaxChild = Syntax(syntaxData)
assert(syntaxChild.is(IfConfigDeclSyntax.self))
}
}
}

extension PostfixIfConfigExprSyntax: CustomReflectable {
public var customMirror: Mirror {
return Mirror(self, children: [
"base": Syntax(base).asProtocol(SyntaxProtocol.self),
"config": Syntax(config).asProtocol(SyntaxProtocol.self),
])
}
}

// MARK: - EditorPlaceholderExprSyntax

public struct EditorPlaceholderExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
Expand Down