From: Robert Bradshaw Date: Thu, 14 Jan 2010 23:09:41 +0000 (-0800) Subject: Dereference node. X-Git-Tag: 0.13.beta0~353^2~24 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=67d4ed42b1d9a6e1df41aa1c7f26020fc4b6a3ad;p=cython.git Dereference node. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index ff8e6525..a9de0cee 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -4129,7 +4129,9 @@ class UnopNode(ExprNode): self.gil_error() def is_cpp_operation(self): - return self.operand.type.is_cpp_class + type = self.operand.type + return (type.is_cpp_class or + (type.is_ptr or type.is_reference) and type.base_type.is_cpp_class) def coerce_operand_to_pyobject(self, env): self.operand = self.operand.coerce_to_pyobject(env) @@ -4156,7 +4158,7 @@ class UnopNode(ExprNode): def analyse_cpp_operation(self, env): type = operand.type - if type.is_ptr: + if type.is_ptr or type.is_reference: type = type.base_type entry = env.lookup(type.name) function = entry.type.scope.lookup("operator%s" % self.operator) @@ -4259,6 +4261,22 @@ class TildeNode(UnopNode): return "(~%s)" % self.operand.result() +class DereferenceNode(UnopNode): + # unary '*' operator + + def is_py_operation(self): + return False + + def analyse_c_operation(self, env): + if self.operand.type.is_ptr: + self.type = self.operand.type.base_type + else: + self.type_error() + + def calculate_result_code(self): + return "(*%s)" % self.operand.result() + + class AmpersandNode(ExprNode): # The C address-of operator. # diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index a0f05484..87963075 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -326,6 +326,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): unop_method_nodes = { 'typeof': TypeofNode, 'address': AmpersandNode, + 'dereference': DereferenceNode, } special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof', 'cast', 'pointer', 'compiled', 'NULL']