annotate libinterp/octave-value/ov-fcn-handle.cc @ 26958:51414d51a973

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