Mercurial > octave
annotate src/toplev.h @ 7912:75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 09 Jul 2008 16:16:19 -0400 |
parents | 3e4c9b69069d |
children | c3d21b9b94b6 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, |
4 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
1670 | 24 #if !defined (octave_toplev_h) |
25 #define octave_toplev_h 1 | |
1 | 26 |
1355 | 27 #include <cstdio> |
1 | 28 |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
29 #include <deque> |
3503 | 30 #include <string> |
31 | |
2086 | 32 class octave_value; |
2796 | 33 class octave_value_list; |
5743 | 34 class octave_function; |
5744 | 35 class octave_user_script; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
36 class tree_statement; |
578 | 37 class tree_statement_list; |
1572 | 38 class charMatrix; |
1 | 39 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
40 #include "input.h" |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
41 #include "oct-map.h" |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
42 |
7250 | 43 extern OCTINTERP_API void |
2796 | 44 clean_up_and_exit (int) GCC_ATTR_NORETURN; |
574 | 45 |
7250 | 46 extern OCTINTERP_API void recover_from_exception (void); |
7202 | 47 |
5189 | 48 extern int main_loop (void); |
1907 | 49 |
7250 | 50 extern OCTINTERP_API void |
2796 | 51 do_octave_atexit (void); |
2077 | 52 |
7409 | 53 extern OCTINTERP_API void |
54 octave_add_atexit_function (const std::string& fname); | |
55 | |
56 extern OCTINTERP_API bool | |
57 octave_remove_atexit_function (const std::string& fname); | |
58 | |
1 | 59 // Current command to execute. |
7250 | 60 extern OCTINTERP_API tree_statement_list *global_command; |
1 | 61 |
4238 | 62 // Pointer to parent function that is currently being evaluated. |
7250 | 63 extern OCTINTERP_API octave_function *curr_parent_function; |
4238 | 64 |
4217 | 65 // TRUE means we are ready to interpret commands, but not everything |
66 // is ready for interactive use. | |
7185 | 67 extern OCTINTERP_API bool octave_interpreter_ready; |
4217 | 68 |
4172 | 69 // TRUE means we've processed all the init code and we are good to go. |
7185 | 70 extern OCTINTERP_API bool octave_initialized; |
4172 | 71 |
5743 | 72 class |
73 octave_call_stack | |
74 { | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
75 private: |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
76 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
77 struct call_stack_elt |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
78 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
79 call_stack_elt (octave_function *f, symbol_table::scope_id s, |
7901 | 80 symbol_table::context_id c, size_t p = 0) |
81 : fcn (f), stmt (0), scope (s), context (c), prev (p) { } | |
82 | |
83 call_stack_elt (const call_stack_elt& elt) | |
84 : fcn (elt.fcn), stmt (elt.stmt), scope (elt.scope), | |
85 context (elt.context), prev (elt.prev) { } | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
86 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
87 octave_function *fcn; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
88 tree_statement *stmt; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
89 symbol_table::scope_id scope; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
90 symbol_table::context_id context; |
7901 | 91 size_t prev; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
92 }; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
93 |
5743 | 94 protected: |
95 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
96 octave_call_stack (void) : cs (), curr_frame (0) { } |
5743 | 97 |
98 public: | |
99 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
100 typedef std::deque<call_stack_elt>::iterator iterator; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
101 typedef std::deque<call_stack_elt>::const_iterator const_iterator; |
7901 | 102 |
103 typedef std::deque<call_stack_elt>::reverse_iterator reverse_iterator; | |
104 typedef std::deque<call_stack_elt>::const_reverse_iterator const_reverse_iterator; | |
105 | |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
106 typedef std::deque<call_stack_elt>::difference_type difference_type; |
5743 | 107 |
108 static bool instance_ok (void) | |
109 { | |
110 bool retval = true; | |
111 | |
112 if (! instance) | |
7912
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
113 { |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
114 instance = new octave_call_stack (); |
5743 | 115 |
7912
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
116 if (instance) |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
117 instance->do_push (0, symbol_table::top_scope (), 0); |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
118 else |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
119 { |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
120 ::error ("unable to create call stack object!"); |
5743 | 121 |
7912
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
122 retval = false; |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
123 } |
5743 | 124 } |
125 | |
126 return retval; | |
127 } | |
128 | |
129 // Current function (top of stack). | |
5744 | 130 static octave_function *current (void) { return top (); } |
5743 | 131 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
132 // Current statement (top of stack). |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
133 static tree_statement *current_statement (void) { return top_statement (); } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
134 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
135 // Current line in current function. |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
136 static int current_line (void) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
137 { |
7877 | 138 return instance_ok () ? instance->do_current_line () : -1; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
139 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
140 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
141 // Current column in current function. |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
142 static int current_column (void) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
143 { |
7877 | 144 return instance_ok () ? instance->do_current_column () : -1; |
145 } | |
146 | |
147 // Line in user code caller. | |
148 static int caller_user_code_line (difference_type q = 0) | |
149 { | |
150 return instance_ok () ? instance->do_caller_user_code_line (q) : -1; | |
151 } | |
152 | |
153 // Column in user code caller. | |
154 static int caller_user_code_column (difference_type q = 0) | |
155 { | |
156 return instance_ok () ? instance->do_caller_user_code_column (q) : -1; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
157 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
158 |
5743 | 159 // Caller function, may be built-in. |
160 static octave_function *caller (void) | |
161 { | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
162 return element (1); |
5743 | 163 } |
164 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
165 static size_t current_frame (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
166 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
167 return instance_ok () ? instance->do_current_frame () : 0; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
168 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
169 |
7890 | 170 static size_t size (void) |
171 { | |
172 return instance_ok () ? instance->do_size () : 0; | |
173 } | |
174 | |
7901 | 175 static size_t num_user_code_frames (octave_idx_type& curr_user_frame) |
176 { | |
177 return instance_ok () | |
178 ? instance->do_num_user_code_frames (curr_user_frame) : 0; | |
179 } | |
180 | |
181 static symbol_table::scope_id current_scope (void) | |
182 { | |
183 return instance_ok () ? instance->do_current_scope () : 0; | |
184 } | |
185 | |
186 static symbol_table::context_id current_context (void) | |
187 { | |
188 return instance_ok () ? instance->do_current_context () : 0; | |
189 } | |
190 | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
191 // Function at location N on the call stack (N == 0 is current), may |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
192 // be built-in. |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
193 static octave_function *element (size_t n) |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
194 { |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
195 return instance_ok () ? instance->do_element (n) : 0; |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
196 } |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
197 |
5744 | 198 // First script on the stack. |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
199 static octave_user_script *caller_script (difference_type q = 0) |
5743 | 200 { |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
201 return instance_ok () ? instance->do_caller_user_script (q) : 0; |
5744 | 202 } |
203 | |
204 // First user-defined function on the stack. | |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
205 static octave_user_function *caller_user_function (difference_type q = 0) |
5744 | 206 { |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
207 return instance_ok () ? instance->do_caller_user_function (q) : 0; |
5744 | 208 } |
209 | |
210 // First user-defined function on the stack. | |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
211 static octave_user_code *caller_user_code (difference_type q = 0) |
5744 | 212 { |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
213 return instance_ok () ? instance->do_caller_user_code (q) : 0; |
5743 | 214 } |
215 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
216 static void |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
217 push (octave_function *f, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
218 symbol_table::scope_id scope = symbol_table::current_scope (), |
7901 | 219 symbol_table::context_id context = symbol_table::current_context ()) |
5743 | 220 { |
221 if (instance_ok ()) | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
222 instance->do_push (f, scope, context); |
5743 | 223 } |
224 | |
5744 | 225 static octave_function *top (void) |
226 { | |
227 return instance_ok () ? instance->do_top (): 0; | |
228 } | |
229 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
230 static tree_statement *top_statement (void) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
231 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
232 return instance_ok () ? instance->do_top_statement (): 0; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
233 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
234 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
235 static void set_statement (tree_statement *s) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
236 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
237 if (instance_ok ()) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
238 instance->do_set_statement (s); |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
239 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
240 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
241 static bool goto_frame (size_t n = 0, bool verbose = false) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
242 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
243 return instance_ok () ? instance->do_goto_frame (n, verbose) : false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
244 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
245 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
246 static bool goto_frame_relative (int n, bool verbose = false) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
247 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
248 return instance_ok () |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
249 ? instance->do_goto_frame_relative (n, verbose) : false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
250 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
251 |
7901 | 252 static void goto_caller_frame (void) |
253 { | |
254 if (instance_ok ()) | |
255 instance->do_goto_caller_frame (); | |
256 } | |
257 | |
258 static void goto_base_frame (void) | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
259 { |
7901 | 260 if (instance_ok ()) |
261 instance->do_goto_base_frame (); | |
262 } | |
263 | |
264 static Octave_map backtrace (size_t nskip, octave_idx_type& curr_user_frame) | |
265 { | |
266 return instance_ok () | |
267 ? instance->do_backtrace (nskip, curr_user_frame) : Octave_map (); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
268 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
269 |
5743 | 270 static void pop (void) |
271 { | |
272 if (instance_ok ()) | |
273 instance->do_pop (); | |
274 } | |
275 | |
276 // A function for popping the top of the call stack that is suitable | |
277 // for use as an unwind_protect handler. | |
278 static void unwind_pop (void *) { pop (); } | |
279 | |
280 static void clear (void) | |
281 { | |
282 if (instance_ok ()) | |
283 instance->do_clear (); | |
284 } | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
285 |
5743 | 286 private: |
287 | |
288 // The current call stack. | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
289 std::deque<call_stack_elt> cs; |
5743 | 290 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
291 size_t curr_frame; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
292 |
5743 | 293 static octave_call_stack *instance; |
294 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
295 int do_current_line (void) const; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
296 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
297 int do_current_column (void) const; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
298 |
7877 | 299 int do_caller_user_code_line (difference_type q = 0) const; |
300 | |
301 int do_caller_user_code_column (difference_type q = 0) const; | |
302 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
303 size_t do_current_frame (void) { return curr_frame; } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
304 |
7890 | 305 size_t do_size (void) { return cs.size (); } |
306 | |
7901 | 307 size_t do_num_user_code_frames (octave_idx_type& curr_user_frame) const; |
308 | |
309 symbol_table::scope_id do_current_scope (void) const | |
310 { | |
311 return curr_frame > 0 && curr_frame < cs.size () | |
312 ? cs[curr_frame].scope : 0; | |
313 } | |
314 | |
315 symbol_table::context_id do_current_context (void) const | |
316 { | |
317 return curr_frame > 0 && curr_frame < cs.size () | |
318 ? cs[curr_frame].context : 0; | |
319 } | |
320 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
321 octave_function *do_element (size_t n) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
322 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
323 octave_function *retval = 0; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
324 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
325 if (cs.size () > n) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
326 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
327 call_stack_elt& elt = cs[n]; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
328 retval = elt.fcn; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
329 } |
5743 | 330 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
331 return retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
332 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
333 |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
334 octave_user_script *do_caller_user_script (difference_type q = 0) const; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
335 |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
336 octave_user_function *do_caller_user_function (difference_type q = 0) const; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
337 |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7752
diff
changeset
|
338 octave_user_code *do_caller_user_code (difference_type q = 0) const; |
5744 | 339 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
340 void do_push (octave_function *f, symbol_table::scope_id scope, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
341 symbol_table::context_id context) |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
342 { |
7901 | 343 size_t prev_frame = curr_frame; |
344 curr_frame = cs.size (); | |
345 cs.push_back (call_stack_elt (f, scope, context, prev_frame)); | |
346 symbol_table::set_scope_and_context (scope, context); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
347 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
348 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
349 octave_function *do_top (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
350 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
351 octave_function *retval = 0; |
5744 | 352 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
353 if (! cs.empty ()) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
354 { |
7890 | 355 const call_stack_elt& elt = cs.back (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
356 retval = elt.fcn; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
357 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
358 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
359 return retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
360 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
361 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
362 tree_statement *do_top_statement (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
363 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
364 tree_statement *retval = 0; |
5743 | 365 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
366 if (! cs.empty ()) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
367 { |
7890 | 368 const call_stack_elt& elt = cs.back (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
369 retval = elt.stmt; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
370 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
371 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
372 return retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
373 } |
5743 | 374 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
375 void do_set_statement (tree_statement *s) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
376 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
377 if (! cs.empty ()) |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
378 { |
7890 | 379 call_stack_elt& elt = cs.back (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
380 elt.stmt = s; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
381 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
382 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
383 |
7901 | 384 Octave_map do_backtrace (size_t nskip, |
385 octave_idx_type& curr_user_frame) const; | |
5744 | 386 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
387 bool do_goto_frame (size_t n, bool verbose); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
388 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
389 bool do_goto_frame_relative (int n, bool verbose); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
390 |
7901 | 391 void do_goto_caller_frame (void); |
392 | |
393 void do_goto_base_frame (void); | |
394 | |
5743 | 395 void do_pop (void) |
396 { | |
7901 | 397 if (cs.size () > 1) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
398 { |
7901 | 399 const call_stack_elt& elt = cs.back (); |
400 curr_frame = elt.prev; | |
7890 | 401 cs.pop_back (); |
7901 | 402 const call_stack_elt& new_elt = cs[curr_frame]; |
403 symbol_table::set_scope_and_context (new_elt.scope, new_elt.context); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
404 } |
5743 | 405 } |
406 | |
407 void do_clear (void) { cs.clear (); } | |
408 }; | |
409 | |
1 | 410 #endif |
411 | |
412 /* | |
413 ;;; Local Variables: *** | |
414 ;;; mode: C++ *** | |
415 ;;; End: *** | |
416 */ |