User Guide
derivative_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 `DERIVATIVE` block in the NMODL
35  *
36  * This block is used to assign values to the derivatives of those
37  * `STATE`s that are described by differential equations. The statements
38  * in this block are of the form \f$y' = expr\f$. Here is an example :
39  *
40  * \code{.mod}
41  * DERIVATIVE states {
42  * rates(v)
43  * m' = (minf-m)/mtau
44  * h' = (hinf-h)/htau
45  * }
46  * \endcode
47  *
48 */
49 class DerivativeBlock : public Block {
50  private:
51  /// Name of the derivative block
52  std::shared_ptr<Name> name;
53  /// Block with statements vector
54  std::shared_ptr<StatementBlock> statement_block;
55  /// token with location information
56  std::shared_ptr<ModToken> token;
57  /// symbol table for a block
59 
60  public:
61  /// \name Ctor & dtor
62  /// \{
64  explicit DerivativeBlock(std::shared_ptr<Name> name, std::shared_ptr<StatementBlock> statement_block);
65  DerivativeBlock(const DerivativeBlock& obj);
66  virtual ~DerivativeBlock() = default;
67  /// \}
68 
69  /**
70  * \brief Check if the ast node is an instance of ast::DerivativeBlock
71  * \return true as object is of type ast::DerivativeBlock
72  */
73  bool is_derivative_block () const noexcept override {
74  return true;
75  }
76 
77  /**
78  * \brief Return a copy of the current node
79  *
80  * Recursively make a new copy/clone of the current node including
81  * all members and return a pointer to the node. This is used for
82  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
83  * ast.
84  *
85  * \return pointer to the clone/copy of the current node
86  */
87  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
88  DerivativeBlock* clone() const override {
89  return new DerivativeBlock(*this);
90  }
91  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
92 
93  /// \name Getters
94  /// \{
95 
96  /**
97  * \brief Return type (ast::AstNodeType) of ast node
98  *
99  * Every node in the ast has a type defined in ast::AstNodeType and this
100  * function is used to retrieve the same.
101  *
102  * \return ast node type i.e. ast::AstNodeType::DERIVATIVE_BLOCK
103  *
104  * \sa Ast::get_node_type_name
105  */
106  AstNodeType get_node_type() const noexcept override {
108  }
109 
110  /**
111  * \brief Return type (ast::AstNodeType) of ast node as std::string
112  *
113  * Every node in the ast has a type defined in ast::AstNodeType.
114  * This type name can be returned as a std::string for printing
115  * node to text/json form.
116  *
117  * \return name of the node type as a string i.e. "DerivativeBlock"
118  *
119  * \sa Ast::get_node_name
120  */
121  std::string get_node_type_name() const noexcept override {
122  return "DerivativeBlock";
123  }
124 
125  /**
126  * \brief Return NMODL statement of ast node as std::string
127  *
128  * Every node is related to a special statement in the NMODL. This
129  * statement can be returned as a std::string for printing to
130  * text/json form.
131  *
132  * \return name of the statement as a string i.e. "DERIVATIVE "
133  *
134  * \sa Ast::get_nmodl_name
135  */
136  std::string get_nmodl_name() const noexcept override {
137  return "DERIVATIVE ";
138  }
139 
140  /**
141  * \brief Get std::shared_ptr from `this` pointer of the current ast node
142  */
143  std::shared_ptr<Ast> get_shared_ptr() override {
144  return std::static_pointer_cast<DerivativeBlock>(shared_from_this());
145  }
146 
147  /**
148  * \brief Get std::shared_ptr from `this` pointer of the current ast node
149  */
150  std::shared_ptr<const Ast> get_shared_ptr() const override {
151  return std::static_pointer_cast<const DerivativeBlock>(shared_from_this());
152  }
153 
154  /**
155  * \brief Return associated token for the current ast node
156  *
157  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
158  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
159  * nullptr to store in the nmodl::symtab::SymbolTable.
160  *
161  * \return pointer to token if exist otherwise nullptr
162  */
163  const ModToken* get_token() const noexcept override {
164  return token.get();
165  }
166  /**
167  * \brief Return associated symbol table for the current ast node
168  *
169  * Only certain ast nodes (e.g. inherited from ast::Block) have associated
170  * symbol table. These nodes have nmodl::symtab::SymbolTable as member
171  * and it can be accessed using this method.
172  *
173  * \return pointer to the symbol table
174  *
175  * \sa nmodl::symtab::SymbolTable nmodl::visitor::SymtabVisitor
176  */
178  return symtab;
179  }
180 
181 
182  /**
183  * \brief Return name of the node
184  *
185  * Some ast nodes have a member marked designated as node name. For example,
186  * in case of this ast::Name has name designated as a
187  * node name.
188  *
189  * \return name of the node as std::string
190  *
191  * \sa Ast::get_node_type_name
192  */
193  std::string get_node_name() const override;
194 
195  /**
196  * \brief Getter for member variable \ref DerivativeBlock.name
197  */
198  std::shared_ptr<Name> get_name() const noexcept {
199  return name;
200  }
201 
202 
203 
204  /**
205  * \brief Getter for member variable \ref DerivativeBlock.statement_block
206  */
207  std::shared_ptr<StatementBlock> get_statement_block() const noexcept override {
208  return statement_block;
209  }
210  /// \}
211 
212  /// \name Setters
213  /// \{
214  /**
215  * \brief Set token for the current ast node
216  */
217  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
218  /**
219  * \brief Set symbol table for the current ast node
220  *
221  * Top level, block scoped nodes store symbol table in the ast node.
222  * nmodl::visitor::SymtabVisitor then used this method to setup symbol table
223  * for every node in the ast.
224  *
225  * \sa nmodl::visitor::SymtabVisitor
226  */
227  void set_symbol_table(symtab::SymbolTable* newsymtab) override {
228  symtab = newsymtab;
229  }
230 
231  /**
232  * \brief Setter for member variable \ref DerivativeBlock.name (rvalue reference)
233  */
234  void set_name(std::shared_ptr<Name>&& name);
235 
236  /**
237  * \brief Setter for member variable \ref DerivativeBlock.name
238  */
239  void set_name(const std::shared_ptr<Name>& name);
240 
241 
242  /**
243  * \brief Setter for member variable \ref DerivativeBlock.statement_block (rvalue reference)
244  */
245  void set_statement_block(std::shared_ptr<StatementBlock>&& statement_block);
246 
247  /**
248  * \brief Setter for member variable \ref DerivativeBlock.statement_block
249  */
250  void set_statement_block(const std::shared_ptr<StatementBlock>& statement_block);
251 
252  /// \}
253 
254  /// \name Visitor
255  /// \{
256  /**
257  * \brief visit children i.e. member variables of current node using provided visitor
258  *
259  * Different nodes in the AST have different members (i.e. children). This method
260  * recursively visits children using provided visitor.
261  *
262  * \param v Concrete visitor that will be used to recursively visit children
263  *
264  * \sa Ast::visit_children for example.
265  */
266  void visit_children(visitor::Visitor& v) override;
267 
268  /**
269  * \brief visit children i.e. member variables of current node using provided visitor
270  *
271  * Different nodes in the AST have different members (i.e. children). This method
272  * recursively visits children using provided visitor.
273  *
274  * \param v Concrete constant visitor that will be used to recursively visit children
275  *
276  * \sa Ast::visit_children for example.
277  */
278  void visit_children(visitor::ConstVisitor& v) const override;
279 
280  /**
281  * \brief accept (or visit) the current AST node using provided visitor
282  *
283  * Instead of visiting children of AST node, like Ast::visit_children,
284  * accept allows to visit the current node itself using provided concrete
285  * visitor.
286  *
287  * \param v Concrete visitor that will be used to recursively visit node
288  *
289  * \sa Ast::accept for example.
290  */
291  void accept(visitor::Visitor& v) override;
292 
293  /**
294  * \copydoc accept(visitor::Visitor&)
295  */
296  void accept(visitor::ConstVisitor& v) const override;
297  /// \}
298 
299  private:
300  /**
301  * \brief Set this object as parent for all the children
302  *
303  * This should be called in every object (with children) constructor
304  * to set parents. Since it is called only in the constructors it
305  * should not be virtual to avoid ambiguities (issue #295).
306  */
307  void set_parent_in_children();
308 };
309 
310 /** \} */ // end of ast_class
311 
312 
313 
314 
315 } // namespace nmodl::ast
nmodl::ast::AstNodeType::DERIVATIVE_BLOCK
@ DERIVATIVE_BLOCK
type of ast::DerivativeBlock
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::DerivativeBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: derivative_block.hpp:56
nmodl::ast::DerivativeBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: derivative_block.hpp:106
nmodl::ast::DerivativeBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: derivative_block.hpp:121
nmodl::ast::DerivativeBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: derivative_block.hpp:58
nmodl::ast::DerivativeBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: derivative_block.hpp:143
nmodl::ast::DerivativeBlock::~DerivativeBlock
virtual ~DerivativeBlock()=default
nmodl::ast::DerivativeBlock::get_name
std::shared_ptr< Name > get_name() const noexcept
Getter for member variable DerivativeBlock::name.
Definition: derivative_block.hpp:198
nmodl::ast::DerivativeBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: derivative_block.hpp:227
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::DerivativeBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: derivative_block.hpp:177
nmodl::ast::DerivativeBlock::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: derivative_block.hpp:150
block.hpp
Auto generated AST classes declaration.
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::DerivativeBlock::get_node_name
std::string get_node_name() const override
Return name of the node.
Definition: ast.cpp:3246
nmodl::ast::DerivativeBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: derivative_block.hpp:136
nmodl::ast::DerivativeBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:3253
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::DerivativeBlock::get_statement_block
std::shared_ptr< StatementBlock > get_statement_block() const noexcept override
Getter for member variable DerivativeBlock::statement_block.
Definition: derivative_block.hpp:207
nmodl::ast::DerivativeBlock::clone
DerivativeBlock * clone() const override
Return a copy of the current node.
Definition: derivative_block.hpp:88
nmodl::ast::DerivativeBlock
Represents DERIVATIVE block in the NMODL.
Definition: derivative_block.hpp:49
nmodl::ast::DerivativeBlock::DerivativeBlock
DerivativeBlock(Name *name, StatementBlock *statement_block)
Definition: ast.cpp:3280
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::ast::DerivativeBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: derivative_block.hpp:163
nmodl::ast::DerivativeBlock::is_derivative_block
bool is_derivative_block() const noexcept override
Check if the ast node is an instance of ast::DerivativeBlock.
Definition: derivative_block.hpp:73
nmodl::ast::StatementBlock
Represents block encapsulating list of statements.
Definition: statement_block.hpp:53
nmodl::ast::DerivativeBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:3271
nmodl::ast::DerivativeBlock::statement_block
std::shared_ptr< StatementBlock > statement_block
Block with statements vector.
Definition: derivative_block.hpp:54
nmodl::ast::Name
Represents a name.
Definition: name.hpp:44
nmodl::ast::DerivativeBlock::name
std::shared_ptr< Name > name
Name of the derivative block.
Definition: derivative_block.hpp:52
nmodl::ast::DerivativeBlock::set_statement_block
void set_statement_block(std::shared_ptr< StatementBlock > &&statement_block)
Setter for member variable DerivativeBlock::statement_block (rvalue reference)
Definition: ast.cpp:3342
nmodl::ast::DerivativeBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:3310
nmodl::ast::DerivativeBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: derivative_block.hpp:217
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::DerivativeBlock::set_name
void set_name(std::shared_ptr< Name > &&name)
Setter for member variable DerivativeBlock::name (rvalue reference)
Definition: ast.cpp:3325