Initial revision
[LeanCalc.git] / calc / calc / symbol.h
1 /*
2  * symbol - global and local symbol routines
3  *
4  * Copyright (C) 1999  David I. Bell
5  *
6  * Calc is open software; you can redistribute it and/or modify it under
7  * the terms of the version 2.1 of the GNU Lesser General Public License
8  * as published by the Free Software Foundation.
9  *
10  * Calc is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
13  * Public License for more details.
14  *
15  * A copy of version 2.1 of the GNU Lesser General Public License is
16  * distributed with calc under the filename COPYING-LGPL.  You should have
17  * received a copy with calc; if not, write to Free Software Foundation, Inc.
18  * 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * @(#) $Revision$
21  * @(#) $Id$
22  * @(#) $Source$
23  *
24  * Under source code control:   1990/02/15 01:48:37
25  * File existed as early as:    before 1990
26  *
27  * Share and enjoy!  :-)        http://www.isthe.com/chongo/tech/comp/calc/
28  */
29
30
31 #if !defined(__SYMBOL_H__)
32 #define __SYMBOL_H__
33
34
35 #if defined(CALC_SRC)   /* if we are building from the calc source tree */
36 # include "calc/zmath.h"
37 #else
38 # include <calc/zmath.h>
39 #endif
40
41
42 /*
43  * Symbol Declarations.
44  */
45 #define SYM_UNDEFINED   0       /* undefined symbol */
46 #define SYM_PARAM       1       /* parameter symbol */
47 #define SYM_LOCAL       2       /* local symbol */
48 #define SYM_GLOBAL      3       /* global symbol */
49 #define SYM_STATIC      4       /* static symbol */
50
51 #define SCOPE_GLOBAL    0       /* file scope level for global variables */
52 #define SCOPE_STATIC    1       /* lowest file scope for static variables */
53
54
55 typedef struct global GLOBAL;
56 struct global {
57         int g_len;              /* length of symbol name */
58         short g_filescope;      /* file scope level of symbol (0 if global) */
59         short g_funcscope;      /* function scope level of symbol */
60         char *g_name;           /* global symbol name */
61         VALUE g_value;          /* global symbol value */
62         GLOBAL *g_next;         /* next symbol in hash chain */
63 };
64
65
66 /*
67  * Routines to search for global symbols.
68  */
69 extern GLOBAL *addglobal(char *name, BOOL isstatic);
70 extern GLOBAL *findglobal(char *name);
71
72
73 /*
74  * Routines to return names of variables.
75  */
76 extern char *localname(long n);
77 extern char *paramname(long n);
78 extern char *globalname(GLOBAL *sp);
79
80
81 /*
82  * Routines to handle entering and leaving of scope levels.
83  */
84 extern void resetscopes(void);
85 extern void enterfilescope(void);
86 extern void exitfilescope(void);
87 extern void enterfuncscope(void);
88 extern void exitfuncscope(void);
89 extern void endscope (char *name, BOOL isglobal);
90
91
92 /*
93  * Other routines.
94  */
95 extern long addlocal(char *name);
96 extern long findlocal(char *name);
97 extern long addparam(char *name);
98 extern long findparam(char *name);
99 extern void initlocals(void);
100 extern void initglobals(void);
101 extern int writeglobals(char *name);
102 extern int symboltype(char *name);
103 extern void showglobals(void);
104 extern void showallglobals(void);
105 extern void freeglobals(void);
106 extern void showstatics(void);
107 extern void freestatics(void);
108
109
110 #endif /* !__SYMBOL_H__ */