GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-args-block.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2021-2024 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 "pt-arg-list.h"
32 #include "pt-cmd.h"
33 #include "pt-exp.h"
34 #include "pt-id.h"
35 #include "pt-walk.h"
36 
37 #include "base-list.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 
45 {
46 public:
47 
49  : m_size_args (size_args)
50  { }
51 
52  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arg_size_spec)
53 
55  {
56  delete m_size_args;
57  }
58 
59  tree_argument_list * size_args () { return m_size_args; }
60 
61  void accept (tree_walker& tw)
62  {
63  tw.visit_arg_size_spec (*this);
64  }
65 
66 private:
67 
68  tree_argument_list *m_size_args;
69 };
70 
72 {
73 public:
74 
76  : m_fcn_args (fcn_args)
77  { }
78 
79  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arg_validation_fcns)
80 
82  {
83  delete m_fcn_args;
84  }
85 
86  tree_argument_list * fcn_args () { return m_fcn_args; }
87 
88  void accept (tree_walker& tw)
89  {
90  tw.visit_arg_validation_fcns (*this);
91  }
92 
93 private:
94 
95  tree_argument_list *m_fcn_args;
96 };
97 
99 {
100 public:
101 
105  tree_expression *default_value)
106  : m_arg_name (nullptr), m_size_spec (size_spec),
107  m_class_name (class_name), m_validation_fcns (validation_fcns),
108  m_default_value (default_value)
109  { }
110 
111  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arg_validation)
112 
114  {
115  delete m_arg_name;
116  delete m_size_spec;
117  delete m_class_name;
118  delete m_validation_fcns;
119  delete m_default_value;
120  }
121 
123  {
124  m_arg_name = name;
125  }
126 
127  tree_expression * identifier_expression () { return m_arg_name; }
128 
129  tree_arg_size_spec * size_spec () { return m_size_spec; }
130 
131  tree_identifier * class_name () { return m_class_name; }
132 
134  validation_fcns () { return m_validation_fcns; }
135 
137  initializer_expression () { return m_default_value; }
138 
139  void accept (tree_walker& tw)
140  {
141  tw.visit_arg_validation (*this);
142  }
143 
144 private:
145 
146  // May be a simple identifier or an identifier followed by a single
147  // field name.
148  tree_expression *m_arg_name;
149  tree_arg_size_spec *m_size_spec;
150  tree_identifier *m_class_name;
151  tree_arg_validation_fcns *m_validation_fcns;
152  tree_expression *m_default_value;
153 };
154 
156  : public base_list<tree_arg_validation *>
157 {
158 public:
159 
161 
163 
166  { }
167 
168  OCTAVE_DISABLE_COPY_MOVE (tree_args_block_validation_list)
169 
171 
172  void accept (tree_walker& tw)
173  {
175  }
176 };
177 
178 // FIXME: Maybe make this object an actual list even though we don't
179 // currently need it?
180 
182 {
183 public:
184 
186  : m_attr (attr)
187  { }
188 
189  OCTAVE_DISABLE_COPY_MOVE (tree_args_block_attribute_list)
190 
192  {
193  delete m_attr;
194  }
195 
196  tree_identifier * attribute () { return m_attr; }
197 
198  void accept (tree_walker& tw)
199  {
201  }
202 
203 private:
204 
205  tree_identifier *m_attr;
206 };
207 
208 // Arguments block.
209 
211 {
212 public:
213 
216  int l = -1, int c = -1)
217  : tree_command (l, c), m_attr_list (attr_list),
218  m_validation_list (validation_list),
219  m_lead_comm (nullptr), m_trail_comm (nullptr)
220  { }
221 
222  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_arguments_block)
223 
225  {
226  delete m_attr_list;
227  delete m_validation_list;
228 
229  delete m_lead_comm;
230  delete m_trail_comm;
231  }
232 
234  {
235  return m_attr_list;
236  }
237 
239  {
240  return m_validation_list;
241  }
242 
243  comment_list * leading_comment () { return m_lead_comm; }
244 
245  comment_list * trailing_comment () { return m_trail_comm; }
246 
247  void accept (tree_walker& tw)
248  {
249  tw.visit_arguments_block (*this);
250  }
251 
252 private:
253 
254  tree_args_block_attribute_list *m_attr_list;
255 
256  tree_args_block_validation_list *m_validation_list;
257 
258  // Comment preceding ARGUMENTS token.
259  comment_list *m_lead_comm;
260 
261  // Comment preceding ENDARGUMENTS token.
262  comment_list *m_trail_comm;
263 };
264 
265 OCTAVE_END_NAMESPACE(octave)
266 
267 #endif
void append(const tree_arg_validation * &s)
Definition: base-list.h:92
tree_argument_list * size_args()
Definition: pt-args-block.h:59
void accept(tree_walker &tw)
Definition: pt-args-block.h:61
tree_arg_size_spec(tree_argument_list *size_args)
Definition: pt-args-block.h:48
void accept(tree_walker &tw)
Definition: pt-args-block.h:88
tree_argument_list * fcn_args()
Definition: pt-args-block.h:86
tree_arg_validation_fcns(tree_argument_list *fcn_args)
Definition: pt-args-block.h:75
tree_expression * identifier_expression()
tree_identifier * class_name()
tree_arg_validation(tree_arg_size_spec *size_spec, tree_identifier *class_name, tree_arg_validation_fcns *validation_fcns, tree_expression *default_value)
void arg_name(tree_expression *name)
void accept(tree_walker &tw)
tree_expression * initializer_expression()
tree_arg_validation_fcns * validation_fcns()
tree_arg_size_spec * size_spec()
tree_identifier * attribute()
tree_args_block_attribute_list(tree_identifier *attr=nullptr)
void accept(tree_walker &tw)
tree_args_block_validation_list(tree_arg_validation *a)
void accept(tree_walker &tw)
tree_args_block_validation_list(const base_list< tree_arg_validation * > &a)
tree_args_block_attribute_list * attribute_list()
tree_arguments_block(tree_args_block_attribute_list *attr_list, tree_args_block_validation_list *validation_list, int l=-1, int c=-1)
void accept(tree_walker &tw)
comment_list * trailing_comment()
tree_args_block_validation_list * validation_list()
comment_list * leading_comment()
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