def find_load(self, target: str) -> t.Optional[t.Any]: if target in self.loads: return self.loads[target]
if self.parent isnotNone: return self.parent.find_load(target)
returnNone
def find_ref(self, name: str) -> t.Optional[str]: if name in self.refs: return self.refs[name]
if self.parent isnotNone: return self.parent.find_ref(name)
returnNone
def ref(self, name: str) -> str:
rv = self.find_ref(name) if rv isNone: raise AssertionError( "Tried to resolve a name to a reference that was"
f" unknown to the frame ({name!r})"
) return rv
# If we have not see the name referenced yet, we need to figure # out what to set it to. if name notin self.refs: # If there is a parent scope we check if the name has a # reference there. If it does it means we might have to alias # to a variable there. if self.parent isnotNone:
outer_ref = self.parent.find_ref(name) if outer_ref isnotNone:
self._define_ref(name, load=(VAR_LOAD_ALIAS, outer_ref)) return
# Otherwise we can just set it to undefined.
self._define_ref(name, load=(VAR_LOAD_UNDEFINED, None))
def branch_update(self, branch_symbols: t.Sequence["Symbols"]) -> None:
stores: t.Dict[str, int] = {} for branch in branch_symbols: for target in branch.stores: if target in self.stores: continue
stores[target] = stores.get(target, 0) + 1
for sym in branch_symbols:
self.refs.update(sym.refs)
self.loads.update(sym.loads)
self.stores.update(sym.stores)
for name, branch_count in stores.items(): if branch_count == len(branch_symbols): continue
if branch: for item in branch:
self.sym_visitor.visit(item)
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None: for target in node.targets:
self.sym_visitor.visit(target) for child in node.body:
self.sym_visitor.visit(child)
for name in node.names: if isinstance(name, tuple):
self.symbols.store(name[1]) else:
self.symbols.store(name)
def visit_Assign(self, node: nodes.Assign, **kwargs: t.Any) -> None: """Visit assignments in the correct order."""
self.visit(node.node, **kwargs)
self.visit(node.target, **kwargs)
def visit_For(self, node: nodes.For, **kwargs: t.Any) -> None: """Visiting stops at for blocks. However the block sequence is visited as part of the outer scope. """
self.visit(node.iter, **kwargs)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.