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.
'operator.predecrement' : inc_dec_constructor(True, '--'),
'operator.postincrement': inc_dec_constructor(False, '++'),
'operator.postdecrement': inc_dec_constructor(False, '--'),
-
+
# For backwards compatability.
'address': AmpersandNode,
}
+
+ binop_method_nodes = {
+ 'operator.comma' : c_binop_constructor(','),
+ }
special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof',
'cast', 'pointer', 'compiled', 'NULL']
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")
supported_overloaded_operators = cython.set([
'+', '-', '*', '/', '%',
- '++', '--', '~', '|', '&', '^', '<<', '>>',
+ '++', '--', '~', '|', '&', '^', '<<', '>>', ',',
'==', '!=', '>=', '>', '<=', '<',
'[]', '()',
])
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 == '(':
char* operator|(int)
char* operator&(int)
char* operator^(int)
+ char* operator,(int)
char* operator<<(int)
char* operator>>(int)
binary ^
binary <<
binary >>
+ binary COMMA
"""
cdef TestOps* t = new TestOps()
out(t[0] + 1)
out(t[0] << 1)
out(t[0] >> 1)
+
+ out(cython.operator.comma(t[0], 1))
del t
def test_cmp():
#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:
BIN_OP(|);
BIN_OP(&);
BIN_OP(^);
+ BIN_OP(COMMA);
BIN_OP(==);
BIN_OP(!=);