User Guide
nmodl::symtab::Symbol Class Reference

Represent symbol in symbol table. More...

Detailed Description

Represent symbol in symbol table.

Symbol table generator pass visit the AST and insert symbol for each node into symtab::SymbolTable. Symbol could appear multiple times in a block or different global blocks. NmodlType object has all nmodl properties information.

Todo:
  • Multiple tokens (i.e. location information) for symbol should be tracked
  • Scope information should be more than just string
  • Perf block should track information about all usage of the symbol (would be helpful for perf modeling)
  • Need to keep track of all renaming information, currently only we keep last state

Definition at line 55 of file symbol.hpp.

#include <symbol.hpp>

Public Member Functions

void read () noexcept
 increment read count More...
 
void write () noexcept
 increment write count More...
 
bool is_external_variable () const noexcept
 Check if symbol represent an external variable. More...
 
bool has_any_property (syminfo::NmodlType new_properties) const noexcept
 check if symbol has any of the given property More...
 
bool has_all_properties (syminfo::NmodlType new_properties) const noexcept
 check if symbol has all of the given properties More...
 
bool has_any_status (syminfo::Status new_status) const noexcept
 check if symbol has any of the status More...
 
bool has_all_status (syminfo::Status new_status) const noexcept
 check if symbol has all of the status More...
 
void add_properties (syminfo::NmodlType new_properties) noexcept
 add new properties to symbol More...
 
void add_property (syminfo::NmodlType property) noexcept
 add new property to symbol More...
 
void remove_property (syminfo::NmodlType property)
 remove property from symbol More...
 
void mark_inlined () noexcept
 mark symbol as inlined (in case of procedure/function) More...
 
void mark_created () noexcept
 mark symbol as newly created (in case of new variable) More...
 
void mark_renamed () noexcept
 
void mark_localized () noexcept
 mark symbol as localized (e.g. from RANGE to LOCAL conversion) More...
 
void mark_thread_safe () noexcept
 
void created_from_state () noexcept
 mark symbol as newly created variable for the STATE variable this is used with legacy euler/derivimplicit solver where DState variables are created More...
 
bool is_array () const noexcept
 
bool is_variable () const noexcept
 check if symbol is a variable in nmodl More...
 
std::string to_string () const
 
bool is_writable () const noexcept
 
Ctor & dtor
 Symbol ()=delete
 
 Symbol (std::string name)
 
 Symbol (std::string name, ast::Ast *node)
 
 Symbol (std::string name, ModToken token)
 
 Symbol (std::string name, ast::Ast *node, ModToken token)
 
Setter
void set_scope (const std::string &s)
 
void set_id (int i) noexcept
 
void set_name (const std::string &new_name)
 Set new name for the symbol. More...
 
void set_order (int new_order) noexcept
 Set order in case of prime/state variable. More...
 
void set_definition_order (int order) noexcept
 
void set_value (double val)
 
void set_as_array (int len) noexcept
 
void set_num_values (int n) noexcept
 
void set_original_name (const std::string &new_name)
 
Getter
int get_length () const noexcept
 
int get_num_values () const noexcept
 
const std::string & get_original_name () const noexcept
 
const std::shared_ptr< double > & get_value () const noexcept
 
const std::string & get_name () const noexcept
 
int get_id () const noexcept
 
const std::string & get_scope () const noexcept
 
const syminfo::NmodlTypeget_properties () const noexcept
 
const syminfo::Statusget_status () const noexcept
 
void add_node (ast::Ast *node) noexcept
 
const std::vector< ast::Ast * > & get_nodes () const noexcept
 
std::vector< ast::Ast * > get_nodes_by_type (std::initializer_list< ast::AstNodeType > l) const noexcept
 
const ModTokenget_token () const noexcept
 
int get_read_count () const noexcept
 
int get_write_count () const noexcept
 
int get_definition_order () const noexcept
 

Private Attributes

std::string name
 name of the symbol More...
 
std::string renamed_from
 original name of the symbol if renamed More...
 
int id = 0
 unique id or index position when symbol is inserted into specific table More...
 
std::vector< ast::Ast * > nodes {}
 All given AST nodes for this symbol. More...
 
ModToken token {}
 token associated with symbol (from node) More...
 
syminfo::NmodlType properties {syminfo::NmodlType::empty}
 properties of symbol as a result of usage across whole mod file More...
 
