Skip to content

Commit 5b64d60

Browse files
committed
Simplify Misc.swift.gyb
1 parent bbab764 commit 5b64d60

File tree

3 files changed

+18
-1176
lines changed

3 files changed

+18
-1176
lines changed

Sources/SwiftSyntax/Misc.swift.gyb

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@
2020
//===----------------------------------------------------------------------===//
2121

2222
extension Syntax {
23-
/// Syntax nodes always conform to SyntaxProtocol. This API is just added
24-
/// for consistency.
25-
/// Note that this will incur an existential conversion.
26-
@available(*, deprecated, message: "Expression always evaluates to true")
27-
public func isProtocol(_: SyntaxProtocol.Protocol) -> Bool {
28-
return true
29-
}
30-
31-
/// Return the non-type erased version of this syntax node.
32-
/// Note that this will incur an existential conversion.
33-
public func asProtocol(_: SyntaxProtocol.Protocol) -> SyntaxProtocol {
34-
switch self.as(SyntaxEnum.self) {
35-
case .token(let node):
36-
return node
37-
case .unknown(let node):
38-
return node
39-
% for node in NON_BASE_SYNTAX_NODES:
40-
case .${node.swift_syntax_kind}(let node):
41-
return node
42-
% end
43-
}
44-
}
45-
4623
public static var structure: SyntaxNodeStructure {
4724
return .choices([
4825
.node(UnknownSyntax.self),
@@ -56,19 +33,6 @@ extension Syntax {
5633
% end
5734
])
5835
}
59-
60-
public func childNameForDiagnostics(_ index: SyntaxChildrenIndex) -> String? {
61-
switch self.as(SyntaxEnum.self) {
62-
case .token(let node):
63-
return node.childNameForDiagnostics(index)
64-
case .unknown(let node):
65-
return node.childNameForDiagnostics(index)
66-
% for node in NON_BASE_SYNTAX_NODES:
67-
case .${node.swift_syntax_kind}(let node):
68-
return node.childNameForDiagnostics(index)
69-
% end
70-
}
71-
}
7236
}
7337

7438
extension SyntaxKind {

Sources/SwiftSyntax/Syntax.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
8787
self = syntax._syntaxNode
8888
}
8989

90+
/// Syntax nodes always conform to SyntaxProtocol. This API is just added
91+
/// for consistency.
92+
/// Note that this will incur an existential conversion.
93+
@available(*, deprecated, message: "Expression always evaluates to true")
94+
public func isProtocol(_: SyntaxProtocol.Protocol) -> Bool {
95+
return true
96+
}
97+
98+
/// Return the non-type erased version of this syntax node.
99+
/// Note that this will incur an existential conversion.
100+
public func asProtocol(_: SyntaxProtocol.Protocol) -> SyntaxProtocol {
101+
return self.raw.kind.syntaxNodeType.init(self)!
102+
}
103+
104+
public func childNameForDiagnostics(_ index: SyntaxChildrenIndex) -> String? {
105+
return self.raw.kind.syntaxNodeType.init(self)!.childNameForDiagnostics(index)
106+
}
107+
90108
public func hash(into hasher: inout Hasher) {
91109
return data.nodeId.hash(into: &hasher)
92110
}

0 commit comments

Comments
 (0)