Mercurial > octave
annotate libinterp/octave-value/ov-fcn-handle.cc @ 28430:5bfa8e018704 stable
store local init vars for anonymous functions in handle, not function object
This change is step toward revamping function handles by storing
variable init values for anonymous functions in function handle
objects instead of in the corresponding functions.
* call-stack.h, call-stack.cc (call_stack::push): New overload that
accepts local variable map in addition to function object.
* stack-frame.h (user_fcn_stack_frame::user_fcn_stack_frame):
New constructor that accepts local variable map in addition to
function object.
(stack_frame::local_vars_map): New typedef.
* ov-fcn-handle.h, ov-fcn-handle.cc (octave_fcn_handle::m_local_vars):
New data member.
(octave_fcn_handle::octave_fcn_handle): Update existing constructors
and provide new one to construct handle from function object and local
variable map.
(octave_fcn_handle::call): If m_local_vars is defined, push stack
frame with that info and execute function here.
(octave_fcn_handle::workspace): Create workspace struct from
m_local_vars instead of getting that info from the function object.
(octave_fcn_handle::parse_anon_fcn_handle): Copy m_local_vars from new
function handle object.
(octave_fcn_handle::save_ascii, octave_fcn_handle::save_binary,
octave_fcn_handle::save_hdf5): Use m_local_vars instead of getting
info from function object.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::local_vars_map):
Delete typedef.
(octave_user_function::m_local_var_init_vals): Delete data member and
all uses.
(octave_user_function::local_var_init_vals): Delete.
* pt-eval.h, pt-eval.cc (tree_evaluator::push_stack_frame):
New overload that accepts local variable map and user function.
(tree_evaluator::init_local_fcn_vars): Delete function and all uses.
* pt-fcn-handle.cc (tree_anon_fcn_handle::evaluate): Store local
variables in function handle object instead of function object.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 30 Mar 2020 15:14:10 -0400 |
parents | 8eb8ba8aff9a |
children | 71c34141cc2d |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 2003-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4343 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21211
diff
changeset
|
27 # include "config.h" |
4343 | 28 #endif |
29 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25383
diff
changeset
|
30 #include <istream> |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
31 #include <list> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25383
diff
changeset
|
32 #include <ostream> |
5765 | 33 #include <sstream> |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
34 #include <string> |
5164 | 35 #include <vector> |
4343 | 36 |
7336 | 37 #include "file-ops.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
38 #include "oct-locbuf.h" |
7336 | 39 |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
40 #include "defaults.h" |
4343 | 41 #include "defun.h" |
4654 | 42 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21079
diff
changeset
|
43 #include "errwarn.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
44 #include "file-stat.h" |
5663 | 45 #include "input.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
46 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
47 #include "interpreter.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
48 #include "load-path.h" |
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
49 #include "oct-env.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
50 #include "oct-hdf5.h" |
4343 | 51 #include "oct-map.h" |
52 #include "ov-base.h" | |
53 #include "ov-fcn-handle.h" | |
4980 | 54 #include "ov-usr-fcn.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
55 #include "parse.h" |
4343 | 56 #include "pr-output.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
57 #include "pt-arg-list.h" |
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
58 #include "pt-assign.h" |
4980 | 59 #include "pt-cmd.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
60 #include "pt-eval.h" |
4980 | 61 #include "pt-exp.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
62 #include "pt-idx.h" |
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
63 #include "pt-misc.h" |
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
64 #include "pt-pr-code.h" |
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
65 #include "pt-stmt.h" |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
66 #include "stack-frame.h" |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
67 #include "syminfo.h" |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24354
diff
changeset
|
68 #include "symscope.h" |
6625 | 69 #include "unwind-prot.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
70 #include "variables.h" |
4988 | 71 |
72 #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
|
73 #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
|
74 #include "ls-hdf5.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20435
diff
changeset
|
75 #include "ls-oct-text.h" |
6625 | 76 #include "ls-oct-binary.h" |
4988 | 77 #include "ls-utils.h" |
4343 | 78 |
79 | |
4612 | 80 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
|
81 "function handle", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
82 "function_handle"); |
4343 | 83 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
84 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
|
85 |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
86 octave_fcn_handle::octave_fcn_handle (const octave::symbol_scope& scope, |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
87 const std::string& n) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
88 : m_fcn (), m_obj (), m_name (n), m_scope (scope), m_is_nested (false), |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
89 m_closure_frames (), m_local_vars (nullptr), m_dispatch_class () |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
90 { |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
91 if (! m_name.empty () && m_name[0] == '@') |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
92 m_name = m_name.substr (1); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
93 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
94 size_t pos = m_name.find ('.'); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
95 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
96 if (pos != std::string::npos) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
97 { |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
98 // If we are looking at |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
99 // |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
100 // obj . meth |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
101 // |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
102 // Store the object so that calling METH for OBJ will work even if |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
103 // it is done outside of the scope whre OBJ was initially defined |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
104 // or if OBJ is cleared before the method call is made through the |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
105 // function handle. |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
106 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
107 std::string obj_name = m_name.substr (0, pos); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
108 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
109 octave::interpreter& interp |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
110 = octave::__get_interpreter__ ("octave_fcn_handle::octave_fcn_handle"); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
111 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
112 octave_value val = interp.varval (obj_name); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
113 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
114 if (val.is_classdef_object ()) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
115 m_obj = val; |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
116 } |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
117 } |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
118 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
119 octave_fcn_handle::octave_fcn_handle (const octave::symbol_scope& scope, |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
120 const octave_value& f, |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
121 const std::string& n) |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
122 : m_fcn (f), m_obj (), m_name (n), m_scope (scope), m_is_nested (false), |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
123 m_closure_frames (), m_local_vars (nullptr), m_dispatch_class () |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
124 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
125 octave_user_function *uf = m_fcn.user_function_value (true); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
126 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
127 if (uf && m_name != anonymous) |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
128 { |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
129 octave::symbol_scope uf_scope = uf->scope (); |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
130 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
131 if (uf_scope) |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
132 uf_scope.cache_name (m_name); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
133 } |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
134 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
135 if (uf && uf->is_nested_function () && ! uf->is_subfunction ()) |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
136 m_is_nested = true; |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
137 } |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
138 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
139 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
|
140 const std::string& n) |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
141 : m_fcn (f), m_obj (), m_name (n), m_scope (), m_is_nested (false), |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
142 m_closure_frames (), m_local_vars (nullptr), m_dispatch_class () |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
143 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
144 octave_user_function *uf = m_fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
145 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
146 if (uf && m_name != anonymous) |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
147 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
148 octave::symbol_scope uf_scope = uf->scope (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
149 |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
150 if (uf_scope) |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
151 uf_scope.cache_name (m_name); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
152 } |
25111
959d6c3da166
undo previous change for handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
153 |
959d6c3da166
undo previous change for handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
154 if (uf && uf->is_nested_function () && ! uf->is_subfunction ()) |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
155 m_is_nested = true; |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
156 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
157 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
158 octave_fcn_handle::octave_fcn_handle (const octave_value& f, |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
159 const octave::stack_frame::local_vars_map& local_vars) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
160 : m_fcn (f), m_obj (), m_name (anonymous), m_scope (), m_is_nested (false), |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
161 m_closure_frames (), m_local_vars (new octave::stack_frame::local_vars_map (local_vars)), |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
162 m_dispatch_class () |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
163 { } |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
164 |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
165 octave_fcn_handle::octave_fcn_handle (const octave_fcn_handle& fh) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
166 : octave_base_value (fh), m_fcn (fh.m_fcn), m_obj (fh.m_obj), |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
167 m_name (fh.m_name), m_scope (fh.m_scope), m_is_nested (fh.m_is_nested), |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
168 m_closure_frames (fh.m_closure_frames), |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
169 m_local_vars (fh.m_local_vars |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
170 ? new octave::stack_frame::local_vars_map (*(fh.m_local_vars)) : nullptr), |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
171 m_dispatch_class (fh.m_dispatch_class) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
172 { } |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
173 |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
174 octave_fcn_handle::~octave_fcn_handle (void) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
175 { |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
176 delete m_local_vars; |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
177 } |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
178 |
4924 | 179 octave_value_list |
180 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
|
181 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
182 int nargout) |
4924 | 183 { |
184 octave_value_list retval; | |
185 | |
186 switch (type[0]) | |
187 { | |
188 case '(': | |
189 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
190 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5663 | 191 |
23502
c6714ae1c06c
eliminate remaining do_multi_index_op methods
John W. Eaton <jwe@octave.org>
parents:
23501
diff
changeset
|
192 retval = call (tmp_nargout, idx.front ()); |
4924 | 193 } |
194 break; | |
195 | |
196 case '{': | |
197 case '.': | |
198 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
199 std::string tnm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
200 error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); |
4924 | 201 } |
202 break; | |
203 | |
204 default: | |
205 panic_impossible (); | |
206 } | |
207 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
208 // FIXME: perhaps there should be an |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
209 // octave_value_list::next_subsref member function? See also |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
210 // octave_builtin::subsref. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
211 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
212 if (idx.size () > 1) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
213 retval = retval(0).next_subsref (nargout, type, idx); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
214 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
215 return retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
216 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
217 |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
218 static void |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
219 err_invalid_fcn_handle (const std::string& name) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
220 { |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
221 error ("%s: invalid function handle", name.c_str ()); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
222 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
223 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
224 octave_value_list |
23502
c6714ae1c06c
eliminate remaining do_multi_index_op methods
John W. Eaton <jwe@octave.org>
parents:
23501
diff
changeset
|
225 octave_fcn_handle::call (int nargout, const octave_value_list& args) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
226 { |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
227 // FIXME: if m_name has a '.' in the name, lookup first component. If |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
228 // it is a classdef meta object, then build TYPE and IDX arguments and |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
229 // make a subsref call using them. |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
230 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
231 octave_value fcn_to_call = m_fcn; |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
232 |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
233 octave::interpreter& interp |
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
234 = octave::__get_interpreter__ ("octave_fcn_handle::call"); |
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
235 |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
236 if (! fcn_to_call.is_defined ()) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
237 { |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
238 // The following code is similar to part of |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
239 // tree_evaluator::visit_index_expression but simpler because it |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
240 // handles a more restricted case. |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
241 |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
242 octave::symbol_table& symtab = interp.get_symbol_table (); |
13193
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
243 |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
244 size_t pos = m_name.find ('.'); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
245 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
246 if (pos != std::string::npos) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
247 { |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
248 // We can have one of |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
249 // |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
250 // pkg-list . fcn (args) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
251 // pkg-list . cls . meth (args) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
252 // cls . meth (args) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
253 |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
254 // Evaluate package elements until we find a function, |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
255 // classdef object, or classdef_meta object that is not a |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
256 // package. An object may only appear as the first element, |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
257 // then it must be followed directly by a function name. |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
258 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
259 size_t beg = 0; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
260 size_t end = pos; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
261 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
262 std::vector<std::string> idx_elts; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
263 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
264 while (true) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
265 { |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
266 end = m_name.find ('.', beg); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
267 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
268 idx_elts.push_back (m_name.substr (beg, end-beg)); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
269 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
270 if (end == std::string::npos) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
271 break; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
272 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
273 beg = end+1; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
274 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
275 |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
276 size_t n_elts = idx_elts.size (); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
277 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
278 bool have_object = false; |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
279 octave_value partial_expr_val; |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
280 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
281 if (m_obj.is_defined ()) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
282 { |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
283 // The first element was already defined elsewhere, |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
284 // possibly in the scope where the function handle was |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
285 // created. |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
286 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
287 partial_expr_val = m_obj; |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
288 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
289 if (m_obj.is_classdef_object ()) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
290 have_object = true; |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
291 else |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
292 err_invalid_fcn_handle (m_name); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
293 } |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
294 else |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
295 { |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
296 // Lazy evaluation. The first element was not known to be |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
297 // defined as an object in the scope where the handle was |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
298 // created. See if there is a definition in the current |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
299 // scope. |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
300 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
301 partial_expr_val = interp.varval (idx_elts[0]); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
302 } |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
303 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
304 if (partial_expr_val.is_defined ()) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
305 { |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
306 if (! partial_expr_val.is_classdef_object () || n_elts != 2) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
307 err_invalid_fcn_handle (m_name); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
308 |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
309 have_object = true; |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
310 } |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
311 else |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
312 partial_expr_val |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
313 = symtab.find_function (idx_elts[0], ovl (), m_scope); |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
314 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
315 std::string type; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
316 std::list<octave_value_list> arg_list; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
317 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
318 for (size_t i = 1; i < n_elts; i++) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
319 { |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
320 if (partial_expr_val.is_package ()) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
321 { |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
322 if (have_object) |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
323 err_invalid_fcn_handle (m_name); |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
324 |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
325 type = "."; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
326 arg_list.push_back (ovl (idx_elts[i])); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
327 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
328 try |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
329 { |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
330 // Silently ignore extra output values. |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
331 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
332 octave_value_list tmp_list |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
333 = partial_expr_val.subsref (type, arg_list, 0); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
334 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
335 partial_expr_val |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
336 = tmp_list.length () ? tmp_list(0) : octave_value (); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
337 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
338 if (partial_expr_val.is_cs_list ()) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
339 err_invalid_fcn_handle (m_name); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
340 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
341 arg_list.clear (); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
342 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
343 catch (octave::index_exception&) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
344 { |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
345 err_invalid_fcn_handle (m_name); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
346 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
347 } |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
348 else if (have_object || partial_expr_val.is_classdef_meta ()) |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
349 { |
26962
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
350 // Object or class name must be the next to the last |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
351 // element (it was the previous one, so if this is the |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
352 // final element, it should be a classdef method, |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
353 // but we'll let the classdef or classdef_meta subsref |
b033cf021048
allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26958
diff
changeset
|
354 // function sort that out. |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
355 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
356 if (i != n_elts-1) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
357 err_invalid_fcn_handle (m_name); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
358 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
359 type = ".("; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
360 arg_list.push_back (ovl (idx_elts[i])); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
361 arg_list.push_back (args); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
362 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
363 return partial_expr_val.subsref (type, arg_list, nargout); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
364 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
365 else |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
366 err_invalid_fcn_handle (m_name); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
367 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
368 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
369 // If we get here, we must have a function to call. |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
370 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
371 if (! partial_expr_val.is_function ()) |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
372 err_invalid_fcn_handle (m_name); |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
373 |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
374 fcn_to_call = partial_expr_val; |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
375 } |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
376 else |
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
377 fcn_to_call = symtab.find_function (m_name, args, m_scope); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
378 } |
13193
a00ff5cedb9b
also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents:
12714
diff
changeset
|
379 |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
380 if (! fcn_to_call.is_defined ()) |
26958
51414d51a973
make function handles work for classdef static methods (bug #51709)
John W. Eaton <jwe@octave.org>
parents:
26892
diff
changeset
|
381 err_invalid_fcn_handle (m_name); |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
382 |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
383 octave::tree_evaluator& tw = interp.get_evaluator (); |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
384 |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
385 octave::unwind_action act2 ([&tw] () { tw.set_dispatch_class (""); }); |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
386 |
27210
bd684aad1821
eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
387 tw.set_dispatch_class (m_dispatch_class); |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
388 |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
389 if (m_closure_frames) |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
390 { |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
391 if (! fcn_to_call.is_user_function ()) |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
392 { |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
393 std::string tname = fcn_to_call.type_name (); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
394 error ("internal error: closure frames associated with '%s' object", |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
395 tname.c_str ()); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
396 } |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
397 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
398 octave_user_function *oct_usr_fcn = fcn_to_call.user_function_value (); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
399 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
400 tw.push_stack_frame (oct_usr_fcn, m_closure_frames); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
401 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
402 octave::unwind_action act1 ([&tw] () { tw.pop_stack_frame (); }); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
403 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
404 return oct_usr_fcn->execute (tw, nargout, args); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
405 } |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
406 else if (m_local_vars) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
407 { |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
408 if (! fcn_to_call.is_user_function ()) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
409 { |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
410 std::string tname = fcn_to_call.type_name (); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
411 error ("internal error: local vars associated with '%s' object", |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
412 tname.c_str ()); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
413 } |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
414 |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
415 octave_user_function *oct_usr_fcn = fcn_to_call.user_function_value (); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
416 |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
417 tw.push_stack_frame (oct_usr_fcn, *m_local_vars); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
418 |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
419 octave::unwind_action act1 ([&tw] () { tw.pop_stack_frame (); }); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
420 |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
421 return oct_usr_fcn->execute (tw, nargout, args); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
422 } |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
423 else |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
424 { |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
425 octave_function *oct_fcn = fcn_to_call.function_value (); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
426 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
427 return oct_fcn->call (tw, nargout, args); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
428 } |
4924 | 429 } |
430 | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
431 dim_vector |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
432 octave_fcn_handle::dims (void) const |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
433 { |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
434 static dim_vector dv (1, 1); |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
435 return dv; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
436 } |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20496
diff
changeset
|
437 |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
438 octave_function * octave_fcn_handle::function_value (bool) |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
439 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
440 if (m_fcn.is_defined ()) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
441 return m_fcn.function_value (); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
442 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
443 octave::symbol_table& symtab |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
444 = octave::__get_symbol_table__ ("octave_fcn_handle::set_fcn"); |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
445 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
446 // Cache this value so that the pointer will be valid as long as the |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
447 // function handle object is valid. |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
448 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
449 m_generic_fcn = symtab.find_function (m_name, octave_value_list (), m_scope); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
450 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
451 return (m_generic_fcn.is_defined () |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
452 ? m_generic_fcn.function_value () : nullptr); |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
453 } |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
454 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
455 octave_user_function * octave_fcn_handle::user_function_value (bool) |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
456 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
457 if (m_fcn.is_defined ()) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
458 return m_fcn.user_function_value (); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
459 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
460 octave::symbol_table& symtab |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
461 = octave::__get_symbol_table__ ("octave_fcn_handle::set_fcn"); |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
462 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
463 // Cache this value so that the pointer will be valid as long as the |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
464 // function handle object is valid. |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
465 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
466 m_generic_fcn = symtab.find_user_function (m_name); |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
467 |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
468 return (m_generic_fcn.is_defined () |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
469 ? m_generic_fcn.user_function_value () : nullptr); |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
470 } |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
471 |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
472 // Save call stack frames for handles to nested functions. |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
473 |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
474 void |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
475 octave_fcn_handle::push_closure_context (octave::tree_evaluator& tw) |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
476 { |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28317
diff
changeset
|
477 m_closure_frames = tw.get_current_stack_frame (); |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
478 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
479 |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
480 octave_value |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
481 octave_fcn_handle::workspace (void) const |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
482 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
483 if (m_name == anonymous) |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
484 { |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
485 octave_scalar_map ws; |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
486 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
487 if (m_local_vars) |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
488 { |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
489 for (const auto& nm_val : *m_local_vars) |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
490 ws.assign (nm_val.first, nm_val.second); |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
491 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
492 |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
493 return ws; |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
494 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
495 else if (m_closure_frames) |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
496 { |
28426
9a3deb17b4ea
use shared_ptr for stack frames in call stack and for accesss and static links
John W. Eaton <jwe@octave.org>
parents:
28317
diff
changeset
|
497 return m_closure_frames->workspace (); |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
498 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
499 |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
500 return Cell (); |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
501 } |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
502 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
503 bool |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
504 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
|
505 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
506 if (m_fcn.is_defined () && h.m_fcn.is_defined ()) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
507 return m_fcn.is_copy_of (h.m_fcn); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
508 else if (m_fcn.is_undefined () && h.m_fcn.is_undefined ()) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
509 return m_name == h.m_name; |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
510 else |
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
511 return false; |
10322
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
512 } |
21551cc88061
improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
513 |
4988 | 514 bool |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
515 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
|
516 const std::string& fpath) |
4988 | 517 { |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
518 if (octaveroot.length () != 0 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
519 && fpath.length () >= octaveroot.length () |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
520 && fpath.substr (0, octaveroot.length ()) == octaveroot |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
521 && octave::config::octave_exec_home () != octaveroot) |
6625 | 522 { |
523 // First check if just replacing matlabroot is enough | |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
524 std::string str |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
525 = (octave::config::octave_exec_home () |
23717
06579337237b
move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
526 + fpath.substr (octaveroot.length ())); |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
527 octave::sys::file_stat fs (str); |
6625 | 528 |
529 if (fs.exists ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
530 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
531 size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
6625 | 532 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
533 std::string dir_name = str.substr (0, xpos); |
6625 | 534 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
535 octave_value ov_fcn |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
536 = octave::load_fcn_from_file (str, dir_name, "", "", m_name); |
6625 | 537 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
538 if (ov_fcn.is_undefined ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
539 error ("function handle points to non-existent function"); |
6625 | 540 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
541 m_fcn = octave_value (new octave_fcn_handle (ov_fcn, m_name)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
542 } |
6625 | 543 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
544 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
545 // Next just search for it anywhere in the system path |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
546 std::list<std::string> names; |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
547 names.push_back (m_name + ".oct"); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
548 names.push_back (m_name + ".mex"); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
549 names.push_back (m_name + ".m"); |
6625 | 550 |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27210
diff
changeset
|
551 octave::load_path& lp |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27210
diff
changeset
|
552 = octave::__get_load_path__ ("octave_fcn_handle::set_fcn"); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
553 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
554 octave::directory_path p (lp.system_path ()); |
6625 | 555 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
556 str = octave::sys::env::make_absolute (p.find_first_of (names)); |
6625 | 557 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
558 size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
6625 | 559 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
560 std::string dir_name = str.substr (0, xpos); |
7336 | 561 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
562 octave_value ov_fcn |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
563 = octave::load_fcn_from_file (str, dir_name, "", "", m_name); |
4989 | 564 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
565 if (ov_fcn.is_undefined ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
566 error ("function handle points to non-existent function"); |
6625 | 567 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
568 m_fcn = octave_value (new octave_fcn_handle (ov_fcn, m_name)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
569 } |
6625 | 570 } |
571 else | |
572 { | |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
573 if (fpath.length () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
574 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
575 size_t xpos = fpath.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
6625 | 576 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
577 std::string dir_name = fpath.substr (0, xpos); |
7336 | 578 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
579 octave_value ov_fcn |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
580 = octave::load_fcn_from_file (fpath, dir_name, "", "", m_name); |
6625 | 581 |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
582 if (ov_fcn.is_undefined ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
583 error ("function handle points to non-existent function"); |
6625 | 584 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
585 m_fcn = octave_value (new octave_fcn_handle (ov_fcn, m_name)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
586 } |
6625 | 587 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
588 { |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23653
diff
changeset
|
589 octave::symbol_table& symtab |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
590 = octave::__get_symbol_table__ ("octave_fcn_handle::set_fcn"); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
591 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
592 m_fcn = symtab.find_function (m_name); |
7336 | 593 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
594 if (! m_fcn.is_function ()) |
20953
758b71e964ce
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
595 error ("function handle points to non-existent function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
596 } |
6625 | 597 } |
598 | |
21124
95f8c8cdbffe
maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
599 return true; |
6625 | 600 } |
601 | |
25969
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
602 octave_value |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
603 octave_fcn_handle::convert_to_str_internal (bool, bool, char type) const |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
604 { |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
605 std::ostringstream buf; |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
606 print_raw (buf, true); |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
607 return octave_value (buf.str (), type); |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
608 } |
7eeb89b0d2d5
make char function work for function handles (bug #53118)
John W. Eaton <jwe@octave.org>
parents:
25824
diff
changeset
|
609 |
6625 | 610 bool |
6974 | 611 octave_fcn_handle::save_ascii (std::ostream& os) |
6625 | 612 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
613 if (m_name == anonymous) |
4988 | 614 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
615 if (m_fcn.is_undefined ()) |
25824
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
25803
diff
changeset
|
616 return false; |
91e1ca0e3a9d
Save all scopes of nested anonymous functions (bug #45969).
Olaf Till <i7tiol@t-online.de>
parents:
25803
diff
changeset
|
617 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
618 os << m_name << "\n"; |
6625 | 619 |
4989 | 620 print_raw (os, true); |
621 os << "\n"; | |
6625 | 622 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
623 size_t varlen = m_local_vars ? m_local_vars->size () : 0; |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
624 |
6625 | 625 if (varlen > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
626 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
627 os << "# length: " << varlen << "\n"; |
6625 | 628 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
629 for (const auto& nm_val : *m_local_vars) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
630 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
631 if (! save_text_data (os, nm_val.second, nm_val.first, 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
|
632 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
633 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
634 } |
6625 | 635 } |
636 else | |
637 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
638 octave_function *f = function_value (); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
639 std::string fnm = (f ? f->fcn_file_name () : ""); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
640 |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
641 os << "# octaveroot: " << octave::config::octave_exec_home () << "\n"; |
15005
74c7265c057a
fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents:
15004
diff
changeset
|
642 if (! fnm.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
643 os << "# path: " << fnm << "\n"; |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
644 os << m_name << "\n"; |
4988 | 645 } |
646 | |
647 return true; | |
648 } | |
649 | |
650 bool | |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
651 octave_fcn_handle::parse_anon_fcn_handle (const std::string& fcn_text) |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
652 { |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
653 bool success = true; |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
654 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
655 octave::interpreter& interp |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
656 = octave::__get_interpreter__ ("octave_fcn_handle::parse_anon_fcn_handle"); |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
657 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
658 int parse_status; |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
659 octave_value anon_fcn_handle |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
660 = interp.eval_string (fcn_text, true, parse_status); |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
661 |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
662 if (parse_status == 0) |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
663 { |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
664 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
665 |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
666 if (fh) |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
667 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
668 m_fcn = fh->m_fcn; |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
669 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
670 if (fh->m_local_vars) |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
671 m_local_vars = new octave::stack_frame::local_vars_map (*(fh->m_local_vars)); |
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
672 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
673 octave_user_function *uf = m_fcn.user_function_value (true); |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
674 |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
675 if (uf) |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
676 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
677 octave::symbol_scope uf_scope = uf->scope (); |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
678 |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
679 if (uf_scope) |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
680 uf_scope.cache_name (m_name); |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
681 } |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
682 } |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
683 else |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
684 success = false; |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
685 } |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
686 else |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
687 success = false; |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
688 |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
689 return success; |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
690 } |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
691 |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
692 bool |
4988 | 693 octave_fcn_handle::load_ascii (std::istream& is) |
694 { | |
6625 | 695 bool success = true; |
696 | |
697 std::streampos pos = is.tellg (); | |
698 std::string octaveroot = extract_keyword (is, "octaveroot", true); | |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21867
diff
changeset
|
699 if (octaveroot.empty ()) |
6625 | 700 { |
701 is.seekg (pos); | |
702 is.clear (); | |
703 } | |
704 pos = is.tellg (); | |
705 std::string fpath = extract_keyword (is, "path", true); | |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21867
diff
changeset
|
706 if (fpath.empty ()) |
6625 | 707 { |
708 is.seekg (pos); | |
709 is.clear (); | |
710 } | |
711 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
712 is >> m_name; |
4989 | 713 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
714 if (m_name == anonymous) |
4988 | 715 { |
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
|
716 skip_preceeding_newline (is); |
4988 | 717 |
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
|
718 std::string buf; |
4988 | 719 |
720 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
721 { |
4988 | 722 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
723 // 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
|
724 // newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
725 buf = read_until_newline (is, true); |
4989 | 726 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
727 } |
4988 | 728 |
6625 | 729 pos = is.tellg (); |
7336 | 730 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
731 octave::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
|
732 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
733 // 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
|
734 // 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
|
735 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
736 octave::interpreter& interp |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
737 = octave::__get_interpreter__ ("octave_fcn_handle::load_ascii"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
738 |
27001
3cea1cfb37d3
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
26966
diff
changeset
|
739 octave::tree_evaluator& tw = interp.get_evaluator (); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
740 |
27001
3cea1cfb37d3
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
26966
diff
changeset
|
741 tw.push_dummy_scope (buf); |
3cea1cfb37d3
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
26966
diff
changeset
|
742 frame.add_method (tw, &octave::tree_evaluator::pop_scope); |
4988 | 743 |
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
|
744 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
|
745 |
6625 | 746 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
|
747 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
748 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
749 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
750 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
|
751 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
752 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
753 bool dummy; |
6625 | 754 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
755 std::string name |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
756 = read_text_data (is, "", dummy, t2, i); |
6625 | 757 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20953
diff
changeset
|
758 if (! is) |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
759 error ("load: failed to load anonymous function handle"); |
6625 | 760 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
761 interp.assign (name, t2); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
762 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
763 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
764 } |
4989 | 765 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
766 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
767 is.seekg (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
768 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
769 } |
6625 | 770 |
771 if (is && success) | |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
772 success = parse_anon_fcn_handle (buf); |
6625 | 773 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
774 success = false; |
4988 | 775 } |
776 else | |
6625 | 777 success = set_fcn (octaveroot, fpath); |
4988 | 778 |
6625 | 779 return success; |
4988 | 780 } |
781 | |
782 bool | |
26399
586413770c7f
pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
783 octave_fcn_handle::save_binary (std::ostream& os, bool save_as_floats) |
4988 | 784 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
785 if (m_name == anonymous) |
4988 | 786 { |
6625 | 787 std::ostringstream nmbuf; |
788 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
789 if (m_fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
790 return false; |
6625 | 791 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
792 size_t varlen = m_local_vars ? m_local_vars->size () : 0; |
6625 | 793 |
794 if (varlen > 0) | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
795 nmbuf << m_name << ' ' << varlen; |
6625 | 796 else |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
797 nmbuf << m_name; |
6625 | 798 |
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
|
799 std::string buf_str = nmbuf.str (); |
6625 | 800 int32_t tmp = buf_str.length (); |
801 os.write (reinterpret_cast<char *> (&tmp), 4); | |
802 os.write (buf_str.c_str (), buf_str.length ()); | |
803 | |
5765 | 804 std::ostringstream buf; |
4988 | 805 print_raw (buf, true); |
5765 | 806 std::string stmp = buf.str (); |
4988 | 807 tmp = stmp.length (); |
5760 | 808 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988 | 809 os.write (stmp.c_str (), stmp.length ()); |
6625 | 810 |
811 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
812 { |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
813 for (const auto& nm_val : *m_local_vars) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
814 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
815 if (! save_binary_data (os, nm_val.second, nm_val.first, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
816 "", 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
|
817 return ! os.fail (); |
10315
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 } |
6625 | 820 } |
821 else | |
822 { | |
823 std::ostringstream nmbuf; | |
824 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
825 octave_function *f = function_value (); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
826 std::string fnm = (f ? f->fcn_file_name () : ""); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
827 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
828 nmbuf << m_name << "\n" << octave::config::octave_exec_home () << "\n" << fnm; |
6625 | 829 |
830 std::string buf_str = nmbuf.str (); | |
831 int32_t tmp = buf_str.length (); | |
832 os.write (reinterpret_cast<char *> (&tmp), 4); | |
833 os.write (buf_str.c_str (), buf_str.length ()); | |
4988 | 834 } |
7336 | 835 |
4988 | 836 return true; |
837 } | |
838 | |
839 bool | |
840 octave_fcn_handle::load_binary (std::istream& is, bool swap, | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
841 octave::mach_info::float_format fmt) |
4988 | 842 { |
6625 | 843 bool success = true; |
7336 | 844 |
5828 | 845 int32_t tmp; |
5760 | 846 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 847 return false; |
848 if (swap) | |
849 swap_bytes<4> (&tmp); | |
850 | |
851 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
|
852 // 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
|
853 // 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
|
854 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
|
855 ctmp1[tmp] = 0; |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
856 m_name = std::string (ctmp1); |
4988 | 857 |
858 if (! is) | |
859 return false; | |
860 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
861 size_t anl = anonymous.length (); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
862 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
863 if (m_name.length () >= anl && m_name.substr (0, anl) == anonymous) |
4988 | 864 { |
6625 | 865 octave_idx_type len = 0; |
866 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
867 if (m_name.length () > anl) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
868 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
869 std::istringstream nm_is (m_name.substr (anl)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
870 nm_is >> len; |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
871 m_name = m_name.substr (0, anl); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
872 } |
6625 | 873 |
5760 | 874 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
|
875 return false; |
4988 | 876 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
877 swap_bytes<4> (&tmp); |
4988 | 878 |
879 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
|
880 // 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
|
881 // 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
|
882 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
|
883 ctmp2[tmp] = 0; |
4988 | 884 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
885 octave::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
|
886 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
887 // 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
|
888 // 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
|
889 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
890 octave::interpreter& interp |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
891 = octave::__get_interpreter__ ("octave_fcn_handle::load_binary"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
892 |
27001
3cea1cfb37d3
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
26966
diff
changeset
|
893 octave::tree_evaluator& tw = interp.get_evaluator (); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
894 |
27001
3cea1cfb37d3
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
26966
diff
changeset
|
895 tw.push_dummy_scope (ctmp2); |
3cea1cfb37d3
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
26966
diff
changeset
|
896 frame.add_method (tw, &octave::tree_evaluator::pop_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
897 |
6625 | 898 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
900 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
|
901 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
902 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
903 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
904 std::string doc; |
6625 | 905 |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27210
diff
changeset
|
906 std::string name |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27210
diff
changeset
|
907 = read_binary_data (is, swap, fmt, "", dummy, t2, doc); |
6625 | 908 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20953
diff
changeset
|
909 if (! is) |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
910 error ("load: failed to load anonymous function handle"); |
6625 | 911 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
912 interp.assign (name, t2); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
913 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
914 } |
6625 | 915 |
916 if (is && success) | |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
917 success = parse_anon_fcn_handle (ctmp2); |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
918 else |
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
919 success = false; |
4988 | 920 } |
921 else | |
922 { | |
6625 | 923 std::string octaveroot; |
924 std::string fpath; | |
925 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
926 if (m_name.find_first_of ('\n') != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
927 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
928 size_t pos1 = m_name.find_first_of ('\n'); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
929 size_t pos2 = m_name.find_first_of ('\n', pos1 + 1); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
930 octaveroot = m_name.substr (pos1 + 1, pos2 - pos1 - 1); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
931 fpath = m_name.substr (pos2 + 1); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
932 m_name = m_name.substr (0, pos1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
933 } |
6625 | 934 |
935 success = set_fcn (octaveroot, fpath); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
936 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
937 |
12714
65b7ce254ba3
Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents:
12483
diff
changeset
|
938 return success; |
4988 | 939 } |
940 | |
941 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
942 octave_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
943 bool save_as_floats) |
4988 | 944 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
945 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
946 |
7336 | 947 bool retval = true; |
948 | |
4988 | 949 hid_t group_hid = -1; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
950 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
951 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
952 octave_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
|
953 #else |
4988 | 954 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
|
955 #endif |
7336 | 956 if (group_hid < 0) |
957 return false; | |
4988 | 958 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
959 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
|
960 space_hid = data_hid = type_hid = -1; |
4988 | 961 |
962 // attach the type of the variable | |
963 type_hid = H5Tcopy (H5T_C_S1); | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
964 H5Tset_size (type_hid, m_name.length () + 1); |
4988 | 965 if (type_hid < 0) |
966 { | |
967 H5Gclose (group_hid); | |
968 return false; | |
969 } | |
970 | |
971 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
972 hdims[0] = 0; | |
973 hdims[1] = 0; | |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
974 space_hid = H5Screate_simple (0, hdims, nullptr); |
4988 | 975 if (space_hid < 0) |
976 { | |
977 H5Tclose (type_hid); | |
978 H5Gclose (group_hid); | |
979 return false; | |
980 } | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
981 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
982 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
983 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
984 octave_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
|
985 #else |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
986 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
987 octave_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
|
988 #endif |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
989 if (data_hid < 0 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
990 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
991 octave_H5P_DEFAULT, m_name.c_str ()) < 0) |
4988 | 992 { |
993 H5Sclose (space_hid); | |
994 H5Tclose (type_hid); | |
995 H5Gclose (group_hid); | |
996 return false; | |
997 } | |
998 H5Dclose (data_hid); | |
999 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
1000 if (m_name == anonymous) |
4988 | 1001 { |
5765 | 1002 std::ostringstream buf; |
4988 | 1003 print_raw (buf, true); |
5765 | 1004 std::string stmp = buf.str (); |
4988 | 1005 |
1006 // attach the type of the variable | |
1007 H5Tset_size (type_hid, stmp.length () + 1); | |
1008 if (type_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1009 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1010 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1011 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1012 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1013 } |
4988 | 1014 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1015 #if defined (HAVE_HDF5_18) |
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
|
1016 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1017 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1018 octave_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
|
1019 #else |
4988 | 1020 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1021 octave_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
|
1022 #endif |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1023 if (data_hid < 0 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1024 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1025 octave_H5P_DEFAULT, stmp.c_str ()) < 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 |
1033 H5Dclose (data_hid); | |
6625 | 1034 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
1035 size_t varlen = m_local_vars ? m_local_vars->size () : 0; |
6625 | 1036 |
1037 if (varlen > 0) | |
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 hid_t as_id = H5Screate (H5S_SCALAR); |
6625 | 1040 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1041 if (as_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1042 { |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1043 #if defined (HAVE_HDF5_18) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1044 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
|
1045 H5T_NATIVE_IDX, as_id, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1046 octave_H5P_DEFAULT, octave_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
|
1047 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1048 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1049 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1050 H5T_NATIVE_IDX, as_id, octave_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
|
1051 #endif |
6625 | 1052 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1053 if (a_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1054 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1055 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); |
6625 | 1056 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1057 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1058 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1059 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1060 retval = false; |
6625 | 1061 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1062 H5Sclose (as_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1063 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1064 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1065 retval = false; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1066 #if defined (HAVE_HDF5_18) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1067 data_hid = H5Gcreate (group_hid, "symbol table", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1068 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
1069 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1070 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
|
1071 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1072 if (data_hid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1073 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1074 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1075 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1076 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1077 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1078 } |
6625 | 1079 |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
1080 for (const auto& nm_val : *m_local_vars) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1081 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
1082 if (! add_hdf5_data (data_hid, nm_val.second, nm_val.first, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
1083 "", false, save_as_floats)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1084 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1085 } |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
1086 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1087 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1088 } |
6625 | 1089 } |
1090 else | |
1091 { | |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1092 std::string octaveroot = octave::config::octave_exec_home (); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1093 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1094 octave_function *f = function_value (); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
1095 std::string fpath = (f ? f->fcn_file_name () : ""); |
6625 | 1096 |
1097 H5Sclose (space_hid); | |
1098 hdims[0] = 1; | |
1099 hdims[1] = octaveroot.length (); | |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
1100 space_hid = H5Screate_simple (0, hdims, nullptr); |
6625 | 1101 if (space_hid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1102 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1103 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1104 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1105 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1106 } |
6625 | 1107 |
1108 H5Tclose (type_hid); | |
1109 type_hid = H5Tcopy (H5T_C_S1); | |
1110 H5Tset_size (type_hid, octaveroot.length () + 1); | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1111 #if defined (HAVE_HDF5_18) |
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
|
1112 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1113 type_hid, space_hid, octave_H5P_DEFAULT, octave_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
|
1114 #else |
6625 | 1115 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1116 type_hid, space_hid, octave_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
|
1117 #endif |
6625 | 1118 |
1119 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1120 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1121 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); |
6625 | 1122 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1123 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1124 } |
6625 | 1125 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1126 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1127 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1128 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1129 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1130 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1131 } |
6625 | 1132 |
1133 H5Sclose (space_hid); | |
1134 hdims[0] = 1; | |
1135 hdims[1] = fpath.length (); | |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
1136 space_hid = H5Screate_simple (0, hdims, nullptr); |
6625 | 1137 if (space_hid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1138 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1139 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1140 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1141 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1142 } |
6625 | 1143 |
1144 H5Tclose (type_hid); | |
1145 type_hid = H5Tcopy (H5T_C_S1); | |
1146 H5Tset_size (type_hid, fpath.length () + 1); | |
1147 | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1148 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1149 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1150 octave_H5P_DEFAULT, octave_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
|
1151 #else |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1152 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, octave_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
|
1153 #endif |
6625 | 1154 |
1155 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1156 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1157 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); |
6625 | 1158 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1159 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1160 } |
6625 | 1161 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1162 retval = false; |
4988 | 1163 } |
1164 | |
1165 H5Sclose (space_hid); | |
1166 H5Tclose (type_hid); | |
1167 H5Gclose (group_hid); | |
1168 | |
1169 return retval; | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1170 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1171 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1172 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1173 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1174 octave_unused_parameter (save_as_floats); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1175 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1176 warn_save ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1177 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1178 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1179 #endif |
4988 | 1180 } |
1181 | |
1182 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1183 octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4988 | 1184 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1185 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1186 |
7336 | 1187 bool success = true; |
1188 | |
4988 | 1189 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
1190 hsize_t rank; | |
1191 int slen; | |
1192 | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1193 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1194 group_hid = H5Gopen (loc_id, name, octave_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
|
1195 #else |
4988 | 1196 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
|
1197 #endif |
7336 | 1198 if (group_hid < 0) |
1199 return false; | |
4988 | 1200 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1201 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1202 data_hid = H5Dopen (group_hid, "nm", octave_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
|
1203 #else |
4988 | 1204 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
|
1205 #endif |
4988 | 1206 |
1207 if (data_hid < 0) | |
1208 { | |
1209 H5Gclose (group_hid); | |
1210 return false; | |
1211 } | |
1212 | |
1213 type_hid = H5Dget_type (data_hid); | |
1214 type_class_hid = H5Tget_class (type_hid); | |
1215 | |
1216 if (type_class_hid != H5T_STRING) | |
1217 { | |
1218 H5Tclose (type_hid); | |
1219 H5Dclose (data_hid); | |
1220 H5Gclose (group_hid); | |
1221 return false; | |
1222 } | |
1223 | |
1224 space_hid = H5Dget_space (data_hid); | |
1225 rank = H5Sget_simple_extent_ndims (space_hid); | |
1226 | |
1227 if (rank != 0) | |
1228 { | |
1229 H5Sclose (space_hid); | |
1230 H5Tclose (type_hid); | |
1231 H5Dclose (data_hid); | |
1232 H5Gclose (group_hid); | |
1233 return false; | |
1234 } | |
1235 | |
1236 slen = H5Tget_size (type_hid); | |
1237 if (slen < 0) | |
1238 { | |
1239 H5Sclose (space_hid); | |
1240 H5Tclose (type_hid); | |
1241 H5Dclose (data_hid); | |
1242 H5Gclose (group_hid); | |
1243 return false; | |
1244 } | |
1245 | |
1246 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
1247 | |
1248 // create datatype for (null-terminated) string to read into: | |
1249 st_id = H5Tcopy (H5T_C_S1); | |
1250 H5Tset_size (st_id, slen); | |
1251 | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1252 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1253 octave_H5P_DEFAULT, nm_tmp) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1254 < 0) |
4988 | 1255 { |
6695 | 1256 H5Tclose (st_id); |
4988 | 1257 H5Sclose (space_hid); |
1258 H5Tclose (type_hid); | |
6695 | 1259 H5Dclose (data_hid); |
4988 | 1260 H5Gclose (group_hid); |
1261 return false; | |
1262 } | |
1263 H5Tclose (st_id); | |
1264 H5Dclose (data_hid); | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
1265 m_name = nm_tmp; |
4988 | 1266 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
1267 if (m_name == anonymous) |
4988 | 1268 { |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1269 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1270 data_hid = H5Dopen (group_hid, "fcn", octave_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
|
1271 #else |
4988 | 1272 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
|
1273 #endif |
4988 | 1274 |
1275 if (data_hid < 0) | |
10315
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 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1278 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1279 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1280 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1281 } |
4988 | 1282 |
6695 | 1283 H5Tclose (type_hid); |
4988 | 1284 type_hid = H5Dget_type (data_hid); |
1285 type_class_hid = H5Tget_class (type_hid); | |
1286 | |
1287 if (type_class_hid != H5T_STRING) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1288 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1289 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1290 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1291 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1292 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1293 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1294 } |
4988 | 1295 |
6695 | 1296 H5Sclose (space_hid); |
4988 | 1297 space_hid = H5Dget_space (data_hid); |
1298 rank = H5Sget_simple_extent_ndims (space_hid); | |
1299 | |
1300 if (rank != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1301 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1302 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1303 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1304 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1305 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1306 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1307 } |
4988 | 1308 |
1309 slen = H5Tget_size (type_hid); | |
1310 if (slen < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1311 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1312 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1313 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1314 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1315 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1316 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1317 } |
4988 | 1318 |
1319 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); | |
1320 | |
1321 // create datatype for (null-terminated) string to read into: | |
1322 st_id = H5Tcopy (H5T_C_S1); | |
1323 H5Tset_size (st_id, slen); | |
1324 | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1325 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1326 octave_H5P_DEFAULT, fcn_tmp) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1327 < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1328 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1329 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1330 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1331 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1332 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1333 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1334 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1335 } |
6695 | 1336 H5Tclose (st_id); |
4988 | 1337 H5Dclose (data_hid); |
6625 | 1338 |
1339 octave_idx_type len = 0; | |
1340 | |
1341 // we have to pull some shenanigans here to make sure | |
1342 // HDF5 doesn't print out all sorts of error messages if we | |
1343 // call H5Aopen for a non-existing attribute | |
1344 | |
1345 H5E_auto_t err_func; | |
1346 void *err_func_data; | |
4988 | 1347 |
6625 | 1348 // turn off error reporting temporarily, but save the error |
1349 // reporting function: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1350 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1351 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data); |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1352 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr); |
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
|
1353 #else |
6625 | 1354 H5Eget_auto (&err_func, &err_func_data); |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1355 H5Eset_auto (nullptr, nullptr); |
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
|
1356 #endif |
6625 | 1357 |
1358 hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); | |
4988 | 1359 |
6625 | 1360 if (attr_id >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1361 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1362 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
|
1363 success = false; |
6625 | 1364 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1365 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1366 } |
6625 | 1367 |
1368 // restore error reporting: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1369 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1370 H5Eset_auto (octave_H5E_DEFAULT, 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
|
1371 #else |
6625 | 1372 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
|
1373 #endif |
6625 | 1374 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
1375 octave::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
|
1376 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1377 // 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
|
1378 // 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
|
1379 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
1380 octave::interpreter& interp |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
1381 = octave::__get_interpreter__ ("octave_fcn_handle::load_hdf5"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
1382 |
27004
b12d5ef8b4f4
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
27001
diff
changeset
|
1383 octave::tree_evaluator& tw = interp.get_evaluator (); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1384 |
27004
b12d5ef8b4f4
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
27001
diff
changeset
|
1385 tw.push_dummy_scope (fcn_tmp); |
b12d5ef8b4f4
move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents:
27001
diff
changeset
|
1386 frame.add_method (tw, &octave::tree_evaluator::pop_scope); |
7336 | 1387 |
6625 | 1388 if (len > 0 && success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1389 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1390 hsize_t num_obj = 0; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1391 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1392 data_hid = H5Gopen (group_hid, "symbol table", octave_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
|
1393 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1394 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
|
1395 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1396 H5Gget_num_objs (data_hid, &num_obj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1397 H5Gclose (data_hid); |
6625 | 1398 |
25688
b2917b7858ba
maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents:
25460
diff
changeset
|
1399 if (num_obj != static_cast<hsize_t> (len)) |
20953
758b71e964ce
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
1400 error ("load: failed to load anonymous function handle"); |
6625 | 1401 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1402 hdf5_callback_data dsub; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1403 int current_item = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1404 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1405 { |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
21966
diff
changeset
|
1406 if (hdf5_h5g_iterate (group_hid, "symbol table", ¤t_item, |
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
21966
diff
changeset
|
1407 &dsub) <= 0) |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1408 error ("load: failed to load anonymous function handle"); |
6625 | 1409 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26466
diff
changeset
|
1410 interp.assign (dsub.name, dsub.tc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1411 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1412 } |
6625 | 1413 |
1414 if (success) | |
24108
1a53f0c855db
move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents:
23829
diff
changeset
|
1415 success = parse_anon_fcn_handle (fcn_tmp); |
4988 | 1416 } |
1417 else | |
1418 { | |
6625 | 1419 std::string octaveroot; |
1420 std::string fpath; | |
1421 | |
1422 // we have to pull some shenanigans here to make sure | |
1423 // HDF5 doesn't print out all sorts of error messages if we | |
1424 // call H5Aopen for a non-existing attribute | |
1425 | |
1426 H5E_auto_t err_func; | |
1427 void *err_func_data; | |
1428 | |
1429 // turn off error reporting temporarily, but save the error | |
1430 // reporting function: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1431 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1432 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data); |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1433 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr); |
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
|
1434 #else |
6625 | 1435 H5Eget_auto (&err_func, &err_func_data); |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1436 H5Eset_auto (nullptr, nullptr); |
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
|
1437 #endif |
6625 | 1438 |
1439 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); | |
1440 if (attr_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1441 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1442 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1443 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1444 type_class_hid = H5Tget_class (type_hid); |
6625 | 1445 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1446 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1447 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1448 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1449 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1450 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1451 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1452 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1453 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); |
6625 | 1454 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1455 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
|
1456 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1457 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1458 octaveroot = root_tmp; |
6695 | 1459 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1460 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1461 } |
6625 | 1462 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1463 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1464 } |
6625 | 1465 |
6695 | 1466 if (success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1468 attr_id = H5Aopen_name (group_hid, "FILE"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1469 if (attr_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1470 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1471 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1472 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1473 type_class_hid = H5Tget_class (type_hid); |
6625 | 1474 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1475 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1476 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1477 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1478 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1479 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1480 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1481 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1482 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); |
6695 | 1483 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1484 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
|
1485 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1486 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1487 fpath = path_tmp; |
6695 | 1488 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1489 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1490 } |
6695 | 1491 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1492 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1493 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1494 } |
6625 | 1495 |
1496 // restore error reporting: | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1497 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1498 H5Eset_auto (octave_H5E_DEFAULT, 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
|
1499 #else |
6625 | 1500 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
|
1501 #endif |
6625 | 1502 |
1503 success = (success ? set_fcn (octaveroot, fpath) : success); | |
4988 | 1504 } |
1505 | |
6695 | 1506 H5Tclose (type_hid); |
1507 H5Sclose (space_hid); | |
1508 H5Gclose (group_hid); | |
1509 | |
6625 | 1510 return success; |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1511 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1512 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1513 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1514 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1515 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1516 warn_load ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
1517 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1518 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1519 #endif |
4988 | 1520 } |
6625 | 1521 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11541
diff
changeset
|
1522 /* |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1523 %!test <*33857> |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1524 %! a = 2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1525 %! f = @(x) a + x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1526 %! 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
|
1527 %! hm = @version; |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
1528 %! hdld = @svd; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1529 %! hbi = @log2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1530 %! f2 = f; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1531 %! g2 = g; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1532 %! hm2 = hm; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1533 %! hdld2 = hdld; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1534 %! hbi2 = hbi; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1535 %! modes = {"-text", "-binary"}; |
21434
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1536 %! if (isfield (__octave_config_info__, "HAVE_HDF5") |
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1537 %! && __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
|
1538 %! modes(end+1) = "-hdf5"; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1539 %! endif |
7901 | 1540 %! for i = 1:numel (modes) |
1541 %! mode = modes{i}; | |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1542 %! nm = tempname (); |
6625 | 1543 %! unwind_protect |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22417
diff
changeset
|
1544 %! f2 (1); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1545 %! 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
|
1546 %! clear f2 g2 hm2 hdld2 hbi2 |
6625 | 1547 %! load (nm); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1548 %! assert (f (2), f2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1549 %! assert (g (2), g2 (2)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
1550 %! assert (g (3), g2 (3)); |
6625 | 1551 %! unlink (nm); |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1552 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
6625 | 1553 %! unwind_protect_cleanup |
1554 %! unlink (nm); | |
1555 %! end_unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1556 %! endfor |
6625 | 1557 */ |
4988 | 1558 |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1559 /* |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1560 %!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
|
1561 %! if (n == 0) |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1562 %! 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
|
1563 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1564 %! 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
|
1565 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1566 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1567 %!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
|
1568 %! if (n == 0) |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
1569 %! load (nm); |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1570 %! else |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1571 %! [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
|
1572 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1573 %!endfunction |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1574 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1575 %!test <*35876> |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1576 %! a = 2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1577 %! f = @(x) a + x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1578 %! g = @(x) 2 * x; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1579 %! hm = @version; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1580 %! hdld = @svd; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1581 %! hbi = @log2; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1582 %! f2 = f; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1583 %! g2 = g; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1584 %! hm2 = hm; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1585 %! hdld2 = hdld; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1586 %! hbi2 = hbi; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1587 %! modes = {"-text", "-binary"}; |
21434
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1588 %! if (isfield (__octave_config_info__, "HAVE_HDF5") |
1da428cbf401
deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1589 %! && __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
|
1590 %! modes(end+1) = "-hdf5"; |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1591 %! endif |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1592 %! for i = 1:numel (modes) |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1593 %! mode = modes{i}; |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1594 %! nm = tempname (); |
15235
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1595 %! unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1596 %! 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
|
1597 %! 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
|
1598 %! [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
|
1599 %! load (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1600 %! assert (f (2), f2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1601 %! assert (g (2), g2 (2)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1602 %! assert (g (3), g2 (3)); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1603 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1604 %! 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
|
1605 %! unwind_protect_cleanup |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1606 %! unlink (nm); |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1607 %! end_unwind_protect |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1608 %! endfor |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1609 */ |
ab3d4c1affee
Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
1610 |
4343 | 1611 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
1612 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) |
4343 | 1613 { |
1614 print_raw (os, pr_as_read_syntax); | |
1615 newline (os); | |
1616 } | |
1617 | |
1618 void | |
1619 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1620 { | |
4980 | 1621 bool printed = false; |
1622 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
1623 if (m_name == anonymous) |
4980 | 1624 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1625 octave::tree_print_code tpc (os); |
4980 | 1626 |
4989 | 1627 // FCN is const because this member function is, so we can't |
4980 | 1628 // use it to call user_function_value, so we make a copy first. |
1629 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
1630 octave_value ftmp = m_fcn; |
4980 | 1631 |
1632 octave_user_function *f = ftmp.user_function_value (); | |
1633 | |
1634 if (f) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1635 { |
28257
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1636 os << "@"; |
4980 | 1637 |
28257
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1638 // The parameter list should always be valid for anonymous |
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1639 // functions, so we should always call accept for it, and it |
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1640 // will print the parens for us. |
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1641 |
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1642 octave::tree_parameter_list *p = f->parameter_list (); |
4980 | 1643 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1644 if (p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1645 p->accept (tpc); |
4980 | 1646 |
28257
ae94e3fad6d4
fix printing of functions with varargin/varargout (bug #58279)
John W. Eaton <jwe@octave.org>
parents:
27975
diff
changeset
|
1647 os << " "; |
4980 | 1648 |
23600
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1649 octave::tree_statement_list *b = f->body (); |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1650 |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1651 assert (b->length () == 1); |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1652 |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1653 octave::tree_statement *s = b->front (); |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1654 |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1655 if (s) |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1656 { |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1657 assert (s->is_expression ()); |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1658 |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1659 octave::tree_expression *e = s->expression (); |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1660 |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1661 if (e) |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1662 tpc.print_fcn_handle_body (e); |
db947ba52118
explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
1663 } |
4980 | 1664 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1665 printed = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1666 } |
4980 | 1667 } |
1668 | |
1669 if (! printed) | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
1670 octave_print_internal (os, '@' + m_name, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1671 current_print_indent_level ()); |
4343 | 1672 } |
1673 | |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1674 namespace octave |
4343 | 1675 { |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1676 // Hmm, should this function be a member of the interpreter class, |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1677 // possibly forwarded to an actual implementation in the |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1678 // tree_evaluator class? |
4343 | 1679 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1680 octave_value |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1681 make_fcn_handle (interpreter& interp, const std::string& nm) |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1682 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1683 octave_value retval; |
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
|
1684 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1685 // Bow to the god of compatibility. |
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
|
1686 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1687 // FIXME: it seems ugly to put this here, but there is no single |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1688 // function in the parser that converts from the operator name to |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1689 // the corresponding function name. At least try to do it without N |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1690 // string compares. |
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
|
1691 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1692 std::string tnm = nm; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1693 |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1694 size_t len = nm.length (); |
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
|
1695 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1696 if (len == 3 && nm == ".**") |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1697 tnm = "power"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1698 else if (len == 2) |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1699 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1700 if (nm[0] == '.') |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1701 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1702 switch (nm[1]) |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1703 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1704 case '\'': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1705 tnm = "transpose"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1706 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
|
1707 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1708 case '+': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1709 tnm = "plus"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1710 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
|
1711 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1712 case '-': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1713 tnm = "minus"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1714 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
|
1715 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1716 case '*': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1717 tnm = "times"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1718 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
|
1719 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1720 case '/': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1721 tnm = "rdivide"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1722 break; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1723 |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1724 case '^': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1725 tnm = "power"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1726 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
|
1727 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1728 case '\\': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1729 tnm = "ldivide"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1730 break; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1731 } |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1732 } |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1733 else if (nm[1] == '=') |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1734 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1735 switch (nm[0]) |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1736 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1737 case '<': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1738 tnm = "le"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1739 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
|
1740 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1741 case '=': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1742 tnm = "eq"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1743 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
|
1744 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1745 case '>': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1746 tnm = "ge"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1747 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
|
1748 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1749 case '~': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1750 case '!': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1751 tnm = "ne"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1752 break; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1753 } |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1754 } |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1755 else if (nm == "**") |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1756 tnm = "mpower"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1757 } |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1758 else if (len == 1) |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1759 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1760 switch (nm[0]) |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1761 { |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1762 case '~': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1763 case '!': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1764 tnm = "not"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1765 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
|
1766 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1767 case '\'': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1768 tnm = "ctranspose"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1769 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
|
1770 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1771 case '+': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1772 tnm = "plus"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1773 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
|
1774 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1775 case '-': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1776 tnm = "minus"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1777 break; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1778 |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1779 case '*': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1780 tnm = "mtimes"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1781 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
|
1782 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1783 case '/': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1784 tnm = "mrdivide"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1785 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
|
1786 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1787 case '^': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1788 tnm = "mpower"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1789 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
|
1790 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1791 case '\\': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1792 tnm = "mldivide"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1793 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
|
1794 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1795 case '<': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1796 tnm = "lt"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1797 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
|
1798 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1799 case '>': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1800 tnm = "gt"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1801 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
|
1802 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1803 case '&': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1804 tnm = "and"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1805 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
|
1806 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1807 case '|': |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1808 tnm = "or"; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1809 break; |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1810 } |
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1811 } |
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
|
1812 |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1813 tree_evaluator& tw = interp.get_evaluator (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
1814 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27004
diff
changeset
|
1815 symbol_scope curr_scope = tw.get_current_scope (); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20957
diff
changeset
|
1816 |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1817 octave_fcn_handle *fh = new octave_fcn_handle (curr_scope, tnm); |
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1818 |
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1819 std::string dispatch_class; |
4343 | 1820 |
27210
bd684aad1821
eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
1821 if (tw.is_class_method_executing (dispatch_class) |
bd684aad1821
eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
1822 || tw.is_class_constructor_executing (dispatch_class)) |
26966
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1823 fh->set_dispatch_class (dispatch_class); |
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1824 |
4ba365817652
allow dispatch class to be stored in octave_fcn_handle (bug #45351)
John W. Eaton <jwe@octave.org>
parents:
26962
diff
changeset
|
1825 return octave_value (fh); |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1826 } |
4343 | 1827 } |
1828 | |
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
|
1829 /* |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1830 %!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
|
1831 %! 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
|
1832 %! ".'", "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
|
1833 %! ".+", "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
|
1834 %! ".-", "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
|
1835 %! ".*", "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
|
1836 %! "./", "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
|
1837 %! ".^", "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
|
1838 %! ".\\", "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
|
1839 %! "<=", "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
|
1840 %! "==", "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
|
1841 %! ">=", "ge"; |
27975
6931d95d1967
Use "!=" in preference to "~=" everywhere in code.
Rik <rik@octave.org>
parents:
27932
diff
changeset
|
1842 %! "!=", "ne"; |
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
|
1843 %! "~=", "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
|
1844 %! "**", "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
|
1845 %! "~", "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
|
1846 %! "!", "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
|
1847 %! "\'", "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
|
1848 %! "+", "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
|
1849 %! "-", "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
|
1850 %! "*", "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
|
1851 %! "/", "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
|
1852 %! "^", "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
|
1853 %! "\\", "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
|
1854 %! "<", "lt"; |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1855 %! ">", "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
|
1856 %! "&", "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
|
1857 %! "|", "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
|
1858 %! 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
|
1859 %! 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
|
1860 %! 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
|
1861 */ |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1862 |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1863 DEFUN (functions, args, , |
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1864 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1865 @deftypefn {} {@var{s} =} functions (@var{fcn_handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1866 Return a structure containing information about the function handle |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1867 @var{fcn_handle}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1868 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1869 The structure @var{s} always contains these three fields: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1870 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1871 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1872 @item function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1873 The function name. For an anonymous function (no name) this will be the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1874 actual function definition. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1875 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1876 @item type |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1877 Type of the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1878 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1879 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1880 @item anonymous |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1881 The function is anonymous. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1882 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1883 @item private |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1884 The function is private. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1885 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1886 @item overloaded |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1887 The function overloads an existing function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1888 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1889 @item simple |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1890 The function is a built-in or m-file function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1891 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1892 @item subfunction |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1893 The function is a subfunction within an m-file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1894 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1895 |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1896 @item nested |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1897 The function is nested. |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1898 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1899 @item file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1900 The m-file that will be called to perform the function. This field is empty |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1901 for anonymous and built-in functions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1902 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1903 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1904 In addition, some function types may return more information in additional |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1905 fields. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1906 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1907 @strong{Warning:} @code{functions} is provided for debugging purposes only. |
22982
aca714a80cfc
doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
1908 Its behavior may change in the future and programs should not depend on any |
aca714a80cfc
doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
1909 particular output format. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1910 |
22982
aca714a80cfc
doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
1911 @seealso{func2str, str2func} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1912 @end deftypefn */) |
4343 | 1913 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1914 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1915 print_usage (); |
4343 | 1916 |
26367
4aebddba871c
ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26294
diff
changeset
|
1917 octave_fcn_handle *fh = args(0).xfcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object"); |
4649 | 1918 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23717
diff
changeset
|
1919 octave_function *fcn = (fh ? fh->function_value () : nullptr); |
4933 | 1920 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1921 if (! fcn) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1922 error ("functions: FCN_HANDLE is not a valid function handle object"); |
4343 | 1923 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1924 octave_scalar_map m; |
4933 | 1925 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1926 std::string fh_nm = fh->fcn_name (); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1927 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1928 if (fh_nm == octave_fcn_handle::anonymous) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1929 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1930 std::ostringstream buf; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1931 fh->print_raw (buf); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1932 m.setfield ("function", buf.str ()); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1933 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1934 m.setfield ("type", "anonymous"); |
4343 | 1935 } |
1936 else | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1937 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1938 m.setfield ("function", fh_nm); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1939 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1940 if (fcn->is_subfunction ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1941 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1942 m.setfield ("type", "subfunction"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1943 Cell parentage (dim_vector (1, 2)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1944 parentage.elem (0) = fh_nm; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1945 parentage.elem (1) = fcn->parent_fcn_name (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1946 m.setfield ("parentage", octave_value (parentage)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1947 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1948 else if (fcn->is_private_function ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1949 m.setfield ("type", "private"); |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1950 else if (fh->is_nested ()) |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1951 m.setfield ("type", "nested"); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1952 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1953 m.setfield ("type", "simple"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1954 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1955 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1956 std::string nm = fcn->fcn_file_name (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1957 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1958 if (fh_nm == octave_fcn_handle::anonymous) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1959 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1960 m.setfield ("file", nm); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1961 |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1962 m.setfield ("workspace", fh->workspace ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1963 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1964 else if (fcn->is_user_function () || fcn->is_user_script ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1965 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1966 octave_function *fu = fh->function_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1967 m.setfield ("file", fu->fcn_file_name ()); |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1968 |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26796
diff
changeset
|
1969 m.setfield ("workspace", fh->workspace ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1970 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1971 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1972 m.setfield ("file", ""); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1973 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1974 return ovl (m); |
4343 | 1975 } |
1976 | |
4933 | 1977 DEFUN (func2str, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1978 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1979 @deftypefn {} {} func2str (@var{fcn_handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1980 Return a string containing the name of the function referenced by the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1981 function handle @var{fcn_handle}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1982 @seealso{str2func, functions} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1983 @end deftypefn */) |
4343 | 1984 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1985 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1986 print_usage (); |
4930 | 1987 |
26367
4aebddba871c
ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26294
diff
changeset
|
1988 octave_fcn_handle *fh = args(0).xfcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object"); |
6416 | 1989 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1990 if (! fh) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1991 error ("func2str: FCN_HANDLE must be a valid function handle"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1992 |
4343 | 1993 octave_value retval; |
1994 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1995 std::string fh_nm = fh->fcn_name (); |
6416 | 1996 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1997 if (fh_nm == octave_fcn_handle::anonymous) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1998 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1999 std::ostringstream buf; |
6416 | 2000 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2001 fh->print_raw (buf); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2002 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2003 retval = buf.str (); |
4343 | 2004 } |
2005 else | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2006 retval = fh_nm; |
4343 | 2007 |
2008 return retval; | |
2009 } | |
2010 | |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
2011 DEFMETHOD (str2func, interp, args, , |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
2012 doc: /* -*- texinfo -*- |
26294
3c5863948bb3
doc: grammarcheck C++ and txi files.
Rik <rik@octave.org>
parents:
26119
diff
changeset
|
2013 @deftypefn {} {} str2func (@var{fcn_name}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2014 Return a function handle constructed from the string @var{fcn_name}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2015 |
26118
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2016 Previous versions of Octave accepted an optional second argument, |
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2017 @qcode{"global"}, that caused str2func to ignore locally visible |
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2018 functions. This option is no longer supported. |
22982
aca714a80cfc
doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
2019 @seealso{func2str, inline, functions} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2020 @end deftypefn */) |
4343 | 2021 { |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
2022 int nargin = args.length (); |
4343 | 2023 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2024 if (nargin < 1 || nargin > 2) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2025 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2026 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2027 std::string nm = args(0).xstring_value ("str2func: FCN_NAME must be a string"); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
2028 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2029 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2030 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2031 if (nm[0] == '@') |
4343 | 2032 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2033 int parse_status; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2034 octave_value anon_fcn_handle |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25969
diff
changeset
|
2035 = interp.eval_string (nm, true, parse_status); |
20508
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2036 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2037 if (parse_status == 0) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2038 retval = anon_fcn_handle; |
4343 | 2039 } |
2040 else | |
26118
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2041 { |
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2042 if (nargin == 2) |
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2043 warning_with_id ("Octave:str2func-global-argument", |
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2044 "str2func: second argument ignored"); |
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2045 |
26693
1da1d9e60bf3
pass reference to interpreter to make_fcn_handle function
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2046 retval = octave::make_fcn_handle (interp, nm); |
26118
7502fce4cd3a
str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
2047 } |
4343 | 2048 |
2049 return retval; | |
2050 } | |
2051 | |
2052 /* | |
20508
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2053 %!test |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2054 %! f = str2func ("<"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2055 %! assert (class (f), "function_handle"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2056 %! assert (func2str (f), "lt"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2057 %! assert (f (1, 2), true); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2058 %! assert (f (2, 1), false); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2059 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2060 %!test |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2061 %! f = str2func ("@(x) sin (x)"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2062 %! assert (func2str (f), "@(x) sin (x)"); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2063 %! assert (f (0:3), sin (0:3)); |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2064 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2065 %!error <FCN_NAME must be a string> str2func ({"sin"}) |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2066 */ |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2067 |
df7d34a1c7e6
str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents:
20501
diff
changeset
|
2068 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2069 %!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
|
2070 %! if (nargin < 3) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2071 %! n = 0; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2072 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2073 %! if (n > 2) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2074 %! y = f (x); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2075 %! else |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2076 %! n++; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
2077 %! 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
|
2078 %! endif |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2079 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2080 %! |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2081 %!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
|
2082 */ |
10960 | 2083 |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2084 DEFUN (is_function_handle, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2085 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2086 @deftypefn {} {} is_function_handle (@var{x}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2087 Return true if @var{x} is a function handle. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2088 @seealso{isa, typeinfo, class, functions} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2089 @end deftypefn */) |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2090 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
2091 if (args.length () != 1) |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2092 print_usage (); |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2093 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2094 return ovl (args(0).is_function_handle ()); |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2095 } |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2096 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2097 /* |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
2098 %!shared fh |
14175
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2099 %! fh = @(x) x; |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2100 |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2101 %!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
|
2102 %!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
|
2103 %!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
|
2104 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
2105 %!error is_function_handle () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14175
diff
changeset
|
2106 %!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
|
2107 */ |
3972c4caa60a
Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents:
14138
diff
changeset
|
2108 |
20605
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2109 /* |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2110 %!test |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2111 %! f = @(t) eval ('2*t'); |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2112 %! assert (f (21), 42); |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2113 */ |
f9c991dc5c1a
avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
2114 |
13696
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2115 /* |
28317
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2116 %!test <*58389> |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2117 %! s = "x"; |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2118 %! a.(s) = [e, pi]; |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2119 %! f = @(x) a.(s)(x); |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2120 %! assert (f(1), e); |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2121 %! assert (f(2), pi); |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2122 %! assert (f([2,1]), [pi, e]); |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2123 */ |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2124 |
ac87763b1949
capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents:
28257
diff
changeset
|
2125 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13696
diff
changeset
|
2126 %!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
|
2127 %! r = g(i); |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2128 %!endfunction |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2129 %!test |
d6118a2c0644
fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents:
13193
diff
changeset
|
2130 %! 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
|
2131 %! 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
|
2132 */ |