pynestml.symbol_table package

Submodules

pynestml.symbol_table.scope module

class pynestml.symbol_table.scope.Scope(scope_type: ScopeType, enclosing_scope: Scope | None = None, source_position: ASTSourceLocation | None = None)

Bases: object

This class is used to store a single scope, i.e., a set of elements as declared in this scope directly and a set of sub-scopes with additional elements. .. attribute:: enclosing_scope The scope this scope is enclosed in. Type

Scope

declared_elements Elements declared in this scope, i.e., scopes and symbols. Type

list(Scope,Symbol)

scope_type The type of this scope. Type

ScopeType

source_position The position in the source file this scope spans over.
add_scope(scope: Scope) None

Adds the handed over scope as a sub-scope to the current one. :param scope: a single scope object.

add_symbol(symbol: Symbol) None

Adds the handed over symbol to the current scope. :param symbol: a single symbol object.

delete_scope(scope: Scope) bool

Used to delete a single sub-scope from the current scope. :param scope: a single scope object. :return: True, if the element has been deleted, otherwise False.

delete_symbol(symbol: Symbol) bool

Used to delete a single symbol from the current scope. :param symbol: a single symbol object. :type symbol: Symbol :return: True, if the element has been deleted, otherwise False.

get_depth_of_scope() int

Returns the depth of this scope. :return: the level of encapsulation of this scope.

get_enclosing_scope() Scope | None

Returns the enclosing scope if any is defined. :return: a scope symbol if available.

get_global_scope() Scope | None

Returns the GLOBAL scope in which all sub-scopes are embedded in. :return: the global scope element.

get_scope_type() ScopeType

Returns the type of scope. :return: a ScopeType element.

get_scopes() List[Scope]

Returns the set of scopes as defined in this scope. :return: a list of scope objects :rtype: list

get_source_location() ASTSourceLocation

Returns the position in the source as enclosed by this scope :return: r

get_symbols_in_complete_scope() List[Symbol]

Returns the set of elements as defined in this scope as well as all scopes enclosing this scope. :return: a list of symbols defined in this and all enclosing scopes.

get_symbols_in_this_scope() List[Symbol]

Returns the set of elements as defined in this scope, but not in the corresponding super scope. :return: a list of symbols defined only in this scope, but not in the upper scopes.

has_enclosing_scope() bool

Returns this scope is embedded in a different scope. :return: True, if enclosed, otherwise False.

is_enclosed_in(scope: Scope) bool

Returns if this scope is directly or indirectly enclosed in the handed over scope. :param scope: the scope in which this scope can be enclosed in. :return: True, if this scope is directly or indirectly enclosed in the handed over one, otherwise False.

print_scope() str

Returns a string representation of symbol table as used for debug purpose. :return: a string representation of the scope and its sub-scope.

resolve_to_all_scopes(name: str, kind: SymbolKind) Scope | None

Resolves the handed over name and type and returns the scope in which the corresponding symbol has been defined. If element has been defined in several scopes, all scopes are returned as a list. :param name: the name of the element. :param kind: the type of the element :return: the scope in which the element has been defined in

resolve_to_all_symbols(name: str, kind: SymbolKind) Symbol | List[Symbol] | None

Resolves the name and type and returns the corresponding symbol. Caution: Here, we also take redeclaration into account. This has to be prevented - if required - by cocos. If element has been defined in several scopes, all scopes are returned as a list. :param name: the name of the element. :param kind: the type of the element :return: a single symbol element.

resolve_to_scope(name: str, kind: SymbolKind) Scope | None

Returns the first scope (starting from this) in which the handed over symbol has been defined, i.e., starting from this, climbs recursively upwards unit the element has been located or no enclosing scope is left. :param name: the name of the symbol. :param kind: the type of the symbol, i.e., Variable,function or type. :return: the first matching scope.

resolve_to_symbol(name: str, kind: SymbolKind) Symbol | None

Returns the first symbol corresponding to the handed over parameters, starting from this scope. Starting from this, climbs recursively upwards until the element has been located or no enclosing scope is left. :param name: the name of the symbol. :param kind: the type of the symbol, i.e., Variable,function or type. :return: the first matching symbol.

update_variable_symbol(_symbol: Symbol) None
class pynestml.symbol_table.scope.ScopeType(value)

Bases: Enum

This enum is used to distinguish between different types of scopes, namely:

-The global scope (neuron), in which all the sub-scopes are embedded. -The function scope, as embedded in the global scope. -The update scope, as embedded in the global scope.

FUNCTION = 3
GLOBAL = 1
ON_RECEIVE = 4
UPDATE = 2

pynestml.symbol_table.symbol_table module

class pynestml.symbol_table.symbol_table.SymbolTable

Bases: object

This class is used to store a single symbol table, consisting of scope and symbols.

name2neuron_scope A dict from the name of a neuron to the corresponding scope. Type str->Scope
source_position The source position of the overall compilation unit. Type ASTSourceLocation
classmethod add_neuron_scope(name, scope)

Adds a single neuron scope to the set of stored scopes. :return: a single scope element. :rtype: Scope

classmethod add_synapse_scope(name, scope)

Adds a single synapse scope to the set of stored scopes. :return: a single scope element. :rtype: Scope

classmethod clean_up_table()

Deletes all entries as stored in the symbol table.

classmethod delete_neuron_scope(name)

Deletes a single neuron scope from the set of stored scopes. :return: the name of the scope to delete. :rtype: Scope

classmethod delete_synapse_scope(name)

Deletes a single synapse scope from the set of stored scopes. :return: the name of the scope to delete. :rtype: Scope

classmethod initialize_symbol_table(source_position)

Standard initializer.

name2neuron_scope: Mapping[str, Scope] = {}
name2synapse_scope = {}
classmethod print_symbol_table() str

Prints the content of this symbol table.

source_location = None