From 736b910d415d10de926e435fba5332d7ff724dfe Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 10 Feb 2010 02:11:52 -0800 Subject: [PATCH] Fixes for nested templates. --- Cython/Compiler/ExprNodes.py | 8 ++++++-- Cython/Compiler/Nodes.py | 2 +- tests/bugs.txt | 1 - tests/run/cpp_nested_templates.pyx | 8 ++++---- tests/run/cpp_templates_helper.h | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index e16b7740..1c04e93e 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1048,7 +1048,7 @@ class NewExprNode(AtomicExprNode): # cppclass string c++ class to create # template_parameters None or [ExprNode] temlate parameters, if any - def analyse_types(self, env): + def infer_type(self, env): entry = env.lookup(self.cppclass) if entry is None or not entry.is_cpp_class: error(self.pos, "new operator can only be applied to a C++ class") @@ -1068,6 +1068,10 @@ class NewExprNode(AtomicExprNode): self.class_type = type self.entry = constructor self.type = constructor.type + return self.type + + def analyse_types(self, env): + self.infer_type(env) def generate_result_code(self, code): pass @@ -1803,7 +1807,7 @@ class IndexNode(ExprNode): base_type = self.base.analyse_as_type(env) if base_type and not base_type.is_pyobject: if base_type.is_cpp_class: - if isinstance(self.index, TupleExprNode): + if isinstance(self.index, TupleNode): template_values = self.index.args else: template_values = [self.index] diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 93536334..9474ee66 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -792,7 +792,7 @@ class TemplatedTypeNode(CBaseTypeNode): if base_type.is_cpp_class: # Templated class - if len(self.keyword_args.key_value_pairs) != 0: + if self.keyword_args and self.keyword_args.key_value_pairs: error(self.pos, "c++ templates cannot take keyword arguments"); self.type = PyrexTypes.error_type else: diff --git a/tests/bugs.txt b/tests/bugs.txt index 6a693799..bcf266f3 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -9,6 +9,5 @@ missing_baseclass_in_predecl_T262 cfunc_call_tuple_args_T408 cascaded_list_unpacking_T467 compile.cpp_operators -cpp_nested_templates cppwrap cpp_overload_wrapper diff --git a/tests/run/cpp_nested_templates.pyx b/tests/run/cpp_nested_templates.pyx index 21477920..dbfcab1b 100644 --- a/tests/run/cpp_nested_templates.pyx +++ b/tests/run/cpp_nested_templates.pyx @@ -1,4 +1,4 @@ -from cython import dereference as deref +from cython.operator cimport dereference as deref cdef extern from "cpp_templates_helper.h": cdef cppclass Wrap[T]: @@ -17,15 +17,15 @@ cdef extern from "cpp_templates_helper.h": def test_wrap_pair(int i, double x): """ >>> test_wrap_pair(1, 1.5) - (1, 1.5, True, False) + (1, 1.5, True) >>> test_wrap_pair(2, 2.25) - (2, 2.25, True, False) + (2, 2.25, True) """ cdef Pair[int, double] *pair cdef Wrap[Pair[int, double]] *wrap try: pair = new Pair[int, double](i, x) - warp = new Wrap[Pair[int, double]](deref(pair)) + wrap = new Wrap[Pair[int, double]](deref(pair)) return wrap.get().first(), wrap.get().second(), deref(wrap) == deref(wrap) finally: del pair, wrap diff --git a/tests/run/cpp_templates_helper.h b/tests/run/cpp_templates_helper.h index 13b262fe..e8b8b8af 100644 --- a/tests/run/cpp_templates_helper.h +++ b/tests/run/cpp_templates_helper.h @@ -2,7 +2,7 @@ template class Wrap { T value; public: - Wrap(T v) { value = v; } + Wrap(T v) : value(v) { } void set(T v) { value = v; } T get(void) { return value; } bool operator==(Wrap other) { return value == other.value; } -- 2.26.2