Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reviewing the generator code just to remember it's a mess. #155

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/generator/callable_gen.cr
Original file line number Diff line number Diff line change
@@ -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|
Expand Down
7 changes: 6 additions & 1 deletion src/generator/file_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions src/generator/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/generator/helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions src/generator/lib_gen.cr
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 0 additions & 4 deletions src/generator/method_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/generator/object_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
17 changes: 0 additions & 17 deletions src/generator/signal_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,16 +24,6 @@ module Generator
"#{@signal.name.tr("-", "_").camelcase}Signal"
end

private def has_return_value?
[email protected]_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)
Expand Down
4 changes: 0 additions & 4 deletions src/generator/struct_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading