summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <armin.rigo@gmail.com>2017-03-15 20:22:58 +0000
committerArmin Rigo <armin.rigo@gmail.com>2017-03-15 20:22:58 +0000
commit85fbc59d662054d2483985564451a2d7b598e87c (patch)
tree121b0adf7a6435a9a8a58e9d972acfed33947a54
parent01bd5815e6f3eb8fb65c96028eb10f0972d92be4 (diff)
parent3dee179b835b14b8b3053013e5972cecada574c5 (diff)
downloadcffi-85fbc59d662054d2483985564451a2d7b598e87c.tar.gz
Merged in realitix/cffi/binary_enum (pull request #78)
Add operation support in enum
-rw-r--r--cffi/cparser.py10
-rw-r--r--testing/cffi0/test_parsing.py3
2 files changed, 12 insertions, 1 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py
index 3d5caed..0c8ef3f 100644
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -803,6 +803,16 @@ class Parser(object):
"the actual array length in this context"
% exprnode.coord.line)
#
+ if (isinstance(exprnode, pycparser.c_ast.BinaryOp) and
+ exprnode.op == '+'):
+ return (self._parse_constant(exprnode.left) +
+ self._parse_constant(exprnode.right))
+ #
+ if (isinstance(exprnode, pycparser.c_ast.BinaryOp) and
+ exprnode.op == '-'):
+ return (self._parse_constant(exprnode.left) -
+ self._parse_constant(exprnode.right))
+ #
raise FFIError(":%d: unsupported expression: expected a "
"simple numeric constant" % exprnode.coord.line)
diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
index 02b0f4e..4678983 100644
--- a/testing/cffi0/test_parsing.py
+++ b/testing/cffi0/test_parsing.py
@@ -386,13 +386,14 @@ def test_const_pointer_to_pointer():
def test_enum():
ffi = FFI()
ffi.cdef("""
- enum Enum { POS = +1, TWO = 2, NIL = 0, NEG = -1};
+ enum Enum { POS = +1, TWO = 2, NIL = 0, NEG = -1, OP = (POS+TWO)-1};
""")
C = ffi.dlopen(None)
assert C.POS == 1
assert C.TWO == 2
assert C.NIL == 0
assert C.NEG == -1
+ assert C.OP == 2
def test_stdcall():
ffi = FFI()