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
946cfc01
Commit
946cfc01
authored
Jun 28, 2012
by
scoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #135 from robertwb/bang
Cython bang operator overloading.
parents
391a336b
c96fc2de
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
5 deletions
+21
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+14
-1
Cython/Compiler/Lexicon.py
Cython/Compiler/Lexicon.py
+1
-1
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+1
-1
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+2
-2
tests/run/cpp_operators.pyx
tests/run/cpp_operators.pyx
+3
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
946cfc01
...
...
@@ -6939,7 +6939,20 @@ class NotNode(ExprNode):
def
analyse_types
(
self
,
env
):
self
.
operand
.
analyse_types
(
env
)
self
.
operand
=
self
.
operand
.
coerce_to_boolean
(
env
)
if
self
.
operand
.
type
.
is_cpp_class
:
type
=
self
.
operand
.
type
function
=
type
.
scope
.
lookup
(
"operator!"
)
if
not
function
:
error
(
self
.
pos
,
"'!' operator not defined for %s"
%
(
type
))
self
.
type
=
PyrexTypes
.
error_type
return
func_type
=
function
.
type
if
func_type
.
is_ptr
:
func_type
=
func_type
.
base_type
self
.
type
=
func_type
.
return_type
else
:
self
.
operand
=
self
.
operand
.
coerce_to_boolean
(
env
)
def
calculate_result_code
(
self
):
return
"(!%s)"
%
self
.
operand
.
result
()
...
...
Cython/Compiler/Lexicon.py
View file @
946cfc01
...
...
@@ -73,7 +73,7 @@ def make_lexicon():
deco
=
Str
(
"@"
)
bra
=
Any
(
"([{"
)
ket
=
Any
(
")]}"
)
punct
=
Any
(
":,;+-*/|&<>=.%`~^?"
)
punct
=
Any
(
":,;+-*/|&<>=.%`~^?
!
"
)
diphthong
=
Str
(
"=="
,
"<>"
,
"!="
,
"<="
,
">="
,
"<<"
,
">>"
,
"**"
,
"//"
,
"+="
,
"-="
,
"*="
,
"/="
,
"%="
,
"|="
,
"^="
,
"&="
,
"<<="
,
">>="
,
"**="
,
"//="
,
"->"
)
...
...
Cython/Compiler/Parsing.py
View file @
946cfc01
...
...
@@ -2297,7 +2297,7 @@ supported_overloaded_operators = set([
'+'
,
'-'
,
'*'
,
'/'
,
'%'
,
'++'
,
'--'
,
'~'
,
'|'
,
'&'
,
'^'
,
'<<'
,
'>>'
,
','
,
'=='
,
'!='
,
'>='
,
'>'
,
'<='
,
'<'
,
'[]'
,
'()'
,
'[]'
,
'()'
,
'!'
,
])
def
p_c_simple_declarator
(
s
,
ctx
,
empty
,
is_type
,
cmethod_flag
,
...
...
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
946cfc01
...
...
@@ -337,9 +337,9 @@ syntax as C++. Cython provides functions replacing these operators in
a special module ``cython.operator``. The functions provided are:
* ``cython.operator.dereference`` for dereferencing. ``dereference(foo)``
will produce the C++ code ``*
foo
``
will produce the C++ code ``*
(foo)
``
* ``cython.operator.preincrement`` for pre-incrementation. ``preincrement(foo)``
will produce the C++ code ``++
foo
``
will produce the C++ code ``++
(foo)
``
* ...
These functions need to be cimported. Of course, one can use a
...
...
tests/run/cpp_operators.pyx
View file @
946cfc01
...
...
@@ -13,6 +13,7 @@ cdef extern from "cpp_operators_helper.h":
char
*
operator
-
()
char
*
operator
*
()
char
*
operator
~
()
char
*
operator
!
()
char
*
operator
++
()
char
*
operator
--
()
...
...
@@ -50,12 +51,14 @@ def test_unops():
unary -
unary ~
unary *
unary !
"""
cdef
TestOps
*
t
=
new
TestOps
()
out
(
+
t
[
0
])
out
(
-
t
[
0
])
out
(
~
t
[
0
])
out
(
deref
(
t
[
0
]))
out
(
not
t
[
0
])
del
t
def
test_incdec
():
...
...
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