User Guide
argument.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 an argument to functions and procedures
35  *
36  * In case of function definitions from different ast nodes like ast::FunctionBlock,
37  * ast::ProcedureBlock, the arguments are store in the ast::Argument. For example,
38  * in below NMODL construct, `weight` is stored as ast::Argument::name and `uS` is
39  * stored as ast::Argument::unit:
40  *
41  * \code {.mod}
42  * NET_RECEIVE(weight (uS)) {
43  * g = g + weight
44  * }
45  * \endcode
46  *
47 */
48 class Argument : public Identifier {
49  private:
50  /// Name of the argument
51  std::shared_ptr<Identifier> name;
52  /// Unit of the argument
53  std::shared_ptr<Unit> unit;
54  /// token with location information
55  std::shared_ptr<ModToken> token;
56 
57  public:
58  /// \name Ctor & dtor
59  /// \{
60  explicit Argument(Identifier* name, Unit* unit);
61  explicit Argument(std::shared_ptr<Identifier> name, std::shared_ptr<Unit> unit);
62  Argument(const Argument& obj);
63  virtual ~Argument() = default;
64  /// \}
65 
66  /**
67  * \brief Check if the ast node is an instance of ast::Argument
68  * \return true as object is of type ast::Argument
69  */
70  bool is_argument () 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  Argument* clone() const override {
86  return new Argument(*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::ARGUMENT
100  *
101  * \sa Ast::get_node_type_name
102  */
103  AstNodeType get_node_type() const noexcept override {
104  return AstNodeType::ARGUMENT;
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. "Argument"
115  *
116  * \sa Ast::get_node_name
117  */
118  std::string get_node_type_name() const noexcept override {
119  return "Argument";
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<Argument>(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 Argument>(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 Argument.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 Argument.unit
175  */
176  std::shared_ptr<Unit> get_unit() const noexcept {
177  return unit;
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 Argument.name (rvalue reference)
190  */
191  void set_name(std::shared_ptr<Identifier>&& name);
192 
193  /**
194  * \brief Setter for member variable \ref Argument.name
195  */
196  void set_name(const std::shared_ptr<Identifier>& name);
197 
198 
199  /**
200  * \brief Setter for member variable \ref Argument.unit (rvalue reference)
201  */
202  void set_unit(std::shared_ptr<Unit>&& unit);
203 
204  /**
205  * \brief Setter for member variable \ref Argument.unit
206  */
207  void set_unit(const std::shared_ptr<Unit>& unit);
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::Argument::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: argument.hpp:186
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::Unit
TODO.
Definition: unit.hpp:38
nmodl::ast::Identifier
Base class for all identifiers.
Definition: identifier.hpp:41
nmodl::ast::Argument::set_name
void set_name(std::shared_ptr< Identifier > &&name)
Setter for member variable Argument::name (rvalue reference)
Definition: ast.cpp:1369
nmodl::ast::Argument::get_node_name
std::string get_node_name() const override
Return name of the node.
Definition: ast.cpp:1286
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::Argument::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: argument.hpp:146
nmodl::ast::AstNodeType::ARGUMENT
@ ARGUMENT
type of ast::Argument
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:166
nmodl::ast::Argument::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:1354
nmodl::ast::Argument::get_name
std::shared_ptr< Identifier > get_name() const noexcept
Getter for member variable Argument::name.
Definition: argument.hpp:167
nmodl::ast::Argument::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: argument.hpp:133
nmodl::ast::Argument::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: argument.hpp:118
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::Argument::set_unit
void set_unit(std::shared_ptr< Unit > &&unit)
Setter for member variable Argument::unit (rvalue reference)
Definition: ast.cpp:1386
nmodl::ast::Argument::unit
std::shared_ptr< Unit > unit
Unit of the argument.
Definition: argument.hpp:53
nmodl::ast::Argument::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: argument.hpp:103
nmodl::ast::Argument::clone
Argument * clone() const override
Return a copy of the current node.
Definition: argument.hpp:85
nmodl::ast::Argument::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: argument.hpp:126
nmodl::ast::Argument::is_argument
bool is_argument() const noexcept override
Check if the ast node is an instance of ast::Argument.
Definition: argument.hpp:70
nmodl::ast::Argument::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:1315
nmodl::ast::Argument::name
std::shared_ptr< Identifier > name
Name of the argument.
Definition: argument.hpp:51
nmodl::ast::Argument::get_unit
std::shared_ptr< Unit > get_unit() const noexcept
Getter for member variable Argument::unit.
Definition: argument.hpp:176
nmodl::ast::Argument::Argument
Argument(Identifier *name, Unit *unit)
Definition: ast.cpp:1324
nmodl::ast::Argument
Represents an argument to functions and procedures.
Definition: argument.hpp:48
nmodl::ast::Argument::~Argument
virtual ~Argument()=default
identifier.hpp
Auto generated AST classes declaration.
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::Argument::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:1293
nmodl::ast::Argument::token
std::shared_ptr< ModToken > token
token with location information
Definition: argument.hpp:55