From 22e2b0e05102d7dd1ae0ade6dd3fccd4d9119f66 Mon Sep 17 00:00:00 2001 From: Danilo Freitas Date: Fri, 26 Jun 2009 19:37:07 -0300 Subject: [PATCH] Workint with 'new' operator --- Cython/Compiler/ExprNodes.py | 20 ++++++++++++++++++++ Cython/Compiler/Parsing.py | 10 ++++++++++ Cython/Compiler/PyrexTypes.py | 2 ++ 3 files changed, 32 insertions(+) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index cb59255e..3364b69f 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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. diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 4b628e4a..8fa08b8f 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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): diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 1847b007..caf258ce 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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() -- 2.26.2