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
532074a2
Commit
532074a2
authored
Aug 26, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for comma operator
parent
c5560a14
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
4 deletions
+41
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+22
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+10
-1
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+2
-3
tests/run/cpp_operators.pyx
tests/run/cpp_operators.pyx
+4
-0
tests/run/cpp_operators_helper.h
tests/run/cpp_operators_helper.h
+3
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
532074a2
...
...
@@ -5279,6 +5279,28 @@ class BinopNode(ExprNode):
self
.
type
=
PyrexTypes
.
error_type
class
CBinopNode
(
BinopNode
):
def
analyse_types
(
self
,
env
):
BinopNode
.
analyse_types
(
self
,
env
)
if
self
.
is_py_operation
():
self
.
type
=
PyrexTypes
.
error_type
def
py_operation_function
():
return
""
def
calculate_result_code
(
self
):
return
"(%s %s %s)"
%
(
self
.
operand1
.
result
(),
self
.
operator
,
self
.
operand2
.
result
())
def
c_binop_constructor
(
operator
):
def
make_binop_node
(
pos
,
**
operands
):
return
CBinopNode
(
pos
,
operator
=
operator
,
**
operands
)
return
make_binop_node
class
NumBinopNode
(
BinopNode
):
# Binary operation taking numeric arguments.
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
532074a2
...
...
@@ -582,6 +582,10 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
'address'
:
AmpersandNode
,
}
binop_method_nodes
=
{
'operator.comma'
:
c_binop_constructor
(
','
),
}
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
'cast'
,
'pointer'
,
'compiled'
,
'NULL'
]
+
unop_method_nodes
.
keys
())
...
...
@@ -1385,6 +1389,11 @@ class TransformBuiltinMethods(EnvTransform):
error
(
node
.
function
.
pos
,
u"%s() takes exactly one argument"
%
function
)
else
:
node
=
InterpretCompilerDirectives
.
unop_method_nodes
[
function
](
node
.
function
.
pos
,
operand
=
node
.
args
[
0
])
elif
function
in
InterpretCompilerDirectives
.
binop_method_nodes
:
if
len
(
node
.
args
)
!=
2
:
error
(
node
.
function
.
pos
,
u"%s() takes exactly two arguments"
%
function
)
else
:
node
=
InterpretCompilerDirectives
.
binop_method_nodes
[
function
](
node
.
function
.
pos
,
operand1
=
node
.
args
[
0
],
operand2
=
node
.
args
[
1
])
elif
function
==
u'cast'
:
if
len
(
node
.
args
)
!=
2
:
error
(
node
.
function
.
pos
,
u"cast() takes exactly two arguments"
)
...
...
Cython/Compiler/Parsing.py
View file @
532074a2
...
...
@@ -2056,7 +2056,7 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
supported_overloaded_operators
=
cython
.
set
([
'+'
,
'-'
,
'*'
,
'/'
,
'%'
,
'++'
,
'--'
,
'~'
,
'|'
,
'&'
,
'^'
,
'<<'
,
'>>'
,
'++'
,
'--'
,
'~'
,
'|'
,
'&'
,
'^'
,
'<<'
,
'>>'
,
','
,
'=='
,
'!='
,
'>='
,
'>'
,
'<='
,
'<'
,
'[]'
,
'()'
,
])
...
...
@@ -2102,12 +2102,11 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
error
(
s
.
position
(),
"Empty declarator"
)
name
=
""
cname
=
None
print
pos
,
ctx
.
__dict__
if
cname
is
None
and
ctx
.
namespace
is
not
None
:
cname
=
ctx
.
namespace
+
"::"
+
name
if
name
==
'operator'
and
ctx
.
visibility
==
'extern'
and
nonempty
:
op
=
s
.
sy
if
op
in
'+-*/<=>!%&|([^~,'
:
if
[
c
in
'+-*/<=>!%&|([^~,'
for
c
in
op
]
:
s
.
next
()
# Handle diphthong operators.
if
op
==
'('
:
...
...
tests/run/cpp_operators.pyx
View file @
532074a2
...
...
@@ -26,6 +26,7 @@ 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
)
...
...
@@ -83,6 +84,7 @@ def test_binop():
binary ^
binary <<
binary >>
binary COMMA
"""
cdef
TestOps
*
t
=
new
TestOps
()
out
(
t
[
0
]
+
1
)
...
...
@@ -97,6 +99,8 @@ def test_binop():
out
(
t
[
0
]
<<
1
)
out
(
t
[
0
]
>>
1
)
out
(
cython
.
operator
.
comma
(
t
[
0
],
1
))
del
t
def
test_cmp
():
...
...
tests/run/cpp_operators_helper.h
View file @
532074a2
...
...
@@ -2,6 +2,8 @@
#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 COMMA ,
class
TestOps
{
public:
...
...
@@ -30,6 +32,7 @@ public:
BIN_OP
(
|
);
BIN_OP
(
&
);
BIN_OP
(
^
);
BIN_OP
(
COMMA
);
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