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