Commit d4a39839 authored by gsamain's avatar gsamain

Cypclass operator overloading

parent ae6315f6
......@@ -11383,6 +11383,8 @@ class NumBinopNode(BinopNode):
result1, result2 = self.operand1.pythran_result(), self.operand2.pythran_result()
else:
result1, result2 = self.operand1.result(), self.operand2.result()
if self.operand1.type.is_cyp_class:
result1 = '*' + result1
return "(%s %s %s)" % (result1, self.operator, result2)
else:
func = self.type.binary_op(self.operator)
......@@ -11701,6 +11703,8 @@ class DivNode(NumBinopNode):
op1 = self.type.cast_code(op1)
if self.type != self.operand2.type:
op2 = self.type.cast_code(op2)
if self.operand1.type.is_cyp_class:
op1 = "*(%s)" % op1
return "(%s / %s)" % (op1, op2)
else:
return "__Pyx_div_%s(%s, %s)" % (
......@@ -11788,8 +11792,11 @@ class ModNode(DivNode):
self.operand1.result(),
self.operand2.result())
else:
op1 = self.operand1.result()
if self.operand1.type.is_cyp_class:
op1 = '*' + op1
return "(%s %% %s)" % (
self.operand1.result(),
op1,
self.operand2.result())
else:
return "__Pyx_mod_%s(%s, %s)" % (
......@@ -11856,9 +11863,12 @@ class PowNode(NumBinopNode):
return operand.result()
else:
return self.type.cast_code(operand.result())
op1 = typecast(self.operand1)
if self.operand1.type.is_cyp_class:
op1 = '*' + op1
return "%s(%s, %s)" % (
self.pow_func,
typecast(self.operand1),
op1,
typecast(self.operand2))
def py_operation_function(self, code):
......@@ -12805,6 +12815,8 @@ class PrimaryCmpNode(ExprNode, CmpNode):
result1, result2 = operand1.pythran_result(), operand2.pythran_result()
else:
result1, result2 = operand1.result(), operand2.result()
if operand1.type.is_cyp_class:
result1 = '*' + result1
if self.is_memslice_nonecheck:
if operand1.type.is_memoryviewslice:
result1 = "((PyObject *) %s.memview)" % result1
......
......@@ -5908,7 +5908,10 @@ class InPlaceAssignmentNode(AssignmentNode):
else:
# C++
# TODO: make sure overload is declared
code.putln("%s %s= %s;" % (lhs.result(), c_op, rhs.result()))
l_op = lhs.result()
if lhs.type.is_cyp_class:
l_op = '*' + l_op
code.putln("%s %s= %s;" % (l_op, c_op, rhs.result()))
lhs.generate_subexpr_disposal_code(code)
lhs.free_subexpr_temps(code)
rhs.generate_disposal_code(code)
......
......@@ -2424,6 +2424,28 @@ class CppClassScope(Scope):
default_constructor = None
type = None
operator_table = {
'__add__': '+', '__iadd__': '+=',
'__sub__': '-', '__isub__': '-=',
'__mul__': '*', '__imul__': '*=',
'__div__': '/', '__idiv__': '/=',
'__mod__': '%', '__imod__': '%=',
'__lshift__': '<<', '__ilshift__': '<<=',
'__rshift__': '>>', '__irshift__': '>>=',
'__and__': '&', '__iand__': '&=',
'__or__': '|', '__ior__': '|=',
'__xor__': '^', '__ixor__': '^=',
'__neg__': '-',
'__pos__': '+',
'__invert__': '~',
'__eq__': '==',
'__ne__': '!=',
'__lt__': '<',
'__gt__': '>',
'__le__': '<=',
'__ge__': '>='
}
def __init__(self, name, outer_scope, templates=None):
Scope.__init__(self, name, outer_scope, None)
self.directives = outer_scope.directives
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment