User Guide
local_list_statement.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/local_var.hpp"
24 #include "ast/statement.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 LocalListStatement : public Statement {
40  private:
41  /// TODO
43  /// token with location information
44  std::shared_ptr<ModToken> token;
45 
46  public:
47  /// \name Ctor & dtor
48  /// \{
51  virtual ~LocalListStatement() = default;
52  /// \}
53 
54  /**
55  * \brief Check if the ast node is an instance of ast::LocalListStatement
56  * \return true as object is of type ast::LocalListStatement
57  */
58  bool is_local_list_statement () const noexcept override {
59  return true;
60  }
61 
62  /**
63  * \brief Return a copy of the current node
64  *
65  * Recursively make a new copy/clone of the current node including
66  * all members and return a pointer to the node. This is used for
67  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
68  * ast.
69  *
70  * \return pointer to the clone/copy of the current node
71  */
72  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
73  LocalListStatement* clone() const override {
74  return new LocalListStatement(*this);
75  }
76  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
77 
78  /// \name Getters
79  /// \{
80 
81  /**
82  * \brief Return type (ast::AstNodeType) of ast node
83  *
84  * Every node in the ast has a type defined in ast::AstNodeType and this
85  * function is used to retrieve the same.
86  *
87  * \return ast node type i.e. ast::AstNodeType::LOCAL_LIST_STATEMENT
88  *
89  * \sa Ast::get_node_type_name
90  */
91  AstNodeType get_node_type() const noexcept override {
93  }
94 
95  /**
96  * \brief Return type (ast::AstNodeType) of ast node as std::string
97  *
98  * Every node in the ast has a type defined in ast::AstNodeType.
99  * This type name can be returned as a std::string for printing
100  * node to text/json form.
101  *
102  * \return name of the node type as a string i.e. "LocalListStatement"
103  *
104  * \sa Ast::get_node_name
105  */
106  std::string get_node_type_name() const noexcept override {
107  return "LocalListStatement";
108  }
109 
110  /**
111  * \brief Return NMODL statement of ast node as std::string
112  *
113  * Every node is related to a special statement in the NMODL. This
114  * statement can be returned as a std::string for printing to
115  * text/json form.
116  *
117  * \return name of the statement as a string i.e. "LOCAL "
118  *
119  * \sa Ast::get_nmodl_name
120  */
121  std::string get_nmodl_name() const noexcept override {
122  return "LOCAL ";
123  }
124 
125  /**
126  * \brief Get std::shared_ptr from `this` pointer of the current ast node
127  */
128  std::shared_ptr<Ast> get_shared_ptr() override {
129  return std::static_pointer_cast<LocalListStatement>(shared_from_this());
130  }
131 
132  /**
133  * \brief Get std::shared_ptr from `this` pointer of the current ast node
134  */
135  std::shared_ptr<const Ast> get_shared_ptr() const override {
136  return std::static_pointer_cast<const LocalListStatement>(shared_from_this());
137  }
138 
139  /**
140  * \brief Return associated token for the current ast node
141  *
142  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
143  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
144  * nullptr to store in the nmodl::symtab::SymbolTable.
145  *
146  * \return pointer to token if exist otherwise nullptr
147  */
148  const ModToken* get_token() const noexcept override {
149  return token.get();
150  }
151 
152  /**
153  * \brief Add member to variables by raw pointer
154  */
156 
157  /**
158  * \brief Add member to variables by shared_ptr
159  */
160  void emplace_back_local_var(std::shared_ptr<LocalVar> n);
161 
162  /**
163  * \brief Erase member to variables
164  */
165  LocalVarVector::const_iterator erase_local_var(LocalVarVector::const_iterator first);
166 
167  /**
168  * \brief Erase members to variables
169  */
170  LocalVarVector::const_iterator erase_local_var(LocalVarVector::const_iterator first, LocalVarVector::const_iterator last);
171 
172  /**
173  * \brief Erase non-consecutive members to variables
174  *
175  * loosely following the cpp reference of remove_if
176  */
177  size_t erase_local_var(std::unordered_set<LocalVar*>& to_be_erased);
178 
179  /**
180  * \brief Insert member to variables
181  */
182  LocalVarVector::const_iterator insert_local_var(LocalVarVector::const_iterator position, const std::shared_ptr<LocalVar>& n);
183 
184  /**
185  * \brief Insert members to variables
186  */
187  template <class NodeType, class InputIterator>
188  void insert_local_var(LocalVarVector::const_iterator position, NodeType& to, InputIterator first, InputIterator last);
189 
190  /**
191  * \brief Reset member to variables
192  */
193  void reset_local_var(LocalVarVector::const_iterator position, LocalVar* n);
194 
195  /**
196  * \brief Reset member to variables
197  */
198  void reset_local_var(LocalVarVector::const_iterator position, std::shared_ptr<LocalVar> n);
199 
200 
201 
202  /**
203  * \brief Getter for member variable \ref LocalListStatement.variables
204  */
205  const LocalVarVector& get_variables() const noexcept {
206  return variables;
207  }
208  /// \}
209 
210  /// \name Setters
211  /// \{
212  /**
213  * \brief Set token for the current ast node
214  */
215  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
216 
217  /**
218  * \brief Setter for member variable \ref LocalListStatement.variables (rvalue reference)
219  */
221 
222  /**
223  * \brief Setter for member variable \ref LocalListStatement.variables
224  */
226 
227  /// \}
228 
229  /// \name Visitor
230  /// \{
231  /**
232  * \brief visit children i.e. member variables of current node using provided visitor
233  *
234  * Different nodes in the AST have different members (i.e. children). This method
235  * recursively visits children using provided visitor.
236  *
237  * \param v Concrete visitor that will be used to recursively visit children
238  *
239  * \sa Ast::visit_children for example.
240  */
241  void visit_children(visitor::Visitor& v) override;
242 
243  /**
244  * \brief visit children i.e. member variables of current node using provided visitor
245  *
246  * Different nodes in the AST have different members (i.e. children). This method
247  * recursively visits children using provided visitor.
248  *
249  * \param v Concrete constant visitor that will be used to recursively visit children
250  *
251  * \sa Ast::visit_children for example.
252  */
253  void visit_children(visitor::ConstVisitor& v) const override;
254 
255  /**
256  * \brief accept (or visit) the current AST node using provided visitor
257  *
258  * Instead of visiting children of AST node, like Ast::visit_children,
259  * accept allows to visit the current node itself using provided concrete
260  * visitor.
261  *
262  * \param v Concrete visitor that will be used to recursively visit node
263  *
264  * \sa Ast::accept for example.
265  */
266  void accept(visitor::Visitor& v) override;
267 
268  /**
269  * \copydoc accept(visitor::Visitor&)
270  */
271  void accept(visitor::ConstVisitor& v) const override;
272  /// \}
273 
274  private:
275  /**
276  * \brief Set this object as parent for all the children
277  *
278  * This should be called in every object (with children) constructor
279  * to set parents. Since it is called only in the constructors it
280  * should not be virtual to avoid ambiguities (issue #295).
281  */
282  void set_parent_in_children();
283 };
284 
285 /** \} */ // end of ast_class
286 
287 
288 /**
289  * \brief Insert members to variables
290  */
291 template <class NodeType, class InputIterator>
292 void LocalListStatement::insert_local_var(LocalVarVector::const_iterator position, NodeType& to, InputIterator first, InputIterator last) {
293 
294  for (auto it = first; it != last; ++it) {
295  auto& n = *it;
296  //set parents
297  n->set_parent(this);
298  }
299  variables.insert(position, first, last);
300 }
301 
302 
303 } // namespace nmodl::ast
nmodl::ast::LocalListStatement::set_variables
void set_variables(LocalVarVector &&variables)
Setter for member variable LocalListStatement::variables (rvalue reference)
Definition: ast.cpp:8041
local_var.hpp
Auto generated AST classes declaration.
nmodl::ast::LocalListStatement::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:7981
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:298
nmodl::ast::LocalListStatement::get_variables
const LocalVarVector & get_variables() const noexcept
Getter for member variable LocalListStatement::variables.
Definition: local_list_statement.hpp:205
nmodl::ast::LocalListStatement::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:8029
nmodl::ast::LocalListStatement::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:7997
nmodl::ast::LocalListStatement::erase_local_var
LocalVarVector::const_iterator erase_local_var(LocalVarVector::const_iterator first)
Erase member to variables.
Definition: ast.cpp:7915
nmodl::ast::LocalListStatement::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: local_list_statement.hpp:121
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::LocalListStatement::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: local_list_statement.hpp:135
nmodl::ast::LocalVarVector
std::vector< std::shared_ptr< LocalVar > > LocalVarVector
Definition: ast_decl.hpp:352
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:164
statement.hpp
Auto generated AST classes declaration.
nmodl::ast::LocalListStatement::reset_local_var
void reset_local_var(LocalVarVector::const_iterator position, LocalVar *n)
Reset member to variables.
Definition: ast.cpp:7961
nmodl::ast::LocalListStatement
TODO.
Definition: local_list_statement.hpp:39
nmodl::ast::LocalListStatement::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: local_list_statement.hpp:106
nmodl::ast::LocalListStatement::emplace_back_local_var
void emplace_back_local_var(LocalVar *n)
Add member to variables by raw pointer.
Definition: ast.cpp:7896
nmodl::ast::LocalListStatement::clone
LocalListStatement * clone() const override
Return a copy of the current node.
Definition: local_list_statement.hpp:73
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::LocalListStatement::insert_local_var
LocalVarVector::const_iterator insert_local_var(LocalVarVector::const_iterator position, const std::shared_ptr< LocalVar > &n)
Insert member to variables.
Definition: ast.cpp:7953
nmodl::ast::LocalListStatement::LocalListStatement
LocalListStatement(const LocalVarVector &variables)
Definition: ast.cpp:8006
nmodl::ast::LocalListStatement::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: local_list_statement.hpp:148
nmodl::ast::LocalListStatement::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: local_list_statement.hpp:91
nmodl::ast::LocalVar
TODO.
Definition: local_var.hpp:38
nmodl::ast::LocalListStatement::variables
LocalVarVector variables
TODO.
Definition: local_list_statement.hpp:42
nmodl::ast::Statement
TODO.
Definition: statement.hpp:38
nmodl::ast::AstNodeType::LOCAL_LIST_STATEMENT
@ LOCAL_LIST_STATEMENT
type of ast::LocalListStatement
nmodl::ast::LocalListStatement::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: local_list_statement.hpp:215
nmodl::ast::LocalListStatement::is_local_list_statement
bool is_local_list_statement() const noexcept override
Check if the ast node is an instance of ast::LocalListStatement.
Definition: local_list_statement.hpp:58
nmodl::ast::LocalListStatement::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: local_list_statement.hpp:128
nmodl::ast::LocalListStatement::token
std::shared_ptr< ModToken > token
token with location information
Definition: local_list_statement.hpp:44
nmodl::ast::LocalListStatement::~LocalListStatement
virtual ~LocalListStatement()=default
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50