User Guide
unary_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/expression.hpp"
24 #include "ast/unary_operator.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 UnaryExpression : public Expression {
40  private:
41  /// TODO
43  /// TODO
44  std::shared_ptr<Expression> expression;
45  /// token with location information
46  std::shared_ptr<ModToken> token;
47 
48  public:
49  /// \name Ctor & dtor
50  /// \{
52  explicit UnaryExpression(const UnaryOperator& op, std::shared_ptr<Expression> expression);
53  UnaryExpression(const UnaryExpression& obj);
54  virtual ~UnaryExpression() = default;
55  /// \}
56 
57  /**
58  * \brief Check if the ast node is an instance of ast::UnaryExpression
59  * \return true as object is of type ast::UnaryExpression
60  */
61  bool is_unary_expression () const noexcept override {
62  return true;
63  }
64 
65  /**
66  * \brief Return a copy of the current node
67  *
68  * Recursively make a new copy/clone of the current node including
69  * all members and return a pointer to the node. This is used for
70  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
71  * ast.
72  *
73  * \return pointer to the clone/copy of the current node
74  */
75  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
76  UnaryExpression* clone() const override {
77  return new UnaryExpression(*this);
78  }
79  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
80 
81  /// \name Getters
82  /// \{
83 
84  /**
85  * \brief Return type (ast::AstNodeType) of ast node
86  *
87  * Every node in the ast has a type defined in ast::AstNodeType and this
88  * function is used to retrieve the same.
89  *
90  * \return ast node type i.e. ast::AstNodeType::UNARY_EXPRESSION
91  *
92  * \sa Ast::get_node_type_name
93  */
94  AstNodeType get_node_type() const noexcept override {
96  }
97 
98  /**
99  * \brief Return type (ast::AstNodeType) of ast node as std::string
100  *
101  * Every node in the ast has a type defined in ast::AstNodeType.
102  * This type name can be returned as a std::string for printing
103  * node to text/json form.
104  *
105  * \return name of the node type as a string i.e. "UnaryExpression"
106  *
107  * \sa Ast::get_node_name
108  */
109  std::string get_node_type_name() const noexcept override {
110  return "UnaryExpression";
111  }
112 
113 
114  /**
115  * \brief Get std::shared_ptr from `this` pointer of the current ast node
116  */
117  std::shared_ptr<Ast> get_shared_ptr() override {
118  return std::static_pointer_cast<UnaryExpression>(shared_from_this());
119  }
120 
121  /**
122  * \brief Get std::shared_ptr from `this` pointer of the current ast node
123  */
124  std::shared_ptr<const Ast> get_shared_ptr() const override {
125  return std::static_pointer_cast<const UnaryExpression>(shared_from_this());
126  }
127 
128  /**
129  * \brief Return associated token for the current ast node
130  *
131  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
132  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
133  * nullptr to store in the nmodl::symtab::SymbolTable.
134  *
135  * \return pointer to token if exist otherwise nullptr
136  */
137  const ModToken* get_token() const noexcept override {
138  return token.get();
139  }
140 
141 
142 
143  /**
144  * \brief Getter for member variable \ref UnaryExpression.op
145  */
146  const UnaryOperator& get_op() const noexcept {
147  return op;
148  }
149 
150 
151 
152  /**
153  * \brief Getter for member variable \ref UnaryExpression.expression
154  */
155  std::shared_ptr<Expression> get_expression() const noexcept {
156  return expression;
157  }
158  /// \}
159 
160  /// \name Setters
161  /// \{
162  /**
163  * \brief Set token for the current ast node
164  */
165  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
166 
167  /**
168  * \brief Setter for member variable \ref UnaryExpression.op (rvalue reference)
169  */
170  void set_op(UnaryOperator&& op);
171 
172  /**
173  * \brief Setter for member variable \ref UnaryExpression.op
174  */
175  void set_op(const UnaryOperator& op);
176 
177 
178  /**
179  * \brief Setter for member variable \ref UnaryExpression.expression (rvalue reference)
180  */
181  void set_expression(std::shared_ptr<Expression>&& expression);
182 
183  /**
184  * \brief Setter for member variable \ref UnaryExpression.expression
185  */
186  void set_expression(const std::shared_ptr<Expression>& expression);
187 
188  /// \}
189 
190  /// \name Visitor
191  /// \{
192  /**
193  * \brief visit children i.e. member variables of current node using provided visitor
194  *
195  * Different nodes in the AST have different members (i.e. children). This method
196  * recursively visits children using provided visitor.
197  *
198  * \param v Concrete visitor that will be used to recursively visit children
199  *
200  * \sa Ast::visit_children for example.
201  */
202  void visit_children(visitor::Visitor& v) override;
203 
204  /**
205  * \brief visit children i.e. member variables of current node using provided visitor
206  *
207  * Different nodes in the AST have different members (i.e. children). This method
208  * recursively visits children using provided visitor.
209  *
210  * \param v Concrete constant visitor that will be used to recursively visit children
211  *
212  * \sa Ast::visit_children for example.
213  */
214  void visit_children(visitor::ConstVisitor& v) const override;
215 
216  /**
217  * \brief accept (or visit) the current AST node using provided visitor
218  *
219  * Instead of visiting children of AST node, like Ast::visit_children,
220  * accept allows to visit the current node itself using provided concrete
221  * visitor.
222  *
223  * \param v Concrete visitor that will be used to recursively visit node
224  *
225  * \sa Ast::accept for example.
226  */
227  void accept(visitor::Visitor& v) override;
228 
229  /**
230  * \copydoc accept(visitor::Visitor&)
231  */
232  void accept(visitor::ConstVisitor& v) const override;
233  /// \}
234 
235  private:
236  /**
237  * \brief Set this object as parent for all the children
238  *
239  * This should be called in every object (with children) constructor
240  * to set parents. Since it is called only in the constructors it
241  * should not be virtual to avoid ambiguities (issue #295).
242  */
243  void set_parent_in_children();
244 };
245 
246 /** \} */ // end of ast_class
247 
248 
249 
250 
251 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::UnaryOperator
TODO.
Definition: unary_operator.hpp:38
nmodl::ast::UnaryExpression::token
std::shared_ptr< ModToken > token
token with location information
Definition: unary_expression.hpp:46
nmodl::ast::UnaryExpression::get_expression
std::shared_ptr< Expression > get_expression() const noexcept
Getter for member variable UnaryExpression::expression.
Definition: unary_expression.hpp:155
nmodl::ast::UnaryExpression::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: unary_expression.hpp:165
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::UnaryExpression::set_expression
void set_expression(std::shared_ptr< Expression > &&expression)
Setter for member variable UnaryExpression::expression (rvalue reference)
Definition: ast.cpp:6805
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::UnaryExpression::op
UnaryOperator op
TODO.
Definition: unary_expression.hpp:42
nmodl::ast::UnaryExpression::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: unary_expression.hpp:124
nmodl::ast::UnaryExpression::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:6747
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::UnaryExpression::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:6729
nmodl::ast::UnaryExpression::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: unary_expression.hpp:109
unary_operator.hpp
Auto generated AST classes declaration.
nmodl::ast::UnaryExpression
TODO.
Definition: unary_expression.hpp:39
nmodl::ast::UnaryExpression::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: unary_expression.hpp:137
nmodl::ast::UnaryExpression::~UnaryExpression
virtual ~UnaryExpression()=default
nmodl::ast::UnaryExpression::get_op
const UnaryOperator & get_op() const noexcept
Getter for member variable UnaryExpression::op.
Definition: unary_expression.hpp:146
nmodl::ast::UnaryExpression::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: unary_expression.hpp:117
nmodl::ast::UnaryExpression::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: unary_expression.hpp:94
nmodl::ast::UnaryExpression::set_op
void set_op(UnaryOperator &&op)
Setter for member variable UnaryExpression::op (rvalue reference)
Definition: ast.cpp:6796
nmodl::ast::UnaryExpression::expression
std::shared_ptr< Expression > expression
TODO.
Definition: unary_expression.hpp:44
nmodl::ast::UnaryExpression::UnaryExpression
UnaryExpression(const UnaryOperator &op, Expression *expression)
Definition: ast.cpp:6756
nmodl::ast::AstNodeType::UNARY_EXPRESSION
@ UNARY_EXPRESSION
type of ast::UnaryExpression
nmodl::ast::UnaryExpression::is_unary_expression
bool is_unary_expression() const noexcept override
Check if the ast node is an instance of ast::UnaryExpression.
Definition: unary_expression.hpp:61
nmodl::ast::UnaryExpression::clone
UnaryExpression * clone() const override
Return a copy of the current node.
Definition: unary_expression.hpp:76
expression.hpp
Auto generated AST classes declaration.
nmodl::ast::Expression
Base class for all expressions in the NMODL.
Definition: expression.hpp:43
nmodl::ast::UnaryExpression::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:6784
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50