|
|
BSD 4.3reno
/* dtabs.c */
#ifndef lint
static char *rcsid = "$Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/pepsy/dtabs.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $";
#endif
/*
* $Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/pepsy/dtabs.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $
*
*
* $Log: dtabs.c,v $
* Revision 1.1.1.1 2018/04/24 16:12:56 root
* BSD 4.3reno
*
* Revision 7.2 90/07/27 08:49:09 mrose
* update
*
* Revision 7.1 90/07/09 14:52:25 mrose
* sync
*
* Revision 7.0 90/07/01 19:54:15 mrose
* *** empty log message ***
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
#include <stdio.h>
#include "pepsydefs.h"
#include "pass2.h"
#include "mine.h"
extern FILE *fptab;
extern char *c_tag(), *c_class();
extern char *ec_tag(), *ec_class();
extern char *strip_last();
extern char *str_yp_code[];
extern char *get_val(), *get_comp(), *strp2name();
extern s_table *lookup_list(), *get_offset();
extern YP tdec_loop();
extern char *concat();
extern char *my_strcat();
/* extern int explicit; */
static int cons_type = 0;
s_table *ptr;
s_table *save_ptr;
#define WORDSIZE 20
/*
* table encode a type. generate tables for the encoding of a type
*/
tdec_typ(yp, id, type)
YP yp;
char *id;
char *type;
{
char *t, *f;
char *p1;
char *s1, *s2, *s3;
char *s;
s_table *ptr1, *ptr2;
YP y;
if (yp->yp_code < 0 || yp->yp_code > YP_REAL)
ferrd(1, "tdec_typ: unimplemented type %d\n", yp->yp_code);
if (yp == NULL) {
ferr(0, "tdec_typ:NULL arguement\n");
return;
}
/* explicit = 0; */
if (yp->yp_flags & YP_TAG && !(yp->yp_flags & YP_IMPLICIT)) {
(void) fprintf(fptab, "\t{ ETAG, 0, ");
/* (void) fprintf(fptab, "%d, ", c_type(yp)); */
(void) fprintf(fptab, "%s, %s },\n", ec_tag(yp), ec_class(yp));
/* explicit++; */
}
if (type)
t = type;
else {
t = my_strcat("struct ", modsym(mymodule, id, "type"));
switch (yp->yp_code) {
/*
* These generate MALLOC entries inside *_START ..
* PE_END fields for historical reasons. One day we might
* fix this to be all done the same way.
*/
case YP_SEQLIST:
case YP_SEQTYPE:
case YP_SETLIST:
case YP_SETTYPE:
case YP_CHOICE:
break;
default:
if (yp->yp_varexp == NULL)
break; /* S* type entry - doesn't need a
* malloc */
(void) fprintf(fptab, "\t{ MALLOC, 0, sizeof (%s), 0 },\n", t);
break;
}
}
f = yp->yp_varexp;
switch (yp->yp_code) {
case YP_UNDF:
ferr(1, "tdec_typ:Undefined type\n");
case YP_BOOL:
p1 = "BOOLEAN";
if (!yp->yp_varexp)
t = NULL;
break;
/* This needs to be fixed up in the action generating area */
case YP_INTLIST:
case YP_INT:
case YP_ENUMLIST:
if (yp->yp_varexp) {
p1 = "INTEGER";
break;
}
t = NULL;
p1 = NULL;
(void) fprintf(fptab, "\t{ SINTEGER, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
break;
case YP_REAL:
if (yp->yp_varexp) {
p1 = "REALTYPE";
break;
}
t = NULL;
p1 = NULL;
(void) fprintf(fptab, "\t{ SREALTYPE, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
break;
case YP_BIT:
case YP_BITLIST:
if (yp->yp_varexp) {
p1 = "BITSTRING";
break;
}
t = NULL;
p1 = NULL;
(void) fprintf(fptab, "\t{ SBITSTRING, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
break;
case YP_OCT:
if (yp->yp_varexp) {
p1 = "OCTETSTRING";
break;
}
t = NULL;
p1 = NULL;
(void) fprintf(fptab, "\t{ SOCTETSTRING, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
break;
case YP_OID:
if (yp->yp_varexp) {
p1 = "OBJID";
break;
}
t = NULL;
p1 = NULL;
(void) fprintf(fptab, "\t{ SOBJID, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
break;
case YP_SEQ:
case YP_SET:
case YP_ANY:
/*
* if (cons_type) p1 = "CONS_ANY"; else
*/
if (yp->yp_varexp) {
p1 = "ANY";
break;
}
t = NULL;
p1 = NULL;
(void) fprintf(fptab, "\t{ SANY, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
break;
case YP_NULL:
p1 = "T_NULL";
t = NULL;
break;
case YP_IDEFINED:
p1 = NULL;
{
/* Predefined Universal Type */
struct univ_typ *p, *univtyp();
if ((p = univtyp(yp->yp_identifier))) {
if (p->univ_flags & UNF_EXTMOD) {
yp->yp_module = p->univ_mod;
goto do_obj;
}
if (f == NULL) {/* No offset type */
if (yp->yp_flags & YP_TAG
&& yp->yp_flags & YP_IMPLICIT)
(void) fprintf(fptab, "\t{ S%s, 0, %d, %s },\n",
p->univ_tab,
yp->yp_tag->yt_value->yv_number,
c_flags(yp, yp->yp_tag->yt_class));
else
(void) fprintf(fptab, "\t{ S%s, 0, %d, %s },\n",
p->univ_tab, p->univ_id,
c_flags(yp, p->univ_class));
goto out;
}
if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
(void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
p->univ_tab, t, f,
yp->yp_tag->yt_value->yv_number,
c_flags(yp, yp->yp_tag->yt_class));
else
(void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
p->univ_tab, t, f, p->univ_id,
c_flags(yp, p->univ_class));
goto out;
}
}
do_obj:
if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
(void) fprintf(fptab, "\t{ IMP_OBJ, 0, %s, %s },\n", c_tag(yp), c_class(yp));
if (yp->yp_parm) {
ferr(1, "tenc_typ:YP_IDEFINED:yp_parm found\n");
}
if (yp->yp_module == NULL
|| strcmp(yp->yp_module, mymodule) == 0) {
if (f == NULL)
(void) fprintf(fptab, "\t{ SOBJECT, 0, _Z%s, %s },\n",
proc_name(yp->yp_identifier, 0), c_class(yp));
else
(void) fprintf(fptab, "\t{ OBJECT, OFFSET(%s, %s), _Z%s, %s },\n",
t, f, proc_name(yp->yp_identifier, 0), c_class(yp));
} else {
if (f == NULL)
(void) fprintf(fptab, "\t{ SEXTOBJ, 0, _Z%s, %s },\n",
strp2name(yp->yp_identifier, yp->yp_module),
c_class(yp));
else
(void) fprintf(fptab, "\t{ EXTOBJ, OFFSET(%s, %s), _Z%s, %s },\n",
t, f, strp2name(yp->yp_identifier, yp->yp_module),
c_class(yp));
(void) fprintf(fptab, "\t{ EXTMOD, %d, 0, 0 },\n",
gen_modref(yp->yp_module));
}
out:
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
break;
case YP_SEQLIST:
p1 = NULL;
/* support for -h flag */
#if 0
if (hflag && (y = yp->yp_type) && !y->yp_next) {
tdec_typ(y, id, yp->yp_structname);
break;
}
#endif
cons_type++;
save_ptr = ptr;
if (yp->yp_varexp == NULL && type != NULL)
ferr(1, "tdec_typ:YP_SEQLIST:NULL varexp pointer\n");
if (type != NULL)
(void) fprintf(fptab, "\t{ SEQ_START, OFFSET(%s, %s), %s, %s },\n",
t, f, c_tag(yp), c_class(yp));
else
(void) fprintf(fptab, "\t{ SEQ_START, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
if (y = yp->yp_type) {
genmalloc(yp);
if (type) {
if (yp->yp_declexp == NULL)
ferr(1, "tdec_typ:YP_SEQLIST:no declexp\n");
yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
} else
yp->yp_structname = t;
if (optfield(y)) {
(void) fprintf(fptab,
"\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
yp->yp_structname);
}
tdec_loop(y, id, yp->yp_structname);
}
(void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
ptr = save_ptr;
cons_type--;
break;
case YP_SETLIST:
p1 = NULL;
/* support for -h flag */
#if 0
if (hflag && (y = yp->yp_type) && !y->yp_next) {
tdec_typ(y, id, yp->yp_structname);
break;
}
#endif
p1 = NULL;
cons_type++;
if (yp->yp_varexp == NULL && type != NULL)
ferr(1, "tdec_typ:YP_SETLIST:NULL varexp pointer\n");
if (type != NULL)
(void) fprintf(fptab, "\t{ SET_START, OFFSET(%s, %s), %s, %s },\n",
t, f, c_tag(yp), c_class(yp));
else
(void) fprintf(fptab, "\t{ SET_START, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
if (y = yp->yp_type) {
genmalloc(yp);
if (type) {
if (yp->yp_declexp == NULL)
ferr(1, "tdec_typ:YP_SETLIST:no declexp\n");
yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
} else
yp->yp_structname = t;
if (optfield(y)) {
(void) fprintf(fptab,
"\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
yp->yp_structname);
}
tdec_loop(y, id, yp->yp_structname);
}
(void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
ptr = save_ptr;
cons_type--;
break;
case YP_SEQTYPE: /* What is the difference ?? */
p1 = NULL;
cons_type++;
save_ptr = ptr;
if (type != NULL)
(void) fprintf(fptab, "\t{ SEQOF_START, OFFSET(%s, %s), %s, %s },\n",
t, f, c_tag(yp), c_class(yp));
else
(void) fprintf(fptab, "\t{ SEQOF_START, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
if (y = yp->yp_type) {
genmalloc(yp);
if (type) {
if (yp->yp_declexp == NULL)
ferr(1, "tdec_typ:YP_SEQTYPE:no declexp\n");
yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
} else
yp->yp_structname = t;
tdec_loop(y, id, yp->yp_structname);
}
if (yp->yp_structname != NULL)
(void) fprintf(fptab, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
yp->yp_structname);
else
(void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
ptr = save_ptr;
cons_type--;
break;
case YP_SETTYPE:
p1 = NULL;
cons_type++;
save_ptr = ptr;
if (type != NULL)
(void) fprintf(fptab, "\t{ SETOF_START, OFFSET(%s, %s), %s, %s },\n",
t, f, c_tag(yp), c_class(yp));
else
(void) fprintf(fptab, "\t{ SETOF_START, 0, %s, %s },\n",
c_tag(yp), c_class(yp));
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
if (y = yp->yp_type) {
genmalloc(yp);
if (type) {
if (yp->yp_declexp == NULL)
ferr(1, "tdec_typ:YP_SETTYPE:no declexp\n");
yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
} else
yp->yp_structname = t;
tdec_loop(y, id, yp->yp_structname);
}
if (yp->yp_structname != NULL)
(void) fprintf(fptab, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
yp->yp_structname);
else
(void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
ptr = save_ptr;
cons_type--;
break;
case YP_CHOICE:
p1 = NULL;
/* support for -h flag */
if (hflag && (y = yp->yp_type) && !y->yp_next) {
tdec_typ(y, id, yp->yp_structname);
break;
}
cons_type++;
save_ptr = ptr;
if (type != NULL)
(void) fprintf(fptab, "\t{ CHOICE_START, OFFSET(%s, %s), 0, %s },\n",
t, f, c_class(yp));
else
(void) fprintf(fptab, "\t{ CHOICE_START, 0, 0, 0 },\n");
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
if (y = yp->yp_type) {
genmalloc(yp);
(void) fprintf(fptab, "\t{ SCTRL, OFFSET(%s, offset), 0, 0 },\n",
yp->yp_structname);
if (type) {
if (yp->yp_declexp == NULL)
ferr(1, "tdec_typ:YP_CHOICE:no declexp\n");
yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
} else
yp->yp_structname = t;
tdec_loop(y, id, yp->yp_structname);
}
(void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
ptr = save_ptr;
cons_type--;
break;
default:
ferrd(1, "tdec_typ: yp_code = %d not implemented\n", yp->yp_code);
}
if (p1 != NULL) {
if (t != NULL) {
(void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %s, %s },\n", p1, t, f,
c_tag(yp), c_class(yp));
} else {
(void) fprintf(fptab, "\t{ %s, 0, %s, %s },\n", p1, c_tag(yp),
c_class(yp));
}
if (yp->yp_flags & YP_DEFAULT)
gdflt(yp, G_DEC);
}
}
static int fflags[] = {
0, 1, 2, 2, 3, 3, 4, 5, 16, 16, 16, 17, 17, 17,
0, -1, 7,};
/*
* generate tables for encoding a contructed type
*/
YP
tdec_loop(yp, id, type)
YP yp;
char *id;
char *type;
{
for (; yp != NULL; yp = yp->yp_next) {
tdec_typ(yp, id, type);
}
}
/*
* Generate a malloc of for the given object
*/
genmalloc(yp)
YP yp;
{
(void) fprintf(fptab, "\t{ MALLOC, 0, sizeof (%s), 0 },\n", yp->yp_structname);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.