User Guide
boolean.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/number.hpp"
24 
25 namespace nmodl::ast {
26 
27 /**
28  * \addtogroup ast_class
29  * \ingroup ast
30  * \{
31  */
32 
33 /**
34  * \brief Represents a boolean variable
35  *
36  * %Boolean values in the mod file can be represented by ast::Boolean.
37  *
38  * \note Currently this type is used as only flag in some of the AST nodes. Similar to ast::Float,
39  * this type was introduced for data type specific code generation support in the future.
40  *
41 */
42 class Boolean : public Number {
43  private:
44  /// Value of boolean
45  int value;
46  /// token with location information
47  std::shared_ptr<ModToken> token;
48 
49  public:
50  /// \name Ctor & dtor
51  /// \{
52  explicit Boolean(int value);
53  Boolean(const Boolean& obj);
54  virtual ~Boolean() = default;
55  /// \}
56 
57  /**
58  * \brief Check if the ast node is an instance of ast::Boolean
59  * \return true as object is of type ast::Boolean
60  */
61  bool is_boolean () 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  Boolean* clone() const override {
77  return new Boolean(*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::BOOLEAN
91  *
92  * \sa Ast::get_node_type_name
93  */
94  AstNodeType get_node_type() const noexcept override {
95  return AstNodeType::BOOLEAN;
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. "Boolean"
106  *
107  * \sa Ast::get_node_name
108  */
109  std::string get_node_type_name() const noexcept override {
110  return "Boolean";
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<Boolean>(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 Boolean>(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 Boolean.value
145  */
146  int 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  * \brief Set new value to the current ast node
159  * \sa Boolean::eval
160  */
161  void set(bool _value) {
162  value = _value;
163  }
164 
165  /**
166  * \brief Setter for member variable \ref Boolean.value
167  */
168  void set_value(int value);
169 
170  /// \}
171 
172  /// \name Visitor
173  /// \{
174  /**
175  * \brief visit children i.e. member variables of current node using provided visitor
176  *
177  * Different nodes in the AST have different members (i.e. children). This method
178  * recursively visits children using provided visitor.
179  *
180  * \param v Concrete visitor that will be used to recursively visit children
181  *
182  * \sa Ast::visit_children for example.
183  */
184  void visit_children(visitor::Visitor& v) override;
185 
186  /**
187  * \brief visit children i.e. member variables of current node using provided visitor
188  *
189  * Different nodes in the AST have different members (i.e. children). This method
190  * recursively visits children using provided visitor.
191  *
192  * \param v Concrete constant visitor that will be used to recursively visit children
193  *
194  * \sa Ast::visit_children for example.
195  */
196  void visit_children(visitor::ConstVisitor& v) const override;
197 
198  /**
199  * \brief accept (or visit) the current AST node using provided visitor
200  *
201  * Instead of visiting children of AST node, like Ast::visit_children,
202  * accept allows to visit the current node itself using provided concrete
203  * visitor.
204  *
205  * \param v Concrete visitor that will be used to recursively visit node
206  *
207  * \sa Ast::accept for example.
208  */
209  void accept(visitor::Visitor& v) override;
210 
211  /**
212  * \copydoc accept(visitor::Visitor&)
213  */
214  void accept(visitor::ConstVisitor& v) const override;
215  /// \}
216 
217  /**
218  * \brief Negate the value of current ast node
219  *
220  * Parser parse `-x` in two parts : `x` and then `-`. Once second token
221  * `-` is encountered, the corresponding value of ast node needs to be
222  * multiplied by `-1` for ast::Number node types.
223  */
224  void negate() override {
225  value = !value;
226  }
227 
228  /**
229  * \brief Return value of the current ast node as double
230  */
231  double to_double() override {
232  return value;
233  }
234  /**
235  * \brief Return value of the ast node
236  *
237  * Base data type nodes like ast::Inetegr, ast::Double can be evaluated
238  * to their literal values. This method is used to access underlying
239  * literal value.
240  *
241  * \sa Boolean::set
242  */
243  bool eval() const {
244  return value;
245  }
246  private:
247  /**
248  * \brief Set this object as parent for all the children
249  *
250  * This should be called in every object (with children) constructor
251  * to set parents. Since it is called only in the constructors it
252  * should not be virtual to avoid ambiguities (issue #295).
253  */
254  void set_parent_in_children();
255 };
256 
257 /** \} */ // end of ast_class
258 
259 
260 
261 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:298
nmodl::ast::Boolean::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:734
nmodl::ast::Boolean::Boolean
Boolean(int value)
Definition: ast.cpp:749
nmodl::ast::Boolean::~Boolean
virtual ~Boolean()=default
nmodl::ast::Boolean::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:740
nmodl::ast::Boolean::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: boolean.hpp:109
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::Boolean::get_token
const ModToken * get_token() const noexcept override
Return associated token for the current ast node.
Definition: boolean.hpp:137
number.hpp
Auto generated AST classes declaration.
nmodl::ast
Abstract Syntax Tree (AST) related implementations.
Definition: ast_common.hpp:29
nmodl::ast::Boolean::clone
Boolean * clone() const override
Return a copy of the current node.
Definition: boolean.hpp:76
nmodl::ast::Boolean::eval
bool eval() const
Return value of the ast node.
Definition: boolean.hpp:243
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:164
nmodl::ast::AstNodeType::BOOLEAN
@ BOOLEAN
type of ast::Boolean
nmodl::ast::Boolean::value
int value
Value of boolean.
Definition: boolean.hpp:45
nmodl::ast::Boolean::to_double
double to_double() override
Return value of the current ast node as double.
Definition: boolean.hpp:231
nmodl::ast::Boolean::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: boolean.hpp:117
nmodl::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::Boolean::get_value
int get_value() const noexcept
Getter for member variable Boolean::value.
Definition: boolean.hpp:146
nmodl::ast::Boolean::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: boolean.hpp:124
nmodl::ast::Boolean::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: boolean.hpp:94
nmodl::ast::Boolean
Represents a boolean variable.
Definition: boolean.hpp:42
nmodl::ast::Boolean::set
void set(bool _value)
Set new value to the current ast node.
Definition: boolean.hpp:161
nmodl::ast::Boolean::negate
void negate() override
Negate the value of current ast node.
Definition: boolean.hpp:224
nmodl::ast::Boolean::is_boolean
bool is_boolean() const noexcept override
Check if the ast node is an instance of ast::Boolean.
Definition: boolean.hpp:61
nmodl::ast::Boolean::token
std::shared_ptr< ModToken > token
token with location information
Definition: boolean.hpp:47
nmodl::ast::Boolean::set_token
void set_token(const ModToken &tok)
Set token for the current ast node.
Definition: boolean.hpp:156
nmodl::ast::Boolean::set_value
void set_value(int value)
Setter for member variable Boolean::value.
Definition: ast.cpp:777
nmodl::ast::Number
Base class for all numbers.
Definition: number.hpp:39
nmodl::ast::Boolean::set_parent_in_children
void set_parent_in_children()
Set this object as parent for all the children.
Definition: ast.cpp:770
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50