Fix large integer literal inference.
authorRobert Bradshaw <robertwb@math.washington.edu>
Mon, 7 Jun 2010 17:51:51 +0000 (10:51 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Mon, 7 Jun 2010 17:51:51 +0000 (10:51 -0700)
Cython/Compiler/TypeInference.py

index b3ddeaf969e038e51c0816021fb44969f2bdbdc9..e0daaabc132c90a1367955e31628f94ca86ee748 100644 (file)
@@ -3,6 +3,7 @@ import ExprNodes
 import Nodes
 import Builtin
 import PyrexTypes
+from Cython import Utils
 from PyrexTypes import py_object_type, unspecified_type
 from Visitor import CythonTransform
 
@@ -175,7 +176,25 @@ class MarkOverflowingArithmetic(CythonTransform):
     visit_InPlaceAssignmentNode = visit_dangerous_node
     
     visit_Node = visit_safe_node
-
+    
+    def visit_assignment(self, lhs, rhs):
+        if (isinstance(rhs, ExprNodes.IntNode) 
+                and isinstance(lhs, ExprNodes.NameNode)
+                and Utils.long_literal(rhs.value)):
+            entry = lhs.entry or self.env.lookup(lhs.name)
+            if entry:
+                entry.might_overflow = True
+    
+    def visit_SingleAssignmentNode(self, node):
+        self.visit_assignment(node.lhs, node.rhs)
+        self.visitchildren(node)
+        return node
+    
+    def visit_CascadedAssignmentNode(self, node):
+        for lhs in node.lhs_list:
+            self.visit_assignment(lhs, node.rhs)
+        self.visitchildren(node)
+        return node
 
 class PyObjectTypeInferer:
     """