From ed063894808f60a5e6c68d3fb24657f9671dcb3e Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 15 Jan 2010 18:14:56 -0800 Subject: [PATCH] cpp () operator --- Cython/Compiler/ExprNodes.py | 10 +++++++++- Cython/Compiler/Parsing.py | 2 +- tests/run/cpp_operators.pyx | 14 ++++++++++++++ tests/run/cpp_operators_helper.h | 3 +++ 4 files changed, 27 insertions(+), 2 deletions(-) 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(()); + }; -- 2.26.2