From: Robert Bradshaw Date: Sat, 16 Jan 2010 02:14:56 +0000 (-0800) Subject: cpp () operator X-Git-Tag: 0.13.beta0~353^2~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ed063894808f60a5e6c68d3fb24657f9671dcb3e;p=cython.git cpp () operator --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 6e9388b6..ffbacdec 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2579,7 +2579,15 @@ class SimpleCallNode(CallNode): return func_type 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 = "" + return + else: + function = self.function.entry + entry = PyrexTypes.best_match(self.args, function.all_alternatives(), self.pos) if not entry: self.type = PyrexTypes.error_type self.result_code = "" diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index b1dd1847..a2bab288 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2061,7 +2061,7 @@ supported_overloaded_operators = set([ '+', '-', '*', '/', '%', '++', '--', '~', '|', '&', '^', '<<', '>>', '==', '!=', '>=', '>', '<=', '<', - '[]', + '[]', '()', ]) def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, diff --git a/tests/run/cpp_operators.pyx b/tests/run/cpp_operators.pyx index d1b85007..cdce50e8 100644 --- a/tests/run/cpp_operators.pyx +++ b/tests/run/cpp_operators.pyx @@ -34,6 +34,9 @@ cdef extern from "cpp_operators_helper.h": char* operator>(int) char* operator<(int) + char* operator[](int) + char* operator()(int) + def test_unops(): """ >>> test_unops() @@ -111,3 +114,14 @@ def test_cmp(): print t[0] <= 1 print t[0] < 1 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 diff --git a/tests/run/cpp_operators_helper.h b/tests/run/cpp_operators_helper.h index f85218e1..b8372f27 100644 --- a/tests/run/cpp_operators_helper.h +++ b/tests/run/cpp_operators_helper.h @@ -38,4 +38,7 @@ public: BIN_OP(>=); BIN_OP(>); + BIN_OP([]); + BIN_OP(()); + };