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
Boxiang Sun
cython
Commits
45ea0053
Commit
45ea0053
authored
Jan 14, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More operator overloading parsing/testing.
parent
650a248b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
18 deletions
+47
-18
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+5
-2
tests/run/cpp_operators.pyx
tests/run/cpp_operators.pyx
+32
-13
tests/run/cpp_operators_helper.h
tests/run/cpp_operators_helper.h
+10
-3
No files found.
Cython/Compiler/Parsing.py
View file @
45ea0053
...
...
@@ -2058,7 +2058,7 @@ 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
):
...
...
@@ -2113,9 +2113,12 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
s
.
expect
(
']'
)
op
=
'[]'
s
.
next
()
if
op
in
[
'-'
,
'+'
]
and
s
.
sy
==
op
:
if
op
in
[
'-'
,
'+'
,
'|'
,
'&'
]
and
s
.
sy
==
op
:
op
=
op
*
2
s
.
next
()
if
s
.
sy
==
'='
:
op
+=
s
.
sy
s
.
next
()
if
op
not
in
supported_overloaded_operators
:
s
.
error
(
"Overloading operator '%s' not yet supported."
%
op
)
name
=
name
+
op
...
...
tests/run/cpp_operators.pyx
View file @
45ea0053
...
...
@@ -20,13 +20,20 @@ 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
)
def
test_unops
():
"""
>>> test_unops()
unary+
unary-
unary~
unary*
unary
+
unary
-
unary
~
unary
*
"""
cdef
TestOps
*
t
=
new
TestOps
()
print
+
t
[
0
]
...
...
@@ -38,10 +45,10 @@ def test_unops():
def
test_incdec
():
"""
>>> test_incdec()
unary++
unary--
post++
post--
unary
++
unary
--
post
++
post
--
"""
cdef
TestOps
*
t
=
new
TestOps
()
print
cython
.
preincrement
(
t
[
0
])
...
...
@@ -53,11 +60,16 @@ def test_incdec():
def
test_binop
():
"""
>>> test_binop()
binary+
binary-
binary*
binary/
binary%
binary +
binary -
binary *
binary /
binary %
binary &
binary |
binary ^
binary <<
binary >>
"""
cdef
TestOps
*
t
=
new
TestOps
()
print
t
[
0
]
+
1
...
...
@@ -65,4 +77,11 @@ def test_binop():
print
t
[
0
]
*
1
print
t
[
0
]
/
1
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 @
45ea0053
#define UN_OP(op) const char* operator op () { return "unary"#op; }
#define POST_UN_OP(op) const char* operator op (int x) { return "post"#op; }
#define BIN_OP(op) const char* operator op (int x) { return "binary"#op; }
#define UN_OP(op) const char* operator op () { return "unary
"#op; }
#define POST_UN_OP(op) const char* operator op (int x) { return "post
"#op; }
#define BIN_OP(op) const char* operator op (int x) { return "binary
"#op; }
class
TestOps
{
...
...
@@ -23,5 +23,12 @@ public:
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