annotate scripts/dgen.rb @ 16:19885b43130e

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