Commit 46953eaa authored by gsamain's avatar gsamain Committed by Xavier Thompson

Cypclass operator overloading

parent cf0fa9e0
......@@ -11462,6 +11462,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)
......@@ -11797,6 +11799,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)" % (
......@@ -11884,8 +11888,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)" % (
......@@ -11952,9 +11959,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):
......@@ -12905,6 +12915,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
......
......@@ -6125,7 +6125,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)
......
......@@ -2525,6 +2525,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