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