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
bd9e529d
Commit
bd9e529d
authored
Jan 14, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ cmp operators.
parent
45ea0053
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
8 deletions
+48
-8
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+9
-6
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+5
-1
tests/run/cpp_operators.pyx
tests/run/cpp_operators.pyx
+26
-0
tests/run/cpp_operators_helper.h
tests/run/cpp_operators_helper.h
+8
-1
No files found.
Cython/Compiler/ExprNodes.py
View file @
bd9e529d
...
...
@@ -5303,9 +5303,9 @@ class CmpNode(object):
def
is_cpp_comparison
(
self
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
if
type1
.
is_
ptr
:
if
type1
.
is_
reference
:
type1
=
type1
.
base_type
if
type2
.
is_
ptr
:
if
type2
.
is_
reference
:
type2
=
type2
.
base_type
return
type1
.
is_cpp_class
or
type2
.
is_cpp_class
...
...
@@ -5569,6 +5569,9 @@ class PrimaryCmpNode(ExprNode, CmpNode):
self
.
operand2
.
analyse_types
(
env
)
if
self
.
is_cpp_comparison
():
self
.
analyse_cpp_comparison
(
env
)
if
self
.
cascade
:
error
(
self
.
pos
,
"Cascading comparison not yet supported for cpp types."
)
return
if
self
.
cascade
:
self
.
cascade
.
analyse_types
(
env
)
...
...
@@ -5601,9 +5604,9 @@ class PrimaryCmpNode(ExprNode, CmpNode):
def
analyse_cpp_comparison
(
self
,
env
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
if
type1
.
is_
ptr
:
if
type1
.
is_
reference
:
type1
=
type1
.
base_type
if
type2
.
is_
ptr
:
if
type2
.
is_
reference
:
type2
=
type2
.
base_type
entry
=
env
.
lookup
(
type1
.
name
)
function
=
entry
.
type
.
scope
.
lookup
(
"operator%s"
%
self
.
operator
)
...
...
@@ -5611,12 +5614,12 @@ class PrimaryCmpNode(ExprNode, CmpNode):
error
(
self
.
pos
,
"Invalid types for '%s' (%s, %s)"
%
(
self
.
operator
,
type1
,
type2
))
return
entry
=
PyrexTypes
.
best_match
([
self
.
operand
1
,
self
.
operand
2
],
function
.
all_alternatives
(),
self
.
pos
)
entry
=
PyrexTypes
.
best_match
([
self
.
operand2
],
function
.
all_alternatives
(),
self
.
pos
)
if
entry
is
None
:
self
.
type
=
PyrexTypes
.
error_type
self
.
result_code
=
"<error>"
return
if
(
entry
.
type
.
is_ptr
)
:
if
entry
.
type
.
is_ptr
:
self
.
type
=
entry
.
type
.
base_type
.
return_type
else
:
self
.
type
=
entry
.
type
.
return_type
...
...
Cython/Compiler/Parsing.py
View file @
bd9e529d
...
...
@@ -2058,7 +2058,11 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
exception_value
=
exc_val
,
exception_check
=
exc_check
,
nogil
=
nogil
or
ctx
.
nogil
or
with_gil
,
with_gil
=
with_gil
)
supported_overloaded_operators
=
set
([
'+'
,
'-'
,
'*'
,
'/'
,
'%'
,
'++'
,
'--'
,
'~'
,
'|'
,
'&'
,
'^'
,
'<<'
,
'>>'
])
supported_overloaded_operators
=
set
([
'+'
,
'-'
,
'*'
,
'/'
,
'%'
,
'++'
,
'--'
,
'~'
,
'|'
,
'&'
,
'^'
,
'<<'
,
'>>'
,
'=='
,
'!='
,
'>='
,
'>'
,
'<='
,
'<'
,
])
def
p_c_simple_declarator
(
s
,
ctx
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
):
...
...
tests/run/cpp_operators.pyx
View file @
bd9e529d
...
...
@@ -27,6 +27,13 @@ cdef extern from "cpp_operators_helper.h":
char
*
operator
<<
(
int
)
char
*
operator
>>
(
int
)
char
*
operator
==
(
int
)
char
*
operator
!=
(
int
)
char
*
operator
>=
(
int
)
char
*
operator
<=
(
int
)
char
*
operator
>
(
int
)
char
*
operator
<
(
int
)
def
test_unops
():
"""
>>> test_unops()
...
...
@@ -85,3 +92,22 @@ def test_binop():
print
t
[
0
]
<<
1
print
t
[
0
]
>>
1
del
t
def
test_cmp
():
"""
>>> test_cmp()
binary ==
binary !=
binary >=
binary >
binary <=
binary <
"""
cdef
TestOps
*
t
=
new
TestOps
()
print
t
[
0
]
==
1
print
t
[
0
]
!=
1
print
t
[
0
]
>=
1
print
t
[
0
]
>
1
print
t
[
0
]
<=
1
print
t
[
0
]
<
1
del
t
tests/run/cpp_operators_helper.h
View file @
bd9e529d
...
...
@@ -30,5 +30,12 @@ public:
BIN_OP
(
|
);
BIN_OP
(
&
);
BIN_OP
(
^
);
BIN_OP
(
==
);
BIN_OP
(
!=
);
BIN_OP
(
<=
);
BIN_OP
(
<
);
BIN_OP
(
>=
);
BIN_OP
(
>
);
};
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