Permalink
Browse files

Handle anonymous enums in classifiy instead of main script.

  • Loading branch information...
1 parent 107001e commit d41e4bfc1a70c3b1ead63f27c587b3cbbba56927 Cournapeau David committed Dec 3, 2008
Showing with 7 additions and 14 deletions.
  1. +6 −2 cycodegenlib/misc.py
  2. +1 −12 scripts/xml2cython.py
View
8 cycodegenlib/misc.py
@@ -28,6 +28,7 @@ def classify(items, locations, lfilter=None):
tpdefs = {}
enumvals = {}
enums = {}
+ anoenums = {}
structs = {}
vars = {}
unions = {}
@@ -44,7 +45,10 @@ def classify(items, locations, lfilter=None):
elif isinstance(it, typedesc.EnumValue):
enumvals[it.name] = it
elif isinstance(it, typedesc.Enumeration):
- enums[it.name] = it
+ if it.name:
+ enums[it.name] = it
+ else:
+ anoenums[it] = it
elif isinstance(it, typedesc.Typedef):
tpdefs[it.name] = it
elif isinstance(it, typedesc.Structure):
@@ -61,4 +65,4 @@ def classify(items, locations, lfilter=None):
else:
print "No location for item %s, ignoring" % str(it)
- return funcs, tpdefs, enumvals, enums, structs, unions, vars
+ return funcs, tpdefs, enumvals, enums, structs, unions, vars, anoenums
View
13 scripts/xml2cython.py
@@ -37,7 +37,7 @@ def generate_main(header, xml, output, lfilter=None, ffilter=None, funcs_list=No
output.write("cdef extern from '%s':\n" % header)
- funcs, tpdefs, enumvals, enums, structs, vars, unions = \
+ funcs, tpdefs, enumvals, enums, structs, vars, unions, anoenums = \
classify(items, locations, lfilter=lfilter)
if ffilter is None:
@@ -56,18 +56,7 @@ def generate_main(header, xml, output, lfilter=None, ffilter=None, funcs_list=No
needed = puller.values()
# Filter "anonymous" enumerations according to location
- # XXX: we should do this in classify
- from ctypeslib.codegen import typedesc
if lfilter:
- anoenums = {}
- for it in items:
- try:
- origin = locations[it][0]
- if lfilter(origin):
- if isinstance(it, typedesc.Enumeration):
- anoenums[it] = it
- except KeyError:
- pass
anoenumvals = []
for v in anoenums.values():
anoenumvals.extend(v.values)

0 comments on commit d41e4bf

Please sign in to comment.