annotate libinterp/octave-value/cdef-utils.cc @ 26772:d1419ac09564

split method, package, and property classes from cdef-class file * cdef-method.cc, cdef-method.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h: New files. * libinterp/octave-value/module.mk: Update. * cdef-class.cc, cdef-class.h, cdef-manager.h, cdef-object.cc, cdef-utils.cc, cdef-utils.h, ov-classdef.cc: Adapt as needed for new file arrangement.
author John W. Eaton <jwe@octave.org>
date Fri, 22 Feb 2019 15:28:42 +0000
parents 2f847e3e8d6b
children 568c2ab2782d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 Copyright (C) 2012-2019 Michael Goffioul
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 (at your option) any later version.
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 GNU General Public License for more details.
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <https://www.gnu.org/licenses/>.
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #if defined (HAVE_CONFIG_H)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 # include "config.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include "call-stack.h"
26772
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
28 #include "cdef-class.h"
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "cdef-manager.h"
26772
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
30 #include "cdef-method.h"
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
31 #include "cdef-package.h"
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
32 #include "cdef-property.h"
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "cdef-utils.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "interpreter-private.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "ov-classdef.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "ov-usr-fcn.h"
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 std::string
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 get_base_name (const std::string& nm)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 std::string::size_type pos = nm.find_last_of ('.');
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 if (pos != std::string::npos)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 return nm.substr (pos + 1);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 return nm;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 void
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 make_function_of_class (const std::string& class_name,
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 const octave_value& fcn)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 octave_function *of = fcn.function_value ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 of->stash_dispatch_class (class_name);
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 octave_user_function *uf = of->user_function_value (true);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 if (uf)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 if (get_base_name (class_name) == uf->name ())
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 uf->mark_as_class_constructor ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 uf->mark_as_classdef_constructor ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 else
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 uf->mark_as_class_method ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 void
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 make_function_of_class (const cdef_class& cls, const octave_value& fcn)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 make_function_of_class (cls.get_name (), fcn);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 cdef_class
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 lookup_class (const std::string& name, bool error_if_not_found,
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 bool load_if_not_found)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 cdef_manager& cdm = octave::__get_cdef_manager__ ("lookup_class");
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 return cdm.find_class (name, error_if_not_found, load_if_not_found);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 cdef_class
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 lookup_class (const cdef_class& cls)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 // FIXME: placeholder for the time being, the purpose
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 // is to centralized any class update activity here.
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 return cls;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 cdef_class
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 lookup_class (const octave_value& ov)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 if (ov.is_string())
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 return lookup_class (ov.string_value ());
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 else
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 cdef_class cls (to_cdef (ov));
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 return lookup_class (cls);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 return cdef_class ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 std::list<cdef_class>
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 lookup_classes (const Cell& cls_list)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 std::list<cdef_class> retval;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 for (int i = 0; i < cls_list.numel (); i++)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 cdef_class c = lookup_class (cls_list(i));
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 retval.push_back (c);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 return retval;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 octave_value
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 to_ov (const std::list<cdef_class>& class_list)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 Cell cls (class_list.size (), 1);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 int i = 0;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 for (const auto& cdef_cls : class_list)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 cls(i++) = to_ov (cdef_cls);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 return octave_value (cls);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 bool
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 is_dummy_method (const octave_value& fcn)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 bool retval = false;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 if (fcn.is_defined ())
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 if (fcn.is_user_function ())
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 octave_user_function *uf = fcn.user_function_value (true);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 if (! uf || ! uf->body ())
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 retval = true;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 else
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 retval = true;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 return retval;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 bool
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 is_superclass (const cdef_class& clsa, const cdef_class& clsb,
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 bool allow_equal, int max_depth)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 bool retval = false;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 if (allow_equal && clsa == clsb)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 retval = true;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 else if (max_depth != 0)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 Cell c = clsb.get ("SuperClasses").cell_value ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 for (int i = 0; ! retval && i < c.numel (); i++)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 cdef_class cls = lookup_class (c(i));
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 retval = is_superclass (clsa, cls, true,
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 max_depth < 0 ? max_depth : max_depth-1);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 return retval;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 bool
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 is_strict_superclass (const cdef_class& clsa, const cdef_class& clsb)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 return is_superclass (clsa, clsb, false);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 bool
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 is_direct_superclass (const cdef_class& clsa, const cdef_class& clsb)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 return is_superclass (clsa, clsb, false, 1);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 cdef_package
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 lookup_package (const std::string& name, bool error_if_not_found,
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 bool load_if_not_found)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 cdef_manager& cdm = octave::__get_cdef_manager__ ("lookup_package");
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 return cdm.find_package (name, error_if_not_found, load_if_not_found);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 cdef_class
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 get_class_context (std::string& name, bool& in_constructor)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 cdef_class cls;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 octave::call_stack& cs = octave::__get_call_stack__ ("get_class_context");
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 octave_function *fcn = cs.current ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 in_constructor = false;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 if (fcn && (fcn->is_class_method ()
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 || fcn->is_classdef_constructor ()
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 || fcn->is_anonymous_function_of_class ()
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 || (fcn->is_private_function ()
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 && ! fcn->dispatch_class ().empty ())))
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 cls = lookup_class (fcn->dispatch_class ());
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 name = fcn->name ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 in_constructor = fcn->is_classdef_constructor ();
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 return cls;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 }
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 cdef_class
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230 get_class_context (void)
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 {
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 std::string dummy_string;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 bool dummy_bool;
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 return get_class_context (dummy_string, dummy_bool);
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 }
26772
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
237
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
238 bool
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
239 check_access (const cdef_class& cls, const octave_value& acc,
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
240 const std::string& meth_name, const std::string& prop_name,
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
241 bool is_prop_set)
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
242 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
243 if (acc.is_string ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
244 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
245 std::string acc_s = acc.string_value ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
246
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
247 if (acc_s == "public")
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
248 return true;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
249
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
250 cdef_class ctx = get_class_context ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
251
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
252 // The access is private or protected, this requires a
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
253 // valid class context.
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
254
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
255 if (ctx.ok ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
256 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
257 if (acc_s == "private")
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
258 return (ctx == cls);
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
259 else if (acc_s == "protected")
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
260 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
261 if (is_superclass (cls, ctx))
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
262 // Calling a protected method in a superclass.
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
263 return true;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
264 else if (is_strict_superclass (ctx, cls))
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
265 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
266 // Calling a protected method or property in a derived class.
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
267 // This is only allowed if the context class knows about it
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
268 // and has access to it.
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
269
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
270 if (! meth_name.empty ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
271 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
272 cdef_method m = ctx.find_method (meth_name);
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
273
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
274 if (m.ok ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
275 return check_access (ctx, m.get ("Access"), meth_name);
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
276
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
277 return false;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
278 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
279 else if (! prop_name.empty ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
280 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
281 cdef_property p = ctx.find_property (prop_name);
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
282
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
283 if (p.ok ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
284 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
285 octave_value p_access = p.get (is_prop_set ?
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
286 "SetAccess" :
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
287 "GetAccess");
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
288
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
289 return check_access (ctx, p_access, meth_name,
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
290 prop_name, is_prop_set);
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
291 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
292
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
293 return false;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
294 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
295 else
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
296 panic_impossible ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
297 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
298
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
299 return false;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
300 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
301 else
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
302 panic_impossible ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
303 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
304 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
305 else if (acc.isobject ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
306 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
307 cdef_class ctx = get_class_context ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
308
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
309 // At this point, a class context is always required.
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
310 if (ctx.ok ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
311 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
312 if (ctx == cls)
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
313 return true;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
314
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
315 cdef_class acc_cls (to_cdef (acc));
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
316
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
317 if (is_superclass (acc_cls, ctx))
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
318 return true;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
319 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
320 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
321 else if (acc.iscell ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
322 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
323 Cell acc_c = acc.cell_value ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
324
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
325 cdef_class ctx = get_class_context ();
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
326
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
327 // At this point, a class context is always required.
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
328
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
329 if (ctx.ok ())
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
330 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
331 if (ctx == cls)
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
332 return true;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
333
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
334 for (int i = 0; i < acc.numel (); i++)
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
335 {
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
336 cdef_class acc_cls (to_cdef (acc_c(i)));
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
337
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
338 if (is_superclass (acc_cls, ctx))
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
339 return true;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
340 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
341 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
342 }
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
343 else
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
344 error ("invalid property/method access in class `%s'",
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
345 cls.get_name ().c_str ());
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
346
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
347 return false;
d1419ac09564 split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
348 }