Skip to content

Commit cdbf1ed

Browse files
committed
Move TypeAttribute to SwiftSyntaxBuilder
1 parent e1f771e commit cdbf1ed

File tree

11 files changed

+467
-53
lines changed

11 files changed

+467
-53
lines changed

CodeGeneration/Package.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package = Package(
99
],
1010
products: [
1111
.executable(name: "generate-swiftbasicformat", targets: ["generate-swiftbasicformat"]),
12+
.executable(name: "generate-swiftparser", targets: ["generate-swiftparser"]),
1213
.executable(name: "generate-swiftsyntaxbuilder", targets: ["generate-swiftsyntaxbuilder"]),
1314
],
1415
dependencies: [
@@ -26,6 +27,16 @@ let package = Package(
2627
"Utils"
2728
]
2829
),
30+
.executableTarget(
31+
name: "generate-swiftparser",
32+
dependencies: [
33+
.product(name: "SwiftSyntax", package: "swift-syntax"),
34+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
35+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
36+
"SyntaxSupport",
37+
"Utils"
38+
]
39+
),
2940
.executableTarget(
3041
name: "generate-swiftsyntaxbuilder",
3142
dependencies: [
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//// Automatically Generated From AttributeNodes.swift.gyb.
2+
//// Do Not Edit Directly!
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the Swift.org open source project
6+
//
7+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
8+
// Licensed under Apache License v2.0 with Runtime Library Exception
9+
//
10+
// See https://swift.org/LICENSE.txt for license information
11+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public class Attribute {
16+
public let name: String
17+
public let swiftName: String?
18+
19+
public init(name: String, swiftName: String? = nil) {
20+
self.name = name
21+
self.swiftName = swiftName
22+
}
23+
}
24+
25+
public class TypeAttribute: Attribute {
26+
public init(name: String) {
27+
super.init(name: name)
28+
}
29+
}
30+
31+
public class DeclAttribute: Attribute {
32+
public let className: String
33+
public let options: [String]
34+
public let code: Int
35+
36+
public convenience init(name: String, className: String, options: String..., code: Int, swiftName: String? = nil) {
37+
self.init(name: name, className: className, options: options, code: code, swiftName: swiftName)
38+
}
39+
40+
public init(name: String, className: String, options: [String], code: Int, swiftName: String? = nil) {
41+
self.className = className
42+
self.options = options
43+
self.code = code
44+
super.init(name: name, swiftName: swiftName)
45+
}
46+
}
47+
48+
public class SimpleDeclAttribute: DeclAttribute { }
49+
50+
public class ContextualDeclAttribute: DeclAttribute {
51+
public init(name: String, className: String, options: String..., code: Int) {
52+
super.init(name: name, className: className, options: options, code: code)
53+
}
54+
}
55+
56+
public class ContextualSimpleDeclAttribute: SimpleDeclAttribute {
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 DeclAttributeAlias: Attribute {
63+
public let className: String
64+
65+
public init(name: String, className: String, swiftName: String? = nil) {
66+
self.className = className
67+
super.init(name: name, swiftName: swiftName)
68+
69+
}
70+
}
71+
72+
public class ContextualDeclAttributeAlias: DeclAttributeAlias { }
73+
74+
public class BuiltinDeclModifier: Attribute { }
75+
76+
// Abstract class aggregations for use in Attr.def.
77+
let onValue = "OnValue"
78+
let onTypeAlias = "OnTypeAlias"
79+
let onEnumElement = "OnEnumElement"
80+
let onSubscript = "OnSubscript"
81+
let onVar = "OnVar"
82+
let onExtension = "OnExtension"
83+
let onClass = "OnClass"
84+
let onFunc = "OnFunc"
85+
let onAccessor = "OnAccessor"
86+
let onEnum = "OnEnum"
87+
let onConstructor = "OnConstructor"
88+
let onStruct = "OnStruct"
89+
let onImport = "OnImport"
90+
let onAssociatedType = "OnAssociatedType"
91+
let onGenericTypeParam = "OnGenericTypeParam"
92+
let onParam = "OnParam"
93+
let onNominalType = "OnNominalType"
94+
let onProtocol = "OnProtocol"
95+
let onConcreteNominalType = "OnConcreteNominalType"
96+
let onGenericType = "OnGenericType"
97+
let onAbstractFunction = "OnAbstractFunction"
98+
let onOperator = "OnOperator"
99+
let onAnyDecl = "OnAnyDecl"
100+
101+
// True if multiple instances of this attribute are allowed on a single
102+
// declaration.
103+
let allowMultipleAttributes = "AllowMultipleAttributes"
104+
105+
// True if this is a decl modifier - i.e., that it should not be spelled
106+
// with an @.
107+
let declModifier = "DeclModifier"
108+
109+
// True if this is a long attribute that should be printed on its own line.
110+
//
111+
// Currently has no effect on DeclModifier attributes.
112+
let longAttribute = "LongAttribute"
113+
114+
// True if this shouldn't be serialized.
115+
let notSerialized = "NotSerialized"
116+
117+
// True if this attribute is only valid when parsing a .sil file.
118+
let SILOnly = "SILOnly"
119+
120+
// The attribute should be reported by parser as unknown.
121+
let rejectByParser = "RejectByParser"
122+
123+
// Whether client code cannot use the attribute.
124+
let userInaccessible = "UserInaccessible"
125+
126+
// Whether adding this attribute can break API
127+
let APIBreakingToAdd = "APIBreakingToAdd"
128+
129+
// Whether removing this attribute can break API
130+
let APIBreakingToRemove = "APIBreakingToRemove"
131+
132+
// Whether adding this attribute can break ABI
133+
let ABIBreakingToAdd = "ABIBreakingToAdd"
134+
135+
// Whether removing this attribute can break ABI
136+
let ABIBreakingToRemove = "ABIBreakingToRemove"
137+
138+
// The opposite of APIBreakingToAdd
139+
let APIStableToAdd = "APIStableToAdd"
140+
141+
// The opposite of APIBreakingToRemove
142+
let APIStableToRemove = "APIStableToRemove"
143+
144+
// The opposite of ABIBreakingToAdd
145+
let ABIStableToAdd = "ABIStableToAdd"
146+
147+
// The opposite of ABIBreakingToRemove
148+
let ABIStableToRemove = "ABIStableToRemove"
149+
150+
// Whether this attribute is only valid when concurrency is enabled.
151+
let concurrencyOnly = "ConcurrencyOnly"
152+
153+
// Whether this attribute is valid on additional decls in ClangImporter.
154+
let onAnyClangDecl = "OnAnyClangDecl"
155+
156+
// Type attributes
157+
public let TYPE_ATTR_KINDS = [
158+
TypeAttribute(name: "autoclosure"),
159+
TypeAttribute(name: "convention"),
160+
TypeAttribute(name: "noescape"),
161+
TypeAttribute(name: "escaping"),
162+
TypeAttribute(name: "differentiable"),
163+
TypeAttribute(name: "noDerivative"),
164+
TypeAttribute(name: "async"),
165+
TypeAttribute(name: "Sendable"),
166+
TypeAttribute(name: "unchecked"),
167+
TypeAttribute(name: "_local"),
168+
TypeAttribute(name: "_noMetadata"),
169+
170+
// Generated interface attributes
171+
TypeAttribute(name: "_opaqueReturnTypeOf"),
172+
]
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//// Automatically Generated From AttributeNodes.swift.gyb.
2+
//// Do Not Edit Directly!
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the Swift.org open source project
6+
//
7+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
8+
// Licensed under Apache License v2.0 with Runtime Library Exception
9+
//
10+
// See https://swift.org/LICENSE.txt for license information
11+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public class Attribute {
16+
public let name: String
17+
public let swiftName: String?
18+
19+
public init(name: String, swiftName: String? = nil) {
20+
self.name = name
21+
self.swiftName = swiftName
22+
}
23+
}
24+
25+
public class TypeAttribute: Attribute {
26+
public init(name: String) {
27+
super.init(name: name)
28+
}
29+
}
30+
31+
public class DeclAttribute: Attribute {
32+
public let className: String
33+
public let options: [String]
34+
public let code: Int
35+
36+
public convenience init(name: String, className: String, options: String..., code: Int, swiftName: String? = nil) {
37+
self.init(name: name, className: className, options: options, code: code, swiftName: swiftName)
38+
}
39+
40+
public init(name: String, className: String, options: [String], code: Int, swiftName: String? = nil) {
41+
self.className = className
42+
self.options = options
43+
self.code = code
44+
super.init(name: name, swiftName: swiftName)
45+
}
46+
}
47+
48+
public class SimpleDeclAttribute: DeclAttribute { }
49+
50+
public class ContextualDeclAttribute: DeclAttribute {
51+
public init(name: String, className: String, options: String..., code: Int) {
52+
super.init(name: name, className: className, options: options, code: code)
53+
}
54+
}
55+
56+
public class ContextualSimpleDeclAttribute: SimpleDeclAttribute {
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 DeclAttributeAlias: Attribute {
63+
public let className: String
64+
65+
public init(name: String, className: String, swiftName: String? = nil) {
66+
self.className = className
67+
super.init(name: name, swiftName: swiftName)
68+
69+
}
70+
}
71+
72+
public class ContextualDeclAttributeAlias: DeclAttributeAlias { }
73+
74+
public class BuiltinDeclModifier: Attribute { }
75+
76+
// Abstract class aggregations for use in Attr.def.
77+
let onValue = "OnValue"
78+
let onTypeAlias = "OnTypeAlias"
79+
let onEnumElement = "OnEnumElement"
80+
let onSubscript = "OnSubscript"
81+
let onVar = "OnVar"
82+
let onExtension = "OnExtension"
83+
let onClass = "OnClass"
84+
let onFunc = "OnFunc"
85+
let onAccessor = "OnAccessor"
86+
let onEnum = "OnEnum"
87+
let onConstructor = "OnConstructor"
88+
let onStruct = "OnStruct"
89+
let onImport = "OnImport"
90+
let onAssociatedType = "OnAssociatedType"
91+
let onGenericTypeParam = "OnGenericTypeParam"
92+
let onParam = "OnParam"
93+
let onNominalType = "OnNominalType"
94+
let onProtocol = "OnProtocol"
95+
let onConcreteNominalType = "OnConcreteNominalType"
96+
let onGenericType = "OnGenericType"
97+
let onAbstractFunction = "OnAbstractFunction"
98+
let onOperator = "OnOperator"
99+
let onAnyDecl = "OnAnyDecl"
100+
101+
// True if multiple instances of this attribute are allowed on a single
102+
// declaration.
103+
let allowMultipleAttributes = "AllowMultipleAttributes"
104+
105+
// True if this is a decl modifier - i.e., that it should not be spelled
106+
// with an @.
107+
let declModifier = "DeclModifier"
108+
109+
// True if this is a long attribute that should be printed on its own line.
110+
//
111+
// Currently has no effect on DeclModifier attributes.
112+
let longAttribute = "LongAttribute"
113+
114+
// True if this shouldn't be serialized.
115+
let notSerialized = "NotSerialized"
116+
117+
// True if this attribute is only valid when parsing a .sil file.
118+
let SILOnly = "SILOnly"
119+
120+
// The attribute should be reported by parser as unknown.
121+
let rejectByParser = "RejectByParser"
122+
123+
// Whether client code cannot use the attribute.
124+
let userInaccessible = "UserInaccessible"
125+
126+
// Whether adding this attribute can break API
127+
let APIBreakingToAdd = "APIBreakingToAdd"
128+
129+
// Whether removing this attribute can break API
130+
let APIBreakingToRemove = "APIBreakingToRemove"
131+
132+
// Whether adding this attribute can break ABI
133+
let ABIBreakingToAdd = "ABIBreakingToAdd"
134+
135+
// Whether removing this attribute can break ABI
136+
let ABIBreakingToRemove = "ABIBreakingToRemove"
137+
138+
// The opposite of APIBreakingToAdd
139+
let APIStableToAdd = "APIStableToAdd"
140+
141+
// The opposite of APIBreakingToRemove
142+
let APIStableToRemove = "APIStableToRemove"
143+
144+
// The opposite of ABIBreakingToAdd
145+
let ABIStableToAdd = "ABIStableToAdd"
146+
147+
// The opposite of ABIBreakingToRemove
148+
let ABIStableToRemove = "ABIStableToRemove"
149+
150+
// Whether this attribute is only valid when concurrency is enabled.
151+
let concurrencyOnly = "ConcurrencyOnly"
152+
153+
// Whether this attribute is valid on additional decls in ClangImporter.
154+
let onAnyClangDecl = "OnAnyClangDecl"
155+
156+
// Type attributes
157+
public let TYPE_ATTR_KINDS = [
158+
TypeAttribute(name: "autoclosure"),
159+
TypeAttribute(name: "convention"),
160+
TypeAttribute(name: "noescape"),
161+
TypeAttribute(name: "escaping"),
162+
TypeAttribute(name: "differentiable"),
163+
TypeAttribute(name: "noDerivative"),
164+
TypeAttribute(name: "async"),
165+
TypeAttribute(name: "Sendable"),
166+
TypeAttribute(name: "unchecked"),
167+
TypeAttribute(name: "_local"),
168+
TypeAttribute(name: "_noMetadata"),
169+
170+
// Generated interface attributes
171+
TypeAttribute(name: "_opaqueReturnTypeOf"),
172+
]

0 commit comments

Comments
 (0)