Skip to content

Commit d3720a9

Browse files
authored
Merge pull request #561 from DougGregor/infix-operator-expr
2 parents 0805792 + 738a5fb commit d3720a9

File tree

15 files changed

+481
-3
lines changed

15 files changed

+481
-3
lines changed

Sources/SwiftSyntax/gyb_generated/Misc.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ extension SyntaxNode {
277277
return ArrowExprSyntax(asSyntaxData)
278278
}
279279

280+
public var isInfixOperatorExpr: Bool { return raw.kind == .infixOperatorExpr }
281+
public var asInfixOperatorExpr: InfixOperatorExprSyntax? {
282+
guard isInfixOperatorExpr else { return nil }
283+
return InfixOperatorExprSyntax(asSyntaxData)
284+
}
285+
280286
public var isFloatLiteralExpr: Bool { return raw.kind == .floatLiteralExpr }
281287
public var asFloatLiteralExpr: FloatLiteralExprSyntax? {
282288
guard isFloatLiteralExpr else { return nil }
@@ -1671,6 +1677,8 @@ extension Syntax {
16711677
return node
16721678
case .arrowExpr(let node):
16731679
return node
1680+
case .infixOperatorExpr(let node):
1681+
return node
16741682
case .floatLiteralExpr(let node):
16751683
return node
16761684
case .tupleExpr(let node):

Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
362362
override open func visitPost(_ node: ArrowExprSyntax) {
363363
visitAnyPost(node._syntaxNode)
364364
}
365+
override open func visit(_ node: InfixOperatorExprSyntax) -> SyntaxVisitorContinueKind {
366+
return visitAny(node._syntaxNode)
367+
}
368+
369+
override open func visitPost(_ node: InfixOperatorExprSyntax) {
370+
visitAnyPost(node._syntaxNode)
371+
}
365372
override open func visit(_ node: FloatLiteralExprSyntax) -> SyntaxVisitorContinueKind {
366373
return visitAny(node._syntaxNode)
367374
}

Sources/SwiftSyntax/gyb_generated/SyntaxBaseNodes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
164164
/// `nil` if the conversion is not possible.
165165
public init?(_ syntax: Syntax) {
166166
switch syntax.raw.kind {
167-
case .unknownExpr, .missingExpr, .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, .regexLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .postfixIfConfigExpr, .editorPlaceholderExpr, .objectLiteralExpr:
167+
case .unknownExpr, .missingExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .awaitExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .infixOperatorExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .regexLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .postfixIfConfigExpr, .editorPlaceholderExpr, .objectLiteralExpr:
168168
self._syntaxNode = syntax
169169
default:
170170
return nil
@@ -178,7 +178,7 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
178178
// Assert that the kind of the given data matches in debug builds.
179179
#if DEBUG
180180
switch data.raw.kind {
181-
case .unknownExpr, .missingExpr, .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, .regexLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .postfixIfConfigExpr, .editorPlaceholderExpr, .objectLiteralExpr:
181+
case .unknownExpr, .missingExpr, .inOutExpr, .poundColumnExpr, .tryExpr, .awaitExpr, .identifierExpr, .superRefExpr, .nilLiteralExpr, .discardAssignmentExpr, .assignmentExpr, .sequenceExpr, .poundLineExpr, .poundFileExpr, .poundFileIDExpr, .poundFilePathExpr, .poundFunctionExpr, .poundDsohandleExpr, .symbolicReferenceExpr, .prefixOperatorExpr, .binaryOperatorExpr, .arrowExpr, .infixOperatorExpr, .floatLiteralExpr, .tupleExpr, .arrayExpr, .dictionaryExpr, .integerLiteralExpr, .booleanLiteralExpr, .ternaryExpr, .memberAccessExpr, .isExpr, .asExpr, .typeExpr, .closureExpr, .unresolvedPatternExpr, .functionCallExpr, .subscriptExpr, .optionalChainingExpr, .forcedValueExpr, .postfixUnaryExpr, .specializeExpr, .stringLiteralExpr, .regexLiteralExpr, .keyPathExpr, .keyPathBaseExpr, .objcKeyPathExpr, .objcSelectorExpr, .postfixIfConfigExpr, .editorPlaceholderExpr, .objectLiteralExpr:
182182
break
183183
default:
184184
fatalError("Unable to create ExprSyntax from \(data.raw.kind)")

Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,60 @@ extension ArrowExprSyntax {
10471047
}
10481048
}
10491049

1050+
public struct InfixOperatorExprSyntaxBuilder {
1051+
private var layout =
1052+
Array<RawSyntax?>(repeating: nil, count: 6)
1053+
1054+
internal init() {}
1055+
1056+
public mutating func useLeftOperand(_ node: ExprSyntax) {
1057+
let idx = InfixOperatorExprSyntax.Cursor.leftOperand.rawValue
1058+
layout[idx] = node.raw
1059+
}
1060+
1061+
public mutating func useOperatorOperand(_ node: ExprSyntax) {
1062+
let idx = InfixOperatorExprSyntax.Cursor.operatorOperand.rawValue
1063+
layout[idx] = node.raw
1064+
}
1065+
1066+
public mutating func useRightOperand(_ node: ExprSyntax) {
1067+
let idx = InfixOperatorExprSyntax.Cursor.rightOperand.rawValue
1068+
layout[idx] = node.raw
1069+
}
1070+
1071+
internal mutating func buildData() -> SyntaxData {
1072+
if (layout[1] == nil) {
1073+
layout[1] = RawSyntax.missing(SyntaxKind.missingExpr)
1074+
}
1075+
if (layout[3] == nil) {
1076+
layout[3] = RawSyntax.missing(SyntaxKind.missingExpr)
1077+
}
1078+
if (layout[5] == nil) {
1079+
layout[5] = RawSyntax.missing(SyntaxKind.missingExpr)
1080+
}
1081+
1082+
return .forRoot(RawSyntax.createAndCalcLength(kind: .infixOperatorExpr,
1083+
layout: layout, presence: .present))
1084+
}
1085+
}
1086+
1087+
extension InfixOperatorExprSyntax {
1088+
/// Creates a `InfixOperatorExprSyntax` using the provided build function.
1089+
/// - Parameter:
1090+
/// - build: A closure that will be invoked in order to initialize
1091+
/// the fields of the syntax node.
1092+
/// This closure is passed a `InfixOperatorExprSyntaxBuilder` which you can use to
1093+
/// incrementally build the structure of the node.
1094+
/// - Returns: A `InfixOperatorExprSyntax` with all the fields populated in the builder
1095+
/// closure.
1096+
public init(_ build: (inout InfixOperatorExprSyntaxBuilder) -> Void) {
1097+
var builder = InfixOperatorExprSyntaxBuilder()
1098+
build(&builder)
1099+
let data = builder.buildData()
1100+
self.init(data)
1101+
}
1102+
}
1103+
10501104
public struct FloatLiteralExprSyntaxBuilder {
10511105
private var layout =
10521106
Array<RawSyntax?>(repeating: nil, count: 2)

Sources/SwiftSyntax/gyb_generated/SyntaxEnum.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public enum SyntaxEnum {
5959
case prefixOperatorExpr(PrefixOperatorExprSyntax)
6060
case binaryOperatorExpr(BinaryOperatorExprSyntax)
6161
case arrowExpr(ArrowExprSyntax)
62+
case infixOperatorExpr(InfixOperatorExprSyntax)
6263
case floatLiteralExpr(FloatLiteralExprSyntax)
6364
case tupleExpr(TupleExprSyntax)
6465
case arrayExpr(ArrayExprSyntax)
@@ -370,6 +371,8 @@ public extension Syntax {
370371
return .binaryOperatorExpr(BinaryOperatorExprSyntax(self)!)
371372
case .arrowExpr:
372373
return .arrowExpr(ArrowExprSyntax(self)!)
374+
case .infixOperatorExpr:
375+
return .infixOperatorExpr(InfixOperatorExprSyntax(self)!)
373376
case .floatLiteralExpr:
374377
return .floatLiteralExpr(FloatLiteralExprSyntax(self)!)
375378
case .tupleExpr:

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,33 @@ public enum SyntaxFactory {
755755
], length: .zero, presence: presence))
756756
return ArrowExprSyntax(data)
757757
}
758+
public static func makeInfixOperatorExpr(_ garbageBeforeLeftOperand: GarbageNodesSyntax? = nil, leftOperand: ExprSyntax, _ garbageBetweenLeftOperandAndOperatorOperand: GarbageNodesSyntax? = nil, operatorOperand: ExprSyntax, _ garbageBetweenOperatorOperandAndRightOperand: GarbageNodesSyntax? = nil, rightOperand: ExprSyntax) -> InfixOperatorExprSyntax {
759+
let layout: [RawSyntax?] = [
760+
garbageBeforeLeftOperand?.raw,
761+
leftOperand.raw,
762+
garbageBetweenLeftOperandAndOperatorOperand?.raw,
763+
operatorOperand.raw,
764+
garbageBetweenOperatorOperandAndRightOperand?.raw,
765+
rightOperand.raw,
766+
]
767+
let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.infixOperatorExpr,
768+
layout: layout, presence: SourcePresence.present)
769+
let data = SyntaxData.forRoot(raw)
770+
return InfixOperatorExprSyntax(data)
771+
}
772+
773+
public static func makeBlankInfixOperatorExpr(presence: SourcePresence = .present) -> InfixOperatorExprSyntax {
774+
let data = SyntaxData.forRoot(RawSyntax.create(kind: .infixOperatorExpr,
775+
layout: [
776+
nil,
777+
RawSyntax.missing(SyntaxKind.missingExpr),
778+
nil,
779+
RawSyntax.missing(SyntaxKind.missingExpr),
780+
nil,
781+
RawSyntax.missing(SyntaxKind.missingExpr),
782+
], length: .zero, presence: presence))
783+
return InfixOperatorExprSyntax(data)
784+
}
758785
public static func makeFloatLiteralExpr(_ garbageBeforeFloatingDigits: GarbageNodesSyntax? = nil, floatingDigits: TokenSyntax) -> FloatLiteralExprSyntax {
759786
let layout: [RawSyntax?] = [
760787
garbageBeforeFloatingDigits?.raw,

Sources/SwiftSyntax/gyb_generated/SyntaxKind.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ internal enum SyntaxKind: CSyntaxKind {
5959
case prefixOperatorExpr = 39
6060
case binaryOperatorExpr = 40
6161
case arrowExpr = 41
62+
case infixOperatorExpr = 268
6263
case floatLiteralExpr = 42
6364
case tupleExpr = 43
6465
case arrayExpr = 44

Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ open class SyntaxRewriter {
324324
return ExprSyntax(visitChildren(node))
325325
}
326326

327+
/// Visit a `InfixOperatorExprSyntax`.
328+
/// - Parameter node: the node that is being visited
329+
/// - Returns: the rewritten node
330+
open func visit(_ node: InfixOperatorExprSyntax) -> ExprSyntax {
331+
return ExprSyntax(visitChildren(node))
332+
}
333+
327334
/// Visit a `FloatLiteralExprSyntax`.
328335
/// - Parameter node: the node that is being visited
329336
/// - Returns: the rewritten node
@@ -2350,6 +2357,16 @@ open class SyntaxRewriter {
23502357
return Syntax(visit(node))
23512358
}
23522359

2360+
/// Implementation detail of visit(_:). Do not call directly.
2361+
private func visitImplInfixOperatorExprSyntax(_ data: SyntaxData) -> Syntax {
2362+
let node = InfixOperatorExprSyntax(data)
2363+
// Accessing _syntaxNode directly is faster than calling Syntax(node)
2364+
visitPre(node._syntaxNode)
2365+
defer { visitPost(node._syntaxNode) }
2366+
if let newNode = visitAny(node._syntaxNode) { return newNode }
2367+
return Syntax(visit(node))
2368+
}
2369+
23532370
/// Implementation detail of visit(_:). Do not call directly.
23542371
private func visitImplFloatLiteralExprSyntax(_ data: SyntaxData) -> Syntax {
23552372
let node = FloatLiteralExprSyntax(data)
@@ -4638,6 +4655,8 @@ open class SyntaxRewriter {
46384655
return visitImplBinaryOperatorExprSyntax
46394656
case .arrowExpr:
46404657
return visitImplArrowExprSyntax
4658+
case .infixOperatorExpr:
4659+
return visitImplInfixOperatorExprSyntax
46414660
case .floatLiteralExpr:
46424661
return visitImplFloatLiteralExprSyntax
46434662
case .tupleExpr:
@@ -5169,6 +5188,8 @@ open class SyntaxRewriter {
51695188
return visitImplBinaryOperatorExprSyntax(data)
51705189
case .arrowExpr:
51715190
return visitImplArrowExprSyntax(data)
5191+
case .infixOperatorExpr:
5192+
return visitImplInfixOperatorExprSyntax(data)
51725193
case .floatLiteralExpr:
51735194
return visitImplFloatLiteralExprSyntax(data)
51745195
case .tupleExpr:

Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ open class SyntaxVisitor {
471471
/// The function called after visiting `ArrowExprSyntax` and its descendents.
472472
/// - node: the node we just finished visiting.
473473
open func visitPost(_ node: ArrowExprSyntax) {}
474+
/// Visiting `InfixOperatorExprSyntax` specifically.
475+
/// - Parameter node: the node we are visiting.
476+
/// - Returns: how should we continue visiting.
477+
open func visit(_ node: InfixOperatorExprSyntax) -> SyntaxVisitorContinueKind {
478+
return .visitChildren
479+
}
480+
481+
/// The function called after visiting `InfixOperatorExprSyntax` and its descendents.
482+
/// - node: the node we just finished visiting.
483+
open func visitPost(_ node: InfixOperatorExprSyntax) {}
474484
/// Visiting `FloatLiteralExprSyntax` specifically.
475485
/// - Parameter node: the node we are visiting.
476486
/// - Returns: how should we continue visiting.
@@ -3172,6 +3182,17 @@ open class SyntaxVisitor {
31723182
visitPost(node)
31733183
}
31743184

3185+
/// Implementation detail of doVisit(_:_:). Do not call directly.
3186+
private func visitImplInfixOperatorExprSyntax(_ data: SyntaxData) {
3187+
let node = InfixOperatorExprSyntax(data)
3188+
let needsChildren = (visit(node) == .visitChildren)
3189+
// Avoid calling into visitChildren if possible.
3190+
if needsChildren && node.raw.numberOfChildren > 0 {
3191+
visitChildren(node)
3192+
}
3193+
visitPost(node)
3194+
}
3195+
31753196
/// Implementation detail of doVisit(_:_:). Do not call directly.
31763197
private func visitImplFloatLiteralExprSyntax(_ data: SyntaxData) {
31773198
let node = FloatLiteralExprSyntax(data)
@@ -5643,6 +5664,8 @@ open class SyntaxVisitor {
56435664
visitImplBinaryOperatorExprSyntax(data)
56445665
case .arrowExpr:
56455666
visitImplArrowExprSyntax(data)
5667+
case .infixOperatorExpr:
5668+
visitImplInfixOperatorExprSyntax(data)
56465669
case .floatLiteralExpr:
56475670
visitImplFloatLiteralExprSyntax(data)
56485671
case .tupleExpr:

0 commit comments

Comments
 (0)