|
|
1.1 root 1: /* dtabs.c */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/pepsy/RCS/dtabs.c,v 7.2 90/07/27 08:49:09 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/pepsy/RCS/dtabs.c,v 7.2 90/07/27 08:49:09 mrose Exp $
9: *
10: *
11: * $Log: dtabs.c,v $
12: * Revision 7.2 90/07/27 08:49:09 mrose
13: * update
14: *
15: * Revision 7.1 90/07/09 14:52:25 mrose
16: * sync
17: *
18: * Revision 7.0 90/07/01 19:54:15 mrose
19: * *** empty log message ***
20: *
21: */
22:
23: /*
24: * NOTICE
25: *
26: * Acquisition, use, and distribution of this module and related
27: * materials are subject to the restrictions of a license agreement.
28: * Consult the Preface in the User's Manual for the full terms of
29: * this agreement.
30: *
31: */
32:
33:
34: #include <stdio.h>
35: #include "pepsydefs.h"
36: #include "pass2.h"
37: #include "mine.h"
38:
39:
40: extern FILE *fptab;
41: extern char *c_tag(), *c_class();
42: extern char *ec_tag(), *ec_class();
43: extern char *strip_last();
44: extern char *str_yp_code[];
45: extern char *get_val(), *get_comp(), *strp2name();
46: extern s_table *lookup_list(), *get_offset();
47: extern YP tdec_loop();
48:
49: extern char *concat();
50: extern char *my_strcat();
51:
52: /* extern int explicit; */
53:
54: static int cons_type = 0;
55:
56: s_table *ptr;
57: s_table *save_ptr;
58:
59: #define WORDSIZE 20
60:
61: /*
62: * table encode a type. generate tables for the encoding of a type
63: */
64: tdec_typ(yp, id, type)
65: YP yp;
66: char *id;
67: char *type;
68: {
69: char *t, *f;
70: char *p1;
71: char *s1, *s2, *s3;
72: char *s;
73: s_table *ptr1, *ptr2;
74: YP y;
75:
76: if (yp->yp_code < 0 || yp->yp_code > YP_REAL)
77: ferrd(1, "tdec_typ: unimplemented type %d\n", yp->yp_code);
78:
79: if (yp == NULL) {
80: ferr(0, "tdec_typ:NULL arguement\n");
81: return;
82: }
83: /* explicit = 0; */
84:
85: if (yp->yp_flags & YP_TAG && !(yp->yp_flags & YP_IMPLICIT)) {
86: (void) fprintf(fptab, "\t{ ETAG, 0, ");
87: /* (void) fprintf(fptab, "%d, ", c_type(yp)); */
88: (void) fprintf(fptab, "%s, %s },\n", ec_tag(yp), ec_class(yp));
89: /* explicit++; */
90: }
91: if (type)
92: t = type;
93: else {
94: t = my_strcat("struct ", modsym(mymodule, id, "type"));
95: switch (yp->yp_code) {
96: /*
97: * These generate MALLOC entries inside *_START ..
98: * PE_END fields for historical reasons. One day we might
99: * fix this to be all done the same way.
100: */
101: case YP_SEQLIST:
102: case YP_SEQTYPE:
103: case YP_SETLIST:
104: case YP_SETTYPE:
105: case YP_CHOICE:
106: break;
107:
108: default:
109: if (yp->yp_varexp == NULL)
110: break; /* S* type entry - doesn't need a
111: * malloc */
112:
113: (void) fprintf(fptab, "\t{ MALLOC, 0, sizeof (%s), 0 },\n", t);
114: break;
115: }
116: }
117:
118: f = yp->yp_varexp;
119: switch (yp->yp_code) {
120:
121: case YP_UNDF:
122: ferr(1, "tdec_typ:Undefined type\n");
123:
124: case YP_BOOL:
125: p1 = "BOOLEAN";
126: if (!yp->yp_varexp)
127: t = NULL;
128: break;
129:
130: /* This needs to be fixed up in the action generating area */
131: case YP_INTLIST:
132:
133: case YP_INT:
134:
135: case YP_ENUMLIST:
136: if (yp->yp_varexp) {
137: p1 = "INTEGER";
138: break;
139: }
140: t = NULL;
141: p1 = NULL;
142: (void) fprintf(fptab, "\t{ SINTEGER, 0, %s, %s },\n",
143: c_tag(yp), c_class(yp));
144: break;
145:
146: case YP_REAL:
147: if (yp->yp_varexp) {
148: p1 = "REALTYPE";
149: break;
150: }
151: t = NULL;
152: p1 = NULL;
153: (void) fprintf(fptab, "\t{ SREALTYPE, 0, %s, %s },\n",
154: c_tag(yp), c_class(yp));
155: break;
156:
157:
158: case YP_BIT:
159: case YP_BITLIST:
160: if (yp->yp_varexp) {
161: p1 = "BITSTRING";
162: break;
163: }
164: t = NULL;
165: p1 = NULL;
166: (void) fprintf(fptab, "\t{ SBITSTRING, 0, %s, %s },\n",
167: c_tag(yp), c_class(yp));
168: break;
169:
170: case YP_OCT:
171: if (yp->yp_varexp) {
172: p1 = "OCTETSTRING";
173: break;
174: }
175: t = NULL;
176: p1 = NULL;
177: (void) fprintf(fptab, "\t{ SOCTETSTRING, 0, %s, %s },\n",
178: c_tag(yp), c_class(yp));
179: break;
180:
181: case YP_OID:
182: if (yp->yp_varexp) {
183: p1 = "OBJID";
184: break;
185: }
186: t = NULL;
187: p1 = NULL;
188: (void) fprintf(fptab, "\t{ SOBJID, 0, %s, %s },\n",
189: c_tag(yp), c_class(yp));
190: break;
191:
192: case YP_SEQ:
193: case YP_SET:
194: case YP_ANY:
195: /*
196: * if (cons_type) p1 = "CONS_ANY"; else
197: */
198: if (yp->yp_varexp) {
199: p1 = "ANY";
200: break;
201: }
202: t = NULL;
203: p1 = NULL;
204: (void) fprintf(fptab, "\t{ SANY, 0, %s, %s },\n",
205: c_tag(yp), c_class(yp));
206: break;
207:
208: case YP_NULL:
209: p1 = "T_NULL";
210: t = NULL;
211: break;
212:
213: case YP_IDEFINED:
214: p1 = NULL;
215: {
216: /* Predefined Universal Type */
217: struct univ_typ *p, *univtyp();
218:
219: if ((p = univtyp(yp->yp_identifier))) {
220: if (p->univ_flags & UNF_EXTMOD) {
221: yp->yp_module = p->univ_mod;
222: goto do_obj;
223: }
224: if (f == NULL) {/* No offset type */
225: if (yp->yp_flags & YP_TAG
226: && yp->yp_flags & YP_IMPLICIT)
227: (void) fprintf(fptab, "\t{ S%s, 0, %d, %s },\n",
228: p->univ_tab,
229: yp->yp_tag->yt_value->yv_number,
230: c_flags(yp, yp->yp_tag->yt_class));
231: else
232: (void) fprintf(fptab, "\t{ S%s, 0, %d, %s },\n",
233: p->univ_tab, p->univ_id,
234: c_flags(yp, p->univ_class));
235: goto out;
236: }
237: if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
238: (void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
239: p->univ_tab, t, f,
240: yp->yp_tag->yt_value->yv_number,
241: c_flags(yp, yp->yp_tag->yt_class));
242: else
243: (void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
244: p->univ_tab, t, f, p->univ_id,
245: c_flags(yp, p->univ_class));
246: goto out;
247: }
248: }
249: do_obj:
250: if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
251: (void) fprintf(fptab, "\t{ IMP_OBJ, 0, %s, %s },\n", c_tag(yp), c_class(yp));
252: if (yp->yp_parm) {
253: ferr(1, "tenc_typ:YP_IDEFINED:yp_parm found\n");
254: }
255: if (yp->yp_module == NULL
256: || strcmp(yp->yp_module, mymodule) == 0) {
257: if (f == NULL)
258: (void) fprintf(fptab, "\t{ SOBJECT, 0, _Z%s, %s },\n",
259: proc_name(yp->yp_identifier, 0), c_class(yp));
260: else
261: (void) fprintf(fptab, "\t{ OBJECT, OFFSET(%s, %s), _Z%s, %s },\n",
262: t, f, proc_name(yp->yp_identifier, 0), c_class(yp));
263: } else {
264: if (f == NULL)
265: (void) fprintf(fptab, "\t{ SEXTOBJ, 0, _Z%s, %s },\n",
266: strp2name(yp->yp_identifier, yp->yp_module),
267: c_class(yp));
268: else
269: (void) fprintf(fptab, "\t{ EXTOBJ, OFFSET(%s, %s), _Z%s, %s },\n",
270: t, f, strp2name(yp->yp_identifier, yp->yp_module),
271: c_class(yp));
272: (void) fprintf(fptab, "\t{ EXTMOD, %d, 0, 0 },\n",
273: gen_modref(yp->yp_module));
274: }
275: out:
276: if (yp->yp_flags & YP_DEFAULT)
277: gdflt(yp, G_DEC);
278: break;
279:
280: case YP_SEQLIST:
281: p1 = NULL;
282: /* support for -h flag */
283: #if 0
284: if (hflag && (y = yp->yp_type) && !y->yp_next) {
285: tdec_typ(y, id, yp->yp_structname);
286: break;
287: }
288: #endif
289: cons_type++;
290: save_ptr = ptr;
291: if (yp->yp_varexp == NULL && type != NULL)
292: ferr(1, "tdec_typ:YP_SEQLIST:NULL varexp pointer\n");
293: if (type != NULL)
294: (void) fprintf(fptab, "\t{ SEQ_START, OFFSET(%s, %s), %s, %s },\n",
295: t, f, c_tag(yp), c_class(yp));
296: else
297: (void) fprintf(fptab, "\t{ SEQ_START, 0, %s, %s },\n",
298: c_tag(yp), c_class(yp));
299:
300: if (yp->yp_flags & YP_DEFAULT)
301: gdflt(yp, G_DEC);
302: if (y = yp->yp_type) {
303: genmalloc(yp);
304: if (type) {
305: if (yp->yp_declexp == NULL)
306: ferr(1, "tdec_typ:YP_SEQLIST:no declexp\n");
307: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
308: } else
309: yp->yp_structname = t;
310: if (optfield(y)) {
311: (void) fprintf(fptab,
312: "\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
313: yp->yp_structname);
314: }
315: tdec_loop(y, id, yp->yp_structname);
316: }
317: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
318: ptr = save_ptr;
319: cons_type--;
320: break;
321:
322: case YP_SETLIST:
323: p1 = NULL;
324: /* support for -h flag */
325: #if 0
326: if (hflag && (y = yp->yp_type) && !y->yp_next) {
327: tdec_typ(y, id, yp->yp_structname);
328: break;
329: }
330: #endif
331: p1 = NULL;
332: cons_type++;
333: if (yp->yp_varexp == NULL && type != NULL)
334: ferr(1, "tdec_typ:YP_SETLIST:NULL varexp pointer\n");
335: if (type != NULL)
336: (void) fprintf(fptab, "\t{ SET_START, OFFSET(%s, %s), %s, %s },\n",
337: t, f, c_tag(yp), c_class(yp));
338: else
339: (void) fprintf(fptab, "\t{ SET_START, 0, %s, %s },\n",
340: c_tag(yp), c_class(yp));
341:
342: if (yp->yp_flags & YP_DEFAULT)
343: gdflt(yp, G_DEC);
344: if (y = yp->yp_type) {
345: genmalloc(yp);
346: if (type) {
347: if (yp->yp_declexp == NULL)
348: ferr(1, "tdec_typ:YP_SETLIST:no declexp\n");
349: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
350: } else
351: yp->yp_structname = t;
352: if (optfield(y)) {
353: (void) fprintf(fptab,
354: "\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
355: yp->yp_structname);
356: }
357: tdec_loop(y, id, yp->yp_structname);
358: }
359: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
360: ptr = save_ptr;
361: cons_type--;
362: break;
363:
364: case YP_SEQTYPE: /* What is the difference ?? */
365: p1 = NULL;
366: cons_type++;
367: save_ptr = ptr;
368: if (type != NULL)
369: (void) fprintf(fptab, "\t{ SEQOF_START, OFFSET(%s, %s), %s, %s },\n",
370: t, f, c_tag(yp), c_class(yp));
371: else
372: (void) fprintf(fptab, "\t{ SEQOF_START, 0, %s, %s },\n",
373: c_tag(yp), c_class(yp));
374: if (yp->yp_flags & YP_DEFAULT)
375: gdflt(yp, G_DEC);
376:
377: if (y = yp->yp_type) {
378: genmalloc(yp);
379: if (type) {
380: if (yp->yp_declexp == NULL)
381: ferr(1, "tdec_typ:YP_SEQTYPE:no declexp\n");
382: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
383: } else
384: yp->yp_structname = t;
385: tdec_loop(y, id, yp->yp_structname);
386: }
387: if (yp->yp_structname != NULL)
388: (void) fprintf(fptab, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
389: yp->yp_structname);
390: else
391: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
392: ptr = save_ptr;
393: cons_type--;
394: break;
395:
396: case YP_SETTYPE:
397: p1 = NULL;
398: cons_type++;
399: save_ptr = ptr;
400: if (type != NULL)
401: (void) fprintf(fptab, "\t{ SETOF_START, OFFSET(%s, %s), %s, %s },\n",
402: t, f, c_tag(yp), c_class(yp));
403: else
404: (void) fprintf(fptab, "\t{ SETOF_START, 0, %s, %s },\n",
405: c_tag(yp), c_class(yp));
406:
407: if (yp->yp_flags & YP_DEFAULT)
408: gdflt(yp, G_DEC);
409:
410: if (y = yp->yp_type) {
411: genmalloc(yp);
412: if (type) {
413: if (yp->yp_declexp == NULL)
414: ferr(1, "tdec_typ:YP_SETTYPE:no declexp\n");
415: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
416: } else
417: yp->yp_structname = t;
418: tdec_loop(y, id, yp->yp_structname);
419: }
420: if (yp->yp_structname != NULL)
421: (void) fprintf(fptab, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
422: yp->yp_structname);
423: else
424: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
425: ptr = save_ptr;
426: cons_type--;
427: break;
428:
429: case YP_CHOICE:
430: p1 = NULL;
431: /* support for -h flag */
432: if (hflag && (y = yp->yp_type) && !y->yp_next) {
433: tdec_typ(y, id, yp->yp_structname);
434: break;
435: }
436: cons_type++;
437: save_ptr = ptr;
438: if (type != NULL)
439: (void) fprintf(fptab, "\t{ CHOICE_START, OFFSET(%s, %s), 0, %s },\n",
440: t, f, c_class(yp));
441: else
442: (void) fprintf(fptab, "\t{ CHOICE_START, 0, 0, 0 },\n");
443:
444: if (yp->yp_flags & YP_DEFAULT)
445: gdflt(yp, G_DEC);
446: if (y = yp->yp_type) {
447: genmalloc(yp);
448: (void) fprintf(fptab, "\t{ SCTRL, OFFSET(%s, offset), 0, 0 },\n",
449: yp->yp_structname);
450: if (type) {
451: if (yp->yp_declexp == NULL)
452: ferr(1, "tdec_typ:YP_CHOICE:no declexp\n");
453: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
454: } else
455: yp->yp_structname = t;
456: tdec_loop(y, id, yp->yp_structname);
457: }
458: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
459: ptr = save_ptr;
460: cons_type--;
461: break;
462:
463: default:
464: ferrd(1, "tdec_typ: yp_code = %d not implemented\n", yp->yp_code);
465: }
466:
467: if (p1 != NULL) {
468: if (t != NULL) {
469: (void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %s, %s },\n", p1, t, f,
470: c_tag(yp), c_class(yp));
471: } else {
472: (void) fprintf(fptab, "\t{ %s, 0, %s, %s },\n", p1, c_tag(yp),
473: c_class(yp));
474: }
475:
476: if (yp->yp_flags & YP_DEFAULT)
477: gdflt(yp, G_DEC);
478: }
479: }
480:
481: static int fflags[] = {
482: 0, 1, 2, 2, 3, 3, 4, 5, 16, 16, 16, 17, 17, 17,
483: 0, -1, 7,};
484:
485: /*
486: * generate tables for encoding a contructed type
487: */
488: YP
489: tdec_loop(yp, id, type)
490: YP yp;
491: char *id;
492: char *type;
493: {
494: for (; yp != NULL; yp = yp->yp_next) {
495: tdec_typ(yp, id, type);
496: }
497: }
498: /*
499: * Generate a malloc of for the given object
500: */
501: genmalloc(yp)
502: YP yp;
503: {
504:
505: (void) fprintf(fptab, "\t{ MALLOC, 0, sizeof (%s), 0 },\n", yp->yp_structname);
506: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.