lib/gir_ffi/builder/function.rb in gir_ffi-0.1.0 vs lib/gir_ffi/builder/function.rb in gir_ffi-0.2.0
- old
+ new
@@ -1,6 +1,7 @@
require 'gir_ffi/builder/argument'
+require 'gir_ffi/variable_name_generator'
module GirFFI::Builder
# Implements the creation of a Ruby function definition out of a GIR
# IFunctionInfo.
class Function
@@ -8,13 +9,13 @@
@info = info
@libmodule = libmodule
end
def generate
- setup_accumulators
- @data = @info.args.map {|arg| Argument.build self, arg, @libmodule}
- @rvdata = ReturnValue.build self, @info
+ vargen = GirFFI::VariableNameGenerator.new
+ @data = @info.args.map {|arg| Argument.build vargen, arg, @libmodule}
+ @rvdata = ReturnValue.build vargen, @info
alldata = @data.dup << @rvdata
alldata.each {|data|
data.prepare
@@ -23,23 +24,23 @@
data.length_arg = @data[idx]
@data[idx].array_arg = data
end
}
- adjust_accumulators
+ setup_error_argument vargen
return filled_out_template
end
- private
-
- def setup_accumulators
- @varno = 0
+ def pretty_print
+ generate
end
- def adjust_accumulators
+ private
+
+ def setup_error_argument vargen
klass = @info.throws? ? ErrorArgument : NullArgument
- @errarg = klass.new(self)
+ @errarg = klass.new vargen, nil, nil, nil
@errarg.prepare
end
def filled_out_template
return <<-CODE
@@ -85,14 +86,7 @@
retvals = ([@rvdata.retval] + @data.map(&:retval)).compact
po << "return #{retvals.join(', ')}" unless retvals.empty?
po.flatten
end
-
- def new_var
- @varno += 1
- "_v#{@varno}"
- end
-
- public :new_var
end
end