![]() |
User Guide
|
Represent symbol table for a NMODL block. More...
Represent symbol table for a NMODL block.
Symbol Table is used to track information about every block construct encountered in the nmodl. In NMODL, block constructs are NEURON, PARAMETER NET_RECEIVE etc. Each block is considered a new scope.
NMODL supports nested block definitions (i.e. nested blocks). One specific example of this is INITIAL block in NET_RECEIVE block. In this case we need multiple scopes for single top level block of NMODL. In the future if we enable block level scopes, we will need symbol tables per block. Hence we are implementing BlockSymbolTable which stores all symbol table information for specific NMODL block. Note that each BlockSymbolTable implementation is recursive because while symbol lookup we have to search first into local/current block. If lookup is unsuccessful then we have to traverse parent blocks until the end.
Definition at line 57 of file symbol_table.hpp.
#include <symbol_table.hpp>
Classes | |
class | Table |
Helper class for implementing symbol table. More... | |
Public Member Functions | |
std::string | to_string () const |
convert symbol table to string More... | |
const std::string & | name () const noexcept |
bool | global_scope () const noexcept |
void | insert (const std::shared_ptr< Symbol > &symbol) |
void | set_parent_table (SymbolTable *block) |
int | symbol_count () const |
SymbolTable * | clone () const |
Create a copy of symbol table. More... | |
std::shared_ptr< Symbol > | lookup (const std::string &name) const |
check if symbol with given name exist in the current table (but not in parents) More... | |
std::shared_ptr< Symbol > | lookup_in_scope (const std::string &name) const |
check if symbol with given name exist in the current table (including all parents) More... | |
bool | under_global_scope () |
check if currently we are visiting global scope node More... | |
void | insert_table (const std::string &name, const std::shared_ptr< SymbolTable > &table) |
insert new symbol table as one of the children block More... | |
void | print (std::ostream &ss, int level) const |
std::string | title () const |
construct title for symbol table More... | |
std::string | position () const |
bool | is_method_defined (const std::string &name) const |
check if procedure/function with given name is defined More... | |
Ctor & dtor | |
SymbolTable (std::string name, const ast::Ast *node, bool global=false) | |
SymbolTable (const SymbolTable &table) | |
Getter | |
SymbolTable * | get_parent_table () const noexcept |
std::string | get_parent_table_name () const |
std::vector< std::shared_ptr< Symbol > > | get_variables (syminfo::NmodlType with=syminfo::NmodlType::empty, syminfo::NmodlType without=syminfo::NmodlType::empty) const |
get variables More... | |
std::vector< std::shared_ptr< Symbol > > | get_variables_with_properties (syminfo::NmodlType properties, bool all=false) const |
get variables with properties More... | |
std::vector< std::shared_ptr< Symbol > > | get_variables_with_status (syminfo::Status status, bool all=false) const |
Private Attributes | |
const std::string | symtab_name |
name of the block More... | |
Table | table |
table holding all symbols in the current block More... | |
const ast::Ast * | node = nullptr |
pointer to ast node for which current symbol table created More... | |
bool | global = false |
true if current symbol table is global. More... | |
SymbolTable * | parent = nullptr |
pointer to the symbol table of parent block in the mod file More... | |
std::map< std::string, std::shared_ptr< SymbolTable > > | children |
symbol table for each enclosing block in the current nmodl block construct. More... | |
|
inline |
Definition at line 113 of file symbol_table.hpp.
nmodl::symtab::SymbolTable::SymbolTable | ( | const SymbolTable & | table | ) |
Definition at line 50 of file symbol_table.cpp.
|
inline |
Create a copy of symbol table.
Definition at line 194 of file symbol_table.hpp.
|
inlinenoexcept |
Definition at line 126 of file symbol_table.hpp.
|
inline |
Definition at line 130 of file symbol_table.hpp.
std::vector< std::shared_ptr< Symbol > > nmodl::symtab::SymbolTable::get_variables | ( | syminfo::NmodlType | with = syminfo::NmodlType::empty , |
syminfo::NmodlType | without = syminfo::NmodlType::empty |
||
) | const |
get variables
return all symbol which has all "with" properties and none of the "without" properties
with | variables with properties. syminfo::NmodlType::empty matches everything |
without | variables without properties. syminfo::NmodlType::empty matches nothing |
The two different behaviors for syminfo::NmodlType::empty
depend on the fact that we get get variables with ALL the with properties and without ANY of the without properties
Definition at line 107 of file symbol_table.cpp.
std::vector< std::shared_ptr< Symbol > > nmodl::symtab::SymbolTable::get_variables_with_properties | ( | syminfo::NmodlType | properties, |
bool | all = false |
||
) | const |
get variables with properties
return all symbol having any of the provided properties
properties | variables with properties. -1 matches everything |
all | all/any |
Definition at line 88 of file symbol_table.cpp.
std::vector< std::shared_ptr< Symbol > > nmodl::symtab::SymbolTable::get_variables_with_status | ( | syminfo::Status | status, |
bool | all = false |
||
) | const |
Definition at line 119 of file symbol_table.cpp.
|
inlinenoexcept |
Definition at line 174 of file symbol_table.hpp.
|
inline |
Definition at line 178 of file symbol_table.hpp.
void nmodl::symtab::SymbolTable::insert_table | ( | const std::string & | name, |
const std::shared_ptr< SymbolTable > & | table | ||
) |
insert new symbol table as one of the children block
Definition at line 79 of file symbol_table.cpp.
bool nmodl::symtab::SymbolTable::is_method_defined | ( | const std::string & | name | ) | const |
check if procedure/function with given name is defined
Definition at line 56 of file symbol_table.cpp.
|
inline |
check if symbol with given name exist in the current table (but not in parents)
Definition at line 199 of file symbol_table.hpp.
std::shared_ptr< Symbol > nmodl::symtab::SymbolTable::lookup_in_scope | ( | const std::string & | name | ) | const |
check if symbol with given name exist in the current table (including all parents)
lookup for symbol in current scope as well as all parents
Definition at line 163 of file symbol_table.cpp.
|
inlinenoexcept |
Definition at line 170 of file symbol_table.hpp.
std::string nmodl::symtab::SymbolTable::position | ( | ) | const |
Definition at line 67 of file symbol_table.cpp.
void nmodl::symtab::SymbolTable::print | ( | std::ostream & | ss, |
int | level | ||
) | const |
when current symbol table is empty, the children can be printed from the same indentation level (this is to avoid unnecessary empty indentations)
recursively print all children tables
Definition at line 510 of file symbol_table.cpp.
|
inline |
Definition at line 182 of file symbol_table.hpp.
|
inline |
Definition at line 186 of file symbol_table.hpp.
std::string nmodl::symtab::SymbolTable::title | ( | ) | const |
construct title for symbol table
Definition at line 501 of file symbol_table.cpp.
|
inline |
convert symbol table to string
Definition at line 164 of file symbol_table.hpp.
bool nmodl::symtab::SymbolTable::under_global_scope | ( | ) |
check if currently we are visiting global scope node
Check if current symbol table is in global scope.
We create program scope at the top level and it has global scope. It contains neuron variables like t, dt, celsius etc. Then each nmodl block defining variables are added under this program's symbol table. Hence there are multiple levels of global scopes. In this helper function we make sure current block as well as it's parent are under global scopes.
Definition at line 147 of file symbol_table.cpp.
|
private |
symbol table for each enclosing block in the current nmodl block construct.
for example, for every block statement (like if, while, for) within function we append new symbol table. note that this is also required for nested blocks like INITIAL in NET_RECEIVE.
Definition at line 107 of file symbol_table.hpp.
|
private |
true if current symbol table is global.
blocks like NEURON, PARAMETER defines global variables and hence they go into single global symbol table
Definition at line 98 of file symbol_table.hpp.
|
private |
pointer to ast node for which current symbol table created
Definition at line 93 of file symbol_table.hpp.
|
private |
pointer to the symbol table of parent block in the mod file
Definition at line 101 of file symbol_table.hpp.
|
private |
name of the block
Definition at line 87 of file symbol_table.hpp.
|
private |
table holding all symbols in the current block
Definition at line 90 of file symbol_table.hpp.