annotate libinterp/corefcn/call-stack.h @ 25399:6ca2c0d76d84

store unwind protect frame for function evaluation in call_stack object * call-stack.h, call-stack.cc (call_stack::m_unwind_protect_frame): New data member. (call_stack::push): Also handle unwind_protect frame. (call_stack::curr_fcn_unwind_protect_frame): New function. * variables.cc (curr_fcn_unwind_protect_frame): Access current unwind_protect frame from call_stack object. * pt-eval.cc (tree_evaluator::maybe_push_echo_state_cleanup): Likewise. * ov-usr-fcn.h (octave_user_code::curr_unwind_protect_frame): Delete member variable and all uses. (octave_user_code::unwind_protect_frame): Delete. * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_script::call, octave_user_function::call): Push current unwind_protect frame on call_stack object instead of saving and restoring octave_user_code::curr_unwind_protect_frame.
author John W. Eaton <jwe@octave.org>
date Mon, 21 May 2018 19:32:57 -0400
parents 6652d3823428
children 661dfb062485
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
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24855
diff changeset
3 Copyright (C) 1993-2018 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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
diff changeset
19 <https://www.gnu.org/licenses/>.
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 */
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 (octave_call_stack_h)
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #define octave_call_stack_h 1
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 #include "octave-config.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include <deque>
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include <string>
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 class octave_function;
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
32 class octave_map;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 class octave_user_code;
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 class octave_user_script;
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
35 class octave_value;
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
36 class octave_value_list;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
38 #include "symscope.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
40 namespace octave
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
42 class interpreter;
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
43 class unwind_protect;
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
44
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
45 class
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
46 OCTINTERP_API
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
47 call_stack
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
48 {
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 public:
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
51 class stack_frame
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
52 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
53 public:
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
54
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
55 friend class call_stack;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
56
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
57 stack_frame (octave_function *fcn = nullptr,
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
58 unwind_protect *up_frame = nullptr,
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
59 const symbol_scope& scope = symbol_scope (),
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
60 symbol_record::context_id context = 0, size_t prev = 0)
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
61 : m_fcn (fcn), m_unwind_protect_frame (up_frame),
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
62 m_line (-1), m_column (-1), m_scope (scope),
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
63 m_context (context), m_prev (prev)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
64 { }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
65
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
66 stack_frame (const stack_frame& elt)
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
67 : m_fcn (elt.m_fcn),
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
68 m_unwind_protect_frame (elt.m_unwind_protect_frame),
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
69 m_line (elt.m_line), m_column (elt.m_column),
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
70 m_scope (elt.m_scope), m_context (elt.m_context),
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
71 m_prev (elt.m_prev)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
72 { }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
73
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
74 int line (void) const { return m_line; }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
75
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76 int column (void) const { return m_column; }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
77
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
78 std::string fcn_file_name (void) const;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
79
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
80 std::string fcn_name (bool print_subfn = true) const;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
81
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
82 bool operator == (const stack_frame& rhs) const;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
83
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
84 private:
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
85
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
86 octave_function *m_fcn;
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
87 unwind_protect *m_unwind_protect_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
88 int m_line;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
89 int m_column;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
90 symbol_scope m_scope;
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
91 symbol_record::context_id m_context;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
92 size_t m_prev;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
93 };
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
94
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
95 typedef std::deque<stack_frame>::iterator iterator;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
96 typedef std::deque<stack_frame>::const_iterator const_iterator;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
97
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
98 typedef std::deque<stack_frame>::reverse_iterator reverse_iterator;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
99 typedef std::deque<stack_frame>::const_reverse_iterator const_reverse_iterator;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
100
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
101 call_stack (interpreter& interp);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
102
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
103 // Current function (top of stack).
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
104 octave_function * current (void) const
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
105 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
106 octave_function *retval = nullptr;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
107
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
108 if (! cs.empty ())
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
109 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
110 const stack_frame& elt = cs[curr_frame];
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
111 retval = elt.m_fcn;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
112 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
113
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
114 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
115 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
116
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
117 // Current line in current function.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
118 int current_line (void) const;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
119
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
120 // Current column in current function.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
121 int current_column (void) const;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
122
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
123 // Caller function, may be built-in.
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
124
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
125 octave_function * caller (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
126 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
127 return curr_frame > 1 ? cs[curr_frame-1].m_fcn : cs[0].m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
128 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
130 size_t current_frame (void) const { return curr_frame; }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
132 size_t size (void) const { return cs.size (); }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
134 size_t num_user_code_frames (octave_idx_type& curr_user_frame) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
136 symbol_scope current_scope (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
137 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
138 return (curr_frame > 0 && curr_frame < cs.size ()
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
139 ? cs[curr_frame].m_scope : symbol_scope ());
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
140 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
142 symbol_record::context_id current_context (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
143 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
144 return (curr_frame > 0 && curr_frame < cs.size ()
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
145 ? cs[curr_frame].m_context : 0);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
146 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
148 // Function at location N on the call stack (N == 0 is current), may
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
149 // be built-in.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
150 octave_function * element (size_t n)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
151 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23446
diff changeset
152 octave_function *retval = nullptr;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
154 if (cs.size () > n)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
155 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
156 stack_frame& elt = cs[n];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
157 retval = elt.m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
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: 22755
diff changeset
160 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
161 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
163 // User code caller.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
164 octave_user_code * caller_user_code (size_t nskip = 0) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
165
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
166 unwind_protect *curr_fcn_unwind_protect_frame (void) const;
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
167
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
168 // Line in user code caller.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
169 int caller_user_code_line (void) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
170
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
171 // Column in user code caller.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
172 int caller_user_code_column (void) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
173
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
174 // Current function that we are debugging.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
175 octave_user_code * debug_user_code (void) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
176
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
177 // Line number in current function that we are debugging.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
178 int debug_user_code_line (void) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
180 // Column number in current function that we are debugging.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
181 int debug_user_code_column (void) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
182
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
183 // Return TRUE if all elements on the call stack are scripts.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
184 bool all_scripts (void) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
186 void push (octave_function *fcn = nullptr,
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
187 unwind_protect *up_frame = nullptr);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
189 void push (octave_function *fcn, unwind_protect *up_frame,
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
190 const symbol_scope& scope, symbol_record::context_id context);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
192 void push (const symbol_scope& scope, symbol_record::context_id context)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
193 {
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
194 push (nullptr, nullptr, scope, context);
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
195 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
196
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
197 void set_location (int l, int c)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
198 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
199 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
200 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
201 stack_frame& elt = cs.back ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
203 elt.m_line = l;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
204 elt.m_column = c;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
205 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
206 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
208 void set_line (int l)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
209 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
210 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
211 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
212 stack_frame& elt = cs.back ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
214 elt.m_line = l;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
215 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
216 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
218 void set_column (int c)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
219 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
220 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
221 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
222 stack_frame& elt = cs.back ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
224 elt.m_column = c;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
225 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
226 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
228 bool goto_frame (size_t n = 0, bool verbose = false);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
229
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
230 void restore_frame (size_t n)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
231 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
232 goto_frame (n);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
233 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
235 bool goto_frame_relative (int n, bool verbose = false);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
236
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
237 void goto_caller_frame (void);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
238
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
239 void goto_base_frame (void);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
240
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
241 std::list<call_stack::stack_frame>
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
242 backtrace_frames (size_t nskip, octave_idx_type& curr_user_frame) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
244 std::list<call_stack::stack_frame>
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
245 backtrace_frames (size_t nskip = 0) const
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
246 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
247 octave_idx_type curr_user_frame = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
249 return backtrace_frames (nskip, curr_user_frame);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
250 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
251
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
252 octave_map 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
253 bool print_subfn = true) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
255 octave_map backtrace (size_t nskip = 0);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
257 octave_map empty_backtrace (void) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
258
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
259 void pop (void);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
261 void clear (void) { cs.clear (); }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
262
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
263 octave_value max_stack_depth (const octave_value_list& args, int nargout);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
264
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
265 private:
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
266
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
267 // The current call stack.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
268 std::deque<stack_frame> cs;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
269
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
270 size_t curr_frame;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
271
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
272 int m_max_stack_depth;
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
273
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
274 interpreter& m_interpreter;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
275 };
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
276 }
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: 22755
diff changeset
278 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
280 OCTAVE_DEPRECATED (4.4, "use 'octave::call_stack' instead")
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
281 typedef octave::call_stack octave_call_stack;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283 #endif
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 #endif