[ctypes-users] Proposal: record argument names in code generation
Brought to you by:
theller
From: Mike C. F. <mcf...@vr...> - 2005-08-21 02:58:55
|
I realise that the default code generator doesn't use the argument names, but recording the names of argument allows subclasses (such as the one I build for OpenGL-ctypes) to access the information. Otherwise will require re-implementing the gccxmlparser etc. The changes to record argument names are fairly minimal: Add an argument name to add_argument. Record the name during the gcc parse by passing it to add_argument. Use the names when generating signatures if they are available. Obviously that last step is optional, but it would seem to make sense. However, if there are any cross-language issues (e.g. C identifiers that can't be used as Python identifiers) may want to punt on it for now. Enjoy all, Mike *** typedesc.py Sun Jul 24 18:28:01 2005 --- .#typedesc.py.1.1 Thu May 12 20:42:12 2005 *************** *** 5,12 **** from sets import Set as set class _HasArgs(object): ! def add_argument(self, arg): self.arguments.append(arg) ################ --- 5,15 ---- from sets import Set as set class _HasArgs(object): ! def add_argument(self, arg, name=None): self.arguments.append(arg) + if not hasattr( self, 'argnames' ): + self.argnames = [] + self.argnames.append( name ) ################ *** gccxmlparser.py Sun Jul 24 18:28:01 2005 --- .#gccxmlparser.py.1.2 Thu May 12 23:00:09 2005 *************** *** 225,231 **** typ = attrs["type"] parent = self.context[-1] if parent is not None: ! parent.add_argument(typ) # name? # enumerations --- 225,231 ---- typ = attrs["type"] parent = self.context[-1] if parent is not None: ! parent.add_argument(typ, attrs.get('name')) # name? # enumerations *************** *** 620,625 **** --- 589,596 ---- print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] + if hasattr( func, 'argnames'): + argnames = [ (name or number) for (name,number) in zip(func.argnames,argnames)] # function definition print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) if func.location: -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |