annotate libinterp/octave-value/ov-usr-fcn.cc @ 33364:9108c5b24626 bytecode-interpreter

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