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