[ctypes-commit] ctypes/codegen/ctypes_codegen codegenerator.py, 1.2, 1.3
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2006-06-08 20:04:18
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv2016 Modified Files: codegenerator.py Log Message: Removed most of the code that generates COM interfaces. Now, COM interfaces are generated as simple Structure subclasses, without any fields or methods - must be fixed manually in the generated code, but better would be to avoid them at all. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/codegenerator.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** codegenerator.py 8 Jun 2006 19:18:28 -0000 1.2 --- codegenerator.py 8 Jun 2006 20:04:14 -0000 1.3 *************** *** 292,322 **** basenames = [self.type_name(b) for b in head.struct.bases] if basenames: ! self.need_GUID() ! method_names = [m.name for m in head.struct.members if type(m) is typedesc.Method] print >> self.stream, "class %s(%s):" % (head.struct.name, ", ".join(basenames)) - print >> self.stream, " _iid_ = GUID('{}') # please look up iid and fill in!" - if "Enum" in method_names: - print >> self.stream, " def __iter__(self):" - print >> self.stream, " return self.Enum()" - elif method_names == "Next Skip Reset Clone".split(): - print >> self.stream, " def __iter__(self):" - print >> self.stream, " return self" - print >> self.stream - print >> self.stream, " def next(self):" - print >> self.stream, " arr, fetched = self.Next(1)" - print >> self.stream, " if fetched == 0:" - print >> self.stream, " raise StopIteration" - print >> self.stream, " return arr[0]" else: ! methods = [m for m in head.struct.members if type(m) is typedesc.Method] ! if methods: ! # Hm. We cannot generate code for IUnknown... ! print >> self.stream, "assert 0, 'cannot generate code for IUnknown'" ! print >> self.stream, "class %s(_com_interface):" % head.struct.name ! elif type(head.struct) == typedesc.Structure: print >> self.stream, "class %s(Structure):" % head.struct.name elif type(head.struct) == typedesc.Union: print >> self.stream, "class %s(Union):" % head.struct.name ! print >> self.stream, " pass" self.names.add(head.struct.name) --- 292,304 ---- basenames = [self.type_name(b) for b in head.struct.bases] if basenames: ! ### method_names = [m.name for m in head.struct.members if type(m) is typedesc.Method] print >> self.stream, "class %s(%s):" % (head.struct.name, ", ".join(basenames)) else: ! ### methods = [m for m in head.struct.members if type(m) is typedesc.Method] ! if type(head.struct) == typedesc.Structure: print >> self.stream, "class %s(Structure):" % head.struct.name elif type(head.struct) == typedesc.Union: print >> self.stream, "class %s(Union):" % head.struct.name ! print >> self.stream, " pass" self.names.add(head.struct.name) *************** *** 435,441 **** pass ! # we don't need _pack_ on Unions (I hope, at least), and not ! # on COM interfaces: ! if not methods: try: pack = calc_packing(body.struct, fields) --- 417,427 ---- pass ! if methods: ! # XXX we have parsed the COM interface methods but should ! # we emit any code for them? ! pass ! else: ! # we don't need _pack_ on Unions (I hope, at least), and not ! # on COM interfaces. try: pack = calc_packing(body.struct, fields) *************** *** 449,453 **** print >> self.stream, "# WARNING: %s" % details ! if fields: if body.struct.bases: assert len(body.struct.bases) == 1 --- 435,445 ---- print >> self.stream, "# WARNING: %s" % details ! if not fields: ! # XXX Normally this does not work for COM ! # interfaces. _fields_ must be defined before they are ! # subclassed. ! ## print >> self.stream, "%s._fields_ = []" % body.struct.name ! pass ! else: if body.struct.bases: assert len(body.struct.bases) == 1 *************** *** 487,536 **** (body.struct.name, align, body.struct.name) - if methods: - # Ha! Autodetect ctypes.com or comtypes ;) - if "COMMETHOD" in self.known_symbols: - self.need_COMMETHOD() - else: - self.need_STDMETHOD() - # method definitions normally span several lines. - # Before we generate them, we need to 'import' everything they need. - # So, call type_name for each field once, - for m in methods: - self.type_name(m.returns) - for a in m.iterArgTypes(): - self.type_name(a) - if "COMMETHOD" in self.known_symbols: - print >> self.stream, "%s._methods_ = [" % body.struct.name - else: - # ctypes.com needs baseclass methods listed as well - if body.struct.bases: - basename = body.struct.bases[0].name - print >> self.stream, "%s._methods_ = %s._methods + [" % \ - (body.struct.name, basename) - else: - print >> self.stream, "%s._methods_ = [" % body.struct.name - if body.struct.location: - print >> self.stream, "# %s %s" % body.struct.location - - if "COMMETHOD" in self.known_symbols: - for m in methods: - if m.location: - print >> self.stream, " # %s %s" % m.location - print >> self.stream, " COMMETHOD([], %s, '%s'," % ( - self.type_name(m.returns), - m.name) - for a in m.iterArgTypes(): - print >> self.stream, \ - " ( [], %s, )," % self.type_name(a) - print >> self.stream, " )," - else: - for m in methods: - args = [self.type_name(a) for a in m.iterArgTypes()] - print >> self.stream, " STDMETHOD(%s, '%s', [%s])," % ( - self.type_name(m.returns), - m.name, - ", ".join(args)) - print >> self.stream, "]" - def find_dllname(self, func): if hasattr(func, "dllname"): --- 479,482 ---- *************** *** 579,605 **** self._WSTRING_defined = True - _STDMETHOD_defined = False - def need_STDMETHOD(self): - if self._STDMETHOD_defined: - return - print >> self.imports, "from ctypes.com import STDMETHOD" - self._STDMETHOD_defined = True - - _COMMETHOD_defined = False - def need_COMMETHOD(self): - if self._COMMETHOD_defined: - return - print >> self.imports, "from comtypes import COMMETHOD" - self._COMMETHOD_defined = True - - _GUID_defined = False - def need_GUID(self): - if self._GUID_defined: - return - self._GUID_defined = True - modname = self.known_symbols.get("GUID") - if modname: - print >> self.imports, "from %s import GUID" % modname - _functiontypes = 0 _notfound_functiontypes = 0 --- 525,528 ---- |