5 def __init__(self, name):
14 def dump(self, instance):
15 raise NotImplementedError
17 def wrap_instance(self, instance):
20 def unwrap_instance(self, instance):
27 Type.__init__(self, "void")
32 class Intrinsic(Type):
34 def __init__(self, name, format):
35 Type.__init__(self, name)
38 def dump(self, instance):
39 print ' g_pLog->TextF("%s", %s);' % (self.format, instance)
44 def __init__(self, type):
45 Type.__init__(self, 'C' + type.name)
48 def dump(self, instance):
49 self.type.dump(instance)
52 return "const " + str(self.type)
57 def __init__(self, type):
58 Type.__init__(self, 'P' + type.name)
62 return str(self.type) + " *"
64 def dump(self, instance):
65 print ' if(%s) {' % instance
67 self.type.dump("*" + instance)
68 except NotImplementedError:
69 print ' g_pLog->TextF("%%p", %s);' % instance
72 print ' g_pLog->Text("NULL");'
74 def wrap_instance(self, instance):
75 self.type.wrap_instance("*" + instance)
77 def unwrap_instance(self, instance):
78 self.type.wrap_instance("*" + instance)
81 class OutPointer(Pointer):
89 def __init__(self, name, values):
90 Type.__init__(self, name)
93 def dump(self, instance):
94 print ' switch(%s) {' % instance
95 for value in self.values:
96 print ' case %s:' % value
97 print ' g_pLog->Text("%s");' % value
100 print ' g_pLog->TextF("%%i", %s);' % instance
107 def __init__(self, type, values):
108 Type.__init__(self, type.name)
114 def __init__(self, name, members):
115 Type.__init__(self, name)
116 self.members = members
118 def dump(self, instance):
119 print ' g_pLog->Text("{");'
121 for type, name in self.members:
125 print ' g_pLog->Text(", ");'
126 type.dump('(%s).%s' % (instance, name))
127 print ' g_pLog->Text("}");'
132 def __init__(self, name, type):
133 Type.__init__(self, name)
136 def dump(self, instance):
137 self.type.dump(instance)
142 def __init__(self, type, name, args, call = '__stdcall'):
148 def prototype(self, name=None):
155 s = self.call + ' ' + s
156 if name.startswith('*'):
158 s = str(self.type) + ' ' + s
161 s += ", ".join(["%s %s" % (type, name) for type, name in self.args])
168 class Interface(Type):
170 def __init__(self, name, base=None):
171 Type.__init__(self, name)
175 def itermethods(self):
176 if self.base is not None:
177 for method in self.base.itermethods():
179 for method in self.methods:
184 return "Wrap" + self.name
186 def wrap_pre_decl(self):
187 print "class %s;" % self.wrap_name()
190 print "class %s : public %s " % (self.wrap_name(), self.name)
193 print " %s(%s * pInstance);" % (self.wrap_name(), self.name)
194 print " virtual ~%s();" % self.wrap_name()
196 for method in self.itermethods():
197 print " " + method.prototype() + ";"
200 print " %s * m_pInstance;" % (self.name,)
205 print '%s::%s(%s * pInstance) {' % (self.wrap_name(), self.wrap_name(), self.name)
206 print ' m_pInstance = pInstance;'
209 print '%s::~%s() {' % (self.wrap_name(), self.wrap_name())
212 for method in self.itermethods():
213 print method.prototype(self.wrap_name() + '::' + method.name) + ' {'
214 if method.type is Void:
217 print ' %s result;' % method.type
219 print ' g_pLog->BeginCall("%s");' % (self.name + '::' + method.name)
220 print ' g_pLog->BeginParam("this", "%s *");' % self.name
221 print ' g_pLog->TextF("%p", m_pInstance);'
222 print ' g_pLog->EndParam();'
223 for type, name in method.args:
224 if not type.isoutput():
225 type.unwrap_instance(name)
226 print ' g_pLog->BeginParam("%s", "%s");' % (name, type)
228 print ' g_pLog->EndParam();'
229 print ' %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
230 for type, name in method.args:
232 print ' g_pLog->BeginParam("%s", "%s");' % (name, type)
234 print ' g_pLog->EndParam();'
235 type.wrap_instance(name)
236 if method.type is not Void:
237 print ' g_pLog->BeginReturn("%s");' % method.type
238 method.type.dump("result")
239 print ' g_pLog->EndReturn();'
240 method.type.wrap_instance('result')
241 print ' g_pLog->EndCall();'
242 if method.name == 'QueryInterface':
243 print ' if(*ppvObj == m_pInstance)'
244 print ' *ppvObj = this;'
245 if method.name == 'Release':
246 assert method.type is not Void
248 print ' delete this;'
249 if method.type is not Void:
250 print ' return result;'
256 class Method(Function):
258 def __init__(self, type, name, args):
259 Function.__init__(self, type, name, args)
264 class WrapPointer(Pointer):
266 def __init__(self, type):
267 Pointer.__init__(self, type)
268 if type not in towrap:
271 def wrap_instance(self, instance):
272 print " if(%s)" % instance
273 print " %s = new %s(%s);" % (instance, self.type.wrap_name(), instance)
275 def unwrap_instance(self, instance):
276 print " if(%s)" % instance
277 print " %s = static_cast<%s *>(%s)->m_pInstance;" % (instance, self.type.wrap_name(), instance)
279 String = Intrinsic("char *", "%s")
280 Int = Intrinsic("int", "%i")
281 Long = Intrinsic("long", "%li")
282 Float = Intrinsic("float", "%f")