NEURON
solve_without_method_visitor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025 EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include "ast/ast_decl.hpp"
10 #include "ast/name.hpp"
11 #include "ast/program.hpp"
12 #include "ast/solve_block.hpp"
13 #include "ast/string.hpp"
17 
18 namespace nmodl {
19 namespace visitor {
20 
22  const auto& derivative_blocks = collect_nodes(node, {ast::AstNodeType::DERIVATIVE_BLOCK});
23  for (const auto& derivative_block: derivative_blocks) {
24  const auto& block = std::dynamic_pointer_cast<ast::DerivativeBlock>(derivative_block);
25  derivative_block_names.insert(block->get_node_name());
26  }
27  node.visit_children(*this);
28 }
29 
31  const auto& name = node.get_block_name()->get_node_name();
32  const auto& method = node.get_method();
33  if (derivative_block_names.count(name) && !method) {
34  node.set_method(std::make_shared<ast::Name>(
35  std::make_shared<ast::String>(codegen::naming::DERIVIMPLICIT_METHOD)));
36  }
37  node.visit_children(*this);
38 }
39 
40 } // namespace visitor
41 } // namespace nmodl
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
Represents top level AST node for whole NMODL input.
Definition: program.hpp:39
std::unordered_set< std::string > derivative_block_names
void visit_solve_block(ast::SolveBlock &node) override
visit node of type ast::SolveBlock
void visit_program(ast::Program &node) override
visit node of type ast::Program
Auto generated AST classes declaration.
@ DERIVATIVE_BLOCK
type of ast::DerivativeBlock
const char * name
Definition: init.cpp:16
Auto generated AST classes declaration.
static constexpr char DERIVIMPLICIT_METHOD[]
derivimplicit method in nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
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 *)
Definition: netcvode.cpp:291
Auto generated AST classes declaration.
Auto generated AST classes declaration.
Visitor for adding an explicit method to a SOLVE block which has an implicit one
Auto generated AST classes declaration.
Utility functions for visitors implementation.