Mercurial > hg > octave-terminal
changeset 220:f736a3ec137e
[project @ 1993-11-14 00:10:26 by jwe]
author | jwe |
---|---|
date | Sun, 14 Nov 1993 00:10:29 +0000 |
parents | e3b1b79cc604 |
children | e2110730e556 |
files | src/symtab.cc src/symtab.h |
diffstat | 2 files changed, 66 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -628,6 +628,33 @@ next_elem = s; } +void +symbol_record::push_context (void) +{ + context.push (definition); + definition = (symbol_def *) NULL; +} + +void +symbol_record::pop_context (void) +{ + assert (! context.empty ()); + + if (is_variable ()) + { + symbol_def *old_def = pop_def (); + maybe_delete (old_def); + } + + if (is_function ()) + { + symbol_def *old_def = pop_def (); + maybe_delete (old_def); + } + + definition = context.pop (); +} + int symbol_record::read_only_error (void) { @@ -1070,6 +1097,36 @@ return symbols; } +void +symbol_table::push_context (void) +{ + for (int i = 0; i < HASH_TABLE_SIZE; i++) + { + symbol_record *ptr = table[i].next (); + + while (ptr != (symbol_record *) NULL) + { + ptr->push_context (); + ptr = ptr->next (); + } + } +} + +void +symbol_table::pop_context (void) +{ + for (int i = 0; i < HASH_TABLE_SIZE; i++) + { + symbol_record *ptr = table[i].next (); + + while (ptr != (symbol_record *) NULL) + { + ptr->pop_context (); + ptr = ptr->next (); + } + } +} + // Chris Torek's fave hash function. unsigned int
--- a/src/symtab.h +++ b/src/symtab.h @@ -33,6 +33,8 @@ #include <iostream.h> #include <assert.h> +#include "SLStack.h" + #ifndef SV_FUNCTION_TYPEDEFS #define SV_FUNCTION_TYPEDEFS 1 @@ -182,6 +184,9 @@ void chain (symbol_record *s); + void push_context (void); + void pop_context (void); + private: unsigned formal_param : 1; @@ -191,6 +196,7 @@ sv_Function sv_fcn; symbol_def *definition; symbol_record *next_elem; + SLStack <symbol_def *> context; void init_state (void); @@ -304,6 +310,9 @@ unsigned type = SYMTAB_ALL_TYPES, unsigned scope = SYMTAB_ALL_SCOPES) const; + void push_context (void); + void pop_context (void); + private: unsigned int hash (const char *s);