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