Skip to content

Commit 0adf3f0

Browse files
committed
Change C API naming to match Ruby API
This commit removes the `c_name` special cases from our templated code. Instead, we rename the C identifiers to always match their Ruby counterparts (which are the ones that matter, since they get exposed as keyword argument labels on the class’ constructors).
1 parent 00bd068 commit 0adf3f0

File tree

6 files changed

+29
-43
lines changed

6 files changed

+29
-43
lines changed

config.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ nodes:
209209
- name: RBS::Types::Alias
210210
fields:
211211
- name: name
212-
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
213212
- name: args
214213
- name: location
215214
- name: RBS::Types::Bases::Any
@@ -247,25 +246,18 @@ nodes:
247246
- name: RBS::Types::ClassInstance
248247
fields:
249248
- name: name
250-
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
251249
- name: args
252-
c_name: type_args # Temporary name to match existing C code. Will be removed in next PR.
253250
- name: location
254251
- name: RBS::Types::ClassSingleton
255252
fields:
256253
- name: name
257-
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
258254
- name: location
259255
- name: RBS::Types::Function
260256
fields:
261257
- name: required_positionals
262-
c_name: required_positional_params # Temporary name to match existing C code. Will be removed in next PR.
263258
- name: optional_positionals
264-
c_name: optional_positional_params # Temporary name to match existing C code. Will be removed in next PR.
265259
- name: rest_positionals
266-
c_name: rest_positional_params # Temporary name to match existing C code. Will be removed in next PR.
267260
- name: trailing_positionals
268-
c_name: trailing_positional_params # Temporary name to match existing C code. Will be removed in next PR.
269261
- name: required_keywords
270262
- name: optional_keywords
271263
- name: rest_keywords
@@ -278,9 +270,7 @@ nodes:
278270
- name: RBS::Types::Interface
279271
fields:
280272
- name: name
281-
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
282273
- name: args
283-
c_name: type_args # Temporary name to match existing C code. Will be removed in next PR.
284274
- name: location
285275
- name: RBS::Types::Intersection
286276
fields:
@@ -297,14 +287,12 @@ nodes:
297287
- name: RBS::Types::Proc
298288
fields:
299289
- name: type
300-
c_name: function # Temporary name to match existing C code. Will be removed in next PR.
301290
- name: block
302291
- name: location
303292
- name: self_type
304293
- name: RBS::Types::Record
305294
fields:
306295
- name: all_fields
307-
c_name: fields # Temporary name to match existing C code. Will be removed in next PR.
308296
- name: location
309297
- name: RBS::Types::Tuple
310298
fields:

include/rbs/ruby_objs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE de
4343
VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
4444
VALUE rbs_namespace(VALUE path, VALUE absolute);
4545
VALUE rbs_type_name(VALUE namespace, VALUE name);
46-
VALUE rbs_alias(VALUE typename, VALUE args, VALUE location);
46+
VALUE rbs_alias(VALUE name, VALUE args, VALUE location);
4747
VALUE rbs_bases_any(VALUE location);
4848
VALUE rbs_bases_bool(VALUE location);
4949
VALUE rbs_bases_bottom(VALUE location);
@@ -54,16 +54,16 @@ VALUE rbs_bases_self(VALUE location);
5454
VALUE rbs_bases_top(VALUE location);
5555
VALUE rbs_bases_void(VALUE location);
5656
VALUE rbs_block(VALUE type, VALUE required, VALUE self_type);
57-
VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location);
58-
VALUE rbs_class_singleton(VALUE typename, VALUE location);
59-
VALUE rbs_function(VALUE required_positional_params, VALUE optional_positional_params, VALUE rest_positional_params, VALUE trailing_positional_params, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type);
57+
VALUE rbs_class_instance(VALUE name, VALUE args, VALUE location);
58+
VALUE rbs_class_singleton(VALUE name, VALUE location);
59+
VALUE rbs_function(VALUE required_positionals, VALUE optional_positionals, VALUE rest_positionals, VALUE trailing_positionals, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type);
6060
VALUE rbs_function_param(VALUE type, VALUE name, VALUE location);
61-
VALUE rbs_interface(VALUE typename, VALUE type_args, VALUE location);
61+
VALUE rbs_interface(VALUE name, VALUE args, VALUE location);
6262
VALUE rbs_intersection(VALUE types, VALUE location);
6363
VALUE rbs_literal(VALUE literal, VALUE location);
6464
VALUE rbs_optional(VALUE type, VALUE location);
65-
VALUE rbs_proc(VALUE function, VALUE block, VALUE location, VALUE self_type);
66-
VALUE rbs_record(VALUE fields, VALUE location);
65+
VALUE rbs_proc(VALUE type, VALUE block, VALUE location, VALUE self_type);
66+
VALUE rbs_record(VALUE all_fields, VALUE location);
6767
VALUE rbs_tuple(VALUE types, VALUE location);
6868
VALUE rbs_union(VALUE types, VALUE location);
6969
VALUE rbs_untyped_function(VALUE return_type);

src/ruby_objs.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ VALUE rbs_type_name(VALUE namespace, VALUE name) {
488488
);
489489
}
490490

491-
VALUE rbs_alias(VALUE typename, VALUE args, VALUE location) {
491+
VALUE rbs_alias(VALUE name, VALUE args, VALUE location) {
492492
VALUE _init_kwargs = rb_hash_new();
493-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), typename);
493+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), name);
494494
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("args")), args);
495495
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
496496

