GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-args-block.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2021-2026 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pt_args_block_h)
27#define octave_pt_args_block_h 1
28
29#include "octave-config.h"
30
31#include <list>
32
33#include "pt-arg-list.h"
34#include "pt-cmd.h"
35#include "pt-exp.h"
36#include "pt-id.h"
37#include "pt-walk.h"
38
39// FIXME: We could maybe re-think the naming of some of these objects
40// before releasing a version that contains these new classes...
41
43
44class comment_list;
45
46class OCTINTERP_API tree_arg_size_spec
47{
48public:
49
51 : m_size_args (size_args)
52 { }
53
54 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arg_size_spec)
55
57 {
58 delete m_size_args;
59 }
60
61 tree_argument_list * size_args () { return m_size_args; }
62
64 {
65 tw.visit_arg_size_spec (*this);
66 }
67
68private:
69
70 tree_argument_list *m_size_args;
71};
72
73class OCTINTERP_API tree_arg_validation_fcns
74{
75public:
76
78 : m_fcn_args (fcn_args)
79 { }
80
81 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arg_validation_fcns)
82
84 {
85 delete m_fcn_args;
86 }
87
88 tree_argument_list * fcn_args () { return m_fcn_args; }
89
91 {
93 }
94
95private:
96
97 tree_argument_list *m_fcn_args;
98};
99
100class OCTINTERP_API tree_arg_validation
101{
102public:
103
105 tree_identifier *class_name,
106 tree_arg_validation_fcns *validation_fcns,
107 const token& eq_tok,
108 tree_expression *default_value)
109 : m_arg_name (nullptr), m_size_spec (size_spec),
110 m_class_name (class_name), m_validation_fcns (validation_fcns),
111 m_eq_tok (eq_tok), m_default_value (default_value)
112 { }
113
114 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arg_validation)
115
117 {
118 delete m_arg_name;
119 delete m_size_spec;
120 delete m_class_name;
121 delete m_validation_fcns;
122 delete m_default_value;
123 }
124
126 {
127 m_arg_name = name;
128 }
129
130 tree_expression * identifier_expression () { return m_arg_name; }
131
132 tree_arg_size_spec * size_spec () { return m_size_spec; }
133
134 tree_identifier * class_name () { return m_class_name; }
135
137 validation_fcns () { return m_validation_fcns; }
138
139 token eq_token () const { return m_eq_tok; }
140
142 initializer_expression () { return m_default_value; }
143
145 {
146 tw.visit_arg_validation (*this);
147 }
148
149private:
150
151 // May be a simple identifier or an identifier followed by a single
152 // field name.
153 tree_expression *m_arg_name;
154 tree_arg_size_spec *m_size_spec;
155 tree_identifier *m_class_name;
156 tree_arg_validation_fcns *m_validation_fcns;
157 token m_eq_tok;
158 tree_expression *m_default_value;
159};
160
162 : public std::list<tree_arg_validation *>
163{
164public:
165
167
169
170 tree_args_block_validation_list (const std::list<tree_arg_validation *>& a)
171 : std::list<tree_arg_validation *> (a)
172 { }
173
174 OCTAVE_DISABLE_COPY_MOVE (tree_args_block_validation_list)
175
177
179 {
181 }
182};
183
184// FIXME: Maybe make this object an actual list even though we don't
185// currently need it?
186
188{
189public:
190
192 : m_attr (attr)
193 { }
194
195 OCTAVE_DISABLE_COPY_MOVE (tree_args_block_attribute_list)
196
198 {
199 delete m_attr;
200 }
201
202 tree_identifier * attribute () { return m_attr; }
203
205 {
207 }
208
209private:
210
211 tree_identifier *m_attr;
212};
213
214// Arguments block.
215
216class OCTINTERP_API tree_arguments_block : public tree_command
217{
218public:
219
220 tree_arguments_block (const token& args_tok, tree_args_block_attribute_list *attr_list, tree_args_block_validation_list *validation_list, const token& end_tok)
221 : m_args_tok (args_tok), m_attr_list (attr_list), m_validation_list (validation_list), m_end_tok (end_tok)
222 { }
223
224 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arguments_block)
225
227 {
228 delete m_attr_list;
229 delete m_validation_list;
230 }
231
232 filepos beg_pos () const { return m_args_tok.beg_pos (); }
233 filepos end_pos () const { return m_end_tok.end_pos (); }
234
235 comment_list leading_comments () const { return m_args_tok.leading_comments (); }
236 comment_list trailing_comments () const { return m_end_tok.trailing_comments (); }
237
238 token args_token () const { return m_args_tok; }
239
241 {
242 return m_attr_list;
243 }
244
246 {
247 return m_validation_list;
248 }
249
250 token end_token () const { return m_end_tok; }
251
253 {
254 tw.visit_arguments_block (*this);
255 }
256
257private:
258
259 token m_args_tok;
260
262
263 tree_args_block_validation_list *m_validation_list;
264
265 token m_end_tok;
266};
267
268OCTAVE_END_NAMESPACE(octave)
269
270#endif
Definition token.h:42
tree_argument_list * size_args()
void accept(tree_walker &tw)
tree_arg_size_spec(tree_argument_list *size_args)
void accept(tree_walker &tw)
tree_argument_list * fcn_args()
tree_arg_validation_fcns(tree_argument_list *fcn_args)
tree_arg_validation(tree_arg_size_spec *size_spec, tree_identifier *class_name, tree_arg_validation_fcns *validation_fcns, const token &eq_tok, tree_expression *default_value)
tree_arg_size_spec * size_spec()
tree_expression * initializer_expression()
tree_identifier * class_name()
void arg_name(tree_expression *name)
token eq_token() const
void accept(tree_walker &tw)
tree_expression * identifier_expression()
tree_arg_validation_fcns * validation_fcns()
tree_identifier * attribute()
tree_args_block_attribute_list(tree_identifier *attr=nullptr)
void accept(tree_walker &tw)
tree_args_block_validation_list(const std::list< tree_arg_validation * > &a)
tree_args_block_validation_list(tree_arg_validation *a)
void accept(tree_walker &tw)
comment_list trailing_comments() const
tree_args_block_attribute_list * attribute_list()
void accept(tree_walker &tw)
tree_args_block_validation_list * validation_list()
filepos beg_pos() const
comment_list leading_comments() const
token end_token() const
tree_arguments_block(const token &args_tok, tree_args_block_attribute_list *attr_list, tree_args_block_validation_list *validation_list, const token &end_tok)
filepos end_pos() const
token args_token() const
virtual void visit_args_block_validation_list(tree_args_block_validation_list &)
Definition pt-walk.cc:85
virtual void visit_arg_size_spec(tree_arg_size_spec &)
Definition pt-walk.cc:124
virtual void visit_args_block_attribute_list(tree_args_block_attribute_list &)
Definition pt-walk.cc:76
virtual void visit_arguments_block(tree_arguments_block &)
Definition pt-walk.cc:62
virtual void visit_arg_validation_fcns(tree_arg_validation_fcns &)
Definition pt-walk.cc:133
virtual void visit_arg_validation(tree_arg_validation &)
Definition pt-walk.cc:95
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn