flow analysis preparation

This commit is contained in:
Dave Halter
2014-08-05 12:06:58 +02:00
parent c44168f7ad
commit f5e49e3218
2 changed files with 33 additions and 5 deletions

View File

@@ -1,7 +1,35 @@
from jedi.parser.representation import Flow
NOT_REACHABLE = object()
REACHABLE = object()
UNSURE = object()
def break_check(scope):
class Status(object):
def __init__(self, value):
self._value = value
def __eq__(self, other):
return self._value == other.value
def __ne__(self, other):
return not self.__eq__(other)
def __and__(self, other):
if UNSURE in (self, other):
return other
else:
return REACHABLE if self._value and other._value else NOT_REACHABLE
NOT_REACHABLE = Status(True)
REACHABLE = Status(False)
UNSURE = Status(None)
def break_check(evaluator, base_scope, element_scope):
reachable = REACHABLE
if isinstance(element_scope, Flow):
if element_scope.command == 'if' and element_scope.inputs:
result = evaluator.eval_statement(element_scope.inputs[0])
print(result)
if base_scope != element_scope.parent:
return reachable & break_check(base_scope, element_scope.parent)
return UNSURE