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