Mercurial > octave-nkf
annotate src/toplev.h @ 9218:00ce0ae4ec63
add missing OCTINTERP_API tag
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 20 May 2009 11:29:08 +0200 |
parents | ee7cf4d963f3 |
children | 659657942ba6 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, |
8920 | 4 2003, 2004, 2005, 2006, 2007, 2008 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 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
40 #include "quit.h" |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
41 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
42 #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
|
43 #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
|
44 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
45 |
9218
00ce0ae4ec63
add missing OCTINTERP_API tag
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
46 extern OCTINTERP_API void (*octave_exit) (int); |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
47 |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
48 // quit is a lot like an interrupt, so we subclass it to simplify possible |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
49 // handling. |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
50 class octave_quit_exception |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
51 : public octave_interrupt_exception |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
52 { |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
53 public: |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
54 int status; |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
55 octave_quit_exception (int s) : status (s) { } |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
56 }; |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
57 |
7250 | 58 extern OCTINTERP_API void |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9144
diff
changeset
|
59 clean_up_and_exit (int); |
574 | 60 |
7250 | 61 extern OCTINTERP_API void recover_from_exception (void); |
7202 | 62 |
5189 | 63 extern int main_loop (void); |
1907 | 64 |
7250 | 65 extern OCTINTERP_API void |
2796 | 66 do_octave_atexit (void); |
2077 | 67 |
7409 | 68 extern OCTINTERP_API void |
69 octave_add_atexit_function (const std::string& fname); | |
70 | |
71 extern OCTINTERP_API bool | |
72 octave_remove_atexit_function (const std::string& fname); | |
73 | |
1 | 74 // Current command to execute. |
7250 | 75 extern OCTINTERP_API tree_statement_list *global_command; |
1 | 76 |
4217 | 77 // TRUE means we are ready to interpret commands, but not everything |
78 // is ready for interactive use. | |
7185 | 79 extern OCTINTERP_API bool octave_interpreter_ready; |
4217 | 80 |
4172 | 81 // TRUE means we've processed all the init code and we are good to go. |
7185 | 82 extern OCTINTERP_API bool octave_initialized; |
4172 | 83 |
5743 | 84 class |
85 octave_call_stack | |
86 { | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
87 private: |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
88 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
89 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
|
90 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
91 call_stack_elt (octave_function *f, symbol_table::scope_id s, |
7901 | 92 symbol_table::context_id c, size_t p = 0) |
93 : fcn (f), stmt (0), scope (s), context (c), prev (p) { } | |
94 | |
95 call_stack_elt (const call_stack_elt& elt) | |
96 : fcn (elt.fcn), stmt (elt.stmt), scope (elt.scope), | |
97 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
|
98 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
99 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
|
100 tree_statement *stmt; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
101 symbol_table::scope_id scope; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
102 symbol_table::context_id context; |
7901 | 103 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
|
104 }; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
105 |
5743 | 106 protected: |
107 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
108 octave_call_stack (void) : cs (), curr_frame (0) { } |
5743 | 109 |
110 public: | |
111 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
112 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
|
113 typedef std::deque<call_stack_elt>::const_iterator const_iterator; |
7901 | 114 |
115 typedef std::deque<call_stack_elt>::reverse_iterator reverse_iterator; | |
116 typedef std::deque<call_stack_elt>::const_reverse_iterator const_reverse_iterator; | |
117 | |
5743 | 118 static bool instance_ok (void) |
119 { | |
120 bool retval = true; | |
121 | |
122 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
|
123 { |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
124 instance = new octave_call_stack (); |
5743 | 125 |
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
|
126 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
|
127 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
|
128 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
|
129 { |
75df1f0b4c9d
toplev.h (octave_call_stack::instance_ok): push top scope when creating instance
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
130 ::error ("unable to create call stack object!"); |
5743 | 131 |
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
|
132 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
|
133 } |
5743 | 134 } |
135 | |
136 return retval; | |
137 } | |
138 | |
139 // Current function (top of stack). | |
5744 | 140 static octave_function *current (void) { return top (); } |
5743 | 141 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
142 // 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
|
143 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
|
144 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
145 // 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
|
146 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
|
147 { |
7877 | 148 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
|
149 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
150 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
151 // 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
|
152 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
|
153 { |
7877 | 154 return instance_ok () ? instance->do_current_column () : -1; |
155 } | |
156 | |
157 // Line in user code caller. | |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
158 static int caller_user_code_line (void) |
7877 | 159 { |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
160 return instance_ok () ? instance->do_caller_user_code_line () : -1; |
7877 | 161 } |
162 | |
163 // Column in user code caller. | |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
164 static int caller_user_code_column (void) |
7877 | 165 { |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
166 return instance_ok () ? instance->do_caller_user_code_column () : -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
|
167 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
168 |
5743 | 169 // Caller function, may be built-in. |
170 static octave_function *caller (void) | |
171 { | |
7942
db6478d9c669
out_of_date_check_internal: make it work for class methods
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
172 return instance_ok () ? instance->do_caller () : 0; |
5743 | 173 } |
174 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
175 static size_t current_frame (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
176 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
177 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
|
178 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
179 |
7890 | 180 static size_t size (void) |
181 { | |
182 return instance_ok () ? instance->do_size () : 0; | |
183 } | |
184 | |
7901 | 185 static size_t num_user_code_frames (octave_idx_type& curr_user_frame) |
186 { | |
187 return instance_ok () | |
188 ? instance->do_num_user_code_frames (curr_user_frame) : 0; | |
189 } | |
190 | |
191 static symbol_table::scope_id current_scope (void) | |
192 { | |
193 return instance_ok () ? instance->do_current_scope () : 0; | |
194 } | |
195 | |
196 static symbol_table::context_id current_context (void) | |
197 { | |
198 return instance_ok () ? instance->do_current_context () : 0; | |
199 } | |
200 | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
201 // 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
|
202 // be built-in. |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
203 static octave_function *element (size_t n) |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
204 { |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
205 return instance_ok () ? instance->do_element (n) : 0; |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
206 } |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
207 |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
208 // First user-defined function on the stack. |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
209 static octave_user_code *caller_user_code (size_t nskip = 0) |
5743 | 210 { |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
211 return instance_ok () ? instance->do_caller_user_code (nskip) : 0; |
5743 | 212 } |
213 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
214 static void |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
215 push (octave_function *f, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
216 symbol_table::scope_id scope = symbol_table::current_scope (), |
7901 | 217 symbol_table::context_id context = symbol_table::current_context ()) |
5743 | 218 { |
219 if (instance_ok ()) | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
220 instance->do_push (f, scope, context); |
5743 | 221 } |
222 | |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
223 static void |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
224 push (symbol_table::scope_id scope = symbol_table::current_scope (), |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
225 symbol_table::context_id context = symbol_table::current_context ()) |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
226 { |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
227 if (instance_ok ()) |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
228 instance->do_push (0, scope, context); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
229 } |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
230 |
5744 | 231 static octave_function *top (void) |
232 { | |
233 return instance_ok () ? instance->do_top (): 0; | |
234 } | |
235 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
236 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
|
237 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
238 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
|
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 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
241 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
|
242 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
243 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
|
244 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
|
245 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
246 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
247 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
|
248 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
249 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
|
250 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
251 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
252 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
|
253 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
254 return instance_ok () |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
255 ? 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
|
256 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
257 |
7901 | 258 static void goto_caller_frame (void) |
259 { | |
260 if (instance_ok ()) | |
261 instance->do_goto_caller_frame (); | |
262 } | |
263 | |
264 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
|
265 { |
7901 | 266 if (instance_ok ()) |
267 instance->do_goto_base_frame (); | |
268 } | |
269 | |
270 static Octave_map backtrace (size_t nskip, octave_idx_type& curr_user_frame) | |
271 { | |
272 return instance_ok () | |
273 ? 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
|
274 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
275 |
5743 | 276 static void pop (void) |
277 { | |
278 if (instance_ok ()) | |
279 instance->do_pop (); | |
280 } | |
281 | |
282 // A function for popping the top of the call stack that is suitable | |
283 // for use as an unwind_protect handler. | |
284 static void unwind_pop (void *) { pop (); } | |
285 | |
286 static void clear (void) | |
287 { | |
288 if (instance_ok ()) | |
289 instance->do_clear (); | |
290 } | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7409
diff
changeset
|
291 |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
292 static void backtrace_error_message (void) |
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
293 { |
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
294 if (instance_ok ()) |
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
295 instance->do_backtrace_error_message (); |
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
296 } |
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
297 |
5743 | 298 private: |
299 | |
300 // 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
|
301 std::deque<call_stack_elt> cs; |
5743 | 302 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
303 size_t curr_frame; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
304 |
5743 | 305 static octave_call_stack *instance; |
306 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
307 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
|
308 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
309 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
|
310 |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
311 int do_caller_user_code_line (void) const; |
7877 | 312 |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
313 int do_caller_user_code_column (void) const; |
7877 | 314 |
7942
db6478d9c669
out_of_date_check_internal: make it work for class methods
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
315 octave_function *do_caller (void) const |
db6478d9c669
out_of_date_check_internal: make it work for class methods
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
316 { |
db6478d9c669
out_of_date_check_internal: make it work for class methods
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
317 return curr_frame > 1 ? cs[curr_frame-1].fcn : cs[0].fcn; |
db6478d9c669
out_of_date_check_internal: make it work for class methods
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
318 } |
db6478d9c669
out_of_date_check_internal: make it work for class methods
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
319 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
320 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
|
321 |
7890 | 322 size_t do_size (void) { return cs.size (); } |
323 | |
7901 | 324 size_t do_num_user_code_frames (octave_idx_type& curr_user_frame) const; |
325 | |
326 symbol_table::scope_id do_current_scope (void) const | |
327 { | |
328 return curr_frame > 0 && curr_frame < cs.size () | |
329 ? cs[curr_frame].scope : 0; | |
330 } | |
331 | |
332 symbol_table::context_id do_current_context (void) const | |
333 { | |
334 return curr_frame > 0 && curr_frame < cs.size () | |
335 ? cs[curr_frame].context : 0; | |
336 } | |
337 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
338 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
|
339 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
340 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
|
341 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
342 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
|
343 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
344 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
|
345 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
|
346 } |
5743 | 347 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
348 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
|
349 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
350 |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7912
diff
changeset
|
351 octave_user_code *do_caller_user_code (size_t nskip) const; |
5744 | 352 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
353 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
|
354 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
|
355 { |
7901 | 356 size_t prev_frame = curr_frame; |
357 curr_frame = cs.size (); | |
358 cs.push_back (call_stack_elt (f, scope, context, prev_frame)); | |
359 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
|
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 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
|
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 octave_function *retval = 0; |
5744 | 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.fcn; |
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 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
374 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
375 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
|
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 tree_statement *retval = 0; |
5743 | 378 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
379 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
|
380 { |
7890 | 381 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
|
382 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
|
383 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
384 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
385 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
|
386 } |
5743 | 387 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
388 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
|
389 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
390 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
|
391 { |
7890 | 392 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
|
393 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
|
394 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
395 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
396 |
7901 | 397 Octave_map do_backtrace (size_t nskip, |
398 octave_idx_type& curr_user_frame) const; | |
5744 | 399 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
400 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
|
401 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
402 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
|
403 |
7901 | 404 void do_goto_caller_frame (void); |
405 | |
406 void do_goto_base_frame (void); | |
407 | |
5743 | 408 void do_pop (void) |
409 { | |
7901 | 410 if (cs.size () > 1) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
411 { |
7901 | 412 const call_stack_elt& elt = cs.back (); |
413 curr_frame = elt.prev; | |
7890 | 414 cs.pop_back (); |
7901 | 415 const call_stack_elt& new_elt = cs[curr_frame]; |
416 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
|
417 } |
5743 | 418 } |
419 | |
420 void do_clear (void) { cs.clear (); } | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
421 |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
422 void do_backtrace_error_message (void) const; |
5743 | 423 }; |
424 | |
1 | 425 #endif |
426 | |
427 /* | |
428 ;;; Local Variables: *** | |
429 ;;; mode: C++ *** | |
430 ;;; End: *** | |
431 */ |