User Guide
independent_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/name.hpp"
25 
26 namespace nmodl::ast {
27 
28 /**
29  * \addtogroup ast_class
30  * \ingroup ast
31  * \{
32  */
33 
34 /**
35  * \brief Represents a `INDEPENDENT` block in the NMODL
36  *
37  * `INDEPENDENT` has following form in the NMODL specification :
38  *
39  * \code{.mod}
40  * INDEPENDENT {
41  * t FROM 0 TO 1 WITH 1 (ms)
42  * }
43  * \endcode
44  *
45 */
46 class IndependentBlock : public Block {
47  private:
48  /// List of variable that should be independent
50  /// token with location information
51  std::shared_ptr<ModToken> token;
52  /// symbol table for a block
54 
55  public:
56  /// \name Ctor & dtor
57  /// \{
58  explicit IndependentBlock(const NameVector& variables);
60  virtual ~IndependentBlock() = default;
61  /// \}
62 
63  /**
64  * \brief Check if the ast node is an instance of ast::IndependentBlock
65  * \return true as object is of type ast::IndependentBlock
66  */
67  bool is_independent_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  IndependentBlock* clone() const override {
83  return new IndependentBlock(*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::INDEPENDENT_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. "IndependentBlock"
112  *
113  * \sa Ast::get_node_name
114  */
115  std::string get_node_type_name() const noexcept override {
116  return "IndependentBlock";
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. "INDEPENDENT "
127  *
128  * \sa Ast::get_nmodl_name
129  */
130  std::string get_nmodl_name() const noexcept override {
131  return "INDEPENDENT ";
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<IndependentBlock>(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 IndependentBlock>(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  /**
178  * \brief Getter for member variable \ref IndependentBlock.variables
179  */
180  const NameVector& get_variables() const noexcept {
181  return variables;
182  }
183  /// \}
184 
185  /// \name Setters
186  /// \{
187  /**
188  * \brief Set token for the current ast node
189  */
190  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
191  /**
192  * \brief Set symbol table for the current ast node
193  *
194  * Top level, block scoped nodes store symbol table in the ast node.
195  * nmodl::visitor::SymtabVisitor then used this method to setup symbol table
196  * for every node in the ast.
197  *
198  * \sa nmodl::visitor::SymtabVisitor
199  */
200  void set_symbol_table(symtab::SymbolTable* newsymtab) override {
201  symtab = newsymtab;
202  }
203 
204  /**
205  * \brief Setter for member variable \ref IndependentBlock.variables (rvalue reference)
206  */
208 
209  /**
210  * \brief Setter for member variable \ref IndependentBlock.variables
211  */
212  void set_variables(const NameVector& variables);
213 
214  /// \}
215 
216  /// \name Visitor
217  /// \{
218  /**
219  * \brief visit children i.e. member variables of current node using provided visitor
220  *
221  * Different nodes in the AST have different members (i.e. children). This method
222  * recursively visits children using provided visitor.
223  *
224  * \param v Concrete visitor that will be used to recursively visit children
225  *
226  * \sa Ast::visit_children for example.
227  */
228  void visit_children(visitor::Visitor& v) override;
229 
230  /**
231  * \brief visit children i.e. member variables of current node using provided visitor
232  *
233  * Different nodes in the AST have different members (i.e. children). This method
234  * recursively visits children using provided visitor.
235  *
236  * \param v Concrete constant visitor that will be used to recursively visit children
237  *
238  * \sa Ast::visit_children for example.
239  */
240  void visit_children(visitor::ConstVisitor& v) const override;
241 
242  /**
243  * \brief accept (or visit) the current AST node using provided visitor
244  *
245  * Instead of visiting children of AST node, like Ast::visit_children,
246  * accept allows to visit the current node itself using provided concrete
247  * visitor.
248  *
249  * \param v Concrete visitor that will be used to recursively visit node
250  *
251  * \sa Ast::accept for example.
252  */
253  void accept(visitor::Visitor& v) override;
254 
255  /**
256  * \copydoc accept(visitor::Visitor&)
257  */
258  void accept(visitor::ConstVisitor& v) const override;
259  /// \}
260 
261  private:
262  /**
263  * \brief Set this object as parent for all the children
264  *
265  * This should be called in every object (with children) constructor
266  * to set parents. Since it is called only in the constructors it
267  * should not be virtual to avoid ambiguities (issue #295).
268  */
269  void set_parent_in_children();
270 };
271 
272 /** \} */ // end of ast_class
273 
274 
275 
276 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::IndependentBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: independent_block.hpp:171
nmodl::ast::IndependentBlock::set_variables
void set_variables(NameVector &&variables)
Setter for member variable IndependentBlock::variables (rvalue reference)
Definition: ast.cpp:2542
nmodl::ast::IndependentBlock::IndependentBlock
IndependentBlock(const NameVector &variables)
Definition: ast.cpp:2507
nmodl::ast::IndependentBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: independent_block.hpp:157
nmodl::ast::IndependentBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:2482
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::IndependentBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: independent_block.hpp:115
block.hpp
Auto generated AST classes declaration.
nmodl::ast::IndependentBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: independent_block.hpp:100
name.hpp
Auto generated AST classes declaration.
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::IndependentBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:2498
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::IndependentBlock::variables
NameVector variables
List of variable that should be independent.
Definition: independent_block.hpp:49
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::NameVector
std::vector< std::shared_ptr< Name > > NameVector
Definition: ast_decl.hpp:312
nmodl::ast::IndependentBlock::get_variables
const NameVector & get_variables() const noexcept
Getter for member variable IndependentBlock::variables.
Definition: independent_block.hpp:180
nmodl::ast::IndependentBlock::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: independent_block.hpp:144
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::IndependentBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: independent_block.hpp:53
nmodl::ast::IndependentBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:2530
nmodl::ast::IndependentBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: independent_block.hpp:130
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::ast::IndependentBlock::clone
IndependentBlock * clone() const override
Return a copy of the current node.
Definition: independent_block.hpp:82
nmodl::ast::IndependentBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: independent_block.hpp:190
nmodl::ast::IndependentBlock::is_independent_block
bool is_independent_block() const noexcept override
Check if the ast node is an instance of ast::IndependentBlock.
Definition: independent_block.hpp:67
nmodl::ast::AstNodeType::INDEPENDENT_BLOCK
@ INDEPENDENT_BLOCK
type of ast::IndependentBlock
nmodl::ast::IndependentBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: independent_block.hpp:200
nmodl::ast::IndependentBlock
Represents a INDEPENDENT block in the NMODL.
Definition: independent_block.hpp:46
nmodl::ast::IndependentBlock::~IndependentBlock
virtual ~IndependentBlock()=default
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::IndependentBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: independent_block.hpp:51
nmodl::ast::IndependentBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: independent_block.hpp:137