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