Commits

Stephen Tu committed ba255e1

WIP: some minor changes

  • Participants
  • Parent commits 8ef5e3e

Comments (0)

Files changed (3)

File pypy/interpreter/astcompiler/astbuilder.py

 
 ### XXX: mutates AST **in place**, instead of returning a copy
 class LineNumberVisitor(ast.ASTVisitor):
-    def __init__(self, lineno):
+    def __init__(self, lineno, offset=0):
         self.lineno = lineno
+        self.offset = offset
 
     def default_visitor(self, node):
-        if not hasattr(node, 'lineno'):
-            return node
-        #print "setting lineno=%d for node:" % (self.lineno), node
-        node.lineno = self.lineno
+        if hasattr(node, 'lineno'):
+            node.lineno = self.lineno
+        if hasattr(node, 'col_offset'):
+            node.col_offset = self.offset
         return node
 
 def ast_from_node(space, node, compile_info):

File pypy/interpreter/astcompiler/codegen.py

         # right now, we just hardcode a bunch of random features
         self.symbol_features = {}
 
+    def _initial_feature_list(self, sym):
+        # These are features that are based  *only* on the symbol name/scope
+        (scope, name) = sym
+        ret = []
+        ret.append(('symbol_type', scope.lookup(name)))
+        return ret
+
     def _feature_list(self, sym):
         # sym is (scope, ident), where ident is a string
         key = sym
         if key in self.symbol_features:
             return self.symbol_features[key]
-        value = []
+        value = self._initial_feature_list(sym)
         self.symbol_features[key] = value
         return value
 
         if name.id == astbuilder.ASTBuilder._HIDDEN_NAME_:
             # ignore our instrumentation
             return None
+        no = self._current_scope().lookup(name.id)
+        #print "filename: %s, lineno: %d, no: %s" % (
+        #    self.symbols.compile_info.filename,
+        #    name.lineno,
+        #    self._scope_no_str(no))
         scope = self._get_originating_scope(self._current_scope(), name.id)
         if not scope:
             return None
         features.append((feature_name, feature_value))
 
         # output a particular feature vector for this node location
-        print '<filename=%s, lineno=%d, varname=%s, features=%s>' % (
+        print '<filename=%s, lineno=%d, column=%d, varname=%s, features=%s>' % (
             self.symbols.compile_info.filename,
-            node.lineno,
+            node.lineno, node.col_offset,
             sym[1],
             str(features)
         )
     def visit_Return(self, node):
         if node.value:
             self._record_binary_feature(node, 'used_as_ret_val')
+        ast.GenericASTVisitor.visit_Return(self, node)
 
     def visit_Print(self, node):
         for value in node.values:

File pypy/interpreter/astcompiler/optimize.py

             assert my_pt.children[0].type == syms.stmt
             my_ast = self.ast_builder.handle_stmt(my_pt.children[0]).value
             assert type(my_ast) == ast.Call
-            v = astbuilder.LineNumberVisitor(name.lineno)
+            v = astbuilder.LineNumberVisitor(name.lineno, name.col_offset)
             my_ast.mutate_over(v)
             assert my_ast.lineno == name.lineno
             print "instrumented: %s:%d %s" % (self.compile_info.filename, name.lineno, name.id)