1988-10-26 15:21:11 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <em.h>
|
|
|
|
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "chk_expr.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "desig.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "main.h"
|
1989-05-03 10:30:22 +00:00
|
|
|
#include "misc.h"
|
1988-10-26 15:21:11 +00:00
|
|
|
#include "node.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "type.h"
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
MarkDef(nd, flags, on)
|
|
|
|
register struct node *nd;
|
|
|
|
unsigned short flags;
|
|
|
|
{
|
|
|
|
while( nd && nd->nd_class != Def ) {
|
|
|
|
if( (nd->nd_class == Arrsel) ||
|
|
|
|
(nd->nd_class == LinkDef) )
|
|
|
|
nd = nd->nd_left;
|
|
|
|
else if( nd->nd_class == Arrow )
|
|
|
|
nd = nd->nd_right;
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
if( nd && (nd->nd_class == Def) ) {
|
|
|
|
if( (flags & D_SET) && on &&
|
|
|
|
BlockScope != nd->nd_def->df_scope )
|
|
|
|
nd->nd_def->df_flags |= D_SETINHIGH;
|
|
|
|
if( on ) {
|
1994-11-01 11:45:23 +00:00
|
|
|
/*
|
1989-05-03 10:30:22 +00:00
|
|
|
if( (flags & D_SET) &&
|
|
|
|
(nd->nd_def->df_flags & D_WITH) )
|
|
|
|
node_warning(nd,
|
|
|
|
"variable \"%s\" already referenced in with",
|
|
|
|
nd->nd_def->df_idf->id_text);
|
1994-11-01 11:45:23 +00:00
|
|
|
*/
|
1989-05-03 10:30:22 +00:00
|
|
|
nd->nd_def->df_flags |= flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nd->nd_def->df_flags &= ~flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssertStat(expp, line)
|
|
|
|
register struct node *expp;
|
|
|
|
unsigned short line;
|
|
|
|
{
|
|
|
|
struct desig dsr;
|
|
|
|
|
|
|
|
if( !ChkExpression(expp) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( expp->nd_type != bool_type ) {
|
|
|
|
node_error(expp, "type of assertion should be boolean");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1989-05-09 15:54:01 +00:00
|
|
|
if( !options['a'] && !err_occurred ) {
|
1989-05-03 10:30:22 +00:00
|
|
|
dsr = InitDesig;
|
|
|
|
CodeExpr(expp, &dsr, NO_LABEL);
|
|
|
|
C_loc((arith)line);
|
|
|
|
C_cal("_ass");
|
|
|
|
}
|
|
|
|
}
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
AssignStat(left, right)
|
|
|
|
register struct node *left, *right;
|
|
|
|
{
|
|
|
|
register struct type *ltp, *rtp;
|
1989-05-03 10:30:22 +00:00
|
|
|
int retval = 0;
|
1988-10-26 15:21:11 +00:00
|
|
|
struct desig dsr;
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
retval = ChkExpression(right);
|
|
|
|
MarkUsed(right);
|
|
|
|
retval &= ChkLhs(left);
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
ltp = left->nd_type;
|
|
|
|
rtp = right->nd_type;
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
MarkDef(left, (unsigned short)D_SET, 1);
|
|
|
|
|
|
|
|
if( !retval ) return;
|
|
|
|
|
|
|
|
if( ltp == int_type && rtp == long_type ) {
|
|
|
|
right = MkNode(IntReduc, NULLNODE, right, &dot);
|
|
|
|
right->nd_type = int_type;
|
|
|
|
}
|
|
|
|
else if( ltp == long_type && rtp == int_type ) {
|
|
|
|
right = MkNode(IntCoerc, NULLNODE, right, &dot);
|
|
|
|
right->nd_type = long_type;
|
|
|
|
}
|
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
if( !TstAssCompat(ltp, rtp) ) {
|
|
|
|
node_error(left, "type incompatibility in assignment");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
if( left->nd_class == Def &&
|
|
|
|
(left->nd_def->df_flags & D_INLOOP) ) {
|
|
|
|
node_error(left, "assignment to a control variable");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
if( rtp == emptyset_type )
|
|
|
|
right->nd_type = ltp;
|
|
|
|
|
|
|
|
if( !err_occurred ) {
|
|
|
|
dsr = InitDesig;
|
|
|
|
CodeExpr(right, &dsr, NO_LABEL);
|
|
|
|
|
|
|
|
if( rtp->tp_fund & (T_ARRAY | T_RECORD) )
|
|
|
|
CodeAddress(&dsr);
|
|
|
|
else {
|
|
|
|
CodeValue(&dsr, rtp);
|
|
|
|
|
|
|
|
if( ltp == real_type && BaseType(rtp) == int_type )
|
1989-05-03 10:30:22 +00:00
|
|
|
Int2Real(rtp->tp_size);
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
RangeCheck(ltp, rtp);
|
|
|
|
}
|
|
|
|
CodeMove(&dsr, left, rtp);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeNode(left);
|
|
|
|
FreeNode(right);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcStat(nd)
|
|
|
|
register struct node *nd;
|
|
|
|
{
|
|
|
|
if( !ChkCall(nd) ) return;
|
|
|
|
|
|
|
|
if( nd->nd_type ) {
|
|
|
|
node_error(nd, "procedure call expected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChkForStat(nd)
|
|
|
|
register struct node *nd;
|
|
|
|
{
|
|
|
|
register struct def *df;
|
1989-05-03 10:30:22 +00:00
|
|
|
int retvar = 0;
|
|
|
|
|
|
|
|
retvar = ChkVariable(nd);
|
|
|
|
retvar &= ChkExpression(nd->nd_left);
|
|
|
|
MarkUsed(nd->nd_left);
|
|
|
|
retvar &= ChkExpression(nd->nd_right);
|
|
|
|
MarkUsed(nd->nd_right);
|
|
|
|
if( !retvar ) return;
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
assert(nd->nd_class == Def);
|
|
|
|
|
|
|
|
df = nd->nd_def;
|
|
|
|
|
|
|
|
if( df->df_scope != BlockScope ) {
|
|
|
|
node_error(nd, "for loop: control variable must be local");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(df->df_kind == D_VARIABLE);
|
|
|
|
|
|
|
|
if( df->df_scope != GlobalScope && df->var_off >= 0 ) {
|
1989-05-03 10:30:22 +00:00
|
|
|
node_error(nd,
|
|
|
|
"for loop: control variable can't be a parameter");
|
|
|
|
MarkDef(nd,(unsigned short)(D_LOOPVAR | D_SET | D_USED), 1);
|
|
|
|
return;
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !(df->df_type->tp_fund & T_ORDINAL) ) {
|
|
|
|
node_error(nd, "for loop: control variable must be ordinal");
|
1989-05-03 10:30:22 +00:00
|
|
|
MarkDef(nd,(unsigned short)(D_LOOPVAR | D_SET | D_USED), 1);
|
1988-10-26 15:21:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !TstCompat(df->df_type, nd->nd_left->nd_type) )
|
|
|
|
node_error(nd,
|
|
|
|
"for loop: initial value incompatible with control variable");
|
|
|
|
|
|
|
|
if( !TstCompat(df->df_type, nd->nd_right->nd_type) )
|
|
|
|
node_error(nd,
|
|
|
|
"for loop: final value incompatible with control variable");
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
if( df->df_type == long_type )
|
|
|
|
node_error(nd, "for loop: control variable can not be a long");
|
|
|
|
|
|
|
|
if( df->df_flags & D_INLOOP )
|
|
|
|
node_error(nd, "for loop: control variable already used");
|
|
|
|
|
|
|
|
if( df->df_flags & D_SETINHIGH )
|
|
|
|
node_error(nd,
|
|
|
|
"for loop: control variable already set in block");
|
|
|
|
|
|
|
|
MarkDef(nd,(unsigned short) (D_LOOPVAR | D_INLOOP | D_SET | D_USED), 1);
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
EndForStat(nd)
|
|
|
|
register struct node *nd;
|
|
|
|
{
|
|
|
|
register struct def *df;
|
|
|
|
|
|
|
|
df = nd->nd_def;
|
|
|
|
|
|
|
|
if( (df->df_scope != BlockScope) ||
|
|
|
|
(df->df_scope != GlobalScope && df->var_off >= 0) ||
|
|
|
|
!(df->df_type->tp_fund & T_ORDINAL)
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MarkDef(nd,(unsigned short) (D_INLOOP | D_SET), 0);
|
|
|
|
}
|
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
arith
|
|
|
|
CodeInitFor(nd, priority)
|
|
|
|
register struct node *nd;
|
|
|
|
{
|
1989-10-30 15:45:43 +00:00
|
|
|
/* Push final-value, the value may only be evaluated
|
1988-10-26 15:21:11 +00:00
|
|
|
once, so generate a temporary for it, when not a constant.
|
|
|
|
*/
|
|
|
|
|
|
|
|
arith tmp;
|
|
|
|
|
|
|
|
CodePExpr(nd);
|
|
|
|
if( nd->nd_class != Value ) {
|
|
|
|
tmp = NewInt(priority);
|
1989-05-03 10:30:22 +00:00
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
C_dup(int_size);
|
|
|
|
C_stl(tmp);
|
1989-05-03 10:30:22 +00:00
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
return (arith) 0;
|
|
|
|
}
|
|
|
|
|
1989-10-30 15:45:43 +00:00
|
|
|
CodeFor(nd, stepsize, l1, l2)
|
1988-10-26 15:21:11 +00:00
|
|
|
struct node *nd;
|
|
|
|
label l1, l2;
|
|
|
|
{
|
|
|
|
/* Test if loop has to be done */
|
|
|
|
if( stepsize == 1 ) /* TO */
|
|
|
|
C_bgt(l2);
|
|
|
|
else /* DOWNTO */
|
|
|
|
C_blt(l2);
|
|
|
|
|
|
|
|
/* Label at begin of the body */
|
|
|
|
C_df_ilb(l1);
|
|
|
|
|
|
|
|
RangeCheck(nd->nd_type, nd->nd_left->nd_type);
|
|
|
|
CodeDStore(nd);
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeEndFor(nd, stepsize, l1, l2, tmp2)
|
|
|
|
struct node *nd;
|
|
|
|
label l1, l2;
|
|
|
|
arith tmp2;
|
|
|
|
{
|
|
|
|
/* Test if loop has to be done once more */
|
|
|
|
CodePExpr(nd);
|
|
|
|
C_dup(int_size);
|
|
|
|
if( tmp2 )
|
|
|
|
C_lol(tmp2);
|
|
|
|
else
|
|
|
|
CodePExpr(nd->nd_right);
|
|
|
|
C_beq(l2);
|
|
|
|
|
|
|
|
/* Increment/decrement the control-variable */
|
|
|
|
if( stepsize == 1 ) /* TO */
|
|
|
|
C_inc();
|
|
|
|
else /* DOWNTO */
|
|
|
|
C_dec();
|
|
|
|
C_bra(l1);
|
|
|
|
|
|
|
|
/* Exit label */
|
|
|
|
C_df_ilb(l2);
|
1989-10-12 11:10:48 +00:00
|
|
|
C_asp(int_size);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WithStat(nd)
|
|
|
|
struct node *nd;
|
|
|
|
{
|
|
|
|
struct withdesig *wds;
|
|
|
|
struct desig ds;
|
|
|
|
struct scopelist *scl;
|
|
|
|
|
|
|
|
if( nd->nd_type->tp_fund != T_RECORD ) {
|
|
|
|
node_error(nd, "record variable expected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
MarkDef(nd, (unsigned short)(D_USED | D_SET | D_WITH), 1);
|
|
|
|
/*
|
|
|
|
if( (nd->nd_class == Arrow) &&
|
|
|
|
(nd->nd_right->nd_type->tp_fund & T_FILE) ) {
|
|
|
|
nd->nd_right->nd_def->df_flags |= D_WITH;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
scl = new_scopelist();
|
|
|
|
scl->sc_scope = nd->nd_type->rec_scope;
|
|
|
|
scl->next = CurrVis;
|
|
|
|
CurrVis = scl;
|
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
if( err_occurred ) return;
|
|
|
|
|
|
|
|
/* Generate code */
|
|
|
|
|
|
|
|
CodeDAddress(nd);
|
|
|
|
|
|
|
|
wds = new_withdesig();
|
|
|
|
wds->w_next = WithDesigs;
|
|
|
|
WithDesigs = wds;
|
1989-05-03 10:30:22 +00:00
|
|
|
wds->w_scope = scl->sc_scope;
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
/* create a desig structure for the temporary */
|
|
|
|
ds.dsg_kind = DSG_FIXED;
|
|
|
|
ds.dsg_offset = NewPtr(1);
|
|
|
|
ds.dsg_name = 0;
|
|
|
|
|
|
|
|
/* need some pointertype to store pointer */
|
|
|
|
CodeStore(&ds, nil_type);
|
|
|
|
|
|
|
|
/* record is indirectly available */
|
|
|
|
ds.dsg_kind = DSG_PFIXED;
|
|
|
|
wds->w_desig = ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndWith(saved_scl, nd)
|
|
|
|
struct scopelist *saved_scl;
|
|
|
|
struct node *nd;
|
|
|
|
{
|
|
|
|
/* restore scope, and release structures */
|
|
|
|
struct scopelist *scl;
|
|
|
|
struct withdesig *wds;
|
1989-05-03 10:30:22 +00:00
|
|
|
struct node *nd1;
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
while( CurrVis != saved_scl ) {
|
|
|
|
|
|
|
|
/* release scopelist */
|
|
|
|
scl = CurrVis;
|
|
|
|
CurrVis = CurrVis->next;
|
|
|
|
free_scopelist(scl);
|
|
|
|
|
1989-05-03 10:30:22 +00:00
|
|
|
if( WithDesigs == 0 )
|
|
|
|
continue; /* we didn't generate any code */
|
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
/* release temporary */
|
|
|
|
FreePtr(WithDesigs->w_desig.dsg_offset);
|
|
|
|
|
|
|
|
/* release withdesig */
|
|
|
|
wds = WithDesigs;
|
|
|
|
WithDesigs = WithDesigs->w_next;
|
|
|
|
free_withdesig(wds);
|
|
|
|
}
|
1989-05-03 10:30:22 +00:00
|
|
|
|
|
|
|
for( nd1 = nd; nd1 != NULLNODE; nd1 = nd1->nd_right ) {
|
|
|
|
MarkDef(nd1->nd_left, (unsigned short)(D_WITH), 0);
|
|
|
|
}
|
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
FreeNode(nd);
|
|
|
|
}
|