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
6c5aea0a
Commit
6c5aea0a
authored
Apr 10, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support typecast operators
parent
802787ca
Changes
4
Hide 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 @
6c5aea0a
...
@@ -10518,12 +10518,14 @@ class TypecastNode(ExprNode):
...
@@ -10518,12 +10518,14 @@ class TypecastNode(ExprNode):
# base_type CBaseTypeNode
# base_type CBaseTypeNode
# declarator CDeclaratorNode
# declarator CDeclaratorNode
# typecheck boolean
# typecheck boolean
# overloaded boolean
#
#
# If used from a transform, one can if wanted specify the attribute
# If used from a transform, one can if wanted specify the attribute
# "type" directly and leave base_type and declarator to None
# "type" directly and leave base_type and declarator to None
subexprs
=
[
'operand'
]
subexprs
=
[
'operand'
]
base_type
=
declarator
=
type
=
None
base_type
=
declarator
=
type
=
None
overloaded
=
False
def
type_dependencies
(
self
,
env
):
def
type_dependencies
(
self
,
env
):
return
()
return
()
...
@@ -10589,6 +10591,10 @@ class TypecastNode(ExprNode):
...
@@ -10589,6 +10591,10 @@ class TypecastNode(ExprNode):
elif
self
.
operand
.
type
.
is_fused
:
elif
self
.
operand
.
type
.
is_fused
:
self
.
operand
=
self
.
operand
.
coerce_to
(
self
.
type
,
env
)
self
.
operand
=
self
.
operand
.
coerce_to
(
self
.
type
,
env
)
#self.type = self.operand.type
#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
:
if
self
.
type
.
is_ptr
and
self
.
type
.
base_type
.
is_cfunction
and
self
.
type
.
base_type
.
nogil
:
op_type
=
self
.
operand
.
type
op_type
=
self
.
operand
.
type
if
op_type
.
is_ptr
:
if
op_type
.
is_ptr
:
...
@@ -10635,6 +10641,8 @@ class TypecastNode(ExprNode):
...
@@ -10635,6 +10641,8 @@ class TypecastNode(ExprNode):
real_part
,
real_part
,
imag_part
)
imag_part
)
else
:
else
:
if
self
.
overloaded
and
self
.
operand
.
type
.
is_cyp_class
:
operand_result
=
'(*%s)'
%
operand_result
return
self
.
type
.
cast_code
(
operand_result
)
return
self
.
type
.
cast_code
(
operand_result
)
def
get_constant_c_result_code
(
self
):
def
get_constant_c_result_code
(
self
):
...
...
Cython/Compiler/ModuleNode.py
View file @
6c5aea0a
...
@@ -953,6 +953,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -953,6 +953,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
elif
attr
.
type
.
is_cfunction
:
elif
attr
.
type
.
is_cfunction
:
code
.
put
(
"virtual "
)
code
.
put
(
"virtual "
)
has_virtual_methods
=
True
has_virtual_methods
=
True
if
'operator '
in
attr
.
name
:
code
.
putln
(
"%s();"
%
attr
.
cname
)
continue
elif
attr
.
type
.
is_cyp_class
:
elif
attr
.
type
.
is_cyp_class
:
cname
=
"%s = NULL"
%
cname
cname
=
"%s = NULL"
%
cname
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
cname
))
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
cname
))
...
...
Cython/Compiler/Nodes.py
View file @
6c5aea0a
...
@@ -2702,7 +2702,10 @@ class CFuncDefNode(FuncDefNode):
...
@@ -2702,7 +2702,10 @@ class CFuncDefNode(FuncDefNode):
dll_linkage
=
None
dll_linkage
=
None
modifiers
=
code
.
build_function_modifiers
(
self
.
entry
.
func_modifiers
)
modifiers
=
code
.
build_function_modifiers
(
self
.
entry
.
func_modifiers
)
header
=
self
.
return_type
.
declaration_code
(
entity
,
dll_linkage
=
dll_linkage
)
if
'operator '
in
entity
:
header
=
entity
else
:
header
=
self
.
return_type
.
declaration_code
(
entity
,
dll_linkage
=
dll_linkage
)
#print (storage_class, modifiers, header)
#print (storage_class, modifiers, header)
needs_proto
=
self
.
is_c_class_method
needs_proto
=
self
.
is_c_class_method
if
self
.
template_declaration
:
if
self
.
template_declaration
:
...
...
Cython/Compiler/Symtab.py
View file @
6c5aea0a
...
@@ -2553,6 +2553,41 @@ class CppClassScope(Scope):
...
@@ -2553,6 +2553,41 @@ class CppClassScope(Scope):
return_type
=
type
.
return_type
)
return_type
=
type
.
return_type
)
type
.
original_alloc_type
=
type
.
args
[
0
]
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
:
if
name
in
(
'<init>'
,
'<del>'
)
and
type
.
nogil
:
for
base
in
self
.
type
.
base_classes
:
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