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