GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-classdef.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2012-2025 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 (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <iostream>
31
32#include "comment-list.h"
33#include "ov.h"
34#include "ov-classdef.h"
35#include "pt-args-block.h"
36#include "pt-classdef.h"
37#include "pt-eval.h"
38
40
43{
44 tree_superclass_ref *new_scr = new tree_superclass_ref (m_method_name, m_class_name, m_token);
45
46 new_scr->copy_base (*this);
47
48 return new_scr;
49}
50
53{
54 octave_value tmp = octave_classdef::superclass_ref (m_method_name, m_class_name);
55
56 if (! is_postfix_indexed ())
57 {
58 // There was no index, so this superclass_ref object is not
59 // part of an index expression. It is also not an identifier in
60 // the syntax tree but we need to handle it as if it were. So
61 // call the function here.
62 octave_function *f = tmp.function_value (true);
63
65
66 return f->call (tw, nargout);
67 }
68
69 // The superclass_ref function object will be indexed as part of the
70 // enclosing index expression.
71
72 return ovl (tmp);
73}
74
77{
78 tree_metaclass_query *new_mcq = new tree_metaclass_query (m_class_name, m_token);
79
80 new_mcq->copy_base (*this);
81
82 return new_mcq;
83}
84
90
91// Classdef attribute
92
93// Classdef attribute_list
94
96{
97 while (! empty ())
98 {
99 auto p = begin ();
100 delete *p;
101 erase (p);
102 }
103}
104
105// Classdef superclass
106
107// Classdef superclass_list
108
110{
111 while (! empty ())
112 {
113 auto p = begin ();
114 delete *p;
115 erase (p);
116 }
117}
118
119// Classdef property
120
121static std::string
122check_for_doc_string (const comment_list& comments)
123{
124 if (! comments.empty ())
125 {
126 // If the comment list ends in a block comment or full-line
127 // comment, then it is the doc string for this property.
128
129 comment_elt last_elt = comments.back ();
130
131 if (! last_elt.is_copyright ()
132 && (last_elt.is_block () || last_elt.is_full_line ()))
133 return last_elt.text ();
134 }
135
136 return "";
137}
138
140 : m_av (av), m_doc_string (check_for_doc_string (leading_comments ()))
141{ }
142
147
150{
151 tree_identifier *id = ident ();
152
153 return id->leading_comments ();
154}
155
158{
159 tree_expression *id_expr = m_av->identifier_expression ();
160
161 return dynamic_cast<tree_identifier *> (id_expr);
162}
163
169
170// Classdef property_list
171
173{
174 while (! empty ())
175 {
176 auto p = begin ();
177 delete *p;
178 erase (p);
179 }
180}
181
182// Classdef properties_block
183
184// Classdef method_list
185
186// Classdef methods_block
187
188// Classdef event
189
193
194// Classdef event_list
195
197{
198 while (! empty ())
199 {
200 auto p = begin ();
201 delete *p;
202 erase (p);
203 }
204}
205
206// Classdef events_block
207
208// Classdef enum
209
211 : m_id (i), m_open_paren (open_paren), m_expr (e), m_close_paren (close_paren)
212{ }
213
214// Classdef enum_list
215
217{
218 while (! empty ())
219 {
220 auto p = begin ();
221 delete *p;
222 erase (p);
223 }
224}
225
226// Classdef enum_block
227
228// Classdef body
229
231 : m_property_lst (), m_method_lst (), m_event_lst (), m_enum_lst ()
232{ }
233
235 : m_property_lst (), m_method_lst (), m_event_lst (), m_enum_lst ()
236{
237 append (pb);
238}
239
241 : m_property_lst (), m_method_lst (), m_event_lst (), m_enum_lst ()
242{
243 append (mb);
244}
245
247 : m_property_lst (), m_method_lst (), m_event_lst (), m_enum_lst ()
248{
249 append (evb);
250}
251
253 : m_property_lst (), m_method_lst (), m_event_lst (), m_enum_lst ()
254{
255 append (enb);
256}
257
260{
261 if (! m_all_elements.empty ())
262 {
263 tree_base_classdef_block *element = m_all_elements.front ();
264
265 if (element)
266 return element->leading_comments ();
267 }
268
269 return comment_list ();
270}
271
273{
274 while (! m_all_elements.empty ())
275 {
276 auto p = m_all_elements.begin ();
277 delete *p;
278 m_all_elements.erase (p);
279 }
280}
281
282// Classdef
283
285tree_classdef::make_meta_class (interpreter& interp, bool is_at_folder)
286{
287 cdef_class cls = cdef_class::make_meta_class (interp, this, is_at_folder);
288
289 if (cls.ok ())
290 return cls.get_constructor_function ();
291
292 return octave_value ();
293}
294
295OCTAVE_END_NAMESPACE(octave)
octave_value get_constructor_function()
Definition cdef-class.h:374
static cdef_class make_meta_class(interpreter &interp, tree_classdef *t, bool is_at_folder=false)
Analyze the tree_classdef tree and transform it to a cdef_class.
bool ok() const
bool is_full_line() const
std::string text() const
bool is_block() const
bool is_copyright() const
reference back()
bool empty() const
static octave_value metaclass_query(const std::string &cls)
static octave_value superclass_ref(const std::string &meth, const std::string &cls)
octave_function * function_value(bool silent=false) const
Definition token.h:42
tree_expression * initializer_expression()
tree_expression * identifier_expression()
comment_list leading_comments() const
tree_classdef_body * append(tree_classdef_properties_block *pb)
comment_list leading_comments() const
tree_classdef_enum(tree_identifier *i, const token &open_paren, tree_expression *e, const token &close_paren)
tree_classdef_event(tree_identifier *i=nullptr)
comment_list leading_comments()
tree_expression * expression()
tree_classdef_property(tree_arg_validation *av)
tree_identifier * ident()
octave_value make_meta_class(interpreter &interp, bool is_at_folder=false)
bool is_postfix_indexed() const
Definition pt-exp.h:99
virtual void copy_base(const tree_expression &e)
Definition pt-exp.h:137
tree_metaclass_query * dup(symbol_scope &scope) const
octave_value evaluate(tree_evaluator &, int nargout=1)
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
tree_superclass_ref * dup(symbol_scope &scope) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition ovl.h:217
#define panic_unless(cond)
Definition panic.h:59