name_resolver.l0

name_resolver.l0

Module: name_resolver

Source: compiler/stage2_l0/src/name_resolver.l0 Language: Dea/L0

Imports / Includes

  • symbols
  • ast
  • util.diag
  • std.string
  • util.strings
  • std.hashset
  • std.hashmap
  • driver
  • std.vector
  • std.text
  • sys.rt

Symbols

Function nr_span_diag_error

1
func nr_span_diag_error(diags: DiagCollector*, code: string, message: string, filename: string, span: Span)

Emit a name-resolution error for a source span.

Parameters:

Function nr_span_diag_warn

1
func nr_span_diag_warn(diags: DiagCollector*, code: string, message: string, filename: string, span: Span)

Emit a name-resolution warning for a source span.

Parameters:

Function nr_map_symbol_get

1
func nr_map_symbol_get(self: StringPtrMap*, name: string) -> Symbol*?

Return a symbol from a string-pointer map when present.

Parameters:

Returns: Matching symbol, or null if absent.

Function nr_build_top_key

1
func nr_build_top_key(module_name: string, name: string) -> string

Build a fully qualified top-level symbol key.

Parameters:

  • module_name: Defining module name.
  • name: Symbol name.

Returns: Key in module::name form.

Function nr_path_is_same_signature

1
func nr_path_is_same_signature(left: TypeRef*?, right: TypeRef*?) -> bool

Compare two parsed type references for signature compatibility.

Parameters:

  • left: First type reference.
  • right: Second type reference.

Returns: true if the two type references describe the same type syntax.

Function nr_extern_signatures_compatible

1
func nr_extern_signatures_compatible(local_sym: Symbol*, imported_sym: Symbol*) -> bool

Check whether two extern function symbols have compatible signatures.

Parameters:

  • local_sym: Local symbol.
  • imported_sym: Imported symbol.

Returns: true if both are extern functions with matching signatures.

Function nr_symbol_free_map

1
func nr_symbol_free_map(self: StringPtrMap*)

Free a symbol map that owns its symbol values.

Parameters:

Function nr_module_env_free

1
func nr_module_env_free(self: ModuleEnv*)

Free a module environment and its owned local symbols.

Parameters:

  • self: Module environment to free.

Function nr_free

1
func nr_free(self: NameResolution*)

Free a complete name-resolution result.

Parameters:

  • self: Name-resolution result to free.

Function nr_env_count

1
func nr_env_count(self: NameResolution*) -> int

Return the number of module environments in the result.

Parameters:

  • self: Name-resolution result to inspect.

Returns: Module-environment count.

Function nr_env_get

1
func nr_env_get(self: NameResolution*, index: int) -> ModuleEnv*

Return a module environment by index.

Parameters:

  • self: Name-resolution result to inspect.
  • index: Zero-based environment index.

Returns: Module environment at index.

Function nr_env_find

1
func nr_env_find(self: NameResolution*, module_name: string) -> ModuleEnv*?

Find a module environment by module name.

Parameters:

  • self: Name-resolution result to inspect.
  • module_name: Module name to look up.

Returns: Matching environment, or null if absent.

Function nr_module_env_local

1
func nr_module_env_local(self: ModuleEnv*, name: string) -> Symbol*?

Look up a locally defined symbol in a module environment.

Parameters:

  • self: Module environment to inspect.
  • name: Symbol name to look up.

Returns: Local symbol, or null if absent.

Function nr_module_env_imported

1
func nr_module_env_imported(self: ModuleEnv*, name: string) -> Symbol*?

Look up an imported symbol in a module environment.

Parameters:

  • self: Module environment to inspect.
  • name: Symbol name to look up.

Returns: Imported symbol, or null if absent.

Function nr_module_env_all

1
func nr_module_env_all(self: ModuleEnv*, name: string) -> Symbol*?

Look up any visible symbol in a module environment.

Parameters:

  • self: Module environment to inspect.
  • name: Symbol name to look up.

