Mercurial > octave
annotate libinterp/octave-value/ov-usr-fcn.cc @ 27263:99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
* event-manager.h, event-manager.cc: Rename from octave-link.h and
octave-link.cc.
(class event_manager): Rename from octave_link. Move inside octave
namespace. Change all uses.
(class interpreter_events): Rename from octave_link_events. Move
inside octave namespace. Change all uses.
* libinterp/corefcn/module.mk: Update.
* qt-interpreter-events.h, qt-interpreter-events.cc: Rename from
octave-qt-link.h and octave-qt-link.cc.
(class qt_interpreter_events): Rename from octave_qt_link_events
Change all uses.
* libgui/src/module.mk: Update.
Change all interpreter functions that uses octave_link in their names
to use event_manager instead.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 18 Jul 2019 11:23:22 -0400 |
parents | dccdc3b001a2 |
children | 7a45100a40c4 |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26065
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2974 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
10 (at your option) any later version. |
2974 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
15 GNU General Public License for more details. |
2974 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2974 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2974 | 25 #endif |
26 | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
27 #include <sstream> |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
28 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
29 #include "file-info.h" |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
30 #include "file-stat.h" |
2974 | 31 #include "str-vec.h" |
32 | |
22097
5ad67277b007
include builtin-defun-decls.h as needed
John W. Eaton <jwe@octave.org>
parents:
22096
diff
changeset
|
33 #include "builtin-defun-decls.h" |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
34 #include "defaults.h" |
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
35 #include "Cell.h" |
2974 | 36 #include "defun.h" |
37 #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
|
38 #include "errwarn.h" |
2974 | 39 #include "input.h" |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
40 #include "ovl.h" |
2974 | 41 #include "ov-usr-fcn.h" |
42 #include "ov.h" | |
43 #include "pager.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
44 #include "pt-eval.h" |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
45 #include "pt-jit.h" |
2985 | 46 #include "pt-jump.h" |
2974 | 47 #include "pt-misc.h" |
48 #include "pt-pr-code.h" | |
2982 | 49 #include "pt-stmt.h" |
2974 | 50 #include "pt-walk.h" |
51 #include "symtab.h" | |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
52 #include "interpreter-private.h" |
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
53 #include "interpreter.h" |
2974 | 54 #include "unwind-prot.h" |
55 #include "utils.h" | |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
56 #include "parse.h" |
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
57 #include "profiler.h" |
2974 | 58 #include "variables.h" |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
59 #include "ov-fcn-handle.h" |
2974 | 60 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
61 // Whether to optimize subsasgn method calls. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
62 static bool Voptimize_subsasgn_calls = true; |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
63 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
64 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
|
65 { |
26980
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
66 // 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
|
67 // 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
|
68 // 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
|
69 // instead of storing a bare pointer in the scope object? |
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
70 m_scope.set_function (nullptr); |
4274f6962e6b
avoid using pointer to function after it is deleted (bug #55981)
John W. Eaton <jwe@octave.org>
parents:
26825
diff
changeset
|
71 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
72 // FIXME: shouldn't this happen automatically when deleting cmd_list? |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
73 if (cmd_list) |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27207
diff
changeset
|
74 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
75 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
|
76 = 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
|
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 cmd_list->remove_all_breakpoints (evmgr, file_name); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27207
diff
changeset
|
79 } |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
80 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
81 delete cmd_list; |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
82 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
|
83 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
84 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
85 void |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
86 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
|
87 { |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
88 m_file_info = new octave::file_info (file_name); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
89 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
90 octave::sys::file_stat fs (file_name); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
91 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
92 if (fs && (fs.mtime () > time_parsed ())) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
93 warning ("function file '%s' changed since it was parsed", |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
94 file_name.c_str ()); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
95 } |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
96 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
97 std::string |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
98 octave_user_code::get_code_line (size_t line) |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
99 { |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
100 if (! m_file_info) |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
101 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
|
102 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
103 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
|
104 } |
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 std::deque<std::string> |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
107 octave_user_code::get_code_lines (size_t line, size_t num_lines) |
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 if (! m_file_info) |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
110 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
|
111 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
112 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
|
113 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
114 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
115 void |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
116 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
|
117 const octave::sys::time& timestamp) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
118 { |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
119 if (m_file_info) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
120 delete m_file_info; |
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 (timestamp > time_parsed ()) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
123 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
|
124 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
125 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
|
126 } |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
127 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
128 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
|
129 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
|
130 { |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
131 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
|
132 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
133 |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
134 octave_value |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
135 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
|
136 { |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
137 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
|
138 = {{ "scope_info", m_scope ? m_scope.dump () : "0x0" }, |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
139 { "file_name", file_name }, |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
140 { "time_parsed", t_parsed }, |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
141 { "time_checked", 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
|
142 |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
143 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
|
144 } |
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 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
147 // User defined scripts. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
148 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
149 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
|
150 "user-defined script", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 "user-defined script"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
152 |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
153 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
|
154 : octave_user_code () |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
155 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
156 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
157 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
|
158 (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
|
159 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
|
160 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
|
161 : octave_user_code (fnm, nm, scope, cmds, ds) |
7736 | 162 { |
163 if (cmd_list) | |
164 cmd_list->mark_as_script_body (); | |
165 } | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
166 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
167 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
|
168 (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
|
169 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
|
170 : 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
|
171 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
172 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
173 octave_value_list |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
174 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
|
175 const octave_value_list& args) |
7336 | 176 { |
25400
d423ce60f5c8
evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents:
25399
diff
changeset
|
177 return tw.execute_user_script (*this, nargout, args); |
7336 | 178 } |
179 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
180 void |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
181 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
|
182 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
183 tw.visit_octave_user_script (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
184 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
185 |
2974 | 186 // User defined functions. |
187 | |
3219 | 188 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
|
189 "user-defined function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 "user-defined function"); |
2974 | 191 |
192 // Ugh. This really needs to be simplified (code/data? | |
193 // extrinsic/intrinsic state?). | |
194 | |
195 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
|
196 (const octave::symbol_scope& scope, octave::tree_parameter_list *pl, |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
197 octave::tree_parameter_list *rl, octave::tree_statement_list *cl, |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
198 const local_vars_map& lviv) |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
199 : octave_user_code ("", "", scope, cl, ""), |
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
200 param_list (pl), ret_list (rl), |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
201 m_local_var_init_vals (lviv), |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
202 lead_comm (), trail_comm (), |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
203 location_line (0), location_column (0), |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
204 parent_name (), system_fcn_file (false), |
7589
90fb25a5a3fa
minor cleanup in octave_user_function constructor
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
205 num_named_args (param_list ? param_list->length () : 0), |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11431
diff
changeset
|
206 subfunction (false), inline_function (false), |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14573
diff
changeset
|
207 anonymous_function (false), nested_function (false), |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
208 class_constructor (none), class_method (none) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
209 #if defined (HAVE_LLVM) |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
210 , jit_info (0) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
211 #endif |
7736 | 212 { |
213 if (cmd_list) | |
214 cmd_list->mark_as_function_body (); | |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
215 |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
216 if (m_scope) |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
217 m_scope.set_function (this); |
7736 | 218 } |
2974 | 219 |
220 octave_user_function::~octave_user_function (void) | |
221 { | |
222 delete param_list; | |
223 delete ret_list; | |
3665 | 224 delete lead_comm; |
225 delete trail_comm; | |
7336 | 226 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
227 #if defined (HAVE_LLVM) |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
228 delete jit_info; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
229 #endif |
2974 | 230 } |
231 | |
232 octave_user_function * | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
233 octave_user_function::define_ret_list (octave::tree_parameter_list *t) |
2974 | 234 { |
235 ret_list = t; | |
236 | |
237 return this; | |
238 } | |
239 | |
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
|
240 // 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
|
241 // 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
|
242 // 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
|
243 // 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
|
244 // 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
|
245 // 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
|
246 // 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
|
247 |
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 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
|
249 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
|
250 { |
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 if (cmd_list && ! cmd_list->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
|
252 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
253 octave::tree_statement *last_stmt = 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
|
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 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
|
256 && 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
|
257 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
258 octave::tree_statement_list::reverse_iterator |
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 next_to_last_elt = cmd_list->rbegin (); |
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
|
260 |
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 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
|
262 |
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 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
|
264 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
|
265 |
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
|
266 if (next_to_last_elt == cmd_list->rend ()) |
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 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
|
269 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
|
270 } |
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 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
|
272 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
273 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
|
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 = 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
|
276 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
|
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 |
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 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
|
280 } |
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 } |
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 |
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 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
|
285 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
|
286 { |
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 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
|
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 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
|
290 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22853
diff
changeset
|
291 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
|
292 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22853
diff
changeset
|
293 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
|
294 |
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 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
|
296 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
|
297 } |
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
|
298 } |
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 |
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
|
300 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
|
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 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
303 void |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
304 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
|
305 { |
24572
4711e4b649d5
fix memory leak with subfunctions and nested functions
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
306 m_scope.set_parent (ps); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
307 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
308 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
309 std::string |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
310 octave_user_function::profiler_name (void) const |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
311 { |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
312 std::ostringstream result; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
313 |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
314 if (is_anonymous_function ()) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
315 result << "anonymous@" << fcn_file_name () |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
316 << ':' << location_line << ':' << location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 result << '@' << dispatch_class () << '/' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
321 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
|
322 result << '@' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
323 else if (is_inline_function ()) |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
324 result << "inline@" << fcn_file_name () |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
325 << ':' << location_line << ':' << location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
326 else |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
327 result << name (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
328 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
329 return result.str (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
330 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
331 |
2974 | 332 void |
333 octave_user_function::mark_as_system_fcn_file (void) | |
334 { | |
335 if (! file_name.empty ()) | |
336 { | |
337 // We really should stash the whole path to the file we found, | |
338 // when we looked it up, to avoid possible race conditions... | |
5775 | 339 // FIXME |
2974 | 340 // |
341 // We probably also don't need to get the library directory | |
342 // every time, but since this function is only called when the | |
343 // function file is parsed, it probably doesn't matter that | |
344 // much. | |
345 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25460
diff
changeset
|
346 std::string ff_name = octave::fcn_file_in_path (file_name); |
2974 | 347 |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
348 std::string fcn_file_dir = octave::config::fcn_file_dir (); |
23717
06579337237b
move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents:
23716
diff
changeset
|
349 if (fcn_file_dir == ff_name.substr (0, fcn_file_dir.length ())) |
14866
2309812f428e
Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14861
diff
changeset
|
350 system_fcn_file = true; |
2974 | 351 } |
352 else | |
14866
2309812f428e
Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14861
diff
changeset
|
353 system_fcn_file = false; |
2974 | 354 } |
355 | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
356 void |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
357 octave_user_function::erase_subfunctions (void) |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
358 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
359 m_scope.erase_subfunctions (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
360 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
361 |
2974 | 362 bool |
363 octave_user_function::takes_varargs (void) const | |
364 { | |
365 return (param_list && param_list->takes_varargs ()); | |
366 } | |
367 | |
5848 | 368 bool |
369 octave_user_function::takes_var_return (void) const | |
2974 | 370 { |
5848 | 371 return (ret_list && ret_list->takes_varargs ()); |
2974 | 372 } |
373 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
374 void |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
375 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
|
376 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
377 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
|
378 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
379 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
|
380 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
381 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
382 void |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
383 octave_user_function::lock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
384 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
385 m_scope.lock_subfunctions (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
386 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
387 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
388 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
389 octave_user_function::unlock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
390 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
391 m_scope.unlock_subfunctions (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
392 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
393 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
394 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
|
395 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
|
396 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
397 return m_scope.subfunctions (); |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
398 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
399 |
26065
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
400 // Find definition of final subfunction in list of subfuns: |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
401 // |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
402 // sub1>sub2>...>subN |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
403 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
404 octave_value |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
405 octave_user_function::find_subfunction (const std::string& subfuns_arg) const |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
406 { |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
407 std::string subfuns = subfuns_arg; |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
408 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
409 std::string first_fun = subfuns; |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
410 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
411 size_t pos = subfuns.find ('>'); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
412 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
413 if (pos == std::string::npos) |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
414 subfuns = ""; |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
415 else |
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 first_fun = subfuns.substr (0, pos-1); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
418 subfuns = subfuns.substr (pos+1); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
419 } |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
420 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
421 octave_value ov_fcn = m_scope.find_subfunction (first_fun); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
422 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
423 if (subfuns.empty ()) |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
424 return ov_fcn; |
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 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
|
427 |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
428 return fcn->find_subfunction (subfuns); |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
429 } |
2eb71b83d3e2
partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents:
26039
diff
changeset
|
430 |
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
|
431 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
|
432 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
|
433 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
434 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
|
435 } |
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
|
436 |
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
|
437 void |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
438 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
|
439 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
440 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
|
441 } |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
442 |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
443 std::list<std::string> |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
444 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
|
445 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24325
diff
changeset
|
446 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
|
447 } |
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 |
2974 | 449 octave_value_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
450 octave_user_function::all_va_args (const octave_value_list& args) |
2974 | 451 { |
452 octave_value_list retval; | |
453 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
454 octave_idx_type n = args.length () - num_named_args; |
2974 | 455 |
3178 | 456 if (n > 0) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
457 retval = args.slice (num_named_args, n); |
2974 | 458 |
459 return retval; | |
460 } | |
461 | |
462 octave_value_list | |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
463 octave_user_function::call (octave::tree_evaluator& tw, int nargout, |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
464 const octave_value_list& args, |
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
465 octave::stack_frame *closure_frames) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
466 { |
26825
6e9034836239
allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents:
26794
diff
changeset
|
467 return tw.execute_user_function (*this, nargout, args, closure_frames); |
2974 | 468 } |
469 | |
470 void | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
471 octave_user_function::accept (octave::tree_walker& tw) |
2974 | 472 { |
473 tw.visit_octave_user_function (*this); | |
474 } | |
475 | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
476 octave::tree_expression * |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
477 octave_user_function::special_expr (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
478 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
479 assert (is_special_expr ()); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
480 assert (cmd_list->length () == 1); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
481 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
482 octave::tree_statement *stmt = cmd_list->front (); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
483 return stmt->expression (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
484 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
485 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
486 bool |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
487 octave_user_function::subsasgn_optimization_ok (void) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
488 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
489 bool retval = false; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
490 if (Voptimize_subsasgn_calls |
18699
e3fca7930c1e
Fix segfault if subsasgn in @class returns no output (bug #41945)
Stefan Mahr <dac922@gmx.de>
parents:
18533
diff
changeset
|
491 && param_list && ret_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
492 && param_list->length () > 0 && ! param_list->varargs_only () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
493 && ret_list->length () == 1 && ! ret_list->takes_varargs ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
494 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
495 octave::tree_identifier *par1 = param_list->front ()->ident (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
496 octave::tree_identifier *ret1 = ret_list->front ()->ident (); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
497 retval = par1->name () == ret1->name (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
498 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
499 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
500 return retval; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
501 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
502 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
503 std::string |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
504 octave_user_function::ctor_type_str (void) const |
3933 | 505 { |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
506 std::string retval; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
507 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
508 switch (class_constructor) |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
509 { |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
510 case none: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
511 retval = "none"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
512 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
513 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
514 case legacy: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
515 retval = "legacy"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
516 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
517 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
518 case classdef: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
519 retval = "classdef"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
520 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
521 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
522 default: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
523 retval = "unrecognized enum value"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
524 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
525 } |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
526 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
527 return retval; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
528 } |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
529 |
26794
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
530 std::string |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
531 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
|
532 { |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
533 std::string retval; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
534 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
535 switch (class_method) |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
536 { |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
537 case none: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
538 retval = "none"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
539 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
540 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
541 case legacy: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
542 retval = "legacy"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
543 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
544 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
545 case classdef: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
546 retval = "classdef"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
547 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
548 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
549 default: |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
550 retval = "unrecognized enum value"; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
551 break; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
552 } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
553 |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
554 return retval; |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
555 } |
287eba9ed14b
refactor predicates for classdef methods/constructors
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
556 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
557 octave_value |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
558 octave_user_function::dump (void) const |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
559 { |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
560 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
|
561 = {{ "user_code", octave_user_code::dump () }, |
23718
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
562 { "line", location_line }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
563 { "col", location_column }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
564 { "end_line", end_location_line }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
565 { "end_col", end_location_column }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
566 { "parent_name", parent_name }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
567 { "system_fcn_file", system_fcn_file }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
568 { "num_named_args", num_named_args }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
569 { "subfunction", subfunction }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
570 { "inline_function", inline_function }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
571 { "anonymous_function", anonymous_function }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
572 { "nested_function", nested_function }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
573 { "ctor_type", ctor_type_str () }, |
25359
b93522e36446
move common function and script data to octave_user_code class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
574 { "class_method", class_method }}; |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
575 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
576 return octave_value (m); |
3933 | 577 } |
578 | |
579 void | |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
580 octave_user_function::print_code_function_header (const std::string& prefix) |
2974 | 581 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
582 octave::tree_print_code tpc (octave_stdout, prefix); |
2974 | 583 |
584 tpc.visit_octave_user_function_header (*this); | |
585 } | |
586 | |
587 void | |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
588 octave_user_function::print_code_function_trailer (const std::string& prefix) |
2974 | 589 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
590 octave::tree_print_code tpc (octave_stdout, prefix); |
2974 | 591 |
592 tpc.visit_octave_user_function_trailer (*this); | |
593 } | |
594 | |
595 void | |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
596 octave_user_function::restore_warning_states (void) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
597 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
598 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
|
599 = 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
|
600 |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
601 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
|
602 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
603 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
|
604 = 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
|
605 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
606 if (val.is_defined ()) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
607 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
608 // 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
|
609 // octave_map (or octave_scalar_map) object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
610 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
611 if (! val.isstruct ()) |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
612 panic_impossible (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
613 |
17612
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
614 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
|
615 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
616 Cell ids = m.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
617 Cell states = m.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
618 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
619 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
|
620 Fwarning (interp, ovl (states(i), ids(i))); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
621 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
622 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
623 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
624 DEFMETHOD (nargin, interp, args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
625 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
626 @deftypefn {} {} nargin () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
627 @deftypefnx {} {} nargin (@var{fcn}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
628 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
|
629 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
634 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
|
635 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
|
636 accept. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
637 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
638 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
|
639 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
|
640 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
641 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
642 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
643 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
|
644 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
645 and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
646 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
647 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
|
648 @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
|
649 @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
|
650 @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
|
651 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
652 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
|
653 (@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
|
654 @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
|
655 @end deftypefn */) |
4700 | 656 { |
657 int nargin = args.length (); | |
658 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
659 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
660 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
661 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
662 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
663 |
4700 | 664 if (nargin == 1) |
665 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
666 octave_value func = args(0); |
4700 | 667 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
668 if (func.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
669 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
670 octave::symbol_table& symtab = interp.get_symbol_table (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
671 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
672 std::string name = func.string_value (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
673 func = symtab.find_function (name); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
674 if (func.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
675 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
|
676 } |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
677 |
21179
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
678 octave_function *fcn_val = func.function_value (true); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
679 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
680 error ("nargin: FCN must be a string or function handle"); |
4700 | 681 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
682 octave_user_function *fcn = 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
|
683 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
684 if (! fcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
685 { |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22164
diff
changeset
|
686 // 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
|
687 // give up sometimes too? |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
688 |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
689 std::string type = fcn_val->type_name (); |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
690 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
|
691 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
692 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
693 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
694 octave::tree_parameter_list *param_list = fcn->parameter_list (); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
695 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23436
diff
changeset
|
696 retval = (param_list ? param_list->length () : 0); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
697 if (fcn->takes_varargs ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
698 retval = -1 - retval; |
4700 | 699 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
700 else |
4700 | 701 { |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
702 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
|
703 |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
704 retval = tw.get_auto_fcn_var (octave::stack_frame::NARGIN); |
4700 | 705 |
7336 | 706 if (retval.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 retval = 0; |
4700 | 708 } |
709 | |
710 return retval; | |
711 } | |
712 | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
713 DEFMETHOD (nargout, interp,args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
714 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
715 @deftypefn {} {} nargout () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
716 @deftypefnx {} {} nargout (@var{fcn}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
717 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
|
718 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
719 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
|
720 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
|
721 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
|
722 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
723 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
|
724 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
|
725 produce. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
726 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
727 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
|
728 negative. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
729 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
730 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
|
731 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
732 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
733 f () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
734 @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
|
735 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
736 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
737 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
|
738 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
739 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
740 [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
|
741 @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
|
742 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
743 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
744 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
|
745 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
746 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
|
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 @example |
22845
e23f7f47d8a3
doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
749 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
|
750 @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
|
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 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
753 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
|
754 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
755 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
756 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
|
757 @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
|
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 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
760 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
|
761 @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
|
762 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
763 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
|
764 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
|
765 @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
|
766 @end deftypefn */) |
4700 | 767 { |
768 int nargin = args.length (); | |
769 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
770 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
771 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
772 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
773 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
774 |
4700 | 775 if (nargin == 1) |
776 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
777 octave_value func = args(0); |
4700 | 778 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
779 if (func.is_string ()) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
780 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
781 octave::symbol_table& symtab = interp.get_symbol_table (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
782 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
783 std::string name = func.string_value (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
784 func = symtab.find_function (name); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
785 if (func.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
786 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
|
787 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
788 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
789 if (func.is_inline_function ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
790 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
|
791 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
792 if (func.is_function_handle ()) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
793 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
794 octave_fcn_handle *fh = func.fcn_handle_value (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
795 std::string fh_nm = fh->fcn_name (); |
4930 | 796 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
797 if (fh_nm == octave_fcn_handle::anonymous) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
798 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
|
799 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
800 |
21180
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
801 octave_function *fcn_val = func.function_value (true); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
802 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
803 error ("nargout: FCN must be a string or function handle"); |
4700 | 804 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
805 octave_user_function *fcn = 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
|
806 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
807 if (! fcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
808 { |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22164
diff
changeset
|
809 // 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
|
810 // give up sometimes too? |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
811 |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
812 std::string type = fcn_val->type_name (); |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
813 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
|
814 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
815 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
816 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
817 octave::tree_parameter_list *ret_list = fcn->return_list (); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
818 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23436
diff
changeset
|
819 retval = (ret_list ? ret_list->length () : 0); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
820 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
821 if (fcn->takes_var_return ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
822 retval = -1 - retval; |
4700 | 823 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
824 else |
4700 | 825 { |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
826 if (interp.at_top_level ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
827 error ("nargout: invalid call at top level"); |
4700 | 828 |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
829 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
|
830 |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
831 retval = tw.get_auto_fcn_var (octave::stack_frame::NARGOUT); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
832 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
833 if (retval.is_undefined ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
834 retval = 0; |
4700 | 835 } |
836 | |
837 return retval; | |
838 } | |
839 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
840 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
|
841 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
|
842 @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
|
843 @deftypefnx {} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
844 @deftypefnx {} {} optimize_subsasgn_calls (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
845 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
|
846 optimizations. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
847 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
848 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
|
849 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
|
850 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
851 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
|
852 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
|
853 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
|
854 @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
|
855 @end deftypefn */) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
856 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
857 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
858 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
859 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
860 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
|
861 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
862 if (table.isempty ()) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
863 return false; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
864 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
865 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
|
866 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
|
867 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
868 |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
869 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
|
870 { |
26415
f553b02e13c6
Use "x == fix (x)" to detect integers rather than floor or round (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
871 if (k != octave::math::fix (k) || k <= 0) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
872 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
|
873 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
874 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
|
875 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
876 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
877 DEFMETHOD (isargout, interp, args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
878 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
879 @deftypefn {} {} isargout (@var{k}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
880 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
|
881 @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
|
882 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
883 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
|
884 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
|
885 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
|
886 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
|
887 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
888 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
|
889 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
|
890 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
|
891 @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
|
892 @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
|
893 @end deftypefn */) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
894 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
895 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
896 print_usage (); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
897 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
898 if (interp.at_top_level ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
899 error ("isargout: invalid call at top level"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
900 |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
901 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
|
902 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
903 octave_value tmp; |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
904 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26415
diff
changeset
|
905 int nargout1 = 0; |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
906 tmp = tw.get_auto_fcn_var (octave::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
|
907 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
|
908 nargout1 = tmp.int_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
909 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
910 Matrix ignored; |
27207
242e66e014d9
eliminate direct access to call stack in ov-usr-fcn.cc
John W. Eaton <jwe@octave.org>
parents:
26980
diff
changeset
|
911 tmp = tw.get_auto_fcn_var (octave::stack_frame::IGNORED); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
912 if (tmp.is_defined ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
913 ignored = tmp.matrix_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
914 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
915 if (args(0).is_scalar_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
916 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
917 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
|
918 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
919 return ovl (isargout1 (nargout1, ignored, k)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
920 } |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
921 else if (args(0).isnumeric ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
922 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
923 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
|
924 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
925 boolNDArray r (ka.dims ()); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
926 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
|
927 r(i) = isargout1 (nargout1, ignored, ka(i)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
928 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
929 return ovl (r); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
930 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
931 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21072
diff
changeset
|
932 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
|
933 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
934 return ovl (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
935 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
936 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
937 /* |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
938 %!function [x, y] = try_isargout () |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
939 %! if (isargout (1)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
940 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
941 %! x = 1; y = 2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
942 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
943 %! x = -1; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
944 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
945 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
946 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
947 %! y = -2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
948 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
949 %! error ("no outputs requested"); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
950 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
951 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
952 %!endfunction |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
953 %! |
23482
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
954 %!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
|
955 %! a = y; |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
956 %! 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
|
957 %!endfunction |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
958 %! |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
959 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
960 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
961 %! assert ([x, y], [1, 2]); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
962 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
963 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
964 %! [x, ~] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
965 %! assert (x, -1); |
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 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
968 %! [~, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
969 %! assert (y, -2); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
970 %! |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
971 %!error [~, ~] = try_isargout () |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
972 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
973 ## 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
|
974 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
975 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
976 %! 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
|
977 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
978 ## 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
|
979 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
980 %! [~, y] = try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
981 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
982 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
983 ## 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
|
984 ## 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
|
985 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
986 %! fh = @try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
987 %! af = @() try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
988 %! c = {fh, af}; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
989 %! [~, y] = fh (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
990 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
991 %! [~, y] = af (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
992 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
993 %! [~, y] = c{1}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
994 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
995 %! [~, y] = c{2}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
996 %! assert (y, -2); |
23482
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
997 %! |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
998 ## Nesting, anyone? |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
999 %!test |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1000 %! [~, 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
|
1001 %! assert (b, {0, 1, -1}); |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1002 %!test |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1003 %! [~, 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
|
1004 %! assert (b, {0, 1, {-1, -1}}); |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1005 */ |