annotate scripts/dgen.rb @ 3:d0162d8ca0f2

Added support for function pointers in dstepgen
author Jacob Carlborg <doob@me.com>
date Sun, 05 Jul 2009 20:54:42 +0200
parents 9fd439a28ce3
children 5a1a6afbfe3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 #!/usr/bin/env ruby
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 ##
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
4 # Copyright:: Copyright (c) 2009 Jacob Carlborg.
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 # Author:: Jacob Carlborg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 # Version:: Initial created: 2009
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 # License:: [Boost Software License 1.0]http://www.boost.org/LICENSE_1_0.txt
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 require "rubygems"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11 gem "xml-simple"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 require "xmlsimple"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 require "optparse"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
14 require "date"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 # Extensions to String
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17 class String
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 # Passes each character to the supplied block
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22 # "str".each_char { |c| puts c }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 # s
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 # t
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 # r
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28 def each_char
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 if block_given?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 scan(/./m) do |x|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 yield x
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 scan(/./m)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38 # Indents the string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 # levels:: how many levels/tabs to indent
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 # "str".indent #=> str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43 # "str".indent(3) #=> str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 def indent (levels = 1)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 "\t" * levels << self
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 # Appends a semicolon and a newline character on the string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 # semicolon:: should a semicolon be appended
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53 # "str".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 # "str".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 # str;
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 # str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61 def nl (semicolon = true)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 if semicolon
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 if self[-1, 1] == "{" || self[-1, 1] == "}"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64 self << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
65 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 self << ";\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 self << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 # Returns the index of the given character or length of the string if not found
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74 # char:: the character to look for
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 # start:: the index where to start the search
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
77 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
78 # "012345789".index_of("1") #=> 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
79 # "0123 0123".index_of("3", 6) #=> 8
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81 def index_of (char, start = 0)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
82 return self.length if start >= self.length
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84 i = 0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
85
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
86 if start == 0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 self.each_char do |c|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
88 return i if char == c
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 i += 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
91 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92 self[start + 1 .. -1].each_char do |c|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
93 return i + start + 1 if char == c
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 i += 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98 return self.length
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 # Returns true if the string is an Objective-C struct
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
102 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 # "{?=ii}".struct? #=> true
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
106 def struct?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 self =~ /\{/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 # Extensions that adds support for member access syntax
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112 class Hash
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 def type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 result = self["type"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 self[:type]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 def type= (type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120 self[:type] = type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123 def id
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 result = self["id"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 self[:id]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 def id= (id)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 self[:id] = id
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
131 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
132
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
133 def methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134 result = self["methods"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
136 self[:methods]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139 def methods= (methods)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 self[:methods] = methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 def method
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144 result = self["method"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
145 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 self[:method]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 def method= (method)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 self[:method] = method
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 def method_missing (method, *args)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 self.class.instance_eval do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 define_method(method) do |*args|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156 if args.length > 0
3
d0162d8ca0f2 Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
157 #self[method[0 ... -1]] = args[0]
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 self[eval(":#{method}"[0 ... -1])] = args[0]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 result = self[method]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162 self[eval(":#{method}")]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167 if (method = method.id2name) =~ /=/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 eval("self.#{method} (args.length < 2 ? args[0] : args)")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 eval("self.#{method}")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 # This Struct represents an Objective-C Framework
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 Framework = Struct.new(:name, :files) do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177 def initialize
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 self.files = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 self.name = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
183 # This Struct represents a C/Objective-C header
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
184 HeaderFile = Struct.new(:name, :framework, :cftypes, :constants, :c_constants, :d_constants, :d_constants_static_this, :defines,
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
185 :enums, :functions, :c_functions, :function_wrappers, :imports, :path, :structs, :typedefs) do
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 def initialize
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187 self.name = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188 self.cftypes = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 self.constants = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190 self.defines = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 self.enums = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
192 self.framework = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
193 self.functions = []
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
194 self.c_functions = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195 self.function_wrappers = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
196 self.imports = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
197 self.path = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 self.structs = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 self.typedefs = []
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
200 self.d_constants_static_this = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
203
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 # Performs the conversion of an xml metadata file to the D programming language
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 class ObjcToD
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206 FIRST_YEAR = "2009"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 VERSION = 1.0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 attr_accessor :out_dir, :files
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211 # Creates a new instance of the ObjcToD class
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212 def initialize
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213 @classes = {}
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
214 @interfaces = {}
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
215 @interfaces2 = []
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
216 @templates = {}
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 @copyright = nil
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
218 @c_constants = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
219 @d_constants = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 @d_constants_static_this = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
221 @files = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
222 @frameworks = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223 @function_wrappers = []
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
224 @c_functions = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 @headers = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 @package = "dstep"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 # Generates the D code from the xml metadata
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230 def generate_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 @files.each do |dstep_file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232 xml = XmlSimple.xml_in(dstep_file)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 unless xml.framework.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 frameworks = xml.framework
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
237 frameworks.each do |frame|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 framework = Framework.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239 framework.name = frame.name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 frame.file.each do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242 header = HeaderFile.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243 header.name = file.name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 header.constants = constants(file.constant) unless file.constant.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
245 header.c_constants = c_constants unless file.constant.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
246 header.d_constants = d_constants unless file.constant.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
247 header.d_constants_static_this = d_constants_static_this unless file.constant.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
248 header.enums = enums(file.enum) unless file.enum.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
249 header.functions = functions(file.function) unless file.function.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
250 header.c_functions = c_functions unless file.function.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251 header.function_wrappers = function_wrappers unless file.function.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 header.imports = imports(file.import, file.name, framework.name) unless file.import.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 header.structs = structs(file.struct) unless file.struct.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
255 header.typedefs = typedefs(file.typedef) unless file.typedef.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 framework.files << header
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
258 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
260 @frameworks << framework
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
261 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
262 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
263
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
264 unless xml.file.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
265 files = xml.file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
266
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267 files.each do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268 header = HeaderFile.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 header.name = file.name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270 header.constants = constants(file.constant) unless file.constant.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
271 header.c_constants = c_constants unless file.constant.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
272 header.d_constants = d_constants unless file.constant.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273 header.d_constants_static_this = d_constants_static_this unless file.constant.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274 header.enums = enums(file.enum) unless file.enum.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 header.functions = functions(file.function) unless file.function.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
276 header.c_functions = c_functions unless file.function.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277 header.function_wrappers = function_wrappers unless file.function.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278 header.imports = imports(file.import, file.name) unless file.import.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 header.structs = structs(file.struct) unless file.struct.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 header.typedefs = typedefs(file.typedef) unless file.typedef.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
282 @headers << header
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
284 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
285
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
286 interfaces(xml.protocol) unless xml.protocol.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
287 templates(xml.category) unless xml.category.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
288 classes(xml["class"]) unless xml["class"].nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 # Outputs the generate D code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 def output_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 @frameworks.each do |framework|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
295 framework_path = framework_path = "#{@out_dir}/#{@package}/#{get_identifier(get_framework_name(framework.name.downcase))}"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
296
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 FileUtils.mkdir_p(framework_path) unless File.exist?(framework_path)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 framework.files.each do |header|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
300 file_path = "#{framework_path}/#{get_identifier(header.name)}"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
301 bindings_file_path = file_path + "_bindings.d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
302 file_path << ".d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
303 mod = "#{@package}.#{get_identifier(get_framework_name(framework.name.downcase))}.#{get_identifier(header.name)}"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 File.open(file_path, "w") do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 file << copyright
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
307 file << "module #{mod};"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
308 file << header.imports
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
309 file << "\n" unless @d_constants.length > 0 || @function_wrappers.length > 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
310 file << "import bindings = #{mod}_bindings".nl.nl(false) if @d_constants.length > 0 || @function_wrappers.length > 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
311 file << header.defines
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
312 file << header.typedefs
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
313 file << header.cftypes
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
314 file << header.c_constants
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
315 file << header.d_constants
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316 file << header.enums
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
317 file << header.structs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
318
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
319 unless header.d_constants_static_this.length == 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 file << "static this ()".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 file << "{".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
322 file << header.d_constants_static_this
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
323 file << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
324 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
326 classes = get_classes(header.name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 classes.each do |clazz, value|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329 file << value.code.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
330 @classes.delete(clazz)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
333 interfaces = get_interfaces(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
334
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
335 interfaces.each do |interface, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
336 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
337 @interfaces.delete(interface)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
338 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
339
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
340 templates = get_templates(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
341
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
342 templates.each do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
343 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
344 @templates.delete(template)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
345 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
346
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
347 file << header.function_wrappers
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
348 file << header.c_functions
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
349 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
350
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
351 File.open(bindings_file_path, "w") do |file|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
352 file << "module "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
353 file << mod
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
354 file << "_bindings;"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
355 file << header.imports.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
356 file << header.constants
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
357 file << header.functions
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
358 end if @d_constants.length > 0 || @function_wrappers.length > 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
359 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
361
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
362 package_path = "#{@out_dir}/#{@package}"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363 FileUtils.mkdir_p(package_path) unless File.exist?(package_path)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
365 @headers.each do |header|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
366 header_path = "#{package_path}/#{get_identifier(header.name)}"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
367 bindings_file_path = header_path + "_bindings.d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
368 header_path << ".d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
369 mod = "#{@package}.#{get_identifier(header.name)}"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 File.open(header_path, "w") do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 file << copyright
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
373 file << "module #{mod};"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
374 file << header.imports
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
375 file << "\n" unless @d_constants.length > 0 || @function_wrappers.length > 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
376 file << "import bindings = #{mod}_bindings".nl.nl(false) if @d_constants.length > 0 || @function_wrappers.length > 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
377 file << header.defines
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
378 file << header.typedefs
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
379 file << header.cftypes
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
380 file << header.c_constants
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381 file << header.d_constants
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 file << header.enums
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383 file << header.structs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
384
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
385 unless header.d_constants_static_this.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
386 file << "static this ()".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
387 file << "{".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
388 file << header.d_constants_static_this
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
389 file << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
390 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
391
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
392 classes = get_classes(header.name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
393
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
394 classes.each do |clazz, value|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
395 file << value.code.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396 @classes.delete(clazz)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
397 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
398
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
399 interfaces = get_interfaces(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
400
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
401 interfaces.each do |interface, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
402 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
403 @interfaces.delete(interface)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
404 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
405
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
406 templates = get_templates(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
407
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
408 templates.each do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
409 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
410 @templates.delete(template)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
411 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
412
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
413 file << header.function_wrappers
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
414 file << header.c_functions
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
415 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
416
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
417 File.open(bindings_file_path, "w") do |file|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
418 file << "module "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
419 file << mod
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
420 file << "_bindings;"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
421 file << header.imports.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
422 file << header.constants
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
423 file << header.functions
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
424 end if @d_constants.length > 0 || @function_wrappers.length > 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
425 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
426
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
427 @classes.each do |clazz, value|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
428 class_path = "#{package_path}/#{get_identifier(clazz)}.d"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
429
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
430 File.open(class_path, "w") do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
431 file << value.code unless value.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
432 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
433 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
434 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
436 # Creates and returns the copyright header that is included in the top of every file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437 def copyright
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438 return @copyright unless @copyright.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
440 # Add an extra empty string in the begining because array indices begin with zero and months don't
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
441 months = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 initialt_year = "2009"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
444 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
445 date = Date.today
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 current_year = date.year.to_s
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
447 year = initialt_year
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
448 initial_created = "#{months[date.month]} #{date.day}, #{initialt_year}"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 year << "-" << current_year unless initialt_year == current_year
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 str << "/**\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 str << " * Copyright: Copyright (c) #{year} Jacob Carlborg.\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 str << " * Authors: Jacob Carlborg\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455 str << " * Version: Initial created: #{initial_created} \n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 str << " * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457 str << " */\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
459 @copyright = str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
460 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
461
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
462 # Gets name of the framework that the given class belongs to
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
463 def get_framework (class_name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
464 @frameworks.each do |framework|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
465 framework.files.each do |file|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
466 return get_identifier(framework.name) if file.name == class_name
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
467 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
468 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
469
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
470 return []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
471 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
472
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
473 # Gets the classes that belongs to the given file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
474 def get_classes (name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
475 classes = @classes.find_all do |clazz, value|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
476 value.file == name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
477 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
478
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
479 return classes
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
480 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
481
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
482 # Gets the interfaces that belongs to the given file
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
483 def get_interfaces (name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
484 interfaces = @interfaces.find_all do |interface, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
485 value.file == name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
486 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
487
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
488 return interfaces
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
489 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
490
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
491 # Gets the templates that belongs to the given file
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
492 def get_templates (name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
493 templates = @templates.find_all do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
494 value.file == name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
495 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
496
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
497 return templates
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
498 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
499
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
500 # Generates the D code for the classes
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
501 def classes (classes)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
502 classes.each do |clazz|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
503 str = StringIO.new
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
504 protocols = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
505
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
506 str << "class "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
507
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
508 if clazz == ""
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
509 str << get_identifier(clazz.name).nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
510 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
511 str << get_identifier(clazz.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
512
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
513 unless clazz.parent == ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
514 str << " : "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
515 str << get_identifier(clazz.parent)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
516 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
517
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
518 unless clazz.protocols.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
519 protocols = clazz.protocols.split(",")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
520
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
521 str2 = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
522
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
523 str2 << ", " unless clazz.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
524 str2 << " : " if clazz.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
525
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
526 protocols.each do |protocol|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
527 str2 << "I"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
528 str2 << get_identifier(protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
529 str2 << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
530 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
531
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
532 str << str2.string[0 .. -3]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
533 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
534
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
535 str << "\n"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
536 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
537
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
538 str << "{".nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
539 str << "mixin ObjcWrap".indent.nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
540
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
541 templates_for_class(clazz.name).each do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
542 str << "mixin #{template}".indent.nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
543 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
544
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
545 str << "\n"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
546
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
547 str << methods(clazz.method, clazz.name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
548 str << "\n" if protocols.length > 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
549
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
550 # implement the interfaces/protocols
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
551 protocols.each_with_index do |protocol, i|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
552 interface = interface_for_protocol(protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
553
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
554 unless interface.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
555 str << methods(interface.method, interface.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
556 str << "\n" unless i == protocols.length - 1
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
557 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
558 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
559
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
560 str << "}".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
561
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
562 @classes[clazz.name] ||= {}
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
563 @classes[clazz.name].code = str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
564 framework = get_framework(clazz.file)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
565 @classes[clazz.name].framework = framework unless framework.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
566 @classes[clazz.name].file = get_identifier(clazz.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
567 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
568 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
569
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
570 # Generates the D code for the interfaces
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
571 def interfaces (interfaces)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
572 interfaces.each do |interface|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
573 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
574
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
575 str << "interface I" # prepend I to the interface name, because it can be the same as a class name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
576
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
577 if interface == ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
578 str << get_identifier(interface.name).nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
579 else
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
580 str << get_identifier(interface.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
581
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
582 unless interface.parent == ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
583 str << " : "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
584 str << get_identifier(interface.parent)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
585 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
586
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
587 unless interface.protocols.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
588 protocols = interface.protocols
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
589 protocols = protocols.split(",")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
590
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
591 str2 = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
592
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
593 str2 << ", " unless interface.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
594 str2 << " : " if interface.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
595
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
596 protocols.each do |protocol|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
597 str2 << "I"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
598 str2 << get_identifier(protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
599 str2 << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
600 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
601
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
602 str << str2.string[0 .. -3]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
603 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
604
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
605 str << "\n"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
606 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
607
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
608 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
609 str << interface_methods(interface.method, interface.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
610 str << "}".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
611
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
612 @interfaces[interface.name] ||= {}
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
613 @interfaces[interface.name].code = str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
614 framework = get_framework(interface.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
615 @interfaces[interface.name].framework = framework unless framework.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
616 @interfaces[interface.name].file = get_identifier(interface.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
617 @interfaces2 << interface
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
618 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
619 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
620
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
621 # Generates the D code for the templates
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
622 def templates (templates)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
623 templates.each do |template|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
624 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
625
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
626 str << "template "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
627 str << get_identifier(template.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
628 str << " ()".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
629 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
630 str << interface_methods(template.method, template.name) if template["class"] == "NSObject"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
631 str << methods(template.method, template.name) unless template["class"] == "NSObject"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
632 str << "}".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
633
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
634 @templates[template.name] ||= {}
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
635 @templates[template.name].code = str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
636 framework = get_framework(template.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
637 @templates[template.name].framework = framework unless framework.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
638 @templates[template.name].file = get_identifier(template.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
639 @templates[template.name][:class] = get_identifier(template["class"])
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
640 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
641 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
642
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
643 # Generates the D code for the constants/globals
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
644 def constants (constants)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
645 return "" if constants.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
646
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
647 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
648
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
649 str << "extern (C)".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
650 str << "{".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
651 str << "extern".indent.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
652 str << "{".indent.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
653
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
654 constants.each do |constant|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
655 type = get_type(constant.type, constant.type64, constant.declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
656 const = constant.const == "true"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
657
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
658 if constant.type == "@"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
659 @d_constants << { :name => constant.name.dup, :type => constant.declaredType.gsub("*", ""), :const => const }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
660
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
661 str << "private ".indent(2)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
662 str << "const id" if const
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
663 str << "id" unless const
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
664 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
665 str << get_identifier(constant["name"]).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
666 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
667 @c_constants << { :name => constant.name.dup, :type => type, :const => const }
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
668 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
669 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
670
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
671 str << "}".indent.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
672 str << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
673
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
674 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
675 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
676
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
677 def c_constants
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
678 return "" if @c_constants.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
679
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
680 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
681
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
682 str << "extern (C)".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
683 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
684 str << "extern".indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
685 str << "{".indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
686
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
687 @c_constants.each do |constant|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
688 if constant.const
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
689 str << "const ".indent(2)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
690 str << constant.type
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
691 else
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
692 str << constant.type.indent(2)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
693 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
694
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
695 str << " "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
696 str << get_identifier(constant.name).nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
697 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
698
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
699 str << "}".indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
700 str << "}".nl(false).nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
701
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
702 @c_constants.clear
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
703 str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
704 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
705
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
706
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
707 # Generates the D code for the constants that D can't handle directly, like classes
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
708 def d_constants
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
709 return "" if @d_constants.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
710
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
711 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
712
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
713 @d_constants.each do |constant|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
714 # Deep copy constant
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
715 c = constant.dup
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
716 c.name = c.name.dup
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
717 c.type = c.type.dup
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
718
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
719 str << "const " if constant.const
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
720 str << get_identifier(constant.type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
721 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
722 str << get_identifier(constant.name).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
723 @d_constants_static_this << c
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
724 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
725
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
726 str << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
727 @d_constants.clear
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
728 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
729 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
730
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
731 # Generates the D code for the constants the has to be in a "static this"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
732 def d_constants_static_this
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
733 return "" if @d_constants_static_this.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
734
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
735 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
736
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
737 @d_constants_static_this.each do |constant|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
738 str << constant.name.indent
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
739 str << " = new "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
740 str << get_identifier(constant.type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
741 str << "("
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
742 str << "bindings."
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
743 str << get_identifier(constant.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
744 str << ")".nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
745 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
746
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
747 @d_constants_static_this.clear
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
748 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
749 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
750
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
751 # Generates the D code for the enums
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
752 def enums (enums)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
753 return "" if enums.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
754
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
755 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
756
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
757 enums.each do |enum|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
758 str << "enum"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
759
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
760 if enum.name.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
761 str << "\n{".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
762
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
763 enum.member.each_with_index do |member, i|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
764 str << get_identifier(member["name"]).indent
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
765 str << " = " if member.value.length > 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
766 str << member.value
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
767 str << ",".nl(false) unless i == enum.member.length - 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
768 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
769 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
770 str << " "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
771 str << get_identifier(enum["name"]).nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
772 str << "{".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
773
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
774 enum["member"].each_with_index do |member, i|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
775 str << get_identifier(member["name"]).indent
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
776 str << " = " if member.value.length > 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
777 str << member.value
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
778 str << ",".nl(false) unless i == enum.member.length - 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
779 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
780 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
781
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
782 str << "\n}".nl(false).nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
783 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
784
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
785 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
786 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
787
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
788 # Generates the D code for the function/method args
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
789 def args (args, variadic, method = false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
790 return "" if args.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
791
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
792 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
793 if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
794 #p args
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
795 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
796 args.each do |arg|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
797
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
798 if method || arg.type != "@"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
799 type = get_type(arg.type, arg.type64, arg.declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
800 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
801 type = "id"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
802 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
803
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
804 str << type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
805 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
806 str << get_identifier(arg["name"])
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
807 str << ", "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
808 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
809
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
810 if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
811 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
812 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
813
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
814 str << "..." if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
815
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
816 return str.string if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
817 return str.string[0 ... -2] unless variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
818 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
819
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
820 # A helper function that generates the D code for the functions/methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
821 def build_function (function, method = false, static = false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
822 str = StringIO.new
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
823 variadic = function.variadic == "true"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
824 return_type = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
825 args = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
826 original_type = function.returnValue[0].type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
827
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
828 if !method && original_type == "@"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
829 return_type = "id"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
830 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
831 return_type = get_type(original_type, function.returnValue[0].type64, function.returnValue[0].declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
832 args(function.arg, variadic) unless function.arg.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
833 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
834
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
835 str << "static " if static
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
836 str << return_type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
837 str << " "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
838 str << function["name"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
839 str << " ("
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
840 str << args(function["arg"], variadic, method)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
841 str << ")".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
842
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
843 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
844 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
845
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
846 # Generates the D code for the functions
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
847 def functions (functions)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
848 return "" if functions.length == 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
849
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
850 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
851 wrapper_needed = false
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
852
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
853 str << "extern (C)".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
854 str << "{".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
855
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
856 functions.each do |function|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
857 wrapper_needed = false
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
858 original_type = function.returnValue[0].type
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
859
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
860 if original_type == "@"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
861 @function_wrappers << function
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
862 wrapper_needed = true
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
863 str << functions_helper(function, wrapper_needed)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
864 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
865 function.arg.each do |arg|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
866 if (arg.type || arg.type64) == "@"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
867 @function_wrappers << function
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
868 wrapper_needed = true
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
869 break
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
870 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
871 end unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
872
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
873 str << functions_helper(function, wrapper_needed) if wrapper_needed
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
874 @c_functions << function unless wrapper_needed
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
875 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
876 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
877
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
878 str << "}"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
879 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
880 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
881
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
882 def c_functions
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
883 return "" if @c_functions.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
884
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
885 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
886
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
887 str << "extern (C)".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
888 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
889
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
890 @c_functions.each do |function|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
891 str << functions_helper(function, false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
892 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
893
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
894 str << "}"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
895
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
896 @c_functions.clear
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
897 str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
898 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
899
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
900
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
901 # A helper function that generates the D code for the functions
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
902 def functions_helper (function, wrapper_needed)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
903 str = StringIO.new
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
904
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
905 str << ("private " + build_function(function)).indent if wrapper_needed
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
906 str << build_function(function).indent unless wrapper_needed
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
907
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
908 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
909 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
910
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
911 # Generates the D code for the functions that D can't handle without wrappers, like functions that takes
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
912 # objects as arguments or returns an object
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
913 def function_wrappers
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
914 return "" if @function_wrappers.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
915
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
916 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
917
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
918 @function_wrappers.each do |function|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
919 return_type = get_type(function.returnValue[0].type, function.returnValue[0].type64, function.returnValue[0].declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
920 variadic = function.variadic == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
921
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
922 str << build_function(function, true)[0 ... -2].nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
923 str << "{".nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
924 str << "return Bridge.invokeObjcFunction!(".indent
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
925 str << return_type
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
926 str << ", bindings."
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
927 str << function.name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
928
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
929 function.arg.each do |arg|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
930 str << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
931 str << get_type(arg.type, arg.type, arg.declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
932 end unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
933
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
934 unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
935 str << ")"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
936 str << "("
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
937 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
938
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
939 function.arg.each_with_index do |arg, i|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
940 str << arg.name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
941 str << ", " unless i == function.arg.length - 1
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
942 end unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
943
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
944 str << ")".nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
945
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
946 str << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
947 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
948
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
949 @function_wrappers.clear
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
950 str.string
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
951 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
952
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
953 # Generates the D code for the imports
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
954 def imports (imports, filename, framework_name = nil)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
955 return "" if imports.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
956
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
957 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
958
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
959 imports.each do |import|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
960 str << "import #{@package}."
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
961 import = import.gsub("/", ".").gsub("Frameworks", "").gsub(".framework", "").gsub("Headers", "").gsub(/\.{2,}/, ".").nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
962
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
963 splits = import.split('.')
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
964 import = ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
965
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
966 splits[0 .. -2].each do |s|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
967 import << get_identifier(s.downcase)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
968 import << '.'
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
969 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
970
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
971 str << import
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
972 str << splits[-1 .. -1]
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
973 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
974
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
975 str << "import dstep.objc.bridge.Bridge".nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
976 str << "import dstep.objc.objc : id".nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
977
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
978 str << "\n\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
979 str = str.string.sort.to_s
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
980
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
981 return "\n\npublic:" << str if filename == framework_name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
982 return str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
983 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
984
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
985 # Generates the D code for the methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
986 def methods (methods, class_name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
987 return "" if methods.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
988
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
989 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
990
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
991 methods.each do |method|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
992 return_type = get_type(method.returnValue[0].type, method.returnValue[0].type64, method.returnValue[0].declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
993 variadic = method.variadic == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
994 static = method.classMethod == "true"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
995
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
996 index = 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
997 declaration = build_function(method, true, static)[0 ... -2].indent.nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
998 index = declaration.index_of(" ") if static
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
999 index = declaration.index_of(" ", index)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1000
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1001 str << (declaration[0 .. index] + get_method_name(method["selector"]) + declaration[index .. -1]).gsub(/ +/, " ")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1002 str << "{".indent.nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1003 str << "return invokeObjcSelf!(".indent(2) unless static
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1004 str << "return invokeObjcSelfClass!(".indent(2) if static
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1005 str << return_type
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1006 str << ', "'
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1007 str << method.selector
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1008 str << '"'
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1009
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1010 method.arg.each do |arg|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1011 str << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1012 str << get_type(arg.type, arg.type, arg.declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1013 end unless method.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1014
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1015 unless method.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1016 str << ")"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1017 str << "("
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1018 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1019
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1020 method.arg.each_with_index do |arg, i|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1021 str << arg.name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1022 str << ", " unless i == method.arg.length - 1
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1023 end unless method.arg.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1024
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1025 str << ")".nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1026
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1027 str << "}".indent.nl(false).nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1028 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1029
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1030 str.string[0 .. -2]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1031 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1032
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1033 # Generates the D code for the interface methods
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1034 def interface_methods (methods, interface_name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1035 return "" if methods.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1036
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1037 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1038
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1039 methods.each do |method|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1040 return_type = get_type(method.returnValue[0].type, method.returnValue[0].type64, method.returnValue[0].declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1041
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1042 variadic = method.variadic == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1043 static = method.classMethod == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1044
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1045 index = 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1046 declaration = build_function(method, true, static)[0 ... -2].indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1047 index = declaration.index_of(" ", index)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1048 str << ((declaration[0 .. index] + get_method_name(method["selector"]) + declaration[index .. -1]).gsub(/ +/, " "))[0 .. -2]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1049 str << ";\n"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1050 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1051
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1052 str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1053 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1054
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1055 # Generates the D code for the structs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1056 def structs (structs)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1057 return "" if structs.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1058
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1059 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1060
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1061 structs.each do |struct|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1062 str << "struct "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1063 str << get_identifier(struct.name).nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1064 str << "{".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1065
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1066 struct.member.each do |member|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1067 type = get_type(member.type, member.type64, member.declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1068
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1069 str << type.indent
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1070 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1071 str << get_identifier(member.name).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1072 end unless struct.member.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1073
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1074 str << "}".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1075 str << "\n\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1076 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1077
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1078 str.string[0 .. -2]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1079 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1080
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1081 # Generates the D code for the typedefs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1082 def typedefs (typedefs)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1083 return "" if typedefs.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1084
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1085 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1086
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1087 typedefs.each do |typedef|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1088
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1089 type = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1090 struct = false
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1091
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1092 if typedef.type.struct?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1093 type = get_struct_type(typedef.type, typedef.type64, typedef.declaredType)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1094 struct = true
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1095 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1096 type = get_type(typedef.type, typedef.type64, typedef.declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1097 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1098
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1099 if struct
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1100 str << typedef.declaredType.gsub("*", "").nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1101 str << "alias "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1102 str << get_identifier(type.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1103 str << "*" if typedef.declaredType =~ /\*/
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1104 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1105 str << get_identifier(typedef.name).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1106 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1107 str << "alias "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1108 str << type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1109 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1110 str << get_identifier(typedef.name).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1111 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1112 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1113
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1114 str << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1115 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1116 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1117
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1118 # Adds specific D extensions to classes, like opIndex and opApply
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1119 def d_class_extensions (args)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1120
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1121 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1122
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1123 # Checks if the declared type should be used instead of the type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1124 # type:: the type to check
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1125 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1126 def check_declared_type (type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1127 case type
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1128 when "unichar"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1129 when "UniChar"; return "wchar"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1130 when "BOOL"; return "bool"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1131 when "CGFloat"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1132 when "NSInteger"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1133 when "NSUInteger"; return type
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1134 when "IMP"; return type;
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1135
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1136 when "unichar*"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1137 when "UniChar*"; return "wchar*"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1138 when "BOOL*"; return "bool*"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1139 when "CGFloat*"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1140 when "NSInteger*"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1141 when "NSUInteger*"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1142
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1143 when "unichar**"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1144 when "UniChar**"; return "wchar**"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1145 when "BOOL**"; return "bool**"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1146 when "CGFloat**"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1147 when "NSInteger**"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1148 when "NSUInteger**"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1149 else return nil;
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1150 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1151 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1152
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1153 # Gets the method name from the supplied selector
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1154 # selector:: the selector to get the method name from
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1155 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1156 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1157 # get_method_name("initWithContentsOfURL:options:error:") #=> initWithContentsOfURL
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1158 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1159 def get_method_name (selector)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1160 i = selector.index_of(":")
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1161 get_identifier(selector[0 ... i])
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1162 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1163
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1164 # Gets the D type from the encoded C/Objective-C type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1165 # type:: the type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1166 # type64:: the type for 64bit targets
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1167 # declared_type:: the declared type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1168 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1169 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1170 # get_type("I", "Q", "NSUInteger") #=> NSUInteger
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1171 # get_type("I", "I", "unsigned int") #=> uint
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1172 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1173 def get_type (type, type64, declared_type)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1174
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1175 return get_identifier(declared_type) if type.nil? && type64.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1176
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1177 t = check_declared_type(declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1178 return t unless t.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1179
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1180 unless type64 == "" || type64.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1181 return get_identifier(declared_type) if type != type64
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1182 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1183
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1184 case type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1185 when "c"; return "byte"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1186 when "i"; return "int"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1187 when "s"; return "short"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1188 when "l"; return "int"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1189 when "q"; return "long"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1190 when "C"; return "ubyte"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1191 when "I"; return "uint"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1192 when "S"; return "ushort"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1193 when "L"; return "uint"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1194 when "Q"; return "ulong"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1195 when "f"; return "float"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1196 when "d"; return "double"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1197 when "B"; return "bool"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1198 when "v"; return "void"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1199 when "*"; return "char*"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1200 when '#'; return "Class"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1201 when ":"; return "SEL"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1202 when "@"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1203 unless declared_type.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1204 t = declared_type.gsub(/\*+/, "")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1205 return t == "id" ? "Object" : t
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1206 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1207
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1208 raise "No declared type given"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1209 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1210 return declared_type if type =~ /\{/
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1211
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1212 case type[0, 1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1213 when "["
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1214 str = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1215 t = type[1 ... -1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1216 count = $1 if t =~ /(\d+)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1217 t = $'
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1218
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1219 t64 = type64[1 ... -1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1220 count = $1 if t64 =~ /(\d+)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1221 t64 = $'
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1222
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1223 str = get_type(t, t64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1224 str << "[#{count}]"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1225
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1226 return get_identifier(str)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1227 when "("
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1228 resolved_types = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1229 types = $2 if type =~ /\((.+)=(.+)\)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1230 types64 = $2 if type64 =~ /\((.+)=(.+)\)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1231
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1232 for i in types
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1233 resolved_types << get_type(types[i], types64[i], declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1234 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1235
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1236 return get_identifier(resolved_types)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1237 when "^"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1238 if type == "^@"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1239 return get_identifier(get_type(type[1 .. -1], type64[1 .. -1], declared_type).dup + "*")
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1240 elsif type.length > 2 && type[0 ... 2] == "^^"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1241 return get_identifier(get_type(type[2 .. -1], type64[2 .. -1], declared_type).dup + "**")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1242 elsif type == "^?" # assuming function pointer
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1243 tmp = cfp_to_dfp(type)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1244 return get_identifier(tmp) unless tmp.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1245 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1246
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1247 if !type.nil? && !type64.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1248 t = get_type(type[1 .. -1], type64[1 .. -1], declared_type).dup
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1249
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1250 return get_identifier(t) if t =~ /\*/
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1251 return get_identifier(t + "*") if t !~ /\*/
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1252 elsif !type.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1253 t = get_type(type[1 .. -1], type64, declared_type).dup << "*"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1254
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1255 return get_identifier(t) if t =~ /\*/
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1256 return get_identifier(t + "*") if t !~ /\*/
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1257 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1258 when "{"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1259 return get_identifier(declared_type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1260 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1261 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1262
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1263 return get_identifier(declared_type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1264 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1265
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1266 # Gets the D type from the encoded C/Objective-C type when it's a struct
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1267 # type:: the type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1268 # type64:: the type for 64bit targets
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1269 # declared_type:: the declared type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1270 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1271 # === Example
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1272 # get_struct_type("{some=III}", "{some=III}", "struct some")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1273 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1274 # { :name => "some", :types => ["uint", "uint", "uint"] }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1275 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1276 def get_struct_type (type, type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1277 return { :name => declared_type } if declared_type[0 ... 2] == "NS"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1278
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1279 case type[0, 1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1280 when "{"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1281 resolved_types = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1282
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1283 if type =~ /\^{0,}\{(.{0,})=(.{0,})\}/
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1284 name = get_identifier($1)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1285 types = get_identifier($2)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1286 elsif type =~ /\^{0,}\((.{0,})=(.{0,})\)/
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1287 name = get_identifier($1)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1288 types = get_identifier($2)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1289 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1290
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1291 unless types.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1292 types.each_char do |t|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1293 resolved_types << get_type(t, type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1294 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1295 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1296
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1297 name = declared_type if name.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1298
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1299 return { :name => name, :types => resolved_types }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1300 when "^"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1301 get_struct_type(type[1 .. -1], type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1302 hash = get_struct_type(type[1 .. -1], type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1303 hash[:name].dup << "*"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1304 return hash
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1305 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1306 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1307
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1308 # C Function Pointer to D Function Pointer
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1309 def cfp_to_dfp (fp)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1310 reg = /(\w+)\s*\(\*(\w*)\)\s*\((.*)\)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1311
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1312 return nil if fp !~ reg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1313
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1314 return_type = $1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1315 name = $2
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1316 arg_types = $3
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1317
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1318 return "#{get_identifier(return_type)} function (#{arg_types})"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1319 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1320
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1321 # Is the supplied argument an "out" argument
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1322 # arg:: the arg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1323 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1324 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1325 # out_arg?("out NSError") #=> true
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1326 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1327 def out_arg? (arg)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1328 return arg[0 .. 4] == "out "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1329 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1330
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1331 # Transform the supplied selector to a valid D representation
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1332 # selector:: the selector to transform
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1333 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1334 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1335 # transform_selector("initWithContentsOfURL:options:error:")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1336 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1337 # initWithContentsOfURL_options_error_
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1338 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1339 def transform_selector (selector)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1340 selector.gsub(/:/, "_")
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1341 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1342
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1343 # Gets the identifier, if it's a D keyoword it
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1344 # will return string appended with a _ otherwise the string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1345 def get_identifier (str)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1346 return is_keyword?(str) ? str + "_" : str
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1347 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1348
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1349 # Returns true if the given string is a D(2) keyword
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1350 def is_keyword? (str)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1351 case str
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1352 when "abstract"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1353 when "alias"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1354 when "align"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1355 when "asm"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1356 when "assert"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1357 when "auto"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1358
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1359 when "body"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1360 when "bool"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1361 when "break"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1362 when "byte"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1363
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1364 when "case"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1365 when "cast"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1366 when "catch"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1367 when "cdouble"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1368 when "cent"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1369 when "cfloat"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1370 when "char"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1371 when "class"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1372 when "const"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1373 when "continue"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1374 when "creal"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1375
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1376 when "dchar"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1377 when "debug"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1378 when "default"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1379 when "delegate"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1380 when "delete"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1381 when "deprecated"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1382 when "do"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1383 when "double"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1384
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1385 when "else"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1386 when "enum"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1387 when "export"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1388 when "extern"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1389
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1390 when "false"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1391 when "final"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1392 when "finally"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1393 when "float"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1394 when "for"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1395 when "foreach"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1396 when "foreach_reverse"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1397 when "function"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1398
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1399 when "goto"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1400
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1401 when "idouble"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1402 when "if"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1403 when "ifloat"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1404 when "import"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1405 when "in"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1406 when "inout"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1407 when "int"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1408 when "interface"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1409 when "invariant"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1410 when "ireal"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1411 when "is"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1412
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1413 when "lazy"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1414 when "long"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1415
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1416 when "macro"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1417 when "mixin"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1418 when "module"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1419
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1420 when "new"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1421 when "nothrow"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1422 when "null"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1423
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1424 when "out"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1425 when "override"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1426
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1427 when "package"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1428 when "pragma"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1429 when "private"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1430 when "protected"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1431 when "public"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1432 when "pure"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1433
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1434 when "real"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1435 when "ref"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1436 when "return"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1437
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1438 when "scope"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1439 when "shared"; return true;s
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1440 when "short"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1441 when "static"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1442 when "struct"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1443 when "super"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1444 when "switch"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1445 when "synchronized"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1446
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1447 when "template"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1448 when "this"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1449 when "throw"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1450 when "true"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1451 when "try"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1452 when "typedef"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1453 when "typeid"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1454 when "typeof"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1455
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1456 when "ubyte"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1457 when "ucent"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1458 when "uint"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1459 when "ulong"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1460 when "union"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1461 when "unittest"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1462 when "ushort"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1463
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1464 when "version"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1465 when "void"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1466 when "volatile"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1467
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1468 when "wchar"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1469 when "while"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1470 when "with"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1471 else return false;
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1472 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1473 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1474
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1475 def templates_for_class (clazz)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1476 templates = @templates.find_all do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1477 value[:class] == clazz
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1478 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1479
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1480 return templates
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1481 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1482
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1483 def interface_for_protocol (protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1484 interface = @interfaces2.find do |interface|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1485 interface.name == protocol
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1486 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1487
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1488 return interface
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1489 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1490
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1491 def get_framework_name (framework)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1492 i = framework.rindex(".framework")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1493 return framework if i.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1494 x = framework.rindex("/", i)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1495 framework[x + 1 ... i]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1496 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1497 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1498
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1499 # Prints the message to stderr, exits
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1500 def die (*msg)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1501 $stderr.puts msg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1502 exit 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1503 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1504
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1505 if __FILE__ == $0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1506 objc_to_d = ObjcToD.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1507
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1508 OptionParser.new do |opts|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1509 opts.banner = "Usage: #{File.basename(__FILE__)} [options] <dstep files...>"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1510 opts.separator ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1511 opts.separator "Options:"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1512
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1513 opts.on("-o", "--output DIRECTORY", "Place the output files in this directory'") do |opt|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1514 die "The specified directory \"#{opt}\" does not exists" if File.exist?(opt) == false
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1515 die "Output directory cannot be specified more than once" if objc_to_d.out_dir
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1516 objc_to_d.out_dir = opt
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1517 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1518
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1519 help_msg = "Use the `-h' flag or for help."
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1520
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1521 opts.on("-h", "--help", "Show this message.") do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1522 puts opts, help_msg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1523 exit
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1524 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1525
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1526 opts.on('-v', '--version', 'Show version.') do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1527 puts ObjcToD::VERSION
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1528 exit
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1529 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1530
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1531 opts.separator ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1532
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1533 if ARGV.empty?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1534 die opts.banner
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1535 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1536 #begin
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1537 opts.parse!(ARGV)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1538
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1539 die "No output directory given" if objc_to_d.out_dir.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1540
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1541 ARGV.each do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1542 objc_to_d.files << file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1543 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1544
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1545 objc_to_d.generate_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1546 objc_to_d.output_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1547 # rescue => e
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1548 # msg = e.message
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1549 # msg = "Internal error" if msg.empty?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1550 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1551 # die msg, opts.banner, help_msg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1552 # end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1553 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1554 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1555 end