@@ -613,10 +613,10 @@ VALUE rbs_block(VALUE type, VALUE required, VALUE self_type) {
613613
);
614614
}
615615

616-
VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location) {
616+
VALUE rbs_class_instance(VALUE name, VALUE args, VALUE location) {
617617
VALUE _init_kwargs = rb_hash_new();
618-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), typename);
619-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("args")), type_args);
618+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), name);
619+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("args")), args);
620620
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
621621

622622
return CLASS_NEW_INSTANCE(
@@ -626,9 +626,9 @@ VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location) {
626626
);
627627
}
628628

629-
VALUE rbs_class_singleton(VALUE typename, VALUE location) {
629+
VALUE rbs_class_singleton(VALUE name, VALUE location) {
630630
VALUE _init_kwargs = rb_hash_new();
631-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), typename);
631+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), name);
632632
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
633633

634634
return CLASS_NEW_INSTANCE(
@@ -638,12 +638,12 @@ VALUE rbs_class_singleton(VALUE typename, VALUE location) {
638638
);
639639
}
640640

641-
VALUE rbs_function(VALUE required_positional_params, VALUE optional_positional_params, VALUE rest_positional_params, VALUE trailing_positional_params, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type) {
641+
VALUE rbs_function(VALUE required_positionals, VALUE optional_positionals, VALUE rest_positionals, VALUE trailing_positionals, VALUE required_keywords, VALUE optional_keywords, VALUE rest_keywords, VALUE return_type) {
642642
VALUE _init_kwargs = rb_hash_new();
643-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("required_positionals")), required_positional_params);
644-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("optional_positionals")), optional_positional_params);
645-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("rest_positionals")), rest_positional_params);
646-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("trailing_positionals")), trailing_positional_params);
643+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("required_positionals")), required_positionals);
644+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("optional_positionals")), optional_positionals);
645+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("rest_positionals")), rest_positionals);
646+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("trailing_positionals")), trailing_positionals);
647647
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("required_keywords")), required_keywords);
648648
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("optional_keywords")), optional_keywords);
649649
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("rest_keywords")), rest_keywords);
@@ -669,10 +669,10 @@ VALUE rbs_function_param(VALUE type, VALUE name, VALUE location) {
669669
);
670670
}
671671

672-
VALUE rbs_interface(VALUE typename, VALUE type_args, VALUE location) {
672+
VALUE rbs_interface(VALUE name, VALUE args, VALUE location) {
673673
VALUE _init_kwargs = rb_hash_new();
674-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), typename);
675-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("args")), type_args);
674+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), name);
675+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("args")), args);
676676
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
677677

678678
return CLASS_NEW_INSTANCE(
@@ -718,9 +718,9 @@ VALUE rbs_optional(VALUE type, VALUE location) {
718718
);
719719
}
720720

721-
VALUE rbs_proc(VALUE function, VALUE block, VALUE location, VALUE self_type) {
721+
VALUE rbs_proc(VALUE type, VALUE block, VALUE location, VALUE self_type) {
722722
VALUE _init_kwargs = rb_hash_new();
723-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("type")), function);
723+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("type")), type);
724724
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("block")), block);
725725
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
726726
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("self_type")), self_type);
@@ -732,9 +732,9 @@ VALUE rbs_proc(VALUE function, VALUE block, VALUE location, VALUE self_type) {
732732
);
733733
}
734734

735-
VALUE rbs_record(VALUE fields, VALUE location) {
735+
VALUE rbs_record(VALUE all_fields, VALUE location) {
736736
VALUE _init_kwargs = rb_hash_new();
737-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("all_fields")), fields);
737+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("all_fields")), all_fields);
738738
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
739739

740740
return CLASS_NEW_INSTANCE(

templates/include/rbs/ruby_objs.h.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "ruby.h"
55

66
<%- nodes.each do |node| -%>
7-
VALUE <%= node.c_function_name %>(<%= node.fields.map { |field| "#{field.c_type} #{field.c_name}" }.join(", ") %>);
7+
VALUE <%= node.c_function_name %>(<%= node.fields.map { |field| "#{field.c_type} #{field.name}" }.join(", ") %>);
88
<%- end -%>
99

1010
#endif

templates/src/ruby_objs.c.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#endif
1212

1313
<%- nodes.each do |node| -%>
14-
VALUE <%= node.c_function_name %>(<%= node.fields.map { |field| "#{field.c_type} #{field.c_name}" }.join(", ") %>) {
14+
VALUE <%= node.c_function_name %>(<%= node.fields.map { |field| "#{field.c_type} #{field.name}" }.join(", ") %>) {
1515
VALUE _init_kwargs = rb_hash_new();
1616
<%- node.fields.each do |field| -%>
17-
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("<%= field.name %>")), <%= field.c_name %>);
17+
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("<%= field.name %>")), <%= field.name %>);
1818
<%- end -%>
1919

2020
return CLASS_NEW_INSTANCE(

templates/template.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ module RBS
1111
class Template
1212
class Field
1313
attr_reader :name
14-
attr_reader :c_name
1514
attr_reader :c_type
1615

1716
def initialize(yaml)
1817
@name = yaml["name"]
19-
@c_name = yaml["c_name"] || @name
2018
@c_type = "VALUE"
2119
end
2220
end

0 commit comments

Comments
 (0)