Mercurial > hg > octave-lyh
diff src/pt-stmt.h @ 7552:6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
author | ryanru@PrinceHumperdinck |
---|---|
date | Tue, 04 Mar 2008 17:01:05 -0500 |
parents | 745a8299c2b5 |
children | 2dee19385d32 |
line wrap: on
line diff
--- a/src/pt-stmt.h +++ b/src/pt-stmt.h @@ -31,6 +31,8 @@ class tree_walker; +#include <deque> + #include "base-list.h" #include "comment-list.h" #include "symtab.h" @@ -158,11 +160,105 @@ tree_statement_list& operator = (const tree_statement_list&); }; -// Pointer to the current statement being executed. -extern tree_statement *curr_statement; +class tree_statement_stack +{ +protected: + + tree_statement_stack (void) : tss () { } + +public: + + typedef std::deque<tree_statement *>::iterator iterator ; + + static bool instance_ok (void) + { + bool retval = true; + + if (! instance) + instance = new tree_statement_stack (); + + if (! instance) + { + ::error ("unable to create stmt stack object!"); + + retval = false; + } + + return retval; + } + + // Current statement (top of stack). + static tree_statement *current (void) { return top (); } + + static int current_line (void) + { + tree_statement *s = current (); + return s ? s->line () : -1; + } + + static int current_column (void) + { + tree_statement *s = current (); + return s ? s->column () : -1; + } + + // Statement at position N on the call stack (N == 0 is current). + static tree_statement *element (size_t n) + { + return instance_ok () ? instance->do_element (n) : 0; + } -// Pointer to the current statement being executed in the calling function. -extern tree_statement *curr_caller_statement; + // Caller statement + static tree_statement *caller (void) { return element (1); } + + static void push (tree_statement *f) + { + if (instance_ok ()) + instance->do_push (f); + } + + static tree_statement *top (void) + { + return instance_ok () ? instance->do_top (): 0; + } + + static void pop (void) + { + if (instance_ok ()) + instance->do_pop (); + } + + // A function for popping the top of the call stack that is suitable + // for use as an unwind_protect handler. + static void unwind_pop (void *) { pop (); } + + static void clear (void) + { + if (instance_ok ()) + instance->do_clear (); + } + +private: + + // The current stmt stack. + std::deque<tree_statement *> tss; + + static tree_statement_stack *instance; + + tree_statement *do_element (size_t n) { return tss.size () > n ? tss[n] : 0; } + + void do_push (tree_statement *f) { tss.push_front (f); } + + tree_statement *do_top (void) { return tss.empty () ? 0 : tss.front (); } + + void do_pop (void) + { + if (! tss.empty ()) + tss.pop_front (); + } + + void do_clear (void) { tss.clear (); } +}; #endif