diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-19 22:12:16 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-20 06:07:33 +0100 |
commit | 90f203bff189706c2dec34482475b89d0a232597 (patch) | |
tree | a13c16ca7f73b779f941e0543bcff81d97e84b4d /goto.h | |
parent | b804417f36ef398f1223e439fd5ac9f2ade046eb (diff) | |
download | sciteco-90f203bff189706c2dec34482475b89d0a232597.tar.gz |
make goto tables local to macro invocation: they are declared on the C++ callstack since macro invocations result in nested macro_execute() calls
otherwise a macro could set labels with program counters which are invalid in other macros/the command line
Diffstat (limited to 'goto.h')
-rw-r--r-- | goto.h | 69 |
1 files changed, 67 insertions, 2 deletions
@@ -2,9 +2,76 @@ #define __GOTO_H #include <glib.h> +#include <glib/gprintf.h> #include "sciteco.h" #include "parser.h" +#include "undo.h" +#include "rbtree.h" + +class GotoTable : public RBTree { + class UndoTokenSet : public UndoToken { + GotoTable *table; + + gchar *name; + gint pc; + + public: + UndoTokenSet(GotoTable *_table, gchar *_name, gint _pc = -1) + : table(_table), name(g_strdup(_name)), pc(_pc) {} + ~UndoTokenSet() + { + g_free(name); + } + + void + run(void) + { + table->set(name, pc); +#ifdef DEBUG + table->dump(); +#endif + } + }; + + class Label : public RBEntry { + public: + gchar *name; + gint pc; + + Label(gchar *_name, gint _pc = -1) + : name(g_strdup(_name)), pc(_pc) {} + ~Label() + { + g_free(name); + } + + int + operator <(RBEntry &l2) + { + return g_strcmp0(name, ((Label &)l2).name); + } + }; + +public: + GotoTable() : RBTree() {} + + gint remove(gchar *name); + gint find(gchar *name); + + gint set(gchar *name, gint pc); + inline void + undo_set(gchar *name, gint pc = -1) + { + undo.push(new UndoTokenSet(this, name, pc)); + } + +#ifdef DEBUG + void dump(void); +#endif +}; + +extern GotoTable *goto_table; /* * Command states @@ -28,6 +95,4 @@ namespace States { extern StateGotoCmd gotocmd; } -void goto_table_clear(void); - #endif |