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