Mercurial > hg > octave-nkf
comparison src/toplev.h @ 7734:2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 25 Apr 2008 12:16:42 -0400 |
parents | bb614b3883a9 |
children | a059b5679fbb |
comparison
equal
deleted
inserted
replaced
7733:bb614b3883a9 | 7734:2dee19385d32 |
---|---|
31 | 31 |
32 class octave_value; | 32 class octave_value; |
33 class octave_value_list; | 33 class octave_value_list; |
34 class octave_function; | 34 class octave_function; |
35 class octave_user_script; | 35 class octave_user_script; |
36 class tree_statement; | |
36 class tree_statement_list; | 37 class tree_statement_list; |
37 class charMatrix; | 38 class charMatrix; |
39 | |
40 #include "oct-map.h" | |
38 | 41 |
39 extern OCTINTERP_API void | 42 extern OCTINTERP_API void |
40 clean_up_and_exit (int) GCC_ATTR_NORETURN; | 43 clean_up_and_exit (int) GCC_ATTR_NORETURN; |
41 | 44 |
42 extern OCTINTERP_API void recover_from_exception (void); | 45 extern OCTINTERP_API void recover_from_exception (void); |
66 extern OCTINTERP_API bool octave_initialized; | 69 extern OCTINTERP_API bool octave_initialized; |
67 | 70 |
68 class | 71 class |
69 octave_call_stack | 72 octave_call_stack |
70 { | 73 { |
74 private: | |
75 | |
76 struct call_stack_elt | |
77 { | |
78 call_stack_elt (octave_function *f) : fcn (f), stmt (0) { } | |
79 | |
80 octave_function *fcn; | |
81 tree_statement *stmt; | |
82 }; | |
83 | |
71 protected: | 84 protected: |
72 | 85 |
73 octave_call_stack (void) : cs () { } | 86 octave_call_stack (void) : cs () { } |
74 | 87 |
75 public: | 88 public: |
76 | 89 |
77 typedef std::deque<octave_function *>::iterator iterator ; | 90 typedef std::deque<call_stack_elt>::iterator iterator; |
91 typedef std::deque<call_stack_elt>::const_iterator const_iterator; | |
78 | 92 |
79 static bool instance_ok (void) | 93 static bool instance_ok (void) |
80 { | 94 { |
81 bool retval = true; | 95 bool retval = true; |
82 | 96 |
93 return retval; | 107 return retval; |
94 } | 108 } |
95 | 109 |
96 // Current function (top of stack). | 110 // Current function (top of stack). |
97 static octave_function *current (void) { return top (); } | 111 static octave_function *current (void) { return top (); } |
112 | |
113 // Current statement (top of stack). | |
114 static tree_statement *current_statement (void) { return top_statement (); } | |
115 | |
116 // Current line in current function. | |
117 static int current_line (void) | |
118 { | |
119 return instance_ok () ? instance->do_current_line () : 0; | |
120 } | |
121 | |
122 // Current column in current function. | |
123 static int current_column (void) | |
124 { | |
125 return instance_ok () ? instance->do_current_column () : 0; | |
126 } | |
98 | 127 |
99 // Caller function, may be built-in. | 128 // Caller function, may be built-in. |
100 static octave_function *caller (void) | 129 static octave_function *caller (void) |
101 { | 130 { |
102 return element (1); | 131 return element (1); |
134 } | 163 } |
135 | 164 |
136 static octave_function *top (void) | 165 static octave_function *top (void) |
137 { | 166 { |
138 return instance_ok () ? instance->do_top (): 0; | 167 return instance_ok () ? instance->do_top (): 0; |
168 } | |
169 | |
170 static tree_statement *top_statement (void) | |
171 { | |
172 return instance_ok () ? instance->do_top_statement (): 0; | |
173 } | |
174 | |
175 static void set_statement (tree_statement *s) | |
176 { | |
177 if (instance_ok ()) | |
178 instance->do_set_statement (s); | |
179 } | |
180 | |
181 static Octave_map backtrace (void) | |
182 { | |
183 return instance_ok () ? instance->do_backtrace () : Octave_map (); | |
139 } | 184 } |
140 | 185 |
141 static void pop (void) | 186 static void pop (void) |
142 { | 187 { |
143 if (instance_ok ()) | 188 if (instance_ok ()) |
155 } | 200 } |
156 | 201 |
157 private: | 202 private: |
158 | 203 |
159 // The current call stack. | 204 // The current call stack. |
160 std::deque<octave_function *> cs; | 205 std::deque<call_stack_elt> cs; |
161 | 206 |
162 static octave_call_stack *instance; | 207 static octave_call_stack *instance; |
163 | 208 |
164 octave_function *do_element (size_t n) { return cs.size () > n ? cs[n] : 0; } | 209 int do_current_line (void) const; |
165 | 210 |
166 octave_user_script *do_caller_user_script (void); | 211 int do_current_column (void) const; |
167 | 212 |
168 octave_user_function *do_caller_user_function (void); | 213 octave_function *do_element (size_t n) |
169 | 214 { |
170 octave_user_code *do_caller_user_code (void); | 215 octave_function *retval = 0; |
171 | 216 |
172 void do_push (octave_function *f) { cs.push_front (f); } | 217 if (cs.size () > n) |
173 | 218 { |
174 octave_function *do_top (void) { return cs.empty () ? 0 : cs.front (); } | 219 call_stack_elt& elt = cs[n]; |
220 retval = elt.fcn; | |
221 } | |
222 | |
223 return retval; | |
224 } | |
225 | |
226 octave_user_script *do_caller_user_script (void) const; | |
227 | |
228 octave_user_function *do_caller_user_function (void) const; | |
229 | |
230 octave_user_code *do_caller_user_code (void) const; | |
231 | |
232 void do_push (octave_function *f) | |
233 { | |
234 cs.push_front (call_stack_elt (f)); | |
235 } | |
236 | |
237 octave_function *do_top (void) const | |
238 { | |
239 octave_function *retval = 0; | |
240 | |
241 if (! cs.empty ()) | |
242 { | |
243 const call_stack_elt& elt = cs.front (); | |
244 retval = elt.fcn; | |
245 } | |
246 | |
247 return retval; | |
248 } | |
249 | |
250 tree_statement *do_top_statement (void) const | |
251 { | |
252 tree_statement *retval = 0; | |
253 | |
254 if (! cs.empty ()) | |
255 { | |
256 const call_stack_elt& elt = cs.front (); | |
257 retval = elt.stmt; | |
258 } | |
259 | |
260 return retval; | |
261 } | |
262 | |
263 void do_set_statement (tree_statement *s) | |
264 { | |
265 if (! cs.empty ()) | |
266 { | |
267 call_stack_elt& elt = cs.front (); | |
268 elt.stmt = s; | |
269 } | |
270 } | |
271 | |
272 Octave_map do_backtrace (void) const; | |
175 | 273 |
176 void do_pop (void) | 274 void do_pop (void) |
177 { | 275 { |
178 if (! cs.empty ()) | 276 if (! cs.empty ()) |
179 cs.pop_front (); | 277 cs.pop_front (); |