14 #include "utils/logger.hpp"
22 auto name =
node.get_block_name()->get_node_name();
23 const auto& method =
node.get_method();
24 solve_method = method ? method->get_value()->eval() :
"";
32 node.visit_children(*
this);
35 const auto& statement_block =
node.get_statement_block();
37 statement_block->emplace_back_statement(e);
45 node.visit_children(*
this);
51 const auto& lhs =
node.get_lhs();
59 auto name = std::dynamic_pointer_cast<ast::VarName>(lhs)->get_name();
61 if (
name->is_prime_name()) {
68 auto expr_statement = std::dynamic_pointer_cast<ast::ExpressionStatement>(
70 const auto bin_expr = std::dynamic_pointer_cast<const ast::BinaryExpression>(
71 expr_statement->get_expression());
72 node.set_lhs(std::shared_ptr<ast::Expression>(bin_expr->get_lhs()->clone()));
73 node.set_rhs(std::shared_ptr<ast::Expression>(bin_expr->get_rhs()->clone()));
75 logger->warn(
"NeuronSolveVisitor :: cnexp solver not possible for {}",
83 auto expr_statement = std::dynamic_pointer_cast<ast::ExpressionStatement>(
85 const auto bin_expr = std::dynamic_pointer_cast<const ast::BinaryExpression>(
86 expr_statement->get_expression());
87 node.set_lhs(std::shared_ptr<ast::Expression>(bin_expr->get_lhs()->clone()));
88 node.set_rhs(std::shared_ptr<ast::Expression>(bin_expr->get_rhs()->clone()));
94 std::string
n =
name->get_node_name();
99 auto varname =
"D" +
name->get_node_name();
102 auto symbol = std::make_shared<symtab::Symbol>(varname,
ModToken());
103 symbol->set_original_name(
name->get_node_name());
104 symbol->created_from_state();
108 logger->error(
"NeuronSolveVisitor :: solver method '{}' not supported",
solve_method);
115 node.visit_children(*
this);
Auto generated AST classes declaration.
Represent token returned by scanner.
Represents binary expression in the NMODL.
Represents DERIVATIVE block in the NMODL.
Represents differential equation in DERIVATIVE block.
Represents top level AST node for whole NMODL input.
static std::string solve(const std::string &equation, std::string method, bool debug=false)
solve equation using provided method
static bool cnexp_possible(const std::string &equation, std::string &solution)
check if given equation can be solved using cnexp method
void insert(const std::shared_ptr< Symbol > &symbol)
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_solve_block(ast::SolveBlock &node) override
visit node of type ast::SolveBlock
std::vector< std::shared_ptr< ast::Statement > > euler_solution_expressions
void visit_diff_eq_expression(ast::DiffEqExpression &node) override
visit node of type ast::DiffEqExpression
std::string derivative_block_name
the derivative name currently being visited
symtab::SymbolTable * program_symtab
global symbol table
void visit_derivative_block(ast::DerivativeBlock &node) override
visit node of type ast::DerivativeBlock
bool differential_equation
true while visiting differential equation
std::map< std::string, std::string > solve_blocks
a map holding solve block names and methods
void visit_program(ast::Program &node) override
visit node of type ast::Program
void visit_binary_expression(ast::BinaryExpression &node) override
visit node of type ast::BinaryExpression
std::string solve_method
method specified in solve block
bool derivative_block
visiting derivative block
static constexpr char DERIVIMPLICIT_METHOD[]
derivimplicit method in nmodl
static constexpr char CNEXP_METHOD[]
cnexp method in nmodl
static constexpr char EULER_METHOD[]
euler method in nmodl
std::shared_ptr< Statement > create_statement(const std::string &code_statement)
Convert given code statement (in string format) to corresponding ast node.
encapsulates code generation backend implementations
std::string to_nmodl(const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types)
Given AST node, return the NMODL string representation.
Visitor that solves ODEs using old solvers of NEURON
static Node * node(Object *)
int const size_t const size_t n
Implement class to represent a symbol in Symbol Table.
Utility functions for visitors implementation.