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
Xavier Thompson
cython
Commits
820f2980
Commit
820f2980
authored
Apr 10, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support typecast operators
parent
a45374f2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
1 deletion
+50
-1
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+8
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+3
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+4
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+35
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
820f2980
...
...
@@ -10444,12 +10444,14 @@ class TypecastNode(ExprNode):
# base_type CBaseTypeNode
# declarator CDeclaratorNode
# typecheck boolean
# overloaded boolean
#
# If used from a transform, one can if wanted specify the attribute
# "type" directly and leave base_type and declarator to None
subexprs
=
[
'operand'
]
base_type
=
declarator
=
type
=
None
overloaded
=
False
def
type_dependencies
(
self
,
env
):
return
()
...
...
@@ -10515,6 +10517,10 @@ class TypecastNode(ExprNode):
elif
self
.
operand
.
type
.
is_fused
:
self
.
operand
=
self
.
operand
.
coerce_to
(
self
.
type
,
env
)
#self.type = self.operand.type
elif
self
.
operand
.
type
.
is_cpp_class
:
operator
=
'operator '
+
self
.
type
.
declaration_code
(
''
)
entry
=
self
.
operand
.
type
.
scope
.
lookup_here
(
operator
)
self
.
overloaded
=
entry
is
not
None
if
self
.
type
.
is_ptr
and
self
.
type
.
base_type
.
is_cfunction
and
self
.
type
.
base_type
.
nogil
:
op_type
=
self
.
operand
.
type
if
op_type
.
is_ptr
:
...
...
@@ -10561,6 +10567,8 @@ class TypecastNode(ExprNode):
real_part
,
imag_part
)
else
:
if
self
.
overloaded
and
self
.
operand
.
type
.
is_cyp_class
:
operand_result
=
'(*%s)'
%
operand_result
return
self
.
type
.
cast_code
(
operand_result
)
def
get_constant_c_result_code
(
self
):
...
...
Cython/Compiler/ModuleNode.py
View file @
820f2980
...
...
@@ -953,6 +953,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
elif
attr
.
type
.
is_cfunction
:
code
.
put
(
"virtual "
)
has_virtual_methods
=
True
if
'operator '
in
attr
.
name
:
code
.
putln
(
"%s();"
%
attr
.
cname
)
continue
elif
attr
.
type
.
is_cyp_class
:
cname
=
"%s = NULL"
%
cname
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
cname
))
...
...
Cython/Compiler/Nodes.py
View file @
820f2980
...
...
@@ -2704,6 +2704,9 @@ class CFuncDefNode(FuncDefNode):
dll_linkage
=
None
modifiers
=
code
.
build_function_modifiers
(
self
.
entry
.
func_modifiers
)
if
'operator '
in
entity
:
header
=
entity
else
:
header
=
self
.
return_type
.
declaration_code
(
entity
,
dll_linkage
=
dll_linkage
)
#print (storage_class, modifiers, header)
needs_proto
=
self
.
is_c_class_method
...
...
Cython/Compiler/Symtab.py
View file @
820f2980
...
...
@@ -2550,6 +2550,41 @@ class CppClassScope(Scope):
return_type
=
type
.
return_type
)
type
.
original_alloc_type
=
type
.
args
[
0
]
else
:
operator
=
self
.
operator_table
.
get
(
name
,
None
)
if
operator
:
name
=
'operator'
+
operator
elif
name
.
startswith
(
'__'
)
and
name
.
endswith
(
'__'
):
stripped_name
=
name
[
2
:
-
2
]
signed
=
1
longness
=
0
ctypename
=
None
exploded_name
=
stripped_name
.
split
(
'_'
)
for
index
,
token
in
enumerate
(
exploded_name
):
# Basically, it is the same code than Parsing.p_sign_and_longness
if
token
==
'unsigned'
:
signed
=
0
elif
token
==
'signed'
:
signed
=
2
elif
token
==
'short'
:
longness
=
-
1
elif
token
==
'long'
:
longness
+=
1
else
:
ctypename
=
'_'
.
join
(
exploded_name
[
index
:])
break
known_type
=
PyrexTypes
.
simple_c_type
(
signed
,
longness
,
ctypename
)
if
not
known_type
:
if
stripped_name
==
"bool"
:
# This one is hardcoded because it is declared as an int
# in PyrexTypes
name
=
'operator bool'
type
.
args
=
[]
else
:
known_type
=
self
.
lookup_type
(
stripped_name
)
if
known_type
:
name
=
'operator '
+
known_type
.
declaration_code
(
''
)
type
.
args
=
[]
if
name
in
(
'<init>'
,
'<del>'
)
and
type
.
nogil
:
for
base
in
self
.
type
.
base_classes
:
...
...
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