From: Robert Bradshaw Date: Tue, 15 Dec 2009 10:58:18 +0000 (-0800) Subject: Work on C++ operators X-Git-Tag: 0.13.beta0~353^2~33 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=1b78e1ae3849782e16f2e843a9fa811874abf323;p=cython.git Work on C++ operators --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 5381666a..eac47237 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -4281,10 +4281,15 @@ class NumBinopNode(BinopNode): type2 = type2.base_type entry = env.lookup(type1.name) function = entry.type.scope.lookup("operator%s" % self.operator) + if function is not None: + operands = [self.operand2] + else: + function = env.lookup("operator%s" % self.operator) + operands = [self.operand1, self.operand2] if not function: self.type_error() return - entry = PyrexTypes.best_match([self.operand1, self.operand2], function.all_alternatives(), self.pos) + entry = PyrexTypes.best_match(operands, function.all_alternatives(), self.pos) if entry is None: self.type = PyrexTypes.error_type self.result_code = "" diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 0e9ab6b2..495abe23 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2008,6 +2008,10 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, cname = None if cname is None and ctx.namespace is not None: cname = ctx.namespace + "::" + name + if name == 'operator' and ctx.visibility == 'extern': + # TODO: This needs to be more strict... + name += s.sy + s.next() result = Nodes.CNameDeclaratorNode(pos, name = name, cname = cname, default = rhs) result.calling_convention = calling_convention diff --git a/tests/compile/cpp_operators.pyx b/tests/compile/cpp_operators.pyx index f1f20abd..6b661b6b 100644 --- a/tests/compile/cpp_operators.pyx +++ b/tests/compile/cpp_operators.pyx @@ -1,6 +1,7 @@ cdef extern from "operators.h": cdef cppclass Operators: - __init__(int) + Operators(int) + Operators operator+(Operators) Operators __add__(Operators, Operators) Operators __sub__(Operators, Operators) Operators __mul__(Operators, Operators)