Work on C++ operators
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 15 Dec 2009 10:58:18 +0000 (02:58 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 15 Dec 2009 10:58:18 +0000 (02:58 -0800)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py
tests/compile/cpp_operators.pyx

index 5381666acb031ed4d4aba8e8a2e219203f2bdf16..eac472378cd352bd1e96889c4430c66e3ab40187 100755 (executable)
@@ -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 = "<error>"
index 0e9ab6b221180b53d1ea22ba025b3e0317ce3d67..495abe238beca3f717e85d42c1574f64b62ac11e 100644 (file)
@@ -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
index f1f20abd4d902d446750aae5eacdfad70d6f89c5..6b661b6be5ab620d04cbd9581d73e0e6683db0f3 100644 (file)
@@ -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)