annotate libinterp/corefcn/call-stack.cc @ 27919:1891570abac8

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2020.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 22:29:51 -0500
parents b442ec6dda5c
children bd51beb6205e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 Copyright (C) 1995-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27873
diff changeset
4
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27873
diff changeset
5 See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27873
diff changeset
6 or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27873
diff changeset
7
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 This file is part of Octave.
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
diff changeset
11 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
12 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
diff changeset
13 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
14 (at your option) any later version.
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
16 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
17 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
19 GNU General Public License for more details.
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 You should have received a copy of the GNU General Public License
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
diff changeset
23 <https://www.gnu.org/licenses/>.
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 */
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #if defined (HAVE_CONFIG_H)
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 # include "config.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #endif
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
31 #include <iostream>
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
32
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
33 #include "lo-regexp.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
34 #include "str-vec.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
35
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "call-stack.h"
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
37 #include "defun.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
38 #include "interpreter.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
39 #include "interpreter-private.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "oct-map.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "ov.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "ov-fcn.h"
22253
dbf7fd79e391 More informative messages for errors in anonymous functions (bug #46136).
Olaf Till <olaf.till@uni-jena.de>
parents: 22091
diff changeset
43 #include "ov-fcn-handle.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "ov-usr-fcn.h"
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
45 #include "pager.h"
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
46 #include "parse.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
47 #include "stack-frame.h"
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
48 #include "stack-frame-walker.h"
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
49 #include "syminfo.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
50 #include "syminfo-accumulator.h"
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
51 #include "symrec.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
52 #include "symscope.h"
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
53 #include "variables.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
55 namespace octave
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 {
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
57 // Use static fields for the best efficiency.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
58 // NOTE: C++0x will allow these two to be merged into one.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
59 static const char *bt_fieldnames[] =
27470
96d4094585da eliminate unused backtrace field name "scope"
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
60 { "file", "name", "line", "column", nullptr };
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
61
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
62 static const octave_fields bt_fields (bt_fieldnames);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
63
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
64 call_stack::call_stack (tree_evaluator& evaluator)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
65 : m_evaluator (evaluator), m_cs (), m_curr_frame (0),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
66 m_max_stack_depth (1024), m_global_values ()
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
67 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
68 push (symbol_scope ("top scope"));
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
69 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
71 octave_function * call_stack::current_function (bool skip_first) const
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
72 {
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
73 if (m_cs.empty ())
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
74 error ("current_function: call stack is empty");
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
75
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
76 octave_function *fcn = nullptr;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
77
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
78 size_t idx = size ();
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
79
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
80 if (idx > 1 && skip_first)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
81 --idx;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
82
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
83 while (--idx)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
84 {
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
85 fcn = m_cs[idx]->function ();
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
86
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
87 if (fcn)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
88 break;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
89 }
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
90
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
91 return fcn;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
92 }
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
93
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
94 int call_stack::current_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
95 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
96 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
98 if (! m_cs.empty ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
99 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
100 const stack_frame *elt = m_cs[m_curr_frame];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
101 retval = elt->line ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
102 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
103
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
104 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
105 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
106
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
107 int call_stack::current_column (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
108 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
109 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
111 if (! m_cs.empty ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
112 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
113 const stack_frame *elt = m_cs[m_curr_frame];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
114 retval = elt->column ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
115 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
116
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
117 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
118 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
119
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
120 octave_user_code * call_stack::current_user_code (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
121 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
122 // Start at current frame.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
123
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
124 size_t xframe = find_current_user_frame ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
126 if (xframe > 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
127 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
128 const stack_frame *elt = m_cs[xframe];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
129
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
130 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
132 if (f && f->is_user_code ())
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
133 return dynamic_cast<octave_user_code *> (f);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
134 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
135
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
136 return nullptr;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
137 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
138
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
139 int call_stack::current_user_code_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
140 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
141 // Start at current frame.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
142
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
143 size_t xframe = find_current_user_frame ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
145 if (xframe > 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
146 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
147 const stack_frame *elt = m_cs[xframe];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
148
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
149 octave_function *f = elt->function ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
150
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
151 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
152 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
153 int line = elt->line ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
154
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
155 if (line > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
156 return line;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
157 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
158 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
160 return -1;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
161 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
162
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
163 int call_stack::current_user_code_column (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
164 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
165 // Start at current frame.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
166
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
167 size_t xframe = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
168
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
169 if (xframe > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
170 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
171 const stack_frame *elt = m_cs[xframe];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
172
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
173 octave_function *f = elt->function ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
174
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
175 if (f && f->is_user_code ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
176 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
177 int column = elt->column ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
178
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
179 if (column > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
180 return column;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
181 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
182 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
183
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
184 return -1;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
185 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
186
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
187 unwind_protect * call_stack::curr_fcn_unwind_protect_frame (void) const
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
188 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
189 // Start at current frame.
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
190
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
191 size_t xframe = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
192
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
193 if (xframe > 0)
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
194 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
195 const stack_frame *elt = m_cs[xframe];
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
196
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
197 octave_function *f = elt->function ();
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
198
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
199 if (f && f->is_user_code ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
200 return elt->unwind_protect_frame ();
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
201 }
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
202
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
203 return nullptr;
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
204 }
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
205
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
206 octave_user_code * call_stack::debug_user_code (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
207 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
208 octave_user_code *retval = nullptr;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
210 // This should never happen...
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
211 if (m_curr_frame == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
212 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
213
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
214 size_t i = m_curr_frame;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
216 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
217 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
218 const stack_frame *elt = m_cs[i--];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
219
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
220 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
222 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
223 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
224 retval = dynamic_cast<octave_user_code *> (f);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
225 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
226 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
227 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
229 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
230 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
231
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
232 int call_stack::debug_user_code_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
233 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
234 int retval = -1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
235
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
236 // This should never happen...
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
237 if (m_curr_frame == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
238 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
239
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
240 size_t i = m_curr_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
241
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
242 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
243 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
244 const stack_frame *elt = m_cs[i--];
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
246 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
248 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
249 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
250 if (elt->line ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
251 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
252 retval = elt->line ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
253 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
254 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
255 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
256 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
258 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
259 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
260
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
261 int call_stack::debug_user_code_column (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
262 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
263 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
265 // This should never happen...
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
266 if (m_curr_frame == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
267 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
268
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
269 // Start looking with the caller of the calling debug function.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
270 size_t i = m_curr_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
271
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
272 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
273 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
274 const stack_frame *elt = m_cs[i--];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
275
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
276 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
278 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
279 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
280 if (elt->column ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
281 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
282 retval = elt->column ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
283 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
284 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
285 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
286 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
288 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
289 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
290
26965
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
291 std::string call_stack::get_dispatch_class (void) const
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
292 {
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
293 return m_cs[m_curr_frame]->get_dispatch_class ();
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
294 }
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
295
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
296 void call_stack::set_dispatch_class (const std::string& class_name)
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
297 {
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
298 m_cs[m_curr_frame]->set_dispatch_class (class_name);
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
299 }
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
300
26795
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
301 bool call_stack::is_class_method_executing (std::string& dispatch_class) const
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
302 {
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
303 dispatch_class = "";
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
304
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
305 octave_function *f = current_function ();
26795
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
306
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
307 bool retval = (f && f->is_class_method ());
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
308
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
309 if (retval)
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
310 dispatch_class = f->dispatch_class ();
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
311
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
312 return retval;
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
313 }
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
314
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
315 bool call_stack::is_class_constructor_executing (std::string& dispatch_class) const
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
316 {
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
317 dispatch_class = "";
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
318
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
319 octave_function *f = current_function ();
26795
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
320
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
321 bool retval = (f && f->is_class_constructor ());
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
322
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
323 if (retval)
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
324 dispatch_class = f->dispatch_class ();
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
325
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
326 return retval;
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
327 }
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
328
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
329 bool call_stack::all_scripts (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
330 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
331 bool retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
332
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
333 auto p = m_cs.cend ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
335 while (p != m_cs.cbegin ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
336 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
337 const stack_frame *elt = *(--p);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
338
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
339 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
341 if (f && ! f->is_user_script ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
342 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
343 retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
344 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
345 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
346 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
348 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
349 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
351 stack_frame * call_stack::get_static_link (size_t prev_frame) const
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
352 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
353 // FIXME: is there a better way?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
354
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
355 stack_frame *slink = nullptr;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
356
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
357 if (m_curr_frame > 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
358 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
359 octave_function *t_fcn = m_cs[prev_frame]->function ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
360
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
361 slink = (t_fcn
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
362 ? (t_fcn->is_user_code ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
363 ? m_cs[prev_frame] : m_cs[prev_frame]->static_link ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
364 : m_cs[prev_frame]);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
365 }
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
366
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
367 return slink;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
368 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
369
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
370 void call_stack::push (const symbol_scope& scope)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
371 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
372 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
373 m_curr_frame = m_cs.size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
374
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
375 // m_max_stack_depth should never be less than zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
376 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
377 error ("max_stack_depth exceeded");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
378
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
379 stack_frame *slink = get_static_link (prev_frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
380
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
381 stack_frame *new_frame
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
382 = new scope_stack_frame (m_evaluator, scope, m_curr_frame, slink);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
383
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
384 m_cs.push_back (new_frame);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
385 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
386
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26795
diff changeset
387 void call_stack::push (octave_user_function *fcn, unwind_protect *up_frame,
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26795
diff changeset
388 stack_frame *closure_frames)
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
389 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
390 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
391 m_curr_frame = m_cs.size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
392
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
393 // m_max_stack_depth should never be less than zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
394 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
395 error ("max_stack_depth exceeded");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
396
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
397 stack_frame *slink = get_static_link (prev_frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
398
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
399 stack_frame *new_frame
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
400 = new user_fcn_stack_frame (m_evaluator, fcn, up_frame, m_curr_frame,
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
401 slink, closure_frames);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
402
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
403 m_cs.push_back (new_frame);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
404 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
405
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
406 void call_stack::push (octave_user_script *script, unwind_protect *up_frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
407 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
408 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
409 m_curr_frame = m_cs.size ();
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
410
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
411 // m_max_stack_depth should never be less than zero.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
412 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
413 error ("max_stack_depth exceeded");
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
414
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
415 stack_frame *slink = get_static_link (prev_frame);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
416
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
417 stack_frame *new_frame
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
418 = new script_stack_frame (m_evaluator, script, up_frame, m_curr_frame,
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
419 slink);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
420
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
421 m_cs.push_back (new_frame);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
422 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
423
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
424 void call_stack::push (octave_function *fcn)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
425 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
426 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
427 m_curr_frame = m_cs.size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
428
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
429 // m_max_stack_depth should never be less than zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
430 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
431 error ("max_stack_depth exceeded");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
432
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
433 stack_frame *slink = get_static_link (prev_frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
434
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
435 stack_frame *new_frame
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
436 = new compiled_fcn_stack_frame (m_evaluator, fcn, m_curr_frame, slink);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
437
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
438 m_cs.push_back (new_frame);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
439 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
440
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
441 bool call_stack::goto_frame (size_t n, bool verbose)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
442 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
443 bool retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
444
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
445 if (n < m_cs.size ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
446 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
447 retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
448
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
449 m_curr_frame = n;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
450
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
451 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
452 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
453 const stack_frame *elt = m_cs[n];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
454
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
455 elt->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
456 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
457 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
459 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
460 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
461
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
462 size_t call_stack::find_current_user_frame (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
463 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
464 size_t user_frame = m_curr_frame;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
465
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
466 stack_frame *frm = m_cs[user_frame];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
467
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
468 if (! (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
469 || frm->is_scope_frame ()))
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
470 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
471 frm = frm->static_link ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
472
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
473 user_frame = frm->index ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
474 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
475
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
476 return user_frame;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
477 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
478
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
479 stack_frame *call_stack::current_user_frame (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
480 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
481 size_t frame = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
482
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
483 return m_cs[frame];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
484 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
485
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
486 // Go to the Nth frame (up if N is negative or down if positive) in
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
487 // the call stack that corresponds to a script, function, or scope
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
488 // beginning with the frame indexed by START.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
489
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
490 size_t call_stack::dbupdown (size_t start, int n, bool verbose)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
491 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
492 if (start >= m_cs.size ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
493 error ("invalid stack frame");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
494
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
495 // Can't go up from here.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
496
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
497 if (start == 0 && n < 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
498 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
499 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
500 m_cs[start]->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
501
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
502 return start;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
503 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
504
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
505 stack_frame *frm = m_cs[start];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
506
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
507 if (! (frm && (frm->is_user_fcn_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
508 || frm->is_user_script_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
509 || frm->is_scope_frame ())))
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
510 error ("call_stack::dbupdown: invalid initial frame in call stack!");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
511
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
512 // Use index into the call stack to begin the search. At this point
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
513 // we iterate up or down using indexing instead of static links
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
514 // because ... FIXME: it's a bit complicated, but deserves
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
515 // explanation. May be easiest with some pictures of the call stack
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
516 // for an example or two.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
517
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
518 size_t xframe = frm->index ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
519
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
520 if (n == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
521 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
522 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
523 frm->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
524
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
525 return xframe;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
526 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
527
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
528 int incr = 0;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
529
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
530 if (n < 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
531 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
532 incr = -1;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
533 n = -n;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
534 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
535 else if (n > 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
536 incr = 1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
537
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
538 size_t last_good_frame = 0;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
540 while (true)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
541 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
542 frm = m_cs[xframe];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
543
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
544 if (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
545 || frm->is_scope_frame ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
546 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
547 last_good_frame = xframe;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
548
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
549 if (n == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
550 break;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
551
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
552 n--;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
553 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
554
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
555 xframe += incr;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
556
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
557 if (xframe == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
558 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
559 last_good_frame = 0;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
560 break;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
561 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
563 if (xframe == m_cs.size ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
564 break;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
565 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
567 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
568 m_cs[last_good_frame]->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
569
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
570 return last_good_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
571 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
572
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
573 // Like dbupdown above but find the starting frame automatically from
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
574 // the current frame. If the current frame is already a user
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
575 // function, script, or scope frame, use that. Otherwise, follow
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
576 // the static link for the current frame. If that is not a user
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
577 // function, script or scope frame then there is an error in the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
578 // implementation.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
579
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
580 size_t call_stack::dbupdown (int n, bool verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
581 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
582 size_t start = find_current_user_frame ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
583
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
584 return dbupdown (start, n, verbose);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
585 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
586
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
587 // May be used to temporarily change the value ov m_curr_frame inside
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
588 // a function like evalin. If used in a function like dbup, the new
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
589 // value of m_curr_frame would be wiped out when dbup returns and the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
590 // stack frame for dbup is popped.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
591
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
592 void call_stack::goto_caller_frame (void)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
593 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
594 size_t start = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
595
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
596 // FIXME: is this supposed to be an error?
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
597 if (start == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
598 error ("already at top level");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
599
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
600 m_curr_frame = dbupdown (start, -1, false);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
601 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
602
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
603 void call_stack::goto_base_frame (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
604 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
605 if (m_curr_frame > 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
606 m_curr_frame = 0;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
607 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
608
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
609 std::list<stack_frame *>
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
610 call_stack::backtrace_frames (octave_idx_type& curr_user_frame) const
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
611 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
612 std::list<stack_frame *> frames;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
613
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
614 // curr_frame is the index to the current frame in the overall call
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
615 // stack, which includes any compiled function frames and scope
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
616 // frames. The curr_user_frame value we set is the index into the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
617 // subset of frames returned in the octave_map object.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
618
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
619 size_t curr_frame = find_current_user_frame ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
620
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
621 // Don't include top-level stack frame in the list.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
622
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
623 for (size_t n = m_cs.size () - 1; n > 0; n--)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
624 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
625 stack_frame *frm = m_cs[n];
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
626
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
627 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
628 || frm->is_scope_frame ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
629 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
630 if (frm->index () == curr_frame)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
631 curr_user_frame = frames.size ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
632
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
633 frames.push_back (frm);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
634 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
635
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
636 if (n == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
637 break;
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
638 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
639
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
640 return frames;
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
641 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
642
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
643 std::list<stack_frame *>
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
644 call_stack::backtrace_frames (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
645 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
646 octave_idx_type curr_user_frame = -1;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
647
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
648 return backtrace_frames (curr_user_frame);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
649 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
650
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
651 std::list<frame_info>
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
652 call_stack::backtrace_info (octave_idx_type& curr_user_frame,
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
653 bool print_subfn) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
654 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
655 std::list<stack_frame *> frames = backtrace_frames (curr_user_frame);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
656
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
657 std::list<frame_info> retval;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
658
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
659 for (const auto *frm : frames)
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
660 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
661 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
662 || frm->is_scope_frame ())
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
663 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
664 retval.push_back (frame_info (frm->fcn_file_name (),
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
665 frm->fcn_name (print_subfn),
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
666 frm->line (), frm->column ()));
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
667 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
668 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
669
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
670 return retval;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
671 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
672
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
673 std::list<frame_info> call_stack::backtrace_info (void) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
674 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
675 octave_idx_type curr_user_frame = -1;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
676
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
677 return backtrace_info (curr_user_frame, true);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
678 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
679
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
680 octave_map call_stack::backtrace (octave_idx_type& curr_user_frame,
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
681 bool print_subfn) const
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
682 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
683 std::list<stack_frame *> frames = backtrace_frames (curr_user_frame);
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
684
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
685 size_t nframes = frames.size ();
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
686
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
687 octave_map retval (dim_vector (nframes, 1), bt_fields);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
688
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
689 Cell& file = retval.contents (0);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
690 Cell& name = retval.contents (1);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
691 Cell& line = retval.contents (2);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
692 Cell& column = retval.contents (3);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
693
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
694 octave_idx_type k = 0;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
695
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
696 for (const auto *frm : frames)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
697 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
698 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
699 || frm->is_scope_frame ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
700 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
701 file(k) = frm->fcn_file_name ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
702 name(k) = frm->fcn_name (print_subfn);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
703 line(k) = frm->line ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
704 column(k) = frm->column ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
705
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
706 k++;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
707 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
708 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
709
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
710 return retval;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
711 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
712
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
713 octave_map call_stack::backtrace (void) const
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
714 {
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
715 octave_idx_type curr_user_frame = -1;
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
716
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
717 return backtrace (curr_user_frame, true);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
718 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
719
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
720 octave_map call_stack::empty_backtrace (void) const
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
721 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
722 return octave_map (dim_vector (0, 1), bt_fields);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
723 }
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
724
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
725 void call_stack::pop (void)
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
726 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
727 // Never pop top scope.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
728 // FIXME: is it possible for this case to happen?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
729
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
730 if (m_cs.size () > 1)
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
731 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
732 stack_frame *elt = m_cs.back ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
733
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
734 stack_frame *caller = elt->static_link ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
735
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
736 m_curr_frame = caller->index ();
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
737
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
738 m_cs.pop_back ();
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
739
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
740 delete elt;
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
741 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
742 }
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
743
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
744 void call_stack::clear (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
745 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
746 while (! m_cs.empty ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
747 pop ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
748 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
749
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
750 symbol_info_list call_stack::all_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
751 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
752 return m_cs[m_curr_frame]->all_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
753 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
754
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
755 std::list<symbol_record> call_stack::glob (const std::string& pattern) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
756 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
757 return m_cs[m_curr_frame]->glob (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
758 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
759
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
760 std::list<symbol_record> call_stack::regexp (const std::string& pattern) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
761 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
762 return m_cs[m_curr_frame]->regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
763 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
764
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
765 std::list<std::string> call_stack::global_variable_names (void) const
26092
661dfb062485 use symbol_info_list to gather data for save function
John W. Eaton <jwe@octave.org>
parents: 26089
diff changeset
766 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
767 std::list<std::string> retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
768
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
769 for (const auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
770 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
771 if (nm_ov.second.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
772 retval.push_back (nm_ov.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
773 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
774
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
775 retval.sort ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
776
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
777 return retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
778 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
779
27594
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
780 std::list<std::string> call_stack::top_level_variable_names (void) const
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
781 {
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
782 return m_cs[0]->variable_names ();
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
783 }
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
784
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
785 std::list<std::string> call_stack::variable_names (void) const
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
786 {
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
787 return m_cs[m_curr_frame]->variable_names ();
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
788 }
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
789
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
790 void call_stack::clear_global_variable (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
791 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
792 auto p = m_global_values.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
793
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
794 if (p != m_global_values.end ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
795 p->second = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
796 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
797
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
798 void call_stack::clear_global_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
799 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
800 glob_match pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
801
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
802 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
803 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
804 if (pat.match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
805 nm_ov.second = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
806 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
807 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
808
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
809 void call_stack::clear_global_variable_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
810 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
811 octave::regexp pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
812
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
813 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
814 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
815 if (pat.is_match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
816 nm_ov.second = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
817 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
818 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
819
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
820 void call_stack::clear_global_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
821 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
822 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
823 nm_ov.second = octave_value ();
26092
661dfb062485 use symbol_info_list to gather data for save function
John W. Eaton <jwe@octave.org>
parents: 26089
diff changeset
824 }
661dfb062485 use symbol_info_list to gather data for save function
John W. Eaton <jwe@octave.org>
parents: 26089
diff changeset
825
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
826 symbol_info_list
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
827 call_stack::glob_symbol_info (const std::string& pattern) const
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
828 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
829 return m_cs[m_curr_frame]->glob_symbol_info (pattern);
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
830 }
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
831
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
832 symbol_info_list
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
833 call_stack::regexp_symbol_info (const std::string& pattern) const
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
834 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
835 return m_cs[m_curr_frame]->glob_symbol_info (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
836 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
837
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
838 symbol_info_list call_stack::get_symbol_info (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
839 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
840 return m_cs[m_curr_frame]->get_symbol_info ();
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
841 }
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
842
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
843 symbol_info_list call_stack::top_scope_symbol_info (void) const
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
844 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
845 return m_cs[0]->get_symbol_info ();
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
846 }
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
847
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
848 octave_value call_stack::max_stack_depth (const octave_value_list& args,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
849 int nargout)
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
850 {
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
851 return set_internal_variable (m_max_stack_depth, args, nargout,
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
852 "max_stack_depth", 0);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
853 }
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
854
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
855 void call_stack::make_persistent (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
856 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
857 m_cs[m_curr_frame]->make_persistent (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
858 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
859
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
860 void call_stack::make_global (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
861 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
862 m_cs[m_curr_frame]->make_global (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
863 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
864
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
865 octave_value call_stack::global_varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
866 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
867 auto p = m_global_values.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
868
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
869 return p == m_global_values.end () ? octave_value () : p->second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
870 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
871
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
872 octave_value& call_stack::global_varref (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
873 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
874 return m_global_values[name];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
875 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
876
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
877 octave_value call_stack::get_top_level_value (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
878 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
879 return m_cs[0]->varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
880 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
881
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
882 void call_stack::set_top_level_value (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
883 const octave_value& value)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
884 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
885 m_cs[0]->assign (name, value);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
886 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
887
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
888 octave_value call_stack::do_who (int argc, const string_vector& argv,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
889 bool return_list, bool verbose)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
890 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
891 octave_value retval;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
892
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
893 std::string my_name = argv[0];
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
894
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
895 std::string file_name;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
896
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
897 bool from_file = false;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
898 bool global_only = false;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
899 bool have_regexp = false;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
900
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
901 int i = 1;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
902 while (i < argc)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
903 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
904 if (argv[i] == "-file")
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
905 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
906 if (from_file)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
907 error ("%s: -file option may only be specified once",
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
908 my_name.c_str ());
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
909
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
910 from_file = true;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
911
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
912 if (i == argc - 1)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
913 error ("%s: -file argument must be followed by a filename",
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
914 my_name.c_str ());
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
915
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
916 file_name = argv[++i];
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
917 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
918 else if (argv[i] == "-regexp")
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
919 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
920 have_regexp = true;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
921 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
922 else if (argv[i] == "global")
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
923 global_only = true;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
924 else if (argv[i][0] == '-')
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
925 warning ("%s: unrecognized option '%s'", my_name.c_str (),
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
926 argv[i].c_str ());
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
927 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
928 break;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
929
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
930 i++;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
931 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
932
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
933 int npatterns = argc - i;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
934 string_vector patterns;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
935 if (npatterns > 0)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
936 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
937 patterns.resize (npatterns);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
938 for (int j = 0; j < npatterns; j++)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
939 patterns[j] = argv[i+j];
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
940 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
941 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
942 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
943 patterns.resize (1);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
944 patterns[0] = "*";
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
945 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
946
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
947 if (from_file)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
948 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
949 // FIXME: This is an inefficient manner to implement this as the
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
950 // variables are loaded in to a temporary context and then treated.
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
951 // It would be better to refactor symbol_info_list to not store the
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
952 // symbol records and then use it in load-save.cc (do_load) to
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
953 // implement this option there so that the variables are never
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
954 // stored at all.
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
955
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
956 unwind_protect frame;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
957
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
958 // Set up temporary scope.
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
959
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
960 symbol_scope tmp_scope ("$dummy_scope$");
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
961
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
962 push (tmp_scope);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
963 frame.add_method (*this, &call_stack::pop);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
964
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
965 feval ("load", octave_value (file_name), 0);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
966
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
967 std::string newmsg = "Variables in the file " + file_name + ":\n\n";
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
968
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
969 if (global_only)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
970 return do_global_who_two (patterns, have_regexp, return_list,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
971 verbose, newmsg);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
972 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
973 return do_who_two (patterns, have_regexp, return_list, verbose,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
974 newmsg);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
975 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
976 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
977 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
978 if (global_only)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
979 return do_global_who_two (patterns, have_regexp, return_list,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
980 verbose);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
981 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
982 return do_who_two (patterns, have_regexp, return_list, verbose);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
983 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
984 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
985
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
986 octave_value call_stack::do_who_two (const string_vector& patterns,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
987 bool have_regexp, bool return_list,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
988 bool verbose, const std::string& msg)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
989 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
990 symbol_info_accumulator sym_inf_accum (patterns, have_regexp);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
991
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
992 m_cs[m_curr_frame]->accept (sym_inf_accum);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
993
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
994 if (return_list)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
995 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
996 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
997 return sym_inf_accum.map_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
998 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
999 return Cell (string_vector (sym_inf_accum.names ()));
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1000 }
27071
4643682db06e who: don't print summary line if variable list is empty (bug #56228)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1001 else if (! sym_inf_accum.is_empty ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1002 {
27071
4643682db06e who: don't print summary line if variable list is empty (bug #56228)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1003
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1004 if (msg.empty ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1005 octave_stdout << "Variables visible from the current scope:\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1006 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1007 octave_stdout << msg;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1008
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1009 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1010 sym_inf_accum.display (octave_stdout,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1011 m_evaluator.whos_line_format ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1012 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1013 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1014 octave_stdout << "\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1015 string_vector names (sym_inf_accum.names ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1016 names.list_in_columns (octave_stdout);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1017 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1018
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1019 octave_stdout << "\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1020 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1021
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1022 return octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1023 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1024
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1025 octave_value call_stack::do_global_who_two (const string_vector& patterns,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1026 bool have_regexp,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1027 bool return_list, bool verbose,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1028 const std::string& msg)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1029 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
1030 symbol_info_list symbol_stats;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1031 std::list<std::string> symbol_names;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1032
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1033 octave_idx_type npatterns = patterns.numel ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1034
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1035 for (octave_idx_type j = 0; j < npatterns; j++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1036 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1037 std::string pattern = patterns[j];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1038
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1039 std::list<std::string> tmp;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1040
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1041 if (have_regexp)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1042 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1043 octave::regexp pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1044
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1045 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1046 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1047 if (pat.is_match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1048 tmp.push_back (nm_ov.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1049 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1050 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1051 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1052 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1053 glob_match pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1054
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1055 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1056 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1057 if (pat.match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1058 tmp.push_back (nm_ov.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1059 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1060 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1061
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1062 for (const auto& nm : tmp)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1063 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1064 octave_value value = m_global_values[nm];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1065
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1066 if (value.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1067 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1068 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1069 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1070 bool is_formal = false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1071 bool is_global = true;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1072 bool is_persistent = false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1073
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
1074 symbol_info
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1075 syminf (nm, value, is_formal,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1076 is_global, is_persistent);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1077
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1078 symbol_stats.append (syminf);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1079 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1080 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1081 symbol_names.push_back (nm);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1082 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1083 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1084 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1085
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1086 if (return_list)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1087 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1088 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1089 {
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1090 std::string caller_fcn_name;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1091 octave_function *caller_fcn = caller_function ();
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1092 if (caller_fcn)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1093 caller_fcn_name = caller_fcn->name ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1094
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1095 return symbol_stats.map_value (caller_fcn_name, 1);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1096 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1097 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1098 return Cell (string_vector (symbol_names));
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1099 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1100 else if (! (symbol_stats.empty () && symbol_names.empty ()))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1101 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1102 if (msg.empty ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1103 octave_stdout << "Global variables:\n\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1104 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1105 octave_stdout << msg;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1106
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1107 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1108 symbol_stats.display (octave_stdout,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1109 m_evaluator.whos_line_format ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1110 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1111 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1112 string_vector names (symbol_names);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1113
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1114 names.list_in_columns (octave_stdout);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1115 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1116
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1117 octave_stdout << "\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1118 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1119
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1120 return octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1121 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1122
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1123 void call_stack::clear_current_frame_values (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1124 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1125 m_cs[m_curr_frame]->clear_values ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1126 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1127
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1128 void call_stack::display (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1129 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1130 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1131
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1132 size_t nframes = size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1133
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1134 for (size_t i = 0; i < nframes; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1135 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1136 m_cs[i]->display (false);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1137 if (i < nframes - 1)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1138 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1139 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1140 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1141
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1142 void call_stack::set_auto_fcn_var (stack_frame::auto_var_type avt,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1143 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1144 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1145 m_cs[m_curr_frame]->set_auto_fcn_var (avt, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1146 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1147
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1148 octave_value call_stack::get_auto_fcn_var (stack_frame::auto_var_type avt) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1149 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1150 return m_cs[m_curr_frame]->get_auto_fcn_var (avt);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1151 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1152 }
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1153
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1154 DEFMETHOD (max_stack_depth, interp, args, nargout,
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1155 doc: /* -*- texinfo -*-
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1156 @deftypefn {} {@var{val} =} max_stack_depth ()
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1157 @deftypefnx {} {@var{old_val} =} max_stack_depth (@var{new_val})
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1158 @deftypefnx {} {} max_stack_depth (@var{new_val}, "local")
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1159 Query or set the internal limit on the number of times a function may
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1160 be called recursively.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1161
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1162 If the limit is exceeded, an error message is printed and control returns to
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1163 the top level.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1164
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1165 When called from inside a function with the @qcode{"local"} option, the
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1166 variable is changed locally for the function and any subroutines it calls.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1167 The original variable value is restored when exiting the function.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1168
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1169 @seealso{max_recursion_depth}
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1170 @end deftypefn */)
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1171 {
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1172 octave::tree_evaluator& tw = interp.get_evaluator ();
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1173
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1174 return tw.max_stack_depth (args, nargout);
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1175 }
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1176
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1177 /*
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1178 %!test
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1179 %! orig_val = max_stack_depth ();
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1180 %! old_val = max_stack_depth (2*orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1181 %! assert (orig_val, old_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1182 %! assert (max_stack_depth (), 2*orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1183 %! max_stack_depth (orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1184 %! assert (max_stack_depth (), orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1185
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1186 %!error (max_stack_depth (1, 2))
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1187 */
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1188
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1189 DEFMETHOD (who, interp, args, nargout,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1190 doc: /* -*- texinfo -*-
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1191 @deftypefn {} {} who
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1192 @deftypefnx {} {} who pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1193 @deftypefnx {} {} who option pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1194 @deftypefnx {} {C =} who ("pattern", @dots{})
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1195 List currently defined variables matching the given patterns.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1196
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1197 Valid pattern syntax is the same as described for the @code{clear} command.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1198 If no patterns are supplied, all variables are listed.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1199
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1200 By default, only variables visible in the local scope are displayed.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1201
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1202 The following are valid options, but may not be combined.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1203
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1204 @table @code
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1205 @item global
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1206 List variables in the global scope rather than the current scope.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1207
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1208 @item -regexp
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1209 The patterns are considered to be regular expressions when matching the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1210 variables to display. The same pattern syntax accepted by the @code{regexp}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1211 function is used.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1212
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1213 @item -file
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1214 The next argument is treated as a filename. All variables found within the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1215 specified file are listed. No patterns are accepted when reading variables
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1216 from a file.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1217 @end table
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1218
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1219 If called as a function, return a cell array of defined variable names
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1220 matching the given patterns.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1221 @seealso{whos, isglobal, isvarname, exist, regexp}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1222 @end deftypefn */)
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1223 {
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1224 int argc = args.length () + 1;
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1225
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1226 string_vector argv = args.make_argv ("who");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1227
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1228 octave::tree_evaluator& tw = interp.get_evaluator ();
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1229
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1230 return tw.do_who (argc, argv, nargout == 1);
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1231 }
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1232
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1233 /*
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1234 %!test
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1235 %! avar = magic (4);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1236 %! ftmp = [tempname() ".mat"];
26698
63b5a17ba30f Use save_default_options() to make BIST test suite robust against user configurations.
Rik <rik@octave.org>
parents: 26661
diff changeset
1237 %! save_default_options ("-binary", "local");
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1238 %! unwind_protect
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1239 %! save (ftmp, "avar");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1240 %! vars = whos ("-file", ftmp);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1241 %! assert (numel (vars), 1);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1242 %! assert (isstruct (vars));
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1243 %! assert (vars.name, "avar");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1244 %! assert (vars.size, [4, 4]);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1245 %! assert (vars.class, "double");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1246 %! assert (vars.bytes, 128);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1247 %! unwind_protect_cleanup
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1248 %! unlink (ftmp);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1249 %! end_unwind_protect
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1250 */
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1251
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1252 DEFMETHOD (whos, interp, args, nargout,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1253 doc: /* -*- texinfo -*-
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1254 @deftypefn {} {} whos
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1255 @deftypefnx {} {} whos pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1256 @deftypefnx {} {} whos option pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1257 @deftypefnx {} {S =} whos ("pattern", @dots{})
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1258 Provide detailed information on currently defined variables matching the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1259 given patterns.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1260
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1261 Options and pattern syntax are the same as for the @code{who} command.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1262
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1263 Extended information about each variable is summarized in a table with the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1264 following default entries.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1265
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1266 @table @asis
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1267 @item Attr
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1268 Attributes of the listed variable. Possible attributes are:
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1269
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1270 @table @asis
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1271 @item blank
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1272 Variable in local scope
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1273
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1274 @item @code{c}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1275 Variable of complex type.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1276
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1277 @item @code{f}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1278 Formal parameter (function argument).
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1279
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1280 @item @code{g}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1281 Variable with global scope.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1282
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1283 @item @code{p}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1284 Persistent variable.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1285 @end table
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1286
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1287 @item Name
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1288 The name of the variable.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1289
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1290 @item Size
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1291 The logical size of the variable. A scalar is 1x1, a vector is
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1292 @nospell{1xN} or @nospell{Nx1}, a 2-D matrix is @nospell{MxN}.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1293
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1294 @item Bytes
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1295 The amount of memory currently used to store the variable.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1296
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1297 @item Class
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1298 The class of the variable. Examples include double, single, char, uint16,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1299 cell, and struct.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1300 @end table
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1301
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1302 The table can be customized to display more or less information through
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1303 the function @code{whos_line_format}.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1304
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1305 If @code{whos} is called as a function, return a struct array of defined
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1306 variable names matching the given patterns. Fields in the structure
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1307 describing each variable are: name, size, bytes, class, global, sparse,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1308 complex, nesting, persistent.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1309 @seealso{who, whos_line_format}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1310 @end deftypefn */)
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1311 {
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1312 int argc = args.length () + 1;
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1313
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1314 string_vector argv = args.make_argv ("whos");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1315
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1316 octave::tree_evaluator& tw = interp.get_evaluator ();
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1317
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1318 return tw.do_who (argc, argv, nargout == 1, true);
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1319 }