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