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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
668b616b
Commit
668b616b
authored
Jun 14, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use dynamic_cast when downcasting from a base to a cypclass
parent
0faa42cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+20
-7
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
668b616b
...
...
@@ -10862,8 +10862,13 @@ class TypecastNode(ExprNode):
real_part
,
imag_part
)
else
:
if
self
.
overloaded
and
self
.
operand
.
type
.
is_cyp_class
:
operand_result
=
'(*%s)'
%
operand_result
operand_type
=
self
.
operand
.
type
if
operand_type
.
is_cyp_class
:
if
self
.
overloaded
:
operand_result
=
'(*%s)'
%
operand_result
# use dynamic cast when dowcasting from a base to a cypclass
if
self
.
type
.
is_cyp_class
and
operand_type
in
self
.
type
.
mro
():
return
self
.
type
.
dynamic_cast_code
(
operand_result
)
return
self
.
type
.
cast_code
(
operand_result
)
def
get_constant_c_result_code
(
self
):
...
...
@@ -10889,11 +10894,19 @@ class TypecastNode(ExprNode):
elif
self
.
type
.
is_cyp_class
:
star
=
"*"
if
self
.
overloaded
else
""
operand_result
=
"%s%s"
%
(
star
,
self
.
operand
.
result
())
code
.
putln
(
"%s = (%s)(%s);"
%
(
self
.
result
(),
self
.
type
.
declaration_code
(
''
),
operand_result
))
# use dynamic cast when dowcasting from a base to a cypclass
if
self
.
operand
.
type
in
self
.
type
.
mro
():
code
.
putln
(
"%s = dynamic_cast<%s>(%s);"
%
(
self
.
result
(),
self
.
type
.
declaration_code
(
''
),
operand_result
))
else
:
code
.
putln
(
"%s = (%s)(%s);"
%
(
self
.
result
(),
self
.
type
.
declaration_code
(
''
),
operand_result
))
code
.
put_cyincref
(
self
.
result
())
...
...
Cython/Compiler/PyrexTypes.py
View file @
668b616b
...
...
@@ -4153,6 +4153,9 @@ class CypClassType(CppClassType):
def
cast_code
(
self
,
expr_code
):
return
"((%s)%s)"
%
(
self
.
declaration_code
(
''
),
expr_code
)
def
dynamic_cast_code
(
self
,
expr_code
):
return
"dynamic_cast<%s>(%s)"
%
(
self
.
declaration_code
(
''
),
expr_code
)
def
assignable_from_resolved_type
(
self
,
other_type
):
if
other_type
.
is_ptr
and
other_type
.
base_type
.
is_cpp_class
and
other_type
.
base_type
.
is_subclass
(
self
)
or
other_type
.
is_null_ptr
:
return
1
...
...
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