Skip to content

Commit 2722ad0

Browse files
authored
Merge pull request #190 from owenv/catch_proposal_updates
Update gyb generated files for multi-pattern catch clauses (SE-0276)
2 parents d571c50 + 76c2e9f commit 2722ad0

File tree

11 files changed

+640
-62
lines changed

11 files changed

+640
-62
lines changed

Sources/SwiftSyntax/gyb_generated/Misc.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,12 @@ extension SyntaxNode {
10411041
return CaseItemListSyntax(asSyntaxData)
10421042
}
10431043

1044+
public var isCatchItemList: Bool { return raw.kind == .catchItemList }
1045+
public var asCatchItemList: CatchItemListSyntax? {
1046+
guard isCatchItemList else { return nil }
1047+
return CatchItemListSyntax(asSyntaxData)
1048+
}
1049+
10441050
public var isConditionElement: Bool { return raw.kind == .conditionElement }
10451051
public var asConditionElement: ConditionElementSyntax? {
10461052
guard isConditionElement else { return nil }
@@ -1119,6 +1125,12 @@ extension SyntaxNode {
11191125
return CaseItemSyntax(asSyntaxData)
11201126
}
11211127

1128+
public var isCatchItem: Bool { return raw.kind == .catchItem }
1129+
public var asCatchItem: CatchItemSyntax? {
1130+
guard isCatchItem else { return nil }
1131+
return CatchItemSyntax(asSyntaxData)
1132+
}
1133+
11221134
public var isSwitchCaseLabel: Bool { return raw.kind == .switchCaseLabel }
11231135
public var asSwitchCaseLabel: SwitchCaseLabelSyntax? {
11241136
guard isSwitchCaseLabel else { return nil }
@@ -1775,6 +1787,8 @@ extension Syntax {
17751787
return node
17761788
case .caseItemList(let node):
17771789
return node
1790+
case .catchItemList(let node):
1791+
return node
17781792
case .conditionElement(let node):
17791793
return node
17801794
case .availabilityCondition(let node):
@@ -1801,6 +1815,8 @@ extension Syntax {
18011815
return node
18021816
case .caseItem(let node):
18031817
return node
1818+
case .catchItem(let node):
1819+
return node
18041820
case .switchCaseLabel(let node):
18051821
return node
18061822
case .catchClause(let node):
@@ -1904,6 +1920,6 @@ extension Syntax {
19041920
extension SyntaxParser {
19051921
static func verifyNodeDeclarationHash() -> Bool {
19061922
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
1907-
"-7765007021548643080"
1923+
"-1461032627210044719"
19081924
}
19091925
}

Sources/SwiftSyntax/gyb_generated/SyntaxAnyVisitor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
12541254
override open func visitPost(_ node: CaseItemListSyntax) {
12551255
visitAnyPost(node._syntaxNode)
12561256
}
1257+
override open func visit(_ node: CatchItemListSyntax) -> SyntaxVisitorContinueKind {
1258+
return visitAny(node._syntaxNode)
1259+
}
1260+
1261+
override open func visitPost(_ node: CatchItemListSyntax) {
1262+
visitAnyPost(node._syntaxNode)
1263+
}
12571264
override open func visit(_ node: ConditionElementSyntax) -> SyntaxVisitorContinueKind {
12581265
return visitAny(node._syntaxNode)
12591266
}
@@ -1345,6 +1352,13 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
13451352
override open func visitPost(_ node: CaseItemSyntax) {
13461353
visitAnyPost(node._syntaxNode)
13471354
}
1355+
override open func visit(_ node: CatchItemSyntax) -> SyntaxVisitorContinueKind {
1356+
return visitAny(node._syntaxNode)
1357+
}
1358+
1359+
override open func visitPost(_ node: CatchItemSyntax) {
1360+
visitAnyPost(node._syntaxNode)
1361+
}
13481362
override open func visit(_ node: SwitchCaseLabelSyntax) -> SyntaxVisitorContinueKind {
13491363
return visitAny(node._syntaxNode)
13501364
}

Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8186,6 +8186,51 @@ extension CaseItemSyntax {
81868186
}
81878187
}
81888188

8189+
public struct CatchItemSyntaxBuilder {
8190+
private var layout =
8191+
Array<RawSyntax?>(repeating: nil, count: 3)
8192+
8193+
internal init() {}
8194+
8195+
public mutating func usePattern(_ node: PatternSyntax) {
8196+
let idx = CatchItemSyntax.Cursor.pattern.rawValue
8197+
layout[idx] = node.raw
8198+
}
8199+
8200+
public mutating func useWhereClause(_ node: WhereClauseSyntax) {
8201+
let idx = CatchItemSyntax.Cursor.whereClause.rawValue
8202+
layout[idx] = node.raw
8203+
}
8204+
8205+
public mutating func useTrailingComma(_ node: TokenSyntax) {
8206+
let idx = CatchItemSyntax.Cursor.trailingComma.rawValue
8207+
layout[idx] = node.raw
8208+
}
8209+
8210+
internal mutating func buildData() -> SyntaxData {
8211+
8212+
return .forRoot(RawSyntax.createAndCalcLength(kind: .catchItem,
8213+
layout: layout, presence: .present))
8214+
}
8215+
}
8216+
8217+
extension CatchItemSyntax {
8218+
/// Creates a `CatchItemSyntax` using the provided build function.
8219+
/// - Parameter:
8220+
/// - build: A closure that wil be invoked in order to initialize
8221+
/// the fields of the syntax node.
8222+
/// This closure is passed a `CatchItemSyntaxBuilder` which you can use to
8223+
/// incrementally build the structure of the node.
8224+
/// - Returns: A `CatchItemSyntax` with all the fields populated in the builder
8225+
/// closure.
8226+
public init(_ build: (inout CatchItemSyntaxBuilder) -> Void) {
8227+
var builder = CatchItemSyntaxBuilder()
8228+
build(&builder)
8229+
let data = builder.buildData()
8230+
self.init(data)
8231+
}
8232+
}
8233+
81898234
public struct SwitchCaseLabelSyntaxBuilder {
81908235
private var layout =
81918236
Array<RawSyntax?>(repeating: nil, count: 3)
@@ -8248,7 +8293,7 @@ extension SwitchCaseLabelSyntax {
82488293

82498294
public struct CatchClauseSyntaxBuilder {
82508295
private var layout =
8251-
Array<RawSyntax?>(repeating: nil, count: 4)
8296+
Array<RawSyntax?>(repeating: nil, count: 3)
82528297

82538298
internal init() {}
82548299

@@ -8257,14 +8302,15 @@ public struct CatchClauseSyntaxBuilder {
82578302
layout[idx] = node.raw
82588303
}
82598304

8260-
public mutating func usePattern(_ node: PatternSyntax) {
8261-
let idx = CatchClauseSyntax.Cursor.pattern.rawValue
8262-
layout[idx] = node.raw
8263-
}
8264-
8265-
public mutating func useWhereClause(_ node: WhereClauseSyntax) {
8266-
let idx = CatchClauseSyntax.Cursor.whereClause.rawValue
8267-
layout[idx] = node.raw
8305+
public mutating func addCatchItem(_ elt: CatchItemSyntax) {
8306+
let idx = CatchClauseSyntax.Cursor.catchItems.rawValue
8307+
if let list = layout[idx] {
8308+
layout[idx] = list.appending(elt.raw)
8309+
} else {
8310+
layout[idx] = RawSyntax.create(kind: SyntaxKind.catchItemList,
8311+
layout: [elt.raw], length: elt.raw.totalLength,
8312+
presence: SourcePresence.present)
8313+
}
82688314
}
82698315

82708316
public mutating func useBody(_ node: CodeBlockSyntax) {
@@ -8276,8 +8322,8 @@ public struct CatchClauseSyntaxBuilder {
82768322
if (layout[0] == nil) {
82778323
layout[0] = RawSyntax.missingToken(TokenKind.catchKeyword)
82788324
}
8279-
if (layout[3] == nil) {
8280-
layout[3] = RawSyntax.missing(SyntaxKind.codeBlock)
8325+
if (layout[2] == nil) {
8326+
layout[2] = RawSyntax.missing(SyntaxKind.codeBlock)
82818327
}
82828328

82838329
return .forRoot(RawSyntax.createAndCalcLength(kind: .catchClause,

0 commit comments

Comments
 (0)