annotate libinterp/octave-value/cdef-class.cc @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents a61e1a0f6024
children 83f9f8bda883
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30390
diff changeset
3 // Copyright (C) 2012-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <algorithm>
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <iomanip>
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "cdef-class.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "cdef-manager.h"
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
35 #include "cdef-method.h"
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
36 #include "cdef-package.h"
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
37 #include "cdef-property.h"
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "cdef-utils.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "errwarn.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "interpreter-private.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "interpreter.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "load-path.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "ov-builtin.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "ov-classdef.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "ov-fcn-handle.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "ov-usr-fcn.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "parse.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "pt-assign.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "pt-classdef.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "pt-eval.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "pt-idx.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 #include "pt-misc.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 #include "pt-stmt.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 #include "pt-walk.h"
27189
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
55 #include "unwind-prot.h"
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 // Define to 1 to enable debugging statements.
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 #define DEBUG_TRACE 0
27146
c776d553c19e * cdef-class.cc: Repair debug code.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26975
diff changeset
59 #if DEBUG_TRACE
c776d553c19e * cdef-class.cc: Repair debug code.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26975
diff changeset
60 # include <iostream>
c776d553c19e * cdef-class.cc: Repair debug code.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26975
diff changeset
61 #endif
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
63 namespace octave
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 {
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
65 static octave_value
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
66 make_fcn_handle (const octave_value& fcn, const std::string& meth_name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
67 const std::string& class_name)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
68 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
69 octave_value retval;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
71 if (fcn.is_defined ())
26847
8bd9fd99c12a lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents: 26774
diff changeset
72 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
73 // FCN_HANDLE: METHOD
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
74 octave_fcn_handle *fh
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
75 = new octave_fcn_handle (fcn, class_name, meth_name);
26847
8bd9fd99c12a lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents: 26774
diff changeset
76
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
77 retval = octave_value (fh);
26847
8bd9fd99c12a lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents: 26774
diff changeset
78 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
80 return retval;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
81 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
83 cdef_class::cdef_class_rep::cdef_class_rep (const std::list<cdef_class>& superclasses)
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
84 : cdef_meta_object_rep (), m_member_count (0), m_handle_class (false),
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
85 m_meta (false)
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 {
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
87 put ("SuperClasses", to_ov (superclasses));
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
88 m_implicit_ctor_list = superclasses;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
91 cdef_method
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
92 cdef_class::cdef_class_rep::find_method (const std::string& nm, bool local)
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 {
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
94 auto it = m_method_map.find (nm);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
96 if (it == m_method_map.end ())
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
97 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
98 // FIXME: look into class directory
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
99 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
100 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
101 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
102 cdef_method& meth = it->second;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
104 // FIXME: check if method reload needed
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
106 if (meth.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
107 return meth;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
108 }
26773
a95887edd55e style fixes for classdef classes
John W. Eaton <jwe@octave.org>
parents: 26772
diff changeset
109
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
110 if (! local)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
111 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
112 // Look into superclasses
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
113
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
114 Cell super_classes = get ("SuperClasses").cell_value ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
116 for (int i = 0; i < super_classes.numel (); i++)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
117 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
118 cdef_class cls = lookup_class (super_classes(i));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
119
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
120 cdef_method meth = cls.find_method (nm);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
122 if (meth.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
123 return meth;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
124 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
125 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
127 return cdef_method ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
130 class ctor_analyzer : public tree_walker
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
131 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
132 public:
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
134 ctor_analyzer (void) = delete;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
136 ctor_analyzer (const std::string& ctor, const std::string& obj)
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
137 : tree_walker (), m_who (ctor), m_obj_name (obj) { }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
139 ctor_analyzer (const ctor_analyzer&) = delete;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
141 ctor_analyzer& operator = (const ctor_analyzer&) = delete;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
143 ~ctor_analyzer (void) = default;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
145 void visit_statement (tree_statement& t)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
146 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
147 if (t.is_expression ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
148 t.expression ()->accept (*this);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
149 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
151 void visit_simple_assignment (tree_simple_assignment& t)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
152 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
153 t.right_hand_side ()->accept (*this);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
154 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
156 void visit_multi_assignment (tree_multi_assignment& t)
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 {
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
158 t.right_hand_side ()->accept (*this);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
159 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
161 void visit_index_expression (tree_index_expression& t)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
162 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
163 t.expression ()->accept (*this);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
166 std::list<cdef_class> get_constructor_list (void) const
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
167 { return m_ctor_list; }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
169 // NO-OP
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
171 void visit_anon_fcn_handle (tree_anon_fcn_handle&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
172 void visit_argument_list (tree_argument_list&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
173 void visit_binary_expression (tree_binary_expression&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
174 void visit_break_command (tree_break_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
175 void visit_colon_expression (tree_colon_expression&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
176 void visit_continue_command (tree_continue_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
177 void visit_decl_command (tree_decl_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
178 void visit_decl_init_list (tree_decl_init_list&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
179 void visit_decl_elt (tree_decl_elt&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
180 void visit_simple_for_command (tree_simple_for_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
181 void visit_complex_for_command (tree_complex_for_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
182 void visit_octave_user_script (octave_user_script&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
183 void visit_octave_user_function (octave_user_function&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
184 void visit_function_def (tree_function_def&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
185 void visit_identifier (tree_identifier&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
186 void visit_if_clause (tree_if_clause&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
187 void visit_if_command (tree_if_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
188 void visit_if_command_list (tree_if_command_list&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
189 void visit_switch_case (tree_switch_case&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
190 void visit_switch_case_list (tree_switch_case_list&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
191 void visit_switch_command (tree_switch_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
192 void visit_matrix (tree_matrix&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
193 void visit_cell (tree_cell&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
194 void visit_no_op_command (tree_no_op_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
195 void visit_constant (tree_constant&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
196 void visit_fcn_handle (tree_fcn_handle&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
197 void visit_parameter_list (tree_parameter_list&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
198 void visit_postfix_expression (tree_postfix_expression&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
199 void visit_prefix_expression (tree_prefix_expression&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
200 void visit_return_command (tree_return_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
201 void visit_try_catch_command (tree_try_catch_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
202 void visit_unwind_protect_command (tree_unwind_protect_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
203 void visit_while_command (tree_while_command&) { }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
204 void visit_do_until_command (tree_do_until_command&) { }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
206 void visit_superclass_ref (tree_superclass_ref& t)
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 {
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
208 if (t.method_name () == m_obj_name)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
209 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
210 std::string class_name = t.class_name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
212 cdef_class cls = lookup_class (class_name, false);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
214 if (cls.ok ())
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
215 m_ctor_list.push_back (cls);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
219 private:
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
220
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
221 // The name of the constructor being analyzed.
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
222 std::string m_who;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
223
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
224 // The name of the first output argument of the constructor.
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
225 std::string m_obj_name;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
226
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
227 // The list of superclass constructors that are explicitly called.
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
228 std::list<cdef_class> m_ctor_list;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
229 };
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
230
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
231 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
232 cdef_class::cdef_class_rep::install_method (const cdef_method& meth)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
233 {
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
234 m_method_map[meth.get_name ()] = meth;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
235
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
236 m_member_count++;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
238 if (meth.is_constructor ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
239 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
240 // Analyze the constructor code to determine what superclass
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
241 // constructors are called explicitly.
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
242
27505
c409d16b7190 eliminate some uses of bare pointers to octave_function objects
John W. Eaton <jwe@octave.org>
parents: 27445
diff changeset
243 octave_value ov_fcn = meth.get_function ();
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
244
27505
c409d16b7190 eliminate some uses of bare pointers to octave_function objects
John W. Eaton <jwe@octave.org>
parents: 27445
diff changeset
245 if (ov_fcn.is_defined ())
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
246 {
27505
c409d16b7190 eliminate some uses of bare pointers to octave_function objects
John W. Eaton <jwe@octave.org>
parents: 27445
diff changeset
247 octave_user_function *uf = ov_fcn.user_function_value (true);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
248
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
249 if (uf)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
250 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
251 tree_parameter_list *ret_list = uf->return_list ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
252 tree_statement_list *body = uf->body ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
253
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
254 if (! ret_list || ret_list->size () != 1)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
255 error ("%s: invalid constructor output arguments",
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
256 meth.get_name ().c_str ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
257
30141
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
258 std::string m_obj_name = ret_list->front ()->name ();
58f043641a78 maint: use "m_" prefix for member variables in class ctor_analyzer.
Rik <rik@octave.org>
parents: 30075
diff changeset
259 ctor_analyzer a (meth.get_name (), m_obj_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
261 body->accept (a);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
262
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
263 std::list<cdef_class> explicit_ctor_list
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
264 = a.get_constructor_list ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
265
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
266 for (const auto& cdef_cls : explicit_ctor_list)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
267 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
268 #if DEBUG_TRACE
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
269 std::cerr << "explicit superclass constructor: "
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
270 << cdef_cls.get_name () << std::endl;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
271 #endif
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
272
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
273 m_implicit_ctor_list.remove (cdef_cls);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
274 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
275 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
276 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
277 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
278 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
280 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
281 cdef_class::cdef_class_rep::load_all_methods (void)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
282 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
283 // FIXME: re-scan class directory
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
284 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
285
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
286 Cell
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
287 cdef_class::cdef_class_rep::get_methods (bool include_ctor)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
288 {
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30259
diff changeset
289 std::map<std::string, cdef_method> meths;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
291 find_methods (meths, false, include_ctor);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
292
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
293 Cell c (meths.size (), 1);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
294
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
295 int idx = 0;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
296
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
297 for (const auto& nm_mthd : meths)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
298 c(idx++, 0) = to_ov (nm_mthd.second);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
299
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
300 return c;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
301 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
303 std::map<std::string, cdef_method>
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
304 cdef_class::cdef_class_rep::get_method_map (bool only_inherited,
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
305 bool include_ctor)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
306 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
307 std::map<std::string, cdef_method> methods;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
308
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
309 find_methods (methods, only_inherited, include_ctor);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
310
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
311 return methods;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
312 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
313
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
314 void
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
315 cdef_class::cdef_class_rep::find_methods (std::map<std::string, cdef_method>& meths,
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
316 bool only_inherited,
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
317 bool include_ctor)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
318 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
319 load_all_methods ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
320
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
321 method_const_iterator it;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
323 for (it = m_method_map.begin (); it != m_method_map.end (); ++it)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
324 {
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
325 if (include_ctor || ! it->second.is_constructor ())
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
326 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
327 std::string nm = it->second.get_name ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
328
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
329 if (meths.find (nm) == meths.end ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
330 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
331 if (only_inherited)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
332 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
333 octave_value acc = it->second.get ("Access");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
334
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
335 if (! acc.is_string ()
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
336 || acc.string_value () == "private")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
337 continue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
338 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
339
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
340 meths[nm] = it->second;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
341 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
342 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
343 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
344
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
345 // Look into superclasses
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
347 Cell super_classes = get ("SuperClasses").cell_value ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
348
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
349 for (int i = 0; i < super_classes.numel (); i++)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
350 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
351 cdef_class cls = lookup_class (super_classes(i));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
352
26950
fbb318c371db methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents: 26926
diff changeset
353 cls.get_rep ()->find_methods (meths, true, false);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
354 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
355 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
356
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
357 cdef_property
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
358 cdef_class::cdef_class_rep::find_property (const std::string& nm)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
359 {
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
360 auto it = m_property_map.find (nm);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
361
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
362 if (it != m_property_map.end ())
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
363 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
364 cdef_property& prop = it->second;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
366 if (prop.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
367 return prop;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
368 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
369
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
370 // Look into superclasses
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
371
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
372 Cell super_classes = get ("SuperClasses").cell_value ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
373
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
374 for (int i = 0; i < super_classes.numel (); i++)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
375 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
376 cdef_class cls = lookup_class (super_classes(i));
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
378 cdef_property prop = cls.find_property (nm);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
379
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
380 if (prop.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
381 return prop;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
382 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
384 return cdef_property ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
385 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
386
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
387 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
388 cdef_class::cdef_class_rep::install_property (const cdef_property& prop)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
389 {
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
390 m_property_map[prop.get_name ()] = prop;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
392 m_member_count++;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
393 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
394
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
395 Cell
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
396 cdef_class::cdef_class_rep::get_properties (int mode)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
397 {
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30259
diff changeset
398 std::map<std::string, cdef_property> props;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
399
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
400 props = get_property_map (mode);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
401
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
402 Cell c (props.size (), 1);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
403
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
404 int idx = 0;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
405
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
406 for (const auto& pname_prop : props)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
407 c(idx++, 0) = to_ov (pname_prop.second);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
408
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
409 return c;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
410 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
412 std::map<std::string, cdef_property>
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
413 cdef_class::cdef_class_rep::get_property_map (int mode)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
414 {
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30259
diff changeset
415 std::map<std::string, cdef_property> props;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
416
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
417 find_properties (props, mode);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
418
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
419 return props;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
420 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
421
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
422 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
423 cdef_class::cdef_class_rep::find_properties (std::map<std::string,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
424 cdef_property>& props,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
425 int mode)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
426 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
427 property_const_iterator it;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
428
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
429 for (it = m_property_map.begin (); it != m_property_map.end (); ++it)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
430 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
431 std::string nm = it->second.get_name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
433 if (props.find (nm) == props.end ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
434 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
435 if (mode == property_inherited)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
436 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
437 octave_value acc = it->second.get ("GetAccess");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
438
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
439 if (! acc.is_string ()
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
440 || acc.string_value () == "private")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
441 continue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
442 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
443
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
444 props[nm] = it->second;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
445 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
446 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
447
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
448 // Look into superclasses
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
449
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
450 Cell super_classes = get ("SuperClasses").cell_value ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
452 for (int i = 0; i < super_classes.numel (); i++)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
453 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
454 cdef_class cls = lookup_class (super_classes(i));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
455
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
456 cls.get_rep ()->find_properties (props,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
457 (mode == property_all
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
458 ? property_all
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
459 : property_inherited));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
460 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
461 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
462
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
463 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
464 cdef_class::cdef_class_rep::find_names (std::set<std::string>& names,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
465 bool all)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
466 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
467 load_all_methods ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
468
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
469 for (const auto& cls_fnmap : m_method_map)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
470 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
471 if (! cls_fnmap.second.is_constructor ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
472 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
473 std::string nm = cls_fnmap.second.get_name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
474
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
475 if (! all)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
476 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
477 octave_value acc = cls_fnmap.second.get ("Access");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
478
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
479 if (! acc.is_string()
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
480 || acc.string_value () != "public")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
481 continue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
482 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
483
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
484 names.insert (nm);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
485 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
486 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
487
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
488 for (const auto& pname_prop : m_property_map)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
489 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
490 std::string nm = pname_prop.second.get_name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
491
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
492 if (! all)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
493 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
494 octave_value acc = pname_prop.second.get ("GetAccess");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
495
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
496 if (! acc.is_string()
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
497 || acc.string_value () != "public")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
498 continue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
499 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
500
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
501 names.insert (nm);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
502 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
503
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
504 // Look into superclasses
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
505
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
506 Cell super_classes = get ("SuperClasses").cell_value ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
507
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
508 for (int i = 0; i < super_classes.numel (); i++)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
509 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
510 cdef_class cls = lookup_class (super_classes(i));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
511
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
512 cls.get_rep ()->find_names (names, all);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
513 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
514 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
515
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
516 string_vector
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
517 cdef_class::cdef_class_rep::get_names (void)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
518 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
519 std::set<std::string> names;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
520
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
521 find_names (names, false);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
522
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
523 string_vector v (names);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
524
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
525 return v.sort (true);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
526 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
527
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
528 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
529 cdef_class::cdef_class_rep::delete_object (const cdef_object& obj)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
530 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
531 cdef_method dtor = find_method ("delete");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
532
26926
71724787d972 don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents: 26847
diff changeset
533 // FIXME: would it be better to tell find_method above to not find
71724787d972 don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents: 26847
diff changeset
534 // overloaded functions?
71724787d972 don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents: 26847
diff changeset
535
71724787d972 don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents: 26847
diff changeset
536 if (dtor.ok () && dtor.is_defined_in_class (get_name ()))
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
537 dtor.execute (obj, octave_value_list (), 0, true, "destructor");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
538
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
539 // FIXME: should we destroy corresponding properties here?
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
540
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
541 // Call "delete" in super classes
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
543 Cell super_classes = get ("SuperClasses").cell_value ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
544
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
545 for (int i = 0; i < super_classes.numel (); i++)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
546 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
547 cdef_class cls = lookup_class (super_classes(i));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
548
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
549 if (cls.get_name () != "handle")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
550 cls.delete_object (obj);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
551 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
552 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
554 octave_value_list
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
555 cdef_class::cdef_class_rep::meta_subsref (const std::string& type,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
556 const std::list<octave_value_list>& idx,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
557 int nargout)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
558 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
559 std::size_t skip = 1;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
560
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
561 octave_value_list retval;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
562
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
563 switch (type[0])
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
564 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
565 case '(':
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
566 // Constructor call
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
567
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
569 std::cerr << "constructor" << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
570 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
571
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
572 retval(0) = construct (idx.front ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
573 break;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
575 case '.':
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
576 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
577 // Static method, constant (or property?)
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
579 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
580 std::cerr << "static method/property" << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
581 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
582
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
583 if (idx.front ().length () != 1)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
584 error ("invalid meta.class indexing");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
585
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
586 std::string nm = idx.front ()(0).xstring_value ("invalid meta.class indexing, expected a method or property name");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
587
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
588 cdef_method meth = find_method (nm);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
589
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
590 if (meth.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
591 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
592 if (! meth.is_static ())
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27189
diff changeset
593 error ("method '%s' is not static", nm.c_str ());
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
594
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
595 octave_value_list args;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
596
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
597 if (type.length () > 1 && idx.size () > 1 && type[1] == '(')
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
598 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
599 args = *(++(idx.begin ()));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
600 skip++;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
601 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
603 retval = meth.execute (args, (type.length () > skip
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
604 ? 1 : nargout), true,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
605 "meta.class");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
606 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
607 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
608 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
609 cdef_property prop = find_property (nm);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
610
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
611 if (! prop.ok ())
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27189
diff changeset
612 error ("no such method or property '%s'", nm.c_str ());
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
613
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
614 if (! prop.is_constant ())
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27189
diff changeset
615 error ("property '%s' is not constant", nm.c_str ());
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
616
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
617 retval(0) = prop.get_value (true, "meta.class");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
618 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
619 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
620 break;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
621
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
622 default:
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
623 error ("invalid meta.class indexing");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
624 break;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
625 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
626
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
627 if (type.length () > skip && idx.size () > skip && ! retval.empty ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
628 retval = retval(0).next_subsref (nargout, type, idx, skip);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
629
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
630 return retval;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
631 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
632
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
633 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
634 cdef_class::cdef_class_rep::meta_release (void)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
635 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
636 cdef_manager& cdm
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
637 = __get_cdef_manager__ ("cdef_class::cdef_class_rep::meta_release");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
638
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
639 cdm.unregister_class (wrap ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
640 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
641
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
642 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
643 cdef_class::cdef_class_rep::initialize_object (cdef_object& obj)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
644 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
645 // Populate the object with default property values
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
646
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27216
diff changeset
647 std::list<cdef_class> super_classes
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27216
diff changeset
648 = lookup_classes (get ("SuperClasses").cell_value ());
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
649
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
650 for (auto& cls : super_classes)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
651 cls.initialize_object (obj);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
652
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
653 for (const auto& pname_prop : m_property_map)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
654 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
655 if (! pname_prop.second.get ("Dependent").bool_value ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
656 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
657 octave_value pvalue = pname_prop.second.get ("DefaultValue");
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
658
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
659 if (pvalue.is_defined ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
660 obj.put (pname_prop.first, pvalue);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
661 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
662 obj.put (pname_prop.first, octave_value (Matrix ()));
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
663 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
664 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
665
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
666 m_count++;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
667 obj.mark_for_construction (cdef_class (this));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
668 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
669
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
670 void
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
671 cdef_class::cdef_class_rep::run_constructor (cdef_object& obj,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
672 const octave_value_list& args)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
673 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
674 octave_value_list empty_args;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
675
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
676 for (const auto& cls : m_implicit_ctor_list)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
677 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
678 cdef_class supcls = lookup_class (cls);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
679
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
680 supcls.run_constructor (obj, empty_args);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
681 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
682
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
683 std::string cls_name = get_name ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
684 std::string ctor_name = get_base_name (cls_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
685
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
686 cdef_method ctor = find_method (ctor_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
687
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
688 if (ctor.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
689 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
690 octave_value_list ctor_args (args);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
691 octave_value_list ctor_retval;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
692
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
693 ctor_args.prepend (to_ov (obj));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
694 ctor_retval = ctor.execute (ctor_args, 1, true, "constructor");
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
695
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
696 if (ctor_retval.length () != 1)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
697 error ("%s: invalid number of output arguments for classdef constructor",
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
698 ctor_name.c_str ());
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
699
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
700 obj = to_cdef (ctor_retval(0));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
701 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
702
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
703 obj.mark_as_constructed (wrap ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
704 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
705
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
706 octave_value
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
707 cdef_class::cdef_class_rep::get_method (const std::string& name) const
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
708 {
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
709 auto p = m_method_map.find (name);
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
710
30075
0e0cc2760540 maint: use "m_" prefix for member variables in some classdef classes.
John W. Eaton <jwe@octave.org>
parents: 29690
diff changeset
711 if (p == m_method_map.end ())
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
712 return octave_value ();
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
713
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
714 return p->second.get_function ();
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
715 }
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
716
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
717
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26950
diff changeset
718 octave_value
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
719 cdef_class::cdef_class_rep::construct (const octave_value_list& args)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
720 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
721 cdef_object obj = construct_object (args);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
722
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
723 if (obj.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
724 return to_ov (obj);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
725
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
726 return octave_value ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
727 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
728
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
729 cdef_object
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
730 cdef_class::cdef_class_rep::construct_object (const octave_value_list& args)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
731 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
732 if (is_abstract ())
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27189
diff changeset
733 error ("cannot instantiate object for abstract class '%s'",
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
734 get_name ().c_str ());
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
735
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
736 cdef_object obj;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
737
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
738 if (is_meta_class ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
739 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
740 // This code path is only used to create empty meta objects
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
741 // as filler for the empty values within a meta object array.
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
742
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
743 cdef_class this_cls = wrap ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
744
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
745 static cdef_object empty_class;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
746
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
747 cdef_manager& cdm
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
748 = __get_cdef_manager__ ("cdef_class::cdef_class_rep::construct_object");
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
749
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
750 if (this_cls == cdm.meta_class ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
751 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
752 if (! empty_class.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
753 empty_class = cdm.make_class ("", std::list<cdef_class> ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
754 obj = empty_class;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
755 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
756 else if (this_cls == cdm.meta_property ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
757 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
758 static cdef_property empty_property;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
759
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
760 if (! empty_class.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
761 empty_class = cdm.make_class ("", std::list<cdef_class> ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
762 if (! empty_property.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
763 empty_property = cdm.make_property (empty_class, "");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
764 obj = empty_property;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
765 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
766 else if (this_cls == cdm.meta_method ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
767 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
768 static cdef_method empty_method;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
769
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
770 if (! empty_class.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
771 empty_class = cdm.make_class ("", std::list<cdef_class> ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
772 if (! empty_method.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
773 empty_method = cdm.make_method (empty_class, "", octave_value ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
774 obj = empty_method;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
775 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
776 else if (this_cls == cdm.meta_package ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
777 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
778 static cdef_package empty_package;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
779
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
780 if (! empty_package.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
781 empty_package = cdm.make_package ("");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
782 obj = empty_package;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
783 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
784 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
785 panic_impossible ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
786
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
787 return obj;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
788 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
789 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
790 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
791 if (is_handle_class ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
792 obj = cdef_object (new handle_cdef_object ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
793 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
794 obj = cdef_object (new value_cdef_object ());
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
795 obj.set_class (wrap ());
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
796
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
797 initialize_object (obj);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
798
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
799 run_constructor (obj, args);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
800
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
801 return obj;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
802 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
803
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
804 return cdef_object ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
805 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
806
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
807 static octave_value
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
808 compute_attribute_value (tree_evaluator& tw,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
809 tree_classdef_attribute *t)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
810 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
811 tree_expression *expr = t->expression ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
812
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
813 if (expr)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
814 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
815 if (expr->is_identifier ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
816 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
817 std::string s = expr->name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
818
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
819 if (s == "public")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
820 return std::string ("public");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
821 else if (s == "protected")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
822 return std::string ("protected");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
823 else if (s == "private")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
824 return std::string ("private");
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
825 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
826
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
827 return expr->evaluate (tw);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
828 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
829 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
830 return octave_value (true);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
831 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
832
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
833 template <typename T>
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
834 static std::string
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
835 attribute_value_to_string (T *t, octave_value v)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
836 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
837 if (v.is_string ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
838 return v.string_value ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
839 else if (t->expression ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
840 return t->expression ()->original_text ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
841 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
842 return "true";
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
843 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
844
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
845 cdef_class
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
846 cdef_class::make_meta_class (interpreter& interp,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
847 tree_classdef *t, bool is_at_folder)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
848 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
849 cdef_class retval;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
850
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
851 // Class creation
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852
30259
03ff3f1020cf store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents: 30141
diff changeset
853 std::string class_name = t->ident ()->name ();
03ff3f1020cf store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents: 30141
diff changeset
854 std::string full_class_name = class_name;
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
855 if (! t->package_name ().empty ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
856 full_class_name = t->package_name () + '.' + full_class_name;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
857
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
858 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
859 std::cerr << "class: " << full_class_name << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
860 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
861
27189
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
862 // Push a dummy scope frame on the call stack that corresponds to
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
863 // the scope that was used when parsing classdef object. Without
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
864 // this, we may pick up stray values from the current scope when
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
865 // evaluating expressions found in things like attribute lists.
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
866
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
867 tree_evaluator& tw = interp.get_evaluator ();
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
868
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
869 tw.push_dummy_scope (full_class_name);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 28857
diff changeset
870 unwind_action pop_scope (&tree_evaluator::pop_scope, &tw);
27189
946c6f117091 use dummy stack frame when creating meta class (bug #55766 and #55768)
John W. Eaton <jwe@octave.org>
parents: 27146
diff changeset
871
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
872 std::list<cdef_class> slist;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
873
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
874 if (t->superclass_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
875 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
876 for (auto& scls : (*t->superclass_list ()))
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
877 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
878 std::string sclass_name = (scls)->class_name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
881 std::cerr << "superclass: " << sclass_name << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
882 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
883
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
884 cdef_class sclass = lookup_class (sclass_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
885
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
886 if (sclass.get ("Sealed").bool_value ())
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27189
diff changeset
887 error ("'%s' cannot inherit from '%s', because it is sealed",
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
888 full_class_name.c_str (), sclass_name.c_str ());
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
889
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
890 slist.push_back (sclass);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
891 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
892 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
893
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
894 cdef_manager& cdm = __get_cdef_manager__ ("cdef_class::make_meta_class");
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
895
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
896 retval = cdm.make_class (full_class_name, slist);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897
28514
fab862fedf85 allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents: 28439
diff changeset
898 retval.doc_string (t->doc_string ());
30259
03ff3f1020cf store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents: 30141
diff changeset
899 retval.file_name (t->file_name ());
28514
fab862fedf85 allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents: 28439
diff changeset
900
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
901 // Package owning this class
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
902
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
903 if (! t->package_name ().empty ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
904 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
905 cdef_package pack = cdm.find_package (t->package_name ());
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
906
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
907 if (pack.ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
908 retval.put ("ContainingPackage", to_ov (pack));
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
909 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910
29690
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
911 // FIXME: instead of attaching attributes here, pass them to
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
912 // cdef_manager::make_method. The classdef manager contains a meta
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
913 // object with a list of all valid properties that can be used to
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
914 // validate the attribute list (see bug #60593).
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
915
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
916 // Class attributes
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
917
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
918 if (t->attribute_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
919 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
920 for (const auto& attr : (*t->attribute_list ()))
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
921 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
922 std::string aname = attr->ident ()->name ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
923 octave_value avalue = compute_attribute_value (tw, attr);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
924
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
925 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
926 std::cerr << "class attribute: " << aname << " = "
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
927 << attribute_value_to_string (attr, avalue) << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
928 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
929
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
930 retval.put (aname, avalue);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
931 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
932 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
933
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
934 tree_classdef_body *b = t->body ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
935
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
936 if (b)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
937 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
938 // Keep track of the get/set accessor methods. They will be used
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
939 // later on when creating properties.
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
940
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
941 std::map<std::string, octave_value> get_methods;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
942 std::map<std::string, octave_value> set_methods;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
943
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
944 // Method blocks
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
945
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
946 std::list<tree_classdef_methods_block *> mb_list = b->methods_list ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
947
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
948 load_path& lp = interp.get_load_path ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
949
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
950 for (auto& mb_p : mb_list)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
951 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
952 std::map<std::string, octave_value> amap;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
953
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
954 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
955 std::cerr << "method block" << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
957
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
958 // Method attributes
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
959
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
960 if (mb_p->attribute_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
961 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
962 for (auto& attr_p : *mb_p->attribute_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
963 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
964 std::string aname = attr_p->ident ()->name ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
965 octave_value avalue = compute_attribute_value (tw, attr_p);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
966
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
967 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
968 std::cerr << "method attribute: " << aname << " = "
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
969 << attribute_value_to_string (attr_p, avalue)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
970 << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
971 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
972
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
973 amap[aname] = avalue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
974 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
975 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
976
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
977 // Methods
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
978
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
979 if (mb_p->element_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
980 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
981 for (auto& mtd : *mb_p->element_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
982 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
983 std::string mname = mtd.function_value ()->name ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
984 std::string mprefix = mname.substr (0, 4);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
985
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
986 if (mprefix == "get.")
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
987 get_methods[mname.substr (4)]
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
988 = make_fcn_handle (mtd, mname, full_class_name);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
989 else if (mprefix == "set.")
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
990 set_methods[mname.substr (4)]
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28256
diff changeset
991 = make_fcn_handle (mtd, mname, full_class_name);
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
992 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
993 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
994 cdef_method meth = cdm.make_method (retval, mname, mtd);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
995
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
996 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
997 std::cerr << (mname == class_name ? "constructor"
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
998 : "method")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
999 << ": " << mname << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1000 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1001
29690
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1002 // FIXME: instead of attaching attributes here,
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1003 // pass them to cdef_manager::make_method. The
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1004 // classdef manager contains a meta object with
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1005 // a list of all valid properties that can be
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1006 // used to validate the attribute list (see bug
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1007 // #60593).
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1008
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1009 for (auto& attrnm_val : amap)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1010 meth.put (attrnm_val.first, attrnm_val.second);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1011
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1012 retval.install_method (meth);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1013 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1014 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1015 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1016 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1018 if (is_at_folder)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1019 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1020 // Look for all external methods visible on octave path at the
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1021 // time of loading of the class.
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1022 //
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1023 // FIXME: This is an "extension" to Matlab behavior, which only looks
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1024 // in the @-folder containing the original classdef file. However,
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1025 // this is easier to implement it that way at the moment.
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1026
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1027 std::list<std::string> external_methods
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1028 = lp.methods (full_class_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1029
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1030 for (const auto& mtdnm : external_methods)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1031 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1032 // FIXME: should we issue a warning if the method is already
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1033 // defined in the classdef file?
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1034
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1035 if (mtdnm != class_name
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1036 && ! retval.find_method (mtdnm, true).ok ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1037 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1038 // Create a dummy method that is used until the actual
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1039 // method is loaded.
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1040 octave_user_function *fcn = new octave_user_function ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1041
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1042 fcn->stash_function_name (mtdnm);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1043
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1044 cdef_method meth
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1045 = cdm.make_method (retval, mtdnm, octave_value (fcn));
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1046
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1047 retval.install_method (meth);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1048 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1049 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1050 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1051
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1052 // Property blocks
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1053
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1054 // FIXME: default property expression should be able to call static
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1055 // methods of the class being constructed. A restricted CLASSNAME
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1056 // symbol should be added to the scope before evaluating default
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1057 // value expressions.
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1058
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1059 std::list<tree_classdef_properties_block *> pb_list
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1060 = b->properties_list ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1061
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1062 for (auto& pb_p : pb_list)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1063 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1064 std::map<std::string, octave_value> amap;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1065
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1066 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1067 std::cerr << "property block" << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1068 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1069
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1070 // Property attributes
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1071
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1072 if (pb_p->attribute_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1073 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1074 for (auto& attr_p : *pb_p->attribute_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1075 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1076 std::string aname = attr_p->ident ()->name ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1077 octave_value avalue = compute_attribute_value (tw, attr_p);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1078
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1079 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1080 std::cerr << "property attribute: " << aname << " = "
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1081 << attribute_value_to_string (attr_p, avalue)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1082 << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1083 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1084
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1085 if (aname == "Access")
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1086 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1087 amap["GetAccess"] = avalue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1088 amap["SetAccess"] = avalue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1089 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1090 else
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1091 amap[aname] = avalue;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1092 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1093 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1094
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1095 // Properties
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1096
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1097 if (pb_p->element_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1098 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1099 for (auto& prop_p : *pb_p->element_list ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1100 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1101 std::string prop_name = prop_p->ident ()->name ();
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1102
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1103 cdef_property prop = cdm.make_property (retval, prop_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1104
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1105 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1106 std::cerr << "property: " << prop_p->ident ()->name ()
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1107 << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1108 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1109
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1110 tree_expression *expr = prop_p->expression ();
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1111 if (expr)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1112 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
1113 octave_value pvalue = expr->evaluate (tw);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1114
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1115 #if DEBUG_TRACE
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1116 std::cerr << "property default: "
27146
c776d553c19e * cdef-class.cc: Repair debug code.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26975
diff changeset
1117 << attribute_value_to_string (prop_p, pvalue)
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1118 << std::endl;
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1119 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1120
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1121 prop.put ("DefaultValue", pvalue);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1122 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1123
29690
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1124 // FIXME: instead of attaching attributes here, pass
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1125 // them to cdef_manager::make_property. The
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1126 // classdef manager contains a meta object with a
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1127 // list of all valid properties that can be used to
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1128 // validate the attribute list (see bug #60593).
f625b7670c0e * cdef-class.cc: Comments about possible way to fix bug #60593.
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1129
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1130 // Install property attributes. This is done before assigning
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1131 // the property accessors so we can do validation by using
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1132 // cdef_property methods.
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1133
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1134 for (auto& attrnm_val : amap)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1135 prop.put (attrnm_val.first, attrnm_val.second);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1136
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1137 // Install property access methods, if any. Remove the
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1138 // accessor methods from the temporary storage map, so we can
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1139 // detect which ones are invalid and do not correspond to a
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1140 // defined property.
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1141
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1142 auto git = get_methods.find (prop_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1143
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1144 if (git != get_methods.end ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1145 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1146 make_function_of_class (retval, git->second);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1147 prop.put ("GetMethod", git->second);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1148 get_methods.erase (git);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1149 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1150
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1151 auto sit = set_methods.find (prop_name);
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1152
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1153 if (sit != set_methods.end ())
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1154 {
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1155 make_function_of_class (retval, sit->second);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1156 prop.put ("SetMethod", sit->second);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1157 set_methods.erase (sit);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1158 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1159
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1160 retval.install_property (prop);
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1161 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1162 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1163 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1164 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1165
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1166 return retval;
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1167 }
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1168
27505
c409d16b7190 eliminate some uses of bare pointers to octave_function objects
John W. Eaton <jwe@octave.org>
parents: 27445
diff changeset
1169 octave_value
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1170 cdef_class::get_method_function (const std::string& /* nm */)
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1171 {
27505
c409d16b7190 eliminate some uses of bare pointers to octave_function objects
John W. Eaton <jwe@octave.org>
parents: 27445
diff changeset
1172 return octave_value (new octave_classdef_meta (*this));
26774
568c2ab2782d move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26773
diff changeset
1173 }
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1174 }