Commit 1b78e1ae authored by Robert Bradshaw's avatar Robert Bradshaw

Work on C++ operators

parent 16bf4f76
......@@ -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>"
......
......@@ -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
......
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)
......
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