File: pt-classdef.cc

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (309 lines) | stat: -rw-r--r-- 7,839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2012-2021 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING.  If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include <iostream>

#include "ov.h"
#include "ov-classdef.h"
#include "pt-classdef.h"
#include "pt-eval.h"

namespace octave
{
  tree_superclass_ref *
  tree_superclass_ref::dup (symbol_scope&) const
  {
    tree_superclass_ref *new_scr
      = new tree_superclass_ref (m_method_name, m_class_name,
                                 line (), column ());

    new_scr->copy_base (*this);

    return new_scr;
  }

  octave_value_list
  tree_superclass_ref::evaluate_n (tree_evaluator& tw, int nargout)
  {
    octave_value tmp
      = octave_classdef::superclass_ref (m_method_name, m_class_name);

    if (! is_postfix_indexed ())
      {
        // There was no index, so this superclass_ref object is not
        // part of an index expression.  It is also not an identifier in
        // the syntax tree but we need to handle it as if it were.  So
        // call the function here.

        octave_function *f = tmp.function_value (true);

        assert (f);

        return f->call (tw, nargout);
      }

    // The superclass_ref function object will be indexed as part of the
    // enclosing index expression.

    return ovl (tmp);
  }

  tree_metaclass_query *
  tree_metaclass_query::dup (symbol_scope&) const
  {
    tree_metaclass_query *new_mcq
      = new tree_metaclass_query (m_class_name, line (), column ());

    new_mcq->copy_base (*this);

    return new_mcq;
  }

  octave_value
  tree_metaclass_query::evaluate (tree_evaluator&, int)
  {
    return octave_classdef::metaclass_query (m_class_name);
  }

  // Classdef attribute

  // Classdef attribute_list

  tree_classdef_attribute_list::~tree_classdef_attribute_list (void)
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  // Classdef superclass

  // Classdef superclass_list

  tree_classdef_superclass_list::~tree_classdef_superclass_list (void)
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  // Classdef property

  std::string check_for_doc_string (comment_list *comments)
  {
    // If the comment list ends in a block comment or full-line comment,
    // then it is the doc string for this property.

    if (comments)
      {
        comment_elt last_elt = comments->back ();

        if (last_elt.is_block () || last_elt.is_full_line ())
          return last_elt.text ();
      }

    return "";
  }

  tree_classdef_property::tree_classdef_property (tree_identifier *i,
                                                  comment_list *comments)
    : m_id (i), m_expr (nullptr), m_comments (comments),
      m_doc_string (check_for_doc_string (m_comments))
  { }

  tree_classdef_property::tree_classdef_property (tree_identifier *i,
                                                  tree_expression *e,
                                                  comment_list *comments)
    : m_id (i), m_expr (e), m_comments (comments),
      m_doc_string (check_for_doc_string (m_comments))
  { }

  // Classdef property_list

  tree_classdef_property_list::~tree_classdef_property_list (void)
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  // Classdef properties_block

  // Classdef methods_list

  // Classdef methods_block

  // Classdef event

  tree_classdef_event::tree_classdef_event (tree_identifier *i,
                                            comment_list *comments)
    : m_id (i), m_comments (comments),
      m_doc_string (check_for_doc_string (m_comments))
  { }

  // Classdef events_list

  tree_classdef_events_list::~tree_classdef_events_list (void)
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  // Classdef events_block

  // Classdef enum

  tree_classdef_enum::tree_classdef_enum (tree_identifier *i,
                                          tree_expression *e,
                                          comment_list *comments)
    : m_id (i), m_expr (e), m_comments (comments),
      m_doc_string (check_for_doc_string (m_comments))
  { }

  // Classdef enum_list

  tree_classdef_enum_list::~tree_classdef_enum_list (void)
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  // Classdef enum_block

  // Classdef body

  tree_classdef_body::tree_classdef_body (void)
    : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst ()
  { }

  tree_classdef_body::tree_classdef_body (tree_classdef_properties_block *pb)
    : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (),
      m_doc_string (pb ? get_doc_string (pb->leading_comment ()) : "")
  {
    append (pb);
  }

  tree_classdef_body::tree_classdef_body (tree_classdef_methods_block *mb)
    : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (),
      m_doc_string (mb ? get_doc_string (mb->leading_comment ()) : "")
  {
    append (mb);
  }

  tree_classdef_body::tree_classdef_body (tree_classdef_events_block *evb)
    : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (),
      m_doc_string (evb ? get_doc_string (evb->leading_comment ()) : "")
  {
    append (evb);
  }

  tree_classdef_body::tree_classdef_body (tree_classdef_enum_block *enb)
    : m_properties_lst (), m_methods_lst (), m_events_lst (), m_enum_lst (),
      m_doc_string (enb ? get_doc_string (enb->leading_comment ()) : "")
  {
    append (enb);
  }

  tree_classdef_body::~tree_classdef_body (void)
  {
    while (! m_properties_lst.empty ())
      {
        auto p = m_properties_lst.begin ();
        delete *p;
        m_properties_lst.erase (p);
      }

    while (! m_methods_lst.empty ())
      {
        auto p = m_methods_lst.begin ();
        delete *p;
        m_methods_lst.erase (p);
      }

    while (! m_events_lst.empty ())
      {
        auto p = m_events_lst.begin ();
        delete *p;
        m_events_lst.erase (p);
      }

    while (! m_enum_lst.empty ())
      {
        auto p = m_enum_lst.begin ();
        delete *p;
        m_enum_lst.erase (p);
      }
  }

  std::string
  tree_classdef_body::get_doc_string (comment_list *comments) const
  {
    // Grab the first comment from the list and use it as the doc string
    // for this classdef body.

    if (comments)
      {
        comment_elt first_elt = comments->front ();

        return first_elt.text ();
      }

    return "";
  }

  // Classdef

  octave_value
  tree_classdef::make_meta_class (interpreter& interp, bool is_at_folder)
  {
    cdef_class cls = cdef_class::make_meta_class (interp, this, is_at_folder);

    if (cls.ok ())
      return cls.get_constructor_function ();

    return octave_value ();
  }
}