User Guide
constant_block.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/block.hpp"
25 
26 namespace nmodl::ast {
27 
28 /**
29  * \addtogroup ast_class
30  * \ingroup ast
31  * \{
32  */
33 
34 /**
35  * \brief Represent `CONSTANT` block in the mod file
36  *
37  * Here is an example of `CONSTANT` block in mod file:
38  *
39  * \code{.mod}
40  * CONSTANT {
41  * q10 = 3
42  *
43  * cvm = 28.9 (mV)
44  * ckm = 6.2 (mV)
45  * ctm = 0.000505 (s)
46  * }
47  * \endcode
48  *
49 */
50 class ConstantBlock : public Block {
51  private:
52  /// Vector of constant statements
54  /// token with location information
55  std::shared_ptr<ModToken> token;
56  /// symbol table for a block
58 
59  public:
60  /// \name Ctor & dtor
61  /// \{
63  ConstantBlock(const ConstantBlock& obj);
64  virtual ~ConstantBlock() = default;
65  /// \}
66 
67  /**
68  * \brief Check if the ast node is an instance of ast::ConstantBlock
69  * \return true as object is of type ast::ConstantBlock
70  */
71  bool is_constant_block () 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  ConstantBlock* clone() const override {
87  return new ConstantBlock(*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::CONSTANT_BLOCK
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. "ConstantBlock"
116  *
117  * \sa Ast::get_node_name
118  */
119  std::string get_node_type_name() const noexcept override {
120  return "ConstantBlock";
121  }
122 
123  /**
124  * \brief Return NMODL statement of ast node as std::string
125  *
126  * Every node is related to a special statement in the NMODL. This
127  * statement can be returned as a std::string for printing to
128  * text/json form.
129  *
130  * \return name of the statement as a string i.e. "CONSTANT "
131  *
132  * \sa Ast::get_nmodl_name
133  */
134  std::string get_nmodl_name() const noexcept override {
135  return "CONSTANT ";
136  }
137 
138  /**
139  * \brief Get std::shared_ptr from `this` pointer of the current ast node
140  */
141  std::shared_ptr<Ast> get_shared_ptr() override {
142  return std::static_pointer_cast<ConstantBlock>(shared_from_this());
143  }
144 
145  /**
146  * \brief Get std::shared_ptr from `this` pointer of the current ast node
147  */
148  std::shared_ptr<const Ast> get_shared_ptr() const override {
149  return std::static_pointer_cast<const ConstantBlock>(shared_from_this());
150  }
151 
152  /**
153  * \brief Return associated token for the current ast node
154  *
155  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
156  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
157  * nullptr to store in the nmodl::symtab::SymbolTable.
158  *
159  * \return pointer to token if exist otherwise nullptr
160  */
161  const ModToken* get_token() const noexcept override {
162  return token.get();
163  }
164  /**
165  * \brief Return associated symbol table for the current ast node
166  *
167  * Only certain ast nodes (e.g. inherited from ast::Block) have associated
168  * symbol table. These nodes have nmodl::symtab::SymbolTable as member
169  * and it can be accessed using this method.
170  *
171  * \return pointer to the symbol table
172  *
173  * \sa nmodl::symtab::SymbolTable nmodl::visitor::SymtabVisitor
174  */
176  return symtab;
177  }
178 
179 
180 
181  /**
182  * \brief Getter for member variable \ref ConstantBlock.statements
183  */
184  const ConstantStatementVector& get_statements() const noexcept {
185  return statements;
186  }
187  /// \}
188 
189  /// \name Setters
190  /// \{
191  /**
192  * \brief Set token for the current ast node
193  */
194  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
195  /**
196  * \brief Set symbol table for the current ast node
197  *
198  * Top level, block scoped nodes store symbol table in the ast node.
199  * nmodl::visitor::SymtabVisitor then used this method to setup symbol table
200  * for every node in the ast.
201  *
202  * \sa nmodl::visitor::SymtabVisitor
203  */
204  void set_symbol_table(symtab::SymbolTable* newsymtab) override {
205  symtab = newsymtab;
206  }
207 
208  /**
209  * \brief Setter for member variable \ref ConstantBlock.statements (rvalue reference)
210  */
212 
213  /**
214  * \brief Setter for member variable \ref ConstantBlock.statements
215  */
217 
218  /// \}
219 
220  /// \name Visitor
221  /// \{
222  /**
223  * \brief visit children i.e. member variables of current node using provided visitor
224  *
225  * Different nodes in the AST have different members (i.e. children). This method
226  * recursively visits children using provided visitor.
227  *
228  * \param v Concrete visitor that will be used to recursively visit children
229  *
230  * \sa Ast::visit_children for example.
231  */
232  void visit_children(visitor::Visitor& v) override;
233 
234  /**
235  * \brief visit children i.e. member variables of current node using provided visitor
236  *
237  * Different nodes in the AST have different members (i.e. children). This method
238  * recursively visits children using provided visitor.
239  *
240  * \param v Concrete constant visitor that will be used to recursively visit children
241  *
242  * \sa Ast::visit_children for example.
243  */
244  void visit_children(visitor::ConstVisitor& v) const override;
245 
246  /**
247  * \brief accept (or visit) the current AST node using provided visitor
248  *
249  * Instead of visiting children of AST node, like Ast::visit_children,
250  * accept allows to visit the current node itself using provided concrete
251  * visitor.
252  *
253  * \param v Concrete visitor that will be used to recursively visit node
254  *
255  * \sa Ast::accept for example.
256  */
257  void accept(visitor::Visitor& v) override;
258 
259  /**
260  * \copydoc accept(visitor::Visitor&)
261  */
262  void accept(visitor::ConstVisitor& v) const override;
263  /// \}
264 
265  private:
266  /**
267  * \brief Set this object as parent for all the children
268  *
269  * This should be called in every object (with children) constructor
270  * to set parents. Since it is called only in the constructors it
271  * should not be virtual to avoid ambiguities (issue #295).
272  */
273  void set_parent_in_children();
274 };
275 
276 /** \} */ // end of ast_class
277 
278 
279 
280 } // namespace nmodl::ast
nmodl::ast::ConstantBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: constant_block.hpp:194
nmodl::ast::ConstantStatementVector
std::vector< std::shared_ptr< ConstantStatement > > ConstantStatementVector
Definition: ast_decl.hpp:398
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::ConstantBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:5384
nmodl::ast::ConstantBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: constant_block.hpp:57
constant_statement.hpp
Auto generated AST classes declaration.
nmodl::ast::ConstantBlock::get_statements
const ConstantStatementVector & get_statements() const noexcept
Getter for member variable ConstantBlock::statements.
Definition: constant_block.hpp:184
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::ConstantBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: constant_block.hpp:104
block.hpp
Auto generated AST classes declaration.
nmodl::ast::ConstantBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: constant_block.hpp:55
nmodl::ast::ConstantBlock::clone
ConstantBlock * clone() const override
Return a copy of the current node.
Definition: constant_block.hpp:86
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::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::ConstantBlock::ConstantBlock
ConstantBlock(const ConstantStatementVector &statements)
Definition: ast.cpp:5409
nmodl::ast::ConstantBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: constant_block.hpp:204
nmodl::ast::ConstantBlock::set_statements
void set_statements(ConstantStatementVector &&statements)
Setter for member variable ConstantBlock::statements (rvalue reference)
Definition: ast.cpp:5444
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::ConstantBlock::is_constant_block
bool is_constant_block() const noexcept override
Check if the ast node is an instance of ast::ConstantBlock.
Definition: constant_block.hpp:71
nmodl::ast::ConstantBlock
Represent CONSTANT block in the mod file.
Definition: constant_block.hpp:50
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::ast::ConstantBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: constant_block.hpp:175
nmodl::ast::ConstantBlock::statements
ConstantStatementVector statements
Vector of constant statements.
Definition: constant_block.hpp:53
nmodl::ast::ConstantBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:5432
nmodl::ast::ConstantBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: constant_block.hpp:134
nmodl::ast::ConstantBlock::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: constant_block.hpp:148
nmodl::ast::ConstantBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: constant_block.hpp:119
nmodl::ast::ConstantBlock::~ConstantBlock
virtual ~ConstantBlock()=default
nmodl::ast::ConstantBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:5400
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::ConstantBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: constant_block.hpp:141
nmodl::ast::ConstantBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: constant_block.hpp:161
nmodl::ast::AstNodeType::CONSTANT_BLOCK
@ CONSTANT_BLOCK
type of ast::ConstantBlock