5 def __init__(self, name):
14 def wrap_instance(self, instance):
21 Type.__init__(self, "void")
26 class Intrinsic(Type):
28 def __init__(self, name, format):
29 Type.__init__(self, name)
35 def __init__(self, type):
36 Type.__init__(self, 'C' + type.name)
40 return "const " + str(self.type)
45 def __init__(self, type):
46 Type.__init__(self, 'P' + type.name)
50 return str(self.type) + " *"
52 def wrap_instance(self, instance):
53 self.type.wrap_instance("*" + instance)
58 def __init__(self, type):
59 Type.__init__(self, type.name)
68 def wrap_instance(self, instance):
69 self.type.wrap_instance(instance)
74 def __init__(self, name, values):
75 Type.__init__(self, name)
81 def __init__(self, type, values):
82 Type.__init__(self, type.name)
88 def __init__(self, name, members):
89 Type.__init__(self, name)
90 self.members = members
95 def __init__(self, name, type):
96 Type.__init__(self, name)
102 def __init__(self, type, name, args, call = '__stdcall'):
108 def prototype(self, name=None):
115 s = self.call + ' ' + s
116 if name.startswith('*'):
118 s = str(self.type) + ' ' + s
121 s += ", ".join(["%s %s" % (type, name) for type, name in self.args])
128 class Interface(Type):
130 def __init__(self, name, base=None):
131 Type.__init__(self, name)
135 def itermethods(self):
136 if self.base is not None:
137 for method in self.base.itermethods():
139 for method in self.methods:
144 return "Wrap" + self.name
146 def wrap_pre_decl(self):
147 print "class %s;" % self.wrap_name()
150 print "class %s : public %s " % (self.wrap_name(), self.name)
153 print " %s(%s * pInstance);" % (self.wrap_name(), self.name)
154 print " virtual ~%s();" % self.wrap_name()
156 for method in self.itermethods():
157 print " " + method.prototype() + ";"
160 print " Log *m_pLog;"
161 print " %s * m_pInstance;" % (self.name,)
166 print '%s::%s(%s * pInstance) {' % (self.wrap_name(), self.wrap_name(), self.name)
167 print ' m_pLog = new Log("d3d8trace");'
168 print ' m_pInstance = pInstance;'
171 print '%s::~%s() {' % (self.wrap_name(), self.wrap_name())
172 print " delete m_pLog;"
175 for method in self.itermethods():
176 print method.prototype(self.wrap_name() + '::' + method.name) + ' {'
177 if method.type is Void:
180 print ' %s result;' % method.type
182 print ' m_pLog->BeginCall("%s");' % (self.name + '::' + method.name)
183 print ' %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
184 for type, name in method.args:
186 type.wrap_instance(name)
187 if method.type is not Void:
188 method.type.wrap_instance('result')
189 print ' m_pLog->EndCall();'
190 if method.name == 'QueryInterface':
191 print ' if(*ppvObj == m_pInstance)'
192 print ' *ppvObj = this;'
193 if method.name == 'Release':
194 assert method.type is not Void
196 print ' delete this;'
197 if method.type is not Void:
198 print ' return result;'
204 class Method(Function):
206 def __init__(self, type, name, args):
207 Function.__init__(self, type, name, args)
212 class WrapPointer(Pointer):
214 def __init__(self, type):
215 Pointer.__init__(self, type)
216 if type not in towrap:
219 def wrap_instance(self, instance):
220 print " if(%s)" % instance
221 print " %s = new %s(%s);" % (instance, self.type.wrap_name(), instance)
223 String = Intrinsic("char *", "%s")
224 Int = Intrinsic("int", "%i")
225 Long = Intrinsic("long", "%li")
226 Float = Intrinsic("float", "%f")