use weakrefs for parents now: rest

This commit is contained in:
David Halter
2012-08-12 01:42:37 +02:00
parent a2611c5db6
commit 3ae7d3f278
4 changed files with 8 additions and 9 deletions

View File

@@ -55,7 +55,7 @@ def search_params(param):
for params in listener.param_possibilities: for params in listener.param_possibilities:
for p in params: for p in params:
if str(p) == param_name: if str(p) == param_name:
result += evaluate.follow_statement(p.parent) result += evaluate.follow_statement(p.parent())
#print listener.param_possibilities, param, result #print listener.param_possibilities, param, result
return result return result
@@ -63,8 +63,8 @@ def search_params(param):
func = param.get_parent_until(parsing.Function) func = param.get_parent_until(parsing.Function)
current_module = param.get_parent_until() current_module = param.get_parent_until()
func_name = str(func.name) func_name = str(func.name)
if func_name == '__init__' and isinstance(func.parent, parsing.Class): if func_name == '__init__' and isinstance(func.parent(), parsing.Class):
func_name = str(func.parent.name) func_name = str(func.parent().name)
# get the param name # get the param name
if param.assignment_details: if param.assignment_details:
@@ -125,7 +125,7 @@ def _check_array_additions(compare_array, module, is_list):
backtrack_path = iter(call_path[:separate_index]) backtrack_path = iter(call_path[:separate_index])
position = c.parent_stmt.start_pos position = c.parent_stmt.start_pos
scope = c.parent_stmt.parent scope = c.parent_stmt.parent()
e = evaluate.follow_call_path(backtrack_path, scope, position) e = evaluate.follow_call_path(backtrack_path, scope, position)
if not compare_array in e: if not compare_array in e:
# the `append`, etc. belong to other arrays # the `append`, etc. belong to other arrays

View File

@@ -946,6 +946,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
and scope.var == name.parent().parent(): and scope.var == name.parent().parent():
name = InstanceElement(scope.instance, name) name = InstanceElement(scope.instance, name)
par = name.parent() par = name.parent()
print name, par
if par.isinstance(parsing.Flow): if par.isinstance(parsing.Flow):
if par.command == 'for': if par.command == 'for':
result += handle_for_loops(par) result += handle_for_loops(par)

View File

@@ -61,7 +61,7 @@ class ImportPath(object):
zero = (None, None) zero = (None, None)
n = parsing.Name(i.namespace.names[1:], zero, zero) n = parsing.Name(i.namespace.names[1:], zero, zero)
new = parsing.Import(zero, zero, n) new = parsing.Import(zero, zero, n)
new.parent = parent new.parent = lambda: parent
debug.dbg('Generated a nested import: %s' % new) debug.dbg('Generated a nested import: %s' % new)
return new return new

View File

@@ -110,7 +110,6 @@ class Scope(Simple):
self.docstr = docstr self.docstr = docstr
def add_scope(self, sub, decorators): def add_scope(self, sub, decorators):
print 'push scope @%s,%s' % sub.start_pos
sub.parent = weakref.ref(self) sub.parent = weakref.ref(self)
sub.decorators = decorators sub.decorators = decorators
for d in decorators: for d in decorators:
@@ -460,7 +459,6 @@ class Flow(Scope):
else: else:
self.next = next self.next = next
self.next.parent = self.parent self.next.parent = self.parent
print 'n', self.next
#next.top_flow = self.top_flow #next.top_flow = self.top_flow
return next return next
@@ -1349,8 +1347,8 @@ class PyFuzzyParser(object):
token_type, tok = self.next() token_type, tok = self.next()
#debug.dbg('main: tok=[%s] type=[%s] indent=[%s]'\ #debug.dbg('main: tok=[%s] type=[%s] indent=[%s]'\
# % (tok, token_type, start_position[0])) # % (tok, token_type, start_position[0]))
print('main: tok=[%s] type=[%s] indent=[%s]' #print('main: tok=[%s] type=[%s] indent=[%s]'
% (tok, tokenize.tok_name[token_type], self.start_pos[0])) # % (tok, tokenize.tok_name[token_type], self.start_pos[0]))
while token_type == tokenize.DEDENT \ while token_type == tokenize.DEDENT \
and self.scope != self.module: and self.scope != self.module: