1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
/* l2xisdcl.c LTX2X declaration analysis */
/* Written by: Peter Wilson, CUA pwilson@cme.nist.gov */
/* This code is partly based on algorithms presented by Ronald Mak in */
/* "Writing Compilers & Interpreters", John Wiley & Sons, 1991 */
#include <stdio.h>
#include "l2xicmon.h"
#include "l2xierr.h"
#include "l2xiscan.h"
#include "l2xisymt.h"
#include "l2xiidbg.h"
/* EXTERNALS */
extern int line_number;
extern TOKEN_CODE token;
/* GLOBALS */
char buffer[MAX_PRINT_LINE_LENGTH];
char *defn_names[] = {
#define dfntc(a, b) b,
#include "l2xidftc.h"
#undef dfntc
};
char *form_names[] = {
#define fotc(a, b, c, d) d,
#define sotc(a, b, c, d)
#define sftc(a, b, c, d) d,
#include "l2xisftc.h"
#undef fotc
#undef sotc
#undef sftc
};
/* ANALYSIS */
/***************************************************************************/
/* analyze_const_defn(idp) Analyze a constant definition */
analyze_const_defn(idp)
SYMTAB_NODE_PTR idp; /* constant id */
{
char *bp;
if (DEBUG < Danalyze) return;
/* the name */
sprintf(buffer, ">> id = %s\n", idp->name);
debug_print(buffer);
sprintf(buffer, ">> address = %d\n", idp);
/* definition and value */
sprintf(buffer, ">> defn = %s, value = ", defn_names[idp->defn.key]);
bp = buffer + strlen(buffer);
if ((idp->typep == integer_typep) || (idp->typep->form == ENUM_FORM))
sprintf(bp, "%d\n", idp->defn.info.constant.value.integer);
else if (idp->typep == real_typep)
sprintf(bp, "%g\n", idp->defn.info.constant.value.real);
else if (idp->typep->form == ARRAY_FORM) /* ????????????????????????? */
sprintf(bp, "'%s'\n", idp->defn.info.constant.value.stringp);
else if (idp->typep->form == STRING_FORM)
sprintf(bp, "'%s'\n", idp->defn.info.constant.value.stringp);
debug_print(buffer);
/* and type. careful as an enum type will get into an infinite loop */
if (idp->typep->form != ENUM_FORM) analyze_type(idp->typep, FALSE);
} /* end analyze_const_defn */
/***************************************************************************/
/***************************************************************************/
/* analyze_type_defn(idp) Analyze a type definition */
analyze_type_defn(idp)
SYMTAB_NODE_PTR idp; /* id */
{
char *bp;
if (DEBUG < Danalyze) return;
/* the type's name, definition ... */
sprintf(buffer, ">>id = %s\n", idp->name);
debug_print(buffer);
sprintf(buffer, ">> address = %d\n", idp);
debug_print(buffer);
sprintf(buffer, ">> defn = %s\n", defn_names[idp->defn.key]);
/* print_line(buffer); */
debug_print(buffer);
/* and type */
analyze_type(idp->typep, TRUE);
} /* end analyze_type_defn */
/***************************************************************************/
/***************************************************************************/
/* analyze_type(tp, verbose_flag) Analyze a type definition */
analyze_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
char *bp;
if (DEBUG < Danalyze) return;
if (tp == NULL) return;
/* the form, byte size (and name) */
sprintf(buffer, ">> form = %s, size = %d bytes, type id = ",
form_names[tp->form], tp->size);
bp = buffer + strlen(buffer);
if (tp->type_idp != NULL)
sprintf(bp, "%s\n", tp->type_idp->name);
else {
sprintf(bp, "<unnamed type>\n");
verbose_flag = TRUE;
}
debug_print(buffer);
/* do the appropriate analysus */
switch (tp->form) {
case ENUM_FORM: {
analyze_enum_type(tp, verbose_flag);
break;
}
case SUBRANGE_FORM: {
analyze_subrange_type(tp, verbose_flag);
break;
}
case ARRAY_FORM: {
analyze_array_type(tp, verbose_flag);
break;
}
case STRING_FORM: {
verbose_flag = TRUE;
analyze_string_type(tp, verbose_flag);
break;
}
case BOUND_FORM: {
analyze_bound_type(tp, verbose_flag);
break;
}
case ENTITY_FORM: {
analyze_entity_type(tp, verbose_flag);
break;
}
case BAG_FORM:
case LIST_FORM:
case SET_FORM: {
analyze_bls_type(tp, verbose_flag);
break;
}
default: {
break;
}
} /* end switch */
} /* end analyze_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_enum_type(tp, verbose_flag) Analyze an enumeration type */
analyze_enum_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
/* loop to analyze each enum constant as a constant defn */
debug_print(">> -- Enum Constants --\n");
for (idp = tp->info.enumeration.const_idp; idp != NULL; idp = idp->next) {
analyze_const_defn(idp);
}
} /* end analyze_enum_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_subrange_type(tp, verbose_flag) Analyze a subrange type */
analyze_subrange_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
sprintf(buffer, ">> min value = %d, max value = %d\n",
tp->info.subrange.min, tp->info.subrange.max);
debug_print(buffer);
debug_print(">> -- Range Type -- \n");
analyze_type(tp->info.subrange.range_typep, FALSE);
} /* end analyze_subrange_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_bound_type(tp, verbose_flag) Analyze a bound type */
analyze_bound_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
sprintf(buffer, ">> min value = %d, max value = %d\n",
tp->info.bound.min, tp->info.bound.max);
debug_print(buffer);
debug_print(">> -- Bound Type -- \n");
analyze_type(tp->info.bound.bound_typep, FALSE);
} /* end analyze_bound_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_array_type(tp, verbose_flag) Analyze an array type */
analyze_array_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
sprintf(buffer, ">> element count = %d\n",
tp->info.array.elmt_count);
debug_print(buffer);
sprintf(buffer, ">> index limits = %d to %d\n",
tp->info.array.min_index, tp->info.array.max_index);
debug_print(buffer);
debug_print(">> -- INDEX TYPE -- \n");
analyze_type(tp->info.array.index_typep, FALSE);
debug_print(">> -- ELEMENT TYPE -- \n");
analyze_type(tp->info.array.elmt_typep, FALSE);
} /* end analyze_array_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_bls_type(tp, verbose_flag) Analyze a bag, etc type */
analyze_bls_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
sprintf(buffer, ">> element count = %d\n",
tp->info.dynagg.elmt_count);
debug_print(buffer);
sprintf(buffer, ">> index limits = %d to %d\n",
tp->info.dynagg.min_index, tp->info.dynagg.max_index);
debug_print(buffer);
debug_print(">> -- INDEX TYPE -- \n");
analyze_type(tp->info.dynagg.index_typep, FALSE);
debug_print(">> -- ELEMENT TYPE -- \n");
analyze_type(tp->info.dynagg.elmt_typep, FALSE);
} /* end analyze_bls_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_string_type(tp, verbose_flag) Analyze a string type */
analyze_string_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
sprintf(buffer, ">> maximum length = %d\n",
tp->info.string.max_length);
debug_print(buffer);
sprintf(buffer, ">> length = %d\n",
tp->info.string.length);
debug_print(buffer);
return;
} /* end analyze_string_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_entity_type(tp, verbose_flag) Analyze an entity type */
analyze_entity_type(tp, verbose_flag)
TYPE_STRUCT_PTR tp; /* pointer to type structure */
BOOLEAN verbose_flag; /* TRUE for verbose analysis */
{
SYMTAB_NODE_PTR idp; /* id */
if (DEBUG < Danalyze) return;
if (!verbose_flag) return;
/* loop to analyze each attribute as a variable decl */
debug_print(">> -- Attributes -- \n");
for (idp = tp->info.entity.attribute_symtab; idp != NULL; idp = idp->next) {
analyze_var_decl(idp);
}
} /* end analyze_entity_type */
/***************************************************************************/
/***************************************************************************/
/* analyze_var_decl(idp) Analyze a variable declaration */
analyze_var_decl(idp)
SYMTAB_NODE_PTR idp; /* id */
{
if (DEBUG < Danalyze) return;
/* the name, definition and offset */
sprintf(buffer, ">> id = %s\n", idp->name);
debug_print(buffer);
sprintf(buffer, ">> address = %d\n", idp);
debug_print(buffer);
sprintf(buffer, ">> defn = %s, offset = %d\n",
defn_names[idp->defn.key], idp->defn.info.data.offset);
/* print_line(buffer); */
debug_print(buffer);
/* and type */
analyze_type(idp->typep, FALSE);
} /* end analyze_var_decl */
/***************************************************************************/
/***************************************************************************/
/* analyze_block(code_segment) a dummy procedure */
analyze_block(code_segment)
char *code_segment;
{
return;
} /* end analyze_block */
/***************************************************************************/
/***************************************************************************/
/* analyze_routine_header(rtn_idp) a dummy procedure */
analyze_routine_header(rtn_idp)
SYMTAB_NODE_PTR rtn_idp;
{
return;
} /* end analyze_routine_header */
/***************************************************************************/
/***************************************************************************/
|