Commit 736b910d authored by Robert Bradshaw's avatar Robert Bradshaw

Fixes for nested templates.

parent ca6c6743
...@@ -1048,7 +1048,7 @@ class NewExprNode(AtomicExprNode): ...@@ -1048,7 +1048,7 @@ class NewExprNode(AtomicExprNode):
# cppclass string c++ class to create # cppclass string c++ class to create
# template_parameters None or [ExprNode] temlate parameters, if any # template_parameters None or [ExprNode] temlate parameters, if any
def analyse_types(self, env): def infer_type(self, env):
entry = env.lookup(self.cppclass) entry = env.lookup(self.cppclass)
if entry is None or not entry.is_cpp_class: if entry is None or not entry.is_cpp_class:
error(self.pos, "new operator can only be applied to a C++ class") error(self.pos, "new operator can only be applied to a C++ class")
...@@ -1068,6 +1068,10 @@ class NewExprNode(AtomicExprNode): ...@@ -1068,6 +1068,10 @@ class NewExprNode(AtomicExprNode):
self.class_type = type self.class_type = type
self.entry = constructor self.entry = constructor
self.type = constructor.type self.type = constructor.type
return self.type
def analyse_types(self, env):
self.infer_type(env)
def generate_result_code(self, code): def generate_result_code(self, code):
pass pass
...@@ -1803,7 +1807,7 @@ class IndexNode(ExprNode): ...@@ -1803,7 +1807,7 @@ class IndexNode(ExprNode):
base_type = self.base.analyse_as_type(env) base_type = self.base.analyse_as_type(env)
if base_type and not base_type.is_pyobject: if base_type and not base_type.is_pyobject:
if base_type.is_cpp_class: if base_type.is_cpp_class:
if isinstance(self.index, TupleExprNode): if isinstance(self.index, TupleNode):
template_values = self.index.args template_values = self.index.args
else: else:
template_values = [self.index] template_values = [self.index]
......
...@@ -792,7 +792,7 @@ class TemplatedTypeNode(CBaseTypeNode): ...@@ -792,7 +792,7 @@ class TemplatedTypeNode(CBaseTypeNode):
if base_type.is_cpp_class: if base_type.is_cpp_class:
# Templated 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"); error(self.pos, "c++ templates cannot take keyword arguments");
self.type = PyrexTypes.error_type self.type = PyrexTypes.error_type
else: else:
......
...@@ -9,6 +9,5 @@ missing_baseclass_in_predecl_T262 ...@@ -9,6 +9,5 @@ missing_baseclass_in_predecl_T262
cfunc_call_tuple_args_T408 cfunc_call_tuple_args_T408
cascaded_list_unpacking_T467 cascaded_list_unpacking_T467
compile.cpp_operators compile.cpp_operators
cpp_nested_templates
cppwrap cppwrap
cpp_overload_wrapper cpp_overload_wrapper
from cython import dereference as deref from cython.operator cimport dereference as deref
cdef extern from "cpp_templates_helper.h": cdef extern from "cpp_templates_helper.h":
cdef cppclass Wrap[T]: cdef cppclass Wrap[T]:
...@@ -17,15 +17,15 @@ cdef extern from "cpp_templates_helper.h": ...@@ -17,15 +17,15 @@ cdef extern from "cpp_templates_helper.h":
def test_wrap_pair(int i, double x): def test_wrap_pair(int i, double x):
""" """
>>> test_wrap_pair(1, 1.5) >>> test_wrap_pair(1, 1.5)
(1, 1.5, True, False) (1, 1.5, True)
>>> test_wrap_pair(2, 2.25) >>> test_wrap_pair(2, 2.25)
(2, 2.25, True, False) (2, 2.25, True)
""" """
cdef Pair[int, double] *pair cdef Pair[int, double] *pair
cdef Wrap[Pair[int, double]] *wrap cdef Wrap[Pair[int, double]] *wrap
try: try:
pair = new Pair[int, double](i, x) 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) return wrap.get().first(), wrap.get().second(), deref(wrap) == deref(wrap)
finally: finally:
del pair, wrap del pair, wrap
...@@ -2,7 +2,7 @@ template <class T> ...@@ -2,7 +2,7 @@ template <class T>
class Wrap { class Wrap {
T value; T value;
public: public:
Wrap(T v) { value = v; } Wrap(T v) : value(v) { }
void set(T v) { value = v; } void set(T v) { value = v; }
T get(void) { return value; } T get(void) { return value; }
bool operator==(Wrap<T> other) { return value == other.value; } bool operator==(Wrap<T> other) { return value == other.value; }
......
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