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
pass
def calculate_result_code(self):
- return "new " + self.class_entry.cname
+ return "new " + self.class_type.declaration_code("")
class NameNode(AtomicExprNode):
"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:
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
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.