Pristine Ack-5.5
[Ack-5.5.git] / lang / occam / comp / symtab.h
1 /* $Id: symtab.h,v 1.7 1994/06/24 12:27:25 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 #ifndef nil
7 #define nil 0
8 #endif
9
10         /* Symbol/Expression type: */
11 #define T_VAR           0x0000
12 #define T_CHAN          0x0001
13 #define T_CONST         0x0002
14 #define T_VALUE         0x0003
15 #define T_PROC          0x0004
16 #define T_NOW           0x0005
17 #define T_VOID          0x0006
18
19 #define T_TYPE          0x0007  /* Mask for type bits */
20
21         /* Flags: */
22 #define T_ARR           0x0008  /* Object is an array */
23 #define T_BYTE          0x0010  /* Object is a byte array if T_ARR */
24 #define T_PARAM         0x0020  /* Formal parameter */
25 #define T_LVALUE        0x0040  /* This object may be assigned */
26 #define T_NOTDECL       0x0080  /* If you didn't declare it */
27 #define T_USED          0x0100  /* If you've used it */
28 #define T_ASSIGNED      0x0200  /* Or assigned it */
29 #define T_REP           0x0400  /* Replicator index */
30 #define T_BUILTIN       0x0800  /* Builtin name */
31 #define T_RECURS        0x1000  /* This proc is now compiled */
32 /* Note that some types and flags are only used for symbols, and others only
33  * for expressions.
34  */
35
36 struct symbol;
37
38 struct par_list {       /* List of parameter types for a proc object */
39         struct par_list *pr_next;
40         struct symbol *pr_var;  /* The formal parameter while visible */
41         int pr_type;            /* Its type */
42 };
43
44 struct expr;
45
46 union storage {         /* An object is found */
47         int level;      /* either at a certain local level */
48         char *builtin;  /* or using a global builtin name */
49 };
50
51 union type_info {
52         struct {
53                 union storage st;
54                 int offset;     /* from its local level or builtin name */
55         } vc;                   /* Variable or channel */
56
57         struct expr *t_const;
58
59         struct {
60                 union storage st;
61                 char *file;     /* file it is in */
62                 int label;      /* A unique id*/
63                 struct par_list *pars;
64         } proc;
65 };
66
67 struct symbol {
68         char    *s_name;
69         short   s_type;
70         int     s_arr_siz;
71         union type_info s_info;
72         struct symbol   *s_left, *s_right;
73 };
74
75 struct symtab {
76         struct symbol *local;
77         struct symtab *global;
78         int old_offset;
79 };
80
81 struct symbol *insert();
82 struct symbol *searchall();
83
84 void sym_down();
85 void sym_up();
86 void var_memory(), chan_memory();
87
88 void pars_add();
89 int form_offsets();
90 void check_recursion();
91
92 #define var_constant(v) (((v)->s_type&T_TYPE)==T_CONST)
93 #define var_proc(v)     (((v)->s_type&T_TYPE)==T_PROC)
94 #define var_declared(v) (! ((v)->s_type&T_NOTDECL))
95
96 extern union type_info none;