diff --git a/Gemfile-39 b/Gemfile-39 new file mode 100644 index 000000000..49f3d9a86 --- /dev/null +++ b/Gemfile-39 @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +gem 'rbs', "~> 3.9" +gem "benchmark-ips" +gem "csv" \ No newline at end of file diff --git a/Gemfile-39.lock b/Gemfile-39.lock new file mode 100644 index 000000000..9b9846dec --- /dev/null +++ b/Gemfile-39.lock @@ -0,0 +1,20 @@ +GEM + remote: https://rubygems.org/ + specs: + benchmark-ips (2.14.0) + csv (3.3.5) + logger (1.7.0) + rbs (3.9.4) + logger + +PLATFORMS + arm64-darwin-23 + ruby + +DEPENDENCIES + benchmark-ips + csv + rbs (~> 3.9) + +BUNDLED WITH + 2.6.3 diff --git a/Rakefile b/Rakefile index 2a9541de8..f3f077714 100644 --- a/Rakefile +++ b/Rakefile @@ -537,3 +537,11 @@ task :compile_c99 do ensure ENV.delete("TEST_NO_C23") end + + +task :prepare_bench do + ENV.delete("DEBUG") + Rake::Task[:"clobber"].invoke + Rake::Task[:"templates"].invoke + Rake::Task[:"compile"].invoke +end \ No newline at end of file diff --git a/benchmark.rb b/benchmark.rb new file mode 100644 index 000000000..1dffe61e5 --- /dev/null +++ b/benchmark.rb @@ -0,0 +1,11 @@ +require "bundler/setup" + +require 'rbs' +require 'benchmark/ips' + +sig = Pathname('/Users/soutaro/Downloads/activerecord-generated.rbs').read +Benchmark.ips do |x| + x.report("rbs v#{RBS::VERSION} parse activerecord-generated.rbs") do + RBS::Parser.parse_signature(sig) + end +end diff --git a/benchmarks.rb b/benchmarks.rb new file mode 100644 index 000000000..43e206618 --- /dev/null +++ b/benchmarks.rb @@ -0,0 +1,35 @@ +require "rbs" +require "benchmark/ips" +require "csv" + +results = [] + +total = ARGV.size +ARGV.each_with_index do |file, index| + GC.start + + STDERR.puts "#{index}/#{total}\tBenchmarking with #{file}..." + content = File.read(file) + + benchmark = Benchmark.ips do |x| + x.report(file) do + RBS::Parser.parse_signature(content) + end + + x.quiet = true + end + + results << { + file: file, + size: content.bytesize, + ips: benchmark.entries[0].ips, + sd: benchmark.entries[0].ips_sd + } +end + +puts CSV.generate {|csv| + csv << ["File", "Size", "IPS", "SD"] + results.each do |result| + csv << [result[:file], result[:size], result[:ips], result[:sd]] + end +} diff --git a/ext/rbs_extension/ast_translation.c b/ext/rbs_extension/ast_translation.c index 37d0ea179..12ebf1f07 100644 --- a/ext/rbs_extension/ast_translation.c +++ b/ext/rbs_extension/ast_translation.c @@ -11,6 +11,9 @@ #include "rbs_string_bridging.h" #include "legacy_location.h" +VALUE EMPTY_ARRAY; +VALUE EMPTY_HASH; + #define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1)) rbs_translation_context_t rbs_translation_context_create(rbs_constant_pool_t *constant_pool, VALUE buffer, rb_encoding *ruby_encoding) { @@ -22,16 +25,32 @@ rbs_translation_context_t rbs_translation_context_create(rbs_constant_pool_t *co } VALUE rbs_node_list_to_ruby_array(rbs_translation_context_t ctx, rbs_node_list_t *list) { + if (!list->head) { + return EMPTY_ARRAY; + } + VALUE ruby_array = rb_ary_new(); + VALUE *values = ALLOCA_N(VALUE, list->length); - for (rbs_node_list_node_t *n = list->head; n != NULL; n = n->next) { - rb_ary_push(ruby_array, rbs_struct_to_ruby_value(ctx, n->node)); + size_t i = 0; + for (rbs_node_list_node_t *n = list->head; n != NULL; n = n->next, i++) { + values[i] = rbs_struct_to_ruby_value(ctx, n->node); } + rb_ary_cat(ruby_array, values, list->length); + return ruby_array; } VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t ctx, rbs_hash_t *rbs_hash) { + if (rbs_hash->length > 0) { + printf("Size of hash: %zu\n", rbs_hash->length); + } + + if (!rbs_hash->head) { + return EMPTY_HASH; + } + VALUE ruby_hash = rb_hash_new(); for (rbs_hash_node_t *n = rbs_hash->head; n != NULL; n = n->next) { @@ -60,12 +79,12 @@ VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *so } VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_location_list_t *list) { - VALUE ruby_array = rb_ary_new(); - if (list == NULL) { - return ruby_array; + return EMPTY_ARRAY; } + VALUE ruby_array = rb_ary_new(); + for (rbs_location_list_node_t *n = list->head; n != NULL; n = n->next) { rb_ary_push(ruby_array, rbs_loc_to_ruby_location(ctx, n->loc)); } @@ -83,264 +102,1017 @@ VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_locatio rb_class_new_instance(argc, argv, receiver) #endif +VALUE rbs_ast_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("string")), rbs_string_to_ruby_string(&node->string, ctx.encoding)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Annotation, + 1, + &h + ); +} + +VALUE rbs_ast_comment_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_comment_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("string")), rbs_string_to_ruby_string(&node->string, ctx.encoding)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Comment, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_class_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_class_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); + rb_hash_aset(h, ID2SYM(rb_intern("super_class")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->super_class)); // rbs_ast_declarations_class_super + rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + rb_funcall( + RBS_AST_TypeParam, + rb_intern("resolve_variables"), + 1, + rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) + ); + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Class, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_class_super_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_class_super_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Class_Super, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_class_alias_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_class_alias_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_ClassAlias, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_constant_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_constant_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Constant, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_global_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_global_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Global, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_interface_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_interface_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); + rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + rb_funcall( + RBS_AST_TypeParam, + rb_intern("resolve_variables"), + 1, + rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) + ); + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Interface, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_module_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_module_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); + rb_hash_aset(h, ID2SYM(rb_intern("self_types")), rbs_node_list_to_ruby_array(ctx, node->self_types)); + rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + rb_funcall( + RBS_AST_TypeParam, + rb_intern("resolve_variables"), + 1, + rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) + ); + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Module, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_module_self_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_module_self_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_Module_Self, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_module_alias_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_module_alias_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_ModuleAlias, + 1, + &h + ); +} + +VALUE rbs_ast_declarations_type_alias_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_declarations_type_alias_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + rb_funcall( + RBS_AST_TypeParam, + rb_intern("resolve_variables"), + 1, + rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) + ); + return CLASS_NEW_INSTANCE( + RBS_AST_Declarations_TypeAlias, + 1, + &h + ); +} + +VALUE rbs_ast_directives_use_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_directives_use_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("clauses")), rbs_node_list_to_ruby_array(ctx, node->clauses)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Directives_Use, + 1, + &h + ); +} + +VALUE rbs_ast_directives_use_single_clause_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_directives_use_single_clause_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_ast_symbol + + return CLASS_NEW_INSTANCE( + RBS_AST_Directives_Use_SingleClause, + 1, + &h + ); +} + +VALUE rbs_ast_directives_use_wildcard_clause_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_directives_use_wildcard_clause_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("namespace")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rbs_namespace)); // rbs_namespace + + return CLASS_NEW_INSTANCE( + RBS_AST_Directives_Use_WildcardClause, + 1, + &h + ); +} + +VALUE rbs_ast_members_alias_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_alias_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_Alias, + 1, + &h + ); +} + +VALUE rbs_ast_members_attr_accessor_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_attr_accessor_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_AttrAccessor, + 1, + &h + ); +} + +VALUE rbs_ast_members_attr_reader_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_attr_reader_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_AttrReader, + 1, + &h + ); +} + +VALUE rbs_ast_members_attr_writer_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_attr_writer_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_AttrWriter, + 1, + &h + ); +} + +VALUE rbs_ast_members_class_instance_variable_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_class_instance_variable_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_ClassInstanceVariable, + 1, + &h + ); +} + +VALUE rbs_ast_members_class_variable_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_class_variable_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_ClassVariable, + 1, + &h + ); +} + +VALUE rbs_ast_members_extend_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_extend_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_Extend, + 1, + &h + ); +} + +VALUE rbs_ast_members_include_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_include_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_Include, + 1, + &h + ); +} + +VALUE rbs_ast_members_instance_variable_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_instance_variable_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_InstanceVariable, + 1, + &h + ); +} + +VALUE rbs_ast_members_method_definition_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_method_definition_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword + rb_hash_aset(h, ID2SYM(rb_intern("overloads")), rbs_node_list_to_ruby_array(ctx, node->overloads)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + rb_hash_aset(h, ID2SYM(rb_intern("overloading")), node->overloading ? Qtrue : Qfalse); + rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_MethodDefinition, + 1, + &h + ); +} + +VALUE rbs_ast_members_method_definition_overload_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_method_definition_overload_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("method_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->method_type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_MethodDefinition_Overload, + 1, + &h + ); +} + +VALUE rbs_ast_members_prepend_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_prepend_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_Prepend, + 1, + &h + ); +} + +VALUE rbs_ast_members_private_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_private_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_Private, + 1, + &h + ); +} + +VALUE rbs_ast_members_public_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_members_public_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Members_Public, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_class_alias_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_class_alias_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("keyword_location")), rbs_loc_to_ruby_location(ctx, node->keyword_location)); + rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type_name_location")), rbs_loc_to_ruby_location(ctx, node->type_name_location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ClassAliasAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_colon_method_type_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_colon_method_type_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("method_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->method_type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_instance_variable_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_instance_variable_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("ivar_name_location")), rbs_loc_to_ruby_location(ctx, node->ivar_name_location)); + rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_loc_to_ruby_location(ctx, node->colon_location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_InstanceVariableAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_method_types_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_method_types_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("overloads")), rbs_node_list_to_ruby_array(ctx, node->overloads)); + rb_hash_aset(h, ID2SYM(rb_intern("vertical_bar_locations")), rbs_location_list_to_ruby_array(ctx, node->vertical_bar_locations)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_MethodTypesAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_module_alias_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_module_alias_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("keyword_location")), rbs_loc_to_ruby_location(ctx, node->keyword_location)); + rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("type_name_location")), rbs_loc_to_ruby_location(ctx, node->type_name_location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ModuleAliasAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_node_type_assertion_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_node_type_assertion_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_NodeTypeAssertion, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_return_type_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_return_type_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("return_location")), rbs_loc_to_ruby_location(ctx, node->return_location)); + rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_loc_to_ruby_location(ctx, node->colon_location)); + rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_skip_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_skip_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("skip_location")), rbs_loc_to_ruby_location(ctx, node->skip_location)); + rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_SkipAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_ruby_annotations_type_application_annotation_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_ruby_annotations_type_application_annotation_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("type_args")), rbs_node_list_to_ruby_array(ctx, node->type_args)); + rb_hash_aset(h, ID2SYM(rb_intern("close_bracket_location")), rbs_loc_to_ruby_location(ctx, node->close_bracket_location)); + rb_hash_aset(h, ID2SYM(rb_intern("comma_locations")), rbs_location_list_to_ruby_array(ctx, node->comma_locations)); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_TypeApplicationAnnotation, + 1, + &h + ); +} + +VALUE rbs_ast_type_param_t_to_ruby_value(rbs_translation_context_t ctx, rbs_ast_type_param_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + rb_hash_aset(h, ID2SYM(rb_intern("variance")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->variance)); // rbs_keyword + rb_hash_aset(h, ID2SYM(rb_intern("upper_bound")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->upper_bound)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("lower_bound")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->lower_bound)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("default_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->default_type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("unchecked")), node->unchecked ? Qtrue : Qfalse); + + return CLASS_NEW_INSTANCE( + RBS_AST_TypeParam, + 1, + &h + ); +} + +VALUE rbs_method_type_t_to_ruby_value(rbs_translation_context_t ctx, rbs_method_type_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("block")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->block)); // rbs_types_block + + rb_funcall( + RBS_AST_TypeParam, + rb_intern("resolve_variables"), + 1, + rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) + ); + return CLASS_NEW_INSTANCE( + RBS_MethodType, + 1, + &h + ); +} + +VALUE rbs_namespace_t_to_ruby_value(rbs_translation_context_t ctx, rbs_namespace_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("path")), rbs_node_list_to_ruby_array(ctx, node->path)); + rb_hash_aset(h, ID2SYM(rb_intern("absolute")), node->absolute ? Qtrue : Qfalse); + + return CLASS_NEW_INSTANCE( + RBS_Namespace, + 1, + &h + ); +} + +VALUE rbs_type_name_t_to_ruby_value(rbs_translation_context_t ctx, rbs_type_name_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("namespace")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rbs_namespace)); // rbs_namespace + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + + return CLASS_NEW_INSTANCE( + RBS_TypeName, + 1, + &h + ); +} + +VALUE rbs_types_alias_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_alias_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Alias, + 1, + &h + ); +} + +VALUE rbs_types_bases_any_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_any_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("todo")), node->todo ? Qtrue : Qfalse); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Any, + 1, + &h + ); +} + +VALUE rbs_types_bases_bool_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_bool_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Bool, + 1, + &h + ); +} + +VALUE rbs_types_bases_bottom_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_bottom_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Bottom, + 1, + &h + ); +} + +VALUE rbs_types_bases_class_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_class_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Class, + 1, + &h + ); +} + +VALUE rbs_types_bases_instance_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_instance_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Instance, + 1, + &h + ); +} + +VALUE rbs_types_bases_nil_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_nil_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Nil, + 1, + &h + ); +} + +VALUE rbs_types_bases_self_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_self_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Self, + 1, + &h + ); +} + +VALUE rbs_types_bases_top_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_top_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Top, + 1, + &h + ); +} + +VALUE rbs_types_bases_void_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_bases_void_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Bases_Void, + 1, + &h + ); +} + +VALUE rbs_types_block_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_block_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("required")), node->required ? Qtrue : Qfalse); + rb_hash_aset(h, ID2SYM(rb_intern("self_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->self_type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_Types_Block, + 1, + &h + ); +} + +VALUE rbs_types_class_instance_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_class_instance_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + + return CLASS_NEW_INSTANCE( + RBS_Types_ClassInstance, + 1, + &h + ); +} + +VALUE rbs_types_class_singleton_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_class_singleton_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + + return CLASS_NEW_INSTANCE( + RBS_Types_ClassSingleton, + 1, + &h + ); +} + +VALUE rbs_types_function_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_function_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("required_positionals")), rbs_node_list_to_ruby_array(ctx, node->required_positionals)); + rb_hash_aset(h, ID2SYM(rb_intern("optional_positionals")), rbs_node_list_to_ruby_array(ctx, node->optional_positionals)); + rb_hash_aset(h, ID2SYM(rb_intern("rest_positionals")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rest_positionals)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("trailing_positionals")), rbs_node_list_to_ruby_array(ctx, node->trailing_positionals)); + rb_hash_aset(h, ID2SYM(rb_intern("required_keywords")), rbs_hash_to_ruby_hash(ctx, node->required_keywords)); + rb_hash_aset(h, ID2SYM(rb_intern("optional_keywords")), rbs_hash_to_ruby_hash(ctx, node->optional_keywords)); + rb_hash_aset(h, ID2SYM(rb_intern("rest_keywords")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rest_keywords)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_Types_Function, + 1, + &h + ); +} + +VALUE rbs_types_function_param_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_function_param_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + + return CLASS_NEW_INSTANCE( + RBS_Types_Function_Param, + 1, + &h + ); +} + +VALUE rbs_types_interface_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_interface_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name + rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Interface, + 1, + &h + ); +} + +VALUE rbs_types_intersection_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_intersection_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Intersection, + 1, + &h + ); +} + +VALUE rbs_types_literal_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_literal_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("literal")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->literal)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_Types_Literal, + 1, + &h + ); +} + +VALUE rbs_types_optional_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_optional_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_Types_Optional, + 1, + &h + ); +} + +VALUE rbs_types_proc_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_proc_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("block")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->block)); // rbs_types_block + rb_hash_aset(h, ID2SYM(rb_intern("self_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->self_type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_Types_Proc, + 1, + &h + ); +} + +VALUE rbs_types_record_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_record_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("all_fields")), rbs_hash_to_ruby_hash(ctx, node->all_fields)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Record, + 1, + &h + ); +} + +VALUE rbs_types_tuple_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_tuple_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Tuple, + 1, + &h + ); +} + +VALUE rbs_types_union_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_union_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types)); + + return CLASS_NEW_INSTANCE( + RBS_Types_Union, + 1, + &h + ); +} + +VALUE rbs_types_untyped_function_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_untyped_function_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node + + return CLASS_NEW_INSTANCE( + RBS_Types_UntypedFunction, + 1, + &h + ); +} + +VALUE rbs_types_variable_t_to_ruby_value(rbs_translation_context_t ctx, rbs_types_variable_t *node) { + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol + + return CLASS_NEW_INSTANCE( + RBS_Types_Variable, + 1, + &h + ); +} + VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instance) { if (instance == NULL) return Qnil; switch (instance->type) { case RBS_AST_ANNOTATION: { rbs_ast_annotation_t *node = (rbs_ast_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("string")), rbs_string_to_ruby_string(&node->string, ctx.encoding)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Annotation, - 1, - &h - ); + return rbs_ast_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_BOOL: { return ((rbs_ast_bool_t *) instance)->value ? Qtrue : Qfalse; } case RBS_AST_COMMENT: { rbs_ast_comment_t *node = (rbs_ast_comment_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("string")), rbs_string_to_ruby_string(&node->string, ctx.encoding)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Comment, - 1, - &h - ); + return rbs_ast_comment_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_CLASS: { rbs_ast_declarations_class_t *node = (rbs_ast_declarations_class_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); - rb_hash_aset(h, ID2SYM(rb_intern("super_class")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->super_class)); // rbs_ast_declarations_class_super - rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - rb_funcall( - RBS_AST_TypeParam, - rb_intern("resolve_variables"), - 1, - rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) - ); - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Class, - 1, - &h - ); + return rbs_ast_declarations_class_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_CLASS_SUPER: { rbs_ast_declarations_class_super_t *node = (rbs_ast_declarations_class_super_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Class_Super, - 1, - &h - ); + return rbs_ast_declarations_class_super_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_CLASS_ALIAS: { rbs_ast_declarations_class_alias_t *node = (rbs_ast_declarations_class_alias_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_ClassAlias, - 1, - &h - ); + return rbs_ast_declarations_class_alias_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_CONSTANT: { rbs_ast_declarations_constant_t *node = (rbs_ast_declarations_constant_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Constant, - 1, - &h - ); + return rbs_ast_declarations_constant_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_GLOBAL: { rbs_ast_declarations_global_t *node = (rbs_ast_declarations_global_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Global, - 1, - &h - ); + return rbs_ast_declarations_global_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_INTERFACE: { rbs_ast_declarations_interface_t *node = (rbs_ast_declarations_interface_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); - rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - rb_funcall( - RBS_AST_TypeParam, - rb_intern("resolve_variables"), - 1, - rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) - ); - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Interface, - 1, - &h - ); + return rbs_ast_declarations_interface_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_MODULE: { rbs_ast_declarations_module_t *node = (rbs_ast_declarations_module_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); - rb_hash_aset(h, ID2SYM(rb_intern("self_types")), rbs_node_list_to_ruby_array(ctx, node->self_types)); - rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - rb_funcall( - RBS_AST_TypeParam, - rb_intern("resolve_variables"), - 1, - rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) - ); - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Module, - 1, - &h - ); + return rbs_ast_declarations_module_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_MODULE_SELF: { rbs_ast_declarations_module_self_t *node = (rbs_ast_declarations_module_self_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_Module_Self, - 1, - &h - ); + return rbs_ast_declarations_module_self_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_MODULE_ALIAS: { rbs_ast_declarations_module_alias_t *node = (rbs_ast_declarations_module_alias_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_ModuleAlias, - 1, - &h - ); + return rbs_ast_declarations_module_alias_t_to_ruby_value(ctx, node); } case RBS_AST_DECLARATIONS_TYPE_ALIAS: { rbs_ast_declarations_type_alias_t *node = (rbs_ast_declarations_type_alias_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - rb_funcall( - RBS_AST_TypeParam, - rb_intern("resolve_variables"), - 1, - rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) - ); - return CLASS_NEW_INSTANCE( - RBS_AST_Declarations_TypeAlias, - 1, - &h - ); + return rbs_ast_declarations_type_alias_t_to_ruby_value(ctx, node); } case RBS_AST_DIRECTIVES_USE: { rbs_ast_directives_use_t *node = (rbs_ast_directives_use_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("clauses")), rbs_node_list_to_ruby_array(ctx, node->clauses)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Directives_Use, - 1, - &h - ); + return rbs_ast_directives_use_t_to_ruby_value(ctx, node); } case RBS_AST_DIRECTIVES_USE_SINGLE_CLAUSE: { rbs_ast_directives_use_single_clause_t *node = (rbs_ast_directives_use_single_clause_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_ast_symbol - - return CLASS_NEW_INSTANCE( - RBS_AST_Directives_Use_SingleClause, - 1, - &h - ); + return rbs_ast_directives_use_single_clause_t_to_ruby_value(ctx, node); } case RBS_AST_DIRECTIVES_USE_WILDCARD_CLAUSE: { rbs_ast_directives_use_wildcard_clause_t *node = (rbs_ast_directives_use_wildcard_clause_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("namespace")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rbs_namespace)); // rbs_namespace - - return CLASS_NEW_INSTANCE( - RBS_AST_Directives_Use_WildcardClause, - 1, - &h - ); + return rbs_ast_directives_use_wildcard_clause_t_to_ruby_value(ctx, node); } case RBS_AST_INTEGER: { rbs_ast_integer_t *integer_node = (rbs_ast_integer_t *) instance; @@ -352,368 +1124,95 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan } case RBS_AST_MEMBERS_ALIAS: { rbs_ast_members_alias_t *node = (rbs_ast_members_alias_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_Alias, - 1, - &h - ); + return rbs_ast_members_alias_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_ATTR_ACCESSOR: { rbs_ast_members_attr_accessor_t *node = (rbs_ast_members_attr_accessor_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_AttrAccessor, - 1, - &h - ); + return rbs_ast_members_attr_accessor_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_ATTR_READER: { rbs_ast_members_attr_reader_t *node = (rbs_ast_members_attr_reader_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_AttrReader, - 1, - &h - ); + return rbs_ast_members_attr_reader_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_ATTR_WRITER: { rbs_ast_members_attr_writer_t *node = (rbs_ast_members_attr_writer_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_AttrWriter, - 1, - &h - ); + return rbs_ast_members_attr_writer_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_CLASS_INSTANCE_VARIABLE: { rbs_ast_members_class_instance_variable_t *node = (rbs_ast_members_class_instance_variable_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_ClassInstanceVariable, - 1, - &h - ); + return rbs_ast_members_class_instance_variable_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_CLASS_VARIABLE: { rbs_ast_members_class_variable_t *node = (rbs_ast_members_class_variable_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_ClassVariable, - 1, - &h - ); + return rbs_ast_members_class_variable_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_EXTEND: { rbs_ast_members_extend_t *node = (rbs_ast_members_extend_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_Extend, - 1, - &h - ); + return rbs_ast_members_extend_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_INCLUDE: { rbs_ast_members_include_t *node = (rbs_ast_members_include_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_Include, - 1, - &h - ); + return rbs_ast_members_include_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_INSTANCE_VARIABLE: { rbs_ast_members_instance_variable_t *node = (rbs_ast_members_instance_variable_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_InstanceVariable, - 1, - &h - ); + return rbs_ast_members_instance_variable_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_METHOD_DEFINITION: { rbs_ast_members_method_definition_t *node = (rbs_ast_members_method_definition_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword - rb_hash_aset(h, ID2SYM(rb_intern("overloads")), rbs_node_list_to_ruby_array(ctx, node->overloads)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - rb_hash_aset(h, ID2SYM(rb_intern("overloading")), node->overloading ? Qtrue : Qfalse); - rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_MethodDefinition, - 1, - &h - ); + return rbs_ast_members_method_definition_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_METHOD_DEFINITION_OVERLOAD: { rbs_ast_members_method_definition_overload_t *node = (rbs_ast_members_method_definition_overload_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("method_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->method_type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_MethodDefinition_Overload, - 1, - &h - ); + return rbs_ast_members_method_definition_overload_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_PREPEND: { rbs_ast_members_prepend_t *node = (rbs_ast_members_prepend_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_Prepend, - 1, - &h - ); + return rbs_ast_members_prepend_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_PRIVATE: { rbs_ast_members_private_t *node = (rbs_ast_members_private_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_Private, - 1, - &h - ); + return rbs_ast_members_private_t_to_ruby_value(ctx, node); } case RBS_AST_MEMBERS_PUBLIC: { rbs_ast_members_public_t *node = (rbs_ast_members_public_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Members_Public, - 1, - &h - ); + return rbs_ast_members_public_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_CLASS_ALIAS_ANNOTATION: { rbs_ast_ruby_annotations_class_alias_annotation_t *node = (rbs_ast_ruby_annotations_class_alias_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("keyword_location")), rbs_loc_to_ruby_location(ctx, node->keyword_location)); - rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type_name_location")), rbs_loc_to_ruby_location(ctx, node->type_name_location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_ClassAliasAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_class_alias_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION: { rbs_ast_ruby_annotations_colon_method_type_annotation_t *node = (rbs_ast_ruby_annotations_colon_method_type_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); - rb_hash_aset(h, ID2SYM(rb_intern("method_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->method_type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_colon_method_type_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_INSTANCE_VARIABLE_ANNOTATION: { rbs_ast_ruby_annotations_instance_variable_annotation_t *node = (rbs_ast_ruby_annotations_instance_variable_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("ivar_name_location")), rbs_loc_to_ruby_location(ctx, node->ivar_name_location)); - rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_loc_to_ruby_location(ctx, node->colon_location)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_InstanceVariableAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_instance_variable_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION: { rbs_ast_ruby_annotations_method_types_annotation_t *node = (rbs_ast_ruby_annotations_method_types_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("overloads")), rbs_node_list_to_ruby_array(ctx, node->overloads)); - rb_hash_aset(h, ID2SYM(rb_intern("vertical_bar_locations")), rbs_location_list_to_ruby_array(ctx, node->vertical_bar_locations)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_MethodTypesAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_method_types_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_MODULE_ALIAS_ANNOTATION: { rbs_ast_ruby_annotations_module_alias_annotation_t *node = (rbs_ast_ruby_annotations_module_alias_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("keyword_location")), rbs_loc_to_ruby_location(ctx, node->keyword_location)); - rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("type_name_location")), rbs_loc_to_ruby_location(ctx, node->type_name_location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_ModuleAliasAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_module_alias_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION: { rbs_ast_ruby_annotations_node_type_assertion_t *node = (rbs_ast_ruby_annotations_node_type_assertion_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_NodeTypeAssertion, - 1, - &h - ); + return rbs_ast_ruby_annotations_node_type_assertion_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION: { rbs_ast_ruby_annotations_return_type_annotation_t *node = (rbs_ast_ruby_annotations_return_type_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("return_location")), rbs_loc_to_ruby_location(ctx, node->return_location)); - rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_loc_to_ruby_location(ctx, node->colon_location)); - rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_return_type_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION: { rbs_ast_ruby_annotations_skip_annotation_t *node = (rbs_ast_ruby_annotations_skip_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("skip_location")), rbs_loc_to_ruby_location(ctx, node->skip_location)); - rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_SkipAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_skip_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_RUBY_ANNOTATIONS_TYPE_APPLICATION_ANNOTATION: { rbs_ast_ruby_annotations_type_application_annotation_t *node = (rbs_ast_ruby_annotations_type_application_annotation_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); - rb_hash_aset(h, ID2SYM(rb_intern("type_args")), rbs_node_list_to_ruby_array(ctx, node->type_args)); - rb_hash_aset(h, ID2SYM(rb_intern("close_bracket_location")), rbs_loc_to_ruby_location(ctx, node->close_bracket_location)); - rb_hash_aset(h, ID2SYM(rb_intern("comma_locations")), rbs_location_list_to_ruby_array(ctx, node->comma_locations)); - - return CLASS_NEW_INSTANCE( - RBS_AST_Ruby_Annotations_TypeApplicationAnnotation, - 1, - &h - ); + return rbs_ast_ruby_annotations_type_application_annotation_t_to_ruby_value(ctx, node); } case RBS_AST_STRING: { rbs_ast_string_t *string_node = (rbs_ast_string_t *) instance; @@ -723,55 +1222,15 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan } case RBS_AST_TYPE_PARAM: { rbs_ast_type_param_t *node = (rbs_ast_type_param_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - rb_hash_aset(h, ID2SYM(rb_intern("variance")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->variance)); // rbs_keyword - rb_hash_aset(h, ID2SYM(rb_intern("upper_bound")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->upper_bound)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("lower_bound")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->lower_bound)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("default_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->default_type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("unchecked")), node->unchecked ? Qtrue : Qfalse); - - return CLASS_NEW_INSTANCE( - RBS_AST_TypeParam, - 1, - &h - ); + return rbs_ast_type_param_t_to_ruby_value(ctx, node); } case RBS_METHOD_TYPE: { rbs_method_type_t *node = (rbs_method_type_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("block")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->block)); // rbs_types_block - - rb_funcall( - RBS_AST_TypeParam, - rb_intern("resolve_variables"), - 1, - rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) - ); - return CLASS_NEW_INSTANCE( - RBS_MethodType, - 1, - &h - ); + return rbs_method_type_t_to_ruby_value(ctx, node); } case RBS_NAMESPACE: { rbs_namespace_t *node = (rbs_namespace_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("path")), rbs_node_list_to_ruby_array(ctx, node->path)); - rb_hash_aset(h, ID2SYM(rb_intern("absolute")), node->absolute ? Qtrue : Qfalse); - - return CLASS_NEW_INSTANCE( - RBS_Namespace, - 1, - &h - ); + return rbs_namespace_t_to_ruby_value(ctx, node); } case RBS_SIGNATURE: { rbs_signature_t *signature = (rbs_signature_t *) instance; @@ -783,295 +1242,91 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan } case RBS_TYPE_NAME: { rbs_type_name_t *node = (rbs_type_name_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("namespace")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rbs_namespace)); // rbs_namespace - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - - return CLASS_NEW_INSTANCE( - RBS_TypeName, - 1, - &h - ); + return rbs_type_name_t_to_ruby_value(ctx, node); } case RBS_TYPES_ALIAS: { rbs_types_alias_t *node = (rbs_types_alias_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Alias, - 1, - &h - ); + return rbs_types_alias_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_ANY: { rbs_types_bases_any_t *node = (rbs_types_bases_any_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("todo")), node->todo ? Qtrue : Qfalse); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Any, - 1, - &h - ); + return rbs_types_bases_any_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_BOOL: { rbs_types_bases_bool_t *node = (rbs_types_bases_bool_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Bool, - 1, - &h - ); + return rbs_types_bases_bool_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_BOTTOM: { rbs_types_bases_bottom_t *node = (rbs_types_bases_bottom_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Bottom, - 1, - &h - ); + return rbs_types_bases_bottom_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_CLASS: { rbs_types_bases_class_t *node = (rbs_types_bases_class_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Class, - 1, - &h - ); + return rbs_types_bases_class_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_INSTANCE: { rbs_types_bases_instance_t *node = (rbs_types_bases_instance_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Instance, - 1, - &h - ); + return rbs_types_bases_instance_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_NIL: { rbs_types_bases_nil_t *node = (rbs_types_bases_nil_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Nil, - 1, - &h - ); + return rbs_types_bases_nil_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_SELF: { rbs_types_bases_self_t *node = (rbs_types_bases_self_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Self, - 1, - &h - ); + return rbs_types_bases_self_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_TOP: { rbs_types_bases_top_t *node = (rbs_types_bases_top_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Top, - 1, - &h - ); + return rbs_types_bases_top_t_to_ruby_value(ctx, node); } case RBS_TYPES_BASES_VOID: { rbs_types_bases_void_t *node = (rbs_types_bases_void_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Bases_Void, - 1, - &h - ); + return rbs_types_bases_void_t_to_ruby_value(ctx, node); } case RBS_TYPES_BLOCK: { rbs_types_block_t *node = (rbs_types_block_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("required")), node->required ? Qtrue : Qfalse); - rb_hash_aset(h, ID2SYM(rb_intern("self_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->self_type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_Types_Block, - 1, - &h - ); + return rbs_types_block_t_to_ruby_value(ctx, node); } case RBS_TYPES_CLASS_INSTANCE: { rbs_types_class_instance_t *node = (rbs_types_class_instance_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - - return CLASS_NEW_INSTANCE( - RBS_Types_ClassInstance, - 1, - &h - ); + return rbs_types_class_instance_t_to_ruby_value(ctx, node); } case RBS_TYPES_CLASS_SINGLETON: { rbs_types_class_singleton_t *node = (rbs_types_class_singleton_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - - return CLASS_NEW_INSTANCE( - RBS_Types_ClassSingleton, - 1, - &h - ); + return rbs_types_class_singleton_t_to_ruby_value(ctx, node); } case RBS_TYPES_FUNCTION: { rbs_types_function_t *node = (rbs_types_function_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("required_positionals")), rbs_node_list_to_ruby_array(ctx, node->required_positionals)); - rb_hash_aset(h, ID2SYM(rb_intern("optional_positionals")), rbs_node_list_to_ruby_array(ctx, node->optional_positionals)); - rb_hash_aset(h, ID2SYM(rb_intern("rest_positionals")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rest_positionals)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("trailing_positionals")), rbs_node_list_to_ruby_array(ctx, node->trailing_positionals)); - rb_hash_aset(h, ID2SYM(rb_intern("required_keywords")), rbs_hash_to_ruby_hash(ctx, node->required_keywords)); - rb_hash_aset(h, ID2SYM(rb_intern("optional_keywords")), rbs_hash_to_ruby_hash(ctx, node->optional_keywords)); - rb_hash_aset(h, ID2SYM(rb_intern("rest_keywords")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rest_keywords)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_Types_Function, - 1, - &h - ); + return rbs_types_function_t_to_ruby_value(ctx, node); } case RBS_TYPES_FUNCTION_PARAM: { rbs_types_function_param_t *node = (rbs_types_function_param_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - - return CLASS_NEW_INSTANCE( - RBS_Types_Function_Param, - 1, - &h - ); + return rbs_types_function_param_t_to_ruby_value(ctx, node); } case RBS_TYPES_INTERFACE: { rbs_types_interface_t *node = (rbs_types_interface_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name - rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Interface, - 1, - &h - ); + return rbs_types_interface_t_to_ruby_value(ctx, node); } case RBS_TYPES_INTERSECTION: { rbs_types_intersection_t *node = (rbs_types_intersection_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Intersection, - 1, - &h - ); + return rbs_types_intersection_t_to_ruby_value(ctx, node); } case RBS_TYPES_LITERAL: { rbs_types_literal_t *node = (rbs_types_literal_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("literal")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->literal)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_Types_Literal, - 1, - &h - ); + return rbs_types_literal_t_to_ruby_value(ctx, node); } case RBS_TYPES_OPTIONAL: { rbs_types_optional_t *node = (rbs_types_optional_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_Types_Optional, - 1, - &h - ); + return rbs_types_optional_t_to_ruby_value(ctx, node); } case RBS_TYPES_PROC: { rbs_types_proc_t *node = (rbs_types_proc_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node - rb_hash_aset(h, ID2SYM(rb_intern("block")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->block)); // rbs_types_block - rb_hash_aset(h, ID2SYM(rb_intern("self_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->self_type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_Types_Proc, - 1, - &h - ); + return rbs_types_proc_t_to_ruby_value(ctx, node); } case RBS_TYPES_RECORD: { rbs_types_record_t *node = (rbs_types_record_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("all_fields")), rbs_hash_to_ruby_hash(ctx, node->all_fields)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Record, - 1, - &h - ); + return rbs_types_record_t_to_ruby_value(ctx, node); } case RBS_TYPES_RECORD_FIELD_TYPE: { rbs_types_record_field_type_t *record_fieldtype = (rbs_types_record_field_type_t *) instance; @@ -1083,54 +1338,19 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan } case RBS_TYPES_TUPLE: { rbs_types_tuple_t *node = (rbs_types_tuple_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Tuple, - 1, - &h - ); + return rbs_types_tuple_t_to_ruby_value(ctx, node); } case RBS_TYPES_UNION: { rbs_types_union_t *node = (rbs_types_union_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types)); - - return CLASS_NEW_INSTANCE( - RBS_Types_Union, - 1, - &h - ); + return rbs_types_union_t_to_ruby_value(ctx, node); } case RBS_TYPES_UNTYPED_FUNCTION: { rbs_types_untyped_function_t *node = (rbs_types_untyped_function_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node - - return CLASS_NEW_INSTANCE( - RBS_Types_UntypedFunction, - 1, - &h - ); + return rbs_types_untyped_function_t_to_ruby_value(ctx, node); } case RBS_TYPES_VARIABLE: { rbs_types_variable_t *node = (rbs_types_variable_t *) instance; - - VALUE h = rb_hash_new(); - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol - - return CLASS_NEW_INSTANCE( - RBS_Types_Variable, - 1, - &h - ); + return rbs_types_variable_t_to_ruby_value(ctx, node); } case RBS_KEYWORD: { rbs_constant_t *constant = rbs_constant_pool_id_to_constant(RBS_GLOBAL_CONSTANT_POOL, ((rbs_keyword_t *) instance)->constant_id); diff --git a/ext/rbs_extension/ast_translation.h b/ext/rbs_extension/ast_translation.h index c40a58d2b..eac4f6238 100644 --- a/ext/rbs_extension/ast_translation.h +++ b/ext/rbs_extension/ast_translation.h @@ -31,4 +31,7 @@ VALUE rbs_node_list_to_ruby_array(rbs_translation_context_t, rbs_node_list_t *li VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t, rbs_hash_t *hash); VALUE rbs_struct_to_ruby_value(rbs_translation_context_t, rbs_node_t *instance); +extern VALUE EMPTY_ARRAY; +extern VALUE EMPTY_HASH; + #endif diff --git a/ext/rbs_extension/extconf.rb b/ext/rbs_extension/extconf.rb index 88e971c3e..eb25ec562 100644 --- a/ext/rbs_extension/extconf.rb +++ b/ext/rbs_extension/extconf.rb @@ -18,7 +18,7 @@ '-Wc++-compat', ] -append_cflags ['-O0', '-g'] if ENV['DEBUG'] +append_cflags ['-O0', '-pg'] if ENV['DEBUG'] if ENV["TEST_NO_C23"] puts "Adding -Wc2x-extensions to CFLAGS" $CFLAGS << " -Werror -Wc2x-extensions" diff --git a/ext/rbs_extension/main.c b/ext/rbs_extension/main.c index 766a6cc06..b817b4cf5 100644 --- a/ext/rbs_extension/main.c +++ b/ext/rbs_extension/main.c @@ -6,8 +6,11 @@ #include "legacy_location.h" #include "rbs_string_bridging.h" +#include "ruby/internal/gc.h" #include "ruby/vm.h" +rbs_allocator_t *shared_allocator; + /** * Raises `RBS::ParsingError` or `RuntimeError` on `tok` with message constructed with given `fmt`. * @@ -169,6 +172,7 @@ static rbs_parser_t *alloc_parser_from_buffer(VALUE buffer, int start_pos, int e const char *encoding_name = rb_enc_name(encoding); return rbs_parser_new( + shared_allocator, rbs_string_from_ruby_string(string), rbs_encoding_find((const uint8_t *) encoding_name, (const uint8_t *) (encoding_name + strlen(encoding_name))), start_pos, @@ -453,6 +457,12 @@ void rbs__init_parser(void) { VALUE empty_array = rb_obj_freeze(rb_ary_new()); rb_gc_register_mark_object(empty_array); + EMPTY_ARRAY = rb_obj_freeze(rb_ary_new()); + rb_gc_register_mark_object(EMPTY_ARRAY); + + EMPTY_HASH = rb_obj_freeze(rb_hash_new()); + rb_gc_register_mark_object(EMPTY_HASH); + rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 7); rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5); rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 3); @@ -463,10 +473,13 @@ void rbs__init_parser(void) { } static void Deinit_rbs_extension(ruby_vm_t *_) { + rbs_allocator_free(shared_allocator); rbs_constant_pool_free(RBS_GLOBAL_CONSTANT_POOL); } void Init_rbs_extension(void) { + shared_allocator = rbs_allocator_init(); + #ifdef HAVE_RB_EXT_RACTOR_SAFE rb_ext_ractor_safe(true); #endif diff --git a/include/rbs/parser.h b/include/rbs/parser.h index 339235deb..26f3c6f1a 100644 --- a/include/rbs/parser.h +++ b/include/rbs/parser.h @@ -99,7 +99,7 @@ rbs_lexer_t *rbs_lexer_new(rbs_allocator_t *, rbs_string_t string, const rbs_enc * rbs_parser_new(buffer, string, encoding, 0, 1); * ``` * */ -rbs_parser_t *rbs_parser_new(rbs_string_t string, const rbs_encoding_t *encoding, int start_pos, int end_pos); +rbs_parser_t *rbs_parser_new(rbs_allocator_t *allocator, rbs_string_t string, const rbs_encoding_t *encoding, int start_pos, int end_pos); void rbs_parser_free(rbs_parser_t *parser); /** diff --git a/include/rbs/util/rbs_allocator.h b/include/rbs/util/rbs_allocator.h index c3356cfad..61894b052 100644 --- a/include/rbs/util/rbs_allocator.h +++ b/include/rbs/util/rbs_allocator.h @@ -42,6 +42,8 @@ void *rbs_allocator_calloc_impl(rbs_allocator_t *, size_t count, size_t size, si void *rbs_allocator_realloc_impl(rbs_allocator_t *, void *ptr, size_t old_size, size_t new_size, size_t alignment); +void rbs_allocator_reset(rbs_allocator_t *); + // Use this when allocating memory for a single instance of a type. #define rbs_allocator_alloc(allocator, type) ((type *) rbs_allocator_malloc_impl((allocator), sizeof(type), rbs_alignof(type))) // Use this when allocating memory that will be immediately written to in full. diff --git a/parse.rb b/parse.rb new file mode 100644 index 000000000..7d0f79978 --- /dev/null +++ b/parse.rb @@ -0,0 +1,23 @@ +# require "bundler/setup" + +require 'rbs' +# require 'benchmark/ips' + +if (opt = ARGV[0]) == "--wait" + ARGV.shift + puts "⏯️ Waiting for enter to continue at #{Process.pid}..." + STDIN.gets +end + +file = ARGV.shift +sig = File.read(file) + +puts "#{file} -- #{sig.bytesize} bytes" + +started_at = Time.now +secs = 3 + +loop do + RBS::Parser.parse_signature(sig) + break if (Time.now - started_at) > secs +end \ No newline at end of file diff --git a/src/parser.c b/src/parser.c index 0cbb4bf12..10ba17f35 100644 --- a/src/parser.c +++ b/src/parser.c @@ -3496,9 +3496,7 @@ rbs_lexer_t *rbs_lexer_new(rbs_allocator_t *allocator, rbs_string_t string, cons return lexer; } -rbs_parser_t *rbs_parser_new(rbs_string_t string, const rbs_encoding_t *encoding, int start_pos, int end_pos) { - rbs_allocator_t *allocator = rbs_allocator_init(); - +rbs_parser_t *rbs_parser_new(rbs_allocator_t *allocator, rbs_string_t string, const rbs_encoding_t *encoding, int start_pos, int end_pos) { rbs_lexer_t *lexer = rbs_lexer_new(allocator, string, encoding, start_pos, end_pos); rbs_parser_t *parser = rbs_allocator_alloc(allocator, rbs_parser_t); @@ -3547,7 +3545,8 @@ rbs_parser_t *rbs_parser_new(rbs_string_t string, const rbs_encoding_t *encoding void rbs_parser_free(rbs_parser_t *parser) { rbs_constant_pool_free(&parser->constant_pool); - rbs_allocator_free(ALLOCATOR()); + rbs_allocator_reset(ALLOCATOR()); + // rbs_allocator_free(ALLOCATOR()); } void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_error, const char *fmt, ...) { diff --git a/src/util/rbs_allocator.c b/src/util/rbs_allocator.c index 0d53031b9..ff37dca9c 100644 --- a/src/util/rbs_allocator.c +++ b/src/util/rbs_allocator.c @@ -129,6 +129,10 @@ rbs_allocator_t *rbs_allocator_init(void) { return (rbs_allocator_t *) mem; } +void rbs_allocator_reset(rbs_allocator_t *allocator) { + allocator->heap_ptr = (uintptr_t)allocator + sizeof(rbs_allocator_t); +} + void rbs_allocator_free(rbs_allocator_t *allocator) { destroy_memory((void *) allocator, allocator->size); } @@ -154,11 +158,7 @@ void *rbs_allocator_malloc_impl(rbs_allocator_t *allocator, size_t size, size_t // It's assumed that callers to this function will immediately write to the allocated memory, anyway. void *rbs_allocator_calloc_impl(rbs_allocator_t *allocator, size_t count, size_t size, size_t alignment) { void *p = rbs_allocator_malloc_many_impl(allocator, count, size, alignment); -#if defined(__linux__) - // mmap with MAP_ANONYMOUS gives zero-filled pages. -#else memset(p, 0, count * size); -#endif return p; } diff --git a/src/util/rbs_encoding.c b/src/util/rbs_encoding.c index 9516e2a4e..979242216 100644 --- a/src/util/rbs_encoding.c +++ b/src/util/rbs_encoding.c @@ -4621,7 +4621,38 @@ rbs_unicode_codepoint_match(rbs_unicode_codepoint_t codepoint, const rbs_unicode * SOFTWARE. */ static const uint8_t rbs_utf_8_dfa[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1f + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 00..1f 0, 0, 0, diff --git a/templates/ext/rbs_extension/ast_translation.c.erb b/templates/ext/rbs_extension/ast_translation.c.erb index b88ab0972..b0f157f0e 100644 --- a/templates/ext/rbs_extension/ast_translation.c.erb +++ b/templates/ext/rbs_extension/ast_translation.c.erb @@ -4,6 +4,9 @@ #include "rbs_string_bridging.h" #include "legacy_location.h" +VALUE EMPTY_ARRAY; +VALUE EMPTY_HASH; + #define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1)) rbs_translation_context_t rbs_translation_context_create(rbs_constant_pool_t *constant_pool, VALUE buffer, rb_encoding *ruby_encoding) { @@ -15,16 +18,32 @@ rbs_translation_context_t rbs_translation_context_create(rbs_constant_pool_t *co } VALUE rbs_node_list_to_ruby_array(rbs_translation_context_t ctx, rbs_node_list_t *list) { + if (!list->head) { + return EMPTY_ARRAY; + } + VALUE ruby_array = rb_ary_new(); + VALUE *values = ALLOCA_N(VALUE, list->length); - for (rbs_node_list_node_t *n = list->head; n != NULL; n = n->next) { - rb_ary_push(ruby_array, rbs_struct_to_ruby_value(ctx, n->node)); + size_t i = 0; + for (rbs_node_list_node_t *n = list->head; n != NULL; n = n->next, i++) { + values[i] = rbs_struct_to_ruby_value(ctx, n->node); } + rb_ary_cat(ruby_array, values, list->length); + return ruby_array; } VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t ctx, rbs_hash_t *rbs_hash) { + if (rbs_hash->length > 0) { + printf("Size of hash: %zu\n", rbs_hash->length); + } + + if (!rbs_hash->head) { + return EMPTY_HASH; + } + VALUE ruby_hash = rb_hash_new(); for (rbs_hash_node_t *n = rbs_hash->head; n != NULL; n = n->next) { @@ -53,12 +72,12 @@ VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *so } VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_location_list_t *list) { - VALUE ruby_array = rb_ary_new(); - if (list == NULL) { - return ruby_array; + return EMPTY_ARRAY; } + VALUE ruby_array = rb_ary_new(); + for (rbs_location_list_node_t *n = list->head; n != NULL; n = n->next) { rb_ary_push(ruby_array, rbs_loc_to_ruby_location(ctx, n->loc)); } @@ -76,6 +95,62 @@ VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_locatio rb_class_new_instance(argc, argv, receiver) #endif +<%- nodes.each do |node| -%> + <%- case node.ruby_full_name -%> + <%- when "RBS::AST::Bool", "RBS::AST::Integer", "RBS::AST::String", "RBS::Types::Record::FieldType", "RBS::Signature" -%> + <%- else -%> +VALUE <%= node.c_type_name %>_to_ruby_value(rbs_translation_context_t ctx, <%= node.c_type_name %> *node) { + VALUE h = rb_hash_new(); + <%- if node.expose_location? -%> + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + <%- end -%> + <%- node.fields.each do |field| -%> + <%- case field.c_type -%> + <%- when "VALUE" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), node-><%= field.c_name %>); + <%- when "rbs_node_list" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_node_list_to_ruby_array(ctx, node-><%= field.c_name %>)); + <%- when "rbs_hash" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_hash_to_ruby_hash(ctx, node-><%= field.c_name %>)); + <%- when "rbs_ast_symbol" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node-><%= field.c_name %>)); // rbs_ast_symbol + <%- when "rbs_keyword" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node-><%= field.c_name %>)); // rbs_keyword + <%- when "rbs_string" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_string_to_ruby_string(&node-><%= field.c_name %>, ctx.encoding)); + <%- when "bool" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), node-><%= field.c_name %> ? Qtrue : Qfalse); + <%- when "rbs_location" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_loc_to_ruby_location(ctx, node-><%= field.name %>)); + <%- when "rbs_location_list" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_location_list_to_ruby_array(ctx, node-><%= field.name %>)); + <%- else -%> + <%- unless field.ast_node? -%> + #warning unexpected type <%= field.c_type -%> + <%- end -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node-><%= field.c_name %>)); // <%= field.c_type %> + <%- end -%> + <%- end -%> + + <%- case node.ruby_full_name -%> + <%- when "RBS::AST::Declarations::Class", "RBS::AST::Declarations::Module", "RBS::AST::Declarations::Interface", "RBS::AST::Declarations::TypeAlias", "RBS::MethodType" -%> + rb_funcall( + RBS_AST_TypeParam, + rb_intern("resolve_variables"), + 1, + rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) + ); + <%- end -%> + return CLASS_NEW_INSTANCE( + <%= node.c_constant_name %>, + 1, + &h + ); +} + + <%- end -%> +<%- end -%> + VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instance) { if (instance == NULL) return Qnil; @@ -116,53 +191,7 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan return array; <%- else -%> <%= node.c_type_name %> *node = (<%= node.c_type_name %> *) instance; - - VALUE h = rb_hash_new(); - <%- if node.expose_location? -%> - rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); - <%- end -%> - <%- node.fields.each do |field| -%> - <%- case field.c_type -%> - <%- when "VALUE" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), node-><%= field.c_name %>); - <%- when "rbs_node_list" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_node_list_to_ruby_array(ctx, node-><%= field.c_name %>)); - <%- when "rbs_hash" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_hash_to_ruby_hash(ctx, node-><%= field.c_name %>)); - <%- when "rbs_ast_symbol" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node-><%= field.c_name %>)); // rbs_ast_symbol - <%- when "rbs_keyword" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node-><%= field.c_name %>)); // rbs_keyword - <%- when "rbs_string" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_string_to_ruby_string(&node-><%= field.c_name %>, ctx.encoding)); - <%- when "bool" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), node-><%= field.c_name %> ? Qtrue : Qfalse); - <%- when "rbs_location" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_loc_to_ruby_location(ctx, node-><%= field.name %>)); - <%- when "rbs_location_list" -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_location_list_to_ruby_array(ctx, node-><%= field.name %>)); - <%- else -%> - <%- unless field.ast_node? -%> - #warning unexpected type <%= field.c_type -%> - <%- end -%> - rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node-><%= field.c_name %>)); // <%= field.c_type %> - <%- end -%> - <%- end -%> - - <%- case node.ruby_full_name -%> - <%- when "RBS::AST::Declarations::Class", "RBS::AST::Declarations::Module", "RBS::AST::Declarations::Interface", "RBS::AST::Declarations::TypeAlias", "RBS::MethodType" -%> - rb_funcall( - RBS_AST_TypeParam, - rb_intern("resolve_variables"), - 1, - rb_hash_lookup(h, ID2SYM(rb_intern("type_params"))) - ); - <%- end -%> - return CLASS_NEW_INSTANCE( - <%= node.c_constant_name %>, - 1, - &h - ); + return <%= node.c_type_name %>_to_ruby_value(ctx, node); <%- end -%> } <%- end -%> diff --git a/templates/ext/rbs_extension/ast_translation.h.erb b/templates/ext/rbs_extension/ast_translation.h.erb index ddf5b00ba..a0ba1948c 100644 --- a/templates/ext/rbs_extension/ast_translation.h.erb +++ b/templates/ext/rbs_extension/ast_translation.h.erb @@ -24,4 +24,7 @@ VALUE rbs_node_list_to_ruby_array(rbs_translation_context_t, rbs_node_list_t *li VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t, rbs_hash_t *hash); VALUE rbs_struct_to_ruby_value(rbs_translation_context_t, rbs_node_t *instance); +extern VALUE EMPTY_ARRAY; +extern VALUE EMPTY_HASH; + #endif