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