annotate scripts/dgen.rb @ 15:7ff919f595d5

Added the Foundation framework, again
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:31:48 +0200
parents 4f583f7e242e
children 19885b43130e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 #!/usr/bin/env ruby
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 ##
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
4 # Copyright:: Copyright (c) 2009 Jacob Carlborg.
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 # Author:: Jacob Carlborg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 # Version:: Initial created: 2009
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 # License:: [Boost Software License 1.0]http://www.boost.org/LICENSE_1_0.txt
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 require "rubygems"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11 gem "xml-simple"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 require "xmlsimple"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 require "optparse"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
14 require "date"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 # Extensions to String
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17 class String
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 # Passes each character to the supplied block
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22 # "str".each_char { |c| puts c }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 # s
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 # t
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 # r
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28 def each_char
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 if block_given?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 scan(/./m) do |x|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 yield x
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 scan(/./m)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38 # Indents the string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 # levels:: how many levels/tabs to indent
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 # "str".indent #=> str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43 # "str".indent(3) #=> str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 def indent (levels = 1)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 "\t" * levels << self
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 # Appends a semicolon and a newline character on the string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 # semicolon:: should a semicolon be appended
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53 # "str".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 # "str".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 # str;
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 # str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61 def nl (semicolon = true)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 if semicolon
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 if self[-1, 1] == "{" || self[-1, 1] == "}"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64 self << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
65 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 self << ";\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 self << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 # Returns the index of the given character or length of the string if not found
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74 # char:: the character to look for
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 # start:: the index where to start the search
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
77 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
78 # "012345789".index_of("1") #=> 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
79 # "0123 0123".index_of("3", 6) #=> 8
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81 def index_of (char, start = 0)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
82 return self.length if start >= self.length
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84 i = 0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
85
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
86 if start == 0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 self.each_char do |c|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
88 return i if char == c
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 i += 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
91 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92 self[start + 1 .. -1].each_char do |c|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
93 return i + start + 1 if char == c
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 i += 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98 return self.length
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 # Returns true if the string is an Objective-C struct
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
102 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 # "{?=ii}".struct? #=> true
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
106 def struct?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 self =~ /\{/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 # Extensions that adds support for member access syntax
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112 class Hash
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 def type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 result = self["type"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 self[:type]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 def type= (type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120 self[:type] = type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123 def id
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 result = self["id"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 self[:id]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 def id= (id)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 self[:id] = id
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
131 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
132
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
133 def methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134 result = self["methods"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
136 self[:methods]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139 def methods= (methods)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 self[:methods] = methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 def method
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144 result = self["method"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
145 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 self[:method]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 def method= (method)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 self[:method] = method
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 def method_missing (method, *args)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 self.class.instance_eval do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 define_method(method) do |*args|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156 if args.length > 0
3
d0162d8ca0f2 Added support for function pointers in dstepgen
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
157 #self[method[0 ... -1]] = args[0]
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 self[eval(":#{method}"[0 ... -1])] = args[0]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 result = self[method]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161 return result unless result.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162 self[eval(":#{method}")]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167 if (method = method.id2name) =~ /=/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 eval("self.#{method} (args.length < 2 ? args[0] : args)")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 eval("self.#{method}")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 # This Struct represents an Objective-C Framework
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 Framework = Struct.new(:name, :files) do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177 def initialize
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 self.files = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 self.name = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
183 # This Struct represents a C/Objective-C header
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
184 HeaderFile = Struct.new(:name, :framework, :cftypes, :constants, :c_constants, :d_constants, :d_constants_static_this, :defines,
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
185 :enums, :enums_gnu, :needs_type_encoding, :functions, :c_functions, :function_pointers, :function_wrappers, :imports, :path, :structs, :typedefs) do
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 def initialize
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187 self.name = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188 self.cftypes = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 self.constants = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190 self.defines = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 self.enums = []
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
192 self.enums_gnu = []
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
193 self.needs_type_encoding = false
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194 self.framework = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195 self.functions = []
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
196 self.c_functions = []
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
197 self.function_pointers = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 self.function_wrappers = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 self.imports = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200 self.path = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 self.structs = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 self.typedefs = []
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
203 self.d_constants_static_this = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 # Performs the conversion of an xml metadata file to the D programming language
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 class ObjcToD
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 FIRST_YEAR = "2009"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210 VERSION = 1.0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212 attr_accessor :out_dir, :files
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214 # Creates a new instance of the ObjcToD class
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 def initialize
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 @classes = {}
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
217 @interfaces = {}
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
218 @interfaces2 = []
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
219 @templates = {}
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 @copyright = nil
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
221 @c_constants = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
222 @d_constants = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223 @d_constants_static_this = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
224 @files = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 @frameworks = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 @function_wrappers = []
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
227 @c_functions = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228 @headers = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 @package = "dstep"
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
230 @needs_bridge = false
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233 # Generates the D code from the xml metadata
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 def generate_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 @files.each do |dstep_file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236 xml = XmlSimple.xml_in(dstep_file)
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
237
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
238 @needs_bridge = !xml.protocol.nil? || !xml.category.nil? || !xml["class"].nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
239
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
240 interfaces(xml.protocol) unless xml.protocol.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
241 templates(xml.category) unless xml.category.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
242 classes(xml["class"]) unless xml["class"].nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 unless xml.framework.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
245 frameworks = xml.framework
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
246
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
247 frameworks.each do |frame|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
248 framework = Framework.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
249 framework.name = frame.name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251 frame.file.each do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 header = HeaderFile.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 header.name = file.name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254 header.constants = constants(file.constant) unless file.constant.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
255 header.c_constants = c_constants unless file.constant.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256 header.d_constants = d_constants unless file.constant.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 header.d_constants_static_this = d_constants_static_this unless file.constant.nil?
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
258 header.enums, header.enums_gnu, header.needs_type_encoding = enums(file.enum, header.name) unless file.enum.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259 header.functions = functions(file.function) unless file.function.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
260 header.c_functions = c_functions unless file.function.nil?
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
261 header.function_pointers = function_pointers(file.functionPointer) unless file.functionPointer.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
262 header.function_wrappers = function_wrappers unless file.function.nil?
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
263 header.imports = imports(header, file.import, file.name, framework.name) unless file.import.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
264 header.structs = structs(file.struct) unless file.struct.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
265
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
266 header.typedefs = typedefs(file.typedef) unless file.typedef.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268 framework.files << header
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 @frameworks << framework
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
272 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 unless xml.file.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
276 files = xml.file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278 files.each do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 header = HeaderFile.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 header.name = file.name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281 header.constants = constants(file.constant) unless file.constant.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
282 header.c_constants = c_constants unless file.constant.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 header.d_constants = d_constants unless file.constant.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
284 header.d_constants_static_this = d_constants_static_this unless file.constant.nil?
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
285 header.enums, header.enums_gnu, header.needs_type_encoding = enums(file.enum) unless file.enum.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286 header.functions = functions(file.function) unless file.function.nil?
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
287 header.function_pointers = function_pointers(file.functionPointer) unless file.functionPointer.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
288 header.c_functions = c_functions unless file.function.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 header.function_wrappers = function_wrappers unless file.function.nil?
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
290 header.imports = imports(header, file.import, file.name) unless file.import.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291 header.structs = structs(file.struct) unless file.struct.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 header.typedefs = typedefs(file.typedef) unless file.typedef.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 @headers << header
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
295 end
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
296 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300 # Outputs the generate D code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
301 def output_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302 @frameworks.each do |framework|
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
303 framework_path = framework_path = "#{@out_dir}/#{@package}/#{get_identifier(get_framework_name(framework.name.downcase))}" unless sub_framework?(framework.name.downcase)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
304 framework_path = framework_path = "#{@out_dir}/#{@package}/#{get_identifier(get_parent_framework_name(framework.name.downcase))}/#{get_identifier(get_framework_name(framework.name.downcase))}" if sub_framework?(framework.name.downcase)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 FileUtils.mkdir_p(framework_path) unless File.exist?(framework_path)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
307
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 framework.files.each do |header|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
309 file_path = "#{framework_path}/#{get_identifier(header.name)}"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
310 bindings_file_path = file_path + "_bindings.d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
311 file_path << ".d"
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
312 mod = "#{@package}.#{get_identifier(get_framework_name(framework.name.downcase))}.#{get_identifier(header.name)}" unless sub_framework?(framework.name.downcase)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
313 mod = "#{@package}.#{get_identifier(get_parent_framework_name(framework.name.downcase))}.#{get_identifier(get_framework_name(framework.name.downcase))}.#{get_identifier(header.name)}" if sub_framework?(framework.name.downcase)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
314
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
315 File.open(file_path, "w") do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316 file << copyright
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
317 file << "module #{mod};"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
318 file << header.imports
9
3592b41928fe Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
319 file << "import bindings = #{mod}_bindings".nl.nl(false) unless header.d_constants.nil? || header.function_wrappers.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 file << header.defines
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 file << header.typedefs
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
322 file << header.cftypes
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
323 file << header.function_pointers
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
324 file << header.c_constants
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325 file << header.d_constants
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
326 file << header.enums_gnu if header.needs_type_encoding
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327 file << header.enums
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 file << header.structs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
330 unless header.d_constants_static_this.length == 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331 file << "static this ()".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332 file << "{".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
333 file << header.d_constants_static_this
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
334 file << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
335 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
337 classes = get_classes(header.name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
339 classes.each do |clazz, value|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
340 file << value.code.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 @classes.delete(clazz)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
344 interfaces = get_interfaces(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
345
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
346 interfaces.each do |interface, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
347 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
348 @interfaces.delete(interface)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
349 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
350
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
351 templates = get_templates(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
352
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
353 templates.each do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
354 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
355 @templates.delete(template)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
356 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
357
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
358 file << header.function_wrappers
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
359 file << header.c_functions
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
361
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
362 File.open(bindings_file_path, "w") do |file|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
363 file << "module "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
364 file << mod
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
365 file << "_bindings;"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
366 file << header.imports.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
367 file << header.constants
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
368 file << header.functions
9
3592b41928fe Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
369 end unless header.d_constants.nil? || header.function_wrappers.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
373 package_path = "#{@out_dir}/#{@package}"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
374 FileUtils.mkdir_p(package_path) unless File.exist?(package_path)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
376 @headers.each do |header|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
377 header_path = "#{package_path}/#{get_identifier(header.name)}"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
378 bindings_file_path = header_path + "_bindings.d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
379 header_path << ".d"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
380 mod = "#{@package}.#{get_identifier(header.name)}"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 File.open(header_path, "w") do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383 file << copyright
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
384 file << "module #{mod};"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
385 file << header.imports
9
3592b41928fe Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
386 file << "import bindings = #{mod}_bindings".nl.nl(false) unless header.d_constants.nil? || header.function_wrappers.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
387 file << header.defines
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
388 file << header.typedefs
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
389 file << header.cftypes
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
390 file << header.function_pointers
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
391 file << header.c_constants
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
392 file << header.d_constants
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
393 file << header.enums_gnu if header.needs_type_encoding
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
394 file << header.enums
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
395 file << header.structs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
397 unless header.d_constants_static_this.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
398 file << "static this ()".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
399 file << "{".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
400 file << header.d_constants_static_this
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
401 file << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
402 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
403
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
404 classes = get_classes(header.name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
405
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
406 classes.each do |clazz, value|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
407 file << value.code.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
408 @classes.delete(clazz)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
409 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
410
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
411 interfaces = get_interfaces(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
412
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
413 interfaces.each do |interface, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
414 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
415 @interfaces.delete(interface)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
416 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
417
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
418 templates = get_templates(header.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
419
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
420 templates.each do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
421 file << value.code.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
422 @templates.delete(template)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
423 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
424
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
425 file << header.function_wrappers
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
426 file << header.c_functions
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
427 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
428
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
429 File.open(bindings_file_path, "w") do |file|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
430 file << "module "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
431 file << mod
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
432 file << "_bindings;"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
433 file << header.imports.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
434 file << header.constants
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435 file << header.functions
9
3592b41928fe Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
436 end unless header.d_constants.nil? || header.function_wrappers.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439 @classes.each do |clazz, value|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
440 class_path = "#{package_path}/#{get_identifier(clazz)}.d"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
441
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 File.open(class_path, "w") do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443 file << value.code unless value.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
444 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
445 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
447
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
448 # Creates and returns the copyright header that is included in the top of every file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449 def copyright
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 return @copyright unless @copyright.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 # Add an extra empty string in the begining because array indices begin with zero and months don't
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 months = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 initialt_year = "2009"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457 date = Date.today
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458 current_year = date.year.to_s
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
459 year = initialt_year
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
460 initial_created = "#{months[date.month]} #{date.day}, #{initialt_year}"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
461
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
462 year << "-" << current_year unless initialt_year == current_year
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
463
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
464 str << "/**\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
465 str << " * Copyright: Copyright (c) #{year} Jacob Carlborg.\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
466 str << " * Authors: Jacob Carlborg\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
467 str << " * Version: Initial created: #{initial_created} \n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
468 str << " * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
469 str << " */\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
470
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
471 @copyright = str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
472 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
473
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
474 # Gets name of the framework that the given class belongs to
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
475 def get_framework (class_name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
476 @frameworks.each do |framework|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
477 framework.files.each do |file|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
478 return get_identifier(framework.name) if file.name == class_name
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
479 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
480 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
481
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
482 return []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
483 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
484
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
485 # Gets the classes that belongs to the given file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
486 def get_classes (name)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
487 classes = @classes.find_all do |clazz, value|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
488 value.file == name
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
489 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
490
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
491 return classes
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
492 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
493
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
494 # Gets the interfaces that belongs to the given file
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
495 def get_interfaces (name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
496 interfaces = @interfaces.find_all do |interface, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
497 value.file == name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
498 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
499
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
500 return interfaces
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
501 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
502
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
503 # Gets the templates that belongs to the given file
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
504 def get_templates (name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
505 templates = @templates.find_all do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
506 value.file == name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
507 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
508
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
509 return templates
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
510 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
511
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
512 # Generates the D code for the classes
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
513 def classes (classes)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
514 classes.each do |clazz|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
515 str = StringIO.new
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
516 protocols = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
517
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
518 str << "class "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
519
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
520 if clazz == ""
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
521 str << get_identifier(clazz.name).nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
522 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
523 str << get_identifier(clazz.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
524
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
525 unless clazz.parent == ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
526 str << " : "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
527 str << get_identifier(clazz.parent)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
528 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
529
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
530 unless clazz.protocols.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
531 protocols = clazz.protocols.split(",")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
532
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
533 str2 = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
534
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
535 str2 << ", " unless clazz.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
536 str2 << " : " if clazz.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
537
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
538 protocols.each do |protocol|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
539 str2 << "I"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
540 str2 << get_identifier(protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
541 str2 << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
542 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
543
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
544 str << str2.string[0 .. -3]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
545 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
546
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
547 str << "\n"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
548 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
549
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
550 str << "{".nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
551 str << "mixin ObjcWrap".indent.nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
552
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
553 templates_for_class(clazz.name).each do |template, value|
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
554 str << "mixin #{get_identifier("T" + template)}".indent.nl
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
555 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
556
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
557 str << "\n"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
558
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
559 str << methods(clazz.method, clazz.name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
560 str << "\n" if protocols.length > 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
561
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
562 # implement the interfaces/protocols
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
563 protocols.each_with_index do |protocol, i|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
564 interface = interface_for_protocol(protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
565
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
566 unless interface.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
567 str << methods(interface.method, interface.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
568 str << "\n" unless i == protocols.length - 1
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
569 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
570 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
571
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
572 str << "}".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
573
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
574 @classes[clazz.name] ||= {}
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
575 @classes[clazz.name].code = str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
576 framework = get_framework(clazz.file)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
577 @classes[clazz.name].framework = framework unless framework.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
578 @classes[clazz.name].file = get_identifier(clazz.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
579 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
580 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
581
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
582 # Generates the D code for the interfaces
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
583 def interfaces (interfaces)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
584 interfaces.each do |interface|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
585 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
586
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
587 str << "interface " # prepend I to the interface name, because it can be the same as a class name
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
588
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
589 if interface == ""
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
590 str << get_identifier("I" + interface.name).nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
591 else
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
592 str << get_identifier("I" + interface.name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
593
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
594 unless interface.parent == ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
595 str << " : "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
596 str << get_identifier(interface.parent)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
597 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
598
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
599 unless interface.protocols.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
600 protocols = interface.protocols
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
601 protocols = protocols.split(",")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
602
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
603 str2 = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
604
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
605 str2 << ", " unless interface.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
606 str2 << " : " if interface.parent.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
607
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
608 protocols.each do |protocol|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
609 str2 << "I"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
610 str2 << get_identifier(protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
611 str2 << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
612 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
613
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
614 str << str2.string[0 .. -3]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
615 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
616
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
617 str << "\n"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
618 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
619
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
620 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
621 str << interface_methods(interface.method, interface.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
622 str << "}".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
623
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
624 @interfaces[interface.name] ||= {}
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
625 @interfaces[interface.name].code = str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
626 framework = get_framework(interface.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
627 @interfaces[interface.name].framework = framework unless framework.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
628 @interfaces[interface.name].file = get_identifier(interface.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
629 @interfaces2 << interface
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
630 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
631 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
632
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
633 # Generates the D code for the templates
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
634 def templates (templates)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
635 templates.each do |template|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
636 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
637
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
638 str << "template "
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
639 str << get_identifier("T" + template.name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
640 str << " ()".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
641 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
642 str << interface_methods(template.method, template.name) if template["class"] == "NSObject"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
643 str << methods(template.method, template.name) unless template["class"] == "NSObject"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
644 str << "}".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
645
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
646 @templates[template.name] ||= {}
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
647 @templates[template.name].code = str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
648 framework = get_framework(template.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
649 @templates[template.name].framework = framework unless framework.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
650 @templates[template.name].file = get_identifier(template.file)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
651 @templates[template.name][:class] = get_identifier(template["class"])
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
652 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
653 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
654
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
655 # Generates the D code for the constants/globals
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
656 def constants (constants)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
657 return "" if constants.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
658
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
659 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
660
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
661 str << "extern (C)".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
662 str << "{".nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
663 str << "extern".indent.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
664 str << "{".indent.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
665
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
666 constants.each do |constant|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
667 type = get_type(constant.type, constant.type64, constant.declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
668 const = constant.const == "true"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
669
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
670 if constant.type == "@"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
671 @d_constants << { :name => constant.name.dup, :type => constant.declaredType.gsub("*", ""), :const => const }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
672
10
27e00625790b Fixed: bindings were private
Jacob Carlborg <doob@me.com>
parents: 9
diff changeset
673 str << "package ".indent(2)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
674 str << "const id" if const
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
675 str << "id" unless const
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
676 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
677 str << get_identifier(constant["name"]).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
678 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
679 @c_constants << { :name => constant.name.dup, :type => type, :const => const }
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
680 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
681 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
682
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
683 str << "}".indent.nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
684 str << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
685
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
686 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
687 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
688
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
689 def c_constants
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
690 return "" if @c_constants.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
691
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
692 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
693
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
694 str << "extern (C)".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
695 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
696 str << "extern".indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
697 str << "{".indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
698
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
699 @c_constants.each do |constant|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
700 if constant.const
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
701 str << "const ".indent(2)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
702 str << constant.type
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
703 else
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
704 str << constant.type.indent(2)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
705 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
706
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
707 str << " "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
708 str << get_identifier(constant.name).nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
709 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
710
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
711 str << "}".indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
712 str << "}".nl(false).nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
713
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
714 @c_constants.clear
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
715 str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
716 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
717
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
718
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
719 # Generates the D code for the constants that D can't handle directly, like classes
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
720 def d_constants
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
721 return "" if @d_constants.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
722
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
723 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
724
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
725 @d_constants.each do |constant|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
726 # Deep copy constant
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
727 c = constant.dup
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
728 c.name = c.name.dup
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
729 c.type = c.type.dup
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
730
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
731 str << "const " if constant.const
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
732 str << get_identifier(constant.type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
733 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
734 str << get_identifier(constant.name).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
735 @d_constants_static_this << c
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
736 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
737
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
738 str << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
739 @d_constants.clear
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
740 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
741 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
742
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
743 # Generates the D code for the constants the has to be in a "static this"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
744 def d_constants_static_this
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
745 return "" if @d_constants_static_this.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
746
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
747 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
748
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
749 @d_constants_static_this.each do |constant|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
750 str << constant.name.indent
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
751 str << " = new "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
752 str << get_identifier(constant.type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
753 str << "("
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
754 str << "bindings."
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
755 str << get_identifier(constant.name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
756 str << ")".nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
757 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
758
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
759 @d_constants_static_this.clear
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
760 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
761 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
762
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
763 # Generates the D code for the enums
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
764 def enums (enums, header_name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
765 return "" if enums.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
766
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
767 str = StringIO.new
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
768 str_gnu = StringIO.new
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
769 consts = []
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
770
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
771 enums.each do |enum|
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
772 localConsts = []
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
773 str_gnu2 = StringIO.new
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
774 str << "enum"
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
775 needs_type_encoding = false
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
776
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
777 if enum.name.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
778 str << "\n{".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
779
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
780 needs_type_encoding, localConsts = enum_helper(enum, str, str_gnu2, header_name)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
781 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
782 str << " "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
783 str << get_identifier(enum["name"]).nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
784 str << "{".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
785
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
786 needs_type_encoding, localConsts = enum_helper(enum, str, str_gnu2, header_name)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
787 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
788
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
789 str << "\n}".nl(false).nl(false)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
790
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
791 # if needs_type_encoding
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
792 # str_gnu << "// This is needed otherwise the enums will fail compiling with gdc\n"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
793 # str_gnu << "version (GNU)\n{\n"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
794 # str_gnu << "private\n".indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
795 # str_gnu << "{\n".indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
796 # str_gnu << str_gnu2.string
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
797 # str_gnu << "\n"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
798 # str_gnu << "}".indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
799 # str_gnu << "\n}".nl(false).nl(false)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
800 # end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
801
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
802 consts << localConsts
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
803 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
804
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
805 consts.flatten!
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
806
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
807 if @needs_type_encoding && consts.length > 0
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
808 str_gnu << "// This is needed otherwise the enums will fail compiling with gdc\n"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
809 str_gnu << "version (GNU)\n{\n"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
810 str_gnu << "private\n".indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
811 str_gnu << "{\n".indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
812
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
813 consts.each do |const|
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
814 str_gnu << "const __".indent(2)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
815 str_gnu << const.name
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
816 str_gnu << ' = getOSType!("'
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
817 str_gnu << const.value
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
818 str_gnu << '")'.nl
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
819 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
820
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
821 str_gnu << "}".indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
822 str_gnu << "\n}".nl(false).nl(false)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
823 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
824
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
825 needs_type_encoding = @needs_type_encoding
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
826 @needs_type_encoding = false
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
827
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
828 return str.string, str_gnu.string, needs_type_encoding
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
829 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
830
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
831 def enum_helper (enum, str, str_gnu, header_name)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
832 needs_type_encoding = false
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
833 consts = []
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
834
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
835 enum.member.each_with_index do |member, i|
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
836 str << get_identifier(member.name).indent
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
837
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
838 if member.value.length > 0
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
839 needs_type_encoding = true if member.value[0, 1] == "'"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
840 @needs_type_encoding = true if needs_type_encoding
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
841 str << " = "
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
842
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
843 if member.value[0, 1] == "'"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
844 str << 'getOSType!("'
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
845 str << member.value[1 ... -1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
846 str << '")'
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
847
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
848 consts << { :name => get_identifier(member.name), :value => member.value[1 ... -1] }
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
849 # str_gnu << "const __".indent(2)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
850 # str_gnu << get_identifier(member.name)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
851 # str_gnu << " = "
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
852 # str_gnu << 'getOSType!("'
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
853 # str_gnu << member.value[1 ... -1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
854 # str_gnu << '")'.nl
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
855 else
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
856 str << member.value
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
857 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
858 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
859
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
860 str << ",".nl(false) unless i == enum.member.length - 1
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
861 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
862
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
863 return needs_type_encoding, consts
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
864 end
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
865
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
866 # Generates the D code for the function/method args
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
867 def args (args, variadic, method = false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
868 return "" if args.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
869
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
870 str = StringIO.new
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
871
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
872 args.each do |arg|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
873
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
874 if method || arg.type != "@"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
875 type = get_type(arg.type, arg.type64, arg.declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
876 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
877 type = "id"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
878 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
879
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
880 str << type
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
881 str << " " unless arg.name.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
882 str << get_identifier(arg["name"])
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
883 str << ", "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
884 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
885
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
886 if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
887 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
888 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
889
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
890 str << "..." if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
891
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
892 return str.string if variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
893 return str.string[0 ... -2] unless variadic
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
894 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
895
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
896 # A helper function that generates the D code for the functions/methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
897 def build_function (function, method = false, static = false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
898 str = StringIO.new
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
899 variadic = function.variadic == "true"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
900 return_type = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
901 args = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
902 original_type = function.returnValue[0].type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
903
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
904 if !method && original_type == "@"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
905 return_type = "id"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
906 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
907 return_type = get_type(original_type, function.returnValue[0].type64, function.returnValue[0].declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
908 args(function.arg, variadic) unless function.arg.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
909 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
910
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
911 str << "static " if static
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
912 str << return_type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
913 str << " "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
914 str << function["name"]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
915 str << " ("
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
916 str << args(function["arg"], variadic, method)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
917 str << ")".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
918
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
919 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
920 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
921
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
922 # Generates the D code for the functions
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
923 def functions (functions)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
924 return "" if functions.length == 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
925
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
926 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
927 wrapper_needed = false
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
928
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
929 str << "extern (C)".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
930 str << "{".nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
931
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
932 functions.each do |function|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
933 wrapper_needed = false
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
934 original_type = function.returnValue[0].type
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
935
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
936 if original_type == "@"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
937 @function_wrappers << function
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
938 wrapper_needed = true
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
939 str << functions_helper(function, wrapper_needed)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
940 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
941 function.arg.each do |arg|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
942 if (arg.type || arg.type64) == "@"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
943 @function_wrappers << function
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
944 wrapper_needed = true
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
945 break
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
946 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
947 end unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
948
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
949 str << functions_helper(function, wrapper_needed) if wrapper_needed
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
950 @c_functions << function unless wrapper_needed
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
951 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
952 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
953
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
954 str << "}"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
955 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
956 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
957
4
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
958 def function_pointers (function_pointers)
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
959 return "" if function_pointers.length == 0
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
960
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
961 str = StringIO.new
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
962
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
963 str << "extern (C)\n{".nl(false)
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
964
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
965 function_pointers.each do |fp|
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
966 str << "alias ".indent
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
967 str << get_type(fp.returnValue[0].type, fp.returnValue[0].type64, fp.returnValue[0].declaredType)
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
968 str << " function ("
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
969 str << args(fp.arg, fp.variadic == "true")
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
970 str << ") "
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
971 str << get_identifier(fp.name).nl
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
972 end
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
973
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
974 str << "}".nl(false).nl(false)
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
975
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
976 str.string
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
977 end
5a1a6afbfe3a Added support for function pointers and variadic function pointers to dgen and dstepgen
Jacob Carlborg <doob@me.com>
parents: 3
diff changeset
978
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
979 def c_functions
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
980 return "" if @c_functions.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
981
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
982 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
983
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
984 str << "extern (C)".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
985 str << "{".nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
986
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
987 @c_functions.each do |function|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
988 str << functions_helper(function, false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
989 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
990
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
991 str << "}"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
992
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
993 @c_functions.clear
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
994 str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
995 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
996
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
997
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
998 # A helper function that generates the D code for the functions
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
999 def functions_helper (function, wrapper_needed)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1000 str = StringIO.new
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1001
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1002 str << ("private " + build_function(function)).indent if wrapper_needed
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1003 str << build_function(function).indent unless wrapper_needed
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1004
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1005 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1006 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1007
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1008 # Generates the D code for the functions that D can't handle without wrappers, like functions that takes
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1009 # objects as arguments or returns an object
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1010 def function_wrappers
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1011 return "" if @function_wrappers.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1012
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1013 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1014
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1015 @function_wrappers.each do |function|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1016 return_type = get_type(function.returnValue[0].type, function.returnValue[0].type64, function.returnValue[0].declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1017 variadic = function.variadic == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1018
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1019 str << build_function(function, true)[0 ... -2].nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1020 str << "{".nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1021 str << "return Bridge.invokeObjcFunction!(".indent
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1022 str << return_type
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1023 str << ", bindings."
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1024 str << function.name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1025
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1026 function.arg.each do |arg|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1027 str << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1028 str << get_type(arg.type, arg.type, arg.declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1029 end unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1030
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1031 unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1032 str << ")"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1033 str << "("
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1034 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1035
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1036 function.arg.each_with_index do |arg, i|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1037 str << arg.name
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1038 str << ", " unless i == function.arg.length - 1
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1039 end unless function.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1040
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1041 str << ")".nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1042
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1043 str << "}".nl(false).nl(false)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1044 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1045
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1046 @function_wrappers.clear
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1047 str.string
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1048 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1049
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1050 # Generates the D code for the imports
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1051 def imports (header, imports, filename, framework_name = nil)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1052 return "" if imports.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1053
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1054 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1055
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1056 imports.each do |import|
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1057 str << "import #{@package}."
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1058 import = import.gsub("/", ".").gsub("Frameworks", "").gsub(".framework", "").gsub("Headers", "").gsub(/\.{2,}/, ".").nl
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1059
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1060 splits = import.split('.')
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1061 import = ""
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1062
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1063 splits[0 .. -2].each do |s|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1064 import << get_identifier(s.downcase)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1065 import << '.'
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1066 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1067
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1068 str << import
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1069 str << splits[-1 .. -1]
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1070 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1071
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1072 str << "import dstep.objc.bridge.TypeEncoding".nl if header.needs_type_encoding && !@needs_bridge
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1073
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1074 if @needs_bridge
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1075 str << "import dstep.objc.bridge.Bridge".nl
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1076 str << "import dstep.objc.bridge.TypeEncoding".nl if header.needs_type_encoding
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1077 str << "import dstep.objc.objc : id".nl
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1078 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1079
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1080 str << "\n\n"
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1081 str = str.string.sort.to_s
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1082 str << "\n"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1083
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1084 return "\n\npublic:" << str if filename == get_framework_name(framework_name)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1085 return str
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1086 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1087
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1088 # Generates the D code for the methods
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1089 def methods (methods, class_name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1090 return "" if methods.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1091
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1092 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1093
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1094 methods.each do |method|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1095 return_type = get_type(method.returnValue[0].type, method.returnValue[0].type64, method.returnValue[0].declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1096 variadic = method.variadic == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1097 static = method.classMethod == "true"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1098
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1099 index = 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1100 declaration = build_function(method, true, static)[0 ... -2].indent.nl(false)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1101 index = declaration.index_of(" ") if static
13
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1102 index = declaration.index_of(" ", index)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1103 name = get_method_name(method.selector)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1104
13
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1105 str << (declaration[0 .. index] + name + declaration[index .. -1]).gsub(/ +/, " ")
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1106 str << "{".indent.nl(false)
13
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1107
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1108 if static
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1109 str << "return invokeObjcSelfClass!(".indent(2)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1110 str << return_type
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1111 else
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1112 if return_type == class_name
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1113 str << "id result = invokeObjcSelf!(".indent(2)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1114 str << "id"
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1115 else
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1116 str << "return invokeObjcSelf!(".indent(2)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1117 str << return_type
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1118 end
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1119 end
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1120
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1121 str << ', "'
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1122 str << method.selector
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1123 str << '"'
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1124
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1125 method.arg.each do |arg|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1126 str << ", "
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1127 str << get_type(arg.type, arg.type, arg.declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1128 end unless method.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1129
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1130 unless method.arg.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1131 str << ")"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1132 str << "("
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1133 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1134
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1135 method.arg.each_with_index do |arg, i|
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
1136 str << get_identifier(arg.name)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1137 str << ", " unless i == method.arg.length - 1
13
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1138 end unless method.arg.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1139
15
7ff919f595d5 Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents: 13
diff changeset
1140 str << ")".nl
7ff919f595d5 Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents: 13
diff changeset
1141 str << "return result is this.objcObject ? this : (result !is null ? new #{return_type}(result) : null)".indent(2).nl if return_type == class_name && !static
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1142 str << "}".indent.nl(false).nl(false)
13
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1143
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1144 if name.length >= 4 && name[0 ... 4] == "init" && name != "initialize"
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1145 str << ("this" + declaration[index .. -1]).gsub(/ +/, " ").indent
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1146 str << "{".indent.nl(false)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1147 str << 'objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass)'.indent(2).nl
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1148 str << 'id result = Bridge.invokeObjcMethod!(id, "'.indent(2)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1149 str << method.selector
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1150 str << '"'
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1151
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1152 method.arg.each do |arg|
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1153 str << ", "
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1154 str << get_type(arg.type, arg.type, arg.declaredType)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1155 end unless method.arg.nil?
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1156
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1157 str << ")(objcObject"
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1158
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1159 method.arg.each do |arg|
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1160 str << ", "
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1161 str << get_identifier(arg.name)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1162 end unless method.arg.nil?
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1163
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1164 str << ")".nl.nl(false)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1165
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1166 str << "if (result)".indent(2).nl(false)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1167 str << "objcObject = ret".indent(3).nl.nl(false)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1168 str << "dObject = this".indent(2).nl
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1169 str << "}".indent.nl(false).nl(false)
4f583f7e242e Added a constructor for every init method
Jacob Carlborg <doob@me.com>
parents: 11
diff changeset
1170 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1171 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1172
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1173 str.string[0 .. -2]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1174 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1175
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1176 # Generates the D code for the interface methods
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1177 def interface_methods (methods, interface_name)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1178 return "" if methods.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1179
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1180 str = StringIO.new
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1181
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1182 methods.each do |method|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1183 return_type = get_type(method.returnValue[0].type, method.returnValue[0].type64, method.returnValue[0].declaredType)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1184
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1185 variadic = method.variadic == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1186 static = method.classMethod == "true"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1187
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1188 index = 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1189 declaration = build_function(method, true, static)[0 ... -2].indent.nl(false)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1190 index = declaration.index_of(" ", index)
9
3592b41928fe Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
1191 index = declaration.index_of(" ", index + 1) if static
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1192 str << ((declaration[0 .. index] + get_method_name(method["selector"]) + declaration[index .. -1]).gsub(/ +/, " "))[0 .. -2]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1193 str << ";\n"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1194 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1195
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1196 str.string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1197 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1198
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1199 # Generates the D code for the structs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1200 def structs (structs)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1201 return "" if structs.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1202
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1203 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1204
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1205 structs.each do |struct|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1206 str << "struct "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1207 str << get_identifier(struct.name).nl(false)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1208 str << "{".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1209
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1210 struct.member.each do |member|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1211 type = get_type(member.type, member.type64, member.declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1212
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1213 str << type.indent
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1214 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1215 str << get_identifier(member.name).nl
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1216 end unless struct.member.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1217
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1218 str << "}".nl
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1219 str << "\n\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1220 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1221
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1222 str.string[0 .. -2]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1223 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1224
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1225 # Generates the D code for the typedefs
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1226 def typedefs (typedefs)
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1227 return "" if typedefs.length == 0
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1228
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1229 str = StringIO.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1230
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1231 typedefs.each do |typedef|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1232
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1233 type = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1234 struct = false
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1235
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1236 if typedef.type.struct?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1237 type = get_struct_type(typedef.type, typedef.type64, typedef.declaredType)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1238 struct = true
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1239 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1240 type = get_type(typedef.type, typedef.type64, typedef.declaredType)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1241 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1242
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1243 if struct
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1244 unless type.name == typedef.name
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1245 declaredType = typedef.declaredType
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1246 declaredType = declaredType[7 .. -1] if declaredType.length > 7 && declaredType[0 ... 6] == "struct"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1247
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1248 unless declaredType == typedef.name
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1249 str << "alias "
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1250 str << get_identifier(declaredType)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1251 str << " "
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1252 str << get_identifier(typedef.name).nl
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1253 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1254
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1255 # str << "alias "
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1256 # str << get_identifier(type.name)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1257 # str << "*" if typedef.declaredType =~ /\*{1}/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1258 # str << " "
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1259 # str << get_identifier(typedef.name).nl
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1260 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1261 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1262 str << "alias "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1263 str << type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1264 str << " "
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1265 str << get_identifier(typedef.name).nl
7
9e67a1122e85 Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
1266 end unless type.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1267 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1268
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1269 str << "\n"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1270 str.string
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1271 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1272
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1273 # Adds specific D extensions to classes, like opIndex and opApply
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1274 def d_class_extensions (args)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1275
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1276 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1277
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1278 # Checks if the declared type should be used instead of the type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1279 # type:: the type to check
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1280 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1281 def check_declared_type (type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1282 case type
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1283 when "unichar"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1284 when "UniChar"; return "wchar"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1285 when "BOOL"; return "bool"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1286 when "CGFloat"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1287 when "NSInteger"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1288 when "NSUInteger"; return type
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1289 when "IMP"; return type;
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1290
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1291 when "unichar*"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1292 when "UniChar*"; return "wchar*"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1293 when "BOOL*"; return "bool*"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1294 when "CGFloat*"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1295 when "NSInteger*"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1296 when "NSUInteger*"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1297
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1298 when "unichar**"
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1299 when "UniChar**"; return "wchar**"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1300 when "BOOL**"; return "bool**"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1301 when "CGFloat**"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1302 when "NSInteger**"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1303 when "NSUInteger**"; return type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1304 else return nil;
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1305 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1306 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1307
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1308 # Gets the method name from the supplied selector
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1309 # selector:: the selector to get the method name from
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1310 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1311 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1312 # get_method_name("initWithContentsOfURL:options:error:") #=> initWithContentsOfURL
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1313 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1314 def get_method_name (selector)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1315 i = selector.index_of(":")
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1316 get_identifier(selector[0 ... i])
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1317 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1318
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1319 def get_matching_close_char (char)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1320 case char
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1321 when "{"; return "}"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1322 when "("; return ")"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1323 when "["; return "]"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1324 else
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1325 char
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1326 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1327 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1328
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1329
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1330
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1331 # Gets the D type from the encoded C/Objective-C type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1332 # type:: the type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1333 # type64:: the type for 64bit targets
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1334 # declared_type:: the declared type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1335 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1336 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1337 # get_type("I", "Q", "NSUInteger") #=> NSUInteger
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1338 # get_type("I", "I", "unsigned int") #=> uint
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1339 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1340 def get_type (type, type64, declared_type)
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
1341 declared_type = "I" + $1 if declared_type =~ /\w+\s*<(.+)>/
9
3592b41928fe Fixed: bindings were not generated
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
1342 declared_type.gsub!(/\(|\)/, "")
8
2c0fd7bb4de6 Added a T in front of every template. Added support for interfaces as method parameters
Jacob Carlborg <doob@me.com>
parents: 7
diff changeset
1343
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1344 return get_identifier(declared_type) if type.nil? && type64.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1345
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1346 t = check_declared_type(declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1347 return t unless t.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1348
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1349 unless type64 == "" || type64.nil?
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1350 return get_identifier(declared_type) if type != type64
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1351 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1352
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1353 case type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1354 when "c"; return "byte"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1355 when "i"; return "int"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1356 when "s"; return "short"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1357 when "l"; return "int"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1358 when "q"; return "long"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1359 when "C"; return "ubyte"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1360 when "I"; return "uint"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1361 when "S"; return "ushort"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1362 when "L"; return "uint"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1363 when "Q"; return "ulong"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1364 when "f"; return "float"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1365 when "d"; return "double"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1366 when "B"; return "bool"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1367 when "v"; return "void"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1368 when "*"; return "char*"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1369 when '#'; return "Class"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1370 when ":"; return "SEL"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1371 when "@"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1372 unless declared_type.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1373 t = declared_type.gsub(/\*+/, "")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1374 return t == "id" ? "Object" : t
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1375 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1376
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1377 raise "No declared type given"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1378 else
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1379 return declared_type if type =~ /\{/
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1380
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1381 case type[0, 1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1382 when "["
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1383 str = ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1384 t = type[1 ... -1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1385 count = $1 if t =~ /(\d+)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1386 t = $'
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1387
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1388 t64 = ""
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1389
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1390 unless type64.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1391 t64 = type64[1 ... -1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1392 count = $1 if t64 =~ /(\d+)/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1393 t64 = $'
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1394 else
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1395 t64 = t
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1396 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1397
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1398 str = get_type(t, t64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1399 str << "[#{count}]"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1400
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1401 return get_identifier(str)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1402 when "("
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1403 resolved_types = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1404 types = $2 if type =~ /\((.+)=(.+)\)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1405 types64 = $2 if type64 =~ /\((.+)=(.+)\)/
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1406 i = 0
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1407
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1408 while i < types.length
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1409 t = types[i, 1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1410 t64 = types64.nil? ? t : types64[i, 1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1411
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1412 index = t =~ /(\(|\[|\{)/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1413
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1414 unless index.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1415 x = types.index(get_matching_close_char($1), index)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1416 t = types[index .. x]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1417 t64 = types64.nil? ? t : types64[index .. x]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1418 i += x - index
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1419 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1420
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1421 resolved_types << get_type(t, t64, declared_type)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1422 i += 1
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1423 end unless types.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1424
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1425 get_identifier(resolved_types)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1426 when "^"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1427 t = type[1 .. -1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1428 t64 = type64.nil? ? t : type64[1 .. -1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1429 get_identifier(get_type(t, t64, declared_type).dup + "*")
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1430
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1431 # if type == "^@"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1432 # return get_identifier(get_type(type[1 .. -1], type64[1 .. -1], declared_type).dup + "*")
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1433 # elsif type.length > 2 && type[0 ... 2] == "^^"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1434 # return get_identifier(get_type(type[2 .. -1], type64[2 .. -1], declared_type).dup + "**")
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1435 # elsif type == "^?" # assuming function pointer
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1436 # tmp = cfp_to_dfp(type)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1437 # return get_identifier(tmp) unless tmp.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1438 # end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1439 #
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1440 # if !type.nil? && !type64.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1441 # t = get_type(type[1 .. -1], type64[1 .. -1], declared_type).dup
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1442 #
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1443 # return get_identifier(t) if t =~ /\*/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1444 # return get_identifier(t + "*") if t !~ /\*/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1445 # elsif !type.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1446 # t = get_type(type[1 .. -1], type64, declared_type).dup << "*"
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1447 #
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1448 # return get_identifier(t) if t =~ /\*/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1449 # return get_identifier(t + "*") if t !~ /\*/
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1450 # end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1451 when "{"
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1452 return get_identifier(declared_type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1453 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1454 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1455
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1456 return get_identifier(declared_type)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1457 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1458
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1459 # Gets the D type from the encoded C/Objective-C type when it's a struct
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1460 # type:: the type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1461 # type64:: the type for 64bit targets
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1462 # declared_type:: the declared type
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1463 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1464 # === Example
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1465 # get_struct_type("{some=III}", "{some=III}", "struct some")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1466 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1467 # { :name => "some", :types => ["uint", "uint", "uint"] }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1468 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1469 def get_struct_type (type, type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1470 return { :name => declared_type } if declared_type[0 ... 2] == "NS"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1471
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1472 case type[0, 1]
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1473 when "{"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1474 resolved_types = []
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1475
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1476 if type =~ /\^{0,}\{(.{0,})=(.{0,})\}/
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1477 name = get_identifier($1)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1478 types = get_identifier($2)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1479 elsif type =~ /\^{0,}\((.{0,})=(.{0,})\)/
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1480 name = get_identifier($1)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1481 types = get_identifier($2)
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1482 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1483
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1484 unless types.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1485 types.each_char do |t|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1486 resolved_types << get_type(t, type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1487 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1488 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1489
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1490 name = declared_type if name.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1491
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1492 return { :name => name, :types => resolved_types }
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1493 when "^"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1494 get_struct_type(type[1 .. -1], type64, declared_type)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1495 hash = get_struct_type(type[1 .. -1], type64, declared_type)
7
9e67a1122e85 Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
1496 hash[:name].dup << "*" unless hash.nil?
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1497 return hash
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1498 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1499 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1500
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1501 # C Function Pointer to D Function Pointer
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1502 def cfp_to_dfp (fp)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1503 reg = /(\w+)\s*\(\*(\w*)\)\s*\((.*)\)/
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1504
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1505 return nil if fp !~ reg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1506
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1507 return_type = $1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1508 name = $2
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1509 arg_types = $3
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1510
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1511 return "#{get_identifier(return_type)} function (#{arg_types})"
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1512 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1513
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1514 # Is the supplied argument an "out" argument
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1515 # arg:: the arg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1516 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1517 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1518 # out_arg?("out NSError") #=> true
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1519 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1520 def out_arg? (arg)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1521 return arg[0 .. 4] == "out "
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1522 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1523
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1524 # Transform the supplied selector to a valid D representation
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1525 # selector:: the selector to transform
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1526 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1527 # === Example:
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1528 # transform_selector("initWithContentsOfURL:options:error:")
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1529 # # outputs below
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1530 # initWithContentsOfURL_options_error_
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1531 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1532 def transform_selector (selector)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1533 selector.gsub(/:/, "_")
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1534 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1535
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1536 # Gets the identifier, if it's a D keyoword it
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1537 # will return string appended with a _ otherwise the string
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1538 def get_identifier (str)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1539 return is_keyword?(str) ? str + "_" : str
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1540 end
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1541
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1542 # Returns true if the given string is a D(2) keyword
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1543 def is_keyword? (str)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1544 case str
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1545 when "abstract"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1546 when "alias"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1547 when "align"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1548 when "asm"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1549 when "assert"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1550 when "auto"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1551
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1552 when "body"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1553 when "bool"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1554 when "break"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1555 when "byte"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1556
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1557 when "case"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1558 when "cast"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1559 when "catch"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1560 when "cdouble"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1561 when "cent"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1562 when "cfloat"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1563 when "char"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1564 when "class"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1565 when "const"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1566 when "continue"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1567 when "creal"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1568
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1569 when "dchar"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1570 when "debug"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1571 when "default"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1572 when "delegate"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1573 when "delete"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1574 when "deprecated"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1575 when "do"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1576 when "double"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1577
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1578 when "else"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1579 when "enum"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1580 when "export"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1581 when "extern"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1582
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1583 when "false"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1584 when "final"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1585 when "finally"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1586 when "float"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1587 when "for"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1588 when "foreach"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1589 when "foreach_reverse"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1590 when "function"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1591
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1592 when "goto"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1593
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1594 when "idouble"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1595 when "if"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1596 when "ifloat"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1597 when "import"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1598 when "in"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1599 when "inout"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1600 when "int"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1601 when "interface"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1602 when "invariant"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1603 when "ireal"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1604 when "is"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1605
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1606 when "lazy"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1607 when "long"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1608
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1609 when "macro"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1610 when "mixin"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1611 when "module"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1612
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1613 when "new"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1614 when "nothrow"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1615 when "null"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1616
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1617 when "out"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1618 when "override"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1619
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1620 when "package"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1621 when "pragma"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1622 when "private"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1623 when "protected"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1624 when "public"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1625 when "pure"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1626
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1627 when "real"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1628 when "ref"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1629 when "return"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1630
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1631 when "scope"; return true
7
9e67a1122e85 Fixed a bug that caused some types to be empty
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
1632 when "shared"; return true
2
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1633 when "short"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1634 when "static"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1635 when "struct"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1636 when "super"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1637 when "switch"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1638 when "synchronized"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1639
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1640 when "template"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1641 when "this"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1642 when "throw"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1643 when "true"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1644 when "try"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1645 when "typedef"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1646 when "typeid"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1647 when "typeof"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1648
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1649 when "ubyte"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1650 when "ucent"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1651 when "uint"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1652 when "ulong"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1653 when "union"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1654 when "unittest"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1655 when "ushort"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1656
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1657 when "version"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1658 when "void"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1659 when "volatile"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1660
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1661 when "wchar"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1662 when "while"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1663 when "with"; return true
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1664 else return false;
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1665 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1666 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1667
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1668 def templates_for_class (clazz)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1669 templates = @templates.find_all do |template, value|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1670 value[:class] == clazz
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1671 end
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 return templates
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1674 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1675
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1676 def interface_for_protocol (protocol)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1677 interface = @interfaces2.find do |interface|
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1678 interface.name == protocol
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1679 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1680
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1681 return interface
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1682 end
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1683
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1684 def get_framework_name (framework)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1685 i = framework.rindex(".framework")
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1686 return framework if i.nil?
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1687 x = framework.rindex("/", i)
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1688 framework[x + 1 ... i]
9fd439a28ce3 Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents: 1
diff changeset
1689 end
11
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1690
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1691 def sub_framework? (framework)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1692 i = framework.index("framework")
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1693 return false if i.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1694 !framework.index("framework", i + 1).nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1695 end
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1696
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1697 def get_parent_framework_name (framework)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1698 return get_framework_name(framework) unless sub_framework?(framework)
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1699 i = framework.index(".framework")
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1700 return framework if i.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1701 str = framework[0 ... i]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1702 x = str.rindex("/")
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1703 return str if x.nil?
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1704 str[x + 1 .. -1]
07194b026fa4 Added bindings to a couple of frameworks, new license + some other things
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
1705 end
1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1706 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1707
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1708 # Prints the message to stderr, exits
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1709 def die (*msg)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1710 $stderr.puts msg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1711 exit 1
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1712 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1713
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1714 if __FILE__ == $0
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1715 objc_to_d = ObjcToD.new
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1716
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1717 OptionParser.new do |opts|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1718 opts.banner = "Usage: #{File.basename(__FILE__)} [options] <dstep files...>"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1719 opts.separator ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1720 opts.separator "Options:"
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1721
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1722 opts.on("-o", "--output DIRECTORY", "Place the output files in this directory'") do |opt|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1723 die "The specified directory \"#{opt}\" does not exists" if File.exist?(opt) == false
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1724 die "Output directory cannot be specified more than once" if objc_to_d.out_dir
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1725 objc_to_d.out_dir = opt
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1726 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1727
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1728 help_msg = "Use the `-h' flag or for help."
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1729
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1730 opts.on("-h", "--help", "Show this message.") do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1731 puts opts, help_msg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1732 exit
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1733 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1734
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1735 opts.on('-v', '--version', 'Show version.') do
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1736 puts ObjcToD::VERSION
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1737 exit
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1738 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1739
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1740 opts.separator ""
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1741
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1742 if ARGV.empty?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1743 die opts.banner
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1744 else
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1745 #begin
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1746 opts.parse!(ARGV)
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1747
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1748 die "No output directory given" if objc_to_d.out_dir.nil?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1749
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1750 ARGV.each do |file|
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1751 objc_to_d.files << file
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1752 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1753
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1754 objc_to_d.generate_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1755 objc_to_d.output_code
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1756 # rescue => e
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1757 # msg = e.message
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1758 # msg = "Internal error" if msg.empty?
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1759 #
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1760 # die msg, opts.banner, help_msg
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1761 # end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1762 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1763 end
033d260cfc9b First upload of the bridge
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1764 end