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