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