@@ -13,7 +13,7 @@ def initialize(target_class)
13
13
end
14
14
15
15
def build_decl
16
- decl = AST ::Declarations ::Class . new (
16
+ AST ::Declarations ::Class . new (
17
17
name : to_type_name ( only_name ( @target_class ) ) ,
18
18
type_params : [ ] ,
19
19
super_class : build_super_class ,
@@ -22,10 +22,6 @@ def build_decl
22
22
location : nil ,
23
23
comment : nil
24
24
)
25
-
26
- add_decl_members ( decl )
27
-
28
- decl
29
25
end
30
26
31
27
private
@@ -100,112 +96,9 @@ def self.generatable?(target)
100
96
CAN_CALL_KEYWORD_INIT_P = Struct . new ( :tmp ) . respond_to? ( :keyword_init? )
101
97
102
98
def build_super_class
103
- AST ::Declarations ::Class ::Super . new ( name : TypeName ( "::Struct" ) , args : [ untyped ] , location : nil )
104
- end
105
-
106
- def add_decl_members ( decl )
107
- decl . members . concat build_s_new
108
- decl . members . concat build_s_keyword_init_p
109
- decl . members . concat build_s_members
110
- decl . members . concat build_member_accessors ( AST ::Members ::AttrAccessor )
99
+ AST ::Declarations ::Class ::Super . new ( name : TypeName ( "::Struct" ) , args : @target_class . members . to_h { |m | [ m , untyped ] } , location : nil )
111
100
end
112
101
113
- # def self.new: (?untyped foo, ?untyped bar) -> instance
114
- # | (?foo: untyped, ?bar: untyped) -> instance
115
- def build_s_new
116
- [ :new , :[] ] . map do |name |
117
- new_overloads = [ ]
118
-
119
- if CAN_CALL_KEYWORD_INIT_P
120
- case @target_class . keyword_init?
121
- when false
122
- new_overloads << build_overload_for_positional_arguments
123
- when true
124
- new_overloads << build_overload_for_keyword_arguments
125
- when nil
126
- new_overloads << build_overload_for_positional_arguments
127
- new_overloads << build_overload_for_keyword_arguments
128
- else
129
- raise
130
- end
131
- else
132
- new_overloads << build_overload_for_positional_arguments
133
- new_overloads << build_overload_for_keyword_arguments
134
- end
135
-
136
- AST ::Members ::MethodDefinition . new (
137
- name : name ,
138
- overloads : new_overloads ,
139
- kind : :singleton ,
140
- location : nil ,
141
- comment : nil ,
142
- annotations : [ ] ,
143
- overloading : false ,
144
- visibility : nil
145
- )
146
- end
147
- end
148
-
149
- def build_overload_for_positional_arguments
150
- AST ::Members ::MethodDefinition ::Overload . new (
151
- annotations : [ ] ,
152
- method_type : MethodType . new (
153
- type : Types ::Function . empty ( Types ::Bases ::Instance . new ( location : nil ) ) . update (
154
- optional_positionals : @target_class . members . map { |m | Types ::Function ::Param . new ( name : m , type : untyped ) } ,
155
- ) ,
156
- type_params : [ ] ,
157
- block : nil ,
158
- location : nil ,
159
- )
160
- )
161
- end
162
-
163
- def build_overload_for_keyword_arguments
164
- AST ::Members ::MethodDefinition ::Overload . new (
165
- annotations : [ ] ,
166
- method_type : MethodType . new (
167
- type : Types ::Function . empty ( Types ::Bases ::Instance . new ( location : nil ) ) . update (
168
- optional_keywords : @target_class . members . to_h { |m | [ m , Types ::Function ::Param . new ( name : nil , type : untyped ) ] } ,
169
- ) ,
170
- type_params : [ ] ,
171
- block : nil ,
172
- location : nil ,
173
- )
174
- )
175
- end
176
-
177
- # def self.keyword_init?: () -> bool?
178
- def build_s_keyword_init_p
179
- return [ ] unless CAN_CALL_KEYWORD_INIT_P
180
-
181
- return_type = @target_class . keyword_init? . nil? \
182
- ? Types ::Bases ::Nil . new ( location : nil )
183
- : Types ::Literal . new ( literal : @target_class . keyword_init? , location : nil )
184
- type = Types ::Function . empty ( return_type )
185
-
186
- [
187
- AST ::Members ::MethodDefinition . new (
188
- name : :keyword_init? ,
189
- overloads : [
190
- AST ::Members ::MethodDefinition ::Overload . new (
191
- annotations : [ ] ,
192
- method_type : MethodType . new (
193
- type : type ,
194
- type_params : [ ] ,
195
- block : nil ,
196
- location : nil ,
197
- )
198
- )
199
- ] ,
200
- kind : :singleton ,
201
- location : nil ,
202
- comment : nil ,
203
- annotations : [ ] ,
204
- overloading : false ,
205
- visibility : nil
206
- )
207
- ]
208
- end
209
102
end
210
103
211
104
class DataGenerator < ValueObjectBase
@@ -221,13 +114,7 @@ def self.generatable?(target)
221
114
private
222
115
223
116
def build_super_class
224
- AST ::Declarations ::Class ::Super . new ( name : TypeName ( "::Data" ) , args : [ ] , location : nil )
225
- end
226
-
227
- def add_decl_members ( decl )
228
- decl . members . concat build_s_new
229
- decl . members . concat build_s_members
230
- decl . members . concat build_member_accessors ( AST ::Members ::AttrReader )
117
+ AST ::Declarations ::Class ::Super . new ( name : TypeName ( "::Data" ) , args : @target_class . members . to_h { |m | [ m , untyped ] } , location : nil )
231
118
end
232
119
233
120
# def self.new: (untyped foo, untyped bar) -> instance
0 commit comments