Mercurial > octave
annotate libinterp/octave-value/ov-usr-fcn.cc @ 30896:c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
* __eigs__.cc, bsxfun.cc, cellfun.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
debug.cc, error.cc, graphics.cc, graphics.in.h, gzfstream.h, ls-hdf5.cc,
lsode.cc, max.cc, oct-opengl.h, quad.cc, strfns.cc, utils.cc, utils.h,
variables.cc, __ode15__.cc, gzip.cc, cdef-manager.cc, ov-fcn-handle.cc,
ov-java.cc, ov-usr-fcn.cc, bp-table.cc, bp-table.h, lex.h, lex.ll,
oct-parse.yy, pt-eval.cc:
Replace "func", "fun", "fn" in documentation and variable names with "fcn".
author | Rik <rik@octave.org> |
---|---|
date | Tue, 05 Apr 2022 08:33:58 -0700 |
parents | 32d2b6604a9f |
children | 670a0d878af1 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30390
diff
changeset
|
3 // Copyright (C) 1996-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2974 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
2974 | 28 #endif |
29 | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
30 #include <sstream> |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
31 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
32 #include "file-info.h" |
29636
9c76a6aefb42
Mark system functions correctly if OCTAVE_HOME is non-canonical (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
33 #include "file-ops.h" |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
34 #include "file-stat.h" |
2974 | 35 #include "str-vec.h" |
36 | |
22097
5ad67277b007
include builtin-defun-decls.h as needed
John W. Eaton <jwe@octave.org>
parents:
22096
diff
changeset
|
37 #include "builtin-defun-decls.h" |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
38 #include "defaults.h" |
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
39 #include "Cell.h" |
2974 | 40 #include "defun.h" |
41 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21072
diff
changeset
|
42 #include "errwarn.h" |
2974 | 43 #include "input.h" |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
44 #include "ovl.h" |
2974 | 45 #include "ov-usr-fcn.h" |
46 #include "ov.h" | |
47 #include "pager.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
48 #include "pt-eval.h" |
2985 | 49 #include "pt-jump.h" |
2974 | 50 #include "pt-misc.h" |
51 #include "pt-pr-code.h" | |
2982 | 52 #include "pt-stmt.h" |
2974 | 53 #include "pt-walk.h" |
54 #include "symtab.h" | |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
55 #include "interpreter-private.h" |
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
56 #include "interpreter.h" |
2974 | 57 #include "unwind-prot.h" |
58 #include "utils.h" | |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
59 #include "parse.h" |
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
60 #include "profiler.h" |
2974 | 61 #include "variables.h" |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
62 #include "ov-fcn-handle.h" |
2974 | 63 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
64 // Whether to optimize subsasgn method calls. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
65 static bool Voptimize_subsasgn_calls = true; |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
66 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
67 octave_user_code::~octave_user_code (void) |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
68 { |
26980
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
69 // This function is no longer valid, so remove the pointer to it from |
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
70 // the corresponding scope. |
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
71 // FIXME: would it be better to use shared/weak pointers for this job |
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
72 // instead of storing a bare pointer in the scope object? |
27745
7a45100a40c4
allow private scripts to be called from other private scripts
John W. Eaton <jwe@octave.org>
parents:
27263
diff
changeset
|
73 m_scope.set_user_code (nullptr); |
26980
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
74 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
75 // FIXME: shouldn't this happen automatically when deleting cmd_list? |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
76 if (m_cmd_list) |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27207
diff
changeset
|
77 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
78 octave::event_manager& evmgr |
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
79 = octave::__get_event_manager__ ("octave_user_code::~octave_user_code"); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27207
diff
changeset
|
80 |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
81 m_cmd_list->remove_all_breakpoints (evmgr, m_file_name); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27207
diff
changeset
|
82 } |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
83 |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
84 delete m_cmd_list; |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
85 delete m_file_info; |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
86 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
87 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
88 void |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
89 octave_user_code::get_file_info (void) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
90 { |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
91 m_file_info = new octave::file_info (m_file_name); |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
92 |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
93 octave::sys::file_stat fs (m_file_name); |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
94 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
95 if (fs && (fs.mtime () > time_parsed ())) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
96 warning ("function file '%s' changed since it was parsed", |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
97 m_file_name.c_str ()); |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
98 } |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
99 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
100 std::string |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29643
diff
changeset
|
101 octave_user_code::get_code_line (std::size_t line) |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
102 { |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
103 if (! m_file_info) |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
104 get_file_info (); |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
105 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
106 return m_file_info->get_line (line); |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
107 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
108 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
109 std::deque<std::string> |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29643
diff
changeset
|
110 octave_user_code::get_code_lines (std::size_t line, std::size_t num_lines) |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
111 { |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
112 if (! m_file_info) |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
113 get_file_info (); |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
114 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
115 return m_file_info->get_lines (line, num_lines); |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
116 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
117 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
118 void |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
119 octave_user_code::cache_function_text (const std::string& text, |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
120 const octave::sys::time& timestamp) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
121 { |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
122 if (m_file_info) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
123 delete m_file_info; |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
124 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
125 if (timestamp > time_parsed ()) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
126 warning ("help text for function is newer than function"); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
127 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
128 m_file_info = new octave::file_info (text, timestamp); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
129 } |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
130 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
131 std::map<std::string, octave_value> |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
132 octave_user_code::subfunctions (void) const |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
133 { |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
134 return std::map<std::string, octave_value> (); |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
135 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
136 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
137 octave_value |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
138 octave_user_code::dump (void) const |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
139 { |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
140 std::map<std::string, octave_value> m |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
141 = {{ "scope_info", m_scope ? m_scope.dump () : "0x0" }, |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
142 { "m_file_name", m_file_name }, |
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
143 { "time_parsed", m_t_parsed }, |
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
144 { "time_checked", m_t_checked }}; |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
145 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
146 return octave_value (m); |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
147 } |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
148 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
149 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
150 // User defined scripts. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
151 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
152 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_script, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 "user-defined script", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 "user-defined script"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
155 |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
156 octave_user_script::octave_user_script (void) |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
157 : octave_user_code () |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
158 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
159 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
160 octave_user_script::octave_user_script |
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
161 (const std::string& fnm, const std::string& nm, |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
162 const octave::symbol_scope& scope, octave::tree_statement_list *cmds, |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
163 const std::string& ds) |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
164 : octave_user_code (fnm, nm, scope, cmds, ds) |
7736 | 165 { |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
166 if (m_cmd_list) |
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
167 m_cmd_list->mark_as_script_body (); |
7736 | 168 } |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
169 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
170 octave_user_script::octave_user_script |
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
171 (const std::string& fnm, const std::string& nm, |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
172 const octave::symbol_scope& scope, const std::string& ds) |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
173 : octave_user_code (fnm, nm, scope, nullptr, ds) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
174 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
175 |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
176 // We must overload the call method so that we call the proper |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
177 // push_stack_frame method, which is overloaded for pointers to |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
178 // octave_function, octave_user_function, and octave_user_script |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
179 // objects. |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
180 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
181 octave_value_list |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
182 octave_user_script::call (octave::tree_evaluator& tw, int nargout, |
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
183 const octave_value_list& args) |
7336 | 184 { |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
185 tw.push_stack_frame (this); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
186 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
187 octave::unwind_action act ([&tw] () { tw.pop_stack_frame (); }); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
188 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
189 return execute (tw, nargout, args); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
190 } |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
191 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
192 octave_value_list |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
193 octave_user_script::execute (octave::tree_evaluator& tw, int nargout, |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
194 const octave_value_list& args) |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
195 { |
25400
d423ce60f5c8
evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents:
25399
diff
changeset
|
196 return tw.execute_user_script (*this, nargout, args); |
7336 | 197 } |
198 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
199 void |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
200 octave_user_script::accept (octave::tree_walker& tw) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
201 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
202 tw.visit_octave_user_script (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
203 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
204 |
2974 | 205 // User defined functions. |
206 | |
3219 | 207 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_function, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 "user-defined function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
209 "user-defined function"); |
2974 | 210 |
211 // Ugh. This really needs to be simplified (code/data? | |
212 // extrinsic/intrinsic state?). | |
213 | |
214 octave_user_function::octave_user_function | |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
215 (const octave::symbol_scope& scope, octave::tree_parameter_list *pl, |
28430
5bfa8e018704
store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
216 octave::tree_parameter_list *rl, octave::tree_statement_list *cl) |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
217 : octave_user_code ("", "", scope, cl, ""), |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
218 m_param_list (pl), m_ret_list (rl), |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
219 m_lead_comm (), m_trail_comm (), |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
220 m_location_line (0), m_location_column (0), |
30105
67994b92a613
eliminate redundant storage of parent function name in function objects
John W. Eaton <jwe@octave.org>
parents:
30001
diff
changeset
|
221 m_system_fcn_file (false), |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
222 m_num_named_args (m_param_list ? m_param_list->length () : 0), |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
223 m_subfunction (false), m_inline_function (false), |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
224 m_anonymous_function (false), m_nested_function (false), |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
225 m_class_constructor (none), m_class_method (none) |
7736 | 226 { |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
227 if (m_cmd_list) |
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
228 m_cmd_list->mark_as_function_body (); |
7736 | 229 } |
2974 | 230 |
231 octave_user_function::~octave_user_function (void) | |
232 { | |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
233 delete m_param_list; |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
234 delete m_ret_list; |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
235 delete m_lead_comm; |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
236 delete m_trail_comm; |
2974 | 237 } |
238 | |
239 octave_user_function * | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
240 octave_user_function::define_ret_list (octave::tree_parameter_list *t) |
2974 | 241 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
242 m_ret_list = t; |
2974 | 243 |
244 return this; | |
245 } | |
246 | |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
247 // If there is no explicit end statement at the end of the function, |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
248 // relocate the no_op that was generated for the end of file condition |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
249 // to appear on the next line after the last statement in the file, or |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
250 // the next line after the function keyword if there are no statements. |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
251 // More precisely, the new location should probably be on the next line |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
252 // after the end of the parameter list, but we aren't tracking that |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
253 // information (yet). |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
254 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
255 void |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
256 octave_user_function::maybe_relocate_end_internal (void) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
257 { |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
258 if (m_cmd_list && ! m_cmd_list->empty ()) |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
259 { |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
260 octave::tree_statement *last_stmt = m_cmd_list->back (); |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
261 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
262 if (last_stmt && last_stmt->is_end_of_fcn_or_script () |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
263 && last_stmt->is_end_of_file ()) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
264 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
265 octave::tree_statement_list::reverse_iterator |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
266 next_to_last_elt = m_cmd_list->rbegin (); |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
267 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
268 next_to_last_elt++; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
269 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
270 int new_eof_line; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
271 int new_eof_col; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
272 |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
273 if (next_to_last_elt == m_cmd_list->rend ()) |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
274 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
275 new_eof_line = beginning_line (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
276 new_eof_col = beginning_column (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
277 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
278 else |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
279 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
280 octave::tree_statement *next_to_last_stmt = *next_to_last_elt; |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
281 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
282 new_eof_line = next_to_last_stmt->line (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
283 new_eof_col = next_to_last_stmt->column (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
284 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
285 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
286 last_stmt->set_location (new_eof_line + 1, new_eof_col); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
287 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
288 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
289 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
290 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
291 void |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
292 octave_user_function::maybe_relocate_end (void) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
293 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
294 std::map<std::string, octave_value> fcns = subfunctions (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
295 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
296 if (! fcns.empty ()) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
297 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22853
diff
changeset
|
298 for (auto& nm_fnval : fcns) |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
299 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22853
diff
changeset
|
300 octave_user_function *f = nm_fnval.second.user_function_value (); |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
301 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
302 if (f) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
303 f->maybe_relocate_end_internal (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
304 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
305 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
306 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
307 maybe_relocate_end_internal (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
308 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
309 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
310 void |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
311 octave_user_function::stash_parent_fcn_scope (const octave::symbol_scope& ps) |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
312 { |
24572
4711e4b649d5
fix memory leak with subfunctions and nested functions
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
313 m_scope.set_parent (ps); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
314 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
315 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
316 std::string |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
317 octave_user_function::profiler_name (void) const |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
318 { |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
319 std::ostringstream result; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
320 |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
321 if (is_anonymous_function ()) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
322 result << "anonymous@" << fcn_file_name () |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
323 << ':' << m_location_line << ':' << m_location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
324 else if (is_subfunction ()) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
325 result << parent_fcn_name () << '>' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
326 else if (is_class_method ()) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
327 result << '@' << dispatch_class () << '/' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
328 else if (is_class_constructor () || is_classdef_constructor ()) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
329 result << '@' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
330 else if (is_inline_function ()) |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
331 result << "inline@" << fcn_file_name () |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
332 << ':' << m_location_line << ':' << m_location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
333 else |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
334 result << name (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
335 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
336 return result.str (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
337 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
338 |
2974 | 339 void |
340 octave_user_function::mark_as_system_fcn_file (void) | |
341 { | |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
342 if (! m_file_name.empty ()) |
2974 | 343 { |
344 // We really should stash the whole path to the file we found, | |
345 // when we looked it up, to avoid possible race conditions... | |
5775 | 346 // FIXME |
2974 | 347 // |
348 // We probably also don't need to get the library directory | |
349 // every time, but since this function is only called when the | |
350 // function file is parsed, it probably doesn't matter that | |
351 // much. | |
352 | |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
353 std::string ff_name = octave::fcn_file_in_path (m_file_name); |
2974 | 354 |
29643
874430de1cc7
Fix error if test suite is run before Octave is installed (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29636
diff
changeset
|
355 static const std::string canonical_fcn_file_dir |
29636
9c76a6aefb42
Mark system functions correctly if OCTAVE_HOME is non-canonical (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
356 = octave::sys::canonicalize_file_name |
9c76a6aefb42
Mark system functions correctly if OCTAVE_HOME is non-canonical (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
357 (octave::config::fcn_file_dir ()); |
29643
874430de1cc7
Fix error if test suite is run before Octave is installed (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29636
diff
changeset
|
358 static const std::string fcn_file_dir |
874430de1cc7
Fix error if test suite is run before Octave is installed (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29636
diff
changeset
|
359 = canonical_fcn_file_dir.empty () ? octave::config::fcn_file_dir () |
874430de1cc7
Fix error if test suite is run before Octave is installed (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29636
diff
changeset
|
360 : canonical_fcn_file_dir; |
874430de1cc7
Fix error if test suite is run before Octave is installed (bug #60554).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29636
diff
changeset
|
361 |
23717
06579337237b
move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents:
23716
diff
changeset
|
362 if (fcn_file_dir == ff_name.substr (0, fcn_file_dir.length ())) |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
363 m_system_fcn_file = true; |
2974 | 364 } |
365 else | |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
366 m_system_fcn_file = false; |
2974 | 367 } |
368 | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
369 void |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
370 octave_user_function::erase_subfunctions (void) |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
371 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
372 m_scope.erase_subfunctions (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
373 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
374 |
2974 | 375 bool |
376 octave_user_function::takes_varargs (void) const | |
377 { | |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
378 return (m_param_list && m_param_list->takes_varargs ()); |
2974 | 379 } |
380 | |
5848 | 381 bool |
382 octave_user_function::takes_var_return (void) const | |
2974 | 383 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
384 return (m_ret_list && m_ret_list->takes_varargs ()); |
2974 | 385 } |
386 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
387 void |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
388 octave_user_function::mark_as_private_function (const std::string& cname) |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
389 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
390 m_scope.mark_subfunctions_in_scope_as_private (cname); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
391 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
392 octave_function::mark_as_private_function (cname); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
393 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
394 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
395 void |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
396 octave_user_function::lock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
397 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
398 m_scope.lock_subfunctions (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
399 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
400 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
401 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
402 octave_user_function::unlock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
403 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
404 m_scope.unlock_subfunctions (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
405 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
406 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
407 std::map<std::string, octave_value> |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
408 octave_user_function::subfunctions (void) const |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
409 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
410 return m_scope.subfunctions (); |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
411 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
412 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
413 // Find definition of final subfunction in list of subfcns: |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
414 // |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
415 // sub1>sub2>...>subN |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
416 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
417 octave_value |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
418 octave_user_function::find_subfunction (const std::string& subfcns_arg) const |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
419 { |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
420 std::string subfcns = subfcns_arg; |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
421 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
422 std::string first_fcn = subfcns; |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
423 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
424 std::size_t pos = subfcns.find ('>'); |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
425 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
426 if (pos == std::string::npos) |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
427 subfcns = ""; |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
428 else |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
429 { |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
430 first_fcn = subfcns.substr (0, pos-1); |
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
431 subfcns = subfcns.substr (pos+1); |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
432 } |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
433 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
434 octave_value ov_fcn = m_scope.find_subfunction (first_fcn); |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
435 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
436 if (subfcns.empty ()) |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
437 return ov_fcn; |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
438 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
439 octave_user_function *fcn = ov_fcn.user_function_value (); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
440 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
441 return fcn->find_subfunction (subfcns); |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
442 } |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
443 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
444 bool |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
445 octave_user_function::has_subfunctions (void) const |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
446 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
447 return m_scope.has_subfunctions (); |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
448 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
449 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
450 void |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
451 octave_user_function::stash_subfunction_names (const std::list<std::string>& names) |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
452 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
453 m_scope.stash_subfunction_names (names); |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
454 } |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
455 |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
456 std::list<std::string> |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
457 octave_user_function::subfunction_names (void) const |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
458 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
459 return m_scope.subfunction_names (); |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
460 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
461 |
2974 | 462 octave_value_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
463 octave_user_function::all_va_args (const octave_value_list& args) |
2974 | 464 { |
465 octave_value_list retval; | |
466 | |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
467 octave_idx_type n = args.length () - m_num_named_args; |
2974 | 468 |
3178 | 469 if (n > 0) |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
470 retval = args.slice (m_num_named_args, n); |
2974 | 471 |
472 return retval; | |
473 } | |
474 | |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
475 // We must overload the call method so that we call the proper |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
476 // push_stack_frame method, which is overloaded for pointers to |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
477 // octave_function, octave_user_function, and octave_user_script |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
478 // objects. |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
479 |
2974 | 480 octave_value_list |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
481 octave_user_function::call (octave::tree_evaluator& tw, int nargout, |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
482 const octave_value_list& args) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
483 { |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
484 tw.push_stack_frame (this); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
485 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
486 octave::unwind_action act ([&tw] () { tw.pop_stack_frame (); }); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
487 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
488 return execute (tw, nargout, args); |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
489 } |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
490 |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
491 octave_value_list |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
492 octave_user_function::execute (octave::tree_evaluator& tw, int nargout, |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
493 const octave_value_list& args) |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
494 { |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28426
diff
changeset
|
495 return tw.execute_user_function (*this, nargout, args); |
2974 | 496 } |
497 | |
498 void | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
499 octave_user_function::accept (octave::tree_walker& tw) |
2974 | 500 { |
501 tw.visit_octave_user_function (*this); | |
502 } | |
503 | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
504 octave::tree_expression * |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
505 octave_user_function::special_expr (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
506 { |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30588
diff
changeset
|
507 panic_unless (is_special_expr ()); |
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30588
diff
changeset
|
508 panic_if (m_cmd_list->length () != 1); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
509 |
30179
5bef5b36747e
maint: use "m_" prefix for protected member variables in class octave_user_code.
Rik <rik@octave.org>
parents:
30105
diff
changeset
|
510 octave::tree_statement *stmt = m_cmd_list->front (); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
511 return stmt->expression (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
512 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
513 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
514 bool |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
515 octave_user_function::subsasgn_optimization_ok (void) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
516 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
517 bool retval = false; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
518 if (Voptimize_subsasgn_calls |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
519 && m_param_list && m_ret_list |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
520 && m_param_list->length () > 0 && ! m_param_list->varargs_only () |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
521 && m_ret_list->length () == 1 && ! m_ret_list->takes_varargs ()) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
522 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
523 octave::tree_identifier *par1 = m_param_list->front ()->ident (); |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
524 octave::tree_identifier *ret1 = m_ret_list->front ()->ident (); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
525 retval = par1->name () == ret1->name (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
526 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
527 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
528 return retval; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
529 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
530 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
531 std::string |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
532 octave_user_function::ctor_type_str (void) const |
3933 | 533 { |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
534 std::string retval; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
535 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
536 switch (m_class_constructor) |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
537 { |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
538 case none: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
539 retval = "none"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
540 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
541 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
542 case legacy: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
543 retval = "legacy"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
544 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
545 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
546 case classdef: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
547 retval = "classdef"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
548 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
549 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
550 default: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
551 retval = "unrecognized enum value"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
552 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
553 } |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
554 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
555 return retval; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
556 } |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
557 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
558 std::string |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
559 octave_user_function::method_type_str (void) const |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
560 { |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
561 std::string retval; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
562 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
563 switch (m_class_method) |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
564 { |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
565 case none: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
566 retval = "none"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
567 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
568 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
569 case legacy: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
570 retval = "legacy"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
571 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
572 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
573 case classdef: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
574 retval = "classdef"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
575 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
576 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
577 default: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
578 retval = "unrecognized enum value"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
579 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
580 } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
581 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
582 return retval; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
583 } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
584 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
585 octave_value |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
586 octave_user_function::dump (void) const |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
587 { |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
588 std::map<std::string, octave_value> m |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
589 = {{ "user_code", octave_user_code::dump () }, |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
590 { "line", m_location_line }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
591 { "col", m_location_column }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
592 { "end_line", m_end_location_line }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
593 { "end_col", m_end_location_column }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
594 { "system_fcn_file", m_system_fcn_file }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
595 { "num_named_args", m_num_named_args }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
596 { "subfunction", m_subfunction }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
597 { "inline_function", m_inline_function }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
598 { "anonymous_function", m_anonymous_function }, |
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
599 { "nested_function", m_nested_function }, |
23718
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
600 { "ctor_type", ctor_type_str () }, |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
601 { "class_method", m_class_method }}; |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
602 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
603 return octave_value (m); |
3933 | 604 } |
605 | |
606 void | |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
607 octave_user_function::print_code_function_header (const std::string& prefix) |
2974 | 608 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
609 octave::tree_print_code tpc (octave_stdout, prefix); |
2974 | 610 |
611 tpc.visit_octave_user_function_header (*this); | |
612 } | |
613 | |
614 void | |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
615 octave_user_function::print_code_function_trailer (const std::string& prefix) |
2974 | 616 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
617 octave::tree_print_code tpc (octave_stdout, prefix); |
2974 | 618 |
619 tpc.visit_octave_user_function_trailer (*this); | |
620 } | |
621 | |
622 void | |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
623 octave_user_function::restore_warning_states (void) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
624 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
625 octave::interpreter& interp |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
626 = octave::__get_interpreter__ ("octave_user_function::restore_warning_states"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
627 |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
628 octave::tree_evaluator& tw = interp.get_evaluator (); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
629 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
630 octave_value val |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
631 = tw.get_auto_fcn_var (octave::stack_frame::SAVED_WARNING_STATES); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
632 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
633 if (val.is_defined ()) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
634 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
635 // Fail spectacularly if SAVED_WARNING_STATES is not an |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
636 // octave_map (or octave_scalar_map) object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
637 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
638 if (! val.isstruct ()) |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
639 panic_impossible (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
640 |
17612
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
641 octave_map m = val.map_value (); |
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
642 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
643 Cell ids = m.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
644 Cell states = m.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
645 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
646 for (octave_idx_type i = 0; i < m.numel (); i++) |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
647 Fwarning (interp, ovl (states(i), ids(i))); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
648 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
649 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
650 |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29949
diff
changeset
|
651 OCTAVE_NAMESPACE_BEGIN |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29949
diff
changeset
|
652 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
653 DEFMETHOD (nargin, interp, args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
654 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
655 @deftypefn {} {@var{n} =} nargin () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
656 @deftypefnx {} {@var{n} =} nargin (@var{fcn}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
657 Report the number of input arguments to a function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
658 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
659 Called from within a function, return the number of arguments passed to the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
660 function. At the top level, return the number of command line arguments |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
661 passed to Octave. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
662 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
663 If called with the optional argument @var{fcn}---a function name or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
664 handle---return the declared number of arguments that the function can |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
665 accept. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
666 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
667 If the last argument to @var{fcn} is @var{varargin} the returned value is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
668 negative. For example, the function @code{union} for sets is declared as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
669 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
670 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
671 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
672 function [y, ia, ib] = union (a, b, varargin) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
673 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
674 and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
675 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
676 nargin ("union") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
677 @result{} -3 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
678 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
679 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
680 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
681 Programming Note: @code{nargin} does not work on compiled functions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
682 (@file{.oct} files) such as built-in or dynamically loaded functions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
683 @seealso{nargout, narginchk, varargin, inputname} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
684 @end deftypefn */) |
4700 | 685 { |
686 int nargin = args.length (); | |
687 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
688 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
689 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
690 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
691 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
692 |
4700 | 693 if (nargin == 1) |
694 { | |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
695 octave_value fcn = args(0); |
4700 | 696 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
697 if (fcn.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
698 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
699 symbol_table& symtab = interp.get_symbol_table (); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
700 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
701 std::string name = fcn.string_value (); |
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
702 fcn = symtab.find_function (name); |
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
703 if (fcn.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
704 error ("nargin: invalid function name: %s", name.c_str ()); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
705 } |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
706 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
707 octave_function *fcn_val = fcn.function_value (true); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
708 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
709 error ("nargin: FCN must be a string or function handle"); |
4700 | 710 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
711 octave_user_function *ufcn = fcn_val->user_function_value (true); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
712 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
713 if (! ufcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
714 { |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22164
diff
changeset
|
715 // Matlab gives up for histc, so maybe it's ok that we |
21179
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
716 // give up sometimes too? |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
717 |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
718 std::string type = fcn_val->type_name (); |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
719 error ("nargin: number of input arguments unavailable for %s objects", |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
720 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
721 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
722 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
723 tree_parameter_list *m_param_list = ufcn->parameter_list (); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
724 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
725 retval = (m_param_list ? m_param_list->length () : 0); |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
726 if (ufcn->takes_varargs ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
727 retval = -1 - retval; |
4700 | 728 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
729 else |
4700 | 730 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
731 tree_evaluator& tw = interp.get_evaluator (); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
732 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
733 retval = tw.get_auto_fcn_var (stack_frame::NARGIN); |
4700 | 734 |
7336 | 735 if (retval.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
736 retval = 0; |
4700 | 737 } |
738 | |
739 return retval; | |
740 } | |
741 | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30179
diff
changeset
|
742 DEFMETHOD (nargout, interp, args, , |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
743 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
744 @deftypefn {} {@var{n} =} nargout () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
745 @deftypefnx {} {@var{n} =} nargout (@var{fcn}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
746 Report the number of output arguments from a function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
747 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
748 Called from within a function, return the number of values the caller |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
749 expects to receive. At the top level, @code{nargout} with no argument is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
750 undefined and will produce an error. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
751 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
752 If called with the optional argument @var{fcn}---a function name or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
753 handle---return the number of declared output values that the function can |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
754 produce. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
755 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
756 If the final output argument is @var{varargout} the returned value is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
757 negative. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
758 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
759 For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
760 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
761 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
762 f () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
763 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
764 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
765 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
766 will cause @code{nargout} to return 0 inside the function @code{f} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
767 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
768 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
769 [s, t] = f () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
770 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
771 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
772 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
773 will cause @code{nargout} to return 2 inside the function @code{f}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
774 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
775 In the second usage, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
776 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
777 @example |
22845
e23f7f47d8a3
doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
778 nargout (@@histc) # or nargout ("histc") using a string input |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
779 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
780 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
781 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
782 will return 2, because @code{histc} has two outputs, whereas |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
783 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
784 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
785 nargout (@@imread) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
786 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
787 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
788 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
789 will return -2, because @code{imread} has two outputs and the second is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
790 @var{varargout}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
791 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
792 Programming Note. @code{nargout} does not work for built-in functions and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
793 returns -1 for all anonymous functions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
794 @seealso{nargin, varargout, isargout, nthargout} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
795 @end deftypefn */) |
4700 | 796 { |
797 int nargin = args.length (); | |
798 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
799 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
800 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
801 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
802 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
803 |
4700 | 804 if (nargin == 1) |
805 { | |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
806 octave_value fcn = args(0); |
4700 | 807 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
808 if (fcn.is_string ()) |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
809 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
810 symbol_table& symtab = interp.get_symbol_table (); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
811 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
812 std::string name = fcn.string_value (); |
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
813 fcn = symtab.find_function (name); |
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
814 if (fcn.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
815 error ("nargout: invalid function name: %s", name.c_str ()); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
816 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
817 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
818 if (fcn.is_inline_function ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
819 return ovl (1); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
820 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
821 if (fcn.is_function_handle ()) |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
822 { |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
823 octave_fcn_handle *fh = fcn.fcn_handle_value (); |
4930 | 824 |
28197
087bccd1ab49
new function to identify anonymous function handles
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
825 if (fh->is_anonymous ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
826 return ovl (-1); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
827 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
828 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
829 octave_function *fcn_val = fcn.function_value (true); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
830 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
831 error ("nargout: FCN must be a string or function handle"); |
4700 | 832 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
833 octave_user_function *ufcn = fcn_val->user_function_value (true); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
834 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
835 if (! ufcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
836 { |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22164
diff
changeset
|
837 // Matlab gives up for histc, so maybe it's ok that we |
21180
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
838 // give up sometimes too? |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
839 |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
840 std::string type = fcn_val->type_name (); |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
841 error ("nargout: number of output arguments unavailable for %s objects", |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
842 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
843 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
844 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
845 tree_parameter_list *m_ret_list = ufcn->return_list (); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
846 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
847 retval = (m_ret_list ? m_ret_list->length () : 0); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
848 |
30896
c9788d7f6e65
maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
849 if (ufcn->takes_var_return ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
850 retval = -1 - retval; |
4700 | 851 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
852 else |
4700 | 853 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
854 if (interp.at_top_level ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
855 error ("nargout: invalid call at top level"); |
4700 | 856 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
857 tree_evaluator& tw = interp.get_evaluator (); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
858 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
859 retval = tw.get_auto_fcn_var (stack_frame::NARGOUT); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
860 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
861 if (retval.is_undefined ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
862 retval = 0; |
4700 | 863 } |
864 | |
865 return retval; | |
866 } | |
867 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
868 DEFUN (optimize_subsasgn_calls, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
869 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
870 @deftypefn {} {@var{val} =} optimize_subsasgn_calls () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
871 @deftypefnx {} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
872 @deftypefnx {} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
873 Query or set the internal flag for @code{subsasgn} method call |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
874 optimizations. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
875 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
876 If true, Octave will attempt to eliminate the redundant copying when calling |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
877 the @code{subsasgn} method of a user-defined class. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
878 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
879 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
880 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
881 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
882 @seealso{subsasgn} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
883 @end deftypefn */) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
884 { |
30001
428cccc75cc9
move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
885 return set_internal_variable (Voptimize_subsasgn_calls, args, nargout, |
428cccc75cc9
move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
886 "optimize_subsasgn_calls"); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
887 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
888 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
889 static bool val_in_table (const Matrix& table, double val) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
890 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
891 if (table.isempty ()) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
892 return false; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
893 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
894 octave_idx_type i = table.lookup (val, ASCENDING); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
895 return (i > 0 && table(i-1) == val); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
896 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
897 |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
898 static bool isargout1 (int nargout, const Matrix& ignored, double k) |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
899 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
900 if (k != math::fix (k) || k <= 0) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
901 error ("isargout: K must be a positive integer"); |
20921
4d3daf7e43f3
eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
902 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
903 return (k == 1 || k <= nargout) && ! val_in_table (ignored, k); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
904 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
905 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
906 DEFMETHOD (isargout, interp, args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
907 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30390
diff
changeset
|
908 @deftypefn {} {@var{tf} =} isargout (@var{k}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
909 Within a function, return a logical value indicating whether the argument |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
910 @var{k} will be assigned to a variable on output. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
911 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
912 If the result is false, the argument has been ignored during the function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
913 call through the use of the tilde (~) special output argument. Functions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
914 can use @code{isargout} to avoid performing unnecessary calculations for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
915 outputs which are unwanted. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
916 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
917 If @var{k} is outside the range @code{1:max (nargout)}, the function returns |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
918 false. @var{k} can also be an array, in which case the function works |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
919 element-by-element and a logical array is returned. At the top level, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
920 @code{isargout} returns an error. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
921 @seealso{nargout, varargout, nthargout} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
922 @end deftypefn */) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
923 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
924 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
925 print_usage (); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
926 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
927 if (interp.at_top_level ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
928 error ("isargout: invalid call at top level"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
929 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
930 tree_evaluator& tw = interp.get_evaluator (); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
931 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
932 octave_value tmp; |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
933 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
934 int nargout1 = 0; |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
935 tmp = tw.get_auto_fcn_var (stack_frame::NARGOUT); |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
936 if (tmp.is_defined ()) |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
937 nargout1 = tmp.int_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
938 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
939 Matrix ignored; |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
940 tmp = tw.get_auto_fcn_var (stack_frame::IGNORED); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
941 if (tmp.is_defined ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
942 ignored = tmp.matrix_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
943 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
944 if (args(0).is_scalar_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
945 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
946 double k = args(0).double_value (); |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
947 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
948 return ovl (isargout1 (nargout1, ignored, k)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
949 } |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
950 else if (args(0).isnumeric ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
951 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
952 const NDArray ka = args(0).array_value (); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
953 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
954 boolNDArray r (ka.dims ()); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
955 for (octave_idx_type i = 0; i < ka.numel (); i++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
956 r(i) = isargout1 (nargout1, ignored, ka(i)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
957 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
958 return ovl (r); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
959 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
960 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21072
diff
changeset
|
961 err_wrong_type_arg ("isargout", args(0)); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
962 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
963 return ovl (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
964 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
965 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
966 /* |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
967 %!function [x, y] = try_isargout () |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
968 %! if (isargout (1)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
969 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
970 %! x = 1; y = 2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
971 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
972 %! x = -1; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
973 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
974 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
975 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
976 %! y = -2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
977 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
978 %! error ("no outputs requested"); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
979 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
980 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
981 %!endfunction |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
982 %! |
23482
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
983 %!function [a, b] = try_isargout2 (x, y) |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
984 %! a = y; |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
985 %! b = {isargout(1), isargout(2), x}; |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
986 %!endfunction |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
987 %! |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
988 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
989 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
990 %! assert ([x, y], [1, 2]); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
991 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
992 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
993 %! [x, ~] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
994 %! assert (x, -1); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
995 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
996 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
997 %! [~, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
998 %! assert (y, -2); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
999 %! |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1000 %!error [~, ~] = try_isargout () |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1001 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1002 ## Check to see that isargout isn't sticky: |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1003 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1004 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1005 %! assert ([x, y], [1, 2]); |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1006 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1007 ## It should work without (): |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1008 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1009 %! [~, y] = try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1010 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1011 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1012 ## It should work in function handles, anonymous functions, and cell |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1013 ## arrays of handles or anonymous functions. |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1014 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1015 %! fh = @try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1016 %! af = @() try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1017 %! c = {fh, af}; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1018 %! [~, y] = fh (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1019 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1020 %! [~, y] = af (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1021 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1022 %! [~, y] = c{1}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1023 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1024 %! [~, y] = c{2}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1025 %! assert (y, -2); |
23482
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1026 %! |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1027 ## Nesting, anyone? |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1028 %!test |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1029 %! [~, b] = try_isargout2 (try_isargout, rand); |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1030 %! assert (b, {0, 1, -1}); |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1031 %!test |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1032 %! [~, b] = try_isargout2 ({try_isargout, try_isargout}, rand); |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1033 %! assert (b, {0, 1, {-1, -1}}); |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1034 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29949
diff
changeset
|
1035 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29949
diff
changeset
|
1036 OCTAVE_NAMESPACE_END |