Skip to content

Commit dedd6c1

Browse files
committed
Move SyntaxKind from gyb to codegen
1 parent 6bd2e72 commit dedd6c1

File tree

9 files changed

+679
-345
lines changed

9 files changed

+679
-345
lines changed

CodeGeneration/Sources/SyntaxSupport/SyntaxBaseKinds.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
public let SYNTAX_BASE_KINDS: Set<String> = [
21+
public let SYNTAX_BASE_KINDS: [String] = [
2222
% for name in SYNTAX_BASE_KINDS:
2323
"${name}",
2424
% end

CodeGeneration/Sources/SyntaxSupport/gyb_generated/SyntaxBaseKinds.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
public let SYNTAX_BASE_KINDS: Set<String> = [
15+
public let SYNTAX_BASE_KINDS: [String] = [
1616
"Decl",
1717
"Expr",
1818
"Pattern",

CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
3030
(syntaxAnyVisitorFile, "SyntaxAnyVisitor.swift"),
3131
(syntaxBaseNodesFile, "SyntaxBaseNodes.swift"),
3232
(syntaxEnumFile, "SyntaxEnum.swift"),
33+
(syntaxKindFile, "SyntaxKind.swift")
3334
],
3435
destination: URL(fileURLWithPath: generatedPath),
3536
verbose: verbose
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SwiftSyntax
14+
import SwiftSyntaxBuilder
15+
import SyntaxSupport
16+
import Utils
17+
18+
let syntaxKindFile = SourceFile(leadingTrivia: .docLineComment(generateCopyrightHeader(for: "generate-swiftsyntax"))) {
19+
EnumDecl("""
20+
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
21+
@frozen // FIXME: Not actually stable, works around a miscompile
22+
public enum SyntaxKind
23+
""") {
24+
EnumCaseDecl("case token")
25+
for node in NON_BASE_SYNTAX_NODES {
26+
EnumCaseDecl("case \(raw: node.swiftSyntaxKind)")
27+
}
28+
29+
VariableDecl(
30+
modifiers: [DeclModifier(name: .public)],
31+
name: IdentifierPattern("isSyntaxCollection"),
32+
type: TypeAnnotation(
33+
colon: .colon,
34+
type: SimpleTypeIdentifier("Bool")
35+
)
36+
) {
37+
SwitchStmt(expression: Expr("self")) {
38+
for node in SYNTAX_NODES where node.baseKind == "SyntaxCollection"{
39+
SwitchCase("case .\(raw: node.swiftSyntaxKind):") {
40+
ReturnStmt("return true")
41+
}
42+
}
43+
44+
SwitchCase("default:") {
45+
ReturnStmt("return false")
46+
}
47+
}
48+
}
49+
50+
VariableDecl(
51+
modifiers: [DeclModifier(name: .public)],
52+
name: IdentifierPattern("isMissing"),
53+
type: TypeAnnotation(
54+
colon: .colon,
55+
type: SimpleTypeIdentifier("Bool")
56+
)
57+
) {
58+
SwitchStmt(expression: Expr("self")) {
59+
for name in SYNTAX_BASE_KINDS where !["Syntax", "SyntaxCollection"].contains(name) {
60+
SwitchCase("case .missing\(raw: name):") {
61+
ReturnStmt("return true")
62+
}
63+
}
64+
65+
SwitchCase("default:") {
66+
ReturnStmt("return false")
67+
}
68+
}
69+
}
70+
}
71+
}

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ let package = Package(
6767
"Raw/RawSyntaxValidation.swift.gyb",
6868
"SyntaxCollections.swift.gyb",
6969
"SyntaxFactory.swift.gyb",
70-
"SyntaxKind.swift.gyb",
7170
"SyntaxNodes.swift.gyb.template",
7271
"SyntaxRewriter.swift.gyb",
7372
"SyntaxTransform.swift.gyb",

Sources/SwiftSyntax/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ add_swift_host_library(SwiftSyntax
3737
gyb_generated/SyntaxCollections.swift
3838
generated/SyntaxEnum.swift
3939
gyb_generated/SyntaxFactory.swift
40-
gyb_generated/SyntaxKind.swift
40+
generated/SyntaxKind.swift
4141
gyb_generated/SyntaxRewriter.swift
4242
gyb_generated/SyntaxTraits.swift
4343
gyb_generated/SyntaxTransform.swift

Sources/SwiftSyntax/SyntaxKind.swift.gyb

Lines changed: 0 additions & 51 deletions
This file was deleted.

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
/// Enum to exhaustively switch over all different syntax nodes.
1817
@frozen // FIXME: Not actually stable, works around a miscompile
1918
public enum SyntaxEnum {
2019
case token(TokenSyntax)

0 commit comments

Comments
 (0)