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
33609776
Commit
33609776
authored
Jul 30, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle mixed cpp / py comparisons properly
parent
8b4b461f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
4 deletions
+39
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+39
-4
No files found.
Cython/Compiler/ExprNodes.py
View file @
33609776
...
...
@@ -12889,6 +12889,11 @@ class CmpNode(object):
def
is_cpp_comparison
(
self
):
return
self
.
operand1
.
type
.
is_cpp_class
or
self
.
operand2
.
type
.
is_cpp_class
def
is_cpp_py_comparison
(
self
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
return
type1
.
is_pyobject
and
type2
.
is_cpp_class
or
type1
.
is_cpp_class
and
type2
.
is_pyobject
def
find_common_int_type
(
self
,
env
,
op
,
operand1
,
operand2
):
# type1 != type2 and at least one of the types is not a C int
type1
=
operand1
.
type
...
...
@@ -13235,12 +13240,17 @@ class PrimaryCmpNode(ExprNode, CmpNode):
def
analyse_types
(
self
,
env
):
self
.
operand1
=
self
.
operand1
.
analyse_types
(
env
)
self
.
operand2
=
self
.
operand2
.
analyse_types
(
env
)
if
self
.
is_cpp_comparison
():
if
self
.
is_cpp_py_comparison
():
return
self
.
analyse_cpp_py_comparison
(
env
)
elif
self
.
is_cpp_comparison
():
self
.
analyse_cpp_comparison
(
env
)
if
self
.
cascade
:
error
(
self
.
pos
,
"Cascading comparison not yet supported for cpp types."
)
return
self
else
:
return
self
.
analyse_non_cpp_comparison
(
env
)
def
analyse_non_cpp_comparison
(
self
,
env
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
if
is_pythran_expr
(
type1
)
or
is_pythran_expr
(
type2
):
...
...
@@ -13319,16 +13329,41 @@ class PrimaryCmpNode(ExprNode, CmpNode):
self
.
is_temp
=
1
return
self
def
analyse_cpp_py_comparison
(
self
,
env
):
operator
=
self
.
operator
if
self
.
operand2
.
type
.
is_cyp_class
and
operator
in
(
"in"
,
"not_in"
):
# swap operands
self
.
operand1
,
self
.
operand2
=
self
.
operand2
,
self
.
operand1
operator
=
"__contains__"
entry
=
None
try
:
entry
=
env
.
lookup_operator
(
operator
,
[
self
.
operand1
,
self
.
operand2
],
throw
=
True
)
except
(
PyrexTypes
.
AmbiguousCallException
,
PyrexTypes
.
NoTypeMatchCallException
):
error
(
self
.
pos
,
(
"Ambiguous operation with PyObject operand
\
n
"
"To select one of the alternatives, explicitly cast the PyObject operand
\
n
"
"To let Python handle the operation instead, cast the other operand to 'object'"
"
\
n
"
))
self
.
type
=
PyrexTypes
.
error_type
return
self
except
PyrexTypes
.
CallException
:
pass
if
entry
:
self
.
analyse_cpp_comparison
(
env
)
return
self
else
:
return
self
.
analyse_non_cpp_comparison
(
env
)
def
analyse_cpp_comparison
(
self
,
env
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
self
.
is_pycmp
=
False
operator
=
self
.
operator
if
type2
.
is_cyp_class
and
self
.
operator
in
(
"in"
,
"not_in"
):
# swap operands
self
.
operand1
,
self
.
operand2
=
self
.
operand2
,
self
.
operand1
entry
=
env
.
lookup_operator
(
"__contains__"
,
[
self
.
operand1
,
self
.
operand2
])
else
:
entry
=
env
.
lookup_operator
(
self
.
operator
,
[
self
.
operand1
,
self
.
operand2
])
operator
=
"__contains__"
entry
=
env
.
lookup_operator
(
operator
,
[
self
.
operand1
,
self
.
operand2
])
if
entry
is
None
:
if
self
.
operator
in
(
"is"
,
"is_not"
)
\
and
(
type1
.
is_ptr
or
type1
.
is_cyp_class
)
\
...
...
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