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