Mercurial > octave
annotate libinterp/octave-value/ov-usr-fcn.cc @ 24285:d22d2936f580
store subfunction names in scope instead of function object
* symscope.h (symbol_scope::m_subfunction_names): New data member.
(symbol_scope::has_subfunctions,
symbol_scope::stash_subfunction_names,
symbol_scope::subfunction_names): New functions.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::has_subfunctions,
octave_user_function::stash_subfunction_names,
octave_user_function::subfunction_names): Forward to symbol_scope
functions.
(octave_user_function::subfcn_names): Delete data member.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 19 Nov 2017 21:17:25 -0500 |
parents | bc3819b7cca1 |
children | bc65aa8a5ff1 |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 John W. Eaton |
2974 | 4 |
5 This file is part of Octave. | |
6 | |
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 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
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 |
19 <http://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" |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
34 #include "call-stack.h" |
23466
5da300c55e89
use "" instead of <> for including defaults.h and version.h
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
35 #include "defaults.h" |
3974 | 36 #include "Cell.h" |
2974 | 37 #include "defun.h" |
38 #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
|
39 #include "errwarn.h" |
2974 | 40 #include "input.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
41 #include "ovl.h" |
2974 | 42 #include "ov-usr-fcn.h" |
43 #include "ov.h" | |
44 #include "pager.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
45 #include "pt-eval.h" |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
46 #include "pt-jit.h" |
2985 | 47 #include "pt-jump.h" |
2974 | 48 #include "pt-misc.h" |
49 #include "pt-pr-code.h" | |
2982 | 50 #include "pt-stmt.h" |
2974 | 51 #include "pt-walk.h" |
52 #include "symtab.h" | |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
53 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
54 #include "interpreter.h" |
2974 | 55 #include "unwind-prot.h" |
56 #include "utils.h" | |
3489 | 57 #include "parse.h" |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
58 #include "profiler.h" |
2974 | 59 #include "variables.h" |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
60 #include "ov-fcn-handle.h" |
2974 | 61 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
62 // Whether to optimize subsasgn method calls. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
63 static bool Voptimize_subsasgn_calls = true; |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
64 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
65 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
|
66 { |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
67 delete m_scope; |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
68 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
|
69 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
70 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
71 void |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
72 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
|
73 { |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
74 std::string file_name = fcn_file_name (); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
75 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
76 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
|
77 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
78 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
|
79 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
80 if (fs && (fs.mtime () > time_parsed ())) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
81 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
|
82 file_name.c_str ()); |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
83 } |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
84 |
23728
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
85 std::string |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
86 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
|
87 { |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
88 if (! m_file_info) |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
89 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
|
90 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
91 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
|
92 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
93 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
94 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
|
95 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
|
96 { |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
97 if (! m_file_info) |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
98 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
|
99 |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
100 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
|
101 } |
b40b7243a782
new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents:
23723
diff
changeset
|
102 |
23730
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
103 void |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
104 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
|
105 const octave::sys::time& timestamp) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
106 { |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
107 if (m_file_info) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
108 delete m_file_info; |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
109 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
110 if (timestamp > time_parsed ()) |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
111 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
|
112 |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
113 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
|
114 } |
85f1d31956c0
make echo work for command-line functions
John W. Eaton <jwe@octave.org>
parents:
23729
diff
changeset
|
115 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
116 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
|
117 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
|
118 { |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
119 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
|
120 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
121 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
122 // User defined scripts. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
123 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
124 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
|
125 "user-defined script", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
126 "user-defined script"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
127 |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
128 octave_user_script::octave_user_script (void) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
129 : octave_user_code (), cmd_list (nullptr), file_name (), |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
130 t_parsed (static_cast<time_t> (0)), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
131 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
132 call_depth (-1) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
133 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
134 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
135 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
|
136 (const std::string& fnm, const std::string& nm, |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
137 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
|
138 const std::string& ds) |
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
139 : octave_user_code (nm, scope, ds), cmd_list (cmds), file_name (fnm), |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
140 t_parsed (static_cast<time_t> (0)), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
141 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
142 call_depth (-1) |
7736 | 143 { |
144 if (cmd_list) | |
145 cmd_list->mark_as_script_body (); | |
146 } | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
147 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
148 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
|
149 (const std::string& fnm, const std::string& nm, |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
150 octave::symbol_scope *scope, const std::string& ds) |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
151 : octave_user_code (nm, scope, ds), cmd_list (nullptr), file_name (fnm), |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
152 t_parsed (static_cast<time_t> (0)), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
153 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
154 call_depth (-1) |
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 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
157 octave_user_script::~octave_user_script (void) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
158 { |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
159 if (cmd_list) |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
160 cmd_list->remove_all_breakpoints (file_name); |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
161 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
162 delete cmd_list; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
163 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
164 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
165 octave_value_list |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
166 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
|
167 const octave_value_list& args) |
7336 | 168 { |
169 octave_value_list retval; | |
170 | |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
171 octave::unwind_protect frame; |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
172 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
173 if (args.length () != 0 || nargout != 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
174 error ("invalid call to script %s", file_name.c_str ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
175 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
176 if (cmd_list) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
177 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
178 frame.protect_var (call_depth); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
179 call_depth++; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
180 |
23705
4c597585ff52
move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23704
diff
changeset
|
181 if (call_depth >= tw.max_recursion_depth ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
182 error ("max_recursion_depth exceeded"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
183 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
184 octave::call_stack& cs |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
185 = octave::__get_call_stack__ ("octave_user_script::call"); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
186 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
187 cs.push (this); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
188 |
23729
06b3d1d54054
allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents:
23728
diff
changeset
|
189 // Set pointer to the current unwind_protect frame to allow |
06b3d1d54054
allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents:
23728
diff
changeset
|
190 // certain builtins register simple cleanup in a very optimized manner. |
06b3d1d54054
allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents:
23728
diff
changeset
|
191 // This is *not* intended as a general-purpose on-cleanup mechanism, |
06b3d1d54054
allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents:
23728
diff
changeset
|
192 frame.protect_var (curr_unwind_protect_frame); |
06b3d1d54054
allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents:
23728
diff
changeset
|
193 curr_unwind_protect_frame = &frame; |
06b3d1d54054
allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents:
23728
diff
changeset
|
194 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
195 frame.add_method (cs, &octave::call_stack::pop); |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
196 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
197 // Update line number even if debugging. |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22097
diff
changeset
|
198 frame.protect_var (Vtrack_line_num); |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
199 Vtrack_line_num = true; |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22097
diff
changeset
|
200 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
201 frame.protect_var (octave::tree_evaluator::statement_context); |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
202 octave::tree_evaluator::statement_context = octave::tree_evaluator::script; |
19327
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18699
diff
changeset
|
203 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
204 octave::profiler& profiler = tw.get_profiler (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
205 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
206 octave::profiler::enter<octave_user_script> block (profiler, *this); |
7336 | 207 |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
208 frame.add_method (m_scope, |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
209 &octave::symbol_scope::unbind_script_symbols); |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
210 m_scope->bind_script_symbols (tw.get_current_scope ()); |
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
211 |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
212 if (tw.echo ()) |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
213 tw.push_echo_state (frame, octave::tree_evaluator::ECHO_SCRIPTS, |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
214 file_name); |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
215 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
216 cmd_list->accept (tw); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
217 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
218 if (octave::tree_return_command::returning) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
219 octave::tree_return_command::returning = 0; |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
220 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
221 if (octave::tree_break_command::breaking) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
222 octave::tree_break_command::breaking--; |
7336 | 223 } |
224 | |
225 return retval; | |
226 } | |
227 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
228 void |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
229 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
|
230 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
231 tw.visit_octave_user_script (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
232 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
233 |
2974 | 234 // User defined functions. |
235 | |
3219 | 236 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
|
237 "user-defined function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 "user-defined function"); |
2974 | 239 |
240 // Ugh. This really needs to be simplified (code/data? | |
241 // extrinsic/intrinsic state?). | |
242 | |
243 octave_user_function::octave_user_function | |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
244 (octave::symbol_scope *scope, octave::tree_parameter_list *pl, |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
245 octave::tree_parameter_list *rl, octave::tree_statement_list *cl) |
24037
21915520ac7b
use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents:
23974
diff
changeset
|
246 : octave_user_code ("", scope, ""), |
2974 | 247 param_list (pl), ret_list (rl), cmd_list (cl), |
7336 | 248 lead_comm (), trail_comm (), file_name (), |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
249 location_line (0), location_column (0), |
6323 | 250 parent_name (), t_parsed (static_cast<time_t> (0)), |
3255 | 251 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
252 system_fcn_file (false), call_depth (-1), |
7589
90fb25a5a3fa
minor cleanup in octave_user_function constructor
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
253 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
|
254 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
|
255 anonymous_function (false), nested_function (false), |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
256 class_constructor (none), class_method (false), |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23753
diff
changeset
|
257 parent_scope (nullptr) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
258 #if defined (HAVE_LLVM) |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
259 , jit_info (0) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
260 #endif |
7736 | 261 { |
262 if (cmd_list) | |
263 cmd_list->mark_as_function_body (); | |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
264 |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
265 if (m_scope) |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
266 m_scope->set_function (this); |
7736 | 267 } |
2974 | 268 |
269 octave_user_function::~octave_user_function (void) | |
270 { | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
271 // FIXME: shouldn't this happen automatically when deleting cmd_list? |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
272 if (cmd_list) |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
273 cmd_list->remove_all_breakpoints (file_name); |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
274 |
2974 | 275 delete param_list; |
276 delete ret_list; | |
277 delete cmd_list; | |
3665 | 278 delete lead_comm; |
279 delete trail_comm; | |
7336 | 280 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
281 #if defined (HAVE_LLVM) |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
282 delete jit_info; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
283 #endif |
2974 | 284 } |
285 | |
286 octave_user_function * | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
287 octave_user_function::define_ret_list (octave::tree_parameter_list *t) |
2974 | 288 { |
289 ret_list = t; | |
290 | |
291 return this; | |
292 } | |
293 | |
294 void | |
4343 | 295 octave_user_function::stash_fcn_file_name (const std::string& nm) |
2974 | 296 { |
4343 | 297 file_name = nm; |
2974 | 298 } |
299 | |
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
|
300 // 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
|
301 // 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
|
302 // 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
|
303 // 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
|
304 // 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
|
305 // 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
|
306 // 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
|
307 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
308 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
|
309 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
|
310 { |
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
|
311 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
|
312 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
313 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
|
314 |
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
|
315 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
|
316 && 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
|
317 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
318 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
|
319 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
|
320 |
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
|
321 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
|
322 |
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
|
323 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
|
324 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
|
325 |
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
|
326 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
|
327 { |
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
|
328 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
|
329 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
|
330 } |
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
|
331 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
|
332 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
333 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
|
334 |
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
|
335 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
|
336 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
|
337 } |
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
|
338 |
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
|
339 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
|
340 } |
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
|
341 } |
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
|
342 } |
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
|
343 |
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
|
344 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
|
345 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
|
346 { |
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
|
347 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
|
348 |
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
|
349 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
|
350 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22853
diff
changeset
|
351 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
|
352 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22853
diff
changeset
|
353 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
|
354 |
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
|
355 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
|
356 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
|
357 } |
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
|
358 } |
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
|
359 |
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
|
360 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
|
361 } |
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
|
362 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
363 void |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
364 octave_user_function::stash_parent_fcn_scope (octave::symbol_scope *ps) |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
365 { |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
366 parent_scope = ps; |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
367 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
368 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
369 std::string |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
370 octave_user_function::profiler_name (void) const |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
371 { |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
372 std::ostringstream result; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
373 |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
374 if (is_anonymous_function ()) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
375 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
|
376 << ':' << location_line << ':' << location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 result << '@' << dispatch_class () << '/' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
381 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
|
382 result << '@' << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
383 else if (is_inline_function ()) |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
384 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
|
385 << ':' << location_line << ':' << location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
386 else |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
387 result << name (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
388 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
389 return result.str (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
390 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
391 |
2974 | 392 void |
393 octave_user_function::mark_as_system_fcn_file (void) | |
394 { | |
395 if (! file_name.empty ()) | |
396 { | |
397 // We really should stash the whole path to the file we found, | |
398 // when we looked it up, to avoid possible race conditions... | |
5775 | 399 // FIXME |
2974 | 400 // |
401 // We probably also don't need to get the library directory | |
402 // every time, but since this function is only called when the | |
403 // function file is parsed, it probably doesn't matter that | |
404 // much. | |
405 | |
3523 | 406 std::string ff_name = fcn_file_in_path (file_name); |
2974 | 407 |
23717
06579337237b
move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents:
23716
diff
changeset
|
408 std::string fcn_file_dir = octave::config::fcn_file_dir (); |
06579337237b
move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents:
23716
diff
changeset
|
409 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
|
410 system_fcn_file = true; |
2974 | 411 } |
412 else | |
14866
2309812f428e
Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14861
diff
changeset
|
413 system_fcn_file = false; |
2974 | 414 } |
415 | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
416 void |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
417 octave_user_function::erase_subfunctions (void) |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
418 { |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
419 m_scope->erase_subfunctions (); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
420 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
421 |
2974 | 422 bool |
423 octave_user_function::takes_varargs (void) const | |
424 { | |
425 return (param_list && param_list->takes_varargs ()); | |
426 } | |
427 | |
5848 | 428 bool |
429 octave_user_function::takes_var_return (void) const | |
2974 | 430 { |
5848 | 431 return (ret_list && ret_list->takes_varargs ()); |
2974 | 432 } |
433 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
434 void |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
435 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
|
436 { |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
437 m_scope->mark_subfunctions_in_scope_as_private (cname); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
438 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
439 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
|
440 } |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
441 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
442 void |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
443 octave_user_function::lock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
444 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
445 m_scope->lock_subfunctions (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
446 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
447 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
448 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
449 octave_user_function::unlock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
450 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
451 m_scope->unlock_subfunctions (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
452 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
453 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
454 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
|
455 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
|
456 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
457 return m_scope->subfunctions (); |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
458 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
459 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
460 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
|
461 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
|
462 { |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
463 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
|
464 } |
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
|
465 |
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
|
466 void |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
467 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
|
468 { |
24285
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
469 m_scope->stash_subfunction_names (names); |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
470 } |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
471 |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
472 std::list<std::string> |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
473 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
|
474 { |
d22d2936f580
store subfunction names in scope instead of function object
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
475 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
|
476 } |
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
|
477 |
2974 | 478 octave_value_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
479 octave_user_function::all_va_args (const octave_value_list& args) |
2974 | 480 { |
481 octave_value_list retval; | |
482 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
483 octave_idx_type n = args.length () - num_named_args; |
2974 | 484 |
3178 | 485 if (n > 0) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
486 retval = args.slice (num_named_args, n); |
2974 | 487 |
488 return retval; | |
489 } | |
490 | |
491 octave_value_list | |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
492 octave_user_function::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
|
493 const octave_value_list& _args) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
494 { |
2974 | 495 octave_value_list retval; |
496 | |
497 if (! cmd_list) | |
498 return retval; | |
499 | |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
500 // If this function is a classdef constructor, extract the first input |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
501 // argument, which must be the partially constructed object instance. |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
502 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
503 octave_value_list args (_args); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
504 octave_value_list ret_args; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
505 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
506 if (is_classdef_constructor ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
507 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
508 if (args.length () > 0) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
509 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
510 ret_args = args.slice (0, 1, true); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
511 args = args.slice (1, args.length () - 1, true); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
512 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
513 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
514 panic_impossible (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
515 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
516 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21581
diff
changeset
|
517 #if defined (HAVE_LLVM) |
15582
52df2e7baabe
Disable JIT when breakpoints are present
Max Brister <max@2bass.com>
parents:
15427
diff
changeset
|
518 if (is_special_expr () |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
519 && octave::tree_jit::execute (*this, args, retval)) |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
520 return retval; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
521 #endif |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
522 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
523 octave::unwind_protect frame; |
2974 | 524 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
525 frame.protect_var (call_depth); |
2974 | 526 call_depth++; |
527 | |
23705
4c597585ff52
move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23704
diff
changeset
|
528 if (call_depth >= tw.max_recursion_depth ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
529 error ("max_recursion_depth exceeded"); |
3131 | 530 |
7336 | 531 // Save old and set current symbol table context, for |
532 // eval_undefined_error(). | |
533 | |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
534 octave::call_stack& cs |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
535 = octave::__get_call_stack__ ("octave_user_function::call"); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
536 |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23680
diff
changeset
|
537 octave::symbol_table::context_id context = anonymous_function ? 0 : call_depth; |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
538 cs.push (this, m_scope, context); |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22097
diff
changeset
|
539 |
23704
c495549e9a94
refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
540 // Set pointer to the current unwind_protect frame to allow |
c495549e9a94
refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
541 // certain builtins register simple cleanup in a very optimized manner. |
c495549e9a94
refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
542 // This is *not* intended as a general-purpose on-cleanup mechanism, |
c495549e9a94
refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
543 frame.protect_var (curr_unwind_protect_frame); |
c495549e9a94
refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
544 curr_unwind_protect_frame = &frame; |
c495549e9a94
refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents:
23693
diff
changeset
|
545 |
22164
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22097
diff
changeset
|
546 frame.protect_var (Vtrack_line_num); |
5d4a286061c8
Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22097
diff
changeset
|
547 Vtrack_line_num = true; // update source line numbers, even if debugging |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
548 frame.add_method (cs, &octave::call_stack::pop); |
7901 | 549 |
14328
19078011cdc3
fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents:
14139
diff
changeset
|
550 if (call_depth > 0 && ! is_anonymous_function ()) |
2974 | 551 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
552 m_scope->push_context (); |
2974 | 553 |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
554 #if 0 |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
555 std::cerr << name () << " scope: " << m_scope |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
556 << " call depth: " << call_depth |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
557 << " context: " << m_scope->current_context () << std::endl; |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
558 #endif |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
559 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
560 frame.add_method (m_scope, &octave::symbol_scope::pop_context); |
7336 | 561 } |
2974 | 562 |
23974
384561642b36
record all input parameters to clasdef constructors (bug #49379)
Markus Mützel <markus.muetzel@gmx.de>
parents:
23916
diff
changeset
|
563 string_vector arg_names = _args.name_tags (); |
2974 | 564 |
565 if (param_list && ! param_list->varargs_only ()) | |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
566 { |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
567 #if 0 |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
568 std::cerr << "defining param list, scope: " << m_scope |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
569 << ", context: " << m_scope->current_context () << std::endl; |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
570 #endif |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
571 tw.define_parameter_list_from_arg_vector (param_list, args); |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
572 } |
2974 | 573 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
574 // For classdef constructor, pre-populate the output arguments |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
575 // with the pre-initialized object instance, extracted above. |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
576 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
577 if (is_classdef_constructor ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
578 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
579 if (! ret_list) |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
580 error ("%s: invalid classdef constructor, no output argument defined", |
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
581 dispatch_class ().c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
582 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
583 tw.define_parameter_list_from_arg_vector (ret_list, ret_args); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
584 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
585 |
3239 | 586 // Force parameter list to be undefined when this function exits. |
587 // Doing so decrements the reference counts on the values of local | |
588 // variables that are also named function parameters. | |
589 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
590 if (param_list) |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
591 frame.add_method (&tw, &octave::tree_evaluator::undefine_parameter_list, |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
592 param_list); |
3239 | 593 |
594 // Force return list to be undefined when this function exits. | |
595 // Doing so decrements the reference counts on the values of local | |
596 // variables that are also named values returned by this function. | |
597 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
598 if (ret_list) |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
599 frame.add_method (&tw, &octave::tree_evaluator::undefine_parameter_list, |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
600 ret_list); |
3239 | 601 |
8142
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
602 if (call_depth == 0) |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
603 { |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
604 // Force symbols to be undefined again when this function |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
605 // exits. |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
606 // |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
607 // This cleanup function is added to the unwind_protect stack |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
608 // after the calls to clear the parameter lists so that local |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
609 // variables will be cleared before the parameter lists are |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
610 // cleared. That way, any function parameters that have been |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
611 // declared global will be unmarked as global before they are |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
612 // undefined by the clear_param_list cleanup function. |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
613 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
614 frame.add_method (m_scope, &octave::symbol_scope::clear_variables); |
8142
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
615 } |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
616 |
23481
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23466
diff
changeset
|
617 bind_automatic_vars (tw, arg_names, args.length (), nargout, |
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23466
diff
changeset
|
618 all_va_args (args)); |
2974 | 619 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
620 frame.add_method (this, &octave_user_function::restore_warning_states); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
621 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
622 // Evaluate the commands that make up the function. |
2974 | 623 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
624 frame.protect_var (octave::tree_evaluator::statement_context); |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
625 octave::tree_evaluator::statement_context = octave::tree_evaluator::function; |
3489 | 626 |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
627 { |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
628 octave::profiler& profiler = tw.get_profiler (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
629 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23730
diff
changeset
|
630 octave::profiler::enter<octave_user_function> block (profiler, *this); |
6657 | 631 |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
632 if (tw.echo ()) |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
633 tw.push_echo_state (frame, octave::tree_evaluator::ECHO_FUNCTIONS, |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
634 file_name); |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
635 |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
636 if (is_special_expr ()) |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
637 { |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
638 assert (cmd_list->length () == 1); |
22253
dbf7fd79e391
More informative messages for errors in anonymous functions (bug #46136).
Olaf Till <olaf.till@uni-jena.de>
parents:
22196
diff
changeset
|
639 |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
640 octave::tree_statement *stmt = cmd_list->front (); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
641 |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
642 octave::tree_expression *expr = stmt->expression (); |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
643 |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
644 if (expr) |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
645 { |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
646 cs.set_location (stmt->line (), stmt->column ()); |
22253
dbf7fd79e391
More informative messages for errors in anonymous functions (bug #46136).
Olaf Till <olaf.till@uni-jena.de>
parents:
22196
diff
changeset
|
647 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
648 retval = tw.evaluate_n (expr, nargout); |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
649 } |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
650 } |
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
651 else |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
652 cmd_list->accept (tw); |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
653 } |
2974 | 654 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
655 if (octave::tree_return_command::returning) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
656 octave::tree_return_command::returning = 0; |
2974 | 657 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
658 if (octave::tree_break_command::breaking) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
659 octave::tree_break_command::breaking--; |
2974 | 660 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
661 // Copy return values out. |
2974 | 662 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
663 if (ret_list && ! is_special_expr ()) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
664 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
665 Cell varargout; |
6591 | 666 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
667 if (ret_list->takes_varargs ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
668 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
669 octave_value varargout_varval = m_scope->varval ("varargout"); |
5848 | 670 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
671 if (varargout_varval.is_defined ()) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
672 varargout = varargout_varval.xcell_value ("varargout must be a cell array object"); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
673 } |
2974 | 674 |
23916
85488effc0ff
refactor function value return code
John W. Eaton <jwe@octave.org>
parents:
23850
diff
changeset
|
675 retval = tw.convert_return_list_to_const_vector (ret_list, nargout, varargout); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
676 } |
2974 | 677 |
678 return retval; | |
679 } | |
680 | |
681 void | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
682 octave_user_function::accept (octave::tree_walker& tw) |
2974 | 683 { |
684 tw.visit_octave_user_function (*this); | |
685 } | |
686 | |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
687 octave::tree_expression * |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
688 octave_user_function::special_expr (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
689 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
690 assert (is_special_expr ()); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
691 assert (cmd_list->length () == 1); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
692 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
693 octave::tree_statement *stmt = cmd_list->front (); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
694 return stmt->expression (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
695 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
696 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
697 bool |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
698 octave_user_function::subsasgn_optimization_ok (void) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
699 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
700 bool retval = false; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
701 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
|
702 && param_list && ret_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
703 && param_list->length () > 0 && ! param_list->varargs_only () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
704 && ret_list->length () == 1 && ! ret_list->takes_varargs ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
705 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
706 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
|
707 octave::tree_identifier *ret1 = ret_list->front ()->ident (); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
708 retval = par1->name () == ret1->name (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
709 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
710 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
711 return retval; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
712 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
713 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
714 std::string |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
715 octave_user_function::ctor_type_str (void) const |
3933 | 716 { |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
717 std::string retval; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
718 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
719 switch (class_constructor) |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
720 { |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
721 case none: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
722 retval = "none"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
723 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
724 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
725 case legacy: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
726 retval = "legacy"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
727 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
728 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
729 case classdef: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
730 retval = "classdef"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
731 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
732 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
733 default: |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
734 retval = "unrecognized enum value"; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
735 break; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
736 } |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
737 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
738 return retval; |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
739 } |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
740 |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
741 octave_value |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
742 octave_user_function::dump (void) const |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
743 { |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
744 std::map<std::string, octave_value> m |
23718
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
745 = {{ "file_name", file_name }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
746 { "line", location_line }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
747 { "col", location_column }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
748 { "end_line", end_location_line }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
749 { "end_col", end_location_column }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
750 { "time_parsed", t_parsed }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
751 { "time_checked", t_checked }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
752 { "parent_name", parent_name }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
753 { "system_fcn_file", system_fcn_file }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
754 { "call_depth", call_depth }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
755 { "num_named_args", num_named_args }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
756 { "subfunction", subfunction }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
757 { "inline_function", inline_function }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
758 { "anonymous_function", anonymous_function }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
759 { "nested_function", nested_function }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
760 { "ctor_type", ctor_type_str () }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
761 { "class_method", class_method }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
762 { "parent_scope", parent_scope ? parent_scope->name () : "0x0" }, |
251cb33c6570
style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents:
23717
diff
changeset
|
763 { "scope_info", m_scope ? m_scope->dump () : "0x0" }}; |
23680
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
764 |
ef71711f6d64
rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
765 return octave_value (m); |
3933 | 766 } |
767 | |
768 void | |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
769 octave_user_function::print_code_function_header (const std::string& prefix) |
2974 | 770 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
771 octave::tree_print_code tpc (octave_stdout, prefix); |
2974 | 772 |
773 tpc.visit_octave_user_function_header (*this); | |
774 } | |
775 | |
776 void | |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
777 octave_user_function::print_code_function_trailer (const std::string& prefix) |
2974 | 778 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23718
diff
changeset
|
779 octave::tree_print_code tpc (octave_stdout, prefix); |
2974 | 780 |
781 tpc.visit_octave_user_function_trailer (*this); | |
782 } | |
783 | |
784 void | |
785 octave_user_function::bind_automatic_vars | |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
786 (octave::tree_evaluator& tw, const string_vector& arg_names, |
23481
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23466
diff
changeset
|
787 int nargin, int nargout, const octave_value_list& va_args) |
2974 | 788 { |
789 if (! arg_names.empty ()) | |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
790 { |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
791 // It is better to save this in the hidden variable .argn. and |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
792 // then use that in the inputname function instead of using argn, |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
793 // which might be redefined in a function. Keep the old argn name |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
794 // for backward compatibility of functions that use it directly. |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
795 |
23706
6683451b75b2
move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23705
diff
changeset
|
796 charMatrix chm (arg_names, tw.string_fill_char ()); |
6683451b75b2
move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23705
diff
changeset
|
797 m_scope->force_assign ("argn", chm); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
798 m_scope->force_assign (".argn.", Cell (arg_names)); |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
799 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
800 m_scope->mark_hidden (".argn."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
801 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
802 m_scope->mark_automatic ("argn"); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
803 m_scope->mark_automatic (".argn."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
804 } |
2974 | 805 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
806 m_scope->force_assign (".nargin.", nargin); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
807 m_scope->force_assign (".nargout.", nargout); |
7336 | 808 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
809 m_scope->mark_hidden (".nargin."); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
810 m_scope->mark_hidden (".nargout."); |
3974 | 811 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
812 m_scope->mark_automatic (".nargin."); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
813 m_scope->mark_automatic (".nargout."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
814 |
23850
4b0e0cae49db
disallow dynamic variable creation in static scopes (bug #51698)
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
815 m_scope->force_assign (".saved_warning_states.", octave_value ()); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
816 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
817 m_scope->mark_automatic (".saved_warning_states."); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
818 m_scope->mark_automatic (".saved_warning_states."); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
819 |
3974 | 820 if (takes_varargs ()) |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
821 m_scope->assign ("varargin", va_args.cell_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
822 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23520
diff
changeset
|
823 Matrix ignored_fcn_outputs = tw.ignored_fcn_outputs (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
824 |
23850
4b0e0cae49db
disallow dynamic variable creation in static scopes (bug #51698)
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
825 m_scope->force_assign (".ignored.", ignored_fcn_outputs); |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
826 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
827 m_scope->mark_hidden (".ignored."); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
828 m_scope->mark_automatic (".ignored."); |
2974 | 829 } |
830 | |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
831 void |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
832 octave_user_function::restore_warning_states (void) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
833 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
834 octave_value val = m_scope->varval (".saved_warning_states."); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
835 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
836 if (val.is_defined ()) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
837 { |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
838 // Fail spectacularly if .saved_warning_states. is not an |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
839 // octave_map (or octave_scalar_map) object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
840 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
841 if (! val.isstruct ()) |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
842 panic_impossible (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
843 |
17612
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
844 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
|
845 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
846 Cell ids = m.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
847 Cell states = m.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
848 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
849 octave::interpreter& interp |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
850 = octave::__get_interpreter__ ("octave_user_function::restore_warning_states"); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
851 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
852 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
|
853 Fwarning (interp, ovl (states(i), ids(i))); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
854 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
855 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
856 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
857 DEFMETHOD (nargin, interp, args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
858 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
|
859 @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
|
860 @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
|
861 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
|
862 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
863 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
|
864 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
|
865 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
|
866 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
867 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
|
868 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
|
869 accept. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
870 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
871 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
|
872 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
|
873 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
874 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
875 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
876 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
|
877 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
878 and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
879 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
880 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
|
881 @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
|
882 @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
|
883 @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
|
884 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
885 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
|
886 (@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
|
887 @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
|
888 @end deftypefn */) |
4700 | 889 { |
890 int nargin = args.length (); | |
891 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
892 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
893 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
894 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
895 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
896 |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23680
diff
changeset
|
897 octave::symbol_table& symtab = interp.get_symbol_table (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
898 |
4700 | 899 if (nargin == 1) |
900 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
901 octave_value func = args(0); |
4700 | 902 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
903 if (func.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
904 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
905 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
|
906 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
|
907 if (func.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
908 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
|
909 } |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
910 |
21179
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
911 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
|
912 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
913 error ("nargin: FCN must be a string or function handle"); |
4700 | 914 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
915 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
|
916 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
917 if (! fcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
918 { |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22164
diff
changeset
|
919 // 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
|
920 // give up sometimes too? |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
921 |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
922 std::string type = fcn_val->type_name (); |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
923 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
|
924 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
925 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
926 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
927 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
|
928 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23436
diff
changeset
|
929 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
|
930 if (fcn->takes_varargs ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
931 retval = -1 - retval; |
4700 | 932 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
933 else |
4700 | 934 { |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
935 octave::symbol_scope *scope = symtab.require_current_scope ("nargin"); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
936 retval = scope->varval (".nargin."); |
4700 | 937 |
7336 | 938 if (retval.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
939 retval = 0; |
4700 | 940 } |
941 | |
942 return retval; | |
943 } | |
944 | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
945 DEFMETHOD (nargout, interp,args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
946 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
|
947 @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
|
948 @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
|
949 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
|
950 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
951 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
|
952 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
|
953 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
|
954 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
955 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
|
956 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
|
957 produce. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
958 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
959 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
|
960 negative. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
961 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
962 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
|
963 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
964 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
965 f () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
966 @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
|
967 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
968 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
969 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
|
970 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
971 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
972 [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
|
973 @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
|
974 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
975 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
976 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
|
977 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
978 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
|
979 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
980 @example |
22845
e23f7f47d8a3
doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
981 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
|
982 @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
|
983 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
984 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
985 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
|
986 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
987 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
988 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
|
989 @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
|
990 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
991 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
992 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
|
993 @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
|
994 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
995 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
|
996 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
|
997 @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
|
998 @end deftypefn */) |
4700 | 999 { |
1000 int nargin = args.length (); | |
1001 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1002 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1003 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1004 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1005 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1006 |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23680
diff
changeset
|
1007 octave::symbol_table& symtab = interp.get_symbol_table (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1008 |
4700 | 1009 if (nargin == 1) |
1010 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1011 octave_value func = args(0); |
4700 | 1012 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1013 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
|
1014 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1015 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
|
1016 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
|
1017 if (func.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1018 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
|
1019 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1020 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1021 if (func.is_inline_function ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1022 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
|
1023 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1024 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
|
1025 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1026 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
|
1027 std::string fh_nm = fh->fcn_name (); |
4930 | 1028 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1029 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
|
1030 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
|
1031 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
1032 |
21180
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
1033 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
|
1034 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1035 error ("nargout: FCN must be a string or function handle"); |
4700 | 1036 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1037 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
|
1038 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1039 if (! fcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1040 { |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22164
diff
changeset
|
1041 // 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
|
1042 // give up sometimes too? |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
1043 |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
1044 std::string type = fcn_val->type_name (); |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
1045 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
|
1046 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1047 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1048 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1049 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
|
1050 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23436
diff
changeset
|
1051 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
|
1052 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1053 if (fcn->takes_var_return ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1054 retval = -1 - retval; |
4700 | 1055 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1056 else |
4700 | 1057 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1058 if (symtab.at_top_level ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1059 error ("nargout: invalid call at top level"); |
4700 | 1060 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
1061 octave::symbol_scope *scope = symtab.require_current_scope ("nargout"); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
1062 retval = scope->varval (".nargout."); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1063 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1064 if (retval.is_undefined ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1065 retval = 0; |
4700 | 1066 } |
1067 | |
1068 return retval; | |
1069 } | |
1070 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1071 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
|
1072 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
|
1073 @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
|
1074 @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
|
1075 @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
|
1076 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
|
1077 optimizations. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1078 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1079 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
|
1080 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
|
1081 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1082 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
|
1083 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
|
1084 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
|
1085 @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
|
1086 @end deftypefn */) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1087 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1088 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1089 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1090 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1091 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
|
1092 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
1093 if (table.isempty ()) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1094 return false; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1095 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1096 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
|
1097 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
|
1098 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1099 |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1100 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
|
1101 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
1102 if (k != octave::math::round (k) || k <= 0) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1103 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
|
1104 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1105 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
|
1106 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1107 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1108 DEFMETHOD (isargout, interp, args, , |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1109 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
|
1110 @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
|
1111 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
|
1112 @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
|
1113 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
1119 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
|
1120 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
|
1121 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
|
1122 @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
|
1123 @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
|
1124 @end deftypefn */) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1125 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
1126 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1127 print_usage (); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1128 |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23680
diff
changeset
|
1129 octave::symbol_table& symtab = interp.get_symbol_table (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1130 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1131 if (symtab.at_top_level ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1132 error ("isargout: invalid call at top level"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1133 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
24037
diff
changeset
|
1134 octave::symbol_scope *scope = symtab.require_current_scope ("isargout"); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
1135 |
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
1136 int nargout1 = scope->varval (".nargout.").int_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1137 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1138 Matrix ignored; |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
1139 octave_value tmp = scope->varval (".ignored."); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1140 if (tmp.is_defined ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1141 ignored = tmp.matrix_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1142 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1143 if (args(0).is_scalar_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1144 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1145 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
|
1146 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1147 return ovl (isargout1 (nargout1, ignored, k)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1148 } |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
1149 else if (args(0).isnumeric ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1150 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1151 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
|
1152 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1153 boolNDArray r (ka.dims ()); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1154 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
|
1155 r(i) = isargout1 (nargout1, ignored, ka(i)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1156 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1157 return ovl (r); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1158 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1159 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21072
diff
changeset
|
1160 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
|
1161 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1162 return ovl (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1163 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1164 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1165 /* |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1166 %!function [x, y] = try_isargout () |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1167 %! if (isargout (1)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1168 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1169 %! x = 1; y = 2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1170 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1171 %! x = -1; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1172 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1173 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1174 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1175 %! y = -2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1176 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1177 %! error ("no outputs requested"); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1178 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1179 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1180 %!endfunction |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1181 %! |
23482
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1182 %!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
|
1183 %! a = y; |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1184 %! 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
|
1185 %!endfunction |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1186 %! |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1187 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1188 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1189 %! assert ([x, y], [1, 2]); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1190 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1191 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1192 %! [x, ~] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1193 %! assert (x, -1); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1194 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1195 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1196 %! [~, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1197 %! assert (y, -2); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1198 %! |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1199 %!error [~, ~] = try_isargout () |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1200 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1201 ## 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
|
1202 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1203 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1204 %! 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
|
1205 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1206 ## 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
|
1207 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1208 %! [~, y] = try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1209 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1210 %! |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1211 ## 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
|
1212 ## 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
|
1213 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1214 %! fh = @try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1215 %! af = @() try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1216 %! c = {fh, af}; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1217 %! [~, y] = fh (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1218 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1219 %! [~, y] = af (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1220 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1221 %! [~, y] = c{1}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1222 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1223 %! [~, y] = c{2}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1224 %! assert (y, -2); |
23482
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1225 %! |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1226 ## Nesting, anyone? |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1227 %!test |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1228 %! [~, 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
|
1229 %! assert (b, {0, 1, -1}); |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1230 %!test |
c9937e865768
make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents:
23481
diff
changeset
|
1231 %! [~, 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
|
1232 %! assert (b, {0, 1, {-1, -1}}); |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1233 */ |