[ctypesgen] r141 committed - Fix enums in JSON output; fixes issue #30 (thanks, mozbugbox).

0 views
Skip to first unread message

codesite...@google.com

unread,
Feb 24, 2012, 7:54:20 AM2/24/12
to ctyp...@googlegroups.com
Revision: 141
Author: r...@sc3d.org
Date: Fri Feb 24 04:53:51 2012
Log: Fix enums in JSON output; fixes issue #30 (thanks, mozbugbox).
http://code.google.com/p/ctypesgen/source/detail?r=141

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

=======================================
--- /trunk/ctypesgencore/parser/datacollectingparser.py Sat Mar 13 16:47:48
2010
+++ /trunk/ctypesgencore/parser/datacollectingparser.py Fri Feb 24 04:53:51
2012
@@ -218,7 +218,7 @@
if ctypeenum.opaque:
if tag not in self.already_seen_opaque_enums:
enum=EnumDescription(ctypeenum.tag,
- ctypeenum.enumerators,
+ None,
ctypeenum,
src = (filename,str(lineno)))
enum.opaque = True
@@ -235,12 +235,13 @@
enum.opaque = False
enum.ctype = ctypeenum
enum.src = ctypeenum.src
+ enum.members = ctypeenum.enumerators

del self.already_seen_opaque_enums[tag]

else:
enum=EnumDescription(ctypeenum.tag,
- None,
+ ctypeenum.enumerators,
src=(filename,str(lineno)),
ctype=ctypeenum)
enum.opaque = False
=======================================
--- /trunk/ctypesgencore/printer_json/printer.py Thu Feb 16 11:09:33 2012
+++ /trunk/ctypesgencore/printer_json/printer.py Fri Feb 24 04:53:51 2012
@@ -13,7 +13,7 @@
return os.path.join(basedir,name)

# From
http://stackoverflow.com/questions/1036409/recursively-convert-python-object-graph-to-dictionary
-def todict(obj, classkey=None):
+def todict(obj, classkey="Klass"):
if isinstance(obj, dict):
for k in obj.keys():
obj[k] = todict(obj[k], classkey)
@@ -99,16 +99,24 @@
pass

def print_enum(self,enum):
- return {'type': 'enum',
+ res = {'type': 'enum',
'name': enum.tag,
}
- # Values of enumerator are output as constants.
+
+ if not enum.opaque:
+ res['fields'] = []
+ for name, ctype in enum.members:
+ field = {'name': name,
+ 'ctype': todict(ctype),
+ }
+ res['fields'].append(field)
+ return res

def print_function(self, function):
res = {'type': 'function',
'name': function.c_name(),
'variadic': function.variadic,
- 'args': todict(function.argtypes, "Klass"),
+ 'args': todict(function.argtypes),
'return': todict(function.restype),
}
if function.source_library:

Reply all
Reply to author
Forward
0 new messages