Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
89cdd5a8
Commit
89cdd5a8
authored
Sep 27, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support nested struct and unions.
parent
18e8b745
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+4
-1
tests/run/cpp_nested_classes.pyx
tests/run/cpp_nested_classes.pyx
+31
-2
tests/run/cpp_nested_classes_support.h
tests/run/cpp_nested_classes_support.h
+1
-1
No files found.
Cython/Compiler/Parsing.py
View file @
89cdd5a8
...
...
@@ -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
:
...
...
tests/run/cpp_nested_classes.pyx
View file @
89cdd5a8
...
...
@@ -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
tests/run/cpp_nested_classes_support.h
View file @
89cdd5a8
...
...
@@ -26,6 +26,6 @@ public:
union
MyUnion
{
T
typed_value
;
int
int_value
;
}
}
;
typedef
T
MyType
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment