User Guide
after_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 a `AFTER` block in NMODL
35  *
36  * This represents a block to be executed before another block.
37  * Here is an example of `BEFORE` :
38  *
39  * \code{.mod}
40  * BEFORE STEP {
41  * if (mode==1) {
42  * if (ica<imax) {
43  * imax = ica
44  * timax = t
45  * }
46  * }
47  * }
48  * \endcode
49  *
50 */
51 class AfterBlock : public Block {
52  private:
53  /// Block to be called after
54  std::shared_ptr<BABlock> bablock;
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  /// \{
63  explicit AfterBlock(BABlock* bablock);
64  explicit AfterBlock(std::shared_ptr<BABlock> bablock);
65  AfterBlock(const AfterBlock& obj);
66  virtual ~AfterBlock() = default;
67  /// \}
68 
69  /**
70  * \brief Check if the ast node is an instance of ast::AfterBlock
71  * \return true as object is of type ast::AfterBlock
72  */
73  bool is_after_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  AfterBlock* clone() const override {
89  return new AfterBlock(*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::AFTER_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. "AfterBlock"
118  *
119  * \sa Ast::get_node_name
120  */
121  std::string get_node_type_name() const noexcept override {
122  return "AfterBlock";
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. "AFTER "
133  *
134  * \sa Ast::get_nmodl_name
135  */
136  std::string get_nmodl_name() const noexcept override {
137  return "AFTER ";
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<AfterBlock>(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 AfterBlock>(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  /**
184  * \brief Getter for member variable \ref AfterBlock.bablock
185  */
186  std::shared_ptr<BABlock> get_bablock() const noexcept {
187  return bablock;
188  }
189  /// \}
190 
191  /// \name Setters
192  /// \{
193  /**
194  * \brief Set token for the current ast node
195  */
196  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
197  /**
198  * \brief Set symbol table for the current ast node
199  *
200  * Top level, block scoped nodes store symbol table in the ast node.
201  * nmodl::visitor::SymtabVisitor then used this method to setup symbol table
202  * for every node in the ast.
203  *
204  * \sa nmodl::visitor::SymtabVisitor
205  */
206  void set_symbol_table(symtab::SymbolTable* newsymtab) override {
207  symtab = newsymtab;
208  }
209 
210  /**
211  * \brief Setter for member variable \ref AfterBlock.bablock (rvalue reference)
212  */
213  void set_bablock(std::shared_ptr<BABlock>&& bablock);
214 
215  /**
216  * \brief Setter for member variable \ref AfterBlock.bablock
217  */
218  void set_bablock(const std::shared_ptr<BABlock>& bablock);
219 
220  /// \}
221 
222  /// \name Visitor
223  /// \{
224  /**
225  * \brief visit children i.e. member variables of current node using provided visitor
226  *
227  * Different nodes in the AST have different members (i.e. children). This method
228  * recursively visits children using provided visitor.
229  *
230  * \param v Concrete visitor that will be used to recursively visit children
231  *
232  * \sa Ast::visit_children for example.
233  */
234  void visit_children(visitor::Visitor& v) override;
235 
236  /**
237  * \brief visit children i.e. member variables of current node using provided visitor
238  *
239  * Different nodes in the AST have different members (i.e. children). This method
240  * recursively visits children using provided visitor.
241  *
242  * \param v Concrete constant visitor that will be used to recursively visit children
243  *
244  * \sa Ast::visit_children for example.
245  */
246  void visit_children(visitor::ConstVisitor& v) const override;
247 
248  /**
249  * \brief accept (or visit) the current AST node using provided visitor
250  *
251  * Instead of visiting children of AST node, like Ast::visit_children,
252  * accept allows to visit the current node itself using provided concrete
253  * visitor.
254  *
255  * \param v Concrete visitor that will be used to recursively visit node
256  *
257  * \sa Ast::accept for example.
258  */
259  void accept(visitor::Visitor& v) override;
260 
261  /**
262  * \copydoc accept(visitor::Visitor&)
263  */
264  void accept(visitor::ConstVisitor& v) const override;
265  /// \}
266 
267  private:
268  /**
269  * \brief Set this object as parent for all the children
270  *
271  * This should be called in every object (with children) constructor
272  * to set parents. Since it is called only in the constructors it
273  * should not be virtual to avoid ambiguities (issue #295).
274  */
275  void set_parent_in_children();
276 };
277 
278 /** \} */ // end of ast_class
279 
280 
281 
282 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::BABlock
Represents a block to be executed before or after another block.
Definition: ba_block.hpp:40
nmodl::ast::AfterBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: after_block.hpp:121
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
block.hpp
Auto generated AST classes declaration.
nmodl::ast::AfterBlock::AfterBlock
AfterBlock(BABlock *bablock)
Definition: ast.cpp:4835
nmodl::ast::AfterBlock::set_bablock
void set_bablock(std::shared_ptr< BABlock > &&bablock)
Setter for member variable AfterBlock::bablock (rvalue reference)
Definition: ast.cpp:4872
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::AfterBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:4814
nmodl::ast::AfterBlock::is_after_block
bool is_after_block() const noexcept override
Check if the ast node is an instance of ast::AfterBlock.
Definition: after_block.hpp:73
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::AfterBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: after_block.hpp:163
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::AfterBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: after_block.hpp:56
nmodl::ast::AfterBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: after_block.hpp:106
nmodl::ast::AfterBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:4861
nmodl::ast::AstNodeType::AFTER_BLOCK
@ AFTER_BLOCK
type of ast::AfterBlock
nmodl::ast::AfterBlock::bablock
std::shared_ptr< BABlock > bablock
Block to be called after.
Definition: after_block.hpp:54
nmodl::ast::AfterBlock::~AfterBlock
virtual ~AfterBlock()=default
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::AfterBlock::get_bablock
std::shared_ptr< BABlock > get_bablock() const noexcept
Getter for member variable AfterBlock::bablock.
Definition: after_block.hpp:186
nmodl::ast::AfterBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:4826
nmodl::ast::AfterBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: after_block.hpp:143
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::ast::AfterBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: after_block.hpp:206
nmodl::ast::AfterBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: after_block.hpp:196
nmodl::ast::AfterBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: after_block.hpp:136
nmodl::ast::AfterBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: after_block.hpp:58
nmodl::ast::AfterBlock::clone
AfterBlock * clone() const override
Return a copy of the current node.
Definition: after_block.hpp:88
nmodl::ast::AfterBlock
Represents a AFTER block in NMODL.
Definition: after_block.hpp:51
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::AfterBlock::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: after_block.hpp:150
nmodl::ast::AfterBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: after_block.hpp:177