User Guide
number.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 Base class for all numbers
35  *
36  * Base class for all number types like ast::Integer, ast::Float and ast::Double.
37  *
38 */
39 class Number : public Expression {
40 
41  public:
42  /// \name Ctor & dtor
43  /// \{
44  virtual ~Number() = default;
45  /// \}
46  /// \name Not implemented
47  /// \{
48  virtual double to_double() {
49  throw std::runtime_error("to_double not implemented");
50  }
51  /// \}
52  /**
53  * \brief Check if the ast node is an instance of ast::Number
54  * \return true as object is of type ast::Number
55  */
56  bool is_number () const noexcept override {
57  return true;
58  }
59 
60  /**
61  * \brief Return a copy of the current node
62  *
63  * Recursively make a new copy/clone of the current node including
64  * all members and return a pointer to the node. This is used for
65  * passes like nmodl::visitor::InlineVisitor where nodes are cloned in the
66  * ast.
67  *
68  * \return pointer to the clone/copy of the current node
69  */
70  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
71  Number* clone() const override {
72  return new Number(*this);
73  }
74  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
75 
76  /// \name Getters
77  /// \{
78 
79  /**
80  * \brief Return type (ast::AstNodeType) of ast node
81  *
82  * Every node in the ast has a type defined in ast::AstNodeType and this
83  * function is used to retrieve the same.
84  *
85  * \return ast node type i.e. ast::AstNodeType::NUMBER
86  *
87  * \sa Ast::get_node_type_name
88  */
89  AstNodeType get_node_type() const noexcept override {
90  return AstNodeType::NUMBER;
91  }
92 
93  /**
94  * \brief Return type (ast::AstNodeType) of ast node as std::string
95  *
96  * Every node in the ast has a type defined in ast::AstNodeType.
97  * This type name can be returned as a std::string for printing
98  * node to text/json form.
99  *
100  * \return name of the node type as a string i.e. "Number"
101  *
102  * \sa Ast::get_node_name
103  */
104  std::string get_node_type_name() const noexcept override {
105  return "Number";
106  }
107 
108 
109  /**
110  * \brief Get std::shared_ptr from `this` pointer of the current ast node
111  */
112  std::shared_ptr<Ast> get_shared_ptr() override {
113  return std::static_pointer_cast<Number>(shared_from_this());
114  }
115 
116  /**
117  * \brief Get std::shared_ptr from `this` pointer of the current ast node
118  */
119  std::shared_ptr<const Ast> get_shared_ptr() const override {
120  return std::static_pointer_cast<const Number>(shared_from_this());
121  }
122 
123  /// \}
124 
125 
126 
127  /// \name Visitor
128  /// \{
129  /**
130  * \brief visit children i.e. member variables of current node using provided visitor
131  *
132  * Different nodes in the AST have different members (i.e. children). This method
133  * recursively visits children using provided visitor.
134  *
135  * \param v Concrete visitor that will be used to recursively visit children
136  *
137  * \sa Ast::visit_children for example.
138  */
139  void visit_children(visitor::Visitor& v) override;
140 
141  /**
142  * \brief visit children i.e. member variables of current node using provided visitor
143  *
144  * Different nodes in the AST have different members (i.e. children). This method
145  * recursively visits children using provided visitor.
146  *
147  * \param v Concrete constant visitor that will be used to recursively visit children
148  *
149  * \sa Ast::visit_children for example.
150  */
151  void visit_children(visitor::ConstVisitor& v) const override;
152 
153  /**
154  * \brief accept (or visit) the current AST node using provided visitor
155  *
156  * Instead of visiting children of AST node, like Ast::visit_children,
157  * accept allows to visit the current node itself using provided concrete
158  * visitor.
159  *
160  * \param v Concrete visitor that will be used to recursively visit node
161  *
162  * \sa Ast::accept for example.
163  */
164  void accept(visitor::Visitor& v) override;
165 
166  /**
167  * \copydoc accept(visitor::Visitor&)
168  */
169  void accept(visitor::ConstVisitor& v) const override;
170  /// \}
171 
172 };
173 
174 /** \} */ // end of ast_class
175 
176 
177 } // namespace nmodl::ast
nmodl::visitor::ConstVisitor
Abstract base class for all constant visitors implementation.
Definition: visitor.hpp:302
nmodl::ast::Number::clone
Number * clone() const override
Return a copy of the current node.
Definition: number.hpp:71
nmodl::ast::Number::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: number.hpp:119
nmodl::ast::Number::~Number
virtual ~Number()=default
nmodl::ast::Number::get_shared_ptr
std::shared_ptr< Ast > get_shared_ptr() override
Get std::shared_ptr from this pointer of the current ast node.
Definition: number.hpp:112
nmodl::ast::Number::get_node_type
AstNodeType get_node_type() const noexcept override
Return type (ast::AstNodeType) of ast node.
Definition: number.hpp:89
nmodl::ast::Number::is_number
bool is_number() const noexcept override
Check if the ast node is an instance of ast::Number.
Definition: number.hpp:56
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::ast::Number::visit_children
void visit_children(visitor::Visitor &v) override
visit children i.e.
Definition: ast.cpp:436
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::visitor::Visitor
Abstract base class for all visitors implementation.
Definition: visitor.hpp:39
nmodl::ast::AstNodeType::NUMBER
@ NUMBER
type of ast::Number
nmodl::ast::Number::get_node_type_name
std::string get_node_type_name() const noexcept override
Return type (ast::AstNodeType) of ast node as std::string.
Definition: number.hpp:104
expression.hpp
Auto generated AST classes declaration.
nmodl::ast::Number
Base class for all numbers.
Definition: number.hpp:39
nmodl::ast::Expression
Base class for all expressions in the NMODL.
Definition: expression.hpp:43
nmodl::ast::Number::to_double
virtual double to_double()
Definition: number.hpp:48
nmodl::ast::Number::accept
void accept(visitor::Visitor &v) override
accept (or visit) the current AST node using provided visitor
Definition: ast.cpp:442