User Guide
cvode_block.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  * \dir
16  * \brief Auto generated AST Implementations
17  *
18  * \file
19  * \brief Auto generated AST classes declaration
20  */
21 
22 #include "ast/ast_decl.hpp"
23 #include "ast/block.hpp"
24 
25 namespace nmodl::ast {
26 
27 /**
28  * \addtogroup ast_class
29  * \ingroup ast
30  * \{
31  */
32 
33 /**
34  * \brief Represents a block used for variable timestep integration (CVODE) of DERIVATIVE blocks
35  *
36  *
37 */
38 class CvodeBlock : public Block {
39  private:
40  /// Name of the block
41  std::shared_ptr<Name> name;
42  /// number of ODEs to solve
43  std::shared_ptr<Integer> n_odes;
44  /// Block with statements of the form Dvar = f(var), used for updating non-stiff systems
45  std::shared_ptr<StatementBlock> non_stiff_block;
46  /// Block with statements of the form Dvar = Dvar / (1 - dt * J(f)), used for updating stiff systems
47  std::shared_ptr<StatementBlock> stiff_block;
48  /// token with location information
49  std::shared_ptr<ModToken> token;
50  /// symbol table for a block
52 
53  public:
54  /// \name Ctor & dtor
55  /// \{
57  explicit CvodeBlock(std::shared_ptr<Name> name, std::shared_ptr<Integer> n_odes, std::shared_ptr<StatementBlock> non_stiff_block, std::shared_ptr<StatementBlock> stiff_block);
58  CvodeBlock(const CvodeBlock& obj);
59  virtual ~CvodeBlock() = default;
60  /// \}
61 
62  /**
63  * \brief Check if the ast node is an instance of ast::CvodeBlock
64  * \return true as object is of type ast::CvodeBlock
65  */
66  bool is_cvode_block () const noexcept override {
67  return true;
68  }
69 
70  /**
71  * \brief Return a copy of the current node
72  *
73  * Recursively make a new copy/clone of the current node including
74  * all members and return a pointer to the node. This is used for
75  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
76  * ast.
77  *
78  * \return pointer to the clone/copy of the current node
79  */
80  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
81  CvodeBlock* clone() const override {
82  return new CvodeBlock(*this);
83  }
84  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
85 
86  /// \name Getters
87  /// \{
88 
89  /**
90  * \brief Return type (ast::AstNodeType) of ast node
91  *
92  * Every node in the ast has a type defined in ast::AstNodeType and this
93  * function is used to retrieve the same.
94  *
95  * \return ast node type i.e. ast::AstNodeType::CVODE_BLOCK
96  *
97  * \sa Ast::get_node_type_name
98  */
99  AstNodeType get_node_type() const noexcept override {
101  }
102 
103  /**
104  * \brief Return type (ast::AstNodeType) of ast node as std::string
105  *
106  * Every node in the ast has a type defined in ast::AstNodeType.
107  * This type name can be returned as a std::string for printing
108  * node to text/json form.
109  *
110  * \return name of the node type as a string i.e. "CvodeBlock"
111  *
112  * \sa Ast::get_node_name
113  */
114  std::string get_node_type_name() const noexcept override {
115  return "CvodeBlock";
116  }
117 
118  /**
119  * \brief Return NMODL statement of ast node as std::string
120  *
121  * Every node is related to a special statement in the NMODL. This
122  * statement can be returned as a std::string for printing to
123  * text/json form.
124  *
125  * \return name of the statement as a string i.e. "CVODE_BLOCK "
126  *
127  * \sa Ast::get_nmodl_name
128  */
129  std::string get_nmodl_name() const noexcept override {
130  return "CVODE_BLOCK ";
131  }
132 
133  /**
134  * \brief Get std::shared_ptr from `this` pointer of the current ast node
135  */
136  std::shared_ptr<Ast> get_shared_ptr() override {
137  return std::static_pointer_cast<CvodeBlock>(shared_from_this());
138  }
139 
140  /**
141  * \brief Get std::shared_ptr from `this` pointer of the current ast node
142  */
143  std::shared_ptr<const Ast> get_shared_ptr() const override {
144  return std::static_pointer_cast<const CvodeBlock>(shared_from_this());
145  }
146 
147  /**
148  * \brief Return associated token for the current ast node
149  *
150  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
151  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
152  * nullptr to store in the nmodl::symtab::SymbolTable.
153  *
154  * \return pointer to token if exist otherwise nullptr
155  */
156  const ModToken* get_token() const noexcept override {
157  return token.get();
158  }
159  /**
160  * \brief Return associated symbol table for the current ast node
161  *
162  * Only certain ast nodes (e.g. inherited from ast::Block) have associated
163  * symbol table. These nodes have nmodl::symtab::SymbolTable as member
164  * and it can be accessed using this method.
165  *
166  * \return pointer to the symbol table
167  *
168  * \sa nmodl::symtab::SymbolTable nmodl::visitor::SymtabVisitor
169  */
171  return symtab;
172  }
173 
174 
175  /**
176  * \brief Return name of the node
177  *
178  * Some ast nodes have a member marked designated as node name. For example,
179  * in case of this ast::Name has name designated as a
180  * node name.
181  *
182  * \return name of the node as std::string
183  *
184  * \sa Ast::get_node_type_name
185  */
186  std::string get_node_name() const override;
187 
188  /**
189  * \brief Getter for member variable \ref CvodeBlock.name
190  */
191  std::shared_ptr<Name> get_name() const noexcept {
192  return name;
193  }
194 
195 
196 
197  /**
198  * \brief Getter for member variable \ref CvodeBlock.n_odes
199  */
200  std::shared_ptr<Integer> get_n_odes() const noexcept {
201  return n_odes;
202  }
203 
204 
205 
206  /**
207  * \brief Getter for member variable \ref CvodeBlock.non_stiff_block
208  */
209  std::shared_ptr<StatementBlock> get_non_stiff_block() const noexcept {
210  return non_stiff_block;
211  }
212 
213 
214 
215  /**
216  * \brief Getter for member variable \ref CvodeBlock.stiff_block
217  */
218  std::shared_ptr<StatementBlock> get_stiff_block() const noexcept {
219  return stiff_block;
220  }
221  /// \}
222 
223  /// \name Setters
224  /// \{
225  /**
226  * \brief Set token for the current ast node
227  */
228  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
229  /**
230  * \brief Set symbol table for the current ast node
231  *
232  * Top level, block scoped nodes store symbol table in the ast node.
233  * nmodl::visitor::SymtabVisitor then used this method to setup symbol table
234  * for every node in the ast.
235  *
236  * \sa nmodl::visitor::SymtabVisitor
237  */
238  void set_symbol_table(symtab::SymbolTable* newsymtab) override {
239  symtab = newsymtab;
240  }
241 
242  /**
243  * \brief Setter for member variable \ref CvodeBlock.name (rvalue reference)
244  */
245  void set_name(std::shared_ptr<Name>&& name);
246 
247  /**
248  * \brief Setter for member variable \ref CvodeBlock.name
249  */
250  void set_name(const std::shared_ptr<Name>& name);
251 
252 
253  /**
254  * \brief Setter for member variable \ref CvodeBlock.n_odes (rvalue reference)
255  */
256  void set_n_odes(std::shared_ptr<Integer>&& n_odes);
257 
258  /**
259  * \brief Setter for member variable \ref CvodeBlock.n_odes
260  */
261  void set_n_odes(const std::shared_ptr<Integer>& n_odes);
262 
263 
264  /**
265  * \brief Setter for member variable \ref CvodeBlock.non_stiff_block (rvalue reference)
266  */
267  void set_non_stiff_block(std::shared_ptr<StatementBlock>&& non_stiff_block);
268 
269  /**
270  * \brief Setter for member variable \ref CvodeBlock.non_stiff_block
271  */
272  void set_non_stiff_block(const std::shared_ptr<StatementBlock>& non_stiff_block);
273 
274 
275  /**
276  * \brief Setter for member variable \ref CvodeBlock.stiff_block (rvalue reference)
277  */
278  void set_stiff_block(std::shared_ptr<StatementBlock>&& stiff_block);
279 
280  /**
281  * \brief Setter for member variable \ref CvodeBlock.stiff_block
282  */
283  void set_stiff_block(const std::shared_ptr<StatementBlock>& stiff_block);
284 
285  /// \}
286 
287  /// \name Visitor
288  /// \{
289  /**
290  * \brief visit children i.e. member variables of current node using provided visitor
291  *
292  * Different nodes in the AST have different members (i.e. children). This method
293  * recursively visits children using provided visitor.
294  *
295  * \param v Concrete visitor that will be used to recursively visit children
296  *
297  * \sa Ast::visit_children for example.
298  */
299  void visit_children(visitor::Visitor& v) override;
300 
301  /**
302  * \brief visit children i.e. member variables of current node using provided visitor
303  *
304  * Different nodes in the AST have different members (i.e. children). This method
305  * recursively visits children using provided visitor.
306  *
307  * \param v Concrete constant visitor that will be used to recursively visit children
308  *
309  * \sa Ast::visit_children for example.
310  */
311  void visit_children(visitor::ConstVisitor& v) const override;
312 
313  /**
314  * \brief accept (or visit) the current AST node using provided visitor
315  *
316  * Instead of visiting children of AST node, like Ast::visit_children,
317  * accept allows to visit the current node itself using provided concrete
318  * visitor.
319  *
320  * \param v Concrete visitor that will be used to recursively visit node
321  *
322  * \sa Ast::accept for example.
323  */
324  void accept(visitor::Visitor& v) override;
325 
326  /**
327  * \copydoc accept(visitor::Visitor&)
328  */
329  void accept(visitor::ConstVisitor& v) const override;
330  /// \}
331 
332  private:
333  /**
334  * \brief Set this object as parent for all the children
335  *
336  * This should be called in every object (with children) constructor
337  * to set parents. Since it is called only in the constructors it
338  * should not be virtual to avoid ambiguities (issue #295).
339  */
340  void set_parent_in_children();
341 };
342 
343 /** \} */ // end of ast_class
344 
345 
346 
347 
348 
349 
350 } // namespace nmodl::ast
nmodl::ast::CvodeBlock::get_non_stiff_block
std::shared_ptr< StatementBlock > get_non_stiff_block() const noexcept
Getter for member variable CvodeBlock::non_stiff_block.
Definition: cvode_block.hpp:209
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::CvodeBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:13631
nmodl::ast::CvodeBlock::n_odes
std::shared_ptr< Integer > n_odes
number of ODEs to solve
Definition: cvode_block.hpp:43
nmodl::ast::CvodeBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:13661
nmodl::ast::CvodeBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: cvode_block.hpp:99
nmodl::ast::CvodeBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: cvode_block.hpp:238
nmodl::ast::CvodeBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: cvode_block.hpp:170
nmodl::ast::CvodeBlock::CvodeBlock
CvodeBlock(Name *name, Integer *n_odes, StatementBlock *non_stiff_block, StatementBlock *stiff_block)
Definition: ast.cpp:13670
nmodl::ast::CvodeBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: cvode_block.hpp:129
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::CvodeBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:13708
nmodl::ast::CvodeBlock::set_name
void set_name(std::shared_ptr< Name > &&name)
Setter for member variable CvodeBlock::name (rvalue reference)
Definition: ast.cpp:13731
nmodl::ast::CvodeBlock::get_node_name
std::string get_node_name() const override
Return name of the node.
Definition: ast.cpp:13618
block.hpp
Auto generated AST classes declaration.
nmodl::ast::CvodeBlock
Represents a block used for variable timestep integration (CVODE) of DERIVATIVE blocks.
Definition: cvode_block.hpp:38
nmodl::ast::CvodeBlock::get_stiff_block
std::shared_ptr< StatementBlock > get_stiff_block() const noexcept
Getter for member variable CvodeBlock::stiff_block.
Definition: cvode_block.hpp:218
nmodl::ast::Integer
Represents an integer variable.
Definition: integer.hpp:49
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::CvodeBlock::set_n_odes
void set_n_odes(std::shared_ptr< Integer > &&n_odes)
Setter for member variable CvodeBlock::n_odes (rvalue reference)
Definition: ast.cpp:13748
nmodl::ast::CvodeBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: cvode_block.hpp:49
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::CvodeBlock::stiff_block
std::shared_ptr< StatementBlock > stiff_block
Block with statements of the form Dvar = Dvar / (1 - dt * J(f)), used for updating stiff systems.
Definition: cvode_block.hpp:47
nmodl::ast::CvodeBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: cvode_block.hpp:51
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::CvodeBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: cvode_block.hpp:136
nmodl::ast::CvodeBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: cvode_block.hpp:156
nmodl::ast::CvodeBlock::is_cvode_block
bool is_cvode_block() const noexcept override
Check if the ast node is an instance of ast::CvodeBlock.
Definition: cvode_block.hpp:66
nmodl::ast::CvodeBlock::name
std::shared_ptr< Name > name
Name of the block.
Definition: cvode_block.hpp:41
nmodl::ast::CvodeBlock::get_n_odes
std::shared_ptr< Integer > get_n_odes() const noexcept
Getter for member variable CvodeBlock::n_odes.
Definition: cvode_block.hpp:200
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::CvodeBlock::set_non_stiff_block
void set_non_stiff_block(std::shared_ptr< StatementBlock > &&non_stiff_block)
Setter for member variable CvodeBlock::non_stiff_block (rvalue reference)
Definition: ast.cpp:13765
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::ast::CvodeBlock::set_stiff_block
void set_stiff_block(std::shared_ptr< StatementBlock > &&stiff_block)
Setter for member variable CvodeBlock::stiff_block (rvalue reference)
Definition: ast.cpp:13782
nmodl::ast::CvodeBlock::get_shared_ptr
std::shared_ptr< const Ast > get_shared_ptr() const override
Get std::shared_ptr from this pointer of the current ast node.
Definition: cvode_block.hpp:143
nmodl::ast::StatementBlock
Represents block encapsulating list of statements.
Definition: statement_block.hpp:53
nmodl::ast::CvodeBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: cvode_block.hpp:228
nmodl::ast::CvodeBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: cvode_block.hpp:114
nmodl::ast::CvodeBlock::~CvodeBlock
virtual ~CvodeBlock()=default
nmodl::ast::Name
Represents a name.
Definition: name.hpp:44
nmodl::ast::CvodeBlock::get_name
std::shared_ptr< Name > get_name() const noexcept
Getter for member variable CvodeBlock::name.
Definition: cvode_block.hpp:191
nmodl::ast::CvodeBlock::clone
CvodeBlock * clone() const override
Return a copy of the current node.
Definition: cvode_block.hpp:81
nmodl::ast::CvodeBlock::non_stiff_block
std::shared_ptr< StatementBlock > non_stiff_block
Block with statements of the form Dvar = f(var), used for updating non-stiff systems.
Definition: cvode_block.hpp:45
nmodl::ast::AstNodeType::CVODE_BLOCK
@ CVODE_BLOCK
type of ast::CvodeBlock
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50