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
Gwenaël Samain
cython
Commits
5d9787ee
Commit
5d9787ee
authored
Nov 23, 2018
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Type inference for stack-allocated C++ types.
parent
090f9ba2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-0
tests/run/cpp_type_inference.pyx
tests/run/cpp_type_inference.pyx
+37
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
5d9787ee
...
@@ -5362,6 +5362,9 @@ class CallNode(ExprNode):
...
@@ -5362,6 +5362,9 @@ class CallNode(ExprNode):
return
PyrexTypes
.
c_double_type
return
PyrexTypes
.
c_double_type
elif
function
.
entry
.
name
in
Builtin
.
types_that_construct_their_instance
:
elif
function
.
entry
.
name
in
Builtin
.
types_that_construct_their_instance
:
return
result_type
return
result_type
func_type
=
self
.
function
.
analyse_as_type
(
env
)
if
func_type
.
is_struct_or_union
or
func_type
.
is_cpp_class
:
return
func_type
return
py_object_type
return
py_object_type
def
type_dependencies
(
self
,
env
):
def
type_dependencies
(
self
,
env
):
...
...
tests/run/cpp_type_inference.pyx
View file @
5d9787ee
...
@@ -12,6 +12,11 @@ cdef extern from "shapes.h" namespace "shapes":
...
@@ -12,6 +12,11 @@ cdef extern from "shapes.h" namespace "shapes":
cdef
cppclass
Square
(
Shape
):
cdef
cppclass
Square
(
Shape
):
Square
(
int
)
Square
(
int
)
cdef
cppclass
Empty
(
Shape
):
Empty
()
cdef
Empty
make_Empty
"shapes::Empty"
()
from
cython
cimport
typeof
from
cython
cimport
typeof
from
cython.operator
cimport
dereference
as
d
from
cython.operator
cimport
dereference
as
d
...
@@ -48,3 +53,35 @@ def test_derived_types(int size, bint round):
...
@@ -48,3 +53,35 @@ def test_derived_types(int size, bint round):
ptr
=
new
Square
(
size
)
ptr
=
new
Square
(
size
)
print
typeof
(
ptr
)
print
typeof
(
ptr
)
del
ptr
del
ptr
def
test_stack_allocated
(
bint
b
=
True
):
"""
>>> test_stack_allocated()
"""
e1
=
Empty
()
e2
=
Empty
()
e
=
e1
if
b
else
e2
assert
typeof
(
e1
)
==
"Empty"
,
typeof
(
e1
)
assert
typeof
(
e2
)
==
"Empty"
,
typeof
(
e2
)
assert
typeof
(
e
)
==
"Empty"
,
typeof
(
e
)
cdef
extern
from
*
:
"""
template <typename T>
struct MyTemplate {};
"""
cdef
cppclass
MyTemplate
[
T
]:
MyTemplate
()
def
test_template_types
():
"""
>>> test_template_types()
"""
t_stack
=
MyTemplate
[
int
]()
assert
typeof
(
t_stack
)
==
"MyTemplate[int]"
,
typeof
(
t_stack
)
t_ptr
=
new
MyTemplate
[
double
]()
try
:
assert
typeof
(
t_ptr
)
==
"MyTemplate[double] *"
,
typeof
(
t_ptr
)
finally
:
del
t_ptr
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