moved a few closures around in NameFinder

This commit is contained in:
Dave Halter
2014-01-06 14:36:24 +01:00
parent 53dbec52ab
commit 0e69ad478b
+10 -10
View File
@@ -110,12 +110,7 @@ class NameFinder(object):
debug.dbg('sfn remove, new: %s, old: %s' % (res_new, result)) debug.dbg('sfn remove, new: %s, old: %s' % (res_new, result))
return res_new return res_new
def filter_name(self, scope_generator, is_goto=False): def _handle_for_loops(self, loop):
"""
Filters all variables of a scope (which are defined in the
`scope_generator`), until the name fits.
"""
def handle_for_loops(loop):
# Take the first statement (for has always only # Take the first statement (for has always only
# one, remember `in`). And follow it. # one, remember `in`). And follow it.
if not loop.inputs: if not loop.inputs:
@@ -128,7 +123,7 @@ class NameFinder(object):
result = evaluate._assign_tuples(expression_list[0], result, self.name_str) result = evaluate._assign_tuples(expression_list[0], result, self.name_str)
return result return result
def process(name): def _process(self, name):
""" """
Returns the parent of a name, which means the element which stands Returns the parent of a name, which means the element which stands
behind a name. behind a name.
@@ -144,7 +139,7 @@ class NameFinder(object):
pass pass
elif par.isinstance(pr.Flow): elif par.isinstance(pr.Flow):
if par.command == 'for': if par.command == 'for':
result += handle_for_loops(par) result += self._handle_for_loops(par)
else: else:
debug.warning('Flow: Why are you here? %s' % par.command) debug.warning('Flow: Why are you here? %s' % par.command)
elif par.isinstance(pr.Param) \ elif par.isinstance(pr.Param) \
@@ -203,6 +198,11 @@ class NameFinder(object):
result.append(par) result.append(par)
return result, no_break_scope, is_array_assignment return result, no_break_scope, is_array_assignment
def filter_name(self, scope_generator, is_goto=False):
"""
Filters all variables of a scope (which are defined in the
`scope_generator`), until the name fits.
"""
flow_scope = self.scope flow_scope = self.scope
result = [] result = []
# compare func uses the tuple of line/indent = line/column # compare func uses the tuple of line/indent = line/column
@@ -217,7 +217,7 @@ class NameFinder(object):
and isinstance(p.var, pr.Class): and isinstance(p.var, pr.Class):
p = p.var p = p.var
if self.name_str == name.get_code() and p not in break_scopes: if self.name_str == name.get_code() and p not in break_scopes:
r, no_break_scope, is_array_assignment = process(name) r, no_break_scope, is_array_assignment = self._process(name)
if is_goto: if is_goto:
if not is_array_assignment: # shouldn't goto arr[1] = if not is_array_assignment: # shouldn't goto arr[1] =
result.append(name) result.append(name)
@@ -258,7 +258,7 @@ class NameFinder(object):
def find(self, scopes, resolve_decorator=True): def find(self, scopes, resolve_decorator=True):
filtered = self.filter_name(scopes) filtered = self.filter_name(scopes)
print 'f', filtered #print 'f', filtered
return self._resolve_descriptors(self._remove_statements(filtered, return self._resolve_descriptors(self._remove_statements(filtered,
resolve_decorator)) resolve_decorator))