annotate libinterp/corefcn/call-stack.cc @ 23602:214cb58ccc1c

use pointer to scope instead of scope id Eliminate symbol table scope ID and the global list of all scopes indexed by numeric ID. Function scope data is now only accessible from the function itself, or by asking a scope for its parent scope (if it exists). The top-level and global scopes are now regular data members of the symbol table class instead of being static. Symbol table scopes are now created in the lexer when parsing a function begins and stored in the function object when finishing the construction of function object. If an error occurs while parsing a function, the list of any pending scopes is deleted.
author John W. Eaton <jwe@octave.org>
date Wed, 14 Jun 2017 11:53:34 -0400
parents 5cb3a2bb5e1e
children 8a47d4735655
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
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1995-2017 John W. Eaton
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
10 (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
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
15 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
16
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 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
18 along with Octave; see the file COPYING. If not, see
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
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 */
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #if defined (HAVE_CONFIG_H)
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 # include "config.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
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 #include "call-stack.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
28 #include "interpreter.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "oct-map.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "ov.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #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
32 #include "ov-fcn-handle.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "ov-usr-fcn.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 // Use static fields for the best efficiency.
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 // NOTE: C++0x will allow these two to be merged into one.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
37 static const char *bt_fieldnames[] =
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
38 { "file", "name", "line", "column", "scope", "context", 0 };
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 static const octave_fields bt_fields (bt_fieldnames);
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
41 namespace octave
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 {
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
43 std::string
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
44 call_stack::stack_frame::fcn_file_name (void) const
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
45 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
46 return m_fcn ? m_fcn->fcn_file_name () : "";
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
47 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
48
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
49 std::string
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
50 call_stack::stack_frame::fcn_name (bool print_subfn) const
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
51 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
52 std::string retval;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
54 if (m_fcn)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
55 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
56 std::string parent_fcn_name = m_fcn->parent_fcn_name ();
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
57
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
58 if (print_subfn && ! parent_fcn_name.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
59 retval = parent_fcn_name + Vfilemarker;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
60
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
61 if (m_fcn->is_anonymous_function ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
62 retval += octave_fcn_handle::anonymous;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
63 else
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
64 retval += m_fcn->name ();
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
65 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
66 else
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
67 retval = "<unknown>";
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
68
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
69 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
70 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
72 bool
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
73 call_stack::stack_frame::operator == (const call_stack::stack_frame& rhs) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
74 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
75 if (this->line () != rhs.line ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
76 return false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
77 else if (this->column () != rhs.column ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
78 return false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
79 else if (this->fcn_file_name () != rhs.fcn_file_name ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
80 return false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
81 else if (this->fcn_name () != rhs.fcn_name ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
82 return false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
83 else
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
84 return true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
85 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
87 call_stack::call_stack (interpreter& interp)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
88 : cs (), curr_frame (0), m_interpreter (interp)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
89 {
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
90 symbol_table& symtab = m_interpreter.get_symbol_table ();
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
91
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
92 push (0, symtab.top_scope (), 0);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
93 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
94
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
95 int
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
96 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
97 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
98 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
100 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
101 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
102 const stack_frame& elt = cs[curr_frame];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
103 retval = elt.m_line;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
104 }
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 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
107 }
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
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
110 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
111 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
112 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
114 if (! cs.empty ())
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 const stack_frame& elt = cs[curr_frame];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
117 retval = elt.m_column;
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
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
120 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
121 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
122
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
123 size_t
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
124 call_stack::num_user_code_frames (octave_idx_type& curr_user_frame) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
125 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
126 size_t retval = 0;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
127
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
128 curr_user_frame = 0;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
129
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
130 // Look for the caller of dbstack.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
131 size_t xframe = cs[curr_frame].m_prev;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
133 bool found = false;
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 size_t k = cs.size ();
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
136
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
137 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
138 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
139 octave_function *f = (*p).m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
140
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
141 if (--k == xframe)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
142 found = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
143
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
144 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
145 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
146 if (! found)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
147 curr_user_frame++;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
149 retval++;
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 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
152
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
153 // We counted how many user frames were not the one, in reverse.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
154 // Now set curr_user_frame to be the index in the other direction.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
155 curr_user_frame = retval - curr_user_frame - 1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
157 return retval;
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
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
160 octave_user_code *
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
161 call_stack::caller_user_code (size_t nskip) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
162 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
163 octave_user_code *retval = nullptr;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
164
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
165 const_iterator p = cs.end ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
167 while (p != cs.begin ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
168 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
169 const stack_frame& elt = *(--p);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
170
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
171 octave_function *f = elt.m_fcn;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
173 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
174 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
175 if (nskip > 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
176 nskip--;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
177 else
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
178 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
179 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
180 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
181 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
182 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
183 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
184
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
185 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
186 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
187
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
188 int
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
189 call_stack::caller_user_code_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
190 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
191 int retval = -1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
192
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
193 const_iterator p = cs.end ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
195 while (p != cs.begin ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
196 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
197 const stack_frame& elt = *(--p);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
198
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
199 octave_function *f = elt.m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
200
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
201 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
202 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
203 if (elt.m_line > 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
204 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
205 retval = elt.m_line;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
206 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
207 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
208 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
209 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
211 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
212 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
213
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
214 int
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
215 call_stack::caller_user_code_column (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
216 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
217 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
219 const_iterator p = cs.end ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
221 while (p != cs.begin ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
222 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
223 const stack_frame& elt = *(--p);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
224
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
225 octave_function *f = elt.m_fcn;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
227 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
228 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
229 if (elt.m_column)
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 retval = elt.m_column;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
232 break;
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 }
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
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
237 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
238 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
239
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
240 octave_user_code *
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
241 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
242 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
243 octave_user_code *retval = nullptr;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
245 // This should never happen...
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
246 if (curr_frame == 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
247 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
248
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
249 // Start looking with the caller of the calling debug function.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
250 size_t i = cs[curr_frame].m_prev;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
252 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
253 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
254 const stack_frame& elt = cs[i--];
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 octave_function *f = elt.m_fcn;
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 if (f && f->is_user_code ())
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 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
261 break;
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 }
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 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
266 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
267
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
268 int
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
269 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
270 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
271 int retval = -1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
272
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
273 // This should never happen...
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
274 if (curr_frame == 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
275 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
276
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
277 // Start looking with the caller of the calling debug function.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
278 size_t i = cs[curr_frame].m_prev;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
279
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
280 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
281 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
282 const stack_frame& elt = cs[i--];
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
284 octave_function *f = elt.m_fcn;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
286 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
287 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
288 if (elt.m_line)
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 retval = elt.m_line;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
291 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
292 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
293 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
294 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
296 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
297 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
298
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
299 int
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
300 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
301 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
302 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
304 // This should never happen...
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
305 if (curr_frame == 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
306 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
307
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
308 // Start looking with the caller of the calling debug function.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
309 size_t i = cs[curr_frame].m_prev;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
310
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
311 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
312 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
313 const stack_frame& elt = cs[i--];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
314
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
315 octave_function *f = elt.m_fcn;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
317 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
318 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
319 if (elt.m_column)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
320 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
321 retval = elt.m_column;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
322 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
323 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
324 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
325 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
327 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
328 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
329
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
330 bool
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
331 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
332 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
333 bool retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
334
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
335 const_iterator p = cs.end ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
337 while (p != cs.begin ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
338 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
339 const stack_frame& elt = *(--p);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
340
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
341 octave_function *f = elt.m_fcn;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
343 if (f && ! f->is_user_script ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
344 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
345 retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
346 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
347 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
348 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
350 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
351 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
353 bool
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
354 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
355 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
356 bool retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
357
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
358 if (n < cs.size ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
359 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
360 retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
361
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
362 curr_frame = n;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
364 const stack_frame& elt = cs[n];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
365
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
366 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
367
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
368 symtab.set_scope_and_context (elt.m_scope, elt.m_context);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
369
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
370 if (verbose)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
371 octave_stdout << "stopped in " << elt.fcn_name ()
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
372 << " at line " << elt.m_line
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
373 << " column " << elt.m_column
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
374 << " [" << elt.fcn_file_name () << "] "
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
375 << " (scope = " << elt.m_scope
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
376 << "[context = " << elt.m_context << "])"
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
377 << std::endl;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
378 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
380 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
381 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
382
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
383 bool
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
384 call_stack::goto_frame_relative (int nskip, bool verbose)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
385 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
386 bool retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
387
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
388 int incr = 0;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
389
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
390 if (nskip < 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
391 incr = -1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
392 else if (nskip > 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
393 incr = 1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
394
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
395 // Start looking with the caller of dbup/dbdown/keyboard.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
396 size_t xframe = cs[curr_frame].m_prev;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
398 while (true)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
399 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
400 if ((incr < 0 && xframe == 0) || (incr > 0 && xframe == cs.size () - 1))
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
401 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
402
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
403 xframe += incr;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
404
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
405 const stack_frame& elt = cs[xframe];
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
407 octave_function *f = elt.m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
408
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
409 if (xframe == 0 || (f && f->is_user_code ()))
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
410 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
411 if (nskip > 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
412 nskip--;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
413 else if (nskip < 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
414 nskip++;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
416 if (nskip == 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
417 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
418 curr_frame = xframe;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
419 cs[cs.size () - 1].m_prev = curr_frame;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
420
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
421 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
422
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
423 symtab.set_scope_and_context (elt.m_scope, elt.m_context);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
425 if (verbose)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
426 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
427 std::ostringstream buf;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
429 if (f)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
430 buf << "stopped in " << elt.fcn_name ()
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
431 << " at line " << elt.m_line
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
432 << " [" << elt.fcn_file_name () << "] "
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
433 << std::endl;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
434 else
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
435 buf << "at top level" << std::endl;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
437 octave_stdout << buf.str ();
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
438 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
439
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
440 retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
441 break;
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 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
444 else if (incr == 0) // Break out of infinite loop by choosing an incr.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
445 incr = -1;
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 // There is no need to set scope and context here. That will
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
448 // happen when the dbup/dbdown/keyboard frame is popped and we
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
449 // jump to the new "prev" frame set above.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
450 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
452 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
453 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
454
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
455 void
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
456 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
457 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
458 size_t xframe = curr_frame;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
460 bool skipped = false;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
462 while (xframe != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
463 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
464 xframe = cs[xframe].m_prev;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
465
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
466 const stack_frame& elt = cs[xframe];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
467
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
468 octave_function *f = elt.m_fcn;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
470 if (elt.m_scope == cs[0].m_scope || (f && f->is_user_code ()))
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
471 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
472 if (! skipped)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
473 // We found the current user code frame, so skip it.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
474 skipped = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
475 else
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
476 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
477 // We found the caller user code frame.
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
478 stack_frame tmp (elt);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
479 tmp.m_prev = curr_frame;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
480
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
481 curr_frame = cs.size ();
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
482
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
483 cs.push_back (tmp);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
484
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
485 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
486
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
487 symtab.set_scope_and_context (tmp.m_scope, tmp.m_context);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
489 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
490 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
491 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
492 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
493 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
494
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
495 void
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
496 call_stack::goto_base_frame (void)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
497 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
498 stack_frame tmp (cs[0]);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
499 tmp.m_prev = curr_frame;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
500
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
501 curr_frame = cs.size ();
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
502
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
503 cs.push_back (tmp);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
505 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
506
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
507 symtab.set_scope_and_context (tmp.m_scope, tmp.m_context);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
508 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
509
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
510 std::list<call_stack::stack_frame>
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
511 call_stack::backtrace_frames (size_t nskip,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
512 octave_idx_type& curr_user_frame) const
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
513 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
514 std::list<call_stack::stack_frame> retval;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
515
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
516 size_t user_code_frames = num_user_code_frames (curr_user_frame);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
517
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
518 size_t nframes = (nskip <= user_code_frames ? user_code_frames - nskip : 0);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
519
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
520 // Our list is reversed.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
521 curr_user_frame = nframes - curr_user_frame - 1;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
522
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
523 if (nframes > 0)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
524 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
525 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
526 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
527 const stack_frame& elt = *p;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
528
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
529 octave_function *f = elt.m_fcn;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
530
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
531 if (f && f->is_user_code ())
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
532 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
533 if (nskip > 0)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
534 nskip--;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
535 else
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
536 retval.push_back (elt);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
537 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
538 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
539 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
540
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
541 return retval;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
542 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
543
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
544 octave_map
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
545 call_stack::backtrace (size_t nskip, octave_idx_type& curr_user_frame,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
546 bool print_subfn) const
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
547 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
548 std::list<call_stack::stack_frame> frames
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
549 = backtrace_frames (nskip, curr_user_frame);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
550
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
551 size_t nframes = frames.size ();
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
552
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
553 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
554
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
555 Cell& file = retval.contents (0);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
556 Cell& name = retval.contents (1);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
557 Cell& line = retval.contents (2);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
558 Cell& column = retval.contents (3);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
559 Cell& scope = retval.contents (4);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
560 Cell& context = retval.contents (5);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
561
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
562 octave_idx_type k = 0;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
563
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
564 for (const auto& frm : frames)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
565 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
566 scope(k) = frm.m_scope;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
567 context(k) = frm.m_context;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
568 file(k) = frm.fcn_file_name ();
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
569 name(k) = frm.fcn_name (print_subfn);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
570 line(k) = frm.m_line;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
571 column(k) = frm.m_column;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
572
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
573 k++;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
574 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
575
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
576 return retval;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
577 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
578
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
579 octave_map
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
580 call_stack::empty_backtrace (void) const
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
581 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
582 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
583 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
584 }