syminfo::Status status {syminfo::Status::empty}
 status of symbol after processing through various passes More...
 
std::string scope
 scope of the symbol (nmodl block name where it appears) More...
 
int order = 0
 order in case of state / prime variable More...
 
int definition_order = -1
 order in which symbol appears in the mod file Different variables appear in different blocks (NEURON, PARAMETER, STATE) and accordingly they appear in the data array (in NEURON). More...
 
std::shared_ptr< double > value
 associated value in case of parameters, constant variable More...
 
bool array = false
 true if symbol represent array variable More...
 
int length = 1
 dimension/length in case of array variable More...
 
int num_values = 0
 number of values that variable can take in case of table variable More...
 
int read_count = 0
 number of times symbol is read More...
 
int write_count = 0
 number of times symbol is written More...
 

Constructor & Destructor Documentation

◆ Symbol() [1/5]

nmodl::symtab::Symbol::Symbol ( )
delete

◆ Symbol() [2/5]

nmodl::symtab::Symbol::Symbol ( std::string  name)
inlineexplicit

Definition at line 114 of file symbol.hpp.

◆ Symbol() [3/5]

nmodl::symtab::Symbol::Symbol ( std::string  name,
ast::Ast node 
)
inline

Definition at line 117 of file symbol.hpp.

◆ Symbol() [4/5]

nmodl::symtab::Symbol::Symbol ( std::string  name,
ModToken  token 
)
inline

Definition at line 122 of file symbol.hpp.

◆ Symbol() [5/5]

nmodl::symtab::Symbol::Symbol ( std::string  name,
ast::Ast node,
ModToken  token 
)
inline

Definition at line 126 of file symbol.hpp.

Member Function Documentation

◆ add_node()

void nmodl::symtab::Symbol::add_node ( ast::Ast node)
inlinenoexcept

Definition at line 243 of file symbol.hpp.

◆ add_properties()

void nmodl::symtab::Symbol::add_properties ( syminfo::NmodlType  new_properties)
inlinenoexcept

add new properties to symbol

Definition at line 309 of file symbol.hpp.

◆ add_property()

void nmodl::symtab::Symbol::add_property ( syminfo::NmodlType  property)
inlinenoexcept

add new property to symbol

Definition at line 314 of file symbol.hpp.

◆ created_from_state()

void nmodl::symtab::Symbol::created_from_state ( )
inlinenoexcept

mark symbol as newly created variable for the STATE variable this is used with legacy euler/derivimplicit solver where DState variables are created

Definition at line 349 of file symbol.hpp.

◆ get_definition_order()

int nmodl::symtab::Symbol::get_definition_order ( ) const
inlinenoexcept

Definition at line 266 of file symbol.hpp.

◆ get_id()

int nmodl::symtab::Symbol::get_id ( ) const
inlinenoexcept

Definition at line 227 of file symbol.hpp.

◆ get_length()

int nmodl::symtab::Symbol::get_length ( ) const
inlinenoexcept

Definition at line 207 of file symbol.hpp.

◆ get_name()

const std::string& nmodl::symtab::Symbol::get_name ( ) const
inlinenoexcept

Definition at line 223 of file symbol.hpp.

◆ get_nodes()

const std::vector<ast::Ast*>& nmodl::symtab::Symbol::get_nodes ( ) const
inlinenoexcept

Definition at line 247 of file symbol.hpp.

◆ get_nodes_by_type()

std::vector< ast::Ast * > nmodl::symtab::Symbol::get_nodes_by_type ( std::initializer_list< ast::AstNodeType l) const
noexcept

Definition at line 52 of file symbol.cpp.

◆ get_num_values()

int nmodl::symtab::Symbol::get_num_values ( ) const
inlinenoexcept

Definition at line 211 of file symbol.hpp.

◆ get_original_name()

const std::string& nmodl::symtab::Symbol::get_original_name ( ) const
inlinenoexcept

Definition at line 215 of file symbol.hpp.

◆ get_properties()

const syminfo::NmodlType& nmodl::symtab::Symbol::get_properties ( ) const
inlinenoexcept

Definition at line 235 of file symbol.hpp.

◆ get_read_count()

int nmodl::symtab::Symbol::get_read_count ( ) const
inlinenoexcept

Definition at line 258 of file symbol.hpp.

◆ get_scope()

