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