loki.types.scope
Representation of symbol tables and scopes in Loki’s internal representation (IR)
Classes
|
Scoping object that manages type caching and derivation for typed symbols. |
- class Scope(parent: dataclasses.InitVar[object] | None = None)
Bases:
objectScoping object that manages type caching and derivation for typed symbols.
The
Scopeprovides a symbol table that uniquely maps a symbol’s name to itsSymbolAttributesor, for a derived type definition, directly to itsDerivedType.See
SymbolTablefor more details on how to look-up symbols.- Parameters:
parent (
Scope, optional) – The enclosing scope, thus allowing recursive look-upssymbol_attrs (
SymbolTable, optional) – Use the given symbol table instead of instantiating a new
- symbol_attrs: SymbolTable
- parent: dataclasses.InitVar[object] = None
- property parents
All parent scopes enclosing the current scope, with the top-level scope at the end of the list
- Returns:
The list of parent scopes
- Return type:
- rescope_symbols()
Make sure all symbols declared and used inside this node belong to a scope in the scope hierarchy
- make_complete(**frontend_args)
Trigger a re-parse of the object if incomplete to produce a full Loki IR
See
ProgramUnit.make_completefor more details.This method relays the call only to the
parent.
- clone(**kwargs)
Create a copy of the scope object with the option to override individual parameters
Note that this will also create a copy of the symbol table via
SymbolTable.cloneand force rescoping of variables, unlesssymbol_attrsandrescope_symbolsare explicitly specified.- Parameters:
**kwargs (Any parameter from the constructor)
- Returns:
The cloned scope object
- Return type:
type(self)
- get_symbol_scope(name)
Find the scope in which
nameis declaredThis performs a recursive lookup in the
SymbolTableto find the scope in whichnameis declared. Note, that this may be the scope with aImportof this name and not the original declaration.- Parameters:
name (str) – The name of the symbol to look for
- Returns:
The scope object in which the symbol is declared, or None if not found
- Return type:
Scopeor None