[ctypesgen] r138 committed - json: Add identifier attribute to each argtype, and Klass names (thank...

2 views
Skip to first unread message

codesite...@google.com

unread,
Feb 16, 2012, 2:12:41 PM2/16/12
to ctyp...@googlegroups.com
Revision: 138
Author: r...@sc3d.org
Date: Thu Feb 16 11:09:33 2012
Log: json: Add identifier attribute to each argtype, and Klass names
(thanks, mozbugbox).
http://code.google.com/p/ctypesgen/source/detail?r=138

Modified:
/trunk/ctypesgencore/parser/ctypesparser.py
/trunk/ctypesgencore/printer_json/printer.py

=======================================
--- /trunk/ctypesgencore/parser/ctypesparser.py Mon Sep 26 11:54:12 2011
+++ /trunk/ctypesgencore/parser/ctypesparser.py Thu Feb 16 11:09:33 2012
@@ -40,6 +40,15 @@
return CtypesEnum(tag, enumerators,
src=(specifier.filename,specifier.lineno))

+def get_decl_id(decl):
+ """Return the identifier of a given declarator"""
+ while isinstance(decl, Pointer):
+ decl = decl.pointer
+ p_name = ""
+ if decl is not None and decl.identifier is not None:
+ p_name = decl.identifier
+ return p_name
+
class CtypesParser(CParser):
'''Parse a C file for declarations that can be used by ctypes.

@@ -128,7 +137,10 @@
for param in declarator.parameters:
if param=="...":
break
- params.append(self.get_ctypes_type(param.type,
param.declarator))
+ param_name = get_decl_id(param.declarator)
+ ct = self.get_ctypes_type(param.type, param.declarator)
+ ct.identifier = param_name
+ params.append(ct)
t = CtypesFunction(t, params, variadic)

a = declarator.array
@@ -149,7 +161,10 @@
for param in declarator.parameters:
if param=="...":
break
- params.append(self.get_ctypes_type(param.type,
param.declarator))
+ param_name = get_decl_id(param.declarator)
+ ct = self.get_ctypes_type(param.type, param.declarator)
+ ct.identifier = param_name
+ params.append(ct)
t = CtypesFunction(t, params, variadic)

if declarator:
=======================================
--- /trunk/ctypesgencore/printer_json/printer.py Mon Sep 26 11:53:29 2011
+++ /trunk/ctypesgencore/printer_json/printer.py Thu Feb 16 11:09:33 2012
@@ -108,7 +108,7 @@
res = {'type': 'function',
'name': function.c_name(),
'variadic': function.variadic,
- 'args': todict(function.argtypes),
+ 'args': todict(function.argtypes, "Klass"),
'return': todict(function.restype),
}
if function.source_library:

Reply all
Reply to author
Forward
0 new messages