pynestml.symbol_table package

Submodules

pynestml.symbol_table.scope module

class pynestml.symbol_table.scope.Scope(scope_type, enclosing_scope=None, source_position=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)

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

add_symbol(symbol)

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

delete_scope(scope)

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

delete_symbol(symbol)

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. :rtype: bool

get_depth_of_scope()

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

get_enclosing_scope()

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

get_global_scope()

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

get_scope_type()

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

get_scopes()

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

get_source_position()

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

get_symbols_in_complete_scope()

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. :rtype: list

get_symbols_in_this_scope()

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. :rtype: list

has_enclosing_scope()

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

is_enclosed_in(scope)

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. :type scope Scope :return: True, if this scope is directly or indirectly enclosed in the handed over one, otherwise False. :rtype: bool

print_scope()

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

resolve_to_all_scopes(name, kind)

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. :type name: str :param kind: the type of the element :type kind: SymbolKind :return: the scope in which the element has been defined in :rtype: Scope

resolve_to_all_symbols(name, kind)

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. :type name: str :param kind: the type of the element :type kind: SymbolType :return: a single symbol element. :rtype: Symbol/list(Symbols)

resolve_to_scope(name, kind)

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. :type name: str :param kind: the type of the symbol, i.e., Variable,function or type. :type kind: SymbolType :return: the first matching scope. :rtype: Scope.

resolve_to_symbol(name, kind)

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. :type name: str :param kind: the type of the symbol, i.e., Variable,function or type. :type kind: SymbolType :return: the first matching symbol. :rtype: variable_symbol or function_symbol

update_variable_symbol(_symbol)
class pynestml.symbol_table.scope.ScopeType(value)

Bases: enum.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
POST_RECEIVE = 5
PRE_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, pynestml.symbol_table.scope.Scope] = {}
name2synapse_scope = {}
classmethod print_symbol_table()

Prints the content of this symbol table.

source_location = None