same work
authorDanilo Freitas <dsurviver@gmail.com>
Thu, 2 Jul 2009 04:20:07 +0000 (01:20 -0300)
committerDanilo Freitas <dsurviver@gmail.com>
Thu, 2 Jul 2009 04:20:07 +0000 (01:20 -0300)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py

index 056e89c8219203a1d55bb847c8622d8562fefd7d..df19539ab83916ebcbe44dbcc7fccff0c3b39cfd 100644 (file)
@@ -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:
index 2fdd11752d9f3048b6f61c8426b105d201a9e6e2..e5ad6d087c2269b92f0aab0470ca7fd7a2fbda63 100644 (file)
@@ -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