#ifndef _SYMTAB_H_
#define _SYMTAB_H_ 1

// This library provides support routines for handling scoped symbol tables.

// Goals:
// 1) support multiple independent symbol tables per scope.
// 2) need to be able to check that a new name does
//    not already exist in this scope and this table.
// 3) support looking up a name in specific table,
//    and return entry from most recent scope including this one.

// Scopes:
//    0 (base_level_scope) Would handle Imp %prim intrinsic routines known to compiler;
//        in C, perhaps things like __FUNCTION__ if they were variables rather than macros
//    1 for explicit declarations (eg externals) at top level before any nested scopes
//      - can replace something that was at level 0 (eg PRINTSTRING)
//        with an external call.
// 2..n first '{' takes us into scope level 2.

// This module does not define the symbol table format itself - that
// is managed by the caller's code - what we do here is assist in
// searching the symbol table while obeying scope rules.
// Actual symbol table entries are passed in and out as opaque "void *" objects.

int current_scope = -1;  // Base scope is scope 0. Most recent scope (top level) is current_scope.

// This interface is under development and may change if we encounter
// problems during integration with my new C compiler...

// There is no 'lookup only in a specific scope' call, as there appears
// to be no need for one yet.

int add_entry(char *table_name, char *entry_name, void *entry_data); // returns FALSE if already exists in this scope.
// (Table is created on the fly if one doesn't already exist in the current top-level scope)

void *lookup(char *table_name, char *entry_name);
int scope_level(char *table_name, char *entry_name);

// to determine if an identifier is a variable or a typename (when it could be either)
// you can lookup in both tables and decide according to which lookup is the most
// recent scope (ie highest scope value).  Note that a 'not found' result is returned
// as scope -1.

void push_scope_level(void);
void pop_scope_level(void);

#endif
