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