Add a max_dynamic_params_depth setting to limit recusive searching for those params. It shouldn't be too crazy.

This commit is contained in:
Dave Halter
2016-07-17 13:59:19 +02:00
parent 218278af8d
commit 75c1ebc2fe
5 changed files with 35 additions and 11 deletions

View File

@@ -89,6 +89,7 @@ class Evaluator(object):
self.mixed_cache = {} # see `evaluate.compiled.mixed.create()`
self.analysis = []
self.predefined_if_name_dict_dict = {}
self.dynamic_params_depth = 0
self.is_analysis = False
if sys_path is None:

View File

@@ -52,17 +52,24 @@ def search_params(evaluator, param):
is.
"""
if not settings.dynamic_params:
return []
return set()
func = param.get_parent_until(tree.Function)
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA')
# Compare the param names.
names = [n for n in search_function_call(evaluator, func)
if n.value == param.name.value]
# Evaluate the ExecutedParams to types.
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
debug.dbg('Dynamic param result %s', result, color='MAGENTA')
return result
if evaluator.dynamic_params_depth == settings.max_dynamic_params_depth:
return set()
evaluator.dynamic_params_depth += 1
try:
func = param.get_parent_until(tree.Function)
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA')
# Compare the param names.
names = [n for n in search_function_call(evaluator, func)
if n.value == param.name.value]
# Evaluate the ExecutedParams to types.
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
debug.dbg('Dynamic param result %s', result, color='MAGENTA')
return result
finally:
evaluator.dynamic_params_depth -= 1
@memoize_default([], evaluator_is_first_arg=True)

View File

@@ -696,7 +696,7 @@ class FunctionExecution(Executed):
else:
yield self._evaluator.eval_element(element)
# TODO add execution_recursion_decorator?!
@recursion.execution_recursion_decorator
def get_yield_types(self):
yields = self.yields
stopAt = tree.ForStmt, tree.WhileStmt, FunctionExecution, tree.IfStmt