From fe8417867fc40789700cb1fa59f9b630dd3bc7b2 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Tue, 9 Jul 2024 18:03:49 -0300 Subject: [PATCH] Reviewing the generator code just to remember it's a mess. --- src/generator/callable_gen.cr | 2 -- src/generator/file_gen.cr | 7 ++++++- src/generator/generator.cr | 17 ----------------- src/generator/helpers.cr | 4 ++-- src/generator/lib_gen.cr | 6 +----- src/generator/method_gen.cr | 4 ---- src/generator/object_gen.cr | 4 ---- src/generator/signal_gen.cr | 17 ----------------- src/generator/struct_gen.cr | 4 ---- 9 files changed, 9 insertions(+), 56 deletions(-) diff --git a/src/generator/callable_gen.cr b/src/generator/callable_gen.cr index f4286a5..2b0f81c 100644 --- a/src/generator/callable_gen.cr +++ b/src/generator/callable_gen.cr @@ -1,7 +1,5 @@ module Generator abstract class CallableGen < Generator - abstract def callable : CallableInfo - def method_gi_annotations : String args = callable.args String.build do |io| diff --git a/src/generator/file_gen.cr b/src/generator/file_gen.cr index 4c7ef1c..9e5ea8b 100644 --- a/src/generator/file_gen.cr +++ b/src/generator/file_gen.cr @@ -5,7 +5,12 @@ module Generator abstract def filename : String def generate - generate(filename) + output_dir = File.join(Generator.output_dir, module_dir) + FileUtils.mkdir_p(output_dir) + + File.open(File.join(output_dir, filename), "w") do |io| + generate(io) + end end end end diff --git a/src/generator/generator.cr b/src/generator/generator.cr index bcedb93..7221e78 100644 --- a/src/generator/generator.cr +++ b/src/generator/generator.cr @@ -25,14 +25,6 @@ module Generator @config = BindingConfig.for(@namespace.name, @namespace.version) end - def namespace_name : String - to_type_name(@namespace.name) - end - - def subject : String - "" - end - def self.push_log_scope(context : String) @@log_scope.push(context) # For some reason this call is *really* slow, probably a bug. @@ -68,15 +60,6 @@ module Generator self.class.name end - def generate(filename : String) - output_dir = File.join(Generator.output_dir, module_dir) - FileUtils.mkdir_p(output_dir) - - File.open(File.join(output_dir, filename), "w") do |io| - generate(io) - end - end - def with_log_scope(scope_name = scope) Generator.push_log_scope(scope_name) yield diff --git a/src/generator/helpers.cr b/src/generator/helpers.cr index 20cc3c8..b9493f5 100644 --- a/src/generator/helpers.cr +++ b/src/generator/helpers.cr @@ -5,8 +5,8 @@ module Generator::Helpers # Keywords not allowed in calls CALL_KEYWORDS = {"initialize", "finalize"} - def to_get_type_function(struct_info : StructInfo) - "#{struct_info.namespace.name.underscore}_#{struct_info.name.underscore}_get_type" + def namespace_name : String + to_type_name(@namespace.name) end def to_lib_namespace(namespace : Namespace) diff --git a/src/generator/lib_gen.cr b/src/generator/lib_gen.cr index 3853a97..19df9c5 100644 --- a/src/generator/lib_gen.cr +++ b/src/generator/lib_gen.cr @@ -1,13 +1,9 @@ module Generator - class LibGen < Generator + class LibGen < FileGen def filename : String "lib_#{namespace.name.underscore}.cr" end - def generate - generate(filename) - end - private def libraries : Array(String) namespace.shared_libraries.map do |library| library[/lib([^\/]+)\.(?:so|.+?\.dylib).*/, 1] diff --git a/src/generator/method_gen.cr b/src/generator/method_gen.cr index 833d721..758744e 100644 --- a/src/generator/method_gen.cr +++ b/src/generator/method_gen.cr @@ -31,10 +31,6 @@ module Generator @method.flags.throws? end - def callable : CallableInfo - @method - end - private def method_identifier : String identifier = to_call(@method.name) method_flags = @method.flags diff --git a/src/generator/object_gen.cr b/src/generator/object_gen.cr index fcb7e0b..8bbd62d 100644 --- a/src/generator/object_gen.cr +++ b/src/generator/object_gen.cr @@ -23,10 +23,6 @@ module Generator "#{@object.name.underscore}.cr" end - def subject : String - @object.name - end - private def parent_class parent = @object.parent return if parent.nil? diff --git a/src/generator/signal_gen.cr b/src/generator/signal_gen.cr index 2f5968d..dcb784d 100644 --- a/src/generator/signal_gen.cr +++ b/src/generator/signal_gen.cr @@ -16,13 +16,6 @@ module Generator @args_strategies = ArgStrategy.find_strategies(@signal, :crystal_to_c) end - def filename : String? - end - - def subject : String - "#{@obj.name}::#{signal_type}" - end - def scope "#{@obj.namespace.name}::#{@obj.name} #{@signal.name} signal" end @@ -31,16 +24,6 @@ module Generator "#{@signal.name.tr("-", "_").camelcase}Signal" end - private def has_return_value? - !@signal.return_type.tag.void? - end - - private def signal_args - @signal_args ||= @signal.args.reject do |arg| - BindingConfig.for(arg.namespace).ignore?(to_crystal_type(arg.type_info, false)) - end - end - private def lean_proc_params : String String.build do |s| arg_strategies_to_proc_param_string(s, @signal, @args_strategies) diff --git a/src/generator/struct_gen.cr b/src/generator/struct_gen.cr index d298442..c096f16 100644 --- a/src/generator/struct_gen.cr +++ b/src/generator/struct_gen.cr @@ -39,10 +39,6 @@ module Generator "#{namespace.name}::#{@struct.name}" end - def subject - @struct.name - end - def type_name to_crystal_type(@struct, false) end