User Guide
assigned_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"
24 #include "ast/block.hpp"
25 
26 namespace nmodl::ast {
27 
28 /**
29  * \addtogroup ast_class
30  * \ingroup ast
31  * \{
32  */
33 
34 /**
35  * \brief Represents a `ASSIGNED` block in the NMODL
36  *
37  * The `ASSIGNED` block is used for declaring two kinds of variables :
38  * - those that are given values outside the mod files
39  * - those that appear on the left hand side of assignment statements within
40  * the mod file
41  *
42  * Below is an example of `ASSIGNED` block in the mod file:
43  *
44  * \code{.mod}
45  * ASSIGNED {
46  * ina (mA/cm2)
47  * gna (pS/um2)
48  * mtau (ms) htau (ms)
49  * tadj
50  * }
51  * \endcode
52  *
53 */
54 class AssignedBlock : public Block {
55  private:
56  /// Vector of assigned variables
58  /// token with location information
59  std::shared_ptr<ModToken> token;
60  /// symbol table for a block
62 
63  public:
64  /// \name Ctor & dtor
65  /// \{
67  AssignedBlock(const AssignedBlock& obj);
68  virtual ~AssignedBlock() = default;
69  /// \}
70 
71  /**
72  * \brief Check if the ast node is an instance of ast::AssignedBlock
73  * \return true as object is of type ast::AssignedBlock
74  */
75  bool is_assigned_block () const noexcept override {
76  return true;
77  }
78 
79  /**
80  * \brief Return a copy of the current node
81  *
82  * Recursively make a new copy/clone of the current node including
83  * all members and return a pointer to the node. This is used for
84  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
85  * ast.
86  *
87  * \return pointer to the clone/copy of the current node
88  */
89  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
90  AssignedBlock* clone() const override {
91  return new AssignedBlock(*this);
92  }
93  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
94 
95  /// \name Getters
96  /// \{
97 
98  /**
99  * \brief Return type (ast::AstNodeType) of ast node
100  *
101  * Every node in the ast has a type defined in ast::AstNodeType and this
102  * function is used to retrieve the same.
103  *
104  * \return ast node type i.e. ast::AstNodeType::ASSIGNED_BLOCK
105  *
106  * \sa Ast::get_node_type_name
107  */
108  AstNodeType get_node_type() const noexcept override {
110  }
111 
112  /**
113  * \brief Return type (ast::AstNodeType) of ast node as std::string
114  *
115  * Every node in the ast has a type defined in ast::AstNodeType.
116  * This type name can be returned as a std::string for printing
117  * node to text/json form.
118  *
119  * \return name of the node type as a string i.e. "AssignedBlock"
120  *
121  * \sa Ast::get_node_name
122  */
123  std::string get_node_type_name() const noexcept override {
124  return "AssignedBlock";
125  }
126 
127  /**
128  * \brief Return NMODL statement of ast node as std::string
129  *
130  * Every node is related to a special statement in the NMODL. This
131  * statement can be returned as a std::string for printing to
132  * text/json form.
133  *
134  * \return name of the statement as a string i.e. "ASSIGNED "
135  *
136  * \sa Ast::get_nmodl_name
137  */
138  std::string get_nmodl_name() const noexcept override {
139  return "ASSIGNED ";
140  }
141 
142  /**
143  * \brief Get std::shared_ptr from `this` pointer of the current ast node
144  */
145  std::shared_ptr<Ast> get_shared_ptr() override {
146  return std::static_pointer_cast<AssignedBlock>(shared_from_this());
147  }
148 
149  /**
150  * \brief Get std::shared_ptr from `this` pointer of the current ast node
151  */
152  std::shared_ptr<const Ast> get_shared_ptr() const override {
153  return std::static_pointer_cast<const AssignedBlock>(shared_from_this());
154  }
155 
156  /**
157  * \brief Return associated token for the current ast node
158  *
159  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
160  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
161  * nullptr to store in the nmodl::symtab::SymbolTable.
162  *
163  * \return pointer to token if exist otherwise nullptr
164  */
165  const ModToken* get_token() const noexcept override {
166  return token.get();
167  }
168  /**
169  * \brief Return associated symbol table for the current ast node
170  *
171  * Only certain ast nodes (e.g. inherited from ast::Block) have associated
172  * symbol table. These nodes have nmodl::symtab::SymbolTable as member
173  * and it can be accessed using this method.
174  *
175  * \return pointer to the symbol table
176  *
177  * \sa nmodl::symtab::SymbolTable nmodl::visitor::SymtabVisitor
178  */
180  return symtab;
181  }
182 
183  /**
184  * \brief Add member to definitions by raw pointer
185  */
187 
188  /**
189  * \brief Add member to definitions by shared_ptr
190  */
191  void emplace_back_assigned_definition(std::shared_ptr<AssignedDefinition> n);
192 
193  /**
194  * \brief Erase member to definitions
195  */
196  AssignedDefinitionVector::const_iterator erase_assigned_definition(AssignedDefinitionVector::const_iterator first);
197 
198  /**
199  * \brief Erase members to definitions
200  */
201  AssignedDefinitionVector::const_iterator erase_assigned_definition(AssignedDefinitionVector::const_iterator first, AssignedDefinitionVector::const_iterator last);
202 
203  /**
204  * \brief Erase non-consecutive members to definitions
205  *
206  * loosely following the cpp reference of remove_if
207  */
208  size_t erase_assigned_definition(std::unordered_set<AssignedDefinition*>& to_be_erased);
209 
210  /**
211  * \brief Insert member to definitions
212  */
213  AssignedDefinitionVector::const_iterator insert_assigned_definition(AssignedDefinitionVector::const_iterator position, const std::shared_ptr<AssignedDefinition>& n);
214 
215  /**
216  * \brief Insert members to definitions
217  */
218  template <class NodeType, class InputIterator>
219  void insert_assigned_definition(AssignedDefinitionVector::const_iterator position, NodeType& to, InputIterator first, InputIterator last);
220 
221  /**
222  * \brief Reset member to definitions
223  */
224  void reset_assigned_definition(AssignedDefinitionVector::const_iterator position, AssignedDefinition* n);
225 
226  /**
227  * \brief Reset member to definitions
228  */
229  void reset_assigned_definition(AssignedDefinitionVector::const_iterator position, std::shared_ptr<AssignedDefinition> n);
230 
231 
232 
233  /**
234  * \brief Getter for member variable \ref AssignedBlock.definitions
235  */
236  const AssignedDefinitionVector& get_definitions() const noexcept {
237  return definitions;
238  }
239  /// \}
240 
241  /// \name Setters
242  /// \{
243  /**
244  * \brief Set token for the current ast node
245  */
246  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
247  /**
248  * \brief Set symbol table for the current ast node
249  *
250  * Top level, block scoped nodes store symbol table in the ast node.
251  * nmodl::visitor::SymtabVisitor then used this method to setup symbol table
252  * for every node in the ast.
253  *
254  * \sa nmodl::visitor::SymtabVisitor
255  */
256  void set_symbol_table(symtab::SymbolTable* newsymtab) override {
257  symtab = newsymtab;
258  }
259 
260  /**
261  * \brief Setter for member variable \ref AssignedBlock.definitions (rvalue reference)
262  */
264 
265  /**
266  * \brief Setter for member variable \ref AssignedBlock.definitions
267  */
269 
270  /// \}
271 
272  /// \name Visitor
273  /// \{
274  /**
275  * \brief visit children i.e. member variables of current node using provided visitor
276  *
277  * Different nodes in the AST have different members (i.e. children). This method
278  * recursively visits children using provided visitor.
279  *
280  * \param v Concrete visitor that will be used to recursively visit children
281  *
282  * \sa Ast::visit_children for example.
283  */
284  void visit_children(visitor::Visitor& v) override;
285 
286  /**
287  * \brief visit children i.e. member variables of current node using provided visitor
288  *
289  * Different nodes in the AST have different members (i.e. children). This method
290  * recursively visits children using provided visitor.
291  *
292  * \param v Concrete constant visitor that will be used to recursively visit children
293  *
294  * \sa Ast::visit_children for example.
295  */
296  void visit_children(visitor::ConstVisitor& v) const override;
297 
298  /**
299  * \brief accept (or visit) the current AST node using provided visitor
300  *
301  * Instead of visiting children of AST node, like Ast::visit_children,
302  * accept allows to visit the current node itself using provided concrete
303  * visitor.
304  *
305  * \param v Concrete visitor that will be used to recursively visit node
306  *
307  * \sa Ast::accept for example.
308  */
309  void accept(visitor::Visitor& v) override;
310 
311  /**
312  * \copydoc accept(visitor::Visitor&)
313  */
314  void accept(visitor::ConstVisitor& v) const override;
315  /// \}
316 
317  private:
318  /**
319  * \brief Set this object as parent for all the children
320  *
321  * This should be called in every object (with children) constructor
322  * to set parents. Since it is called only in the constructors it
323  * should not be virtual to avoid ambiguities (issue #295).
324  */
325  void set_parent_in_children();
326 };
327 
328 /** \} */ // end of ast_class
329 
330 
331 /**
332  * \brief Insert members to definitions
333  */
334 template <class NodeType, class InputIterator>
335 void AssignedBlock::insert_assigned_definition(AssignedDefinitionVector::const_iterator position, NodeType& to, InputIterator first, InputIterator last) {
336 
337  for (auto it = first; it != last; ++it) {
338  auto& n = *it;
339  //set parents
340  n->set_parent(this);
341  }
342  definitions.insert(position, first, last);
343 }
344 
345 
346 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::AssignedBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:2669
nmodl::ast::AssignedDefinition
Represents a statement in ASSIGNED or STATE block.
Definition: assigned_definition.hpp:38
nmodl::ast::AssignedBlock::~AssignedBlock
virtual ~AssignedBlock()=default
nmodl::ast::AssignedBlock::AssignedBlock
AssignedBlock(const AssignedDefinitionVector &definitions)
Definition: ast.cpp:2678
nmodl::ast::AssignedBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: assigned_block.hpp:256
nmodl::ast::AssignedBlock::insert_assigned_definition
AssignedDefinitionVector::const_iterator insert_assigned_definition(AssignedDefinitionVector::const_iterator position, const std::shared_ptr< AssignedDefinition > &n)
Insert member to definitions.
Definition: ast.cpp:2625
nmodl::ast::AssignedBlock::erase_assigned_definition
AssignedDefinitionVector::const_iterator erase_assigned_definition(AssignedDefinitionVector::const_iterator first)
Erase member to definitions.
Definition: ast.cpp:2587
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::AssignedBlock::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: assigned_block.hpp:152
block.hpp
Auto generated AST classes declaration.
nmodl::ast::AssignedBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: assigned_block.hpp:165
nmodl::ast::AssignedBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: assigned_block.hpp:123
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::AssignedBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:2701
nmodl::ast::AssignedBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:2653
nmodl::ast::AssignedBlock
Represents a ASSIGNED block in the NMODL.
Definition: assigned_block.hpp:54
nmodl::ast::AssignedBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: assigned_block.hpp:179
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::AssignedBlock::is_assigned_block
bool is_assigned_block() const noexcept override
Check if the ast node is an instance of ast::AssignedBlock.
Definition: assigned_block.hpp:75
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::AssignedBlock::clone
AssignedBlock * clone() const override
Return a copy of the current node.
Definition: assigned_block.hpp:90
nmodl::ast::AssignedBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: assigned_block.hpp:108
nmodl::ast::AssignedBlock::get_definitions
const AssignedDefinitionVector & get_definitions() const noexcept
Getter for member variable AssignedBlock::definitions.
Definition: assigned_block.hpp:236
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::AssignedBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: assigned_block.hpp:246
nmodl::ast::AssignedBlock::emplace_back_assigned_definition
void emplace_back_assigned_definition(AssignedDefinition *n)
Add member to definitions by raw pointer.
Definition: ast.cpp:2568
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
assigned_definition.hpp
Auto generated AST classes declaration.
nmodl::ast::AssignedBlock::reset_assigned_definition
void reset_assigned_definition(AssignedDefinitionVector::const_iterator position, AssignedDefinition *n)
Reset member to definitions.
Definition: ast.cpp:2633
nmodl::ast::AssignedDefinitionVector
std::vector< std::shared_ptr< AssignedDefinition > > AssignedDefinitionVector
Definition: ast_decl.hpp:381
nmodl::ast::AssignedBlock::set_definitions
void set_definitions(AssignedDefinitionVector &&definitions)
Setter for member variable AssignedBlock::definitions (rvalue reference)
Definition: ast.cpp:2713
nmodl::ast::AssignedBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: assigned_block.hpp:61
nmodl::ast::AstNodeType::ASSIGNED_BLOCK
@ ASSIGNED_BLOCK
type of ast::AssignedBlock
nmodl::ast::AssignedBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: assigned_block.hpp:145
nmodl::ast::AssignedBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: assigned_block.hpp:138
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::AssignedBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: assigned_block.hpp:59
nmodl::ast::AssignedBlock::definitions
AssignedDefinitionVector definitions
Vector of assigned variables.
Definition: assigned_block.hpp:57