23 node.visit_children(*
this);
45 const auto& block_name = solve_block.
get_block_name()->get_node_name();
46 const auto& solve_node_symbol =
symtab->
lookup(block_name);
47 if (solve_node_symbol ==
nullptr) {
48 throw std::runtime_error(
49 fmt::format(
"SolveBlockVisitor :: cannot find the block '{}' to solve it", block_name));
51 auto node_to_solve = solve_node_symbol->get_nodes().front();
56 std::string solve_method = method ? method->get_node_name() :
"";
61 const std::string node_name = node_to_solve->get_node_name();
62 const std::string node_type = node_to_solve->get_node_type_name();
63 throw std::runtime_error(fmt::format(
64 "Method {} cannot be used for {} {}", solve_method, node_type, node_name));
73 auto statement = std::make_shared<ast::ExpressionStatement>(procedure_call);
79 auto block_to_solve = node_to_solve->get_statement_block();
88 node.visit_children(*
this);
89 if (
node.get_expression()->is_solve_block()) {
95 node.set_expression(std::shared_ptr<ast::SolutionExpression>(sol_expr));
102 node.visit_children(*
this);
Auto generated AST classes declaration.
Represents a BREAKPOINT block in NMODL.
Represents DERIVATIVE block in the NMODL.
Represent a callback to NEURON's derivimplicit solver.
Represents the coreneuron nrn_state callback function.
Represents top level AST node for whole NMODL input.
Represent solution of a block in the AST.
std::shared_ptr< Name > get_block_name() const noexcept
Getter for member variable SolveBlock::block_name.
std::shared_ptr< Name > get_method() const noexcept
Getter for member variable SolveBlock::method.
SolveBlock * clone() const override
Return a copy of the current node.
Represents block encapsulating list of statements.
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)
void visit_breakpoint_block(ast::BreakpointBlock &node) override
visit node of type ast::BreakpointBlock
ast::SolutionExpression * create_solution_expression(ast::SolveBlock &solve_block)
Create solution expression node that will be used for solve block.
void visit_program(ast::Program &node) override
visit node of type ast::Program
ast::StatementVector nrn_state_solve_statements
solve expression statements for NrnState block
symtab::SymbolTable * symtab
void visit_expression_statement(ast::ExpressionStatement &node) override
Replace solve blocks with solution expression.
@ DERIVATIVE_BLOCK
type of ast::DerivativeBlock
@ EIGEN_NEWTON_SOLVER_BLOCK
type of ast::EigenNewtonSolverBlock
@ PROCEDURE_BLOCK
type of ast::ProcedureBlock
static void nrn_state(neuron::model_sorted_token const &, NrnThread *nt, Memb_list *ml, int type)
static constexpr char DERIVIMPLICIT_METHOD[]
derivimplicit method in nmodl
static bool has_sympy_solution(const ast::Ast &node)
check if given node contains sympy solution
encapsulates code generation backend implementations
std::vector< std::shared_ptr< const ast::Ast > > collect_nodes(const ast::Ast &node, const std::vector< ast::AstNodeType > &types)
traverse node recursively and collect nodes of given types
static Node * node(Object *)
Replace solve block statements with actual solution node in the AST.
Base class for all Abstract Syntax Tree node types.
Utility functions for visitors implementation.