Skip to content

Commit d3b8694

Browse files
committed
Annotate nullable pointer fields in config.yml with optional: true (#70)
Some C struct pointer fields can be NULL (super_class when no parent class, comment when no doc comment). This metadata allows our Rust codegen to generate Option<T> return types for these accessors instead of unconditionally wrapping potentially NULL pointers.
1 parent 7e7876e commit d3b8694

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

config.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ nodes:
2525
c_type: rbs_node_list
2626
- name: super_class
2727
c_type: rbs_ast_declarations_class_super
28+
optional: true # NULL when no superclass (e.g., `class Foo end` vs `class Foo < Bar end`)
2829
- name: members
2930
c_type: rbs_node_list
3031
- name: annotations
3132
c_type: rbs_node_list
3233
- name: comment
3334
c_type: rbs_ast_comment
35+
optional: true # NULL when no comment precedes the declaration
3436
- name: RBS::AST::Declarations::Class::Super
3537
rust_name: ClassSuperNode
3638
fields:
@@ -47,6 +49,7 @@ nodes:
4749
c_type: rbs_type_name
4850
- name: comment
4951
c_type: rbs_ast_comment
52+
optional: true # NULL when no comment precedes the declaration
5053
- name: annotations
5154
c_type: rbs_node_list
5255
- name: RBS::AST::Declarations::Constant
@@ -58,6 +61,7 @@ nodes:
5861
c_type: rbs_node
5962
- name: comment
6063
c_type: rbs_ast_comment
64+
optional: true # NULL when no comment precedes the declaration
6165
- name: annotations
6266
c_type: rbs_node_list
6367
- name: RBS::AST::Declarations::Global
@@ -69,6 +73,7 @@ nodes:
6973
c_type: rbs_node
7074
- name: comment
7175
c_type: rbs_ast_comment
76+
optional: true # NULL when no comment precedes the declaration
7277
- name: annotations
7378
c_type: rbs_node_list
7479
- name: RBS::AST::Declarations::Interface
@@ -84,6 +89,7 @@ nodes:
8489
c_type: rbs_node_list
8590
- name: comment
8691
c_type: rbs_ast_comment
92+
optional: true # NULL when no comment precedes the declaration
8793
- name: RBS::AST::Declarations::Module
8894
rust_name: ModuleNode
8995
fields:
@@ -99,6 +105,7 @@ nodes:
99105
c_type: rbs_node_list
100106
- name: comment
101107
c_type: rbs_ast_comment
108+
optional: true # NULL when no comment precedes the declaration
102109
- name: RBS::AST::Declarations::Module::Self
103110
rust_name: ModuleSelfNode
104111
fields:
@@ -115,6 +122,7 @@ nodes:
115122
c_type: rbs_type_name
116123
- name: comment
117124
c_type: rbs_ast_comment
125+
optional: true # NULL when no comment precedes the declaration
118126
- name: annotations
119127
c_type: rbs_node_list
120128
- name: RBS::AST::Declarations::TypeAlias
@@ -130,6 +138,7 @@ nodes:
130138
c_type: rbs_node_list
131139
- name: comment
132140
c_type: rbs_ast_comment
141+
optional: true # NULL when no comment precedes the declaration
133142
- name: RBS::AST::Directives::Use
134143
rust_name: UseNode
135144
fields:
@@ -142,6 +151,7 @@ nodes:
142151
c_type: rbs_type_name
143152
- name: new_name
144153
c_type: rbs_ast_symbol
154+
optional: true # NULL when no alias (e.g., `use Foo::Bar` vs `use Foo::Bar as Baz`)
145155
- name: RBS::AST::Directives::Use::WildcardClause
146156
rust_name: UseWildcardClauseNode
147157
fields:
@@ -161,6 +171,7 @@ nodes:
161171
c_type: rbs_node_list
162172
- name: comment
163173
c_type: rbs_ast_comment
174+
optional: true # NULL when no comment precedes the declaration
164175
- name: RBS::AST::Members::AttrAccessor
165176
rust_name: AttrAccessorNode
166177
fields:
@@ -170,14 +181,17 @@ nodes:
170181
c_type: rbs_node
171182
- name: ivar_name
172183
c_type: rbs_node # rbs_ast_symbol_t, NULL or rbs_ast_bool_new(false)
184+
optional: true # NULL when omitted (`attr_accessor foo: T`); Symbol when named (`attr_accessor foo (@bar): T`); Bool(false) when empty parens (`attr_accessor foo (): T`)
173185
- name: kind
174186
c_type: rbs_keyword
175187
- name: annotations
176188
c_type: rbs_node_list
177189
- name: comment
178190
c_type: rbs_ast_comment
191+
optional: true # NULL when no comment precedes the declaration
179192
- name: visibility
180193
c_type: rbs_keyword
194+
optional: true # NULL when no visibility prefix (e.g., `attr_accessor foo: T` vs `private attr_accessor foo: T`)
181195
- name: RBS::AST::Members::AttrReader
182196
rust_name: AttrReaderNode
183197
fields:
@@ -187,14 +201,17 @@ nodes:
187201
c_type: rbs_node
188202
- name: ivar_name
189203
c_type: rbs_node # rbs_ast_symbol_t, NULL or rbs_ast_bool_new(false)
204+
optional: true # NULL when omitted (`attr_reader foo: T`); Symbol when named (`attr_reader foo (@bar): T`); Bool(false) when empty parens (`attr_reader foo (): T`)
190205
- name: kind
191206
c_type: rbs_keyword
192207
- name: annotations
193208
c_type: rbs_node_list
194209
- name: comment
195210
c_type: rbs_ast_comment
211+
optional: true # NULL when no comment precedes the declaration
196212
- name: visibility
197213
c_type: rbs_keyword
214+
optional: true # NULL when no visibility prefix (e.g., `attr_reader foo: T` vs `private attr_reader foo: T`)
198215
- name: RBS::AST::Members::AttrWriter
199216
rust_name: AttrWriterNode
200217
fields:
@@ -204,14 +221,17 @@ nodes:
204221
c_type: rbs_node
205222
- name: ivar_name
206223
c_type: rbs_node # rbs_ast_symbol_t, NULL or rbs_ast_bool_new(false)
224+
optional: true # NULL when omitted (`attr_writer foo: T`); Symbol when named (`attr_writer foo (@bar): T`); Bool(false) when empty parens (`attr_writer foo (): T`)
207225
- name: kind
208226
c_type: rbs_keyword
209227
- name: annotations
210228
c_type: rbs_node_list
211229
- name: comment
212230
c_type: rbs_ast_comment
231+
optional: true # NULL when no comment precedes the declaration
213232
- name: visibility
214233
c_type: rbs_keyword
234+
optional: true # NULL when no visibility prefix (e.g., `attr_writer foo: T` vs `private attr_writer foo: T`)
215235
- name: RBS::AST::Members::ClassInstanceVariable
216236
rust_name: ClassInstanceVariableNode
217237
fields:
@@ -221,6 +241,7 @@ nodes:
221241
c_type: rbs_node
222242
- name: comment
223243
c_type: rbs_ast_comment
244+
optional: true # NULL when no comment precedes the declaration
224245
- name: RBS::AST::Members::ClassVariable
225246
rust_name: ClassVariableNode
226247
fields:
@@ -230,6 +251,7 @@ nodes:
230251
c_type: rbs_node
231252
- name: comment
232253
c_type: rbs_ast_comment
254+
optional: true # NULL when no comment precedes the declaration
233255
- name: RBS::AST::Members::Extend
234256
rust_name: ExtendNode
235257
fields:
@@ -241,6 +263,7 @@ nodes:
241263
c_type: rbs_node_list
242264
- name: comment
243265
c_type: rbs_ast_comment
266+
optional: true # NULL when no comment precedes the declaration
244267
- name: RBS::AST::Members::Include
245268
rust_name: IncludeNode
246269
fields:
@@ -252,6 +275,7 @@ nodes:
252275
c_type: rbs_node_list
253276
- name: comment
254277
c_type: rbs_ast_comment
278+
optional: true # NULL when no comment precedes the declaration
255279
- name: RBS::AST::Members::InstanceVariable
256280
rust_name: InstanceVariableNode
257281
fields:
@@ -261,6 +285,7 @@ nodes:
261285
c_type: rbs_node
262286
- name: comment
263287
c_type: rbs_ast_comment
288+
optional: true # NULL when no comment precedes the declaration
264289
- name: RBS::AST::Members::MethodDefinition
265290
rust_name: MethodDefinitionNode
266291
fields:
@@ -274,10 +299,12 @@ nodes:
274299
c_type: rbs_node_list
275300
- name: comment
276301
c_type: rbs_ast_comment
302+
optional: true # NULL when no comment precedes the declaration
277303
- name: overloading
278304
c_type: bool
279305
- name: visibility
280306
c_type: rbs_keyword
307+
optional: true # NULL when no visibility prefix (e.g., `def foo: ...` vs `private def foo: ...`)
281308
- name: RBS::AST::Members::MethodDefinition::Overload
282309
rust_name: MethodDefinitionOverloadNode
283310
expose_location: false
@@ -297,6 +324,7 @@ nodes:
297324
c_type: rbs_node_list
298325
- name: comment
299326
c_type: rbs_ast_comment
327+
optional: true # NULL when no comment precedes the declaration
300328
- name: RBS::AST::Members::Private
301329
rust_name: PrivateNode
302330
- name: RBS::AST::Members::Public
@@ -310,10 +338,13 @@ nodes:
310338
c_type: rbs_keyword
311339
- name: upper_bound
312340
c_type: rbs_node
341+
optional: true # NULL when no upper bound (e.g., `[T]` vs `[T < Bound]`)
313342
- name: lower_bound
314343
c_type: rbs_node
344+
optional: true # NULL when no lower bound (e.g., `[T]` vs `[T > Bound]`)
315345
- name: default_type
316346
c_type: rbs_node
347+
optional: true # NULL when no default (e.g., `[T]` vs `[T = Default]`)
317348
- name: unchecked
318349
c_type: bool
319350
- name: RBS::AST::Integer
@@ -339,6 +370,7 @@ nodes:
339370
c_type: rbs_node
340371
- name: block
341372
c_type: rbs_types_block
373+
optional: true # NULL when no block (e.g., `() -> void` vs `() { () -> void } -> void`)
342374
- name: RBS::Namespace
343375
rust_name: NamespaceNode
344376
expose_location: false
@@ -403,6 +435,7 @@ nodes:
403435
c_type: bool
404436
- name: self_type
405437
c_type: rbs_node
438+
optional: true # NULL when no self binding (e.g., `{ () -> void }` vs `{ () [self: T] -> void }`)
406439
- name: RBS::Types::ClassInstance
407440
rust_name: ClassInstanceTypeNode
408441
fields:
@@ -425,6 +458,7 @@ nodes:
425458
c_type: rbs_node_list
426459
- name: rest_positionals
427460
c_type: rbs_node
461+
optional: true # NULL when no splat (e.g., `(String) -> void` vs `(*String) -> void`)
428462
- name: trailing_positionals
429463
c_type: rbs_node_list
430464
- name: required_keywords
@@ -433,6 +467,7 @@ nodes:
433467
c_type: rbs_hash
434468
- name: rest_keywords
435469
c_type: rbs_node
470+
optional: true # NULL when no double-splat (e.g., `() -> void` vs `(**String) -> void`)
436471
- name: return_type
437472
c_type: rbs_node
438473
- name: RBS::Types::Function::Param
@@ -442,6 +477,7 @@ nodes:
442477
c_type: rbs_node
443478
- name: name
444479
c_type: rbs_ast_symbol
480+
optional: true # NULL when param is unnamed (e.g., `(String) -> void` vs `(String name) -> void`)
445481
- name: RBS::Types::Interface
446482
rust_name: InterfaceTypeNode
447483
fields:
@@ -471,8 +507,10 @@ nodes:
471507
c_type: rbs_node
472508
- name: block
473509
c_type: rbs_types_block
510+
optional: true # NULL when proc has no block (e.g., `^() -> void` vs `^() { () -> void } -> void`)
474511
- name: self_type
475512
c_type: rbs_node
513+
optional: true # NULL when no self binding (e.g., `^() -> void` vs `^() [self: T] -> void`)
476514
- name: RBS::Types::Record
477515
rust_name: RecordTypeNode
478516
fields:

0 commit comments

Comments
 (0)