Dereference node.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 14 Jan 2010 23:09:41 +0000 (15:09 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 14 Jan 2010 23:09:41 +0000 (15:09 -0800)
Cython/Compiler/ExprNodes.py
Cython/Compiler/ParseTreeTransforms.py

index ff8e65256bf40f18b9102d23f75b90e6cd99ba23..a9de0ceee683a9e0f58274c5c8d3426d4417ad2c 100755 (executable)
@@ -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.
     #
index a0f0548431773a9f15535f71176b684775ea6998..87963075230844ac187c7bd04b04935f35d8e1a0 100644 (file)
@@ -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']