User Guide
initial_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 
25 namespace nmodl::ast {
26 
27 /**
28  * \addtogroup ast_class
29  * \ingroup ast
30  * \{
31  */
32 
33 /**
34  * \brief Represents a `INITIAL` block in the NMODL
35  *
36  * The code in the `INITIAL` block is executed when the hoc function `finitialize()`
37  * is called. Here is an example :
38  *
39  * \code{.mod}
40  * INITIAL {
41  * rates(v+vshift)
42  * m = minf
43  * h = hinf
44  * tadj = q10^((celsius - temp)/10)
45  * }
46  * \endcode
47  *
48 */
49 class InitialBlock : public Block {
50  private:
51  /// Block with statements vector
52  std::shared_ptr<StatementBlock> statement_block;
53  /// token with location information
54  std::shared_ptr<ModToken> token;
55  /// symbol table for a block
57 
58  public:
59  /// \name Ctor & dtor
60  /// \{
62  explicit InitialBlock(std::shared_ptr<StatementBlock> statement_block);
63  InitialBlock(const InitialBlock& obj);
64  virtual ~InitialBlock() = default;
65  /// \}
66 
67  /**
68  * \brief Check if the ast node is an instance of ast::InitialBlock
69  * \return true as object is of type ast::InitialBlock
70  */
71  bool is_initial_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  InitialBlock* clone() const override {
87  return new InitialBlock(*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::INITIAL_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. "InitialBlock"
116  *
117  * \sa Ast::get_node_name
118  */
119  std::string get_node_type_name() const noexcept override {
120  return "InitialBlock";
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. "INITIAL "
131  *
132  * \sa Ast::get_nmodl_name
133  */
134  std::string get_nmodl_name() const noexcept override {
135  return "INITIAL ";
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<InitialBlock>(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 InitialBlock>(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 InitialBlock.statement_block
183  */
184  std::shared_ptr<StatementBlock> get_statement_block() const noexcept override {
185  return statement_block;
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 InitialBlock.statement_block (rvalue reference)
210  */
211  void set_statement_block(std::shared_ptr<StatementBlock>&& statement_block);
212 
213  /**
214  * \brief Setter for member variable \ref InitialBlock.statement_block
215  */
216  void set_statement_block(const std::shared_ptr<StatementBlock>& statement_block);
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::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:298
nmodl::ast::InitialBlock::token
std::shared_ptr< ModToken > token
token with location information
Definition: initial_block.hpp:54
nmodl::ast::AstNodeType::INITIAL_BLOCK
@ INITIAL_BLOCK
type of ast::InitialBlock
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::InitialBlock::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: initial_block.hpp:148
nmodl::ast::InitialBlock::get_statement_block
std::shared_ptr< StatementBlock > get_statement_block() const noexcept override
Getter for member variable InitialBlock::statement_block.
Definition: initial_block.hpp:184
block.hpp
Auto generated AST classes declaration.
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::InitialBlock::get_nmodl_name
std::string get_nmodl_name() const noexcept override
Return NMODL statement of ast node as std::string.
Definition: initial_block.hpp:134
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:164
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::InitialBlock
Represents a INITIAL block in the NMODL.
Definition: initial_block.hpp:49
nmodl::ast::InitialBlock::statement_block
std::shared_ptr< StatementBlock > statement_block
Block with statements vector.
Definition: initial_block.hpp:52
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::InitialBlock::get_symbol_table
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Definition: initial_block.hpp:175
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::ast::InitialBlock::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:2833
nmodl::ast::InitialBlock::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: initial_block.hpp:194
nmodl::ast::StatementBlock
Represents block encapsulating list of statements.
Definition: statement_block.hpp:53
nmodl::ast::InitialBlock::set_symbol_table
void set_symbol_table(symtab::SymbolTable *newsymtab) override
Set symbol table for the current ast node.
Definition: initial_block.hpp:204
nmodl::ast::InitialBlock::~InitialBlock
virtual ~InitialBlock()=default
nmodl::ast::InitialBlock::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:2868
nmodl::ast::InitialBlock::clone
InitialBlock * clone() const override
Return a copy of the current node.
Definition: initial_block.hpp:86
nmodl::ast::InitialBlock::InitialBlock
InitialBlock(StatementBlock *statement_block)
Definition: ast.cpp:2842
nmodl::ast::InitialBlock::symtab
symtab::SymbolTable * symtab
symbol table for a block
Definition: initial_block.hpp:56
nmodl::ast::InitialBlock::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: initial_block.hpp:141
nmodl::ast::InitialBlock::set_statement_block
void set_statement_block(std::shared_ptr< StatementBlock > &&statement_block)
Setter for member variable InitialBlock::statement_block (rvalue reference)
Definition: ast.cpp:2879
nmodl::ast::InitialBlock::is_initial_block
bool is_initial_block() const noexcept override
Check if the ast node is an instance of ast::InitialBlock.
Definition: initial_block.hpp:71
nmodl::ast::InitialBlock::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: initial_block.hpp:119
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::InitialBlock::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: initial_block.hpp:161
nmodl::ast::InitialBlock::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: initial_block.hpp:104
nmodl::ast::InitialBlock::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:2821