User Guide
ba_block_type.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/expression.hpp"
24 
25 namespace nmodl::ast {
26 
27 /**
28  * \addtogroup ast_class
29  * \ingroup ast
30  * \{
31  */
32 
33 /**
34  * \brief Type to represent different block types for before/after block
35  *
36  * Different NMODL blocks can be used with ast::BeforeBlock and ast::AfterBlock.
37  * This type is used to represent such block types.
38  *
39  * \sa ast::BeforeBlock as::AfterBlock
40  *
41 */
42 class BABlockType : public Expression {
43  private:
44  /// block type
46  /// token with location information
47  std::shared_ptr<ModToken> token;
48 
49  public:
50  /// \name Ctor & dtor
51  /// \{
52  explicit BABlockType(BAType value);
53  BABlockType(const BABlockType& obj);
54  virtual ~BABlockType() = default;
55  /// \}
56 
57  /**
58  * \brief Check if the ast node is an instance of ast::BABlockType
59  * \return true as object is of type ast::BABlockType
60  */
61  bool is_ba_block_type () const noexcept override {
62  return true;
63  }
64 
65  /**
66  * \brief Return a copy of the current node
67  *
68  * Recursively make a new copy/clone of the current node including
69  * all members and return a pointer to the node. This is used for
70  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
71  * ast.
72  *
73  * \return pointer to the clone/copy of the current node
74  */
75  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
76  BABlockType* clone() const override {
77  return new BABlockType(*this);
78  }
79  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
80 
81  /// \name Getters
82  /// \{
83 
84  /**
85  * \brief Return type (ast::AstNodeType) of ast node
86  *
87  * Every node in the ast has a type defined in ast::AstNodeType and this
88  * function is used to retrieve the same.
89  *
90  * \return ast node type i.e. ast::AstNodeType::BA_BLOCK_TYPE
91  *
92  * \sa Ast::get_node_type_name
93  */
94  AstNodeType get_node_type() const noexcept override {
96  }
97 
98  /**
99  * \brief Return type (ast::AstNodeType) of ast node as std::string
100  *
101  * Every node in the ast has a type defined in ast::AstNodeType.
102  * This type name can be returned as a std::string for printing
103  * node to text/json form.
104  *
105  * \return name of the node type as a string i.e. "BABlockType"
106  *
107  * \sa Ast::get_node_name
108  */
109  std::string get_node_type_name() const noexcept override {
110  return "BABlockType";
111  }
112 
113 
114  /**
115  * \brief Get std::shared_ptr from `this` pointer of the current ast node
116  */
117  std::shared_ptr<Ast> get_shared_ptr() override {
118  return std::static_pointer_cast<BABlockType>(shared_from_this());
119  }
120 
121  /**
122  * \brief Get std::shared_ptr from `this` pointer of the current ast node
123  */
124  std::shared_ptr<const Ast> get_shared_ptr() const override {
125  return std::static_pointer_cast<const BABlockType>(shared_from_this());
126  }
127 
128  /**
129  * \brief Return associated token for the current ast node
130  *
131  * Not all ast nodes have token information. For example, nmodl::visitor::NeuronSolveVisitor
132  * can insert new nodes in the ast as a solution of ODEs. In this case, we return
133  * nullptr to store in the nmodl::symtab::SymbolTable.
134  *
135  * \return pointer to token if exist otherwise nullptr
136  */
137  const ModToken* get_token() const noexcept override {
138  return token.get();
139  }
140 
141 
142 
143  /**
144  * \brief Getter for member variable \ref BABlockType.value
145  */
146  BAType get_value() const noexcept {
147  return value;
148  }
149  /// \}
150 
151  /// \name Setters
152  /// \{
153  /**
154  * \brief Set token for the current ast node
155  */
156  void set_token(const ModToken& tok) { token = std::make_shared<ModToken>(tok); }
157 
158  /**
159  * \brief Setter for member variable \ref BABlockType.value
160  */
161  void set_value(BAType value);
162 
163  /// \}
164 
165  /// \name Visitor
166  /// \{
167  /**
168  * \brief visit children i.e. member variables of current node using provided visitor
169  *
170  * Different nodes in the AST have different members (i.e. children). This method
171  * recursively visits children using provided visitor.
172  *
173  * \param v Concrete visitor that will be used to recursively visit children
174  *
175  * \sa Ast::visit_children for example.
176  */
177  void visit_children(visitor::Visitor& v) override;
178 
179  /**
180  * \brief visit children i.e. member variables of current node using provided visitor
181  *
182  * Different nodes in the AST have different members (i.e. children). This method
183  * recursively visits children using provided visitor.
184  *
185  * \param v Concrete constant visitor that will be used to recursively visit children
186  *
187  * \sa Ast::visit_children for example.
188  */
189  void visit_children(visitor::ConstVisitor& v) const override;
190 
191  /**
192  * \brief accept (or visit) the current AST node using provided visitor
193  *
194  * Instead of visiting children of AST node, like Ast::visit_children,
195  * accept allows to visit the current node itself using provided concrete
196  * visitor.
197  *
198  * \param v Concrete visitor that will be used to recursively visit node
199  *
200  * \sa Ast::accept for example.
201  */
202  void accept(visitor::Visitor& v) override;
203 
204  /**
205  * \copydoc accept(visitor::Visitor&)
206  */
207  void accept(visitor::ConstVisitor& v) const override;
208  /// \}
209 
210  /**
211  * \brief Return enum value in string form
212  *
213  * Enum variables (e.g. ast::BinaryOp, ast::UnitStateType) have
214  * string representation when they are converted from AST back to
215  * NMODL. This method is used to return corresponding string representation.
216  */
217  std::string eval() const {
218  return BATypeNames[value];
219  }
220 
221  private:
222  /**
223  * \brief Set this object as parent for all the children
224  *
225  * This should be called in every object (with children) constructor
226  * to set parents. Since it is called only in the constructors it
227  * should not be virtual to avoid ambiguities (issue #295).
228  */
229  void set_parent_in_children();
230 };
231 
232 /** \} */ // end of ast_class
233 
234 
235 
236 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::BABlockType::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: ba_block_type.hpp:94
nmodl::ast::BABlockType::eval
std::string eval() const
Return enum value in string form.
Definition: ba_block_type.hpp:217
nmodl::ast::BAType
BAType
enum type to distinguish BEFORE or AFTER blocks
Definition: ast_common.hpp:80
nmodl::ast::BABlockType::~BABlockType
virtual ~BABlockType()=default
nmodl::ast::BABlockType::is_ba_block_type
bool is_ba_block_type() const noexcept override
Check if the ast node is an instance of ast::BABlockType.
Definition: ba_block_type.hpp:61
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::BABlockType::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: ba_block_type.hpp:109
nmodl::ast::BATypeNames
static const std::string BATypeNames[]
string representation of ast::BAType
Definition: ast_common.hpp:83
nmodl::ast::BABlockType::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:7310
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::BABlockType::BABlockType
BABlockType(BAType value)
Definition: ast.cpp:7325
nmodl::ast::BABlockType::get_value
BAType get_value() const noexcept
Getter for member variable BABlockType::value.
Definition: ba_block_type.hpp:146
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
nmodl::ast::BABlockType::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:7316
nmodl::ast::BABlockType::set_value
void set_value(BAType value)
Setter for member variable BABlockType::value.
Definition: ast.cpp:7353
nmodl::ast::BABlockType::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:7346
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::BABlockType::value
BAType value
block type
Definition: ba_block_type.hpp:45
nmodl::ast::BABlockType::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: ba_block_type.hpp:117
nmodl::ast::AstNodeType::BA_BLOCK_TYPE
@ BA_BLOCK_TYPE
type of ast::BABlockType
nmodl::ast::BABlockType::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: ba_block_type.hpp:156
nmodl::ast::BABlockType::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: ba_block_type.hpp:124
nmodl::ast::BABlockType
Type to represent different block types for before/after block.
Definition: ba_block_type.hpp:42
nmodl::ast::BABlockType::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: ba_block_type.hpp:137
expression.hpp
Auto generated AST classes declaration.
nmodl::ast::Expression
Base class for all expressions in the NMODL.
Definition: expression.hpp:43
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::BABlockType::clone
BABlockType * clone() const override
Return a copy of the current node.
Definition: ba_block_type.hpp:76
nmodl::ast::BABlockType::token
std::shared_ptr< ModToken > token
token with location information
Definition: ba_block_type.hpp:47