Mercurial > octave
annotate libinterp/octave-value/cdef-method.cc @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 Copyright (C) 2012-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
7 |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 This file is part of Octave. |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 Octave is free software: you can redistribute it and/or modify it |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 under the terms of the GNU General Public License as published by |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 (at your option) any later version. |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 Octave is distributed in the hope that it will be useful, but |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 GNU General Public License for more details. |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 You should have received a copy of the GNU General Public License |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 along with Octave; see the file COPYING. If not, see |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 */ |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #if defined (HAVE_CONFIG_H) |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 # include "config.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #endif |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <algorithm> |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <iomanip> |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "cdef-class.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include "cdef-manager.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include "cdef-utils.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "errwarn.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 #include "interpreter-private.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "interpreter.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 #include "load-path.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 #include "ov-builtin.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #include "ov-classdef.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include "ov-fcn-handle.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include "ov-usr-fcn.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 #include "parse.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #include "pt-assign.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 #include "pt-classdef.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 #include "pt-idx.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 #include "pt-misc.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 #include "pt-stmt.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 #include "pt-walk.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
53 namespace octave |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
55 OCTAVE_NORETURN static |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
56 void |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
57 err_method_access (const std::string& from, const cdef_method& meth) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
58 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
59 octave_value acc = meth.get ("Access"); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
60 std::string acc_s; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
62 if (acc.is_string ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
63 acc_s = acc.string_value (); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
64 else |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
65 acc_s = "class-restricted"; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
67 error ("%s: method '%s' has %s access and cannot be run in this context", |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
68 from.c_str (), meth.get_name ().c_str (), acc_s.c_str ()); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
69 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
71 void |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
72 cdef_method::cdef_method_rep::check_method (void) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
73 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
74 if (is_external ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
75 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
76 if (is_dummy_method (function)) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
77 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
78 load_path& lp |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
79 = __get_load_path__ ("cdef_method::cdef_method_rep::check_method"); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
81 std::string name = get_name (); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
82 std::string cls_name = dispatch_type; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
83 std::string pack_name; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
84 |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
85 size_t pos = cls_name.rfind ('.'); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
87 if (pos != std::string::npos) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
88 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
89 pack_name = cls_name.substr (0, pos); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
90 cls_name = cls_name.substr (pos + 1); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
91 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
93 std::string dir_name; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
94 std::string file_name = lp.find_method (cls_name, name, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
95 dir_name, pack_name); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
97 if (! file_name.empty ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
98 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
99 octave_value ov_fcn |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
100 = load_fcn_from_file (file_name, dir_name, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
101 dispatch_type, pack_name); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
103 if (ov_fcn.is_defined ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
104 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
105 function = ov_fcn; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
107 make_function_of_class (dispatch_type, function); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
108 } |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
109 } |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
110 } |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
111 else |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
112 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
113 // FIXME: check out-of-date status |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
114 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
116 if (is_dummy_method (function)) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
117 error ("no definition found for method '%s' of class '%s'", |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
118 get_name ().c_str (), dispatch_type.c_str ()); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
119 } |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
120 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
122 octave_value_list |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
123 cdef_method::cdef_method_rep::execute (const octave_value_list& args, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
124 int nargout, bool do_check_access, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
125 const std::string& who) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
126 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
127 octave_value_list retval; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
129 if (do_check_access && ! check_access ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
130 err_method_access (who, wrap ()); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
132 if (get ("Abstract").bool_value ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
133 error ("%s: cannot execute abstract method", |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
134 get ("Name").string_value ().c_str ()); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
136 check_method (); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
138 if (function.is_defined ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
139 retval = feval (function, args, nargout); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
141 return retval; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
142 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
144 octave_value_list |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
145 cdef_method::cdef_method_rep::execute (const cdef_object& obj, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
146 const octave_value_list& args, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
147 int nargout, bool do_check_access, |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
148 const std::string& who) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
149 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
150 octave_value_list retval; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
152 if (do_check_access && ! check_access ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
153 err_method_access (who, wrap ()); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
155 if (get ("Abstract").bool_value ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
156 error ("%s: cannot execute abstract method", |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
157 get ("Name").string_value ().c_str ()); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
159 check_method (); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
161 if (function.is_defined ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
162 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
163 octave_value_list new_args; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
165 new_args.resize (args.length () + 1); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
167 new_args(0) = to_ov (obj); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
168 for (int i = 0; i < args.length (); i++) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
169 new_args(i+1) = args(i); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
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:
26772
diff
changeset
|
171 retval = feval (function, new_args, nargout); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
172 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
174 return retval; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
175 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
177 bool |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
178 cdef_method::cdef_method_rep::is_constructor (void) const |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
179 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
180 if (function.is_function()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
181 return function.function_value ()->is_classdef_constructor (); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
183 return false; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
184 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
186 bool |
26926
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
187 cdef_method::cdef_method_rep::is_defined_in_class (const std::string &cname) const |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
188 { |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
189 return (function.is_function () |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
190 ? function.function_value ()->dispatch_class () == cname |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
191 : false); |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
192 } |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
193 |
71724787d972
don't call inherited delete methods (bug #53956)
John W. Eaton <jwe@octave.org>
parents:
26774
diff
changeset
|
194 bool |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
195 cdef_method::cdef_method_rep::check_access (void) const |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
196 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
197 cdef_class cls (to_cdef (get ("DefiningClass"))); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
199 return octave::check_access (cls, get ("Access"), get_name ()); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
200 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
202 octave_value_list |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
203 cdef_method::cdef_method_rep::meta_subsref |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 (const std::string& type, const std::list<octave_value_list>& idx, |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 int nargout) |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
206 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
207 octave_value_list retval; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
209 switch (type[0]) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
210 { |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
211 case '(': |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
212 retval = (execute (idx.front (), type.length () > 1 ? 1 : nargout, true)); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
213 break; |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
215 default: |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
216 error ("invalid meta.method indexing"); |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
217 break; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
218 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
220 if (type.length () > 1 && idx.size () > 1 && ! retval.empty ()) |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
221 retval = retval(0).next_subsref (nargout, type, idx, 1); |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
223 return retval; |
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
224 } |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 } |