Commit ed063894 authored by Robert Bradshaw's avatar Robert Bradshaw

cpp () operator

parent c0b49eab
...@@ -2579,7 +2579,15 @@ class SimpleCallNode(CallNode): ...@@ -2579,7 +2579,15 @@ class SimpleCallNode(CallNode):
return func_type return func_type
def analyse_c_function_call(self, env): def analyse_c_function_call(self, env):
entry = PyrexTypes.best_match(self.args, self.function.entry.all_alternatives(), self.pos) if self.function.type.is_cpp_class:
function = self.function.type.scope.lookup("operator()")
if function is None:
self.type = PyrexTypes.error_type
self.result_code = "<error>"
return
else:
function = self.function.entry
entry = PyrexTypes.best_match(self.args, function.all_alternatives(), self.pos)
if not entry: if not entry:
self.type = PyrexTypes.error_type self.type = PyrexTypes.error_type
self.result_code = "<error>" self.result_code = "<error>"
......
...@@ -2061,7 +2061,7 @@ supported_overloaded_operators = set([ ...@@ -2061,7 +2061,7 @@ supported_overloaded_operators = set([
'+', '-', '*', '/', '%', '+', '-', '*', '/', '%',
'++', '--', '~', '|', '&', '^', '<<', '>>', '++', '--', '~', '|', '&', '^', '<<', '>>',
'==', '!=', '>=', '>', '<=', '<', '==', '!=', '>=', '>', '<=', '<',
'[]', '[]', '()',
]) ])
def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
......
...@@ -34,6 +34,9 @@ cdef extern from "cpp_operators_helper.h": ...@@ -34,6 +34,9 @@ cdef extern from "cpp_operators_helper.h":
char* operator>(int) char* operator>(int)
char* operator<(int) char* operator<(int)
char* operator[](int)
char* operator()(int)
def test_unops(): def test_unops():
""" """
>>> test_unops() >>> test_unops()
...@@ -111,3 +114,14 @@ def test_cmp(): ...@@ -111,3 +114,14 @@ def test_cmp():
print t[0] <= 1 print t[0] <= 1
print t[0] < 1 print t[0] < 1
del t del t
def test_index_call():
"""
>>> test_index_call()
binary []
binary ()
"""
cdef TestOps* t = new TestOps()
print t[0][100]
print t[0](100)
del t
...@@ -38,4 +38,7 @@ public: ...@@ -38,4 +38,7 @@ public:
BIN_OP(>=); BIN_OP(>=);
BIN_OP(>); BIN_OP(>);
BIN_OP([]);
BIN_OP(());
}; };
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