Class: Rbind::GeneratorRuby::RTypeHelper
- Inherits:
-
HelperBase
- Object
- HelperBase
- Rbind::GeneratorRuby::RTypeHelper
- Defined in:
- lib/rbind/generator_ruby.rb
Defined Under Namespace
Classes: OperationHelper, OverloadedOperationHelper
Instance Method Summary collapse
- #add_constructor ⇒ Object
- #add_consts(root = @root) ⇒ Object
- #add_methods(root = @root) ⇒ Object
- #add_specializing(root = @root) ⇒ Object
- #add_to_s ⇒ Object
- #add_types(root = @root) ⇒ Object
- #cdelete_method ⇒ Object
- #cname ⇒ Object
- #full_name ⇒ Object
-
#initialize(name, root, compact_namespace = false) ⇒ RTypeHelper
constructor
A new instance of RTypeHelper.
- #name ⇒ Object
- #result ⇒ Object
Methods inherited from HelperBase
Constructor Details
#initialize(name, root, compact_namespace = false) ⇒ RTypeHelper
Returns a new instance of RTypeHelper.
367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/rbind/generator_ruby.rb', line 367 def initialize(name, root,compact_namespace = false) @type_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rtype.rb")).read,nil,"-") @namespace_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rnamespace.rb")).read,nil,"-") @static_method_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rstatic_method.rb")).read) @method_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rmethod.rb")).read,nil,'-') @overloaded_method_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","roverloaded_method.rb")).read,nil,"-") @overloaded_static_method_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","roverloaded_static_method.rb")).read,nil,"-") @overloaded_method_call_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","roverloaded_method_call.rb")).read,nil,"-") @compact_namespace = compact_namespace super(name,root) end |
Instance Method Details
#add_constructor ⇒ Object
404 405 406 407 408 409 410 411 412 |
# File 'lib/rbind/generator_ruby.rb', line 404 def add_constructor raise "there is no constructor for namespaces!" if self.is_a?(RNamespace) ops = Array(@root.operation(@root.name,false)) ops.map do |c| next if c.ignore? ch = OperationHelper.new(c) @overloaded_method_call_wrapper.result(ch.binding) end.join("\n") end |
#add_consts(root = @root) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/rbind/generator_ruby.rb', line 414 def add_consts(root=@root) str = @root.consts.map do |c| next if c.extern? || c.ignore? " #{c.name} = #{GeneratorRuby::normalize_type_name(c.value)}\n" end.join return str unless @compact_namespace root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += add_consts(t) if name == GeneratorRuby.normalize_type_name(t.full_name) end str end |
#add_methods(root = @root) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/rbind/generator_ruby.rb', line 438 def add_methods(root=@root) # sort all method according their target name ops = Hash.new do |h,k| h[k] = Array.new end root.each_operation do |o| next if o.constructor? || o.ignore? op = OperationHelper.new(o) if op.instance_method? ops["rbind_instance_#{op.name}"] << op else ops["rbind_static_#{op.name}"] << op end end # render method str = "" ops.each_value do |o| if o.size == 1 op = o.first str += if op.instance_method? @method_wrapper.result(op.binding) else @static_method_wrapper.result(op.binding) end else helper = OverloadedOperationHelper.new(o) str += if o.first.instance_method? @overloaded_method_wrapper.result(helper.binding) else @overloaded_static_method_wrapper.result(helper.binding) end end end return str unless @compact_namespace root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += add_methods(t) if name == GeneratorRuby.normalize_type_name(t.full_name) end str end |
#add_specializing(root = @root) ⇒ Object
391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/rbind/generator_ruby.rb', line 391 def add_specializing(root = @root) str = if @root.respond_to?(:specialize_ruby) root.specialize_ruby else "" end root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += add_specialize(t) if name == GeneratorRuby.normalize_type_name(t.full_name) end str end |
#add_to_s ⇒ Object
428 429 430 431 432 433 434 435 436 |
# File 'lib/rbind/generator_ruby.rb', line 428 def add_to_s str = [] @root.each_operation do |o| next unless o.is_a? RGetter op = OperationHelper.new(o) str << "#{op.name}=\#{self.#{op.name}}" end "\"#<#{full_name} #{str.join(" ")}>\"" end |
#add_types(root = @root) ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/rbind/generator_ruby.rb', line 479 def add_types(root = @root) str = "" root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += if @compact_namespace && name == GeneratorRuby.normalize_type_name(t.full_name) add_types(t) else RTypeHelper.new(t.name,t).result end end str end |
#cdelete_method ⇒ Object
387 388 389 |
# File 'lib/rbind/generator_ruby.rb', line 387 def cdelete_method GeneratorRuby.normalize_method_name(@root.cdelete_method) end |
#cname ⇒ Object
383 384 385 |
# File 'lib/rbind/generator_ruby.rb', line 383 def cname GeneratorRuby.normalize_type_name(@root.cname) end |
#full_name ⇒ Object
492 493 494 |
# File 'lib/rbind/generator_ruby.rb', line 492 def full_name @root.full_name end |
#name ⇒ Object
379 380 381 |
# File 'lib/rbind/generator_ruby.rb', line 379 def name GeneratorRuby.normalize_type_name(@name) end |
#result ⇒ Object
496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/rbind/generator_ruby.rb', line 496 def result return "" if @root.extern? str = if @root.is_a? RStruct @type_wrapper.result(self.binding) else @namespace_wrapper.result(self.binding) end if(@root.root?) str else str.gsub!("\n","\n ").gsub!(" \n","\n") " "+str[0,str.size-4] end end |