From c6050b86ba6f5ec3016f75dfa2f2411a3d15dd00 Mon Sep 17 00:00:00 2001 From: Danilo Freitas Date: Thu, 2 Jul 2009 01:20:07 -0300 Subject: [PATCH] same work --- Cython/Compiler/ExprNodes.py | 32 ++++++++++++++++++++------------ Cython/Compiler/Parsing.py | 7 +++---- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 056e89c8..df19539a 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1080,20 +1080,27 @@ class ImagNode(AtomicNewTempExprNode): class NewExprNode(AtomicExprNode): type = PyrexTypes.cpp_class_type - subexpr = ['args'] + subexpr = ['cppclass'] def analyse_types(self, env): - for arg in self.args: - arg.analyse_types(env) - - def coerce_to(self, type, env): - return self - + 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 + + constructor = entry.scope.lookup('__init__') + if constructor is None: + print "no constructor declared" + # create one + self.class_entry = entry + self.type = PyrexTypes.CPtrType(entry.type) + self.func_type = constructor.type + def generate_result_code(self, code): pass - + def calculate_result_code(self): - return "" + return "new " + self.entry.cname class NameNode(AtomicExprNode): @@ -2377,10 +2384,11 @@ class SimpleCallNode(CallNode): if func_type.is_cpp_class: for arg in self.args: arg.analyse_types(env) - entry = env.lookup(self.function.name) + entry = env.lookup(self.function.cppclass) + print entry.name self.type = entry.type - self.function.type = PyrexTypes.CppMethodType(self.function.name, - PyrexTypes.CppClassType(self.function.name, "cppclass", + self.function.type = PyrexTypes.CppMethodType(self.function.cppclass, + PyrexTypes.CppClassType(self.function.cppclass, "cppclass", entry.scope, 0, entry.cname, []), self.args) self.analyse_c_function_call(env) else: diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 2fdd1175..e5ad6d08 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -292,12 +292,11 @@ def p_power(s): return n1 def p_new_expr(s): - # s.systring == 'new' + # s.systring == 'new'. pos = s.position() s.next() - args = p_simple_expr_list(s) - return ExprNodes.NewExprNode(pos, args = args) - + name = p_ident(s) + return p_call(s, ExprNodes.NewExprNode(pos, cppclass = name)) #trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -- 2.26.2