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