cache and executions work now recursive

This commit is contained in:
David Halter
2012-03-25 12:59:04 +02:00
parent 36f5cccfe9
commit 6c377d6e91

View File

@@ -42,15 +42,28 @@ class Execution(Exec):
This class is used to evaluate functions and their returns. This class is used to evaluate functions and their returns.
""" """
cache = {}
def get_return_types(self): def get_return_types(self):
""" """
Get the return vars of a function. Get the return vars of a function.
""" """
# check cache
try:
return Execution.cache[self.base]
except KeyError:
# cache is not only here as a cache, but also to prevent an
# endless recursion.
Execution.cache[self.base] = []
def remove_executions(scope):
if isinstance(scope, Execution):
# there maybe executions of executions
stmts = scope.get_return_types()
else:
stmts = scope.returns
return stmts
result = [] result = []
if isinstance(self.base, Execution): stmts = remove_executions(self.base)
stmts = self.base.get_return_types() print 'stmts=', stmts, self.base, repr(self)
else:
stmts = self.base.returns
#n += self.function.get_set_vars() #n += self.function.get_set_vars()
# these are the statements of the return functions # these are the statements of the return functions
@@ -61,9 +74,11 @@ class Execution(Exec):
result.append(Instance(stmt)) result.append(Instance(stmt))
else: else:
print 'addstmt', stmt print 'addstmt', stmt
result += follow_statement(stmt) for followed in follow_statement(stmt):
result += remove_executions(followed)
print 'ret', stmt print 'ret', stmt
Execution.cache[self.base] = result
return result return result
def __repr__(self): def __repr__(self):
@@ -174,7 +189,6 @@ def follow_paths(path, results):
print 'enter', results, len(results) print 'enter', results, len(results)
if len(results): if len(results):
for i, r in enumerate(results): for i, r in enumerate(results):
print 1
results_new += follow_path(iter_paths[i], r) results_new += follow_path(iter_paths[i], r)
except StopIteration: except StopIteration:
return results return results
@@ -204,6 +218,7 @@ def follow_path(path, input):
search_func=input.get_instance_vars) search_func=input.get_instance_vars)
elif isinstance(input, Execution): elif isinstance(input, Execution):
#try: #try:
print '\n\n\n\n\nbefexec', input
stmts = input.get_return_types() stmts = input.get_return_types()
print 'exec', stmts print 'exec', stmts
for s in stmts: for s in stmts: