Mercurial > octave-nkf
annotate libinterp/octave-value/ov-fcn-handle.cc @ 19731:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | 76478d2da117 |
children | 09ed6f7538dd |
rev | line source |
---|---|
4343 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19632
diff
changeset
|
3 Copyright (C) 2003-2015 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
10960 | 5 Copyright (C) 2010 Jaroslav Hajek |
4343 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
4343 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
4343 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include <iostream> | |
5765 | 30 #include <sstream> |
5164 | 31 #include <vector> |
4343 | 32 |
7336 | 33 #include "file-ops.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
34 #include "oct-locbuf.h" |
7336 | 35 |
4343 | 36 #include "defun.h" |
4654 | 37 #include "error.h" |
38 #include "gripes.h" | |
5663 | 39 #include "input.h" |
4343 | 40 #include "oct-map.h" |
41 #include "ov-base.h" | |
42 #include "ov-fcn-handle.h" | |
4980 | 43 #include "ov-usr-fcn.h" |
4343 | 44 #include "pr-output.h" |
4980 | 45 #include "pt-pr-code.h" |
46 #include "pt-misc.h" | |
47 #include "pt-stmt.h" | |
48 #include "pt-cmd.h" | |
49 #include "pt-exp.h" | |
50 #include "pt-assign.h" | |
10960 | 51 #include "pt-arg-list.h" |
4343 | 52 #include "variables.h" |
4988 | 53 #include "parse.h" |
6625 | 54 #include "unwind-prot.h" |
55 #include "defaults.h" | |
56 #include "file-stat.h" | |
57 #include "load-path.h" | |
58 #include "oct-env.h" | |
4988 | 59 |
60 #include "byte-swap.h" | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
61 #include "ls-ascii-helper.h" |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
62 #include "ls-hdf5.h" |
4988 | 63 #include "ls-oct-ascii.h" |
6625 | 64 #include "ls-oct-binary.h" |
4988 | 65 #include "ls-utils.h" |
4343 | 66 |
67 | |
4612 | 68 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
69 "function handle", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
70 "function_handle"); |
4343 | 71 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
72 const std::string octave_fcn_handle::anonymous ("@<anonymous>"); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
73 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
74 octave_fcn_handle::octave_fcn_handle (const octave_value& f, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
75 const std::string& n) |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
76 : fcn (f), nm (n), has_overloads (false) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
77 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
78 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
79 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
80 if (uf && nm != anonymous) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
81 symbol_table::cache_name (uf->scope (), nm); |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14429
diff
changeset
|
82 |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14429
diff
changeset
|
83 if (uf && uf->is_nested_function ()) |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14429
diff
changeset
|
84 ::error ("handles to nested functions are not yet supported"); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
85 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
86 |
4924 | 87 octave_value_list |
88 octave_fcn_handle::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
89 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
90 int nargout) |
4924 | 91 { |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
92 return octave_fcn_handle::subsref (type, idx, nargout, 0); |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
93 } |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
94 |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
95 octave_value_list |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
96 octave_fcn_handle::subsref (const std::string& type, |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
97 const std::list<octave_value_list>& idx, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 const std::list<octave_lvalue>* lvalue_list) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
100 { |
4924 | 101 octave_value_list retval; |
102 | |
103 switch (type[0]) | |
104 { | |
105 case '(': | |
106 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
107 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5663 | 108 |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
109 retval = do_multi_index_op (tmp_nargout, idx.front (), |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
110 idx.size () == 1 ? lvalue_list : 0); |
4924 | 111 } |
112 break; | |
113 | |
114 case '{': | |
115 case '.': | |
116 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
117 std::string tnm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
118 error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); |
4924 | 119 } |
120 break; | |
121 | |
122 default: | |
123 panic_impossible (); | |
124 } | |
125 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
126 // FIXME: perhaps there should be an |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
127 // octave_value_list::next_subsref member function? See also |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
128 // octave_builtin::subsref. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
129 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
130 if (idx.size () > 1) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
131 retval = retval(0).next_subsref (nargout, type, idx); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
132 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
133 return retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
134 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
135 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
136 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
137 octave_fcn_handle::do_multi_index_op (int nargout, |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
138 const octave_value_list& args) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
139 { |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
140 return do_multi_index_op (nargout, args, 0); |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
141 } |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
142 |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
143 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
144 octave_fcn_handle::do_multi_index_op (int nargout, |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
145 const octave_value_list& args, |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
146 const std::list<octave_lvalue>* lvalue_list) |
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
147 { |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
148 octave_value_list retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
149 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
150 out_of_date_check (fcn, std::string (), false); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
151 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
152 if (has_overloads) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
153 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
154 // Possibly overloaded function. |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
155 octave_value ov_fcn; |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
156 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
157 // Compute dispatch type. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
158 builtin_type_t btyp; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
159 std::string dispatch_type = get_dispatch_type (args, btyp); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
160 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
161 // Retrieve overload. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
162 if (btyp != btyp_unknown) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
163 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
164 out_of_date_check (builtin_overloads[btyp], dispatch_type, false); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
165 ov_fcn = builtin_overloads[btyp]; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
166 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
167 else |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
168 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
169 str_ov_map::iterator it = overloads.find (dispatch_type); |
13193
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
170 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
171 if (it == overloads.end ()) |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
172 { |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
173 // Try parent classes too. |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
174 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
175 std::list<std::string> plist |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
176 = symbol_table::parent_classes (dispatch_type); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
177 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
178 std::list<std::string>::const_iterator pit = plist.begin (); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
179 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
180 while (pit != plist.end ()) |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
181 { |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
182 std::string pname = *pit; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
183 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
184 std::string fnm = fcn_name (); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
185 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
186 octave_value ftmp = symbol_table::find_method (fnm, pname); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
187 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
188 if (ftmp.is_defined ()) |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
189 { |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
190 set_overload (pname, ftmp); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
191 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
192 out_of_date_check (ftmp, pname, false); |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
193 ov_fcn = ftmp; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
194 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
195 break; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
196 } |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
197 |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
198 pit++; |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
199 } |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
200 } |
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
201 else |
9466
2ebd0717c12d
also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9463
diff
changeset
|
202 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
203 out_of_date_check (it->second, dispatch_type, false); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
204 ov_fcn = it->second; |
9466
2ebd0717c12d
also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9463
diff
changeset
|
205 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
206 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
207 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
208 if (ov_fcn.is_defined ()) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
209 retval = ov_fcn.do_multi_index_op (nargout, args, lvalue_list); |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
210 else if (fcn.is_defined ()) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
211 retval = fcn.do_multi_index_op (nargout, args, lvalue_list); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
212 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
213 error ("%s: no method for class %s", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
214 nm.c_str (), dispatch_type.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
215 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
216 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
217 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
218 // Non-overloaded function (anonymous, subfunction, private function). |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
219 if (fcn.is_defined ()) |
10849
f1a45913662a
propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
220 retval = fcn.do_multi_index_op (nargout, args, lvalue_list); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
221 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
222 error ("%s: no longer valid function handle", nm.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
223 } |
4924 | 224 |
225 return retval; | |
226 } | |
227 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
228 bool |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
229 octave_fcn_handle::is_equal_to (const octave_fcn_handle& h) const |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
230 { |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
231 bool retval = fcn.is_copy_of (h.fcn) && (has_overloads == h.has_overloads); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
232 retval = retval && (overloads.size () == h.overloads.size ()); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
233 |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
234 if (retval && has_overloads) |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
235 { |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
236 for (int i = 0; i < btyp_num_types && retval; i++) |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
237 retval = builtin_overloads[i].is_copy_of (h.builtin_overloads[i]); |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
238 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
239 str_ov_map::const_iterator iter = overloads.begin (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
240 str_ov_map::const_iterator hiter = h.overloads.begin (); |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
241 for (; iter != overloads.end () && retval; iter++, hiter++) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
242 retval = (iter->first == hiter->first) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
243 && (iter->second.is_copy_of (hiter->second)); |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
244 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
245 |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
246 return retval; |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
247 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
248 |
4988 | 249 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
250 octave_fcn_handle::set_fcn (const std::string &octaveroot, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
251 const std::string& fpath) |
4988 | 252 { |
6625 | 253 bool success = true; |
254 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
255 if (octaveroot.length () != 0 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
256 && fpath.length () >= octaveroot.length () |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
257 && fpath.substr (0, octaveroot.length ()) == octaveroot |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
258 && OCTAVE_EXEC_PREFIX != octaveroot) |
6625 | 259 { |
260 // First check if just replacing matlabroot is enough | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
261 std::string str = OCTAVE_EXEC_PREFIX + |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
262 fpath.substr (octaveroot.length ()); |
6625 | 263 file_stat fs (str); |
264 | |
265 if (fs.exists ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
266 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
267 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 268 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
269 std::string dir_name = str.substr (0, xpos); |
6625 | 270 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
271 octave_function *xfcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
272 = load_fcn_from_file (str, dir_name, "", "", nm); |
6625 | 273 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
274 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
275 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
276 octave_value tmp (xfcn); |
6625 | 277 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
278 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
279 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
280 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
281 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
282 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
283 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
284 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
285 } |
6625 | 286 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
287 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
288 // Next just search for it anywhere in the system path |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
289 string_vector names(3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
290 names(0) = nm + ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
291 names(1) = nm + ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
292 names(2) = nm + ".m"; |
6625 | 293 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
294 dir_path p (load_path::system_path ()); |
6625 | 295 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
296 str = octave_env::make_absolute (p.find_first_of (names)); |
6625 | 297 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
298 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 299 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
300 std::string dir_name = str.substr (0, xpos); |
7336 | 301 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
302 octave_function *xfcn = load_fcn_from_file (str, dir_name, "", "", nm); |
4989 | 303 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
304 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
305 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
306 octave_value tmp (xfcn); |
6625 | 307 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
308 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
309 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
310 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
311 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
312 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
313 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
314 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
315 } |
6625 | 316 } |
317 else | |
318 { | |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
319 if (fpath.length () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
321 size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 322 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
323 std::string dir_name = fpath.substr (0, xpos); |
7336 | 324 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
325 octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", "", nm); |
6625 | 326 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
327 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
328 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
329 octave_value tmp (xfcn); |
6625 | 330 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
331 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
332 } |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
333 else |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
334 { |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
335 error ("function handle points to non-existent function"); |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
336 success = false; |
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
337 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
338 } |
6625 | 339 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
340 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
341 fcn = symbol_table::find_function (nm); |
7336 | 342 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
343 if (! fcn.is_function ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
344 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
345 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
346 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
347 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
348 } |
6625 | 349 } |
350 | |
351 return success; | |
352 } | |
353 | |
354 bool | |
6974 | 355 octave_fcn_handle::save_ascii (std::ostream& os) |
6625 | 356 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
357 if (nm == anonymous) |
4988 | 358 { |
6625 | 359 os << nm << "\n"; |
360 | |
4989 | 361 print_raw (os, true); |
362 os << "\n"; | |
6625 | 363 |
7336 | 364 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
365 return false; |
6625 | 366 |
367 octave_user_function *f = fcn.user_function_value (); | |
368 | |
7336 | 369 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
370 = symbol_table::all_variables (f->scope (), 0); |
6625 | 371 |
7336 | 372 size_t varlen = vars.size (); |
6625 | 373 |
374 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
375 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
376 os << "# length: " << varlen << "\n"; |
6625 | 377 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
378 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
379 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
380 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
381 if (! save_ascii_data (os, p->varval (0), p->name (), false, 0)) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17898
diff
changeset
|
382 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
383 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
384 } |
6625 | 385 } |
386 else | |
387 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
388 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
389 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
390 |
6625 | 391 os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
392 if (! fnm.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
393 os << "# path: " << fnm << "\n"; |
6625 | 394 os << nm << "\n"; |
4988 | 395 } |
396 | |
397 return true; | |
398 } | |
399 | |
400 bool | |
401 octave_fcn_handle::load_ascii (std::istream& is) | |
402 { | |
6625 | 403 bool success = true; |
404 | |
405 std::streampos pos = is.tellg (); | |
406 std::string octaveroot = extract_keyword (is, "octaveroot", true); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
407 if (octaveroot.length () == 0) |
6625 | 408 { |
409 is.seekg (pos); | |
410 is.clear (); | |
411 } | |
412 pos = is.tellg (); | |
413 std::string fpath = extract_keyword (is, "path", true); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
414 if (fpath.length () == 0) |
6625 | 415 { |
416 is.seekg (pos); | |
417 is.clear (); | |
418 } | |
419 | |
4988 | 420 is >> nm; |
4989 | 421 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
422 if (nm == anonymous) |
4988 | 423 { |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
424 skip_preceeding_newline (is); |
4988 | 425 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
426 std::string buf; |
4988 | 427 |
428 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
429 { |
4988 | 430 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
431 // Get a line of text whitespace characters included, leaving |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
432 // newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
433 buf = read_until_newline (is, true); |
4989 | 434 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
435 } |
4988 | 436 |
6625 | 437 pos = is.tellg (); |
7336 | 438 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
439 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
440 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
441 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
442 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
443 |
7336 | 444 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
445 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
446 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
447 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
448 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
449 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
450 frame.add_fcn (octave_call_stack::pop); |
4988 | 451 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
452 octave_idx_type len = 0; |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
453 |
6625 | 454 if (extract_keyword (is, "length", len, true) && len >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
455 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
456 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
457 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
458 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
459 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
460 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
461 bool dummy; |
6625 | 462 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
463 std::string name |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
464 = read_ascii_data (is, std::string (), dummy, t2, i); |
6625 | 465 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
466 if (!is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
468 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
469 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
470 } |
6625 | 471 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
472 symbol_table::assign (name, t2, local_scope, 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
473 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
474 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
475 } |
4989 | 476 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
477 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
478 is.seekg (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
479 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
480 } |
6625 | 481 |
482 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
483 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
484 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
485 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
486 eval_string (buf, true, parse_status); |
6625 | 487 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
488 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
489 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
490 octave_fcn_handle *fh = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
491 anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
492 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
493 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
494 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
495 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
496 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
497 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
498 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
499 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
500 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
501 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
502 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
503 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
504 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
505 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
506 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
507 } |
6625 | 508 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
509 success = false; |
4988 | 510 } |
511 else | |
6625 | 512 success = set_fcn (octaveroot, fpath); |
4988 | 513 |
6625 | 514 return success; |
4988 | 515 } |
516 | |
517 bool | |
6625 | 518 octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats) |
4988 | 519 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
520 if (nm == anonymous) |
4988 | 521 { |
6625 | 522 std::ostringstream nmbuf; |
523 | |
7336 | 524 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
525 return false; |
6625 | 526 |
527 octave_user_function *f = fcn.user_function_value (); | |
528 | |
7336 | 529 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
530 = symbol_table::all_variables (f->scope (), 0); |
6625 | 531 |
7336 | 532 size_t varlen = vars.size (); |
6625 | 533 |
534 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
535 nmbuf << nm << " " << varlen; |
6625 | 536 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
537 nmbuf << nm; |
6625 | 538 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
539 std::string buf_str = nmbuf.str (); |
6625 | 540 int32_t tmp = buf_str.length (); |
541 os.write (reinterpret_cast<char *> (&tmp), 4); | |
542 os.write (buf_str.c_str (), buf_str.length ()); | |
543 | |
5765 | 544 std::ostringstream buf; |
4988 | 545 print_raw (buf, true); |
5765 | 546 std::string stmp = buf.str (); |
4988 | 547 tmp = stmp.length (); |
5760 | 548 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988 | 549 os.write (stmp.c_str (), stmp.length ()); |
6625 | 550 |
551 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
552 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
553 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
554 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
555 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
556 if (! save_binary_data (os, p->varval (0), p->name (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
557 "", 0, save_as_floats)) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17898
diff
changeset
|
558 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
559 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
560 } |
6625 | 561 } |
562 else | |
563 { | |
564 std::ostringstream nmbuf; | |
565 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
566 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
567 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
568 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
569 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm; |
6625 | 570 |
571 std::string buf_str = nmbuf.str (); | |
572 int32_t tmp = buf_str.length (); | |
573 os.write (reinterpret_cast<char *> (&tmp), 4); | |
574 os.write (buf_str.c_str (), buf_str.length ()); | |
4988 | 575 } |
7336 | 576 |
4988 | 577 return true; |
578 } | |
579 | |
580 bool | |
581 octave_fcn_handle::load_binary (std::istream& is, bool swap, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
582 oct_mach_info::float_format fmt) |
4988 | 583 { |
6625 | 584 bool success = true; |
7336 | 585 |
5828 | 586 int32_t tmp; |
5760 | 587 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 588 return false; |
589 if (swap) | |
590 swap_bytes<4> (&tmp); | |
591 | |
592 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
593 // is.get (ctmp1, tmp+1, 0); caused is.eof () to be true though |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
594 // effectively not reading over file end |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
595 is.read (ctmp1, tmp); |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
596 ctmp1[tmp] = 0; |
4988 | 597 nm = std::string (ctmp1); |
598 | |
599 if (! is) | |
600 return false; | |
601 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
602 size_t anl = anonymous.length (); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
603 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
604 if (nm.length () >= anl && nm.substr (0, anl) == anonymous) |
4988 | 605 { |
6625 | 606 octave_idx_type len = 0; |
607 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14544
diff
changeset
|
608 if (nm.length () > anl) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
609 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
610 std::istringstream nm_is (nm.substr (anl)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
611 nm_is >> len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
612 nm = nm.substr (0, anl); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
613 } |
6625 | 614 |
5760 | 615 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
616 return false; |
4988 | 617 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
618 swap_bytes<4> (&tmp); |
4988 | 619 |
620 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
621 // is.get (ctmp2, tmp+1, 0); caused is.eof () to be true though |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
622 // effectively not reading over file end |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
623 is.read (ctmp2, tmp); |
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
624 ctmp2[tmp] = 0; |
4988 | 625 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
626 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
627 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
628 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
629 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
630 |
7336 | 631 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
632 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
633 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
634 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
635 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
636 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
637 frame.add_fcn (octave_call_stack::pop); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
638 |
6625 | 639 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
640 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
641 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
642 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
643 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
644 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
645 std::string doc; |
6625 | 646 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
647 std::string name = |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
648 read_binary_data (is, swap, fmt, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
649 dummy, t2, doc); |
6625 | 650 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
651 if (!is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
652 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
653 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
654 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
655 } |
6625 | 656 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
657 symbol_table::assign (name, t2, local_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
658 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
659 } |
6625 | 660 |
661 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
662 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
663 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
664 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
665 eval_string (ctmp2, true, parse_status); |
6625 | 666 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
667 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
668 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
669 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
670 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
671 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
672 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
673 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
674 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
675 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
676 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
677 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
678 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
679 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
680 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
681 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
682 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
683 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
684 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
685 } |
4988 | 686 } |
687 else | |
688 { | |
6625 | 689 std::string octaveroot; |
690 std::string fpath; | |
691 | |
8021 | 692 if (nm.find_first_of ("\n") != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
693 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
694 size_t pos1 = nm.find_first_of ("\n"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
695 size_t pos2 = nm.find_first_of ("\n", pos1 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
696 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
697 fpath = nm.substr (pos2 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
698 nm = nm.substr (0, pos1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
699 } |
6625 | 700 |
701 success = set_fcn (octaveroot, fpath); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
702 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
703 |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
704 return success; |
4988 | 705 } |
706 | |
707 #if defined (HAVE_HDF5) | |
708 bool | |
709 octave_fcn_handle::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
710 bool save_as_floats) |
4988 | 711 { |
7336 | 712 bool retval = true; |
713 | |
4988 | 714 hid_t group_hid = -1; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
715 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
716 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
717 #else |
4988 | 718 group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
719 #endif |
7336 | 720 if (group_hid < 0) |
721 return false; | |
4988 | 722 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
723 hid_t space_hid, data_hid, type_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
724 space_hid = data_hid = type_hid = -1; |
4988 | 725 |
726 // attach the type of the variable | |
727 type_hid = H5Tcopy (H5T_C_S1); | |
728 H5Tset_size (type_hid, nm.length () + 1); | |
729 if (type_hid < 0) | |
730 { | |
731 H5Gclose (group_hid); | |
732 return false; | |
733 } | |
734 | |
735 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
736 hdims[0] = 0; | |
737 hdims[1] = 0; | |
5760 | 738 space_hid = H5Screate_simple (0 , hdims, 0); |
4988 | 739 if (space_hid < 0) |
740 { | |
741 H5Tclose (type_hid); | |
742 H5Gclose (group_hid); | |
743 return false; | |
744 } | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
745 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
746 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
747 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
748 #else |
4988 | 749 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
750 #endif |
4988 | 751 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
752 H5P_DEFAULT, nm.c_str ()) < 0) |
4988 | 753 { |
754 H5Sclose (space_hid); | |
755 H5Tclose (type_hid); | |
756 H5Gclose (group_hid); | |
757 return false; | |
758 } | |
759 H5Dclose (data_hid); | |
760 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
761 if (nm == anonymous) |
4988 | 762 { |
5765 | 763 std::ostringstream buf; |
4988 | 764 print_raw (buf, true); |
5765 | 765 std::string stmp = buf.str (); |
4988 | 766 |
767 // attach the type of the variable | |
768 H5Tset_size (type_hid, stmp.length () + 1); | |
769 if (type_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
770 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
771 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
772 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
773 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
774 } |
4988 | 775 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
776 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
777 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
778 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
779 #else |
4988 | 780 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
781 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
782 #endif |
4988 | 783 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
784 H5P_DEFAULT, stmp.c_str ()) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
785 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
786 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
787 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
788 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
789 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
790 } |
4988 | 791 |
792 H5Dclose (data_hid); | |
6625 | 793 |
794 octave_user_function *f = fcn.user_function_value (); | |
795 | |
7336 | 796 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
797 = symbol_table::all_variables (f->scope (), 0); |
7336 | 798 |
799 size_t varlen = vars.size (); | |
6625 | 800 |
801 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
802 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
803 hid_t as_id = H5Screate (H5S_SCALAR); |
6625 | 804 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
805 if (as_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
806 { |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
807 #if HAVE_HDF5_18 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
808 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
809 H5T_NATIVE_IDX, as_id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
810 H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
811 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
812 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
813 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
814 H5T_NATIVE_IDX, as_id, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
815 #endif |
6625 | 816 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
817 if (a_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
819 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); |
6625 | 820 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
821 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
822 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
823 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
824 retval = false; |
6625 | 825 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
826 H5Sclose (as_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
827 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
828 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
829 retval = false; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
830 #if HAVE_HDF5_18 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
831 data_hid = H5Gcreate (group_hid, "symbol table", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
832 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
833 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
834 data_hid = H5Gcreate (group_hid, "symbol table", 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
835 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
836 if (data_hid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
837 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
838 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
839 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
840 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
841 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
842 } |
6625 | 843 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
844 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
845 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
846 { |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
847 if (! add_hdf5_data (data_hid, p->varval (0), p->name (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
848 "", false, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
849 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
850 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
851 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
852 } |
6625 | 853 } |
854 else | |
855 { | |
856 std::string octaveroot = OCTAVE_EXEC_PREFIX; | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
857 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
858 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
859 std::string fpath = f ? f->fcn_file_name () : std::string (); |
6625 | 860 |
861 H5Sclose (space_hid); | |
862 hdims[0] = 1; | |
863 hdims[1] = octaveroot.length (); | |
864 space_hid = H5Screate_simple (0 , hdims, 0); | |
865 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
866 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
867 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
868 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
869 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
870 } |
6625 | 871 |
872 H5Tclose (type_hid); | |
873 type_hid = H5Tcopy (H5T_C_S1); | |
874 H5Tset_size (type_hid, octaveroot.length () + 1); | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
875 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
876 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
877 type_hid, space_hid, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
878 #else |
6625 | 879 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
880 type_hid, space_hid, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
881 #endif |
6625 | 882 |
883 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
885 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); |
6625 | 886 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
887 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
888 } |
6625 | 889 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
890 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
891 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
892 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
893 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
894 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
895 } |
6625 | 896 |
897 H5Sclose (space_hid); | |
898 hdims[0] = 1; | |
899 hdims[1] = fpath.length (); | |
900 space_hid = H5Screate_simple (0 , hdims, 0); | |
901 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
902 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
903 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
904 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
905 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
906 } |
6625 | 907 |
908 H5Tclose (type_hid); | |
909 type_hid = H5Tcopy (H5T_C_S1); | |
910 H5Tset_size (type_hid, fpath.length () + 1); | |
911 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
912 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
913 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
914 H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
915 #else |
6625 | 916 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
917 #endif |
6625 | 918 |
919 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
920 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
921 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); |
6625 | 922 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
923 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
924 } |
6625 | 925 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
926 retval = false; |
4988 | 927 } |
928 | |
929 H5Sclose (space_hid); | |
930 H5Tclose (type_hid); | |
931 H5Gclose (group_hid); | |
932 | |
933 return retval; | |
934 } | |
935 | |
936 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9601
diff
changeset
|
937 octave_fcn_handle::load_hdf5 (hid_t loc_id, const char *name) |
4988 | 938 { |
7336 | 939 bool success = true; |
940 | |
4988 | 941 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
942 hsize_t rank; | |
943 int slen; | |
944 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
945 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
946 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
947 #else |
4988 | 948 group_hid = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
949 #endif |
7336 | 950 if (group_hid < 0) |
951 return false; | |
4988 | 952 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
953 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
954 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
955 #else |
4988 | 956 data_hid = H5Dopen (group_hid, "nm"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
957 #endif |
4988 | 958 |
959 if (data_hid < 0) | |
960 { | |
961 H5Gclose (group_hid); | |
962 return false; | |
963 } | |
964 | |
965 type_hid = H5Dget_type (data_hid); | |
966 type_class_hid = H5Tget_class (type_hid); | |
967 | |
968 if (type_class_hid != H5T_STRING) | |
969 { | |
970 H5Tclose (type_hid); | |
971 H5Dclose (data_hid); | |
972 H5Gclose (group_hid); | |
973 return false; | |
974 } | |
975 | |
976 space_hid = H5Dget_space (data_hid); | |
977 rank = H5Sget_simple_extent_ndims (space_hid); | |
978 | |
979 if (rank != 0) | |
980 { | |
981 H5Sclose (space_hid); | |
982 H5Tclose (type_hid); | |
983 H5Dclose (data_hid); | |
984 H5Gclose (group_hid); | |
985 return false; | |
986 } | |
987 | |
988 slen = H5Tget_size (type_hid); | |
989 if (slen < 0) | |
990 { | |
991 H5Sclose (space_hid); | |
992 H5Tclose (type_hid); | |
993 H5Dclose (data_hid); | |
994 H5Gclose (group_hid); | |
995 return false; | |
996 } | |
997 | |
998 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
999 | |
1000 // create datatype for (null-terminated) string to read into: | |
1001 st_id = H5Tcopy (H5T_C_S1); | |
1002 H5Tset_size (st_id, slen); | |
1003 | |
5760 | 1004 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4988 | 1005 { |
6695 | 1006 H5Tclose (st_id); |
4988 | 1007 H5Sclose (space_hid); |
1008 H5Tclose (type_hid); | |
6695 | 1009 H5Dclose (data_hid); |
4988 | 1010 H5Gclose (group_hid); |
1011 return false; | |
1012 } | |
1013 H5Tclose (st_id); | |
1014 H5Dclose (data_hid); | |
1015 nm = nm_tmp; | |
1016 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1017 if (nm == anonymous) |
4988 | 1018 { |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1019 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1020 data_hid = H5Dopen (group_hid, "fcn", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1021 #else |
4988 | 1022 data_hid = H5Dopen (group_hid, "fcn"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1023 #endif |
4988 | 1024 |
1025 if (data_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1026 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1027 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1028 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1029 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1030 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1031 } |
4988 | 1032 |
6695 | 1033 H5Tclose (type_hid); |
4988 | 1034 type_hid = H5Dget_type (data_hid); |
1035 type_class_hid = H5Tget_class (type_hid); | |
1036 | |
1037 if (type_class_hid != H5T_STRING) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1038 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1039 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1040 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1041 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1042 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1043 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1044 } |
4988 | 1045 |
6695 | 1046 H5Sclose (space_hid); |
4988 | 1047 space_hid = H5Dget_space (data_hid); |
1048 rank = H5Sget_simple_extent_ndims (space_hid); | |
1049 | |
1050 if (rank != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1051 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1052 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1053 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1054 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1055 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1056 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1057 } |
4988 | 1058 |
1059 slen = H5Tget_size (type_hid); | |
1060 if (slen < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1061 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1062 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1063 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1064 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1065 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1066 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1067 } |
4988 | 1068 |
1069 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); | |
1070 | |
1071 // create datatype for (null-terminated) string to read into: | |
1072 st_id = H5Tcopy (H5T_C_S1); | |
1073 H5Tset_size (st_id, slen); | |
1074 | |
5760 | 1075 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1076 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1077 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1078 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1079 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1080 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1081 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1082 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1083 } |
6695 | 1084 H5Tclose (st_id); |
4988 | 1085 H5Dclose (data_hid); |
6625 | 1086 |
1087 octave_idx_type len = 0; | |
1088 | |
1089 // we have to pull some shenanigans here to make sure | |
1090 // HDF5 doesn't print out all sorts of error messages if we | |
1091 // call H5Aopen for a non-existing attribute | |
1092 | |
1093 H5E_auto_t err_func; | |
1094 void *err_func_data; | |
4988 | 1095 |
6625 | 1096 // turn off error reporting temporarily, but save the error |
1097 // reporting function: | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1098 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1099 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1100 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1101 #else |
6625 | 1102 H5Eget_auto (&err_func, &err_func_data); |
1103 H5Eset_auto (0, 0); | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1104 #endif |
6625 | 1105 |
1106 hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); | |
4988 | 1107 |
6625 | 1108 if (attr_id >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1109 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1110 if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1111 success = false; |
6625 | 1112 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1113 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1114 } |
6625 | 1115 |
1116 // restore error reporting: | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1117 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1118 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1119 #else |
6625 | 1120 H5Eset_auto (err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1121 #endif |
6625 | 1122 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1123 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1124 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1125 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1126 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1127 |
7336 | 1128 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1129 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1130 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1131 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1132 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1133 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1134 frame.add_fcn (octave_call_stack::pop); |
7336 | 1135 |
6625 | 1136 if (len > 0 && success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1137 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1138 hsize_t num_obj = 0; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1139 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1140 data_hid = H5Gopen (group_hid, "symbol table", H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1141 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1142 data_hid = H5Gopen (group_hid, "symbol table"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1143 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1144 H5Gget_num_objs (data_hid, &num_obj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1145 H5Gclose (data_hid); |
6625 | 1146 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1147 if (num_obj != static_cast<hsize_t>(len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1149 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1150 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1151 } |
6625 | 1152 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1153 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1154 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1155 hdf5_callback_data dsub; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1156 int current_item = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1157 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1158 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1159 if (H5Giterate (group_hid, "symbol table", ¤t_item, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1160 hdf5_read_next_data, &dsub) <= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1161 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1162 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1163 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1164 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1165 } |
6625 | 1166 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16170
diff
changeset
|
1167 symbol_table::assign (dsub.name, dsub.tc, local_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1168 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1169 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1170 } |
6625 | 1171 |
1172 if (success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1173 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1174 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1175 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1176 eval_string (fcn_tmp, true, parse_status); |
6625 | 1177 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1178 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1179 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1180 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1181 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1182 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1183 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1184 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1185 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1186 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1187 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1188 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1189 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1190 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1191 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1192 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1193 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1194 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1195 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1196 } |
6625 | 1197 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1198 frame.run (); |
4988 | 1199 } |
1200 else | |
1201 { | |
6625 | 1202 std::string octaveroot; |
1203 std::string fpath; | |
1204 | |
1205 // we have to pull some shenanigans here to make sure | |
1206 // HDF5 doesn't print out all sorts of error messages if we | |
1207 // call H5Aopen for a non-existing attribute | |
1208 | |
1209 H5E_auto_t err_func; | |
1210 void *err_func_data; | |
1211 | |
1212 // turn off error reporting temporarily, but save the error | |
1213 // reporting function: | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1214 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1215 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1216 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1217 #else |
6625 | 1218 H5Eget_auto (&err_func, &err_func_data); |
1219 H5Eset_auto (0, 0); | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1220 #endif |
6625 | 1221 |
1222 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); | |
1223 if (attr_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1224 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1225 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1226 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1227 type_class_hid = H5Tget_class (type_hid); |
6625 | 1228 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1229 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1230 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1231 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1232 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1233 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1234 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1235 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1236 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); |
6625 | 1237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1238 if (H5Aread (attr_id, st_id, root_tmp) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1239 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1240 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1241 octaveroot = root_tmp; |
6695 | 1242 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1243 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1244 } |
6625 | 1245 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1246 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1247 } |
6625 | 1248 |
6695 | 1249 if (success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1250 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1251 attr_id = H5Aopen_name (group_hid, "FILE"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1252 if (attr_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1253 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1254 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1255 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1256 type_class_hid = H5Tget_class (type_hid); |
6625 | 1257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1258 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1259 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1260 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1262 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1263 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1264 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1265 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); |
6695 | 1266 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1267 if (H5Aread (attr_id, st_id, path_tmp) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1268 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1269 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1270 fpath = path_tmp; |
6695 | 1271 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1272 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1273 } |
6695 | 1274 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1275 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1276 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1277 } |
6625 | 1278 |
1279 // restore error reporting: | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1280 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1281 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1282 #else |
6625 | 1283 H5Eset_auto (err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1284 #endif |
6625 | 1285 |
1286 success = (success ? set_fcn (octaveroot, fpath) : success); | |
4988 | 1287 } |
1288 | |
6695 | 1289 H5Tclose (type_hid); |
1290 H5Sclose (space_hid); | |
1291 H5Gclose (group_hid); | |
1292 | |
6625 | 1293 return success; |
4988 | 1294 } |
6625 | 1295 |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1296 #endif |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1297 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1298 /* |
6625 | 1299 %!test |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1300 %! a = 2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1301 %! f = @(x) a + x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1302 %! g = @(x) 2 * x; |
11541
28bae9cd7ea9
ov-fcn-handle.cc: use version instead of flops in test
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1303 %! hm = @version; |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
1304 %! hdld = @svd; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1305 %! hbi = @log2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1306 %! f2 = f; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1307 %! g2 = g; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1308 %! hm2 = hm; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1309 %! hdld2 = hdld; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1310 %! hbi2 = hbi; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1311 %! modes = {"-text", "-binary"}; |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1312 %! if (isfield (octave_config_info, "HAVE_HDF5") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1313 %! && octave_config_info ("HAVE_HDF5")) |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1314 %! modes(end+1) = "-hdf5"; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1315 %! endif |
7901 | 1316 %! for i = 1:numel (modes) |
1317 %! mode = modes{i}; | |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1318 %! nm = tempname (); |
6625 | 1319 %! unwind_protect |
15572
859c8bf6d134
Fix saved struct with function handle fails to load (bug #33857)
Max Brister <max@2bass.com>
parents:
15235
diff
changeset
|
1320 %! f2 (1); # bug #33857 |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1321 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1322 %! clear f2 g2 hm2 hdld2 hbi2 |
6625 | 1323 %! load (nm); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1324 %! assert (f (2), f2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1325 %! assert (g (2), g2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1326 %! assert (g (3), g2 (3)); |
6625 | 1327 %! unlink (nm); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1328 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
6625 | 1329 %! unwind_protect_cleanup |
1330 %! unlink (nm); | |
1331 %! end_unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1332 %! endfor |
6625 | 1333 */ |
4988 | 1334 |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1335 /* |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1336 %!function fcn_handle_save_recurse (n, mode, nm, f2, g2, hm2, hdld2, hbi2) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1337 %! if (n == 0) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1338 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1339 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1340 %! fcn_handle_save_recurse (n - 1, mode, nm, f2, g2, hm2, hdld2, hbi2); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1341 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1342 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1343 %!function [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n, nm) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1344 %! if (n == 0) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1345 %! load (nm) |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1346 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1347 %! [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n - 1, nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1348 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1349 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1350 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1351 Test for bug #35876 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1352 %!test |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1353 %! a = 2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1354 %! f = @(x) a + x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1355 %! g = @(x) 2 * x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1356 %! hm = @version; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1357 %! hdld = @svd; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1358 %! hbi = @log2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1359 %! f2 = f; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1360 %! g2 = g; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1361 %! hm2 = hm; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1362 %! hdld2 = hdld; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1363 %! hbi2 = hbi; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1364 %! modes = {"-text", "-binary"}; |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1365 %! if (isfield (octave_config_info, "HAVE_HDF5") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
15572
diff
changeset
|
1366 %! && octave_config_info ("HAVE_HDF5")) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1367 %! modes(end+1) = "-hdf5"; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1368 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1369 %! for i = 1:numel (modes) |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1370 %! mode = modes{i}; |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1371 %! nm = tempname (); |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1372 %! unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1373 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1374 %! clear f2 g2 hm2 hdld2 hbi2 |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1375 %! [f2, f2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (2, nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1376 %! load (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1377 %! assert (f (2), f2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1378 %! assert (g (2), g2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1379 %! assert (g (3), g2 (3)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1380 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1381 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1382 %! unwind_protect_cleanup |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1383 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1384 %! end_unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1385 %! endfor |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1386 */ |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1387 |
4343 | 1388 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
1389 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) |
4343 | 1390 { |
1391 print_raw (os, pr_as_read_syntax); | |
1392 newline (os); | |
1393 } | |
1394 | |
1395 void | |
1396 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1397 { | |
4980 | 1398 bool printed = false; |
1399 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1400 if (nm == anonymous) |
4980 | 1401 { |
1402 tree_print_code tpc (os); | |
1403 | |
4989 | 1404 // FCN is const because this member function is, so we can't |
4980 | 1405 // use it to call user_function_value, so we make a copy first. |
1406 | |
1407 octave_value ftmp = fcn; | |
1408 | |
1409 octave_user_function *f = ftmp.user_function_value (); | |
1410 | |
1411 if (f) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1412 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1413 tree_parameter_list *p = f->parameter_list (); |
4980 | 1414 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1415 os << "@("; |
4980 | 1416 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1417 if (p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1418 p->accept (tpc); |
4980 | 1419 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1420 os << ") "; |
4980 | 1421 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
11220
diff
changeset
|
1422 tpc.print_fcn_handle_body (f->body ()); |
4980 | 1423 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1424 printed = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1425 } |
4980 | 1426 } |
1427 | |
1428 if (! printed) | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1429 octave_print_internal (os, "@" + nm, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1430 current_print_indent_level ()); |
4343 | 1431 } |
1432 | |
1433 octave_value | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1434 make_fcn_handle (const std::string& nm, bool local_funcs) |
4343 | 1435 { |
1436 octave_value retval; | |
1437 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1438 // Bow to the god of compatibility. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1439 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1440 // FIXME: it seems ugly to put this here, but there is no single |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1441 // function in the parser that converts from the operator name to |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1442 // the corresponding function name. At least try to do it without N |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1443 // string compares. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1444 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1445 std::string tnm = nm; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1446 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1447 size_t len = nm.length (); |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1448 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1449 if (len == 3 && nm == ".**") |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1450 tnm = "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1451 else if (len == 2) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1452 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1453 if (nm[0] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1454 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1455 switch (nm[1]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1456 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1457 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1458 tnm = "transpose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1459 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1460 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1461 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1462 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1463 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1464 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1465 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1466 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1467 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1468 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1469 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1470 tnm = "times"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1471 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1472 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1473 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1474 tnm = "rdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1475 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1476 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1477 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1478 tnm = "power"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1479 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1480 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1481 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1482 tnm = "ldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1483 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1484 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1485 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1486 else if (nm[1] == '=') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1487 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1488 switch (nm[0]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1489 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1490 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1491 tnm = "le"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1492 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1493 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1494 case '=': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1495 tnm = "eq"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1496 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1497 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1498 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1499 tnm = "ge"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1500 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1501 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1502 case '~': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1503 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1504 tnm = "ne"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1505 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1506 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1507 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1508 else if (nm == "**") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1509 tnm = "mpower"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1510 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1511 else if (len == 1) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1512 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1513 switch (nm[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1514 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1515 case '~': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1516 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1517 tnm = "not"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1518 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1520 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1521 tnm = "ctranspose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1522 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1523 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1524 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1525 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1526 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1527 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1528 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1529 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1530 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1531 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1532 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1533 tnm = "mtimes"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1534 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1535 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1536 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1537 tnm = "mrdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1538 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1539 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1540 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1541 tnm = "mpower"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1542 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1543 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1544 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1545 tnm = "mldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1546 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1547 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1548 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1549 tnm = "lt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1550 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1551 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1552 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1553 tnm = "gt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1554 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1555 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1556 case '&': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1557 tnm = "and"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1558 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1559 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1560 case '|': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1561 tnm = "or"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1562 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1563 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1564 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1565 |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1566 octave_value f = symbol_table::find_function (tnm, octave_value_list (), |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1567 local_funcs); |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1568 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1569 octave_function *fptr = f.function_value (true); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1570 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1571 // Here we are just looking to see if FCN is a method or constructor |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1572 // for any class. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1573 if (local_funcs && fptr |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11223
diff
changeset
|
1574 && (fptr->is_subfunction () || fptr->is_private_function () |
18441
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18416
diff
changeset
|
1575 || fptr->is_class_constructor () |
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18416
diff
changeset
|
1576 || fptr->is_classdef_constructor ())) |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1577 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1578 // Locally visible function. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1579 retval = octave_value (new octave_fcn_handle (f, tnm)); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1580 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1581 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1582 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1583 // Globally visible (or no match yet). Query overloads. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1584 std::list<std::string> classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1585 bool any_match = fptr != 0 || classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1586 if (! any_match) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1587 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1588 // No match found, try updating load_path and query classes again. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1589 load_path::update (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1590 classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1591 any_match = classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1592 } |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1593 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1594 if (any_match) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1595 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1596 octave_fcn_handle *fh = new octave_fcn_handle (f, tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1597 retval = fh; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1598 |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1599 for (std::list<std::string>::iterator iter = classes.begin (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1600 iter != classes.end (); iter++) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1601 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1602 std::string class_name = *iter; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1603 octave_value fmeth = symbol_table::find_method (tnm, class_name); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1604 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1605 bool is_builtin = false; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1606 for (int i = 0; i < btyp_num_types; i++) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1607 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1608 // FIXME: Too slow? Maybe binary lookup? |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1609 if (class_name == btyp_class_name[i]) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1610 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1611 is_builtin = true; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1612 fh->set_overload (static_cast<builtin_type_t> (i), fmeth); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1613 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1614 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1615 |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1616 if (! is_builtin) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1617 fh->set_overload (class_name, fmeth); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1618 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1619 } |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1620 else |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1621 error ("@%s: no function and no method found", tnm.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1622 } |
4343 | 1623 |
1624 return retval; | |
1625 } | |
1626 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1627 /* |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1628 %!test |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1629 %! x = {".**", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1630 %! ".'", "transpose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1631 %! ".+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1632 %! ".-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1633 %! ".*", "times"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1634 %! "./", "rdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1635 %! ".^", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1636 %! ".\\", "ldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1637 %! "<=", "le"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1638 %! "==", "eq"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1639 %! ">=", "ge"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1640 %! "~=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1641 %! "!=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1642 %! "**", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1643 %! "~", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1644 %! "!", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1645 %! "\'", "ctranspose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1646 %! "+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1647 %! "-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1648 %! "*", "mtimes"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1649 %! "/", "mrdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1650 %! "^", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1651 %! "\\", "mldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1652 %! "<", "lt"; |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1653 %! ">", "gt"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1654 %! "&", "and"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1655 %! "|", "or"}; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1656 %! for i = 1:rows (x) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1657 %! assert (functions (str2func (x{i,1})).function, x{i,2}); |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1658 %! endfor |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1659 */ |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1660 |
4933 | 1661 DEFUN (functions, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1662 "-*- texinfo -*-\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1663 @deftypefn {Built-in Function} {@var{s} =} functions (@var{fcn_handle})\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1664 Return a structure containing information about the function handle\n\ |
4933 | 1665 @var{fcn_handle}.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1666 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1667 The structure @var{s} always contains these 3 fields:\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1668 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1669 @table @asis\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1670 @item function\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1671 The function name. For an anonymous function (no name) this will be the\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1672 actual function definition.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1673 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1674 @item type\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1675 Type of the function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1676 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1677 @table @asis\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1678 @item anonymous\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1679 The function is anonymous.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1680 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1681 @item private\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1682 The function is private.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1683 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1684 @item overloaded\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1685 The function overloads an existing function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1686 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1687 @item simple\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1688 The function is a built-in or m-file function.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1689 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1690 @item subfunction\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1691 The function is a subfunction within an m-file.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1692 @end table\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1693 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1694 @item file\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1695 The m-file that will be called to perform the function. This field is empty\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1696 for anonymous and built-in functions.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1697 @end table\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1698 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1699 In addition, some function types may return more information in additional\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1700 fields.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1701 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1702 @strong{Warning:} @code{functions} is provided for debugging purposes only.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1703 It's behavior may change in the future and programs should not depend on a\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1704 particular output.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1705 \n\ |
4933 | 1706 @end deftypefn") |
4343 | 1707 { |
1708 octave_value retval; | |
1709 | |
4933 | 1710 if (args.length () == 1) |
4343 | 1711 { |
4933 | 1712 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4343 | 1713 |
1714 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1715 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1716 octave_function *fcn = fh ? fh->function_value () : 0; |
4343 | 1717 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1718 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1719 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1720 octave_scalar_map m; |
4649 | 1721 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1722 std::string fh_nm = fh->fcn_name (); |
4933 | 1723 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1724 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1725 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1726 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1727 fh->print_raw (buf); |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1728 m.setfield ("function", buf.str ()); |
6625 | 1729 |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1730 m.setfield ("type", "anonymous"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1731 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1732 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1733 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1734 m.setfield ("function", fh_nm); |
4343 | 1735 |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11223
diff
changeset
|
1736 if (fcn->is_subfunction ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1737 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1738 m.setfield ("type", "subfunction"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1739 Cell parentage (dim_vector (1, 2)); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1740 parentage.elem (0) = fh_nm; |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1741 parentage.elem (1) = fcn->parent_fcn_name (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1742 m.setfield ("parentage", octave_value (parentage)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1743 } |
9509
c5330ef7aecd
fix handles to private functions, simplify out-of-date checks in symtab
Jaroslav Hajek <highegg@gmail.com>
parents:
9466
diff
changeset
|
1744 else if (fcn->is_private_function ()) |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1745 m.setfield ("type", "private"); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1746 else if (fh->is_overloaded ()) |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1747 m.setfield ("type", "overloaded"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1748 else |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1749 m.setfield ("type", "simple"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1750 } |
4933 | 1751 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1752 std::string nm = fcn->fcn_file_name (); |
4343 | 1753 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1754 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1755 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1756 m.setfield ("file", nm); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1757 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1758 octave_user_function *fu = fh->user_function_value (); |
6625 | 1759 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1760 std::list<symbol_table::symbol_record> vars |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1761 = symbol_table::all_variables (fu->scope (), 0); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1762 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1763 size_t varlen = vars.size (); |
6625 | 1764 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1765 if (varlen > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1766 { |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1767 octave_scalar_map ws; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1768 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1769 p = vars.begin (); p != vars.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1770 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1771 ws.assign (p->name (), p->varval (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1772 } |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1773 |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1774 m.setfield ("workspace", ws); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1775 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1776 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1777 else if (fcn->is_user_function () || fcn->is_user_script ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1778 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1779 octave_function *fu = fh->function_value (); |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1780 m.setfield ("file", fu->fcn_file_name ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1781 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1782 else |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1783 m.setfield ("file", ""); |
4933 | 1784 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1785 retval = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1786 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1787 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1788 error ("functions: FCN_HANDLE is not a valid function handle object"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1789 } |
4343 | 1790 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1791 error ("functions: FCN_HANDLE argument must be a function handle object"); |
4343 | 1792 } |
1793 else | |
5823 | 1794 print_usage (); |
4343 | 1795 |
1796 return retval; | |
1797 } | |
1798 | |
4933 | 1799 DEFUN (func2str, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1800 "-*- texinfo -*-\n\ |
4933 | 1801 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\ |
1802 Return a string containing the name of the function referenced by\n\ | |
1803 the function handle @var{fcn_handle}.\n\ | |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1804 @seealso{str2func, functions}\n\ |
4933 | 1805 @end deftypefn") |
4343 | 1806 { |
1807 octave_value retval; | |
1808 | |
4933 | 1809 if (args.length () == 1) |
4930 | 1810 { |
4933 | 1811 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4930 | 1812 |
4933 | 1813 if (! error_state && fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1814 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1815 std::string fh_nm = fh->fcn_name (); |
6416 | 1816 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1817 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1819 std::ostringstream buf; |
6416 | 1820 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1821 fh->print_raw (buf); |
6416 | 1822 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1823 retval = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1824 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1825 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1826 retval = fh_nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1827 } |
4343 | 1828 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1829 error ("func2str: FCN_HANDLE must be a valid function handle"); |
4343 | 1830 } |
1831 else | |
5823 | 1832 print_usage (); |
4343 | 1833 |
1834 return retval; | |
1835 } | |
1836 | |
4933 | 1837 DEFUN (str2func, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1838 "-*- texinfo -*-\n\ |
10840 | 1839 @deftypefn {Built-in Function} {} str2func (@var{fcn_name})\n\ |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1840 @deftypefnx {Built-in Function} {} str2func (@var{fcn_name}, \"global\")\n\ |
4933 | 1841 Return a function handle constructed from the string @var{fcn_name}.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1842 If the optional @qcode{\"global\"} argument is passed, locally visible\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1843 functions are ignored in the lookup.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1844 @seealso{func2str, inline}\n\ |
4933 | 1845 @end deftypefn") |
4343 | 1846 { |
1847 octave_value retval; | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1848 int nargin = args.length (); |
4343 | 1849 |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1850 if (nargin == 1 || nargin == 2) |
4343 | 1851 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1852 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1853 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1854 std::string nm = args(0).string_value (); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1855 retval = make_fcn_handle (nm, nargin != 2); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1856 } |
4343 | 1857 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1858 error ("str2func: FCN_NAME must be a string"); |
4343 | 1859 } |
1860 else | |
5823 | 1861 print_usage (); |
4343 | 1862 |
1863 return retval; | |
1864 } | |
1865 | |
1866 /* | |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1867 %!function y = __testrecursionfunc (f, x, n) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1868 %! if (nargin < 3) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1869 %! n = 0; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1870 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1871 %! if (n > 2) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1872 %! y = f (x); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1873 %! else |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1874 %! n++; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1875 %! y = __testrecursionfunc (@(x) f (2*x), x, n); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1876 %! endif |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1877 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1878 %! |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
1879 %!assert (__testrecursionfunc (@(x) x, 1), 8) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1880 */ |
10960 | 1881 |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1882 DEFUN (is_function_handle, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1883 "-*- texinfo -*-\n\ |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1884 @deftypefn {Built-in Function} {} is_function_handle (@var{x})\n\ |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1885 Return true if @var{x} is a function handle.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1886 @seealso{isa, typeinfo, class, functions}\n\ |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1887 @end deftypefn") |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1888 { |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1889 octave_value retval; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1890 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1891 int nargin = args.length (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1892 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1893 if (nargin == 1) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1894 retval = args(0).is_function_handle (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1895 else |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1896 print_usage (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1897 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1898 return retval; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1899 } |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1900 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1901 /* |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1902 %!shared fh |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1903 %! fh = @(x) x; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1904 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1905 %!assert (is_function_handle (fh)) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1906 %!assert (! is_function_handle ({fh})) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1907 %!assert (! is_function_handle (1)) |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1908 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1909 %!error is_function_handle () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1910 %!error is_function_handle (1, 2) |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1911 */ |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
1912 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1913 octave_fcn_binder::octave_fcn_binder (const octave_value& f, |
10960 | 1914 const octave_value& root, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1915 const octave_value_list& templ, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1916 const std::vector<int>& mask, |
10960 | 1917 int exp_nargin) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1918 : octave_fcn_handle (f), root_handle (root), arg_template (templ), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1919 arg_mask (mask), expected_nargin (exp_nargin) |
10960 | 1920 { |
1921 } | |
1922 | |
1923 octave_fcn_handle * | |
1924 octave_fcn_binder::maybe_binder (const octave_value& f) | |
1925 { | |
1926 octave_fcn_handle *retval = 0; | |
1927 | |
1928 octave_user_function *usr_fcn = f.user_function_value (false); | |
1929 tree_parameter_list *param_list = usr_fcn ? usr_fcn->parameter_list () : 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1930 |
17898
8c33abdd2f9a
maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents:
17896
diff
changeset
|
1931 tree_statement_list *cmd_list = 0; |
8c33abdd2f9a
maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents:
17896
diff
changeset
|
1932 tree_expression *body_expr = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1933 |
17896
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1934 if (usr_fcn) |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1935 { |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1936 cmd_list = usr_fcn->body (); |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1937 if (cmd_list) |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1938 { |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1939 // Verify that body is a single expression (always true in theory). |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1940 body_expr = (cmd_list->length () == 1 |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1941 ? cmd_list->front ()->expression () : 0); |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1942 } |
f05f571ff1fa
Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
17787
diff
changeset
|
1943 } |
10960 | 1944 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1945 if (body_expr && body_expr->is_index_expression () |
10960 | 1946 && ! (param_list && param_list->takes_varargs ())) |
1947 { | |
1948 // It's an index expression. | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1949 tree_index_expression *idx_expr = dynamic_cast<tree_index_expression *> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1950 (body_expr); |
10960 | 1951 tree_expression *head_expr = idx_expr->expression (); |
1952 std::list<tree_argument_list *> arg_lists = idx_expr->arg_lists (); | |
1953 std::string type_tags = idx_expr->type_tags (); | |
1954 | |
1955 if (type_tags.length () == 1 && type_tags[0] == '(' | |
1956 && head_expr->is_identifier ()) | |
1957 { | |
1958 assert (arg_lists.size () == 1); | |
1959 | |
1960 // It's a single index expression: a(x,y,....) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1961 tree_identifier *head_id = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1962 dynamic_cast<tree_identifier *> (head_expr); |
10960 | 1963 tree_argument_list *arg_list = arg_lists.front (); |
1964 | |
1965 // Build a map of input params to their position. | |
1966 std::map<std::string, int> arginmap; | |
1967 int npar = 0; | |
1968 | |
1969 if (param_list) | |
1970 { | |
1971 for (tree_parameter_list::iterator it = param_list->begin (); | |
1972 it != param_list->end (); ++it, ++npar) | |
1973 { | |
1974 tree_decl_elt *elt = *it; | |
1975 tree_identifier *id = elt ? elt->ident () : 0; | |
1976 if (id && ! id->is_black_hole ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1977 arginmap[id->name ()] = npar; |
10960 | 1978 } |
1979 } | |
1980 | |
1981 if (arg_list && arg_list->length () > 0) | |
1982 { | |
1983 bool bad = false; | |
1984 int nargs = arg_list->length (); | |
1985 octave_value_list arg_template (nargs); | |
1986 std::vector<int> arg_mask (nargs); | |
1987 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1988 // Verify that each argument is either a named param, a constant, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1989 // or a defined identifier. |
10960 | 1990 int iarg = 0; |
1991 for (tree_argument_list::iterator it = arg_list->begin (); | |
1992 it != arg_list->end (); ++it, ++iarg) | |
1993 { | |
1994 tree_expression *elt = *it; | |
1995 if (elt && elt->is_constant ()) | |
1996 { | |
1997 arg_template(iarg) = elt->rvalue1 (); | |
1998 arg_mask[iarg] = -1; | |
1999 } | |
2000 else if (elt && elt->is_identifier ()) | |
2001 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2002 tree_identifier *elt_id = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2003 dynamic_cast<tree_identifier *> (elt); |
10960 | 2004 if (arginmap.find (elt_id->name ()) != arginmap.end ()) |
2005 { | |
2006 arg_mask[iarg] = arginmap[elt_id->name ()]; | |
2007 } | |
2008 else if (elt_id->is_defined ()) | |
2009 { | |
2010 arg_template(iarg) = elt_id->rvalue1 (); | |
2011 arg_mask[iarg] = -1; | |
2012 } | |
2013 else | |
2014 { | |
2015 bad = true; | |
2016 break; | |
2017 } | |
2018 } | |
2019 else | |
2020 { | |
2021 bad = true; | |
2022 break; | |
2023 } | |
2024 } | |
2025 | |
2026 octave_value root_val; | |
2027 | |
2028 if (! bad) | |
2029 { | |
2030 // If the head is a value, use it as root. | |
2031 if (head_id->is_defined ()) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2032 root_val = head_id->rvalue1 (); |
10960 | 2033 else |
2034 { | |
2035 // It's a name. | |
2036 std::string head_name = head_id->name (); | |
2037 // Function handles can't handle legacy dispatch, so | |
2038 // we make sure it's not defined. | |
2039 if (symbol_table::get_dispatch (head_name).size () > 0) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2040 bad = true; |
10960 | 2041 else |
2042 { | |
2043 // Simulate try/catch. | |
2044 unwind_protect frame; | |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10961
diff
changeset
|
2045 interpreter_try (frame); |
10960 | 2046 |
2047 root_val = make_fcn_handle (head_name); | |
2048 if (error_state) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2049 bad = true; |
10960 | 2050 } |
2051 } | |
2052 } | |
2053 | |
2054 if (! bad) | |
2055 { | |
10961 | 2056 // Stash proper name tags. |
2057 std::list<string_vector> arg_names = idx_expr->arg_names (); | |
2058 assert (arg_names.size () == 1); | |
2059 arg_template.stash_name_tags (arg_names.front ()); | |
2060 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2061 retval = new octave_fcn_binder (f, root_val, arg_template, |
10960 | 2062 arg_mask, npar); |
2063 } | |
2064 } | |
2065 } | |
2066 } | |
2067 | |
2068 if (! retval) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2069 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous); |
10960 | 2070 |
2071 return retval; | |
2072 } | |
2073 | |
2074 octave_value_list | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2075 octave_fcn_binder::do_multi_index_op (int nargout, |
10960 | 2076 const octave_value_list& args) |
2077 { | |
2078 return do_multi_index_op (nargout, args, 0); | |
2079 } | |
2080 | |
2081 octave_value_list | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
2082 octave_fcn_binder::do_multi_index_op (int nargout, |
10960 | 2083 const octave_value_list& args, |
2084 const std::list<octave_lvalue>* lvalue_list) | |
2085 { | |
2086 octave_value_list retval; | |
2087 | |
2088 if (args.length () == expected_nargin) | |
2089 { | |
2090 for (int i = 0; i < arg_template.length (); i++) | |
2091 { | |
2092 int j = arg_mask[i]; | |
2093 if (j >= 0) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2094 arg_template(i) = args(j); // May force a copy... |
10960 | 2095 } |
2096 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2097 // Make a shallow copy of arg_template, to ensure consistency throughout |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2098 // the following call even if we happen to get back here. |
10961 | 2099 octave_value_list tmp (arg_template); |
2100 retval = root_handle.do_multi_index_op (nargout, tmp, lvalue_list); | |
10960 | 2101 } |
2102 else | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2103 retval = octave_fcn_handle::do_multi_index_op (nargout, args, lvalue_list); |
10960 | 2104 |
2105 return retval; | |
2106 } | |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2107 |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2108 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2109 %!function r = __f (g, i) |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2110 %! r = g(i); |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2111 %!endfunction |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2112 %!test |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2113 %! x = [1,2;3,4]; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2114 %! assert (__f (@(i) x(:,i), 1), [1;3]); |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2115 */ |