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