Mercurial > projects > dstep
annotate scripts/dstepgen.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 | 9e67a1122e85 |
children | 19885b43130e |
rev | line source |
---|---|
1 | 1 #!/usr/bin/env ruby |
2 | |
3 # Copyright (c) 2008-2009, Jacob Carlborg. All rights reserved. | |
4 # Copyright (c) 2006-2007, Apple Inc. All rights reserved. | |
5 # Copyright (c) 2005-2006 FUJIMOTO Hisakuni | |
6 # | |
7 # Redistribution and use in source and binary forms, with or without | |
8 # modification, are permitted provided that the following conditions | |
9 # are met: | |
10 # 1. Redistributions of source code must retain the above copyright | |
11 # notice, this list of conditions and the following disclaimer. | |
12 # 2. Redistributions in binary form must reproduce the above copyright | |
13 # notice, this list of conditions and the following disclaimer in the | |
14 # documentation and/or other materials provided with the distribution. | |
15 # 3. Neither the name of Apple Inc. ("Apple") nor the names of | |
16 # its contributors may be used to endorse or promote products derived | |
17 # from this software without specific prior written permission. | |
18 # | |
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND | |
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 # ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR | |
23 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
27 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
28 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 # POSSIBILITY OF SUCH DAMAGE. | |
30 | |
31 require "rubygems" | |
32 gem "builder", "~> 2.0" | |
33 require "builder" | |
34 require "tmpdir" | |
35 require "optparse" | |
36 include Builder | |
37 | |
38 $KCODE = "UTF8" | |
39 | |
40 # Extensions that adds support for member access syntax | |
41 class Hash | |
42 def type | |
43 result = self["type"] | |
44 return result unless result.nil? | |
45 self[:type] | |
46 end | |
47 | |
48 def type= (type) | |
49 self[:type] = type | |
50 end | |
51 | |
52 def id | |
53 result = self["id"] | |
54 return result unless result.nil? | |
55 self[:id] | |
56 end | |
57 | |
58 def id= (id) | |
59 self[:id] = id | |
60 end | |
61 | |
62 def methods | |
63 result = self["methods"] | |
64 return result unless result.nil? | |
65 self[:methods] | |
66 end | |
67 | |
68 def methods= (methods) | |
69 self[:methods] = methods | |
70 end | |
71 | |
72 def method_missing (method, *args) | |
73 self.class.instance_eval do | |
74 define_method(method) do |*args| | |
75 if args.length > 0 | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
76 #self[method[0 ... -1]] = args[0] |
1 | 77 self[eval(":#{method}"[0 ... -1])] = args[0] |
78 else | |
79 result = self[method] | |
80 return result unless result.nil? | |
81 self[eval(":#{method}")] | |
82 end | |
83 end | |
84 end | |
85 | |
86 if (method = method.id2name) =~ /=/ | |
87 eval("self.#{method} (args.length < 2 ? args[0] : args)") | |
88 else | |
89 eval("self.#{method}") | |
90 end | |
91 end | |
92 end | |
93 | |
94 # This Struct represents an Objective-C Framework | |
95 Framework = Struct.new(:name, :headers, :path) do | |
96 def initialize | |
97 self.headers = [] | |
98 self.name = "" | |
99 self.path = "" | |
100 end | |
101 end | |
102 | |
103 # This Struct represents a C/Objective-C header | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
104 HeaderFile = Struct.new(:name, :framework, :cftypes, :constants, :defines, :enums, :externs, :functions, :function_pointers, |
1 | 105 :imports, :inline_functions, :opaques, :path, :structs, :typedefs) do |
106 def initialize | |
107 self.name = "" | |
108 self.cftypes = [] | |
109 self.constants = [] | |
110 self.defines = [] | |
111 self.enums = [] | |
112 self.externs = [] | |
113 self.framework = "" | |
114 self.functions = [] | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
115 self.function_pointers = {} |
1 | 116 self.imports = [] |
117 self.inline_functions = [] | |
118 self.opaques = [] | |
119 self.path = "" | |
120 self.structs = [] | |
121 self.typedefs = [] | |
122 end | |
123 end | |
124 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
125 Category = Struct.new(:name, :class) do |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
126 def initialize |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
127 self.name = "" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
128 self.class = "" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
129 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
130 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
131 |
1 | 132 # This class scans the headers |
133 class HeaderScaner | |
134 CPP = ['/usr/bin/cpp-4.0', '/usr/bin/cpp-3.3', '/usr/bin/cpp3'].find { |x| File.exist?(x) } | |
135 raise "cpp not found" if CPP.nil? | |
136 CPPFLAGS = "-D__APPLE_CPP__ -include /usr/include/AvailabilityMacros.h" | |
137 CPPFLAGS << "-D__GNUC__" unless /\Acpp-4/.match(File.basename(CPP)) | |
138 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
139 attr_accessor :frameworks, :headers, :do_64bit, :extra |
1 | 140 |
141 def initialize | |
142 @extern_name = 'extern' | |
143 @frameworks = [] | |
144 @file_content = nil | |
145 @headers = [] | |
146 @classes = {} | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
147 @protocols = {} |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
148 @categories = {} |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
149 #@informal_protocols = {} |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
150 #@function_pointers = {} |
1 | 151 @do_64bit = false |
152 end | |
153 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
154 def get_classes |
1 | 155 @classes |
156 end | |
157 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
158 def get_protocols |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
159 @protocols |
1 | 160 end |
161 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
162 def get_categories |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
163 @categories |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
164 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
165 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
166 # def get_informal_protocols |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
167 # @informal_protocols |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
168 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
169 |
1 | 170 def cftypes (header) |
171 re = /typedef\s+(const\s+)?(struct\s*\w+\s*\*\s*)([^\s]+Ref)\s*;/ | |
172 @cpp_result.scan(re).each do |m| | |
173 header.cftypes << { :name => m[2], :type => m[1], :const => m[0] =~ /const/ ? true : false} | |
174 end | |
175 end | |
176 | |
177 def constants (header) | |
178 tmp = header.externs.map do |i| | |
179 constant?(i, true) | |
180 end | |
181 | |
182 header.constants = tmp.flatten.compact | |
183 end | |
184 | |
185 def defines (header) | |
186 re = /#define\s+([^\s]+)\s+(\([^)]+\)|[^\s]+)\s*$/ | |
187 @file_content.scan(re).each do |m| | |
188 next unless !m[0].include?('(') && m[1] != '\\' | |
189 header.defines << { :name => m[0], :value => m[1] } | |
190 end | |
191 end | |
192 | |
193 def enums (header) | |
194 re = /\benum\b\s*(\w+\s+)?\{([^}]*)\}/ | |
195 @cpp_result.scan(re).each do |m| | |
196 enum = { :name => m[0], :members => [] } | |
197 | |
198 m[1].split(",").map do |i| | |
199 name, value = i.split("=", 2).map do |x| | |
200 x.strip | |
201 end | |
202 | |
203 enum[:members] << { :name => name, :value => value } unless name.empty? || name[0] == ?# | |
204 end | |
205 | |
206 header.enums << enum | |
207 end | |
208 end | |
209 | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
210 def function_pointers (header) |
4
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
211 re = /typedef\s+([\w\s\*]+)\s*\(\s*\*\s*(\w+)\s*\)\s*\(([^)]*)\)\s*;/ |
1 | 212 data = @cpp_result.scan(re) |
4
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
213 re = /typedef\s+([\w\s\*]+)\s*\(([^)]+)\)\s*;/ |
1 | 214 data |= @cpp_result.scan(re).map do |m| |
215 ary = m[0].split(/(\w+)$/) | |
216 ary[1] << " *" | |
217 ary << m[1] | |
218 ary | |
219 end | |
220 | |
221 data.each do |m| | |
4
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
222 variadic = false |
1 | 223 name = m[1] |
224 args = m[2].split(",").map do |x| | |
4
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
225 variadic = x =~ /\.\.\./ ? true : false |
1 | 226 if x.include?(" ") |
227 ptr = x.sub!(/\[\]\s*$/, "") | |
228 x = x.sub(/\w+\s*$/, "").strip | |
229 ptr ? x + "*" : x | |
230 else | |
231 x.strip | |
232 end | |
233 end | |
234 | |
4
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
235 args.delete("...") do |
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
236 args |
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
237 end |
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
238 |
1 | 239 type = "#{m[0]}(*)(#{args.join(', ')})" |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
240 header.function_pointers[name] = get_function_pointer(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
|
241 header.function_pointers[name].variadic = variadic |
1 | 242 end |
243 end | |
244 | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
245 def get_function_pointer (fp) |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
246 type = {} |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
247 re = /(.+)\(\*\)\((.+)\)/ |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
248 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
249 if fp =~ /(.+)\(\*\)\((.+)\)/ |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
250 m1 = $1 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
251 m2 = $2 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
252 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
253 type.const = m1 =~ /const/ ? true : false |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
254 m1.gsub!(/const/, "") |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
255 type.return_type = m1.strip |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
256 type.args = [] |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
257 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
258 args = m2.split(",") |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
259 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
260 args.each do |arg| |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
261 const = arg =~ /const/ ? true : false |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
262 arg.gsub!(/const/, "") |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
263 arg.strip! |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
264 arg.gsub!(/\s*\*/, "*") |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
265 type.args << {:type => arg, :const => const} |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
266 end |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
267 end |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
268 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
269 type |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
270 end |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
271 |
1 | 272 def typedefs (header) |
273 re = /^\s*typedef\s+(.+)\s+([\w\*]+)\s*;$/ | |
274 data = @cpp_result | |
275 data.scan(re).each do |m| | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
276 str = m[0] + m[1] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
277 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
278 if str =~ /,/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
279 i = str.index(",") |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
280 i = str.rindex(" ", i) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
281 type = str[0 ... i] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
282 names = str[i .. -1] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
283 names.gsub!(/ /, "") |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
284 names = names.split(",") |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
285 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
286 names.each do |name| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
287 var = get_var_info(type + " " + name) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
288 header.typedefs << var if var |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
289 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
290 else |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
291 var = get_var_info(m[0] + " " + m[1]) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
292 header.typedefs << get_var_info(m[0] + " " + m[1]) if var |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
293 end |
1 | 294 end |
295 end | |
296 | |
297 def externs (header) | |
298 re = /^\s*#{@extern_name}\s+\b(.*)\s*;.*$/ | |
299 header.externs = @cpp_result.scan(re).map do |m| | |
300 m[0].strip | |
301 end | |
302 end | |
303 | |
304 def imports (header) | |
305 tmp = [] | |
306 | |
307 @file_content.each do |line| | |
308 if line =~ /#(include|import) <(.+)\.h>/ | |
309 next if $2 == header.name | |
310 tmp << $2 | |
311 elsif line =~ /@class(\s+)(\w+)(,|;)/ | |
312 next if $2 == header.name | |
313 | |
314 if $3 == ";" | |
315 tmp << header.framework + "/" + $2 unless header.framework == "" | |
316 tmp << $2 if header.framework == "" | |
317 elsif | |
318 str = line[6 + $1.length ... -2] | |
319 str.gsub!(" ", "") | |
320 arr = str.split(",") | |
321 | |
322 arr.each do |s| | |
323 tmp << header.framework + "/" + s unless header.framework == "" | |
324 tmp << s if header.framework == "" | |
325 end | |
326 end | |
327 end | |
328 end | |
329 | |
330 header.imports = tmp.compact.uniq | |
331 end | |
332 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
333 # def informal_protocols (header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
334 # methods(header, /^@(interface)\s+(\w+)\s*:?\s*(\w*)\s*(\([^)]+\))?/, @protocols, false) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
335 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
336 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
337 def classes (header) |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
338 methods(header, /^@(interface)\s+(\w+)\s*:?\s*(\w*)\s*(\<([\w,\s]+)>)?(\s*\{|$)/, @classes, false) |
1 | 339 end |
340 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
341 def protocols (header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
342 methods(header, /^@(protocol)\s+(\w+)\s*:?\s*(\w*)\s*(\<([\w,\s]+)>)?(\([^)]+\))?/, @protocols, true) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
343 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
344 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
345 def categories (header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
346 methods(header, /^@(interface)\s+(\w+)\s*:?\s*(\w*)\s*(\<([\w,\s]+)>)?(\([^)]+\))/, @categories, false, true) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
347 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
348 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
349 def methods (header, regex, array, protocol, category = false) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
350 interface_re = regex |
1 | 351 |
352 end_re = /^@end/ | |
353 body_re = /^[-+]\s*(\([^)]+\))?\s*([^:\s;]+)/ | |
354 args_re = /\w+\s*:/ | |
355 prop_re = /^@property\s*(\([^)]+\))?\s*([^;]+);$/ | |
356 current_interface = current_category = nil | |
357 i = 0 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
358 parent = nil |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
359 protocols = nil |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
360 cat = nil |
1 | 361 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
362 @cpp_result.each_line do |line| |
1 | 363 size = line.size |
364 line.strip! | |
365 | |
366 if md = interface_re.match(line) | |
367 parent = nil | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
368 protocols = nil |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
369 current_category = md[6].delete("()").strip if md[6] |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
370 current_interface = md[2] unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
371 current_interface = current_category if category |
1 | 372 parent = md[3] unless md[3] == "" |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
373 protocols = md[5] if md[5] |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
374 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
375 if category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
376 cat = Category.new if category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
377 cat.name = current_category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
378 cat.class = md[2] |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
379 end |
1 | 380 |
381 elsif end_re.match(line) | |
382 current_interface = current_category = nil | |
383 | |
384 elsif current_interface && md = prop_re.match(line) | |
385 # Parsing Objective-C 2.0 properties | |
386 if (a = md[2].split(/\s/)).length >= 2 && /^\w+$/.match(name = a[-1]) && (type = a[0 .. -2].join(" ")).index(",").nil? | |
387 getter, setter = name, "set#{name[0].chr.upcase + name[1 .. -1]}" | |
388 readonly = false | |
389 | |
390 if attributes = md[1] | |
391 if md = /getter\s*=\s*(\w+)/.match(attributes) | |
392 getter = md[1] | |
393 end | |
394 | |
395 if md = /setter\s*=\s*(\w+)/.match(attributes) | |
396 setter = md[1] | |
397 end | |
398 | |
399 readonly = true if attributes.index("readonly") | |
400 end | |
401 | |
402 typeinfo = VarInfo.new(type, "", "") | |
403 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
404 array[current_interface] ||= {} unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
405 array[cat] ||= {} if category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
406 methods = (array[current_interface].methods ||= []) unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
407 methods = (array[cat].methods ||= []) if category |
1 | 408 methods << MethodInfo.new(typeinfo, getter, false, [], line) |
409 | |
410 unless readonly | |
411 methods << MethodInfo.new(VarInfo.new("void", "", ""), setter + ":", false, [typeinfo], line) | |
412 end | |
413 end | |
414 | |
415 elsif current_interface && (line[0] == ?+ || line[0] == ?-) | |
416 mtype = line[0] | |
417 data = @cpp_result[i .. -1] | |
418 body_md = body_re.match(data) | |
419 | |
420 next if body_md.nil? | |
421 | |
422 rettype = body_md[1] ? body_md[1].delete("()") : "id" | |
423 retval = VarInfo.new(rettype, "", "") | |
424 args = [] | |
425 selector = "" | |
426 data = data[0 .. data.index(";")] | |
427 args_data = [] | |
428 | |
429 data.scan(args_re) do |x| | |
430 args_data << [$`, x, $'] | |
431 end | |
432 | |
433 variadic = false | |
434 args_data.each_with_index do |ary, n| | |
435 before, argname, argtype = ary | |
436 arg_nameless = (n > 0 && /\)\s*$/.match(before)) | |
437 argname = ":" if arg_nameless | |
438 realargname = nil | |
439 | |
440 if n < args_data.length - 1 | |
441 argtype.sub!(args_data[n + 1][2], "") | |
442 | |
443 if arg_nameless | |
444 argtype.sub!(/(\w+\s*)?\w+\s*:\s*$/, "") | |
445 else | |
446 unless argtype.sub!(/(\w+)\s+\w+:\s*$/) { |s| realargname = $1; "" } | |
447 # maybe the next argument is nameless | |
448 argtype.sub!(/\w+\s*:\s*$/, "") | |
449 end | |
450 end | |
451 else | |
452 argtype.sub!(/\s+__attribute__\(\(.+\)\)/, "") | |
453 | |
454 if arg_nameless | |
455 argtype.sub!(/\w+\s*;$/, "") | |
456 else | |
457 unless argtype.sub!(/(\w+)\s*;$/) { |s| realargname = $1; "" } | |
458 variadic = argtype.sub!(/,\s*\.\.\.\s*;/, "") != nil | |
459 argtype.sub!(/\w+\s*$/, "") if variadic | |
460 end | |
461 end | |
462 end | |
463 | |
464 selector << argname | |
465 realargname ||= argname.sub(/:/, "") | |
466 args << VarInfo.new(argtype, realargname, "") unless argtype.empty? | |
467 end | |
468 | |
469 selector = body_md[2] if selector.empty? | |
470 args << VarInfo.new("...", "vararg", "") if variadic | |
471 method = MethodInfo.new(retval, selector, line[0] == ?+, args, data) | |
472 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
473 # if protocol && current_category && current_interface == "NSObject" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
474 # (@informal_protocols[current_category] ||= []) << method |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
475 # end |
1 | 476 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
477 array[current_interface] ||= {} unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
478 array[cat] ||= {} if category |
1 | 479 |
480 if header.name == current_interface | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
481 array[current_interface].file = header.name unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
482 array[cat].file = header.name if category |
1 | 483 else |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
484 array[current_interface].file ||= header.name unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
485 array[cat].file ||= header.name if category |
1 | 486 end |
487 | |
488 unless parent == current_interface || parent =~ /\s+/ || parent.nil? | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
489 array[current_interface].parent = parent unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
490 array[cat].parent = parent if category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
491 end |
1 | 492 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
493 unless protocols.nil? |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
494 protocols.gsub!(/ /, "") |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
495 array[current_interface].protocols = protocols unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
496 array[cat].protocols = protocols if category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
497 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
498 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
499 (array[current_interface].methods ||= []) << method unless category |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
500 (array[cat].methods ||= []) << method if category |
1 | 501 end |
502 i += size | |
503 end | |
504 end | |
505 | |
506 def structs (header) | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
507 re = /typedef\s+struct\s*\w*\s*((\w+)|\{([^{}]*(\{[^}]+\})?)*\}\s*([^\s]+))\s*(__attribute__\(.+\))?\s*((.+);|;)/ |
1 | 508 i = 0 |
509 body = nil | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
510 |
1 | 511 @cpp_result.scan(re).each do |m| |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
512 #name = m[4] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
513 #name = m[5] if name.nil? || name =~ /__attribute__/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
514 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
515 name = "" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
516 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
517 if !m[7].nil? && m[7] !~ /typedef/ && m[7] !~ /\W/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
518 name = m[7] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
519 elsif !m[4].nil? && m[4] !~ /__attribute__/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
520 name = m[4] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
521 else |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
522 name = m[5] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
523 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
524 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
525 unless name.nil? |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
526 name.gsub!(/\W/, "") |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
527 name = name[6 .. -1] if name.length > 6 && name[0 ... 6] == "packed" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
528 name = name[7 .. -1] if name.length > 7 && name[0 ... 7] == "typedef" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
529 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
530 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
531 struct = { :name => name, :members => [] } |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
532 |
1 | 533 unless struct[:name].nil? |
534 if struct[:name][0, 1] == "*" | |
535 struct[:name].sub!("*", "") | |
536 end | |
537 end | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
538 |
1 | 539 return_type = nil |
540 stripped_return_type = nil | |
541 body = m[2] | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
542 |
1 | 543 if m[2] |
544 m[2].split(/,|;/).map do |i| | |
545 str, bytes = i.split(":", 2).map do |x| | |
546 x.strip | |
547 end | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
548 |
1 | 549 var = get_var_info(str, true) |
550 | |
551 if var | |
552 if var.return_type == "***dummy***" | |
553 var.return_type = return_type | |
554 var.stripped_return_type = stripped_return_type | |
555 else | |
556 return_type = var.return_type | |
557 stripped_return_type = var.stripped_return_type | |
558 end | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
559 |
1 | 560 struct[:members] << { :name => var.name, :bytes => bytes, :declaredType => var.return_type, :type => "", :type64 => "" } unless str.empty? || str[0] == ?# |
561 | |
562 names = [] | |
563 | |
564 tmp = struct[:members].collect do |member| | |
565 unless names.include?(member[:name]) | |
566 names << member[:name] | |
567 member | |
568 end | |
569 end | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
570 |
1 | 571 struct[:members] = tmp.compact |
572 end | |
573 end | |
574 end | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
575 |
1 | 576 header.structs << struct if body |
577 end | |
578 end | |
579 | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
580 def structs2 (header) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
581 re = /^struct\s*(\w+)\s*((\w+)|\{([^{}]*(\{[^}]+\})?)*\}\s*([^\s]+))$/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
582 i = 0 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
583 body = nil |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
584 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
585 @cpp_result.scan(re).each do |m| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
586 name = m[0] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
587 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
588 struct = { :name => name, :members => [] } |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
589 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
590 return_type = nil |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
591 stripped_return_type = nil |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
592 body = m[3] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
593 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
594 if m[3] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
595 m[3].split(/,|;/).map do |i| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
596 str, bytes = i.split(":", 2).map do |x| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
597 x.strip |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
598 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
599 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
600 var = get_var_info(str, true) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
601 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
602 if var |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
603 if var.return_type == "***dummy***" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
604 var.return_type = return_type |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
605 var.stripped_return_type = stripped_return_type |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
606 else |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
607 return_type = var.return_type |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
608 stripped_return_type = var.stripped_return_type |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
609 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
610 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
611 struct[:members] << { :name => var.name, :bytes => bytes, :declaredType => var.return_type, :type => "", :type64 => "" } unless str.empty? || str[0] == ?# |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
612 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
613 names = [] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
614 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
615 tmp = struct[:members].collect do |member| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
616 unless names.include?(member[:name]) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
617 names << member[:name] |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
618 member |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
619 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
620 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
621 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
622 struct[:members] = tmp.compact |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
623 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
624 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
625 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
626 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
627 header.structs << struct if body |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
628 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
629 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
630 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
631 |
1 | 632 def functions (header, inline = false) |
633 if inline | |
634 inline_func_re = /(inline|__inline__)\s+((__attribute__\(\([^)]*\)\)\s+)?([\w\s\*<>]+)\s*\(([^)]*)\)\s*)\{/ | |
635 res = @cpp_result.scan(inline_func_re) | |
636 res.each do |x| | |
637 x.delete_at(0) | |
638 x.delete_at(1) | |
639 end | |
640 else | |
641 skip_inline_re = /(static)?\s(inline|__inline__)[^{;]+(;|\{([^{}]*(\{[^}]+\})?)*\})\s*/ | |
642 func_re = /(^([\w\s\*<>]+)\s*\(([^)]*)\)\s*)(__attribute__[^;]+)?;/ | |
643 res = @cpp_result.gsub(skip_inline_re, '').scan(func_re) | |
644 end | |
645 | |
646 funcs = res.map do |m| | |
647 orig, base, args = m | |
648 base.sub!(/^.*extern\s/, "") | |
649 func = constant?(base) | |
650 | |
651 if func | |
652 args = args.strip.split(",").map do |i| | |
653 constant?(i) | |
654 end | |
655 | |
656 next if args.any? do |x| | |
657 x.nil? | |
658 end | |
659 | |
660 args = [] if args.size == 1 && args[0].return_type == "void" | |
661 FunctionInfo.new(func, args, orig, inline) | |
662 end | |
663 end.compact | |
664 | |
665 if inline | |
666 header.inline_functions = funcs | |
667 else | |
668 header.functions = funcs | |
669 end | |
670 end | |
671 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
672 def prepare (path) |
1 | 673 @file_content = File.read(path) |
674 @file_content.gsub!(%r{(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)}, ""); | |
675 @complete_cpp_result, @cpp_result = do_cpp(path, false, true, "") | |
676 end | |
677 | |
678 def scan (frameworks, headers) | |
679 @frameworks = frameworks | |
680 @headers = headers | |
681 | |
682 @frameworks.each do |framework| | |
683 framework.headers.each do |header| | |
684 prepare(header.path) | |
685 | |
686 imports(header) | |
687 cftypes(header) | |
688 externs(header) | |
689 constants(header) | |
690 enums(header) | |
691 structs(header) | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
692 structs2(header) |
1 | 693 typedefs(header) |
694 functions(header) | |
695 functions(header, true) | |
696 defines(header) | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
697 classes(header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
698 protocols(header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
699 #informal_protocols(header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
700 categories(header) |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
701 function_pointers(header) |
1 | 702 end |
703 end | |
704 | |
705 @headers.each do |header| | |
706 prepare(header.path) | |
707 | |
708 imports(header) | |
709 cftypes(header) | |
710 externs(header) | |
711 constants(header) | |
712 enums(header) | |
713 structs(header) | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
714 structs2(header) |
1 | 715 typedefs(header) |
716 functions(header) | |
717 functions(header, true) | |
718 defines(header) | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
719 classes(header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
720 protocols(header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
721 #informal_protocols(header) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
722 categories(header) |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
723 function_pointers(header) |
1 | 724 end |
725 end | |
726 | |
727 def get_var_info (str, multi = false) | |
728 str.strip! | |
729 | |
730 return nil if str.empty? | |
731 | |
732 if str == "..." | |
733 VarInfo.new("...", "...", str) | |
734 else | |
735 str = "***dummy*** " + str if str[-1].chr == '*' || str.index(/\s/).nil? | |
736 tokens = multi ? str.split(',') : [str] | |
737 part = tokens.first | |
738 re = /^([^()]*)\b(\w+)\b\s*(\[[^\]]*\])*$/ | |
739 m = re.match(part) | |
740 | |
741 if m | |
742 return nil if m[1].split(/\s+/).any? do |x| | |
743 ['end', 'typedef'].include?(x) | |
744 end | |
745 | |
746 m = m.to_a[1..-1].compact.map do |i| | |
747 i.strip | |
748 end | |
749 | |
750 m[0] += m[2] if m.size == 3 | |
751 m[0] = 'void' if m[1] == 'void' | |
752 | |
753 var = begin | |
754 VarInfo.new(m[0], m[1], part) | |
755 rescue | |
756 return nil | |
757 end | |
758 | |
759 if tokens.size > 1 | |
760 [var, *tokens[1..-1].map { |x| constant?(m[0] + x.strip.sub(/^\*+/, '')) }] | |
761 else | |
762 var | |
763 end | |
764 end | |
765 end | |
766 end | |
767 | |
768 def constant? (str, multi = false) | |
769 str.strip! | |
770 return nil if str.empty? | |
771 | |
772 if str == '...' | |
773 VarInfo.new('...', '...', str) | |
774 else | |
775 str << " dummy" if str[-1].chr == '*' or str.index(/\s/).nil? | |
776 tokens = multi ? str.split(',') : [str] | |
777 part = tokens.first | |
778 re = /^([^()]*)\b(\w+)\b\s*(\[[^\]]*\])*$/ | |
779 m = re.match(part) | |
780 | |
781 if m | |
782 return nil if m[1].split(/\s+/).any? do |x| | |
783 ['end', 'typedef'].include?(x) | |
784 end | |
785 | |
786 m = m.to_a[1..-1].compact.map do |i| | |
787 i.strip | |
788 end | |
789 | |
790 m[0] += m[2] if m.size == 3 | |
791 m[0] = 'void' if m[1] == 'void' | |
792 | |
793 var = begin | |
794 VarInfo.new(m[0], m[1], part) | |
795 rescue | |
796 return nil | |
797 end | |
798 | |
799 if tokens.size > 1 | |
800 [var, *tokens[1..-1].map { |x| constant?(m[0] + x.strip.sub(/^\*+/, '')) }] | |
801 else | |
802 var | |
803 end | |
804 end | |
805 end | |
806 end | |
807 | |
808 class VarInfo | |
809 | |
810 attr_reader :name, :orig, :const, :type_modifier | |
811 attr_accessor :octype, :resolved_type, :resolved_type64, :return_type, :stripped_return_type | |
812 | |
813 def initialize (type, name, orig) | |
814 @return_type = type.clone | |
815 @name = name | |
816 @orig = orig | |
817 @const = false | |
818 @type_modifier = "" | |
819 | |
820 @return_type.gsub!(/\[[^\]]*\]/, "*") | |
821 | |
822 if @return_type =~ /\bconst\b/ | |
823 @const = true | |
824 @return_type.gsub!("const", "") | |
825 end | |
826 | |
827 if @return_type =~ /\b(in|out|inout|oneway|bycopy|byref)\b/ | |
828 | |
829 case $1 | |
830 when "in" | |
831 @type_modifier << "n" | |
832 when "out" | |
833 @type_modifier << "o" | |
834 when "inout" | |
835 @type_modifier << "N" | |
836 when "oneway" | |
837 @type_modifier << "w" | |
838 when "bycopy" | |
839 @type_modifier << "c" | |
840 when "byref" | |
841 @type_modifier << "r" | |
842 end | |
843 | |
844 @return_type.gsub!("#{$1}", "") | |
845 end | |
846 | |
847 @return_type.gsub!(/\s?\*\s?/, "*") | |
848 @return_type.gsub!(/^\(|\)$/, "") | |
849 @return_type.strip! | |
850 | |
851 t = type.gsub(/\b(__)?const\b/, "") | |
852 t.gsub!(/<[^>]*>/, '') | |
853 t.gsub!(/\b(in|out|inout|oneway|const)\b/, "") | |
854 t.gsub!(/\b__private_extern__\b/, "") | |
855 t.gsub!(/^\s*\(?\s*/, "") | |
856 t.gsub!(/\s*\)?\s*$/, "") | |
857 | |
858 raise "Empty type (was '#{type}')" if t.empty? | |
859 | |
860 @stripped_return_type = t | |
861 end | |
862 | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
863 # def function_pointer? (function_pointers) |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
864 # type = @function_pointers[@stripped_return_type] || @stripped_return_type |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
865 # @function_pointer ||= FunctionPointerInfo.new_from_type(type) |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
866 # end |
1 | 867 |
868 def <=>(x) | |
869 self.name <=> x.name | |
870 end | |
871 | |
872 def hash | |
873 @name.hash | |
874 end | |
875 | |
876 def eql? (o) | |
877 @name == o.name | |
878 end | |
879 end | |
880 | |
881 class FunctionInfo < VarInfo | |
882 | |
883 attr_reader :args, :argc | |
884 | |
885 def initialize (function, args, orig, inline = false) | |
886 super(function.return_type, function.name, orig) | |
887 | |
888 @args = args | |
889 @argc = @args.size | |
890 @variadic = false | |
891 | |
892 if @args[-1] && @args[-1].return_type == "..." | |
893 @argc -= 1 | |
894 @variadic = true | |
895 @args.pop | |
896 end | |
897 | |
898 @inline = inline | |
899 self | |
900 end | |
901 | |
902 def variadic? | |
903 @variadic | |
904 end | |
905 | |
906 def inline? | |
907 @inline | |
908 end | |
909 end | |
910 | |
911 class FunctionPointerInfo < FunctionInfo | |
912 def initialize (return_type, arg_types, orig) | |
913 args = arg_types.map do |x| | |
914 VarInfo.new(x, "", "") | |
915 end | |
916 | |
917 super(VarInfo.new(return_type, "", ""), args, orig) | |
918 end | |
919 | |
920 def self.new_from_type (type) | |
921 @cache ||= {} | |
922 info = @cache[type] | |
923 | |
924 return info if info | |
925 | |
926 tokens = type.split(/\(\*\)/) | |
927 return nil if tokens.size != 2 | |
928 | |
929 return_type = tokens.first.strip | |
930 rest = tokens.last.sub(/^\s*\(\s*/, "").sub(/\s*\)\s*$/, "") | |
931 | |
932 arg_types = rest.split(/,/).map do |x| | |
933 x.strip | |
934 end | |
935 | |
936 @cache[type] = self.new(return_type, arg_types, type) | |
937 end | |
938 end | |
939 | |
940 class MethodInfo < FunctionInfo | |
941 | |
942 attr_reader :selector | |
943 | |
944 def initialize (method, selector, is_class, args, orig) | |
945 super(method, args, orig) | |
946 | |
947 @selector = selector | |
948 @is_class = is_class | |
949 self | |
950 end | |
951 | |
952 def class_method? | |
953 @is_class | |
954 end | |
955 | |
956 def <=>(o) | |
957 @selector <=> o.selector | |
958 end | |
959 | |
960 def hash | |
961 @selector.hash | |
962 end | |
963 | |
964 def eql? (o) | |
965 @selector == o.selector | |
966 end | |
967 end | |
968 | |
969 def do_cpp (path, fails_on_error = true, do_64 = true, flags = "") | |
970 f_on = false | |
971 err_file = '/tmp/.cpp.err' | |
972 cpp_line = "#{CPP} #{CPPFLAGS} #{flags} #{do_64 ? '-D__LP64__' : ''} \"#{path}\" 2>#{err_file}" | |
973 complete_result = `#{cpp_line}` | |
974 | |
975 if $?.to_i != 0 && fails_on_error | |
976 $stderr.puts File.read(err_file) | |
977 File.unlink(err_file) | |
978 raise "#{CPP} returned #{$?.to_int/256} exit status\nline was: #{cpp_line}" | |
979 end | |
980 | |
981 result = complete_result.select do |s| | |
982 # First pass to only grab non-empty lines and the pre-processed lines | |
983 # only from the target header (and not the entire pre-processing result). | |
984 next if s.strip.empty? | |
985 m = %r{^#\s*\d+\s+"([^"]+)"}.match(s) | |
986 f_on = (File.basename(m[1]) == File.basename(path)) if m | |
987 f_on | |
988 end.select do |s| | |
989 # Second pass to ignore all pro-processor comments that were left. | |
990 /^#/.match(s) == nil | |
991 end.join | |
992 | |
993 File.unlink(err_file) | |
994 return [complete_result, result] | |
995 end | |
996 end | |
997 | |
998 class DStepGenerator | |
999 | |
1000 VERSION = 1.0 | |
1001 | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1002 attr_accessor :out_file, :scaner, :inject_path, :dependencies_switch, :options, :exclude, :frameworks_do_add |
1 | 1003 |
1004 def initialize | |
1005 @do_64bit = false | |
1006 @frameworks = [] | |
1007 @framework_paths = [] | |
1008 @headers = [] | |
1009 @import_directives = "#import <Foundation/Foundation.h>\n" | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1010 #@informal_protocols = [] |
1 | 1011 @classes = [] |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1012 @protocols = [] |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1013 @categories = [] |
1 | 1014 @scaner = HeaderScaner.new |
1015 @scaner.do_64bit = @do_64bit | |
1016 @umbrella_framework = nil | |
1017 @handled_dependencies = [] | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1018 @dependencies_switch = false |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1019 @options = [] |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1020 @extra = false |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1021 @exclude = [] |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1022 @frameworks_do_add = [] |
1 | 1023 |
1024 # link to foundation framework by default | |
1025 @compiler_flags = "-framework Foundation" | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1026 end |
1 | 1027 |
1028 def do_64bit | |
1029 return @do_64bit | |
1030 end | |
1031 | |
1032 def do_64bit= (do_64bit) | |
1033 @do_64bit = do_64bit | |
1034 @scaner.do_64bit = do_64bit | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1035 end |
1 | 1036 |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1037 def extra |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1038 @extra |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1039 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1040 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1041 def extra= (extra) |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1042 @extra = extra |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1043 @scaner.extra = extra |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1044 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1045 |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1046 def collect |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1047 @frameworks_do_add.each do |framework| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1048 add_framework(framework) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1049 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1050 |
1 | 1051 scaner.scan(@frameworks, @headers) |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1052 @classes = scaner.get_classes |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1053 @protocols = scaner.get_protocols |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1054 @categories = scaner.get_categories |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1055 #@informal_protocols = scaner.get_informal_protocols |
1 | 1056 end |
1057 | |
1058 def handle_framework (framework, sub_framework = false, parent_framework = nil) | |
1059 val = framework.name | |
1060 path = framework_path(val) | |
1061 | |
1062 raise "Can't locate framework '#{val}'" if path.nil? | |
1063 @framework_paths << File.dirname(path) | |
1064 raise "Can't find framework '#{val}'" if path.nil? | |
1065 | |
1066 parent_path, name = path.scan(/^(.+)\/(\w+)\.framework\/?$/)[0] | |
1067 | |
1068 if @private | |
1069 headers_path = File.join(path, "PrivateHeaders") | |
1070 raise "Can't locate private framework headers at '#{headers_path}'" unless File.exist?(headers_path) | |
1071 | |
1072 headers = Dir.glob(File.join(headers_path, "**", "*.h")) | |
1073 public_headers_path = File.join(path, "Headers") | |
1074 public_headers = if File.exist?(public_headers_path) | |
1075 HeaderScaner::CPPFLAGS << " -I#{public_headers_path} " | |
1076 Dir.glob(File.join8(headers_path, "**", "*.h")) | |
1077 else | |
1078 [] | |
1079 end | |
1080 else | |
1081 headers_path = File.join(path, "Headers") | |
1082 raise "Can't locate public framework headers at '#{headers_path}'" unless File.exist?(headers_path) | |
1083 public_headers = headers = Dir.glob(File.join(headers_path, "**", "*.h")) | |
1084 end | |
1085 | |
1086 # We can't just "#import <x/x.h>" as the main Framework header might not include _all_ headers. | |
1087 # So we are tricking this by importing the main header first, then all headers. | |
1088 header_basenames = (headers | public_headers).map do |x| | |
1089 x.sub(/#{headers_path}\/*/, "") | |
1090 end | |
1091 | |
1092 if idx = header_basenames.index("#{name}.h") | |
1093 header_basenames.delete_at(idx) | |
1094 header_basenames.unshift("#{name}.h") | |
1095 end | |
1096 | |
1097 if sub_framework | |
1098 pp = framework_path(parent_framework.name) | |
1099 tmp, pname = pp.scan(/^(.+)\/(\w+)\.framework\/?$/)[0] | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1100 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1101 exclude = false |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1102 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1103 @exclude.each do |e| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1104 exclude = true if pname =~ /#{e}/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1105 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1106 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1107 header_path = "#{pp}/Frameworks/#{name}.framework/Headers/#{name}.h" |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1108 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1109 @import_directives << '#import "' + header_path + '"' if File.exist?(header_path) && !exclude |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1110 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1111 exclude = false |
1 | 1112 else |
1113 @import_directives << header_basenames.map do |x| | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1114 exclude = false |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1115 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1116 @exclude.each do |e| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1117 exclude = true if x =~ /#{e}/ |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1118 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1119 |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1120 next if exclude |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1121 |
1 | 1122 "#import <#{name}/#{x}>" |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1123 end.join("\n") |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1124 end |
1 | 1125 |
1126 @import_directives << "\n" | |
1127 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1128 @compiler_flags << " -F\"#{parent_path}\" -framework #{name}" unless sub_framework?(framework.name) |
1 | 1129 @cpp_flags ||= "" |
1130 @cpp_flags << "-F\"#{parent_path}\" " | |
1131 | |
1132 headers.each do |header| | |
1133 header_file = HeaderFile.new | |
1134 header_file.path = header | |
1135 header_file.name = File.basename(header, File.extname(header)) | |
1136 header_file.framework = framework.name | |
1137 | |
1138 framework.headers << header_file | |
1139 end | |
1140 | |
1141 # Memorize the dependencies. | |
1142 @dependencies = DStepGenerator.dependencies_of_framework(path) | |
1143 handle_sub_frameworks(framework) | |
1144 end | |
1145 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1146 def sub_framework? (framework) |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1147 i = framework.index("framework") |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1148 return false if i.nil? |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1149 !framework.index("framework", i + 1).nil? |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1150 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1151 |
1 | 1152 def handle_sub_frameworks (framework) |
1153 path = framework_path(framework.name) | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1154 @compiler_flags << " -B #{path}/Headers/ " |
1 | 1155 frameworks_path = File.join(path, "Frameworks") |
1156 frameworks = Dir.glob(File.join(frameworks_path, "*.framework")) | |
1157 | |
1158 frameworks.each do |f| | |
1159 add_framework(f, true, framework) | |
1160 end | |
1161 end | |
1162 | |
1163 def framework_path (val) | |
1164 return val if File.exist?(val) | |
1165 | |
1166 val += ".framework" unless /\.framework$/.match(val) | |
1167 paths = ["/System/Library/Frameworks", "/Library/Frameworks", "#{ENV['HOME']}/Library/Frameworks"] | |
1168 paths << "/System/Library/PrivateFrameworks" if @private | |
1169 | |
1170 paths.each do |dir| | |
1171 path = File.join(dir, val) | |
1172 return path if File.exist?(path) | |
1173 end | |
1174 | |
1175 return nil | |
1176 end | |
1177 | |
1178 def umbrella_framework (val) | |
1179 | |
1180 unless val == "" || val.nil? | |
1181 @umbrella_framework = val | |
1182 | |
1183 unless @compiler_flags.nil? || @compiler_flags == "" | |
1184 i = @compiler_flags.index("-framework") | |
1185 @compiler_flags = @compiler_flags[0 .. i - 1] + "-framework #{val}" | |
1186 else | |
1187 @compiler_flags = "-framework #{val}" | |
1188 end | |
1189 end | |
1190 end | |
1191 | |
1192 def self.dependencies_of_framework (path) | |
1193 @dependencies ||= {} | |
1194 name = File.basename(path, ".framework") | |
1195 path = File.join(path, name) | |
1196 deps = @dependencies[path] | |
1197 | |
1198 if deps.nil? | |
1199 deps = `otool -L "#{path}"`.scan(/\t([^\s]+)/).map do |m| | |
1200 dpath = m[0] | |
1201 next if File.basename(dpath) == name | |
1202 next if dpath.include?("PrivateFrameworks") | |
1203 next unless dpath.sub!(/\.framework\/Versions\/\w+\/\w+$/, "") | |
1204 dpath + ".framework" | |
1205 end.compact | |
1206 | |
1207 @dependencies[path] = deps | |
1208 end | |
1209 | |
1210 return deps | |
1211 end | |
1212 | |
1213 def compile_and_execute (code, enable_64bit = false, clean_when_fail = false) | |
1214 compiler_line = "gcc " | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1215 src = File.new(unique_tmp_path("src", ".m"), "w") |
1 | 1216 src << code |
1217 src.close | |
1218 | |
1219 arch_flag = if enable_64bit | |
1220 "-arch x86_64 -arch ppc64" | |
1221 else | |
1222 "-arch i386 -arch ppc" | |
1223 end | |
1224 | |
1225 compiler_line << arch_flag | |
1226 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1227 bin = unique_tmp_path "bin", "" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1228 log = unique_tmp_path "log", ".txt" |
1 | 1229 |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1230 @options.each do |option| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1231 @compiler_flags << " #{option} " |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1232 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1233 |
1 | 1234 line = "#{compiler_line} -o #{bin} #{src.path} #{@compiler_flags} 2>#{log}" |
1235 | |
1236 unless system(line) | |
1237 msg = "Cannot compile Objective-C code ...aborting\nCommand was: #{line}\n\nLog:\n#{File.read(log)}\n\n" | |
1238 $stderr << msg | |
1239 File.delete src.path if clean_when_fail | |
1240 raise msg | |
1241 end | |
1242 | |
1243 result = `#{bin}` | |
1244 | |
1245 unless $?.success? | |
1246 raise "Cannot execute compiled Objective-C code ... aborting\nCommand was: #{line}\nBinary is: #{bin}" | |
1247 end | |
1248 | |
1249 File.delete bin | |
1250 File.delete log | |
1251 File.delete src.path | |
1252 | |
1253 return result | |
1254 end | |
1255 | |
1256 def unique_tmp_path (base, extension = "", dir = Dir.tmpdir) | |
1257 i = 0 | |
1258 loop do | |
1259 path = File.join(dir, "#{base}-#{Process.pid}-#{i}#{extension}") | |
1260 return path unless File.exists?(path) | |
1261 i += 1 | |
1262 end | |
1263 end | |
1264 | |
1265 def add_header (path) | |
1266 header = HeaderFile.new | |
1267 header.path = path | |
1268 header.name = File.basename(path, File.extname(path)) | |
1269 @import_directives << "#include <#{path}>\n" | |
1270 @headers << header | |
1271 end | |
1272 | |
1273 def add_framework (name, sub_framework = false, parent_framework = nil) | |
1274 framework = Framework.new | |
1275 framework.name = name | |
1276 handle_framework(framework, sub_framework, parent_framework) | |
1277 #@import_directives << "#import <#{framework.name}/#{framework.name}.h>\n" | |
1278 @frameworks << framework | |
1279 end | |
1280 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1281 def collect_cftypes (header, enable_64bit) |
1 | 1282 types = [] |
1283 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1284 header.cftypes.each do |cftype| |
1 | 1285 types << cftype[:type] |
1286 end | |
1287 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1288 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1289 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1290 header.cftypes.each_with_index do |cftype, i| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1291 cftype[enable_64bit ? :type64 : :type] = resolved_types[i] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1292 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1293 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1294 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1295 def collect_constants (header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1296 types = [] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1297 |
1 | 1298 header.constants.each do |constant| |
1299 types << constant.stripped_return_type | |
1300 end | |
1301 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1302 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1303 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1304 header.constants.each_with_index do |constant, i| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1305 constant.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1306 constant.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1307 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1308 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1309 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1310 def collect_structs (header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1311 types = [] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1312 |
1 | 1313 header.structs.each do |struct| |
1314 types << struct[:name] | |
1315 | |
1316 struct[:members].each do |member| | |
1317 types << member[:declaredType] | |
1318 end | |
1319 end | |
1320 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1321 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1322 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1323 i = 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1324 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1325 header.structs.each do |struct| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1326 struct[enable_64bit ? :type64 : :type] = resolved_types[i] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1327 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1328 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1329 struct[:members].each do |member| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1330 member[enable_64bit ? :type64 : :type] = resolved_types[i] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1331 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1332 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1333 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1334 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1335 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1336 def collect_typedefs (header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1337 types = [] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1338 |
1 | 1339 header.typedefs.each do |typedef| |
1340 types << typedef.stripped_return_type | |
1341 end | |
1342 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1343 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1344 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1345 header.typedefs.each_with_index do |typedef, i| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1346 typedef.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1347 typedef.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1348 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1349 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1350 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1351 def collect_functions (header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1352 types = [] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1353 |
1 | 1354 header.functions.each do |function| |
1355 types << function.stripped_return_type | |
1356 | |
1357 function.args.each do |arg| | |
1358 types << arg.stripped_return_type | |
1359 end | |
1360 end | |
1361 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1362 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1363 i = 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1364 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1365 header.functions.each do |function| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1366 function.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1367 function.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1368 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1369 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1370 function.args.each do |arg| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1371 arg.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1372 arg.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1373 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1374 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1375 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1376 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1377 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1378 def collect_functions_pointers (header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1379 types = [] |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1380 |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1381 header.function_pointers.each do |fp, value| |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1382 types << value.return_type |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1383 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1384 value.args.each do |arg| |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1385 types << arg.type |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1386 end unless value.args.nil? |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1387 end |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1388 |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1389 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1390 i = 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1391 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1392 header.function_pointers.each do |fp, value| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1393 value.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1394 value.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1395 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1396 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1397 value.args.each do |arg| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1398 arg.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1399 arg.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1400 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1401 end unless value.args.nil? |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1402 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1403 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1404 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1405 def collect_header_types (header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1406 collect_cftypes(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1407 collect_constants(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1408 collect_structs(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1409 collect_typedefs(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1410 collect_functions(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1411 collect_functions_pointers(header, enable_64bit) |
1 | 1412 end |
1413 | |
1414 def collect_classes_types (enable_64bit) | |
1415 types = [] | |
1416 | |
1417 @classes.each do |clazz, value| | |
1418 value.methods.each do |method| | |
1419 types << method.stripped_return_type | |
1420 | |
1421 method.args.each do |arg| | |
1422 types << arg.stripped_return_type | |
1423 end | |
1424 end | |
1425 end | |
1426 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1427 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1428 i = 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1429 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1430 @classes.each do |clazz, value| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1431 value.methods.each do |method| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1432 method.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1433 method.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1434 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1435 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1436 method.args.each do |arg| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1437 arg.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1438 arg.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1439 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1440 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1441 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1442 end |
1 | 1443 end |
1444 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1445 def collect_protocols_types (enable_64bit) |
1 | 1446 types = [] |
1447 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1448 @protocols.each do |protocol, value| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1449 value.methods.each do |method| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1450 types << method.stripped_return_type |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1451 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1452 method.args.each do |arg| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1453 types << arg.stripped_return_type |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1454 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1455 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1456 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1457 |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1458 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1459 i = 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1460 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1461 @protocols.each do |protocol, value| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1462 value.methods.each do |method| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1463 method.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1464 method.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1465 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1466 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1467 method.args.each do |arg| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1468 arg.resolved_type = resolved_types[i] unless enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1469 arg.resolved_type64 = resolved_types[i] if enable_64bit |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1470 i += 1 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1471 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1472 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1473 end |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1474 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1475 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1476 def collect_categories_types (enable_64bit) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1477 types = [] |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1478 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1479 @categories.each do |category, value| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1480 value.methods.each do |method| |
1 | 1481 types << method.stripped_return_type |
1482 | |
1483 method.args.each do |arg| | |
1484 types << arg.stripped_return_type | |
1485 end | |
1486 end | |
1487 end | |
1488 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1489 resolved_types = resolve_types_helper(types, enable_64bit) if types.length > 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1490 i = 0 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1491 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1492 @categories.each do |category, value| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1493 value.methods.each do |method| |
1 | 1494 method.resolved_type = resolved_types[i] unless enable_64bit |
1495 method.resolved_type64 = resolved_types[i] if enable_64bit | |
1496 i += 1 | |
1497 | |
1498 method.args.each do |arg| | |
1499 arg.resolved_type = resolved_types[i] unless enable_64bit | |
1500 arg.resolved_type64 = resolved_types[i] if enable_64bit | |
1501 i += 1 | |
1502 end | |
1503 end | |
1504 end | |
1505 end | |
1506 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1507 def get_framework_name (framework) |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1508 i = framework.rindex(".framework") |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1509 return framework if i.nil? |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1510 x = framework.rindex("/", i) |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1511 framework[x + 1 ... i] |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1512 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1513 |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1514 def resolve_types (enable_64bit = false) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1515 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1516 @frameworks.each do |framework| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1517 framework.headers.each do |header| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1518 collect_header_types(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1519 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1520 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1521 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1522 @headers.each do |header| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1523 collect_header_types(header, enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1524 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1525 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1526 collect_classes_types(enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1527 collect_protocols_types(enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1528 collect_categories_types(enable_64bit) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1529 end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1530 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1531 def resolve_types_helper (types, enable_64bit) |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1532 code = "#include <stdio.h>\n" |
1 | 1533 code << @import_directives |
1534 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1535 @frameworks.each do |framework| |
1 | 1536 framework.headers.each do |header| |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1537 exclude = false |
1 | 1538 |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1539 @exclude.each do |e| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1540 exclude = true if e =~ header.name |
1 | 1541 end |
1542 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1543 if framework.name[0, 1] == "/" |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1544 code << "#import \"#{framework.name}/Headers/#{header.name}.h\"\n" unless header.name == "xmmintrin" |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1545 else |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1546 code << "#import <#{framework.name}/#{header.name}.h>\n" unless header.name == "xmmintrin" |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1547 end unless exclude |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1548 |
1 | 1549 types << collect_header_types(header, enable_64bit) |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1550 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1551 exclude = false |
1 | 1552 end |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1553 end if @extra |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1554 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1555 @headers.each do |header| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1556 exclude = false |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1557 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1558 @exclude.each do |e| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1559 exclude = true if e =~ header.name |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1560 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1561 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1562 code << "#import <#{header.name}.h>\n" unless exclude || header.name == "xmmintrin" |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1563 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1564 exclude = false |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1565 end if @extra |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1566 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1567 File.foreach(@inject_path) do |line| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1568 code << line |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1569 end if !@inject_path.nil? && File.exist?(@inject_path) |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1570 |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1571 code << "\n\n" |
1 | 1572 code << "int main ()\n{\n" |
1573 types.flatten! | |
1574 | |
1575 types.each do |type| | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1576 code << ' printf("%s\n", ' + "@encode(__typeof__(#{type})));\n" unless type.nil? || type.length == 0 |
1 | 1577 end |
1578 | |
1579 code << " return 0;\n}" | |
1580 | |
1581 resolved_types = [] | |
1582 | |
1583 compile_and_execute(code, enable_64bit).split("\n").each do |line| | |
1584 resolved_types << line | |
1585 end | |
1586 | |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1587 resolved_types |
1 | 1588 |
7
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1589 # i = 0 |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1590 # |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1591 # @frameworks.each do |framework| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1592 # framework.headers.each do |header| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1593 # i = resolve_header_types(header, enable_64bit, resolved_types, i) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1594 # end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1595 # end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1596 # |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1597 # @headers.each do |header| |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1598 # i = resolve_header_types(header, enable_64bit, resolved_types, i) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1599 # end |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1600 # |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1601 # i = resolve_classes_types(enable_64bit, resolved_types, i) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1602 # i = resolve_protocols_types(enable_64bit, resolved_types, i) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1603 # #i = resolve_informal_protocols_types(enable_64bit, resolved_types, i) |
9e67a1122e85
Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
1604 # i = resolve_categories_types(enable_64bit, resolved_types, i) |
1 | 1605 end |
1606 | |
1607 def generate_header (xml, header) | |
1608 xml.file :name => header.name do | |
1609 header.imports.each do |import| | |
1610 xml.import import | |
1611 end | |
1612 | |
1613 header.defines.each do |define| | |
1614 xml.define define | |
1615 end | |
1616 | |
1617 header.cftypes.each do |cftype| | |
1618 xml.cftype cftype | |
1619 end | |
1620 | |
1621 header.constants.each do |constant| | |
1622 xml.constant :name => constant.name, :declaredType => constant.return_type, :type => constant.resolved_type, :type64 => constant.resolved_type64, :const => constant.const | |
1623 end | |
1624 | |
1625 header.enums.each do |enum| | |
1626 xml.enum :name => enum[:name] do | |
1627 enum[:members].each do |member| | |
1628 xml.member member | |
1629 end | |
1630 end | |
1631 end | |
1632 | |
1633 header.structs.each do |struct| | |
1634 xml.struct :name => struct[:name], :type => struct[:type], :type64 => struct[:type64] do | |
1635 struct[:members].each do |member| | |
1636 xml.member member | |
1637 end | |
1638 end | |
1639 end | |
1640 | |
1641 header.typedefs.each do |typedef| | |
1642 xml.typedef :name => typedef.name, :declaredType => typedef.return_type, :type => typedef.resolved_type, :type64 => typedef.resolved_type64, :const => typedef.const | |
1643 end | |
1644 | |
1645 header.functions.each do |function| | |
1646 xml.function :name => function.name, :inline => function.inline?, :variadic => function.variadic? do | |
1647 function.args.each do |arg| | |
1648 xml.arg :name => arg.name, :declaredType => arg.return_type, :type => arg.resolved_type, :type64 => arg.resolved_type64, :const => arg.const, :typeModifier => arg.type_modifier | |
1649 end | |
1650 | |
1651 xml.returnValue :declaredType => function.return_type, :type => function.resolved_type, :type64 => function.resolved_type64, :const => function.const, :typeModifier => function.type_modifier | |
1652 end | |
1653 end | |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1654 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1655 header.function_pointers.each do |fp, value| |
4
5a1a6afbfe3a
Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
1656 xml.functionPointer :name => fp, :variadic => value.variadic do |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1657 value.args.each do |arg| |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1658 xml.arg :declaredType => arg.type, :type => arg.resolved_type, :type64 => arg.resolved_type64, :const => arg.const |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1659 end unless value.args.nil? |
3
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1660 |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1661 xml.returnValue :declaredType => value.return_type, :type => value.resolved_type, :type64 => value.resolved_type64, :const => value.const |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1662 end |
d0162d8ca0f2
Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
1663 end |
1 | 1664 end |
1665 end | |
1666 | |
1667 def generate_classes (xml) | |
1668 @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
|
1669 xml.class :name => clazz, :parent => value.parent, :protocols => value.protocols, :file => value.file do |
1 | 1670 value.methods.each do |method| |
1671 xml.method :selector => method.selector, :classMethod => method.class_method?, :variadic => method.variadic? do | |
1672 method.args.each do |arg| | |
1673 xml.arg :name => arg.name, :declaredType => arg.return_type, :type => arg.resolved_type, :type64 => arg.resolved_type64, :const => arg.const, :typeModifier => arg.type_modifier | |
1674 end | |
1675 | |
1676 xml.returnValue :declaredType => method.return_type, :type => method.resolved_type, :type64 => method.resolved_type64, :const => method.const, :typeModifier => method.type_modifier | |
1677 end | |
1678 end | |
1679 end | |
1680 end | |
1681 end | |
1682 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1683 def generate_protocols (xml) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1684 @protocols.each do |protocol, value| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1685 xml.protocol :name => protocol, :parent => value.parent, :protocols => value.protocols, :file => value.file do |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1686 value.methods.each do |method| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1687 xml.method :selector => method.selector, :classMethod => method.class_method?, :variadic => method.variadic? do |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1688 method.args.each do |arg| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1689 xml.arg :name => arg.name, :declaredType => arg.return_type, :type => arg.resolved_type, :type64 => arg.resolved_type64, :const => arg.const, :typeModifier => arg.type_modifier |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1690 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1691 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1692 xml.returnValue :declaredType => method.return_type, :type => method.resolved_type, :type64 => method.resolved_type64, :const => method.const, :typeModifier => method.type_modifier |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1693 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1694 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1695 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1696 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1697 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1698 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1699 # def generate_informal_protocols (xml) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1700 # @informal_protocols.each do |name, methods| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1701 # xml.informalProtocol :name => name do |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1702 # methods.each do |method| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1703 # xml.method :selector => method.selector, :classMethod => method.class_method?, :variadic => method.variadic? do |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1704 # method.args.each do |arg| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1705 # xml.arg :name => arg.name, :declaredType => arg.return_type, :type => arg.resolved_type, :type64 => arg.resolved_type64, :const => arg.const, :typeModifier => arg.type_modifier |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1706 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1707 # |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1708 # xml.returnValue :declaredType => method.return_type, :type => method.resolved_type, :type64 => method.resolved_type64, :const => method.const, :typeModifier => method.type_modifier |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1709 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1710 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1711 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1712 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1713 # end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1714 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1715 def generate_categories (xml) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1716 @categories.each do |category, value| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1717 xml.category :name => category.name, :class => category.class, :parent => value.parent, :protocols => value.protocols, :file => value.file do |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1718 value.methods.each do |method| |
1 | 1719 xml.method :selector => method.selector, :classMethod => method.class_method?, :variadic => method.variadic? do |
1720 method.args.each do |arg| | |
1721 xml.arg :name => arg.name, :declaredType => arg.return_type, :type => arg.resolved_type, :type64 => arg.resolved_type64, :const => arg.const, :typeModifier => arg.type_modifier | |
1722 end | |
1723 | |
1724 xml.returnValue :declaredType => method.return_type, :type => method.resolved_type, :type64 => method.resolved_type64, :const => method.const, :typeModifier => method.type_modifier | |
1725 end | |
1726 end | |
1727 end | |
1728 end | |
1729 end | |
1730 | |
1731 def generate | |
1732 resolve_types | |
1733 resolve_types(true) if @do_64bit | |
1734 | |
1735 file = STDOUT if @out_file == nil | |
1736 file = File.open @out_file, "w" unless @out_file == nil | |
1737 | |
1738 xml = XmlMarkup.new(:target => file, :indent => 4) | |
1739 xml.instruct! | |
1740 | |
1741 xml.dstep :xmlns => "http://www.dsource.org/projects/dstep", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://www.dsource.org/projects/dstep/trunk/scripts/dstep.xsd" do | |
1742 @frameworks.each do |framework| | |
1743 xml.framework :name => framework.name do | |
1744 framework.headers.each do |header| | |
1745 generate_header(xml, header) | |
1746 end | |
1747 end | |
1748 end | |
1749 | |
1750 @headers.each do |header| | |
1751 generate_header(xml, header) | |
1752 end | |
1753 | |
1754 generate_classes(xml) | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1755 generate_protocols(xml) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1756 #generate_informal_protocols(xml) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1757 generate_categories(xml) |
1 | 1758 end |
1759 | |
1760 file.close unless file == STDOUT | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1761 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1762 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1763 def write_dependencies |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1764 @frameworks_do_add.each do |framework| |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1765 add_framework(framework) |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1766 end |
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1767 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1768 file = STDOUT if @out_file == nil |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1769 file = File.open @out_file, "w" unless @out_file == nil |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1770 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1771 @dependencies.each do |dep| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1772 file << dep + "\n" |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1773 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1774 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1775 file.close unless file == STDOUT |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1776 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1777 exit 0 |
1 | 1778 end |
1779 end | |
1780 | |
1781 def die (*msg) | |
1782 $stderr.puts msg | |
1783 exit 1 | |
1784 end | |
1785 | |
1786 if __FILE__ == $0 | |
1787 dstep_gen = DStepGenerator.new | |
1788 | |
1789 OptionParser.new do |opts| | |
1790 opts.banner = "Usage: #{File.basename(__FILE__)} [options] <headers...>" | |
1791 opts.separator "" | |
1792 opts.separator "Options:" | |
1793 | |
1794 opts.on("-f", "--framework FRAMEWORK", "Generate metadata for the given framework.") do |opt| | |
11
07194b026fa4
Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents:
7
diff
changeset
|
1795 dstep_gen.frameworks_do_add << opt |
1 | 1796 end |
1797 | |
1798 opts.on("-u", "--umbrella FRAMEWORK", "Link againts the given umbrella framework.") do |opt| | |
1799 dstep_gen.umbrella_framework(opt) | |
1800 end | |
1801 | |
1802 opts.on(nil, "--64-bit", "Write 64-bit annotations.") do | |
1803 dstep_gen.do_64bit = true | |
1804 end | |
1805 | |
1806 opts.on("-o", "--output FILE", "Write output to the given file.") do |opt| | |
1807 die "Output file can't be specified more than once" if dstep_gen.out_file | |
1808 dstep_gen.out_file = opt | |
1809 end | |
1810 | |
1811 # opts.on("-d", "--output-dir PATH", "Write ouptut to the given paht, use this with the --framework option") do |opt| | |
1812 # die "Output directory can't be specified more than once" if dstep_gen.out_dir | |
1813 # dstep_gen.out_dir = opt | |
1814 # end | |
1815 | |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1816 opts.on("-c", "--code FILE", "The path to a file with code to inject") do |opt| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1817 dstep_gen.inject_path = opt |
1 | 1818 end |
1819 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1820 opts.on("-d", "--dependencies", "Write framework dependencies and exit") do |opt| |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1821 dstep_gen.dependencies_switch = true |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1822 end |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1823 |
6
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1824 opts.on("-s", "--option OPTION", "Pass OPTION to the compiler") do |opt| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1825 dstep_gen.options << opt |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1826 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1827 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1828 opts.on("-e", "--extra", "Included extra headers headers") do |opt| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1829 dstep_gen.extra = true |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1830 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1831 |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1832 opts.on("-x", "--exclude HEADER", "Exlude the given header file") do |opt| |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1833 dstep_gen.exclude << opt |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1834 end |
c0cfd40362ee
Fixed the bridge to work with ldc and dmd. Added a couple of hooks to manipulate the source code
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
1835 |
1 | 1836 help_msg = "Use the `-h' flag or for help." |
1837 | |
1838 opts.on("-h", "--help", "Show this message.") do | |
1839 puts opts, help_msg | |
1840 exit | |
1841 end | |
1842 | |
1843 opts.on('-v', '--version', 'Show version.') do | |
1844 puts DStepGenerator::VERSION | |
1845 exit | |
1846 end | |
1847 | |
1848 opts.separator "" | |
1849 | |
1850 if ARGV.empty? | |
1851 die opts.banner | |
1852 else | |
1853 #begin | |
1854 opts.parse!(ARGV) | |
1855 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1856 dstep_gen.write_dependencies if dstep_gen.dependencies_switch |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1857 |
1 | 1858 ARGV.each do |header| |
1859 dstep_gen.add_header(header) | |
1860 end | |
1861 | |
1862 dstep_gen.collect | |
1863 dstep_gen.generate | |
1864 # rescue => e | |
1865 # msg = e.message | |
1866 # msg = "Internal error" if msg.empty? | |
1867 # | |
1868 # die msg, opts.banner, help_msg | |
1869 # end | |
1870 end | |
1871 end | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
1872 end |