annotate libinterp/corefcn/call-stack.h @ 24362:3fc24b792a24

avoid including symtab.h, symscope.h, or symrec.h unnecessarily * main-window.cc, workspace-view.cc, call-stack.cc, call-stack.h, defun-int.h, input.cc, load-save.h, symscope.h, symtab.h, variables.h, ov-fcn-inline.h, ov-fcn.h, ov-usr-fcn.cc, ov-usr-fcn.h, lex.h, oct-lvalue.h, parse.h, pt-arg-list.h, pt-array-list.h, pt-assign.h, pt-binop.h, pt-cbinop.h, pt-cell.h, pt-cmd.h, pt-colon.h, pt-const.h, pt-decl.h, pt-eval.h, pt-except.h, pt-exp.h, pt-fcn-handle.h, pt-idx.h, pt-jit.h, pt-jump.h, pt-loop.h, pt-mat.h, pt-misc.h, pt-select.h, pt-stmt.h, pt-unop.h, token.cc, token.h: Where possible, use forward declarations for symbol_table, symbol_scope, and symbol_record. Don't include symtab.h, symscope.h, or symrec.h unless needed. Use symbol_record::context_id instead of symbol_table::context_id or symbol_scope::context_id. Delete typedefs for symbol_table::context_id and symbol_scope::context_id.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Dec 2017 17:09:24 -0500
parents 8bcfddad15ec
children 194eb4bd202b
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) 1993-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 (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;
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
36 #include "symscope.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
38 namespace octave
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
40 class interpreter;
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
41
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
42 class
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
43 OCTINTERP_API
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
44 call_stack
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
45 {
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 public:
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
48 class stack_frame
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
49 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
50 public:
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
51
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
52 friend class call_stack;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
53
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
54 stack_frame (octave_function *fcn = nullptr,
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
55 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
56 symbol_record::context_id context = 0, size_t prev = 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
57 : m_fcn (fcn), m_line (-1), m_column (-1), m_scope (scope),
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
58 m_context (context), m_prev (prev)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
59 { }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
60
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
61 stack_frame (const stack_frame& elt)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
62 : m_fcn (elt.m_fcn), m_line (elt.m_line), m_column (elt.m_column),
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
63 m_scope (elt.m_scope), m_context (elt.m_context), m_prev (elt.m_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 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
67
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
68 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
69
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
70 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
71
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
72 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
73
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
74 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
75
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76 private:
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 octave_function *m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
79 int m_line;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
80 int m_column;
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
81 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
82 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
83 size_t m_prev;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
84 };
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 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
87 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
88
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
89 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
90 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
91
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
92 call_stack (interpreter& interp);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
93
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
94 // Current function (top of stack).
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
95 octave_function * current (void) const
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
96 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
97 octave_function *retval = nullptr;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
98
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
99 if (! cs.empty ())
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
100 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
101 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
102 retval = elt.m_fcn;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
103 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
104
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
105 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
106 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
107
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
108 // Current line in current function.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
109 int current_line (void) const;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
110
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
111 // Current column in current function.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
112 int current_column (void) const;
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 // 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
115
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
116 octave_function * caller (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
117 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
118 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
119 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
121 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
122
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
123 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
124
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
125 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
126
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
127 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
128 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
129 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
130 ? 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
131 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
133 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
134 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
135 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
136 ? 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
137 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
139 // 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
140 // be built-in.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
141 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
142 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23446
diff changeset
143 octave_function *retval = nullptr;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
145 if (cs.size () > n)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
146 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
147 stack_frame& elt = cs[n];
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
148 retval = elt.m_fcn;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
149 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
151 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
152 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
154 // User code caller.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
155 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
156
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
157 // Line in user code caller.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
158 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
159
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
160 // Column in user code caller.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
161 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
162
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
163 // Current function that we are debugging.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
164 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
165
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
166 // 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
167 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
168
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
169 // 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
170 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
171
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
172 // 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
173 bool all_scripts (void) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
175 void push (octave_function *fcn);
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
176 void push (octave_function *fcn, const symbol_scope& scope,
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
177 symbol_record::context_id context);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
179 void push (void)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
180 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
181 push (nullptr);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
182 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
184 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
185 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
186 push (nullptr, scope, context);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
187 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
188
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
189 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
190 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
191 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
192 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
193 stack_frame& elt = cs.back ();
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: 22755
diff changeset
195 elt.m_line = l;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
196 elt.m_column = c;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
197 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
198 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
200 void set_line (int l)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
201 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
202 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
203 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
204 stack_frame& elt = cs.back ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
206 elt.m_line = l;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
207 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
208 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
210 void set_column (int c)
23052
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 if (! cs.empty ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
213 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
214 stack_frame& elt = cs.back ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
216 elt.m_column = c;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
217 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
218 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
220 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
221
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
222 void restore_frame (size_t n)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
223 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
224 goto_frame (n);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
225 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
227 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
228
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
229 void goto_caller_frame (void);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
230
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
231 void goto_base_frame (void);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
232
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
233 std::list<call_stack::stack_frame>
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
234 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
235
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
236 std::list<call_stack::stack_frame>
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
237 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
238 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
239 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
240
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
241 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
242 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
243
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
244 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
245 bool print_subfn = true) const;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
247 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
248
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
249 octave_map empty_backtrace (void) const;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
250
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
251 void pop (void);
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
253 void clear (void) { cs.clear (); }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
254
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
255 private:
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
256
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
257 // The current call stack.
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
258 std::deque<stack_frame> cs;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
259
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
260 size_t curr_frame;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
261
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
262 interpreter& m_interpreter;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
263 };
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
264 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
266 #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
267
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
268 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
269 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
270
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 #endif
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 #endif