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): ...@@ -3628,7 +3628,10 @@ def p_cpp_class_attribute(s, ctx):
elif s.systring == 'ctypedef': elif s.systring == 'ctypedef':
return p_ctypedef_statement(s, ctx) return p_ctypedef_statement(s, ctx)
elif s.sy == 'IDENT' and s.systring in struct_enum_union: 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: else:
node = p_c_func_or_var_declaration(s, s.position(), ctx) node = p_c_func_or_var_declaration(s, s.position(), ctx)
if decorators is not None: if decorators is not None:
......
...@@ -12,6 +12,10 @@ cdef extern from "cpp_nested_classes_support.h": ...@@ -12,6 +12,10 @@ cdef extern from "cpp_nested_classes_support.h":
my_int negate(my_int) my_int negate(my_int)
cdef cppclass TypedClass[T]: cdef cppclass TypedClass[T]:
ctypedef T MyType
union MyUnion:
T typed_value
int int_value
enum MyEnum: enum MyEnum:
value value
...@@ -30,10 +34,35 @@ def test_nested_classes(): ...@@ -30,10 +34,35 @@ def test_nested_classes():
del b_ptr del b_ptr
def test_nested_typedef(py_x): def test_nested_typedef(py_x):
"""
>>> test_nested_typedef(5)
"""
cdef A.my_int x = py_x cdef A.my_int x = py_x
assert A.negate(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): def test_nested_enum(TypedClass[double].MyEnum x):
return x == 3 """
>>> test_nested_enum(4)
False
"""
return x == 0
def test_ def test_nested_union(x):
\ No newline at end of file """
>>> 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: ...@@ -26,6 +26,6 @@ public:
union MyUnion { union MyUnion {
T typed_value; T typed_value;
int int_value; int int_value;
} };
typedef T MyType; 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