27 bool under_state_block) {
30 if (token_ptr !=
nullptr) {
36 symbol->add_property(property);
39 if (property == NmodlType::nonspecific_cur_var) {
40 symbol->add_property(NmodlType::range_var);
44 if (under_state_block) {
45 symbol->add_property(NmodlType::state_var);
54 std::shared_ptr<Symbol> symbol;
59 if (
node->is_prime_name()) {
63 symbol->set_order(prime->get_order()->eval());
64 symbol->add_property(property);
72 if (property == NmodlType::range_var || property == NmodlType::nonspecific_cur_var) {
74 if (
s &&
s->has_any_property(NmodlType::nonspecific_cur_var | NmodlType::range_var)) {
75 s->add_property(property);
85 if (
node->is_param_assign()) {
87 const auto&
value = parameter->get_value();
88 const auto&
name = parameter->get_name();
90 symbol->set_value(
value->to_double());
92 if (
name->is_indexed_name()) {
94 auto length =
dynamic_cast<ast::Integer*
>(index_name->get_length().get());
95 symbol->set_as_array(length->eval());
99 if (
node->is_assigned_definition()) {
101 auto length = variable->get_length();
103 symbol->set_as_array(length->eval());
107 if (
node->is_constant_var()) {
109 auto value = constant->get_value();
111 symbol->set_value(
value->to_double());
115 if (
node->is_local_var()) {
117 auto name = variable->get_name();
118 if (
name->is_indexed_name()) {
120 auto length =
dynamic_cast<ast::Integer*
>(index_name->get_length().get());
121 symbol->set_as_array(length->eval());
125 if (
node->is_define()) {
127 symbol->
set_value(define->get_value()->to_double());
133 if (
node->is_useion()) {
135 auto name = use_ion->get_name()->get_node_name();
138 auto symbol = std::make_shared<symtab::Symbol>(ion_variable);
139 symbol->add_property(NmodlType::codegen_var);
146 node->visit_children(*
this);
152 std::shared_ptr<Symbol> symbol;
153 if (
node->get_token()) {
154 symbol = std::make_shared<Symbol>(
name,
node, *
node->get_token());
158 symbol->add_property(property);
161 symbol->add_property(NmodlType::to_solve);
171 for (
auto variable: variables) {
172 auto symbol = std::make_shared<Symbol>(variable, tok);
173 symbol->add_property(NmodlType::extern_neuron_variable);
178 auto symbol = std::make_shared<Symbol>(method, tok);
179 symbol->add_property(NmodlType::extern_method);
189 if (
node->is_state_block()) {
194 if (
node->is_solve_block()) {
196 block_to_solve.insert(solve_block->get_block_name()->get_node_name());
201 node->set_symbol_table(symtab);
205 if (
node->is_program()) {
210 node->visit_children(*
this);
215 if (
node->is_state_block()) {
250 for (
auto&
var: variables) {
251 auto name =
var->get_node_name();
254 symbol->add_property(property);
255 symbol->set_num_values(num_values);
259 int num_values =
node.get_with()->eval() + 1;
260 update_symbol(
node.get_table_vars(), NmodlType::table_statement_var, num_values);
261 update_symbol(
node.get_depend_vars(), NmodlType::table_assigned_var, num_values);
Represent token returned by scanner.
Represents a statement in ASSIGNED or STATE block.
Represents a variable in the ast::ConstantBlock.
Represents a DEFINE statement in NMODL.
void set_value(std::shared_ptr< Integer > &&value)
Setter for member variable Define::value (rvalue reference)
Represents specific element of an array variable.
Represents an integer variable.
Base class for all AST node.
Represents a prime variable (for ODE)
Represents top level AST node for whole NMODL input.
Represents TABLE statement in NMODL.
Represents USEION statement in NMODL.
void leave_scope()
leaving current nmodl block
SymbolTable * enter_scope(const std::string &name, ast::Ast *node, bool global, SymbolTable *node_symtab)
entering into new nmodl block
std::shared_ptr< Symbol > insert(const std::shared_ptr< Symbol > &symbol)
insert new symbol into current table
void set_mode(bool update_mode)
re-initialize members to throw away old symbol tables this is required as symtab visitor pass runs mu...
std::shared_ptr< Symbol > lookup(const std::string &name)
lookup for symbol into current as well as all parent tables
void setup_symbol_table_for_program_block(ast::Program *node)
Symtab visitor could be called multiple times, after optimization passes, in which case we have to th...
void add_model_symbol_with_property(ast::Node *node, symtab::syminfo::NmodlType property)
symtab::ModelSymbolTable * modsymtab
void setup_symbol_table_for_scoped_block(ast::Node *node, const std::string &name)
void setup_symbol(ast::Node *node, symtab::syminfo::NmodlType property)
helper function to setup/insert symbol into symbol table for the ast nodes which are of variable type...
void setup_symbol_table_for_global_block(ast::Node *node)
std::set< std::string > block_to_solve
void visit_table_statement(ast::TableStatement &node) override
Visit table statement and update symbol in symbol table.
void setup_symbol_table(ast::Ast *node, const std::string &name, bool is_global)
Various types to store code generation specific information.
virtual const ModToken * get_token() const
Return associated token for the AST node.
virtual std::string get_node_name() const
Return name of of the node.
std::vector< std::shared_ptr< Name > > NameVector
double var(InputIterator begin, InputIterator end)
static struct @27 methods[]
static constexpr char ION_VARNAME_PREFIX[]
prefix for ion variable
NmodlType
NMODL variable properties.
static void add_external_symbols(symtab::ModelSymbolTable *symtab)
static std::shared_ptr< Symbol > create_symbol_for_node(ast::Node *node, NmodlType property, bool under_state_block)
encapsulates code generation backend implementations
std::vector< std::string > get_external_variables()
Return variables declared in NEURON that are available to NMODL.
std::vector< std::string > get_external_functions()
Return functions that can be used in the NMODL.
static Node * node(Object *)
Base class for all Abstract Syntax Tree node types.
static std::vector< std::string > get_possible_variables(const std::string &ion_name)
for a given ion, return different variable names/properties like internal/external concentration,...
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
Map different tokens from lexer to token types.