generate set_vars now

This commit is contained in:
David Halter
2013-09-02 16:02:18 +04:30
parent a253f07827
commit ad16f34cda
2 changed files with 18 additions and 29 deletions

View File

@@ -219,7 +219,7 @@ def save_module(path, name, parser, pickling=True):
class _ModulePickling(object): class _ModulePickling(object):
version = 3 version = 4
""" """
Version number (integer) for file system cache. Version number (integer) for file system cache.

View File

@@ -758,7 +758,7 @@ class Statement(Simple):
:param start_pos: Position (line, column) of the Statement. :param start_pos: Position (line, column) of the Statement.
""" """
__slots__ = ('token_list', 'used_vars', __slots__ = ('token_list', 'used_vars',
'set_vars', '_commands', '_assignment_details', '_set_vars', '_commands', '_assignment_details',
'docstr') 'docstr')
def __init__(self, module, set_vars, used_vars, token_list, def __init__(self, module, set_vars, used_vars, token_list,
@@ -770,9 +770,9 @@ class Statement(Simple):
for t in token_list: for t in token_list:
if isinstance(t, Name): if isinstance(t, Name):
t.parent = self.use_as_parent t.parent = self.use_as_parent
self.set_vars = self._remove_executions_from_set_vars(set_vars)
self.parent = parent self.parent = parent
self.docstr = '' self.docstr = ''
self._set_vars = None
# cache # cache
self._commands = None self._commands = None
@@ -783,7 +783,8 @@ class Statement(Simple):
""" Clean up a docstring """ """ Clean up a docstring """
self.docstr = cleandoc(literal_eval(string)) self.docstr = cleandoc(literal_eval(string))
def _remove_executions_from_set_vars(self, set_vars): @property
def set_vars(self):
""" """
Removes all executions and uses in lookups. Removes all executions and uses in lookups.
Important mainly for assosiative arrays:: Important mainly for assosiative arrays::
@@ -795,33 +796,21 @@ class Statement(Simple):
`a` is in this case not a set_var, it is used to index the dict. `a` is in this case not a set_var, it is used to index the dict.
""" """
if not set_vars: if self._set_vars is None:
return []
"""
_set_vars = [] _set_vars = []
def search_calls(calls): def search_calls(calls):
for calls, operation in self.assignment_details: for call in calls:
search_elements() if isinstance(call, Array):
set_vars for stmt in call:
""" search_calls(stmt.get_commands())
elif isinstance(call, Call):
if call.type == Call.NAME:
_set_vars.append(call.name)
result = set(set_vars) for calls, operation in self.assignment_details:
last = None search_calls(calls)
in_lookup = 0 self._set_vars = _set_vars
is_execution = False return self._set_vars
for i, tok in enumerate(self.token_list):
if isinstance(tok, Name):
if in_lookup or is_execution:
result.discard(tok)
elif isinstance(tok, tuple):
tok = tok[1]
if tok in '[(' and isinstance(last, Name):
in_lookup += 1
elif tok in ')]' and in_lookup > 0:
in_lookup -= 1
last = tok
return list(result)
def get_code(self, new_line=True): def get_code(self, new_line=True):
def assemble(command_list, assignment=None): def assemble(command_list, assignment=None):