Commit 89cdd5a8 authored by Robert Bradshaw's avatar Robert Bradshaw

Support nested struct and unions.

parent 18e8b745
......@@ -3628,7 +3628,10 @@ def p_cpp_class_attribute(s, ctx):
elif s.systring == 'ctypedef':
return p_ctypedef_statement(s, ctx)
elif s.sy == 'IDENT' and s.systring in struct_enum_union:
return p_struct_enum(s, s.position(), ctx)
if s.systring != 'enum':
return p_cpp_class_definition(s, s.position(), ctx)
else:
return p_struct_enum(s, s.position(), ctx)
else:
node = p_c_func_or_var_declaration(s, s.position(), ctx)
if decorators is not None:
......
......@@ -12,6 +12,10 @@ cdef extern from "cpp_nested_classes_support.h":
my_int negate(my_int)
cdef cppclass TypedClass[T]:
ctypedef T MyType
union MyUnion:
T typed_value
int int_value
enum MyEnum:
value
......@@ -30,10 +34,35 @@ def test_nested_classes():
del b_ptr
def test_nested_typedef(py_x):
"""
>>> test_nested_typedef(5)
"""
cdef A.my_int x = py_x
assert A.negate(x) == -py_x
def test_typed_nested_typedef(x):
"""
>>> test_typed_nested_typedef(4)
(4, 4.0)
"""
cdef TypedClass[int].MyType ix = x
cdef TypedClass[double].MyType dx = x
return ix, dx
def test_nested_enum(TypedClass[double].MyEnum x):
return x == 3
"""
>>> test_nested_enum(4)
False
"""
return x == 0
def test_
\ No newline at end of file
def test_nested_union(x):
"""
>>> test_nested_union(2)
2.0
"""
cdef TypedClass[double].MyUnion u
u.int_value = x
assert u.int_value == x
u.typed_value = x
return u.typed_value
......@@ -26,6 +26,6 @@ public:
union MyUnion {
T typed_value;
int int_value;
}
};
typedef T MyType;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment