Workint with 'new' operator
authorDanilo Freitas <dsurviver@gmail.com>
Fri, 26 Jun 2009 22:37:07 +0000 (19:37 -0300)
committerDanilo Freitas <dsurviver@gmail.com>
Fri, 26 Jun 2009 22:37:07 +0000 (19:37 -0300)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py

index cb59255e10fdfc4e6ab5124ec7e44adb438d2797..3364b69fc5a2351d565cb7d83f666962b837cd43 100644 (file)
@@ -1077,6 +1077,26 @@ class ImagNode(AtomicNewTempExprNode):
             self.c99_complex = code.globalstate.directives['c99_complex']
         
 
+class NewExprNode(AtomicExprNode):
+    
+    type = PyrexTypes.cpp_class_type
+    subexpr = ['arg']
+    
+    def analyse_types(self, env):
+        entry = env.lookup(self.arg.name)
+        if not entry:
+            self.type = PyrexTypes.error_type
+            return
+    
+    def coerce_to(self, type, env):
+        return self
+    
+    def generate_result_code(self, code):
+        pass
+    
+    def calculate_result_code(self):
+        pass
+
 
 class NameNode(AtomicExprNode):
     #  Reference to a local or global variable name.
index 4b628e4a842b824788890da90246d289170b14c8..8fa08b8f156542c10a33b7c4bf6c7c64d6a2918b 100644 (file)
@@ -279,6 +279,8 @@ def p_yield_expression(s):
 #power: atom trailer* ('**' factor)*
 
 def p_power(s):
+    if s.systring == 'new':
+        return p_new_expr(s)
     n1 = p_atom(s)
     while s.sy in ('(', '[', '.'):
         n1 = p_trailer(s, n1)
@@ -289,6 +291,14 @@ def p_power(s):
         n1 = ExprNodes.binop_node(pos, '**', n1, n2)
     return n1
 
+def p_new_expr(s):
+    # s.systring == 'new'
+    pos = s.position()
+    s.next()
+    args = p_simple_expr_list(s)
+    return ExprNodes.NewExprNode(pos, arg = args[0])
+    
+
 #trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
 
 def p_trailer(s, node1):
index 1847b007c3abda6bc5b3e11f65dd9f4ba45491cb..caf258cef24b570588fab11e6ebf11d3ee22be52 100644 (file)
@@ -1586,6 +1586,8 @@ c_anon_enum_type =    CAnonEnumType(-1, 1)
 c_py_buffer_type = CStructOrUnionType("Py_buffer", "struct", None, 1, "Py_buffer")
 c_py_buffer_ptr_type = CPtrType(c_py_buffer_type)
 
+cpp_class_type = CppClassType("cpp_class", "cppclass", None, 1, "cpp_class", [])
+
 error_type =    ErrorType()
 unspecified_type = UnspecifiedType()