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