[ctypes-commit] ctypes/sandbox/tools/codegen xml2py.py,1.4,1.5 codegenerator.py,1.6,1.7
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-12-17 08:27:49
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9181 Modified Files: xml2py.py codegenerator.py Log Message: Can now use '@' decorators, or PEAK's add_assignment_advisor (imported as 'call_as'). Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xml2py.py 17 Dec 2004 08:18:06 -0000 1.4 --- xml2py.py 17 Dec 2004 08:27:40 -0000 1.5 *************** *** 45,48 **** --- 45,55 ---- action="store_true", dest="verbose", + help="verbose output", + default=False) + + parser.add_option("-d", + action="store_true", + dest="use_decorators", + help="use Python 2.4 function decorators", default=False) *************** *** 66,70 **** symbols=options.symbols, expressions=options.expressions, ! verbose=options.verbose) --- 73,78 ---- symbols=options.symbols, expressions=options.expressions, ! verbose=options.verbose, ! use_decorators=options.use_decorators) Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** codegenerator.py 17 Dec 2004 08:02:19 -0000 1.6 --- codegenerator.py 17 Dec 2004 08:27:40 -0000 1.7 *************** *** 200,206 **** class Generator(object): ! def __init__(self, stream): self.done = set() self.stream = stream def StructureHead(self, head): --- 200,207 ---- class Generator(object): ! def __init__(self, stream, use_decorators=False): self.done = set() self.stream = stream + self.use_decorators = use_decorators def StructureHead(self, head): *************** *** 399,412 **** args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! print >> self.stream, "@ stdcall(%s, %s)" % \ ! (type_name(func.returns), ", ".join(["'%s'" % dllname] + args)) ! ## print >> self.stream, "%s = STDCALL('%s', %s, '%s', [%s])" % \ ! ## (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) else: ! ## print >> self.stream, "%s = CDECL('%s', %s, '%s', [%s])" % \ ! ## (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) ! print >> self.stream, "@ cdecl(%s, %s)" % \ ! (type_name(func.returns), ", ".join(["'%s'" % dllname] + args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) print >> self.stream, " return _api_(%s)" % ", ".join(argnames) --- 400,416 ---- args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! cc = "stdcall" else: ! cc = "cdecl" ! print >> self.stream ! # decorator ! if self.use_decorators: ! print >> self.stream, "@ %s(%s, %s, [%s])" % \ ! (cc, type_name(func.returns), dllname, ", ".join(args)) ! else: ! print >> self.stream, "[call_as( %s(%s, %s, [%s]) )]" % \ ! (cc, type_name(func.returns), dllname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] + # function definition print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) print >> self.stream, " return _api_(%s)" % ", ".join(argnames) *************** *** 463,467 **** ################################################################ ! def generate_code(xmlfile, outfile, expressions=None, symbols=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names --- 467,474 ---- ################################################################ ! def generate_code(xmlfile, outfile, ! expressions=None, symbols=None, ! verbose=False, ! use_decorators=False): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names *************** *** 494,507 **** items = todo ! gen = Generator(outfile) # output header print >> outfile, "from ctypes import *" ## print >> outfile, "from _support import STDCALL, CDECL" ! print >> outfile, "from deco import stdcall" print >> outfile, "def const(x): return x" print >> outfile loops = gen.generate_code(items) ! gen.print_stats(sys.stderr) ! ! print "needed %d loop(s)" % loops --- 501,517 ---- items = todo ! gen = Generator(outfile, use_decorators=use_decorators) # output header print >> outfile, "from ctypes import *" ## print >> outfile, "from _support import STDCALL, CDECL" ! if use_decorators: ! print >> outfile, "from deco import stdcall" ! else: ! print >> outfile, "from deco import stdcall, call_as" print >> outfile, "def const(x): return x" print >> outfile loops = gen.generate_code(items) ! if verbose: ! gen.print_stats(sys.stderr) ! print >> sys.stderr, "needed %d loop(s)" % loops |