Commit 78871be7 authored by Robert Bradshaw's avatar Robert Bradshaw

C++ class constructor calls.

parent b6df7f92
...@@ -2453,6 +2453,15 @@ class CallNode(ExprNode): ...@@ -2453,6 +2453,15 @@ class CallNode(ExprNode):
self.analyse_types(env) self.analyse_types(env)
self.coerce_to(type, env) self.coerce_to(type, env)
return True return True
elif type and type.is_cpp_class:
for arg in self.args:
arg.analyse_types(env)
constructor = type.scope.lookup("<init>")
self.function = RawCNameExprNode(self.function.pos, constructor.type)
self.function.entry = constructor
self.function.set_cname(type.declaration_code(""))
self.analyse_c_function_call(env)
return True
def nogil_check(self, env): def nogil_check(self, env):
func_type = self.function_type() func_type = self.function_type()
......
...@@ -1890,6 +1890,8 @@ class CppClassType(CType): ...@@ -1890,6 +1890,8 @@ class CppClassType(CType):
def assignable_from_resolved_type(self, other_type): def assignable_from_resolved_type(self, other_type):
# TODO: handle operator=(...) here? # TODO: handle operator=(...) here?
if other_type is error_type:
return True
return other_type.is_cpp_class and other_type.is_subclass(self) return other_type.is_cpp_class and other_type.is_subclass(self)
def attributes_known(self): def attributes_known(self):
......
...@@ -1536,6 +1536,7 @@ class CppClassScope(Scope): ...@@ -1536,6 +1536,7 @@ class CppClassScope(Scope):
api = 0, in_pxd = 0, modifiers = ()): api = 0, in_pxd = 0, modifiers = ()):
if name == self.name.split('::')[-1] and cname is None: if name == self.name.split('::')[-1] and cname is None:
name = '<init>' name = '<init>'
type.return_type = self.lookup(self.name).type
prev_entry = self.lookup_here(name) prev_entry = self.lookup_here(name)
entry = self.declare_var(name, type, pos, cname, visibility) entry = self.declare_var(name, type, pos, cname, visibility)
if prev_entry: if prev_entry:
......
...@@ -22,8 +22,7 @@ def test_wrap_pair(int i, double x): ...@@ -22,8 +22,7 @@ def test_wrap_pair(int i, double x):
(2, 2.25, True) (2, 2.25, True)
""" """
try: try:
pair = new Pair[int, double](i, x) wrap = new Wrap[Pair[int, double]](Pair[int, double](i, x))
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 wrap
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