Returns: Visible symbol, or null if absent or ambiguous.

Function nr_module_env_is_ambiguous

1
func nr_module_env_is_ambiguous(self: ModuleEnv*, name: string) -> bool

Check whether an imported name is ambiguous in a module environment.

Parameters:

  • self: Module environment to inspect.
  • name: Symbol name to check.

Returns: true if multiple imports provide name.

Function nr_module_env_imports_module

1
func nr_module_env_imports_module(self: ModuleEnv*, module_name: string) -> bool

Check whether a module environment imports a given module.

Parameters:

  • self: Module environment to inspect.
  • module_name: Imported module name to check.

Returns: true if module_name appears in the import set.

Function nr_module_env_local_keys

1
func nr_module_env_local_keys(self: ModuleEnv*) -> StringVector*

Return the names of locally defined symbols.

Parameters:

  • self: Module environment to inspect.

Returns: New vector of local symbol names.

Function nr_module_env_imported_keys

1
func nr_module_env_imported_keys(self: ModuleEnv*) -> StringVector*

Return the names of imported symbols.

Parameters:

  • self: Module environment to inspect.

Returns: New vector of imported symbol names.

Function nr_module_env_all_keys

1
func nr_module_env_all_keys(self: ModuleEnv*) -> StringVector*

Return the names of all visible non-ambiguous symbols.

Parameters:

  • self: Module environment to inspect.

Returns: New vector of visible symbol names.

Function nr_define_local

1
func nr_define_local(env: ModuleEnv*, diags: DiagCollector*, name: string, sym: Symbol*)

Add a top-level local symbol to a module environment.

Parameters:

  • env: Module environment being populated.
  • diags: Diagnostic collector for duplicate-definition errors.
  • name: Symbol name.
  • sym: Symbol to insert.

Function nr_collect_locals

1
func nr_collect_locals(env: ModuleEnv*, diags: DiagCollector*)

Collect locally declared top-level symbols for one module.

Parameters:

Function nr_open_imports_one

1
func nr_open_imports_one(env: ModuleEnv*, imported_env: ModuleEnv*, diags: DiagCollector*, imp: Import*)

Merge one imported module’s visible symbols into a module environment.

Parameters:

  • env: Importing module environment.
  • imported_env: Imported module environment.
  • diags: Diagnostic collector.
  • imp: Import declaration being processed.

Function nr_open_imports

1
func nr_open_imports(nr: NameResolution*, env: ModuleEnv*, diags: DiagCollector*)

Resolve and open every import for a module environment.

Parameters:

  • nr: Full name-resolution state.
  • env: Module environment being populated.
  • diags: Diagnostic collector.

Function nr_make_env

1
func nr_make_env(module_ptr: Module*) -> ModuleEnv*

Create an empty module environment for a parsed module.

Parameters:

  • module_ptr: Parsed module.

Returns: New module environment for module_ptr.

Function nr_resolve

1
func nr_resolve(driver_state: DriverState*, diags: DiagCollector*) -> NameResolution*

Build module environments and resolve opened imports.

Parameters:

  • driver_state: Parsed driver state.
  • diags: Diagnostic collector.

Returns: Name-resolution result containing per-module environments.

Struct ModuleEnv

Represents the ModuleEnv structure.

ModuleEnv Field module_name

1
module_name: string

ModuleEnv Field module_ptr

1
module_ptr: Module*

ModuleEnv Field locals

1
locals: StringPtrMap*

ModuleEnv Field imported

1
imported: StringPtrMap*

ModuleEnv Field all

1
all: StringPtrMap*

ModuleEnv Field ambiguous_imports

1
ambiguous_imports: StringSet*

ModuleEnv Field imported_modules

1
imported_modules: StringSet*

Struct NameResolution

Represents the NameResolution structure.

NameResolution Field envs

1
envs: VectorBase*

NameResolution Field by_name

1
by_name: StringPtrMap*