[ctypes-commit] ctypes/sandbox/tools/codegen codegenerator.py,1.31,1.32
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-01-21 20:17:07
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12611 Modified Files: codegenerator.py Log Message: After code for a type descriptions is emitted, the name (if it has one) is added to self.names. So, Alias type descriptions can try to generate their dependencies, and then look if they are resolved. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** codegenerator.py 21 Jan 2005 19:50:33 -0000 1.31 --- codegenerator.py 21 Jan 2005 20:16:56 -0000 1.32 *************** *** 2,16 **** # Type descriptions are collections of typedesc instances. - # Problems: - # - # SDL.h somewhere contains #define main SDL_main - # - # SDL_main is known to be a Function, but cannot be found in the dll - # (probably because it is in the static library SDLmain.lib). - # So, SDL_main cannot be generated because of the unknown dll. - # - # Hm, should self.generate() return whether code was actually generated, - # or would it be better to have a namespace of generated names? - import typedesc, sys --- 2,5 ---- *************** *** 142,148 **** class Generator(object): def __init__(self, stream, use_decorators=False): - self.done = set() self.stream = stream self.use_decorators = use_decorators def init_value(self, t, init): --- 131,138 ---- class Generator(object): def __init__(self, stream, use_decorators=False): self.stream = stream self.use_decorators = use_decorators + self.done = set() # type descriptions that have been generated + self.names = set() # names that have been generated def init_value(self, t, init): *************** *** 243,253 **** if alias in self.done: return if alias.typ is not None: # we can resolve it self.generate(alias.typ) ! print >> self.stream, "%s = %s # alias" % (alias.name, alias.alias) ! else: # we cannot resolve it ! print >> self.stream, "# %s = %s # alias" % (alias.name, alias.alias) - self.done.add(alias) def Macro(self, macro): --- 233,247 ---- if alias in self.done: return + self.done.add(alias) if alias.typ is not None: # we can resolve it self.generate(alias.typ) ! if alias.alias in self.names: ! print >> self.stream, "%s = %s # alias" % (alias.name, alias.alias) ! self.names.add(alias.name) ! return ! # we cannot resolve it ! print >> self.stream, "# %s = %s # alias" % (alias.name, alias.alias) ! print "# unresolved alias: %s = %s" % (alias.name, alias.alias) def Macro(self, macro): *************** *** 265,268 **** --- 259,263 ---- else: print >> self.stream, code + self.names.add(macro.name) self.done.add(macro) *************** *** 289,292 **** --- 284,288 ---- print >> self.stream, " # %s %s" % head.struct.location print >> self.stream, " pass" + self.names.add(head.struct.name) self.done.add(head) *************** *** 319,322 **** --- 315,319 ---- print >> self.stream, "%s = %s # typedef" % \ (tp.name, self.type_name(tp.typ)) + self.names.add(tp.name) self.done.add(tp) *************** *** 379,382 **** --- 376,380 ---- value, self.type_name(tp.typ, False)) + self.names.add(tp.name) _enumvalues = 0 *************** *** 387,390 **** --- 385,389 ---- print >> self.stream, \ "%s = %d # enum %s" % (tp.name, value, tp.enumeration.name or "") + self.names.add(tp.name) self._enumvalues += 1 self.done.add(tp) *************** *** 618,626 **** print >> self.stream, " # %s %s" % func.location print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) - ## print >> self.stream, " return _api_(%s)" % ", ".join(argnames) if not self.use_decorators: print >> self.stream, "%s = %s(%s, %s, [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream self._functiontypes += 1 else: --- 617,625 ---- print >> self.stream, " # %s %s" % func.location print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: print >> self.stream, "%s = %s(%s, %s, [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream + self.names.add(func.name) self._functiontypes += 1 else: |