const std::string& nmodl::symtab::Symbol::get_scope ( ) const
inlinenoexcept

Definition at line 231 of file symbol.hpp.

◆ get_status()

const syminfo::Status& nmodl::symtab::Symbol::get_status ( ) const
inlinenoexcept

Definition at line 239 of file symbol.hpp.

◆ get_token()

const ModToken& nmodl::symtab::Symbol::get_token ( ) const
inlinenoexcept

Definition at line 254 of file symbol.hpp.

◆ get_value()

const std::shared_ptr<double>& nmodl::symtab::Symbol::get_value ( ) const
inlinenoexcept

Definition at line 219 of file symbol.hpp.

◆ get_write_count()

int nmodl::symtab::Symbol::get_write_count ( ) const
inlinenoexcept

Definition at line 262 of file symbol.hpp.

◆ has_all_properties()

bool nmodl::symtab::Symbol::has_all_properties ( syminfo::NmodlType  new_properties) const
inlinenoexcept

check if symbol has all of the given properties

Definition at line 294 of file symbol.hpp.

◆ has_all_status()

bool nmodl::symtab::Symbol::has_all_status ( syminfo::Status  new_status) const
inlinenoexcept

check if symbol has all of the status

Definition at line 304 of file symbol.hpp.

◆ has_any_property()

bool nmodl::symtab::Symbol::has_any_property ( syminfo::NmodlType  new_properties) const
inlinenoexcept

check if symbol has any of the given property

Definition at line 289 of file symbol.hpp.

◆ has_any_status()

bool nmodl::symtab::Symbol::has_any_status ( syminfo::Status  new_status) const
inlinenoexcept

check if symbol has any of the status

Definition at line 299 of file symbol.hpp.

◆ is_array()

bool nmodl::symtab::Symbol::is_array ( ) const
inlinenoexcept

Definition at line 354 of file symbol.hpp.

◆ is_external_variable()

bool nmodl::symtab::Symbol::is_external_variable ( ) const
inlinenoexcept

Check if symbol represent an external variable.

External variables are the variables that are defined in NEURON and available in mod file.

Todo:
Need to check if we should check two properties using has_any_property instead of exact comparison
See also
nmodl::details::NEURON_VARIABLES

Definition at line 283 of file symbol.hpp.

◆ is_variable()

bool nmodl::symtab::Symbol::is_variable ( ) const
noexcept

check if symbol is a variable in nmodl

Definition at line 19 of file symbol.cpp.

◆ is_writable()

bool nmodl::symtab::Symbol::is_writable ( ) const
inlinenoexcept

Definition at line 363 of file symbol.hpp.

◆ mark_created()

void nmodl::symtab::Symbol::mark_created ( )
inlinenoexcept

mark symbol as newly created (in case of new variable)

Definition at line 329 of file symbol.hpp.

◆ mark_inlined()

void nmodl::symtab::Symbol::mark_inlined ( )
inlinenoexcept

mark symbol as inlined (in case of procedure/function)

Definition at line 324 of file symbol.hpp.

◆ mark_localized()

void nmodl::symtab::Symbol::mark_localized ( )
inlinenoexcept

mark symbol as localized (e.g. from RANGE to LOCAL conversion)

Definition at line 338 of file symbol.hpp.

◆ mark_renamed()

void nmodl::symtab::Symbol::mark_renamed ( )
inlinenoexcept

Definition at line 333 of file symbol.hpp.

◆ mark_thread_safe()

void nmodl::symtab::Symbol::mark_thread_safe ( )
inlinenoexcept

Definition at line 342 of file symbol.hpp.

◆ read()

void nmodl::symtab::Symbol::read ( )
inlinenoexcept

increment read count

Definition at line 135 of file symbol.hpp.

◆ remove_property()

void nmodl::symtab::Symbol::remove_property ( syminfo::NmodlType  property)
inline

remove property from symbol

Definition at line 319 of file symbol.hpp.

◆ set_as_array()

void nmodl::symtab::Symbol::set_as_array ( int  len)
inlinenoexcept

Definition at line 189 of file symbol.hpp.

◆ set_definition_order()

void nmodl::symtab::Symbol::set_definition_order ( int  order)
inlinenoexcept

Definition at line 181 of file symbol.hpp.

◆ set_id()

void nmodl::symtab::Symbol::set_id ( int  i)
inlinenoexcept

