Commit fee03687 authored by Robert Bradshaw's avatar Robert Bradshaw

fix templating, actually works

parent c599ab4b
......@@ -1079,18 +1079,27 @@ class ImagNode(AtomicNewTempExprNode):
class NewExprNode(AtomicExprNode):
# C++ new statement
#
# cppclass string c++ class to create
# template_parameters None or [ExprNode] temlate parameters, if any
def analyse_types(self, env):
print self.cppclass
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")
return
if self.template_parameters is not None:
template_types = [v.analyse_as_type(env) for v in self.template_parameters]
type = entry.type.specialize_here(self.pos, template_types)
else:
type = entry.type
constructor = entry.type.scope.lookup(u'__init__')
constructor = type.scope.lookup(u'__init__')
if constructor is None:
print "no constructor declared"
# create one
self.class_entry = entry
# TODO(danilo): create one
self.class_type = type
self.entry = constructor
self.type = constructor.type
......@@ -1098,7 +1107,7 @@ class NewExprNode(AtomicExprNode):
pass
def calculate_result_code(self):
return "new " + self.class_entry.cname
return "new " + self.class_type.declaration_code("")
class NameNode(AtomicExprNode):
......@@ -2442,7 +2451,7 @@ class SimpleCallNode(CallNode):
"Python object cannot be passed as a varargs parameter")
# Calc result type and code fragment
if isinstance(self.function, NewExprNode):
self.type = PyrexTypes.CPtrType(self.function.class_entry.type)
self.type = PyrexTypes.CPtrType(self.function.class_type)
else:
self.type = func_type.return_type
if self.type.is_pyobject:
......
......@@ -297,7 +297,13 @@ def p_new_expr(s):
pos = s.position()
s.next()
name = p_ident(s)
return p_call(s, ExprNodes.NewExprNode(pos, cppclass = name))
if s.sy == '[':
s.next()
template_parameters = p_simple_expr_list(s)
s.expect(']')
else:
template_parameters = None
return p_call(s, ExprNodes.NewExprNode(pos, cppclass = name, template_parameters = template_parameters))
#trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
......
......@@ -1423,7 +1423,7 @@ class CppClassType(CType):
name = self.name
else:
name = self.cname
return "%s %s%s" % (name, entity_code, templates)
return "%s%s %s" % (name, templates, entity_code)
def is_subclass(self, other_type):
# TODO(danilo): Handle templates.
......
......@@ -393,6 +393,7 @@ class Scope(object):
entry.type.scope = scope
self.type_entries.append(entry)
if not scope and not entry.type.scope:
print pos
self.check_for_illegal_incomplete_ctypedef(typedef_flag, pos)
return entry
......
......@@ -3,7 +3,8 @@ cdef extern from "Python.h":
ctypedef struct PyObject:
Py_ssize_t ob_refcnt
PyTypeObject *ob_type
ctypedef struct FILE
ctypedef struct FILE:
pass
#####################################################################
......
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