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