Definition at line 151 of file symbol.hpp.

◆ set_name()

void nmodl::symtab::Symbol::set_name ( const std::string &  new_name)
inline

Set new name for the symbol.

If symbol is already renamed, do not rename it again as we want to keep track of original name and not intermediate renames

Definition at line 162 of file symbol.hpp.

◆ set_num_values()

void nmodl::symtab::Symbol::set_num_values ( int  n)
inlinenoexcept

Definition at line 194 of file symbol.hpp.

◆ set_order()

void nmodl::symtab::Symbol::set_order ( int  new_order)
inlinenoexcept

Set order in case of prime/state variable.

Prime variable will appear in different block and could have multiple derivative orders. We have to store highest order.

Definition at line 175 of file symbol.hpp.

◆ set_original_name()

void nmodl::symtab::Symbol::set_original_name ( const std::string &  new_name)
inline

Definition at line 198 of file symbol.hpp.

◆ set_scope()

void nmodl::symtab::Symbol::set_scope ( const std::string &  s)
inline

Definition at line 147 of file symbol.hpp.

◆ set_value()

void nmodl::symtab::Symbol::set_value ( double  val)
inline

Definition at line 185 of file symbol.hpp.

◆ to_string()

std::string nmodl::symtab::Symbol::to_string ( ) const

Definition at line 41 of file symbol.cpp.

◆ write()

void nmodl::symtab::Symbol::write ( )
inlinenoexcept

increment write count

Definition at line 140 of file symbol.hpp.

Member Data Documentation

◆ array

bool nmodl::symtab::Symbol::array = false
private

true if symbol represent array variable

Definition at line 94 of file symbol.hpp.

◆ definition_order

int nmodl::symtab::Symbol::definition_order = -1
private

order in which symbol appears in the mod file Different variables appear in different blocks (NEURON, PARAMETER, STATE) and accordingly they appear in the data array (in NEURON).

This order is based on appearance in the mod file.

Definition at line 88 of file symbol.hpp.

◆ id

int nmodl::symtab::Symbol::id = 0
private

unique id or index position when symbol is inserted into specific table

Definition at line 63 of file symbol.hpp.

◆ length

int nmodl::symtab::Symbol::length = 1
private

dimension/length in case of array variable

Definition at line 97 of file symbol.hpp.

◆ name

std::string nmodl::symtab::Symbol::name
private

name of the symbol

Definition at line 57 of file symbol.hpp.

◆ nodes

std::vector<ast::Ast*> nmodl::symtab::Symbol::nodes {}
private

All given AST nodes for this symbol.

Variable can appear multiple times in the mod file.

Definition at line 67 of file symbol.hpp.

◆ num_values

int nmodl::symtab::Symbol::num_values = 0
private

number of values that variable can take in case of table variable

Definition at line 100 of file symbol.hpp.

◆ order

int nmodl::symtab::Symbol::order = 0
private

order in case of state / prime variable

Definition at line 82 of file symbol.hpp.

◆ properties

syminfo::NmodlType nmodl::symtab::Symbol::properties {syminfo::NmodlType::empty}
private

properties of symbol as a result of usage across whole mod file

Definition at line 73 of file symbol.hpp.

◆ read_count

int nmodl::symtab::Symbol::read_count = 0
private

number of times symbol is read

Definition at line 103 of file symbol.hpp.

◆ renamed_from

std::string nmodl::symtab::Symbol::renamed_from
private

original name of the symbol if renamed

Definition at line 60 of file symbol.hpp.

◆ scope

std::string nmodl::symtab::Symbol::scope
private

scope of the symbol (nmodl block name where it appears)

Definition at line 79 of file symbol.hpp.

◆ status

syminfo::Status nmodl::symtab::Symbol::status {syminfo::Status::empty}
private

status of symbol after processing through various passes

Definition at line 76 of file symbol.hpp.

◆ token

ModToken nmodl::symtab::Symbol::token {}
private

token associated with symbol (from node)

Definition at line 70 of file symbol.hpp.

◆ value

std::shared_ptr<double> nmodl::symtab::Symbol::value
private

associated value in case of parameters, constant variable

Definition at line 91 of file symbol.hpp.

◆ write_count

int nmodl::symtab::Symbol::write_count = 0
private

number of times symbol is written

Definition at line 106 of file symbol.hpp.


The documentation for this class was generated from the following files: