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
e7db08f2
Commit
e7db08f2
authored
Jul 22, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support membership tests on cypclass objects with '__contains__'
parent
f42751b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+12
-2
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+2
-1
No files found.
Cython/Compiler/ExprNodes.py
View file @
e7db08f2
...
...
@@ -13239,7 +13239,12 @@ class PrimaryCmpNode(ExprNode, CmpNode):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
self
.
is_pycmp
=
False
entry
=
env
.
lookup_operator
(
self
.
operator
,
[
self
.
operand1
,
self
.
operand2
])
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
])
if
entry
is
None
:
if
self
.
operator
in
(
"is"
,
"is_not"
)
\
and
(
type1
.
is_ptr
or
type1
.
is_cyp_class
)
\
...
...
@@ -13345,7 +13350,12 @@ class PrimaryCmpNode(ExprNode, CmpNode):
result1
,
result2
=
operand1
.
pythran_result
(),
operand2
.
pythran_result
()
else
:
result1
,
result2
=
operand1
.
result
(),
operand2
.
result
()
if
operand1
.
type
.
is_cyp_class
and
self
.
operator
not
in
(
"is"
,
"is_not"
):
if
operand1
.
type
.
is_cyp_class
and
self
.
operator
in
(
"in"
,
"not_in"
):
return
"(%s%s->operator__contains__(%s))"
%
(
"!"
if
self
.
operator
is
"not_in"
else
""
,
result1
,
result2
)
elif
operand1
.
type
.
is_cyp_class
and
self
.
operator
not
in
(
"is"
,
"is_not"
):
result1
=
"(*%s)"
%
result1
if
self
.
is_memslice_nonecheck
:
if
operand1
.
type
.
is_memoryviewslice
:
...
...
Cython/Compiler/Symtab.py
View file @
e7db08f2
...
...
@@ -2807,7 +2807,8 @@ class CppClassScope(Scope):
'__le__'
:
'<='
,
'__ge__'
:
'>='
,
'__call__'
:
'()'
,
'__getitem__'
:
'[]'
'__getitem__'
:
'[]'
,
"__contains__"
:
"__contains__"
# not actually a c++ operator: will generate a normal function named "operator__contains__"
}
def
__init__
(
self
,
name
,
outer_scope
,
templates
=
None
):
...
...
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