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