/* ======================================================================== bisl_sym - symbol-table handling for BISL compiler. Uses Plank's rb-tree library. Global routines: add_cstr - add named constraint to the symbol-table add_tupl - add named tuple to the symbol-table find_cstr - find named constraint in table find_tupl - find named tupl in table init_syms - initialize symbol-table Copyright 1996 Micah Beck / Simon D. Levy University of Tennessee All distributions of this product must include source code. Source code is not to be distributed in any modified form. ======================================================================== */ #include "bisl.h" #include "rb.h" /* red-black tree for symbol table */ static Rb_node m_etab, /* root of constraint symbol table */ m_ttab; /* root of tuple symbol table */ /* ------------------------------------------------------------------------ kill_insert - destructively insert item in table using name-key ------------------------------------------------------------------------ */ static void kill_insert( Rb_node tab, char *name, char *ptr) { int fnd; Rb_node n = rb_find_key_n(tab, name, &fnd); if (fnd) rb_delete_node(n); rb_insert(tab, name, ptr); } /* kill_insert */ /* ------------------------------------------------------------------------ add_cstr - add named constraint to the symbol-table ------------------------------------------------------------------------ */ void add_cstr(char *name, CSTR *cstr) { kill_insert(m_etab, name, (char *)cstr); /* insert in tree */ cstr->name = name; /* store name */ } /* add_cstr */ /* ------------------------------------------------------------------------ add_tupl - add named tuple to the symbol-table ------------------------------------------------------------------------ */ void add_tupl(char *name, TUPL *tupl) { kill_insert(m_ttab, name, (char *)tupl); /* insert in tree */ } /* add_tupl */ /* ------------------------------------------------------------------------ find_cstr - find named constraint in table, and return it a pointer to it, or zero if not found ------------------------------------------------------------------------ */ CSTR *find_cstr(char *name) { int fnd; Rb_node n = rb_find_key_n(m_etab, name, &fnd); if (fnd) return (CSTR *)n->v.val; else return 0; } /* find_cstr */ /* ------------------------------------------------------------------------ find_tupl - find named tupl in table, and return a pointer to it, or zero if not found ------------------------------------------------------------------------ */ TUPL *find_tupl(char *name) { int fnd; Rb_node n = rb_find_key_n(m_ttab, name, &fnd); if (fnd) return (TUPL *)n->v.val; else return 0; } /* find_tupl */ /* ------------------------------------------------------------------------ init_syms - initialize symbol-table ------------------------------------------------------------------------ */ void init_syms(void) { m_etab = make_rb(); m_ttab = make_rb(); } /* init_syms */