ack/lang/pc/comp/enter.c

257 lines
5.9 KiB
C
Raw Normal View History

1988-10-26 15:21:11 +00:00
/* H I G H L E V E L S Y M B O L E N T R Y */
#include <alloc.h>
#include <assert.h>
#include <em_arith.h>
#include <em_label.h>
#include "LLlex.h"
#include "def.h"
#include "idf.h"
#include "main.h"
#include "node.h"
#include "scope.h"
#include "type.h"
extern int proclevel;
extern int parlevel;
struct def *
Enter(name, kind, type, pnam)
char *name;
register struct type *type;
{
/* Enter a definition for "name" with kind "kind" and type
"type" in the Current Scope. If it is a standard name, also
1989-05-03 10:30:22 +00:00
put its number in the definition structure, and mark the
name as set, to inhibit warnings about used before set.
1988-10-26 15:21:11 +00:00
*/
register struct def *df;
df = define(str2idf(name, 0), CurrentScope, kind);
df->df_type = type;
1989-05-03 10:30:22 +00:00
if( pnam ) {
df->df_value.df_reqname = pnam;
df->df_flags |= D_SET;
}
1990-12-11 13:52:08 +00:00
else if (options['g']) stb_string(df, kind);
1988-10-26 15:21:11 +00:00
return df;
}
EnterProgList(Idlist)
register struct node *Idlist;
{
register struct node *idlist = Idlist;
register struct def *df;
for( ; idlist; idlist = idlist->nd_next )
if ( !strcmp(input, idlist->nd_IDF->id_text)
||
!strcmp(output, idlist->nd_IDF->id_text)
) {
/* the occurence of input or output as program-
1989-05-03 10:30:22 +00:00
* parameter is their declaration as a GLOBAL
* variable of type text
1988-10-26 15:21:11 +00:00
*/
if( df = define(idlist->nd_IDF, CurrentScope,
D_VARIABLE) ) {
df->df_type = text_type;
1989-05-03 10:30:22 +00:00
df->df_flags |= (D_SET | D_PROGPAR | D_NOREG);
1988-10-26 15:21:11 +00:00
if( !strcmp(input, idlist->nd_IDF->id_text) ) {
df->var_name = input;
set_inp();
1988-10-26 15:21:11 +00:00
}
else {
df->var_name = output;
set_outp();
1988-10-26 15:21:11 +00:00
}
1990-12-11 13:52:08 +00:00
if (options['g']) stb_string(df, D_VARIABLE);
1988-10-26 15:21:11 +00:00
}
}
else {
if( df = define(idlist->nd_IDF, CurrentScope,
D_PARAMETER) ) {
df->df_type = error_type;
df->df_flags |= D_PROGPAR;
1989-05-03 10:30:22 +00:00
df->var_name = idlist->nd_IDF->id_text;
1988-10-26 15:21:11 +00:00
}
}
FreeNode(Idlist);
}
EnterEnumList(Idlist, type)
struct node *Idlist;
register struct type *type;
{
/* Put a list of enumeration literals in the symbol table.
They all have type "type". Also assign numbers to them.
*/
1990-12-11 13:52:08 +00:00
register struct def *df, *df1 = 0;
1988-10-26 15:21:11 +00:00
register struct node *idlist = Idlist;
type->enm_ncst = 0;
for( ; idlist; idlist = idlist->nd_next )
if( df = define(idlist->nd_IDF, CurrentScope, D_ENUM) ) {
df->df_type = type;
df->enm_val = (type->enm_ncst)++;
1989-05-03 10:30:22 +00:00
df->df_flags |= D_SET;
1990-12-11 13:52:08 +00:00
if (! df1) {
type->enm_enums = df;
}
else df1->enm_next = df;
df1 = df;
1988-10-26 15:21:11 +00:00
}
FreeNode(Idlist);
}
EnterFieldList(Idlist, type, scope, addr, packed)
struct node *Idlist;
register struct type *type;
struct scope *scope;
arith *addr;
unsigned short packed;
{
/* Put a list of fields in the symbol table.
They all have type "type", and are put in scope "scope".
*/
register struct def *df;
register struct node *idlist = Idlist;
for( ; idlist; idlist = idlist->nd_next )
if( df = define(idlist->nd_IDF, scope, D_FIELD) ) {
df->df_type = type;
if( packed ) {
df->fld_flags |= F_PACKED;
df->fld_off = align(*addr, type->tp_palign);
*addr = df->fld_off + type->tp_psize;
}
else {
df->fld_off = align(*addr, type->tp_align);
*addr = df->fld_off + type->tp_size;
}
}
FreeNode(Idlist);
}
EnterVarList(Idlist, type, local)
struct node *Idlist;
struct type *type;
{
/* Enter a list of identifiers representing variables into the
name list. "type" represents the type of the variables.
"local" is set if the variables are declared local to a
procedure.
*/
register struct def *df;
register struct node *idlist = Idlist;
register struct scopelist *sc = CurrVis;
for( ; idlist; idlist = idlist->nd_next ) {
if( !(df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE)) )
continue; /* skip this identifier */
df->df_type = type;
if( local ) {
/* subtract size, which is already aligned, of
* variable to the offset, as the variable list
* exists only local to a procedure
*/
sc->sc_scope->sc_off -= type->tp_size;
df->var_off = sc->sc_scope->sc_off;
}
else { /* Global name */
df->var_name = df->df_idf->id_text;
df->df_flags |= D_NOREG;
}
1990-12-11 13:52:08 +00:00
if (options['g']) stb_string(df, D_VARIABLE);
1988-10-26 15:21:11 +00:00
}
FreeNode(Idlist);
}
arith
EnterParamList(fpl, parlist)
register struct node *fpl;
struct paramlist **parlist;
{
register arith nb_pars = (proclevel > 1) ? pointer_size : 0;
register struct node *id;
struct type *tp;
struct def *df;
for( ; fpl; fpl = fpl->nd_right ) {
assert(fpl->nd_class == Link);
tp = fpl->nd_type;
for( id = fpl->nd_left; id; id = id->nd_next )
if( df = define(id->nd_IDF, CurrentScope, D_VARIABLE) ) {
df->var_off = nb_pars;
1989-05-03 10:30:22 +00:00
if( fpl->nd_INT & D_VARPAR || IsConformantArray(tp) )
1988-10-26 15:21:11 +00:00
nb_pars += pointer_size;
else
nb_pars += tp->tp_size;
LinkParam(parlist, df);
df->df_type = tp;
df->df_flags |= fpl->nd_INT;
}
while( IsConformantArray(tp) ) {
/* we need room for the descriptors */
tp->arr_sclevel = CurrentScope->sc_level;
tp->arr_cfdescr = nb_pars;
nb_pars += 3 * word_size;
tp = tp->arr_elem;
}
}
return nb_pars;
}
1989-05-03 10:30:22 +00:00
arith
1988-10-26 15:21:11 +00:00
EnterParTypes(fpl, parlist)
register struct node *fpl;
struct paramlist **parlist;
{
/* Parameters in heading of procedural and functional
parameters (only types are important, not the names).
*/
1989-05-03 10:30:22 +00:00
register arith nb_pars = 0;
1988-10-26 15:21:11 +00:00
register struct node *id;
1989-05-03 10:30:22 +00:00
struct type *tp;
1988-10-26 15:21:11 +00:00
struct def *df;
1989-05-03 10:30:22 +00:00
for( ; fpl; fpl = fpl->nd_right ) {
tp = fpl->nd_type;
1988-10-26 15:21:11 +00:00
for( id = fpl->nd_left; id; id = id->nd_next )
if( df = new_def() ) {
1989-05-03 10:30:22 +00:00
if( fpl->nd_INT & D_VARPAR ||
IsConformantArray(tp) )
nb_pars += pointer_size;
else
nb_pars += tp->tp_size;
1988-10-26 15:21:11 +00:00
LinkParam(parlist, df);
1989-05-03 10:30:22 +00:00
df->df_type = tp;
1988-10-26 15:21:11 +00:00
df->df_flags |= fpl->nd_INT;
}
1989-05-03 10:30:22 +00:00
while( IsConformantArray(tp) ) {
nb_pars += 3 * word_size;
tp = tp->arr_elem;
}
}
return nb_pars;
1988-10-26 15:21:11 +00:00
}
LinkParam(parlist, df)
struct paramlist **parlist;
struct def *df;
{
static struct paramlist *pr;
if( !*parlist )
*parlist = pr = new_paramlist();
else {
pr->next = new_paramlist();
pr = pr->next;
}
pr->par_def = df;
}