NEURON
symtab_visitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 ///
9 /// THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
10 ///
11 
12 #pragma once
13 
14 /**
15  * \file
16  * \brief \copybrief nmodl::visitor::SymtabVisitor
17  */
18 
19 #include <set>
20 
21 #include "symtab/symbol_table.hpp"
22 #include "visitors/ast_visitor.hpp"
24 
25 namespace nmodl {
26 namespace visitor {
27 
28 /**
29  * @addtogroup visitor_classes
30  * @{
31  */
32 
33 /**
34  * \class SymtabVisitor
35  * \brief Concrete visitor for constructing symbol table from AST
36  */
37 class SymtabVisitor: public AstVisitor {
38  private:
40 
41  std::unique_ptr<printer::JSONPrinter> printer;
42  std::set<std::string> block_to_solve;
43  bool update = false;
44  bool under_state_block = false;
45 
46  public:
47  explicit SymtabVisitor(bool update = false)
48  : printer(new printer::JSONPrinter())
49  , update(update) {}
50 
51  SymtabVisitor(symtab::ModelSymbolTable* _modsymtab, bool update = false)
52  : modsymtab(_modsymtab)
53  , update(update) {}
54 
55  SymtabVisitor(std::ostream& os, bool update = false)
56  : printer(new printer::JSONPrinter(os))
57  , update(update) {}
58 
59  SymtabVisitor(const std::string& filename, bool update = false)
60  : printer(new printer::JSONPrinter(filename))
61  , update(update) {}
62 
64 
66 
67  void setup_symbol_table(ast::Ast* node, const std::string& name, bool is_global);
68 
70 
72 
73  void setup_symbol_table_for_scoped_block(ast::Node* node, const std::string& name);
74 
75  // clang-format off
76  void visit_prime_name(ast::PrimeName& node) override;
77  void visit_argument(ast::Argument& node) override;
78  void visit_read_ion_var(ast::ReadIonVar& node) override;
82  void visit_range_var(ast::RangeVar& node) override;
83  void visit_global_var(ast::GlobalVar& node) override;
84  void visit_pointer_var(ast::PointerVar& node) override;
85  void visit_random_var(ast::RandomVar& node) override;
87  void visit_extern_var(ast::ExternVar& node) override;
88  void visit_param_block(ast::ParamBlock& node) override;
91  void visit_state_block(ast::StateBlock& node) override;
104  void visit_solve_block(ast::SolveBlock& node) override;
106  void visit_before_block(ast::BeforeBlock& node) override;
107  void visit_after_block(ast::AfterBlock& node) override;
108  void visit_ba_block(ast::BABlock& node) override;
109  void visit_for_netcon(ast::ForNetcon& node) override;
111  void visit_unit_block(ast::UnitBlock& node) override;
113  void visit_neuron_block(ast::NeuronBlock& node) override;
114  void visit_local_var(ast::LocalVar& node) override;
115  void visit_constant_var(ast::ConstantVar& node) override;
116  void visit_unit_def(ast::UnitDef& node) override;
117  void visit_factor_def(ast::FactorDef& node) override;
118  void visit_define(ast::Define& node) override;
119  void visit_param_assign(ast::ParamAssign& node) override;
122  void visit_useion(ast::Useion& node) override;
123  void visit_program(ast::Program& node) override;
127  void visit_cvode_block(ast::CvodeBlock& node) override;
129  // clang-format on
130 };
131 
132 /** @} */ // end of visitor_classes
133 
134 } // namespace visitor
135 } // namespace nmodl
136 
Concrete visitor for all AST classes.
Represents a AFTER block in NMODL.
Definition: after_block.hpp:51
Represents an argument to functions and procedures.
Definition: argument.hpp:48
Represents a ASSIGNED block in the NMODL.
Represents a statement in ASSIGNED or STATE block.
Represents a block to be executed before or after another block.
Definition: ba_block.hpp:40
Represent a single variable of type BBCOREPOINTER.
Represents a BEFORE block in NMODL.
Represents a BREAKPOINT block in NMODL.
Represent CONSTANT block in the mod file.
Represents a variable in the ast::ConstantBlock.
Represents a CONSTRUCTOR block in the NMODL.
Represents a block used for variable timestep integration (CVODE) of DERIVATIVE blocks.
Definition: cvode_block.hpp:38
Represents a DEFINE statement in NMODL.
Definition: define.hpp:38
Represents DERIVATIVE block in the NMODL.
Represents a DESTRUCTOR block in the NMODL.
Represent linear solver solution block based on Eigen.
Represent newton solver solution block based on Eigen.
Represents a INDEPENDENT block in the NMODL.
Represents a INITIAL block in the NMODL.
Represents LINEAR block in the NMODL.
Extracts information required for LONGITUDINAL_DIFFUSION for each KINETIC block.
Represent NEURON block in the mod file.
Base class for all AST node.
Definition: node.hpp:40
Represents NONLINEAR block in the NMODL.
Represents the coreneuron nrn_state callback function.
Represents a PARAMETER block in the NMODL.
Definition: param_block.hpp:53
Represents a prime variable (for ODE)
Definition: prime_name.hpp:48
Represents top level AST node for whole NMODL input.
Definition: program.hpp:39
Single variable of type RANDOM.
Definition: random_var.hpp:38
Represents a STATE block in the NMODL.
Definition: state_block.hpp:52
Represents block encapsulating list of statements.
Represents TABLE statement in NMODL.
Represents USEION statement in NMODL.
Definition: useion.hpp:40
Helper class for printing AST in JSON form.
Concrete visitor for all AST classes.
Definition: ast_visitor.hpp:37
Concrete visitor for constructing symbol table from AST.
void visit_bbcore_pointer_var(ast::BbcorePointerVar &node) override
visit node of type ast::BbcorePointerVar
void visit_non_linear_block(ast::NonLinearBlock &node) override
visit node of type ast::NonLinearBlock
void visit_local_var(ast::LocalVar &node) override
visit node of type ast::LocalVar
void visit_neuron_block(ast::NeuronBlock &node) override
visit node of type ast::NeuronBlock
void visit_solve_block(ast::SolveBlock &node) override
visit node of type ast::SolveBlock
void visit_factor_def(ast::FactorDef &node) override
visit node of type ast::FactorDef
void visit_program(ast::Program &node) override
visit node of type ast::Program
void visit_for_netcon(ast::ForNetcon &node) override
visit node of type ast::ForNetcon
void visit_pointer_var(ast::PointerVar &node) override
visit node of type ast::PointerVar
void visit_eigen_newton_solver_block(ast::EigenNewtonSolverBlock &node) override
visit node of type ast::EigenNewtonSolverBlock
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 visit_function_table_block(ast::FunctionTableBlock &node) override
visit node of type ast::FunctionTableBlock
void visit_independent_block(ast::IndependentBlock &node) override
visit node of type ast::IndependentBlock
void visit_unit_def(ast::UnitDef &node) override
visit node of type ast::UnitDef
void visit_longitudinal_diffusion_block(ast::LongitudinalDiffusionBlock &node) override
visit node of type ast::LongitudinalDiffusionBlock
void add_model_symbol_with_property(ast::Node *node, symtab::syminfo::NmodlType property)
void visit_useion(ast::Useion &node) override
visit node of type ast::Useion
void visit_before_block(ast::BeforeBlock &node) override
visit node of type ast::BeforeBlock
symtab::ModelSymbolTable * modsymtab
void visit_kinetic_block(ast::KineticBlock &node) override
visit node of type ast::KineticBlock
void visit_constructor_block(ast::ConstructorBlock &node) override
visit node of type ast::ConstructorBlock
void visit_extern_var(ast::ExternVar &node) override
visit node of type ast::ExternVar
void setup_symbol_table_for_scoped_block(ast::Node *node, const std::string &name)
SymtabVisitor(symtab::ModelSymbolTable *_modsymtab, bool update=false)
void visit_eigen_linear_solver_block(ast::EigenLinearSolverBlock &node) override
visit node of type ast::EigenLinearSolverBlock
void visit_net_receive_block(ast::NetReceiveBlock &node) override
visit node of type ast::NetReceiveBlock
void visit_read_ion_var(ast::ReadIonVar &node) override
visit node of type ast::ReadIonVar
void visit_constant_var(ast::ConstantVar &node) override
visit node of type ast::ConstantVar
SymtabVisitor(const std::string &filename, bool update=false)
void visit_nrn_state_block(ast::NrnStateBlock &node) override
visit node of type ast::NrnStateBlock
void visit_ba_block(ast::BABlock &node) override
visit node of type ast::BABlock
void visit_linear_block(ast::LinearBlock &node) override
visit node of type ast::LinearBlock
SymtabVisitor(std::ostream &os, bool update=false)
void visit_breakpoint_block(ast::BreakpointBlock &node) override
visit node of type ast::BreakpointBlock
void visit_nonspecific_cur_var(ast::NonspecificCurVar &node) override
visit node of type ast::NonspecificCurVar
void visit_state_block(ast::StateBlock &node) override
visit node of type ast::StateBlock
void visit_argument(ast::Argument &node) override
visit node of type ast::Argument
void visit_electrode_cur_var(ast::ElectrodeCurVar &node) override
visit node of type ast::ElectrodeCurVar
void visit_initial_block(ast::InitialBlock &node) override
visit node of type ast::InitialBlock
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 visit_global_var(ast::GlobalVar &node) override
visit node of type ast::GlobalVar
SymtabVisitor(bool update=false)
void visit_function_block(ast::FunctionBlock &node) override
visit node of type ast::FunctionBlock
void visit_after_block(ast::AfterBlock &node) override
visit node of type ast::AfterBlock
std::unique_ptr< printer::JSONPrinter > printer
void visit_range_var(ast::RangeVar &node) override
visit node of type ast::RangeVar
void visit_param_assign(ast::ParamAssign &node) override
visit node of type ast::ParamAssign
void visit_constant_block(ast::ConstantBlock &node) override
visit node of type ast::ConstantBlock
void setup_symbol_table_for_global_block(ast::Node *node)
void visit_param_block(ast::ParamBlock &node) override
visit node of type ast::ParamBlock
void visit_derivative_block(ast::DerivativeBlock &node) override
visit node of type ast::DerivativeBlock
void visit_unit_block(ast::UnitBlock &node) override
visit node of type ast::UnitBlock
std::set< std::string > block_to_solve
void visit_write_ion_var(ast::WriteIonVar &node) override
visit node of type ast::WriteIonVar
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)
void visit_assigned_block(ast::AssignedBlock &node) override
visit node of type ast::AssignedBlock
void visit_random_var(ast::RandomVar &node) override
visit node of type ast::RandomVar
void visit_cvode_block(ast::CvodeBlock &node) override
visit node of type ast::CvodeBlock
void visit_discrete_block(ast::DiscreteBlock &node) override
visit node of type ast::DiscreteBlock
void visit_assigned_definition(ast::AssignedDefinition &node) override
visit node of type ast::AssignedDefinition
void visit_procedure_block(ast::ProcedureBlock &node) override
visit node of type ast::ProcedureBlock
void visit_destructor_block(ast::DestructorBlock &node) override
visit node of type ast::DestructorBlock
void visit_statement_block(ast::StatementBlock &node) override
visit node of type ast::StatementBlock
void visit_prime_name(ast::PrimeName &node) override
visit node of type ast::PrimeName
void visit_define(ast::Define &node) override
visit node of type ast::Define
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
const char * name
Definition: init.cpp:16
NmodlType
NMODL variable properties.
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
static Node * node(Object *)
Definition: netcvode.cpp:291
Base class for all Abstract Syntax Tree node types.
Definition: ast.hpp:52
Implement classes for representing symbol table at block and file scope.