Permalink
Browse files

Use new-style classes in opy/ so callgraph can properly walk it.

  • Loading branch information...
Andy Chu
Andy Chu committed Mar 18, 2018
1 parent 74a7f76 commit 3284fda9dc59fd239260e25716b70bcef42fe437
View
@@ -230,6 +230,10 @@ def _Walk(obj, cls, ref, syms):
if callable(val):
#log('VAL %s module %s', val, val.__module__)
# Recursive call.
# Check for old style:
#if isinstance(val, types.ClassType):
# print('OLD %s' % val)
_Walk(val, None, ref, syms)
# If the value is a class, walk its methods. Note that we assume ALL
@@ -408,8 +412,8 @@ def Report(self, f=sys.stdout):
print('%s' % path)
for func, ref, _ in src.functions:
#third = func
third = ''
third = func
#third = ''
#print(' %s [%s] %s' % (func.__name__, '.'.join(ref), third))
print(' %s' % func.__name__)
PrintSig(' %s', func)
View
@@ -15,7 +15,7 @@ def is_future(stmt):
else:
return 0
class FutureParser:
class FutureParser(object):
features = ("nested_scopes", "generators", "division",
"absolute_import", "with_statement", "print_function",
@@ -46,7 +46,7 @@ def get_features(self):
"""Return list of features enabled by future statements"""
return self.found.keys()
class BadFutureParser:
class BadFutureParser(object):
"""Check for invalid future statements"""
def visitFrom(self, node):
View
@@ -8,7 +8,7 @@ def flatten(tup):
elts.append(elt)
return elts
class Stack:
class Stack(object):
def __init__(self):
self.stack = []
self.pop = self.stack.pop
View
@@ -8,7 +8,7 @@
from . import misc
from .consts import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS
class FlowGraph:
class FlowGraph(object):
def __init__(self):
self.current = self.entry = Block()
self.exit = Block("exit")
@@ -162,7 +162,7 @@ def find_next():
return order
class Block:
class Block(object):
_count = 0
def __init__(self, label=''):
@@ -566,7 +566,7 @@ def isJump(opname):
if opname[:4] == 'JUMP':
return 1
class TupleArg:
class TupleArg(object):
"""Helper for marking func defs with nested tuples in arglist"""
def __init__(self, count, names):
self.count = count
@@ -590,7 +590,7 @@ def twobyte(val):
assert isinstance(val, int)
return divmod(val, 256)
class LineAddrTable:
class LineAddrTable(object):
"""lnotab
This class builds the lnotab, which is documented in compile.c.
@@ -123,7 +123,7 @@ def compile(self, display=0, transformer=None):
print(pprint.pprint(tree))
self.code = gen.getCode()
class LocalNameFinder:
class LocalNameFinder(object):
"""Find local names in scope"""
def __init__(self, names=()):
self.names = set()
@@ -173,7 +173,7 @@ def is_constant_false(node):
return 1
return 0
class CodeGenerator:
class CodeGenerator(object):
"""Defines basic code generator for Python bytecode
This class is an abstract base class. Concrete subclasses must
@@ -1278,7 +1278,7 @@ def visitDict(self, node):
self.emit('ROT_THREE')
self.emit('STORE_SUBSCR')
class NestedScopeMixin:
class NestedScopeMixin(object):
"""Defines initClass() for nested scoping (Python 2.2-compatible)"""
def initClass(self):
self.__class__.NameFinder = LocalNameFinder
@@ -1498,7 +1498,7 @@ def findOp(node):
walk(node, v, verbose=0)
return v.op
class OpFinder:
class OpFinder(object):
def __init__(self):
self.op = None
def visitAssName(self, node):
View
@@ -12,7 +12,7 @@
MANGLE_LEN = 256
class Scope:
class Scope(object):
# XXX how much information do I need about each name?
def __init__(self, name, module, klass=None):
self.name = name
@@ -210,7 +210,7 @@ class ClassScope(Scope):
def __init__(self, name, module):
self.__super_init(name, module, name)
class SymbolVisitor:
class SymbolVisitor(object):
def __init__(self):
self.scopes = {}
self.klass = None
View
@@ -17,7 +17,7 @@ def check(tree, multi=None):
walk(tree, v)
return v.errors
class SyntaxErrorChecker:
class SyntaxErrorChecker(object):
"""A visitor to find syntax errors in the AST."""
def __init__(self, multi=None):
@@ -25,6 +25,9 @@
# http://www.opensource.org/licenses/bsd-license.html
# and replace OWNER, ORGANIZATION, and YEAR as appropriate.
# NOTE: For the unused parser.suite() and parser.expr()
import parser
from .ast import *
from .consts import CO_VARARGS, CO_VARKEYWORDS
from .consts import OP_ASSIGN, OP_DELETE, OP_APPLY
@@ -33,6 +36,7 @@
from ..pytree import type_repr
symbol = None
def Init(sym):
@@ -222,7 +226,7 @@ def Node(*args):
raise WalkerError, "Can't find appropriate Node type: %s" % str(args)
#return apply(ast.Node, args)
class Transformer:
class Transformer(object):
"""Utility object for transforming Python parse trees.
Exposes the following methods:
View
@@ -2,7 +2,7 @@
# XXX should probably rename ASTVisitor to ASTWalker
# XXX can it be made even more generic?
class ASTVisitor:
class ASTVisitor(object):
"""Performs a depth-first walk of the AST
The ASTVisitor will walk the AST, performing either a preorder or

0 comments on commit 3284fda

Please sign in to comment.