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