Commits

Stephen Tu committed 3fb9e4a

bug fixes

Comments (0)

Files changed (1)

pypy/interpreter/astcompiler/codegen.py

             import pdb
             pdb.set_trace()
 
+    def _break_if_cond_fails(self, cond):
+        if not cond:
+            import pdb
+            pdb.set_trace()
+
     ### Visitors ###
 
     def visit_FunctionDef(self, func):
 
     def visit_AugAssign(self, node):
         self._assignment_like(node.target, node.value, aug=True)
-        self._binop_like(node.target, node.value, node.op)
+        self._binop_like(node.target, node.value, node.op, is_cmp=False)
         ast.GenericASTVisitor.visit_AugAssign(self, node)
 
     def visit_Print(self, node):
-        for value in node.values:
-            self._record_binary_feature(value, 'used_in_print_stmt')
+        if node.values:
+            for value in node.values:
+                self._record_binary_feature(value, 'used_in_print_stmt')
         ast.GenericASTVisitor.visit_Print(self, node)
 
     def visit_For(self, node):
         ast.GenericASTVisitor.visit_BoolOp(self, node)
 
     def visit_BinOp(self, node):
-        self._binop_like(node.left, node.right, node.op)
+        self._binop_like(node.left, node.right, node.op, is_cmp=False)
         ast.GenericASTVisitor.visit_BinOp(self, node)
 
     def visit_UnaryOp(self, node):
             self._record_binary_feature(node.left, 'used_as_search_key')
             self._record_binary_feature(node.comparators[0], 'used_as_searchable')
         else:
-            self._binop_like(node.left, node.comparators[0], node.ops[0])
+            self._binop_like(node.left, node.comparators[0], node.ops[0], is_cmp=True)
         ast.GenericASTVisitor.visit_Compare(self, node)
 
     def visit_Call(self, node):
         # check builtin arg
         func = self._unwrap_instrumentation(node.func)
         #self._break_if_file_matches('foobar.py')
-        if isinstance(func, ast.Name):
+        if node.args and isinstance(func, ast.Name):
             name = func.id
             try:
                 argmask = self._BuiltinsTrackArgs[name]
     _BinopTypeToFeatureName = {
         ast.Add      : 'plusminus',
         ast.Sub      : 'plusminus',
+        ast.Mult     : 'multdiv',
         ast.Div      : 'multdiv',
-        ast.FloorDiv : 'multdiv',
         ast.Mod      : 'mod',
+        ast.Pow      : 'pow',
         ast.LShift   : 'bitops',
         ast.RShift   : 'bitops',
-        ast.BitAnd   : 'bitops',
         ast.BitOr    : 'bitops',
         ast.BitXor   : 'bitops',
-        ast.Mult     : 'multdiv',
-        ast.Pow      : 'pow',
+        ast.BitAnd   : 'bitops',
+        ast.FloorDiv : 'multdiv',
+    }
+
+    _CmpTypeToFeatureName = {
         ast.Eq       : 'eq',
         ast.NotEq    : 'eq',
         ast.Lt       : 'ieq',
         ast.IsNot    : 'ref_eq',
     }
 
-    def _binop_like(self, lhs, rhs, op):
-        assert op not in (ast.In, ast.NotIn), 'not handled'
+    def _binop_like(self, lhs, rhs, op, is_cmp):
+        sanity = not is_cmp or (op not in (ast.In, ast.NotIn))
+        self._break_if_cond_fails(sanity)
+        assert sanity, 'not handled'
+        op_map = self._CmpTypeToFeatureName if is_cmp else \
+            self._BinopTypeToFeatureName
+
         # check two special cases: lhs is const, and rhs is const
         lhs_const_type = self._literal_type(lhs)
         rhs_const_type = self._literal_type(rhs)
         if lhs_const_type:
             try:
                 k = self._TypeToFeatureName[lhs_const_type]
-                self._record_binary_feature(rhs, 'used_in_%s_%s' % (
-                    self._BinopTypeToFeatureName[op],
-                    k))
+                self._record_binary_feature(rhs, 'used_in_%s_%s' % (op_map[op], k))
                 done = True
             except KeyError:
                 pass
         elif rhs_const_type:
             try:
                 k = self._TypeToFeatureName[rhs_const_type]
-                self._record_binary_feature(lhs, 'used_in_%s_%s' % (
-                    self._BinopTypeToFeatureName[op],
-                    k))
+                self._record_binary_feature(lhs, 'used_in_%s_%s' % (op_map[op], k))
                 done = True
             except KeyError:
                 pass
         if not done:
             # the general case (which is also a fallback case if the const
             # cases fail above)
-            self._record_binary_feature(
-                lhs, 'used_in_%s' % (self._BinopTypeToFeatureName[op]))
+            self._record_binary_feature(lhs, 'used_in_%s' % (op_map[op]))
 
 ### XXX: avoid code duplication