irx.analysis.context

irx.analysis.context

Source: packages/irx/src/irx/analysis/context.py

title: Shared semantic-analysis context.
summary: >-
  Hold the mutable semantic-analysis state that is shared across node visits
  and, in multi-module mode, across modules in one session.

Classes

SemanticContext

title: Shared semantic-analysis state.
summary: >-
  Store scopes, diagnostics, module-aware top-level registries, and
  transient current-node context for the analyzer.
attributes:
  scopes:
    type: ScopeStack
  diagnostics:
    type: DiagnosticBag
  functions:
    type: dict[tuple[ModuleKey, str], SemanticFunction]
  structs:
    type: dict[tuple[ModuleKey, str], SemanticStruct]
  classes:
    type: dict[tuple[ModuleKey, str], SemanticClass]
  current_function:
    type: SemanticFunction | None
  current_class:
    type: SemanticClass | None
  current_module_key:
    type: ModuleKey | None
  loop_depth:
    type: int
  _symbol_counter:
    type: int
  _method_slot_counter:
    type: int

Methods

next_symbol_id(self, prefix: str) -> str
title: Return a fresh semantic symbol id.
summary: >-
  Generate a unique semantic id for locals and declarations that need
  stable identity inside one analysis run.
parameters:
  prefix:
    type: str
returns:
  type: str
next_method_slot(self) -> int
title: Return a fresh class-method dispatch slot.
summary: >-
  Generate a deterministic dispatch-table slot index for one newly
  introduced overridable instance method.
returns:
  type: int
register_function(self, function: SemanticFunction) -> None
title: Register a top-level function by module and name.
summary: >-
  Store the canonical semantic function object for one module-qualified
  top-level name.
parameters:
  function:
    type: SemanticFunction
get_function(self, module_key: ModuleKey, name: str) -> SemanticFunction | None
title: Return a top-level function by module and name.
summary: >-
  Retrieve the canonical semantic function for one module-qualified
  top-level name.
parameters:
  module_key:
    type: ModuleKey
  name:
    type: str
returns:
  type: SemanticFunction | None
register_struct(self, struct: SemanticStruct) -> None
title: Register a top-level struct by module and name.
summary: >-
  Store the canonical semantic struct object for one module-qualified
  top-level name.
parameters:
  struct:
    type: SemanticStruct
get_struct(self, module_key: ModuleKey, name: str) -> SemanticStruct | None
title: Return a top-level struct by module and name.
summary: >-
  Retrieve the canonical semantic struct for one module-qualified top-
  level name.
parameters:
  module_key:
    type: ModuleKey
  name:
    type: str
returns:
  type: SemanticStruct | None
register_class(self, class_: SemanticClass) -> None
title: Register a top-level class by module and name.
summary: >-
  Store the canonical semantic class object for one module-qualified
  top-level name.
parameters:
  class_:
    type: SemanticClass
get_class(self, module_key: ModuleKey, name: str) -> SemanticClass | None
title: Return a top-level class by module and name.
summary: >-
  Retrieve the canonical semantic class for one module-qualified top-
  level name.
parameters:
  module_key:
    type: ModuleKey
  name:
    type: str
returns:
  type: SemanticClass | None
scope(self, kind: str) -> Iterator[None]
title: Push/pop a scope around a block of work.
summary: >-
  Temporarily add a lexical scope frame while analyzing a block of
  statements.
parameters:
  kind:
    type: str
returns:
  type: Iterator[None]
in_function(self, function: SemanticFunction) -> Iterator[None]
title: Temporarily set current_function.
summary: >-
  Remember which function body is being analyzed so return and control-
  flow rules can consult it.
parameters:
  function:
    type: SemanticFunction
returns:
  type: Iterator[None]
in_class(self, class_: SemanticClass) -> Iterator[None]
title: Temporarily set current_class.
summary: >-
  Remember which class declaration is being analyzed so inheritance and
  member-semantics helpers can consult the active owner.
parameters:
  class_:
    type: SemanticClass
returns:
  type: Iterator[None]
in_module(self, module_key: ModuleKey) -> Iterator[None]
title: Temporarily set the current module key.
summary: >-
  Switch the active module identity so registrations and diagnostics
  are attributed to the right module.
parameters:
  module_key:
    type: ModuleKey
returns:
  type: Iterator[None]
in_loop(self) -> Iterator[None]
title: Increase loop depth for loop analysis.
summary: >-
  Mark a temporary loop region so break and continue validation can see
  that loop nesting exists.
returns:
  type: Iterator[None]