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