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