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