l0_locals::LocalScopeResolver class

Defined in module l0_locals (l0_locals.py).

Builds lexical scopes for functions within a compilation unit.

This resolver traverses function bodies and creates nested scopes for blocks, loops, and match arms.

Public functions

auto __init__(self, Dict modules[str, Module]) -> None
Initialize the local scope resolver.
auto resolve(self) -> Dict[Tuple[str, str], FunctionEnv]
Build scopes for all non-extern functions in the modules.
auto get_block_scope(self, Block block) -> Optional[Scope]
Get the lexical scope associated with a block.
auto get_match_arm_scope(self, MatchArm arm) -> Optional[Scope]
Get the lexical scope associated with a match arm.

Public attributes

modules

Protected functions

auto _build_function_env(self, str module_name, FuncDecl func) -> FunctionEnv
Build the environment and root scope for a single function.
auto _visit_block(self, Block block, Scope scope) -> None
Traverse a block and populate scopes.
auto _visit_stmt(self, Stmt stmt, Scope scope) -> None
Visit a statement and handle any scope introductions.
auto _visit_with_stmt(self, WithStmt stmt, Scope parent_scope) -> None
Visit a with statement and manage its header and body scopes.
auto _visit_match_arm(self, MatchArm arm, Scope parent_scope) -> None
Visit a match arm and create its child scope.
auto _visit_case_arm(self, CaseArm arm, Scope parent_scope) -> None
Visit a case arm.
auto _visit_case_else(self, CaseElse arm, Scope parent_scope) -> None
Visit a case else arm.
auto _bind_pattern_vars(self, Pattern pattern, Scope scope) -> None
Bind variables introduced by a pattern in the given scope.
auto _declare(self, Scope scope, str name, LocalKind kind, Optional type_ref[TypeRef], Node decl) -> LocalSymbol
Declare a local symbol in the given scope.

Function documentation

None l0_locals::LocalScopeResolver::__init__(self, Dict modules[str, Module])

Initialize the local scope resolver.

Parameters
modules The modules to analyze.

Dict[Tuple[str, str], FunctionEnv] l0_locals::LocalScopeResolver::resolve(self)

Build scopes for all non-extern functions in the modules.

Returns A mapping from function identifiers to their environments.

Optional[Scope] l0_locals::LocalScopeResolver::get_block_scope(self, Block block)

Get the lexical scope associated with a block.

Parameters
block The Block AST node.
Returns The associated Scope if found, otherwise None.

Optional[Scope] l0_locals::LocalScopeResolver::get_match_arm_scope(self, MatchArm arm)

Get the lexical scope associated with a match arm.

Parameters
arm The MatchArm AST node.
Returns The associated Scope if found, otherwise None.