[pypy-commit] cffi reusable-enum-values: Make int constant available in the following declaration.
mozbugbox
noreply at buildbot.pypy.org
Wed Apr 2 09:26:18 CEST 2014
Author: mozbugbox <mozbugbox at yahoo.com.au>
Branch: reusable-enum-values
Changeset: r1486:2286da76d88b
Date: 2014-04-01 17:25 +0800
http://bitbucket.org/cffi/cffi/changeset/2286da76d88b/
Log: Make int constant available in the following declaration.
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -99,6 +99,7 @@
self._structnode2type = weakref.WeakKeyDictionary()
self._override = False
self._packed = False
+ self._int_constants = {}
def _parse(self, csource):
csource, macros = _preprocess(csource)
@@ -514,6 +515,10 @@
if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and
exprnode.op == '-'):
return -self._parse_constant(exprnode.expr)
+ # load previously defined int constant
+ if (isinstance(exprnode, pycparser.c_ast.ID) and
+ exprnode.name in self._int_constants):
+ return self._int_constants[exprnode.name]
#
if partial_length_ok:
if (isinstance(exprnode, pycparser.c_ast.ID) and
@@ -537,6 +542,7 @@
if enum.value is not None:
nextenumvalue = self._parse_constant(enum.value)
enumvalues.append(nextenumvalue)
+ self._int_constants[enum.name] = nextenumvalue
nextenumvalue += 1
enumvalues = tuple(enumvalues)
tp = model.EnumType(explicit_name, enumerators, enumvalues)
More information about the pypy-commit
mailing list