Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / loglan96 / loglan93 / symtable.h
1 typedef int bool;
2
3 typedef enum { FATHER,PREFIX,CLASS_S,PROCESS_S,COROUTINE_S,VARIABLE_S,SIGNAL_S,
4                CONSTANT_S,FUNCTION_S,PROCEDURE_S,BLOCK_S,HANDLERS_S }  type;
5
6 typedef enum { CLOSE,HIDDEN,TAKEN,NORMAL }  spec;
7
8 typedef enum { INTEGER,REAL,BOOLEAN,CHARACTER,STRING,FILE,SEMAPHORE,POINTER } var_type;
9
10 typedef enum { ALL,NOT_HIDDEN } visible;
11
12 typedef enum { SHARED,NOT_SHARED } sharing;
13
14
15
16
17 #define NO_OFFSET    -2
18 #define NO_IDENT     NULL
19 #define OFFSET          150   
20 #define TRUE          1
21 #define FALSE         0
22 #define MAIN_LEVEL    0   
23 #define DOT           TRUE
24 #define NOT_DOT       FALSE
25
26 class packet {public : };
27
28 class entry
29 {
30 public :
31   String  id;
32   type    kind;
33   int     offset;
34   spec    visible;
35   packet* rest;
36   entry*  prev;
37
38   entry(String,type,int,spec,packet*);
39 };
40
41 struct find_result
42 {
43   int    level;
44   entry* found;         
45
46   find_result(int l,entry* e) { level=l;found=e;}
47 };
48
49
50 class list_elem
51 {
52 public :
53   entry*      info_ptr;
54   list_elem*  next;
55   list_elem(entry*  e) { info_ptr=e; };
56 };
57
58 class list
59 {
60 public :
61   list_elem*  end_ptr;
62   void        add_elem(entry*);
63
64   entry*      find_virt(String); 
65
66   list()      { end_ptr=NULL; };
67 };
68
69 class spec_elem
70 {
71 public :
72   String      info;
73   spec_elem*  next;
74
75   spec_elem(String e,spec_elem* n) { info=e;next=n; };
76 };
77
78 class spec_list
79 {
80 public :
81   spec_elem*  end_ptr;
82
83   void        add    ( String );
84   bool        present( String );
85
86   spec_list() { end_ptr=NULL; };
87 };
88
89 class pref_list_elem
90 {
91   public :
92   entry*    where;
93   int       base;
94   sharing      shared;
95   pref_list_elem* next; 
96
97   pref_list_elem(entry* e,sharing sh,pref_list_elem* c)
98   {
99     where  = e;
100     shared = sh;
101     next   = c;
102   };
103
104 };
105
106
107 class pref_list
108 {
109 public :
110   pref_list_elem*  end_ptr;
111   void add_pref(entry*,sharing);
112   pref_list() {end_ptr=NULL;};
113 };
114
115 class node
116 {
117 public :
118   int         level;
119   int         current_offset;
120   entry*      end_ptr;
121   entry*      begin_ptr;
122   list*       virtual_list;
123   list*       formal_param_list;
124   list*       ref_var_list;
125   pref_list*  prefix;
126   spec_list*  close;
127   spec_list*  hidden;
128   spec_list*  taken; 
129
130   void        add_spec(spec,String);
131   void        add_virt(entry*);
132   void        add_form_param(entry*);
133   void        close_unit();
134   node*       open_unit();
135   struct find_result*   local_find(String,visible);
136   node(int);
137  
138 };
139
140 class c_class : public packet
141 {
142 public :
143   pref_list*  prefix;
144   bool        f_param;
145   bool        virt;  // or shared
146   node*       my_symtab;
147
148 };
149
150 class f_father : public packet
151 {
152 public :
153   node*   father_ptr;
154   int     level;
155   int     base;
156   f_father(node* ff,int ll) {    father_ptr=ff;level=ll;  };
157 };
158
159 class symboltable
160 {
161 public :
162   node*   last;
163   node*   root;
164   entry*   inherit(String,sharing sh = NOT_SHARED);
165   entry*  insert(String,type,packet*);
166
167   struct find_result* find_in_module(node*,String,bool,visible vis = ALL);
168
169   struct find_result* find(String);
170   symboltable()  {root=last=new node(MAIN_LEVEL);};
171 };
172
173 class v_variable : public packet
174 {
175 public :
176   var_type  type;
177   bool      f_param;
178 };
179
180 class s_signal : public c_class {};
181
182 class h_handler : public c_class  {}; 
183
184 class c_coroutine : public c_class { };
185
186 class p_process : public c_class {};
187
188 class b_block : public c_class {};
189
190 class p_procedure : public c_class { public: } ;
191
192 class f_function : public c_class {
193
194 public :
195   type       result_type;
196 };
197
198 class c_constant : public packet
199 {
200 public :
201   int   ptr;  //here will be link to constant value
202 };