Mercurial > projects > dstep
annotate scripts/dgen.rb @ 11:07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 01 Aug 2009 15:03:28 +0200 |
parents | 27e00625790b |
children | 4f583f7e242e |
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 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1102 index = declaration.index_of(" ", index) |
1 | 1103 |
1104 str << (declaration[0 .. index] + get_method_name(method["selector"]) + declaration[index .. -1]).gsub(/ +/, " ") | |
1105 str << "{".indent.nl(false) | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1106 str << "return invokeObjcSelf!(".indent(2) unless static |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1107 str << "return invokeObjcSelfClass!(".indent(2) if static |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1108 str << return_type |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1109 str << ', "' |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1110 str << method.selector |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1111 str << '"' |
1 | 1112 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1113 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
|
1114 str << ", " |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1115 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
|
1116 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
|
1117 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1118 unless method.arg.nil? |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1119 str << ")" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1120 str << "(" |
1 | 1121 end |
1122 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1123 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
|
1124 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
|
1125 str << ", " unless i == method.arg.length - 1 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1126 end unless method.arg.nil? |
1 | 1127 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1128 str << ")".nl |
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 str << "}".indent.nl(false).nl(false) |
1 | 1131 end |
1132 | |
1133 str.string[0 .. -2] | |
1134 end | |
1135 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1136 # 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
|
1137 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
|
1138 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
|
1139 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1140 str = StringIO.new |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1141 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1142 methods.each do |method| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1143 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
|
1144 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1145 variadic = method.variadic == "true" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1146 static = method.classMethod == "true" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1147 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1148 index = 0 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1149 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
|
1150 index = declaration.index_of(" ", index) |
9
3592b41928fe
Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents:
8
diff
changeset
|
1151 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
|
1152 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
|
1153 str << ";\n" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1154 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1155 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1156 str.string |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1157 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1158 |
1 | 1159 # Generates the D code for the structs |
1160 def structs (structs) | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1161 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
|
1162 |
1 | 1163 str = StringIO.new |
1164 | |
1165 structs.each do |struct| | |
1166 str << "struct " | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1167 str << get_identifier(struct.name).nl(false) |
1 | 1168 str << "{".nl |
1169 | |
1170 struct.member.each do |member| | |
1171 type = get_type(member.type, member.type64, member.declaredType) | |
1172 | |
1173 str << type.indent | |
1174 str << " " | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1175 str << get_identifier(member.name).nl |
1 | 1176 end unless struct.member.nil? |
1177 | |
1178 str << "}".nl | |
1179 str << "\n\n" | |
1180 end | |
1181 | |
1182 str.string[0 .. -2] | |
1183 end | |
1184 | |
1185 # Generates the D code for the typedefs | |
1186 def typedefs (typedefs) | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1187 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
|
1188 |
1 | 1189 str = StringIO.new |
1190 | |
1191 typedefs.each do |typedef| | |
1192 | |
1193 type = "" | |
1194 struct = false | |
1195 | |
1196 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
|
1197 type = get_struct_type(typedef.type, typedef.type64, typedef.declaredType) |
1 | 1198 struct = true |
1199 else | |
1200 type = get_type(typedef.type, typedef.type64, typedef.declaredType) | |
1201 end | |
1202 | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1203 if struct |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1204 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
|
1205 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
|
1206 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
|
1207 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1208 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
|
1209 str << "alias " |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1210 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
|
1211 str << " " |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1212 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
|
1213 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1214 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1215 # str << "alias " |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1216 # 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
|
1217 # 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
|
1218 # str << " " |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1219 # 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
|
1220 end |
1 | 1221 else |
1222 str << "alias " | |
1223 str << type | |
1224 str << " " | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1225 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
|
1226 end unless type.nil? |
1 | 1227 end |
1228 | |
1229 str << "\n" | |
1230 str.string | |
1231 end | |
1232 | |
1233 # Adds specific D extensions to classes, like opIndex and opApply | |
1234 def d_class_extensions (args) | |
1235 | |
1236 end | |
1237 | |
1238 # Checks if the declared type should be used instead of the type | |
1239 # type:: the type to check | |
1240 # | |
1241 def check_declared_type (type) | |
1242 case type | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1243 when "unichar" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1244 when "UniChar"; return "wchar" |
1 | 1245 when "BOOL"; return "bool" |
1246 when "CGFloat"; return type | |
1247 when "NSInteger"; return type | |
1248 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
|
1249 when "IMP"; return type; |
1 | 1250 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1251 when "unichar*" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1252 when "UniChar*"; return "wchar*" |
1 | 1253 when "BOOL*"; return "bool*" |
1254 when "CGFloat*"; return type | |
1255 when "NSInteger*"; return type | |
1256 when "NSUInteger*"; return type | |
1257 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1258 when "unichar**" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1259 when "UniChar**"; return "wchar**" |
1 | 1260 when "BOOL**"; return "bool**" |
1261 when "CGFloat**"; return type | |
1262 when "NSInteger**"; return type | |
1263 when "NSUInteger**"; return type | |
1264 else return nil; | |
1265 end | |
1266 end | |
1267 | |
1268 # Gets the method name from the supplied selector | |
1269 # selector:: the selector to get the method name from | |
1270 # | |
1271 # === Example: | |
1272 # get_method_name("initWithContentsOfURL:options:error:") #=> initWithContentsOfURL | |
1273 # | |
1274 def get_method_name (selector) | |
1275 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
|
1276 get_identifier(selector[0 ... i]) |
1 | 1277 end |
1278 | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1279 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
|
1280 case char |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1281 when "{"; return "}" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1282 when "("; return ")" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1283 when "["; return "]" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1284 else |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1285 char |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1286 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1287 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1288 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1289 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1290 |
1 | 1291 # Gets the D type from the encoded C/Objective-C type |
1292 # type:: the type | |
1293 # type64:: the type for 64bit targets | |
1294 # declared_type:: the declared type | |
1295 # | |
1296 # === Example: | |
1297 # get_type("I", "Q", "NSUInteger") #=> NSUInteger | |
1298 # get_type("I", "I", "unsigned int") #=> uint | |
1299 # | |
1300 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
|
1301 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
|
1302 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
|
1303 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1304 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
|
1305 |
1 | 1306 t = check_declared_type(declared_type) |
1307 return t unless t.nil? | |
1308 | |
1309 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
|
1310 return get_identifier(declared_type) if type != type64 |
1 | 1311 end |
1312 | |
1313 case type | |
1314 when "c"; return "byte" | |
1315 when "i"; return "int" | |
1316 when "s"; return "short" | |
1317 when "l"; return "int" | |
1318 when "q"; return "long" | |
1319 when "C"; return "ubyte" | |
1320 when "I"; return "uint" | |
1321 when "S"; return "ushort" | |
1322 when "L"; return "uint" | |
1323 when "Q"; return "ulong" | |
1324 when "f"; return "float" | |
1325 when "d"; return "double" | |
1326 when "B"; return "bool" | |
1327 when "v"; return "void" | |
1328 when "*"; return "char*" | |
1329 when '#'; return "Class" | |
1330 when ":"; return "SEL" | |
1331 when "@" | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1332 unless declared_type.nil? |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1333 t = declared_type.gsub(/\*+/, "") |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1334 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
|
1335 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1336 |
1 | 1337 raise "No declared type given" |
1338 else | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1339 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
|
1340 |
1 | 1341 case type[0, 1] |
1342 when "[" | |
1343 str = "" | |
1344 t = type[1 ... -1] | |
1345 count = $1 if t =~ /(\d+)/ | |
1346 t = $' | |
1347 | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1348 t64 = "" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1349 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1350 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
|
1351 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
|
1352 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
|
1353 t64 = $' |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1354 else |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1355 t64 = t |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1356 end |
1 | 1357 |
1358 str = get_type(t, t64, declared_type) | |
1359 str << "[#{count}]" | |
1360 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1361 return get_identifier(str) |
1 | 1362 when "(" |
1363 resolved_types = [] | |
1364 types = $2 if type =~ /\((.+)=(.+)\)/ | |
1365 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
|
1366 i = 0 |
1 | 1367 |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1368 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
|
1369 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
|
1370 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
|
1371 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1372 index = t =~ /(\(|\[|\{)/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1373 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1374 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
|
1375 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
|
1376 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
|
1377 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
|
1378 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
|
1379 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1380 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1381 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
|
1382 i += 1 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1383 end unless types.nil? |
1 | 1384 |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1385 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
|
1386 when "^" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1387 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
|
1388 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
|
1389 get_identifier(get_type(t, t64, declared_type).dup + "*") |
1 | 1390 |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1391 # if type == "^@" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1392 # 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
|
1393 # 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
|
1394 # 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
|
1395 # 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
|
1396 # 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
|
1397 # 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
|
1398 # end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1399 # |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1400 # 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
|
1401 # 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
|
1402 # |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1403 # 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
|
1404 # 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
|
1405 # 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
|
1406 # 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
|
1407 # |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1408 # 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
|
1409 # 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
|
1410 # end |
1 | 1411 when "{" |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1412 return get_identifier(declared_type) |
1 | 1413 end |
1414 end | |
1415 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1416 return get_identifier(declared_type) |
1 | 1417 end |
1418 | |
1419 # Gets the D type from the encoded C/Objective-C type when it's a struct | |
1420 # type:: the type | |
1421 # type64:: the type for 64bit targets | |
1422 # declared_type:: the declared type | |
1423 # | |
1424 # === Example | |
1425 # get_struct_type("{some=III}", "{some=III}", "struct some") | |
1426 # # outputs below | |
1427 # { :name => "some", :types => ["uint", "uint", "uint"] } | |
1428 # | |
1429 def get_struct_type (type, type64, declared_type) | |
1430 return { :name => declared_type } if declared_type[0 ... 2] == "NS" | |
1431 | |
1432 case type[0, 1] | |
1433 when "{" | |
1434 resolved_types = [] | |
1435 | |
1436 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
|
1437 name = get_identifier($1) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1438 types = get_identifier($2) |
1 | 1439 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
|
1440 name = get_identifier($1) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1441 types = get_identifier($2) |
1 | 1442 end |
1443 | |
1444 unless types.nil? | |
1445 types.each_char do |t| | |
1446 resolved_types << get_type(t, type64, declared_type) | |
1447 end | |
1448 end | |
1449 | |
1450 name = declared_type if name.nil? | |
1451 | |
1452 return { :name => name, :types => resolved_types } | |
1453 when "^" | |
1454 get_struct_type(type[1 .. -1], type64, declared_type) | |
1455 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
|
1456 hash[:name].dup << "*" unless hash.nil? |
1 | 1457 return hash |
1458 end | |
1459 end | |
1460 | |
1461 # C Function Pointer to D Function Pointer | |
1462 def cfp_to_dfp (fp) | |
1463 reg = /(\w+)\s*\(\*(\w*)\)\s*\((.*)\)/ | |
1464 | |
1465 return nil if fp !~ reg | |
1466 | |
1467 return_type = $1 | |
1468 name = $2 | |
1469 arg_types = $3 | |
1470 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1471 return "#{get_identifier(return_type)} function (#{arg_types})" |
1 | 1472 end |
1473 | |
1474 # Is the supplied argument an "out" argument | |
1475 # arg:: the arg | |
1476 # | |
1477 # === Example: | |
1478 # out_arg?("out NSError") #=> true | |
1479 # | |
1480 def out_arg? (arg) | |
1481 return arg[0 .. 4] == "out " | |
1482 end | |
1483 | |
1484 # Transform the supplied selector to a valid D representation | |
1485 # selector:: the selector to transform | |
1486 # | |
1487 # === Example: | |
1488 # transform_selector("initWithContentsOfURL:options:error:") | |
1489 # # outputs below | |
1490 # initWithContentsOfURL_options_error_ | |
1491 # | |
1492 def transform_selector (selector) | |
1493 selector.gsub(/:/, "_") | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1494 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1495 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1496 # 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
|
1497 # 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
|
1498 def get_identifier (str) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1499 return is_keyword?(str) ? str + "_" : str |
1 | 1500 end |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1501 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1502 # 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
|
1503 def is_keyword? (str) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1504 case str |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1505 when "abstract"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1506 when "alias"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1507 when "align"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1508 when "asm"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1509 when "assert"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1510 when "auto"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1511 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1512 when "body"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1513 when "bool"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1514 when "break"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1515 when "byte"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1516 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1517 when "case"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1518 when "cast"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1519 when "catch"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1520 when "cdouble"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1521 when "cent"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1522 when "cfloat"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1523 when "char"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1524 when "class"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1525 when "const"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1526 when "continue"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1527 when "creal"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1528 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1529 when "dchar"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1530 when "debug"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1531 when "default"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1532 when "delegate"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1533 when "delete"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1534 when "deprecated"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1535 when "do"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1536 when "double"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1537 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1538 when "else"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1539 when "enum"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1540 when "export"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1541 when "extern"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1542 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1543 when "false"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1544 when "final"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1545 when "finally"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1546 when "float"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1547 when "for"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1548 when "foreach"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1549 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
|
1550 when "function"; 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 "goto"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1553 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1554 when "idouble"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1555 when "if"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1556 when "ifloat"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1557 when "import"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1558 when "in"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1559 when "inout"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1560 when "int"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1561 when "interface"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1562 when "invariant"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1563 when "ireal"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1564 when "is"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1565 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1566 when "lazy"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1567 when "long"; 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 "macro"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1570 when "mixin"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1571 when "module"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1572 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1573 when "new"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1574 when "nothrow"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1575 when "null"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1576 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1577 when "out"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1578 when "override"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1579 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1580 when "package"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1581 when "pragma"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1582 when "private"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1583 when "protected"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1584 when "public"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1585 when "pure"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1586 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1587 when "real"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1588 when "ref"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1589 when "return"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1590 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1591 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
|
1592 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
|
1593 when "short"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1594 when "static"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1595 when "struct"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1596 when "super"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1597 when "switch"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1598 when "synchronized"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1599 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1600 when "template"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1601 when "this"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1602 when "throw"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1603 when "true"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1604 when "try"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1605 when "typedef"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1606 when "typeid"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1607 when "typeof"; 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 "ubyte"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1610 when "ucent"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1611 when "uint"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1612 when "ulong"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1613 when "union"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1614 when "unittest"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1615 when "ushort"; 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 "version"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1618 when "void"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1619 when "volatile"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1620 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1621 when "wchar"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1622 when "while"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1623 when "with"; return true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1624 else return false; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1625 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1626 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1627 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1628 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
|
1629 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
|
1630 value[:class] == clazz |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1631 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1632 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1633 return templates |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1634 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1635 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1636 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
|
1637 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
|
1638 interface.name == protocol |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1639 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1640 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1641 return interface |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1642 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1643 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1644 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
|
1645 i = framework.rindex(".framework") |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1646 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
|
1647 x = framework.rindex("/", i) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1648 framework[x + 1 ... i] |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1649 end |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1650 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1651 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
|
1652 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
|
1653 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
|
1654 !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
|
1655 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1656 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
1657 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
|
1658 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
|
1659 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
|
1660 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
|
1661 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
|
1662 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
|
1663 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
|
1664 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
|
1665 end |
1 | 1666 end |
1667 | |
1668 # Prints the message to stderr, exits | |
1669 def die (*msg) | |
1670 $stderr.puts msg | |
1671 exit 1 | |
1672 end | |
1673 | |
1674 if __FILE__ == $0 | |
1675 objc_to_d = ObjcToD.new | |
1676 | |
1677 OptionParser.new do |opts| | |
1678 opts.banner = "Usage: #{File.basename(__FILE__)} [options] <dstep files...>" | |
1679 opts.separator "" | |
1680 opts.separator "Options:" | |
1681 | |
1682 opts.on("-o", "--output DIRECTORY", "Place the output files in this directory'") do |opt| | |
1683 die "The specified directory \"#{opt}\" does not exists" if File.exist?(opt) == false | |
1684 die "Output directory cannot be specified more than once" if objc_to_d.out_dir | |
1685 objc_to_d.out_dir = opt | |
1686 end | |
1687 | |
1688 help_msg = "Use the `-h' flag or for help." | |
1689 | |
1690 opts.on("-h", "--help", "Show this message.") do | |
1691 puts opts, help_msg | |
1692 exit | |
1693 end | |
1694 | |
1695 opts.on('-v', '--version', 'Show version.') do | |
1696 puts ObjcToD::VERSION | |
1697 exit | |
1698 end | |
1699 | |
1700 opts.separator "" | |
1701 | |
1702 if ARGV.empty? | |
1703 die opts.banner | |
1704 else | |
1705 #begin | |
1706 opts.parse!(ARGV) | |
1707 | |
1708 die "No output directory given" if objc_to_d.out_dir.nil? | |
1709 | |
1710 ARGV.each do |file| | |
1711 objc_to_d.files << file | |
1712 end | |
1713 | |
1714 objc_to_d.generate_code | |
1715 objc_to_d.output_code | |
1716 # rescue => e | |
1717 # msg = e.message | |
1718 # msg = "Internal error" if msg.empty? | |
1719 # | |
1720 # die msg, opts.banner, help_msg | |
1721 # end | |
1722 end | |
1723 end | |
1724 end |