mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 19:45:57 +08:00
flow analysis preparation
This commit is contained in:
@@ -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
|
return UNSURE
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ class FunctionExecution(Executed):
|
|||||||
if r is None:
|
if r is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
check = flow_analysis.break_check(r.parent.parent)
|
check = flow_analysis.break_check(self._evaluator, self, r.parent.parent)
|
||||||
if check is not flow_analysis.NOT_REACHABLE:
|
if check is not flow_analysis.NOT_REACHABLE:
|
||||||
types += self._evaluator.eval_statement(r)
|
types += self._evaluator.eval_statement(r)
|
||||||
if check is flow_analysis.REACHABLE:
|
if check is flow_analysis.REACHABLE:
|
||||||
|
|||||||
Reference in New Issue
Block a user