head	1.1;
access;
symbols;
locks
	gtoal:1.1; strict;
comment	@ * @;


1.1
date	2024.05.28.02.18.10;	author gtoal;	state Exp;
branches;
next	;


desc
@symtab.h
@


1.1
log
@Initial revision
@
text
@#ifndef _SYMTAB_H_
#define _SYMTAB_H_ 1

extern int debug_scope;

#ifdef OLD_VERSION
#define DATA void *
#define NO_DATA NULL
#else
#define DATA int
#define NO_DATA (-1)
#endif

// 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.  NO. Now as DATA type which is being changed to "int" ...

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

// 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.

extern int add_entry(char *table_name, char *entry_name, DATA 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)

extern DATA lookup(char *table_name, char *entry_name);
extern 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.

// It might be useful to have a tag that can be added to a scope level
// in case it matters what type of scope was entered.  This should be
// separate from the explicit stucture stack such as in Imp where you
// have to keep track of begin/routine/start/cycle nesting.  Meanwhile, not.
extern void push_scope_level(void);
extern void pop_scope_level(void);

#endif
@
