Skip to content

Commit 7e224da

Browse files
committed
Move TypeAttribute to SwiftSyntaxBuilder
1 parent 76d0119 commit 7e224da

24 files changed

+2645
-357
lines changed

CodeGeneration/Package.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let package = Package(
1010
products: [
1111
.executable(name: "generate-swiftbasicformat", targets: ["generate-swiftbasicformat"]),
1212
.executable(name: "generate-swiftideutils", targets: ["generate-swiftideutils"]),
13+
.executable(name: "generate-swiftparser", targets: ["generate-swiftparser"]),
1314
.executable(name: "generate-swiftsyntaxbuilder", targets: ["generate-swiftsyntaxbuilder"]),
1415
],
1516
dependencies: [
@@ -36,6 +37,16 @@ let package = Package(
3637
"SyntaxSupport",
3738
"Utils"
3839
]
40+
),
41+
.executableTarget(
42+
name: "generate-swiftparser",
43+
dependencies: [
44+
.product(name: "SwiftSyntax", package: "swift-syntax"),
45+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
46+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
47+
"SyntaxSupport",
48+
"Utils"
49+
]
3950
),
4051
.executableTarget(
4152
name: "generate-swiftsyntaxbuilder",
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
%{
2+
from gyb_syntax_support import *
3+
from gyb_helpers import make_swift_attribute
4+
# -*- mode: Swift -*-
5+
# Ignore the following admonition it applies to the resulting .swift file only
6+
}%
7+
//// Automatically Generated From AttributeNodes.swift.gyb.
8+
//// Do Not Edit Directly!
9+
//===----------------------------------------------------------------------===//
10+
//
11+
// This source file is part of the Swift.org open source project
12+
//
13+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
14+
// Licensed under Apache License v2.0 with Runtime Library Exception
15+
//
16+
// See https://swift.org/LICENSE.txt for license information
17+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
18+
//
19+
//===----------------------------------------------------------------------===//
20+
21+
public class Attribute {
22+
public let name: String
23+
public let swiftName: String
24+
25+
public init(name: String, swiftName: String? = nil) {
26+
self.name = name
27+
self.swiftName = swiftName ?? name
28+
}
29+
}
30+
31+
public class TypeAttribute: Attribute {
32+
public init(name: String) {
33+
super.init(name: name)
34+
}
35+
}
36+
37+
public class DeclAttribute: Attribute {
38+
public let className: String
39+
public let options: [String]
40+
public let code: Int
41+
42+
public convenience init(name: String, className: String, options: String..., code: Int, swiftName: String? = nil) {
43+
self.init(name: name, className: className, options: options, code: code, swiftName: swiftName)
44+
}
45+
46+
public init(name: String, className: String, options: [String], code: Int, swiftName: String? = nil) {
47+
self.className = className
48+
self.options = options
49+
self.code = code
50+
super.init(name: name, swiftName: swiftName)
51+
}
52+
}
53+
54+
public class SimpleDeclAttribute: DeclAttribute { }
55+
56+
public class ContextualDeclAttribute: DeclAttribute {
57+
public init(name: String, className: String, options: String..., code: Int) {
58+
super.init(name: name, className: className, options: options, code: code)
59+
}
60+
}
61+
62+
public class ContextualSimpleDeclAttribute: SimpleDeclAttribute {
63+
public init(name: String, className: String, options: String..., code: Int) {
64+
super.init(name: name, className: className, options: options, code: code)
65+
}
66+
}
67+
68+
public class DeclAttributeAlias: Attribute {
69+
public let className: String
70+
71+
public init(name: String, className: String, swiftName: String? = nil) {
72+
self.className = className
73+
super.init(name: name, swiftName: swiftName)
74+
75+
}
76+
}
77+
78+
public class ContextualDeclAttributeAlias: DeclAttributeAlias { }
79+
80+
public class BuiltinDeclModifier: Attribute { }
81+
82+
// Type attributes
83+
public let TYPE_ATTR_KINDS = [
84+
% for attr in TYPE_ATTR_KINDS:
85+
TypeAttribute(name: "${attr.name}"),
86+
% end
87+
]
88+
89+
/// Schema for `DeclAttribute`s:
90+
///
91+
/// - Attribute name.
92+
/// - C++ class name without the 'Attr' suffix
93+
/// - Options for the attribute, including:
94+
/// * the declarations the attribute can appear on
95+
/// * whether duplicates are allowed
96+
/// - Unique attribute identifier used for serialization. This
97+
/// can never be changed.
98+
///
99+
/// SimpleDeclAttribute is the same, but the class becomes
100+
/// SimpleDeclAttr<DAK_##NAME> on the C++ side.
101+
///
102+
/// Please help ease code review/audits:
103+
/// - Please place the "OnXYZ" flags together on the next line.
104+
/// - Please place the non-OnXYZ flags together on the next to last line.
105+
/// - Please place the unique code number on the last line.
106+
/// - Please sort attributes by serialization number.
107+
/// - Please create a "NOTE" comment if a unique number is skipped.
108+
///
109+
/// If you're adding a new kind of "attribute" that is spelled without a leading
110+
/// '@' symbol, add an entry to the `DECL_MODIFIER_KINDS` array instead.
111+
///
112+
/// If you're adding a new underscored attribute here, please document it in
113+
/// docs/ReferenceGuides/UnderscoredAttributes.md.
114+
public let DECL_ATTR_KINDS: [Attribute] = [
115+
% for attr in DECL_ATTR_KINDS:
116+
${make_swift_attribute(attr)},
117+
% end
118+
]
119+
120+
/// Schema for declaration modifiers:
121+
///
122+
/// - Modifier name.
123+
/// - C++ class name without the 'Attr' suffix
124+
/// - Options for the attribute, including:
125+
/// * the declarations the attribute can appear on
126+
/// * whether duplicates are allowed
127+
/// - Unique attribute identifier used for serialization. This
128+
/// can never be changed.
129+
///
130+
/// SimpleDeclAttribute is the same, but the class becomes
131+
/// SimpleDeclAttr<DAK_##NAME> on the C++ side.
132+
///
133+
/// Please help ease code review/audits:
134+
/// - Please place the "OnXYZ" flags together on the next line.
135+
/// - Please place the non-OnXYZ flags together on the next to last line.
136+
/// - Please place the unique code number on the last line.
137+
/// - Please sort attributes by serialization number.
138+
/// - Please create a "NOTE" comment if a unique number is skipped.
139+
///
140+
/// If you're adding a new kind of attribute that is spelled with a leading
141+
/// '@' symbol, add an entry to the `DECL_ATTR_KINDS` array instead.
142+
public let DECL_MODIFIER_KINDS: [Attribute] = [
143+
% for attr in DECL_MODIFIER_KINDS:
144+
${make_swift_attribute(attr)},
145+
% end
146+
]
147+
148+
public let DEPRECATED_MODIFIER_KINDS: [Attribute] = [
149+
% for attr in DEPRECATED_MODIFIER_KINDS:
150+
${make_swift_attribute(attr)},
151+
% end
152+
]

0 commit comments

Comments
 (0)