diff options
| author | fijal <fijall@gmail.com> | 2012-06-03 21:05:52 +0200 |
|---|---|---|
| committer | fijal <fijall@gmail.com> | 2012-06-03 21:05:52 +0200 |
| commit | 7c9b37bb96501551e752784f0d37797bf3d510f4 (patch) | |
| tree | 592cf76b74de0bde85d5e0aa362b0d137b34f632 | |
| parent | c63862bb5aec9260cffe4434bbd005bb3323436f (diff) | |
| download | cffi-7c9b37bb96501551e752784f0d37797bf3d510f4.tar.gz | |
Union support
| -rw-r--r-- | ffi/cparser.py | 9 | ||||
| -rw-r--r-- | ffi/model.py | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/ffi/cparser.py b/ffi/cparser.py index c0f9bf8..f3d7a80 100644 --- a/ffi/cparser.py +++ b/ffi/cparser.py @@ -42,9 +42,8 @@ class Parser(object): if node.decls is not None: self._get_struct_or_union_type('struct', node) elif isinstance(node, pycparser.c_ast.Union): - xxx if node.decls is not None: - self._declare('union ' + node.name, node) + self._get_struct_or_union_type('union', node) elif isinstance(node, pycparser.c_ast.Enum): if node.values is not None: xxx @@ -178,7 +177,11 @@ class Parser(object): # decls = type.decls # create an empty type for now - tp = model.StructType(name, None, None, None) + if kind == 'struct': + tp = model.StructType(name, None, None, None) + else: + assert kind == 'union' + tp = model.UnionType(name, None, None, None) self._declarations[key] = tp #if decls is None and name is not None: diff --git a/ffi/model.py b/ffi/model.py index a91fed9..91a6239 100644 --- a/ffi/model.py +++ b/ffi/model.py @@ -76,9 +76,9 @@ class ArrayType(BaseType): return ffi._backend.new_array_type(ffi._get_cached_btype(self.item), self.length) -class StructType(BaseType): +class StructOrUnion(BaseType): _attrs_ = ('name',) - + is_struct_or_union_type = True def __init__(self, name, fldnames, fldtypes, fldbitsize): @@ -94,5 +94,11 @@ class StructType(BaseType): zip(self.fldnames, self.fldtypes)]) return '<struct %s {%s}>' % (self.name, fldrepr) +class StructType(StructOrUnion): def new_backend_type(self, ffi): return ffi._backend.new_struct_type(self.name) + +class UnionType(StructOrUnion): + def new_backend_type(self, ffi): + return ffi._backend.new_union_type(self.name) + |
