comparison scripts/dgen.rb @ 8:2c0fd7bb4de6

Added a T in front of every template. Added support for interfaces as method parameters
author Jacob Carlborg <doob@me.com>
date Thu, 09 Jul 2009 22:16:40 +0200
parents 9e67a1122e85
children 3592b41928fe
comparison
equal deleted inserted replaced
7:9e67a1122e85 8:2c0fd7bb4de6
542 542
543 str << "{".nl(false) 543 str << "{".nl(false)
544 str << "mixin ObjcWrap".indent.nl 544 str << "mixin ObjcWrap".indent.nl
545 545
546 templates_for_class(clazz.name).each do |template, value| 546 templates_for_class(clazz.name).each do |template, value|
547 str << "mixin #{template}".indent.nl 547 str << "mixin #{get_identifier("T" + template)}".indent.nl
548 end 548 end
549 549
550 str << "\n" 550 str << "\n"
551 551
552 str << methods(clazz.method, clazz.name) 552 str << methods(clazz.method, clazz.name)
575 # Generates the D code for the interfaces 575 # Generates the D code for the interfaces
576 def interfaces (interfaces) 576 def interfaces (interfaces)
577 interfaces.each do |interface| 577 interfaces.each do |interface|
578 str = StringIO.new 578 str = StringIO.new
579 579
580 str << "interface I" # prepend I to the interface name, because it can be the same as a class name 580 str << "interface " # prepend I to the interface name, because it can be the same as a class name
581 581
582 if interface == "" 582 if interface == ""
583 str << get_identifier(interface.name).nl(false) 583 str << get_identifier("I" + interface.name).nl(false)
584 else 584 else
585 str << get_identifier(interface.name) 585 str << get_identifier("I" + interface.name)
586 586
587 unless interface.parent == "" 587 unless interface.parent == ""
588 str << " : " 588 str << " : "
589 str << get_identifier(interface.parent) 589 str << get_identifier(interface.parent)
590 end 590 end
627 def templates (templates) 627 def templates (templates)
628 templates.each do |template| 628 templates.each do |template|
629 str = StringIO.new 629 str = StringIO.new
630 630
631 str << "template " 631 str << "template "
632 str << get_identifier(template.name) 632 str << get_identifier("T" + template.name)
633 str << " ()".nl(false) 633 str << " ()".nl(false)
634 str << "{".nl(false) 634 str << "{".nl(false)
635 str << interface_methods(template.method, template.name) if template["class"] == "NSObject" 635 str << interface_methods(template.method, template.name) if template["class"] == "NSObject"
636 str << methods(template.method, template.name) unless template["class"] == "NSObject" 636 str << methods(template.method, template.name) unless template["class"] == "NSObject"
637 str << "}".nl(false) 637 str << "}".nl(false)
1040 str << ")" 1040 str << ")"
1041 str << "(" 1041 str << "("
1042 end 1042 end
1043 1043
1044 method.arg.each_with_index do |arg, i| 1044 method.arg.each_with_index do |arg, i|
1045 str << arg.name 1045 str << get_identifier(arg.name)
1046 str << ", " unless i == method.arg.length - 1 1046 str << ", " unless i == method.arg.length - 1
1047 end unless method.arg.nil? 1047 end unless method.arg.nil?
1048 1048
1049 str << ")".nl 1049 str << ")".nl
1050 1050
1193 # === Example: 1193 # === Example:
1194 # get_type("I", "Q", "NSUInteger") #=> NSUInteger 1194 # get_type("I", "Q", "NSUInteger") #=> NSUInteger
1195 # get_type("I", "I", "unsigned int") #=> uint 1195 # get_type("I", "I", "unsigned int") #=> uint
1196 # 1196 #
1197 def get_type (type, type64, declared_type) 1197 def get_type (type, type64, declared_type)
1198 1198 declared_type = "I" + $1 if declared_type =~ /\w+\s*<(.+)>/
1199
1199 return get_identifier(declared_type) if type.nil? && type64.nil? 1200 return get_identifier(declared_type) if type.nil? && type64.nil?
1200 1201
1201 t = check_declared_type(declared_type) 1202 t = check_declared_type(declared_type)
1202 return t unless t.nil? 1203 return t unless t.nil?
1203 1204