1987-04-29 10:22:07 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
/* E X P R E S S I O N C H E C K I N G */
|
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
/* Check expressions, and try to evaluate them as far as possible.
|
|
|
|
*/
|
1986-05-01 19:06:53 +00:00
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
|
|
|
#include <assert.h>
|
1986-04-09 18:14:49 +00:00
|
|
|
#include <alloc.h>
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1987-10-19 11:28:37 +00:00
|
|
|
#include "strict3rd.h"
|
1986-04-10 01:08:49 +00:00
|
|
|
#include "Lpars.h"
|
1986-04-08 18:15:46 +00:00
|
|
|
#include "idf.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "LLlex.h"
|
1987-07-30 13:37:39 +00:00
|
|
|
#include "def.h"
|
1986-04-08 18:15:46 +00:00
|
|
|
#include "node.h"
|
|
|
|
#include "scope.h"
|
1986-04-09 18:14:49 +00:00
|
|
|
#include "standards.h"
|
1986-06-17 12:04:05 +00:00
|
|
|
#include "chk_expr.h"
|
1986-10-22 15:38:24 +00:00
|
|
|
#include "misc.h"
|
1986-11-05 14:33:00 +00:00
|
|
|
#include "warning.h"
|
1987-10-19 11:28:37 +00:00
|
|
|
#include "main.h"
|
1987-11-09 16:11:04 +00:00
|
|
|
#include "nostrict.h"
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-04-23 22:12:22 +00:00
|
|
|
extern char *symbol2str();
|
1987-05-18 15:57:33 +00:00
|
|
|
extern char *sprint();
|
1990-06-11 15:17:50 +00:00
|
|
|
extern arith flt_flt2arith();
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
STATIC
|
1987-09-23 16:39:43 +00:00
|
|
|
df_error(nd, mess, edf)
|
|
|
|
t_node *nd; /* node on which error occurred */
|
|
|
|
char *mess; /* error message */
|
|
|
|
register t_def *edf; /* do we have a name? */
|
1986-11-17 11:41:28 +00:00
|
|
|
{
|
|
|
|
if (edf) {
|
|
|
|
if (edf->df_kind != D_ERROR) {
|
1986-11-17 13:08:18 +00:00
|
|
|
node_error(nd,"\"%s\": %s", edf->df_idf->id_text, mess);
|
1986-11-17 11:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
else node_error(nd, mess);
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MkCoercion(pnd, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node **pnd;
|
|
|
|
register t_type *tp;
|
1987-07-30 13:37:39 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
/* Make a coercion from the node indicated by *pnd to the
|
1988-02-10 14:06:34 +00:00
|
|
|
type indicated by tp. If the node indicated by *pnd
|
|
|
|
is constant, try to do the coercion compile-time.
|
|
|
|
Coercions are inserted in the tree when
|
|
|
|
- the expression is not constant or
|
|
|
|
- we are in the second pass and the coercion might cause
|
|
|
|
an error
|
1987-09-23 16:39:43 +00:00
|
|
|
*/
|
|
|
|
register t_node *nd = *pnd;
|
|
|
|
register t_type *nd_tp = nd->nd_type;
|
|
|
|
extern int pass_1;
|
1988-02-10 14:06:34 +00:00
|
|
|
char *wmess = 0;
|
1989-12-19 09:40:25 +00:00
|
|
|
arith op;
|
1987-07-30 13:37:39 +00:00
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
if (nd_tp == tp || nd_tp->tp_fund == T_STRING /* Why ??? */) return;
|
1987-07-30 13:37:39 +00:00
|
|
|
nd_tp = BaseType(nd_tp);
|
1989-12-19 09:40:25 +00:00
|
|
|
if (nd->nd_class == Value) {
|
|
|
|
if (nd_tp->tp_fund == T_REAL) {
|
|
|
|
switch(tp->tp_fund) {
|
|
|
|
case T_REAL:
|
|
|
|
nd->nd_type = tp;
|
|
|
|
return;
|
|
|
|
case T_CARDINAL:
|
|
|
|
op = flt_flt2arith(&nd->nd_RVAL, 1);
|
|
|
|
break;
|
|
|
|
case T_INTEGER:
|
|
|
|
op = flt_flt2arith(&nd->nd_RVAL, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("MkCoercion");
|
1991-04-25 16:47:47 +00:00
|
|
|
/*NOTREACHED*/
|
1989-12-19 09:40:25 +00:00
|
|
|
}
|
|
|
|
if (flt_status == FLT_OVFL) {
|
|
|
|
wmess = "conversion";
|
|
|
|
}
|
|
|
|
if (!wmess || pass_1) {
|
1991-03-06 10:52:34 +00:00
|
|
|
if (nd->nd_RSTR) free(nd->nd_RSTR);
|
|
|
|
free_real(nd->nd_REAL);
|
1989-12-19 09:40:25 +00:00
|
|
|
nd->nd_INT = op;
|
|
|
|
nd->nd_symb = INTEGER;
|
|
|
|
}
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
switch(tp->tp_fund) {
|
1989-12-19 09:40:25 +00:00
|
|
|
case T_REAL: {
|
|
|
|
struct real *p = new_real();
|
|
|
|
switch(BaseType(nd_tp)->tp_fund) {
|
|
|
|
case T_CARDINAL:
|
|
|
|
case T_INTORCARD:
|
|
|
|
flt_arith2flt(nd->nd_INT, &p->r_val, 1);
|
|
|
|
break;
|
|
|
|
case T_INTEGER:
|
|
|
|
flt_arith2flt(nd->nd_INT, &p->r_val, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("MkCoercion");
|
|
|
|
}
|
1991-03-06 10:52:34 +00:00
|
|
|
nd->nd_REAL = p;
|
1989-12-19 09:40:25 +00:00
|
|
|
nd->nd_symb = REAL;
|
|
|
|
}
|
|
|
|
break;
|
1987-07-30 13:37:39 +00:00
|
|
|
case T_SUBRANGE:
|
|
|
|
case T_ENUMERATION:
|
|
|
|
case T_CHAR:
|
1988-04-13 18:37:45 +00:00
|
|
|
if (! in_range(nd->nd_INT, tp)) {
|
1988-02-10 14:06:34 +00:00
|
|
|
wmess = "range bound";
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_INTORCARD:
|
|
|
|
case T_CARDINAL:
|
|
|
|
case T_POINTER:
|
1987-08-19 18:07:41 +00:00
|
|
|
if ((nd_tp->tp_fund == T_INTEGER && nd->nd_INT < 0) ||
|
1987-07-30 13:37:39 +00:00
|
|
|
(nd->nd_INT & ~full_mask[(int)(tp->tp_size)])) {
|
1988-02-10 14:06:34 +00:00
|
|
|
wmess = "conversion";
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
break;
|
1988-04-19 14:40:27 +00:00
|
|
|
case T_INTEGER:
|
|
|
|
if (! chk_bounds(nd->nd_INT,
|
|
|
|
max_int[(int)(tp->tp_size)],
|
|
|
|
nd_tp->tp_fund) ||
|
|
|
|
! chk_bounds(min_int[(int)(tp->tp_size)],
|
|
|
|
nd->nd_INT,
|
|
|
|
T_INTEGER)) {
|
1988-02-10 14:06:34 +00:00
|
|
|
wmess = "conversion";
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1988-02-10 14:06:34 +00:00
|
|
|
if (wmess) {
|
|
|
|
node_warning(nd, W_ORDINARY, "might cause %s error", wmess);
|
|
|
|
}
|
|
|
|
if (!wmess || pass_1) {
|
1987-07-30 13:37:39 +00:00
|
|
|
nd->nd_type = tp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
*pnd = nd;
|
|
|
|
nd = getnode(Uoper);
|
1987-07-30 13:37:39 +00:00
|
|
|
nd->nd_symb = COERCION;
|
|
|
|
nd->nd_type = tp;
|
1991-03-18 16:30:49 +00:00
|
|
|
nd->nd_LEFT = NULLNODE;
|
|
|
|
nd->nd_RIGHT = *pnd;
|
|
|
|
nd->nd_lineno = (*pnd)->nd_lineno;
|
|
|
|
*pnd = nd;
|
1986-11-17 11:41:28 +00:00
|
|
|
}
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
int
|
1987-10-19 11:28:37 +00:00
|
|
|
ChkVariable(expp, flags)
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node **expp;
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check that "expp" indicates an item that can be
|
|
|
|
assigned to.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! ChkDesig(expp, flags)) return 0;
|
|
|
|
|
|
|
|
exp = *expp;
|
|
|
|
if (exp->nd_class == Def &&
|
|
|
|
! (exp->nd_def->df_kind & (D_FIELD|D_VARIABLE))) {
|
|
|
|
df_error(exp, "variable expected", exp->nd_def);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkArrow(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check an application of the '^' operator.
|
|
|
|
The operand must be a variable of a pointer type.
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
assert(exp->nd_class == Arrow);
|
|
|
|
assert(exp->nd_symb == '^');
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = error_type;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! ChkVariable(&(exp->nd_RIGHT), D_USED)) return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
tp = exp->nd_RIGHT->nd_type;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
if (tp->tp_fund != T_POINTER) {
|
1991-03-13 17:26:07 +00:00
|
|
|
node_error(exp, "\"^\": illegal operand type");
|
|
|
|
return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
1988-11-15 14:45:59 +00:00
|
|
|
if ((tp = RemoveEqual(PointedtoType(tp))) == 0) tp = error_type;
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = tp;
|
1986-06-26 09:39:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1987-10-19 11:28:37 +00:00
|
|
|
ChkArr(expp, flags)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-04-08 18:15:46 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check an array selection.
|
|
|
|
The left hand side must be a variable of an array type,
|
|
|
|
and the right hand side must be an expression that is
|
|
|
|
assignment compatible with the array-index.
|
|
|
|
*/
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tpl;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
assert(exp->nd_class == Arrsel);
|
|
|
|
assert(exp->nd_symb == '[' || exp->nd_symb == ',');
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = error_type;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! (ChkVariable(&(exp->nd_LEFT), flags) &
|
|
|
|
ChkExpression(&(exp->nd_RIGHT)))) {
|
1987-09-23 16:39:43 +00:00
|
|
|
/* Bitwise and, because we want them both evaluated.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
tpl = exp->nd_LEFT->nd_type;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
if (tpl->tp_fund != T_ARRAY) {
|
1991-03-12 16:52:00 +00:00
|
|
|
node_error(exp, "not indexing an ARRAY type");
|
1986-06-26 09:39:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = RemoveEqual(tpl->arr_elem);
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
/* Type of the index must be assignment compatible with
|
|
|
|
the index type of the array (Def 8.1).
|
|
|
|
However, the index type of a conformant array is not specified.
|
1987-07-22 17:02:54 +00:00
|
|
|
In our implementation it is CARDINAL.
|
1986-06-26 09:39:36 +00:00
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
return ChkAssCompat(&(exp->nd_RIGHT),
|
1987-07-30 13:37:39 +00:00
|
|
|
BaseType(IndexType(tpl)),
|
|
|
|
"index type");
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1989-03-20 13:32:06 +00:00
|
|
|
/*ARGSUSED*/
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkValue(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
#ifdef DEBUG
|
1991-03-12 16:52:00 +00:00
|
|
|
switch((*expp)->nd_symb) {
|
1986-06-17 12:04:05 +00:00
|
|
|
case REAL:
|
|
|
|
case STRING:
|
|
|
|
case INTEGER:
|
1989-03-20 13:32:06 +00:00
|
|
|
break;
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-04-08 23:34:10 +00:00
|
|
|
default:
|
1986-07-10 16:27:26 +00:00
|
|
|
crash("(ChkValue)");
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
#endif
|
1989-03-20 13:32:06 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1986-04-08 18:15:46 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkSelOrName(expp, flags)
|
|
|
|
t_node **expp;
|
1986-04-08 18:15:46 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check either an ID or a construction of the form
|
|
|
|
ID.ID [ .ID ]*
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
|
|
|
|
|
|
|
exp->nd_type = error_type;
|
|
|
|
|
|
|
|
if (exp->nd_class == Name) {
|
|
|
|
df = lookfor(exp, CurrVis, 1, flags);
|
|
|
|
exp = getnode(Def);
|
|
|
|
exp->nd_def = df;
|
|
|
|
exp->nd_lineno = (*expp)->nd_lineno;
|
|
|
|
exp->nd_type = RemoveEqual(df->df_type);
|
|
|
|
FreeNode(*expp);
|
|
|
|
*expp = exp;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
else if (exp->nd_class == Select) {
|
1986-10-06 20:36:30 +00:00
|
|
|
/* A selection from a record or a module.
|
|
|
|
Modules also have a record type.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *left;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
assert(exp->nd_symb == '.');
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! ChkDesig(&(exp->nd_NEXT), flags)) return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
left = exp->nd_NEXT;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (left->nd_class==Def &&
|
1987-07-13 11:49:32 +00:00
|
|
|
(left->nd_type->tp_fund != T_RECORD ||
|
1987-05-11 14:38:37 +00:00
|
|
|
!(left->nd_def->df_kind & (D_MODULE|D_VARIABLE|D_FIELD))
|
1986-06-26 09:39:36 +00:00
|
|
|
)
|
|
|
|
) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(left, "illegal selection", left->nd_def);
|
|
|
|
return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
1987-05-11 14:38:37 +00:00
|
|
|
if (left->nd_type->tp_fund != T_RECORD) {
|
|
|
|
node_error(left, "illegal selection");
|
|
|
|
return 0;
|
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (!(df = lookup(exp->nd_IDF, left->nd_type->rec_scope, D_IMPORTED, flags))) {
|
|
|
|
id_not_declared(exp);
|
1986-06-26 09:39:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = getnode(Def);
|
|
|
|
exp->nd_def = df;
|
|
|
|
exp->nd_type = RemoveEqual(df->df_type);
|
|
|
|
exp->nd_lineno = (*expp)->nd_lineno;
|
|
|
|
free_node(*expp);
|
|
|
|
*expp = exp;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) {
|
|
|
|
/* Fields of a record are always D_QEXPORTED,
|
|
|
|
so ...
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(exp, "not exported from qualifying module", df);
|
1986-04-08 23:34:10 +00:00
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!(left->nd_class == Def &&
|
|
|
|
left->nd_def->df_kind == D_MODULE)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_NEXT = left;
|
1987-07-30 13:37:39 +00:00
|
|
|
return 1;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
FreeNode(left);
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
assert(exp->nd_class == Def);
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
return exp->nd_def->df_kind != D_ERROR;
|
1987-07-13 10:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkExSelOrName(expp)
|
|
|
|
t_node **expp;
|
1987-07-13 10:30:37 +00:00
|
|
|
{
|
|
|
|
/* Check either an ID or an ID.ID [.ID]* occurring in an
|
|
|
|
expression.
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp;
|
|
|
|
|
|
|
|
if (! ChkSelOrName(expp, D_USED)) return 0;
|
1987-07-13 10:30:37 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = *expp;
|
1987-07-13 10:30:37 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
df = exp->nd_def;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
if (df->df_kind & (D_ENUM | D_CONST)) {
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Replace an enum-literal or a CONST identifier by its value.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = getnode(Value);
|
|
|
|
exp->nd_type = df->df_type;
|
1986-06-26 09:39:36 +00:00
|
|
|
if (df->df_kind == D_ENUM) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_INT = df->enm_val;
|
|
|
|
exp->nd_symb = INTEGER;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(df->df_kind == D_CONST);
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_token = df->con_const;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_lineno = (*expp)->nd_lineno;
|
1987-10-20 13:32:18 +00:00
|
|
|
if (df->df_type->tp_fund == T_SET) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_class = Set;
|
|
|
|
inc_refcount(exp->nd_set);
|
1987-10-20 13:32:18 +00:00
|
|
|
}
|
1989-03-03 16:13:45 +00:00
|
|
|
else if (df->df_type->tp_fund == T_PROCEDURE) {
|
|
|
|
/* for procedure constants */
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_class = Def;
|
1989-03-03 16:13:45 +00:00
|
|
|
}
|
1989-12-19 09:40:25 +00:00
|
|
|
if (df->df_type->tp_fund == T_REAL) {
|
1991-03-12 16:52:00 +00:00
|
|
|
struct real *p = exp->nd_REAL;
|
1989-12-19 09:40:25 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_REAL = new_real();
|
|
|
|
*(exp->nd_REAL) = *p;
|
1989-12-19 09:40:25 +00:00
|
|
|
if (p->r_real) {
|
|
|
|
p->r_real = Salloc(p->r_real,
|
|
|
|
(unsigned)(strlen(p->r_real)+1));
|
|
|
|
}
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
FreeNode(*expp);
|
|
|
|
*expp = exp;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
if (!(df->df_kind & D_VALUE)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(exp, "value expected", df);
|
|
|
|
return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (df->df_kind == D_PROCEDURE) {
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check that this procedure is one that we may take the
|
|
|
|
address from.
|
1986-06-26 09:39:36 +00:00
|
|
|
*/
|
|
|
|
if (df->df_type == std_type || df->df_scope->sc_level > 0) {
|
|
|
|
/* Address of standard or nested procedure
|
|
|
|
taken.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
node_error(exp,
|
1987-09-23 16:39:43 +00:00
|
|
|
"standard or local procedures may not be assigned");
|
1986-06-26 09:39:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkEl(expp, tp)
|
|
|
|
register t_node **expp;
|
1987-09-23 16:39:43 +00:00
|
|
|
t_type *tp;
|
1987-07-21 13:54:33 +00:00
|
|
|
{
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
return ChkExpression(expp) && ChkCompat(expp, tp, "set element");
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
|
|
|
ChkElement(expp, tp, set)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node **expp;
|
|
|
|
t_type *tp;
|
1987-07-30 13:37:39 +00:00
|
|
|
arith *set;
|
1986-04-08 23:34:10 +00:00
|
|
|
{
|
|
|
|
/* Check elements of a set. This routine may call itself
|
1986-04-09 18:14:49 +00:00
|
|
|
recursively.
|
|
|
|
Also try to compute the set!
|
1986-04-08 23:34:10 +00:00
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *expr = *expp;
|
1987-10-28 16:03:56 +00:00
|
|
|
t_type *el_type = ElementType(tp);
|
1987-07-21 13:54:33 +00:00
|
|
|
register unsigned int i;
|
1988-04-13 18:37:45 +00:00
|
|
|
arith low, high;
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1987-05-11 14:38:37 +00:00
|
|
|
if (expr->nd_class == Link && expr->nd_symb == UPTO) {
|
1986-04-09 18:14:49 +00:00
|
|
|
/* { ... , expr1 .. expr2, ... }
|
|
|
|
First check expr1 and expr2, and try to compute them.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! (ChkEl(&(expr->nd_LEFT), el_type) &
|
|
|
|
ChkEl(&(expr->nd_RIGHT), el_type))) {
|
1986-04-08 23:34:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (!(expr->nd_LEFT->nd_class == Value &&
|
|
|
|
expr->nd_RIGHT->nd_class == Value)) {
|
1987-07-21 13:54:33 +00:00
|
|
|
return 1;
|
1986-04-08 23:34:10 +00:00
|
|
|
}
|
1987-07-21 13:54:33 +00:00
|
|
|
/* We have a constant range. Put all elements in the
|
|
|
|
set
|
|
|
|
*/
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
low = expr->nd_LEFT->nd_INT;
|
|
|
|
high = expr->nd_RIGHT->nd_INT;
|
1986-04-08 23:34:10 +00:00
|
|
|
}
|
1987-07-21 13:54:33 +00:00
|
|
|
else {
|
1987-10-28 16:03:56 +00:00
|
|
|
if (! ChkEl(expp, el_type)) return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
expr = *expp;
|
1987-07-21 13:54:33 +00:00
|
|
|
if (expr->nd_class != Value) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
low = high = expr->nd_INT;
|
|
|
|
}
|
1988-04-13 18:37:45 +00:00
|
|
|
if (! chk_bounds(low, high, BaseType(el_type)->tp_fund)) {
|
1987-07-21 13:54:33 +00:00
|
|
|
node_error(expr, "lower bound exceeds upper bound in range");
|
1986-10-06 20:36:30 +00:00
|
|
|
return 0;
|
1986-04-08 23:34:10 +00:00
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1988-04-13 18:37:45 +00:00
|
|
|
if (! in_range(low, el_type) || ! in_range(high, el_type)) {
|
1987-07-21 13:54:33 +00:00
|
|
|
node_error(expr, "set element out of range");
|
|
|
|
return 0;
|
1986-04-08 23:34:10 +00:00
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1987-10-28 16:03:56 +00:00
|
|
|
low -= tp->set_low;
|
|
|
|
high -= tp->set_low;
|
1987-07-21 13:54:33 +00:00
|
|
|
for (i=(unsigned)low; i<= (unsigned)high; i++) {
|
1987-07-30 13:37:39 +00:00
|
|
|
set[i/wrd_bits] |= (1<<(i%wrd_bits));
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
|
|
|
FreeNode(expr);
|
|
|
|
*expp = 0;
|
1986-04-08 18:15:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
arith *
|
|
|
|
MkSet(size)
|
|
|
|
unsigned size;
|
|
|
|
{
|
1991-03-14 11:10:40 +00:00
|
|
|
register arith *s, *t;
|
1987-09-23 16:39:43 +00:00
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
s = t = (arith *) Malloc(size);
|
1987-09-23 16:39:43 +00:00
|
|
|
s++;
|
1991-03-14 11:10:40 +00:00
|
|
|
size /= sizeof(arith);
|
|
|
|
while (size--) *t++ = 0;
|
1987-09-23 16:39:43 +00:00
|
|
|
inc_refcount(s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeSet(s)
|
|
|
|
register arith *s;
|
|
|
|
{
|
1987-10-14 12:34:47 +00:00
|
|
|
dec_refcount(s);
|
1987-09-23 16:39:43 +00:00
|
|
|
if (refcount(s) <= 0) {
|
1987-10-20 13:32:18 +00:00
|
|
|
assert(refcount(s) == 0);
|
1987-09-23 16:39:43 +00:00
|
|
|
free((char *) (s-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkSet(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-04-09 18:14:49 +00:00
|
|
|
{
|
1986-06-17 12:04:05 +00:00
|
|
|
/* Check the legality of a SET aggregate, and try to evaluate it
|
|
|
|
compile time. Unfortunately this is all rather complicated.
|
1986-04-09 18:14:49 +00:00
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
|
|
|
register t_def *df;
|
1987-05-11 14:38:37 +00:00
|
|
|
int retval = 1;
|
1987-08-03 18:20:55 +00:00
|
|
|
int SetIsConstant = 1;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
assert(exp->nd_symb == SET);
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
*expp = getnode(Set);
|
|
|
|
(*expp)->nd_type = error_type;
|
|
|
|
(*expp)->nd_lineno = exp->nd_lineno;
|
1987-05-11 14:38:37 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
/* First determine the type of the set
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
if (exp->nd_LEFT) {
|
1986-06-17 12:04:05 +00:00
|
|
|
/* A type was given. Check it out
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! ChkDesig(&(exp->nd_LEFT), D_USED)) return 0;
|
|
|
|
nd = exp->nd_LEFT;
|
1987-07-30 13:37:39 +00:00
|
|
|
assert(nd->nd_class == Def);
|
1986-06-17 12:04:05 +00:00
|
|
|
df = nd->nd_def;
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
if (!is_type(df) ||
|
1986-11-17 11:41:28 +00:00
|
|
|
(df->df_type->tp_fund != T_SET)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(nd, "not a SET type", df);
|
|
|
|
return 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
tp = df->df_type;
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
else tp = bitset_type;
|
1991-03-12 16:52:00 +00:00
|
|
|
(*expp)->nd_type = tp;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
nd = exp->nd_RIGHT;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
/* Now check the elements given, and try to compute a constant set.
|
1987-05-13 13:04:28 +00:00
|
|
|
First allocate room for the set.
|
1986-06-17 12:04:05 +00:00
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
(*expp)->nd_set = MkSet(tp->set_sz);
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
/* Now check the elements, one by one
|
|
|
|
*/
|
|
|
|
while (nd) {
|
|
|
|
assert(nd->nd_class == Link && nd->nd_symb == ',');
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (!ChkElement(&(nd->nd_LEFT), tp, (*expp)->nd_set)) {
|
1987-05-11 14:38:37 +00:00
|
|
|
retval = 0;
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
if (nd->nd_LEFT) SetIsConstant = 0;
|
|
|
|
nd = nd->nd_RIGHT;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! SetIsConstant) {
|
|
|
|
(*expp)->nd_NEXT = exp->nd_RIGHT;
|
|
|
|
exp->nd_RIGHT = 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
FreeNode(exp);
|
1987-05-11 14:38:37 +00:00
|
|
|
return retval;
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
STATIC t_node *
|
1987-07-30 13:37:39 +00:00
|
|
|
nextarg(argp, edf)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node **argp;
|
|
|
|
t_def *edf;
|
1987-07-30 13:37:39 +00:00
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *arg = (*argp)->nd_RIGHT;
|
1987-07-30 13:37:39 +00:00
|
|
|
|
|
|
|
if (! arg) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(*argp, "too few arguments supplied", edf);
|
|
|
|
return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*argp = arg;
|
1991-03-12 16:52:00 +00:00
|
|
|
return arg;
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
STATIC t_node *
|
1986-11-17 11:41:28 +00:00
|
|
|
getarg(argp, bases, designator, edf)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node **argp;
|
|
|
|
t_def *edf;
|
1986-04-10 01:08:49 +00:00
|
|
|
{
|
1986-06-17 12:04:05 +00:00
|
|
|
/* This routine is used to fetch the next argument from an
|
|
|
|
argument list. The argument list is indicated by "argp".
|
|
|
|
The parameter "bases" is a bitset indicating which types
|
|
|
|
are allowed at this point, and "designator" is a flag
|
|
|
|
indicating that the address from this argument is taken, so
|
|
|
|
that it must be a designator and may not be a register
|
|
|
|
variable.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *arg = nextarg(argp, edf);
|
|
|
|
register t_node *left;
|
1986-04-10 01:08:49 +00:00
|
|
|
|
1991-05-13 13:57:25 +00:00
|
|
|
if (! arg ||
|
|
|
|
! arg->nd_LEFT ||
|
1991-03-12 16:52:00 +00:00
|
|
|
! (designator ? ChkVariable(&(arg->nd_LEFT), D_USED|D_DEFINED) : ChkExpression(&(arg->nd_LEFT)))) {
|
1986-04-10 01:08:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
left = arg->nd_LEFT;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (designator && left->nd_class==Def) {
|
1986-07-14 15:00:08 +00:00
|
|
|
left->nd_def->df_flags |= D_NOREG;
|
|
|
|
}
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
if (bases) {
|
1987-09-23 16:39:43 +00:00
|
|
|
t_type *tp = BaseType(left->nd_type);
|
1987-07-30 13:37:39 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! designator) MkCoercion(&(arg->nd_LEFT), tp);
|
|
|
|
left = arg->nd_LEFT;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!(tp->tp_fund & bases)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(left, "unexpected parameter type", edf);
|
|
|
|
return 0;
|
1986-09-25 19:39:06 +00:00
|
|
|
}
|
1986-04-10 01:08:49 +00:00
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
return left;
|
1986-04-10 01:08:49 +00:00
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
STATIC t_node *
|
1986-11-17 11:41:28 +00:00
|
|
|
getname(argp, kinds, bases, edf)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node **argp;
|
|
|
|
t_def *edf;
|
1986-04-10 01:08:49 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Get the next argument from argument list "argp".
|
|
|
|
The argument must indicate a definition, and the
|
|
|
|
definition kind must be one of "kinds".
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *arg = nextarg(argp, edf);
|
|
|
|
register t_node *left;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-05-13 13:57:25 +00:00
|
|
|
if (!arg || !arg->nd_LEFT || ! ChkDesig(&(arg->nd_LEFT), D_USED)) return 0;
|
1986-11-26 16:40:45 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
left = arg->nd_LEFT;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (left->nd_class != Def) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(left, "identifier expected", edf);
|
|
|
|
return 0;
|
1986-04-10 01:08:49 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!(left->nd_def->df_kind & kinds) ||
|
|
|
|
(bases && !(left->nd_type->tp_fund & bases))) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(left, "unexpected parameter type", edf);
|
|
|
|
return 0;
|
1986-11-17 11:41:28 +00:00
|
|
|
}
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
return left;
|
1986-04-10 01:08:49 +00:00
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkProcCall(exp)
|
|
|
|
register t_node *exp;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
|
|
|
/* Check a procedure call
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *left;
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node *argp;
|
1987-09-23 16:39:43 +00:00
|
|
|
t_def *edf = 0;
|
1987-09-24 13:07:31 +00:00
|
|
|
register t_param *param;
|
1986-11-17 11:41:28 +00:00
|
|
|
int retval = 1;
|
|
|
|
int cnt = 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
left = exp->nd_LEFT;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (left->nd_class == Def) {
|
1986-11-17 11:41:28 +00:00
|
|
|
edf = left->nd_def;
|
|
|
|
}
|
1986-11-17 13:08:18 +00:00
|
|
|
if (left->nd_type == error_type) {
|
|
|
|
/* Just check parameters as if they were value parameters
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
argp = exp;
|
|
|
|
while (argp->nd_RIGHT) {
|
|
|
|
if (getarg(&argp, 0, 0, edf)) { }
|
1986-11-17 13:08:18 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = RemoveEqual(ResultType(left->nd_type));
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check parameter list
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
argp = exp;
|
1987-07-16 19:51:40 +00:00
|
|
|
for (param = ParamList(left->nd_type); param; param = param->par_next) {
|
1991-03-12 16:52:00 +00:00
|
|
|
if (!(left = getarg(&argp, 0, IsVarParam(param), edf))) {
|
1987-10-19 11:28:37 +00:00
|
|
|
retval = 0;
|
|
|
|
cnt++;
|
|
|
|
continue;
|
1986-11-17 11:41:28 +00:00
|
|
|
}
|
|
|
|
cnt++;
|
1986-06-17 12:04:05 +00:00
|
|
|
if (left->nd_symb == STRING) {
|
|
|
|
TryToString(left, TypeOfParam(param));
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! TstParCompat(cnt,
|
|
|
|
RemoveEqual(TypeOfParam(param)),
|
1986-06-17 12:04:05 +00:00
|
|
|
IsVarParam(param),
|
1991-03-12 16:52:00 +00:00
|
|
|
&(argp->nd_LEFT),
|
1987-07-30 13:37:39 +00:00
|
|
|
edf)) {
|
1986-11-17 11:41:28 +00:00
|
|
|
retval = 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = argp;
|
|
|
|
if (exp->nd_RIGHT) {
|
|
|
|
df_error(exp->nd_RIGHT,"too many parameters supplied",edf);
|
|
|
|
while (argp->nd_RIGHT) {
|
|
|
|
if (getarg(&argp, 0, 0, edf)) { }
|
1986-11-26 16:40:45 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1986-11-17 11:41:28 +00:00
|
|
|
return retval;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
STATIC int
|
1987-05-18 15:57:33 +00:00
|
|
|
ChkFunCall(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node **expp;
|
1987-05-18 15:57:33 +00:00
|
|
|
{
|
|
|
|
/* Check a call that must have a result
|
|
|
|
*/
|
|
|
|
|
1988-04-13 18:37:45 +00:00
|
|
|
if (ChkCall(expp)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
if ((*expp)->nd_type != 0) return 1;
|
|
|
|
node_error(*expp, "function call expected");
|
1987-05-18 15:57:33 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
(*expp)->nd_type = error_type;
|
1988-04-13 18:37:45 +00:00
|
|
|
return 0;
|
1987-05-18 15:57:33 +00:00
|
|
|
}
|
|
|
|
|
1991-02-19 12:44:38 +00:00
|
|
|
STATIC int ChkStandard();
|
|
|
|
STATIC int ChkCast();
|
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkCall(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-04-08 18:15:46 +00:00
|
|
|
{
|
1986-04-11 11:57:19 +00:00
|
|
|
/* Check something that looks like a procedure or function call.
|
1986-10-06 20:36:30 +00:00
|
|
|
Of course this does not have to be a call at all,
|
1986-04-11 11:57:19 +00:00
|
|
|
it may also be a cast or a standard procedure call.
|
|
|
|
*/
|
1986-04-09 18:14:49 +00:00
|
|
|
|
1986-04-18 17:53:47 +00:00
|
|
|
/* First, get the name of the function or procedure
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
if (ChkDesig(&((*expp)->nd_LEFT), D_USED)) {
|
|
|
|
register t_node *left = (*expp)->nd_LEFT;
|
|
|
|
|
1986-11-17 13:08:18 +00:00
|
|
|
if (IsCast(left)) {
|
|
|
|
/* It was a type cast.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
return ChkCast(expp);
|
1986-11-17 13:08:18 +00:00
|
|
|
}
|
1986-04-09 18:14:49 +00:00
|
|
|
|
1989-03-03 16:13:45 +00:00
|
|
|
if (IsProc(left) || left->nd_type == error_type) {
|
1986-11-17 13:08:18 +00:00
|
|
|
/* A procedure call.
|
|
|
|
It may also be a call to a standard procedure
|
|
|
|
*/
|
|
|
|
if (left->nd_type == std_type) {
|
|
|
|
/* A standard procedure
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
return ChkStandard(expp);
|
1986-11-17 13:08:18 +00:00
|
|
|
}
|
|
|
|
/* Here, we have found a real procedure call.
|
|
|
|
The left hand side may also represent a procedure
|
|
|
|
variable.
|
1986-04-11 11:57:19 +00:00
|
|
|
*/
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
1987-09-14 11:24:12 +00:00
|
|
|
else {
|
|
|
|
node_error(left, "procedure, type, or function expected");
|
|
|
|
left->nd_type = error_type;
|
|
|
|
}
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
return ChkProcCall(*expp);
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
STATIC t_type *
|
1986-06-06 02:22:09 +00:00
|
|
|
ResultOfOperation(operator, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_type *tp;
|
1986-06-06 02:22:09 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Return the result type of the binary operation "operator",
|
|
|
|
with operand type "tp".
|
|
|
|
*/
|
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
switch(operator) {
|
|
|
|
case '=':
|
|
|
|
case '#':
|
|
|
|
case GREATEREQUAL:
|
|
|
|
case LESSEQUAL:
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
case IN:
|
|
|
|
return bool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
1987-08-03 09:09:07 +00:00
|
|
|
#define Boolean(operator) (operator == OR || operator == AND)
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-06-06 02:22:09 +00:00
|
|
|
AllowedTypes(operator)
|
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Return a bit mask indicating the allowed operand types
|
|
|
|
for binary operator "operator".
|
|
|
|
*/
|
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
switch(operator) {
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
case '*':
|
|
|
|
return T_NUMERIC|T_SET;
|
|
|
|
case '/':
|
|
|
|
return T_REAL|T_SET;
|
|
|
|
case DIV:
|
|
|
|
case MOD:
|
|
|
|
return T_INTORCARD;
|
|
|
|
case OR:
|
|
|
|
case AND:
|
|
|
|
return T_ENUMERATION;
|
|
|
|
case '=':
|
|
|
|
case '#':
|
|
|
|
return T_POINTER|T_HIDDEN|T_SET|T_NUMERIC|T_ENUMERATION|T_CHAR;
|
|
|
|
case GREATEREQUAL:
|
|
|
|
case LESSEQUAL:
|
|
|
|
return T_SET|T_NUMERIC|T_CHAR|T_ENUMERATION;
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
return T_NUMERIC|T_CHAR|T_ENUMERATION;
|
|
|
|
default:
|
|
|
|
crash("(AllowedTypes)");
|
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1988-03-21 16:36:31 +00:00
|
|
|
ChkAddressOper(tpl, tpr, expp)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tpl, *tpr;
|
1988-03-21 16:36:31 +00:00
|
|
|
register t_node *expp;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check that either "tpl" or "tpr" are both of type
|
|
|
|
address_type, or that one of them is, but the other is
|
1988-03-21 16:36:31 +00:00
|
|
|
of a cardinal type.
|
|
|
|
Also insert proper coercions, making sure that the EM pointer
|
|
|
|
arithmetic instructions can be generated whenever possible
|
1986-10-06 20:36:30 +00:00
|
|
|
*/
|
1988-03-21 16:36:31 +00:00
|
|
|
|
|
|
|
if (tpr == address_type && expp->nd_symb == '+') {
|
|
|
|
/* use the fact that '+' is a commutative operator */
|
|
|
|
t_type *tmptype = tpr;
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node *tmpnode = expp->nd_RIGHT;
|
1988-03-21 16:36:31 +00:00
|
|
|
|
|
|
|
tpr = tpl;
|
1991-03-12 16:52:00 +00:00
|
|
|
expp->nd_RIGHT = expp->nd_LEFT;
|
1988-03-21 16:36:31 +00:00
|
|
|
tpl = tmptype;
|
1991-03-12 16:52:00 +00:00
|
|
|
expp->nd_LEFT = tmpnode;
|
1988-03-21 16:36:31 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
if (tpl == address_type) {
|
1988-03-21 16:36:31 +00:00
|
|
|
expp->nd_type = address_type;
|
|
|
|
if (tpr == address_type) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (tpr->tp_fund & T_CARDINAL) {
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(expp->nd_RIGHT),
|
1988-03-21 16:36:31 +00:00
|
|
|
expp->nd_symb=='+' || expp->nd_symb=='-' ?
|
|
|
|
tpr :
|
|
|
|
address_type);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
1988-03-21 16:36:31 +00:00
|
|
|
if (tpr == address_type && tpl->tp_fund & T_CARDINAL) {
|
|
|
|
expp->nd_type = address_type;
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(expp->nd_LEFT), address_type);
|
1988-03-21 16:36:31 +00:00
|
|
|
return 1;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkBinOper(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-04-08 18:15:46 +00:00
|
|
|
{
|
1986-04-10 01:08:49 +00:00
|
|
|
/* Check a binary operation.
|
1986-04-08 18:15:46 +00:00
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tpl, *tpr;
|
1988-03-21 16:36:31 +00:00
|
|
|
t_type *result_type;
|
1986-06-06 02:22:09 +00:00
|
|
|
int allowed;
|
1986-11-17 11:41:28 +00:00
|
|
|
int retval;
|
1991-03-13 17:26:07 +00:00
|
|
|
char *symb;
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1988-03-21 16:36:31 +00:00
|
|
|
/* First, check BOTH operands */
|
1986-06-10 13:18:52 +00:00
|
|
|
|
1991-04-25 16:47:47 +00:00
|
|
|
retval = ChkExpression(&(exp->nd_LEFT));
|
|
|
|
retval &= ChkExpression(&(exp->nd_RIGHT));
|
1986-06-10 13:18:52 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
tpl = BaseType(exp->nd_LEFT->nd_type);
|
|
|
|
tpr = BaseType(exp->nd_RIGHT->nd_type);
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1988-11-29 13:13:03 +00:00
|
|
|
if (intorcard(tpl, tpr) != 0) {
|
|
|
|
if (tpl == intorcard_type) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_LEFT->nd_type = tpl = tpr;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
1988-11-29 13:13:03 +00:00
|
|
|
if (tpr == intorcard_type) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_RIGHT->nd_type = tpr = tpl;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = result_type = ResultOfOperation(exp->nd_symb, tpr);
|
1986-04-08 18:15:46 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check that the application of the operator is allowed on the type
|
|
|
|
of the operands.
|
|
|
|
There are three tricky parts:
|
|
|
|
- Boolean operators are only allowed on boolean operands, but
|
|
|
|
the "allowed-mask" of "AllowedTypes" can only indicate
|
|
|
|
an enumeration type.
|
|
|
|
- All operations that are allowed on CARDINALS are also allowed
|
|
|
|
on ADDRESS.
|
|
|
|
- The IN-operator has as right-hand-size operand a set.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
if (exp->nd_symb == IN) {
|
1987-06-18 15:46:08 +00:00
|
|
|
if (tpr->tp_fund != T_SET) {
|
1991-03-13 17:26:07 +00:00
|
|
|
node_error(exp, "\"IN\": right operand must be a set");
|
|
|
|
return 0;
|
1987-06-18 15:46:08 +00:00
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!TstAssCompat(ElementType(tpr), tpl)) {
|
1986-04-23 22:12:22 +00:00
|
|
|
/* Assignment compatible ???
|
1986-04-28 18:06:58 +00:00
|
|
|
I don't know! Should we be allowed to check
|
1986-11-17 11:41:28 +00:00
|
|
|
if a INTEGER is a member of a BITSET???
|
1986-04-23 22:12:22 +00:00
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
node_error(exp->nd_LEFT, "type incompatibility in IN");
|
1986-04-08 18:15:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(exp->nd_LEFT), word_type);
|
|
|
|
if (exp->nd_LEFT->nd_class == Value &&
|
|
|
|
exp->nd_RIGHT->nd_class == Set &&
|
|
|
|
! exp->nd_RIGHT->nd_NEXT) {
|
1986-04-11 11:57:19 +00:00
|
|
|
cstset(expp);
|
|
|
|
}
|
1986-11-17 11:41:28 +00:00
|
|
|
return retval;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!retval) return 0;
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
allowed = AllowedTypes(exp->nd_symb);
|
1986-09-25 19:39:06 +00:00
|
|
|
|
1991-03-13 17:26:07 +00:00
|
|
|
symb = symbol2str(exp->nd_symb);
|
1986-10-06 20:36:30 +00:00
|
|
|
if (!(tpr->tp_fund & allowed) || !(tpl->tp_fund & allowed)) {
|
|
|
|
if (!((T_CARDINAL & allowed) &&
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkAddressOper(tpl, tpr, exp))) {
|
1991-03-13 17:26:07 +00:00
|
|
|
node_error(exp, "\"%s\": illegal operand type(s)", symb);
|
|
|
|
return 0;
|
1986-10-06 20:36:30 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
if (result_type == bool_type) exp->nd_type = bool_type;
|
1986-10-06 20:36:30 +00:00
|
|
|
}
|
1988-03-21 16:36:31 +00:00
|
|
|
else {
|
1991-03-12 16:52:00 +00:00
|
|
|
if (Boolean(exp->nd_symb) && tpl != bool_type) {
|
1991-03-13 17:26:07 +00:00
|
|
|
node_error(exp, "\"%s\": illegal operand type(s)", symb);
|
|
|
|
return 0;
|
1988-03-21 16:36:31 +00:00
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
|
1988-03-21 16:36:31 +00:00
|
|
|
/* Operands must be compatible (distilled from Def 8.2)
|
|
|
|
*/
|
|
|
|
if (!TstCompat(tpr, tpl)) {
|
1988-06-09 11:39:11 +00:00
|
|
|
extern char *incompat();
|
1991-03-13 17:26:07 +00:00
|
|
|
node_error(exp, "\"%s\": %s in operands", symb, incompat(tpl, tpr));
|
|
|
|
return 0;
|
1988-03-21 16:36:31 +00:00
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(exp->nd_LEFT), tpl);
|
|
|
|
MkCoercion(&(exp->nd_RIGHT), tpr);
|
1986-06-06 02:22:09 +00:00
|
|
|
}
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
if (tpl->tp_fund == T_SET) {
|
1991-03-12 16:52:00 +00:00
|
|
|
if (exp->nd_LEFT->nd_class == Set &&
|
|
|
|
! exp->nd_LEFT->nd_NEXT &&
|
|
|
|
exp->nd_RIGHT->nd_class == Set &&
|
|
|
|
! exp->nd_RIGHT->nd_NEXT) {
|
1986-06-06 02:22:09 +00:00
|
|
|
cstset(expp);
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
else if ( exp->nd_LEFT->nd_class == Value &&
|
|
|
|
exp->nd_RIGHT->nd_class == Value) {
|
|
|
|
if (tpl->tp_fund == T_INTEGER) {
|
1987-11-26 14:15:24 +00:00
|
|
|
cstibin(expp);
|
|
|
|
}
|
1989-12-19 09:40:25 +00:00
|
|
|
else if (tpl->tp_fund == T_REAL) {
|
|
|
|
cstfbin(expp);
|
|
|
|
}
|
1987-11-26 14:15:24 +00:00
|
|
|
else cstubin(expp);
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
1986-06-06 02:22:09 +00:00
|
|
|
|
|
|
|
return 1;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkUnOper(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-04-08 18:15:46 +00:00
|
|
|
{
|
1986-04-10 01:08:49 +00:00
|
|
|
/* Check an unary operation.
|
1986-04-08 18:15:46 +00:00
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
|
|
|
register t_node *right = exp->nd_RIGHT;
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tpr;
|
1986-06-10 13:18:52 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (exp->nd_symb == COERCION) return 1;
|
|
|
|
if (exp->nd_symb == '(') {
|
|
|
|
*expp = right;
|
|
|
|
free_node(exp);
|
1987-09-14 11:24:12 +00:00
|
|
|
return ChkExpression(expp);
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = error_type;
|
|
|
|
if (! ChkExpression(&(exp->nd_RIGHT))) return 0;
|
|
|
|
exp->nd_type = tpr = BaseType(exp->nd_RIGHT->nd_type);
|
|
|
|
MkCoercion(&(exp->nd_RIGHT), tpr);
|
|
|
|
right = exp->nd_RIGHT;
|
1987-07-30 13:37:39 +00:00
|
|
|
|
1986-07-10 16:27:26 +00:00
|
|
|
if (tpr == address_type) tpr = card_type;
|
1986-04-08 18:15:46 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
switch(exp->nd_symb) {
|
1986-04-08 18:15:46 +00:00
|
|
|
case '+':
|
1987-06-18 15:46:08 +00:00
|
|
|
if (!(tpr->tp_fund & T_NUMERIC)) break;
|
1991-03-12 16:52:00 +00:00
|
|
|
*expp = right;
|
|
|
|
free_node(exp);
|
1987-09-23 16:39:43 +00:00
|
|
|
return 1;
|
1987-06-18 15:46:08 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
case '-':
|
1987-10-19 11:28:37 +00:00
|
|
|
if (tpr->tp_fund == T_INTORCARD || tpr->tp_fund == T_INTEGER) {
|
|
|
|
if (tpr == intorcard_type) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = int_type;
|
1986-05-14 09:03:51 +00:00
|
|
|
}
|
1986-04-28 18:06:58 +00:00
|
|
|
if (right->nd_class == Value) {
|
1986-04-08 18:15:46 +00:00
|
|
|
cstunary(expp);
|
|
|
|
}
|
|
|
|
return 1;
|
1986-04-11 11:57:19 +00:00
|
|
|
}
|
|
|
|
else if (tpr->tp_fund == T_REAL) {
|
1986-04-28 18:06:58 +00:00
|
|
|
if (right->nd_class == Value) {
|
1991-03-12 16:52:00 +00:00
|
|
|
*expp = right;
|
|
|
|
flt_umin(&(right->nd_RVAL));
|
|
|
|
if (right->nd_RSTR) {
|
|
|
|
free(right->nd_RSTR);
|
|
|
|
right->nd_RSTR = 0;
|
1989-12-19 09:40:25 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
free_node(exp);
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
case NOT:
|
1989-12-19 09:40:25 +00:00
|
|
|
case '~':
|
1986-04-08 18:15:46 +00:00
|
|
|
if (tpr == bool_type) {
|
1986-04-28 18:06:58 +00:00
|
|
|
if (right->nd_class == Value) {
|
1986-04-08 18:15:46 +00:00
|
|
|
cstunary(expp);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
default:
|
1986-07-10 16:27:26 +00:00
|
|
|
crash("ChkUnOper");
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
1991-03-13 17:26:07 +00:00
|
|
|
node_error(exp, "\"%s\": illegal operand type", symbol2str(exp->nd_symb));
|
|
|
|
return 0;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
STATIC t_node *
|
1987-10-19 11:28:37 +00:00
|
|
|
getvariable(argp, edf, flags)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node **argp;
|
|
|
|
t_def *edf;
|
1986-04-23 22:12:22 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Get the next argument from argument list "argp".
|
|
|
|
It must obey the rules of "ChkVariable".
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *arg = nextarg(argp, edf);
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! arg ||
|
|
|
|
! arg->nd_LEFT ||
|
|
|
|
! ChkVariable(&(arg->nd_LEFT), flags)) return 0;
|
1986-10-06 20:36:30 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
return arg->nd_LEFT;
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
STATIC int
|
1987-07-30 13:37:39 +00:00
|
|
|
ChkStandard(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-04-23 22:12:22 +00:00
|
|
|
{
|
|
|
|
/* Check a call of a standard procedure or function
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
1991-03-18 16:30:49 +00:00
|
|
|
t_node *arglink = exp;
|
|
|
|
register t_node *arg;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_def *edf = exp->nd_LEFT->nd_def;
|
1987-07-30 13:37:39 +00:00
|
|
|
int free_it = 0;
|
1991-03-12 16:52:00 +00:00
|
|
|
int isconstant = 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
assert(exp->nd_LEFT->nd_class == Def);
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = error_type;
|
1987-07-30 13:37:39 +00:00
|
|
|
switch(edf->df_value.df_stdname) {
|
1986-04-23 22:12:22 +00:00
|
|
|
case S_ABS:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getarg(&arglink, T_NUMERIC, 0, edf))) return 0;
|
|
|
|
exp->nd_type = BaseType(arg->nd_type);
|
|
|
|
MkCoercion(&(arglink->nd_LEFT), exp->nd_type);
|
|
|
|
arg = arglink->nd_LEFT;
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! (exp->nd_type->tp_fund & (T_INTEGER|T_REAL))) {
|
|
|
|
free_it = 1;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arg->nd_class == Value) {
|
1991-03-12 16:52:00 +00:00
|
|
|
switch(exp->nd_type->tp_fund) {
|
|
|
|
case T_REAL:
|
1991-03-18 16:30:49 +00:00
|
|
|
arg->nd_RVAL.flt_sign = 0;
|
1989-12-19 09:40:25 +00:00
|
|
|
free_it = 1;
|
1991-03-12 16:52:00 +00:00
|
|
|
break;
|
|
|
|
case T_INTEGER:
|
|
|
|
isconstant = 1;
|
|
|
|
break;
|
1989-12-19 09:40:25 +00:00
|
|
|
}
|
1987-09-14 11:24:12 +00:00
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CAP:
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = char_type;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getarg(&arglink, T_CHAR, 0, edf))) return 0;
|
|
|
|
if (arg->nd_class == Value) isconstant = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
1987-05-27 10:16:03 +00:00
|
|
|
case S_FLOATD:
|
1986-04-23 22:12:22 +00:00
|
|
|
case S_FLOAT:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! getarg(&arglink, T_INTORCARD, 0, edf)) return 0;
|
|
|
|
arg = arglink;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (edf->df_value.df_stdname == S_FLOAT) {
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(arg->nd_LEFT), card_type);
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(arg->nd_LEFT),
|
1987-07-30 13:37:39 +00:00
|
|
|
edf->df_value.df_stdname == S_FLOATD ?
|
|
|
|
longreal_type :
|
|
|
|
real_type);
|
|
|
|
free_it = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
case S_SHORT:
|
1987-05-27 10:16:03 +00:00
|
|
|
case S_LONG: {
|
1987-09-23 16:39:43 +00:00
|
|
|
t_type *tp;
|
|
|
|
t_type *s1, *s2, *d1, *d2;
|
1987-05-27 10:16:03 +00:00
|
|
|
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getarg(&arglink, 0, 0, edf))) {
|
1991-03-12 16:52:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
tp = BaseType(arg->nd_type);
|
1991-03-12 16:52:00 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (edf->df_value.df_stdname == S_SHORT) {
|
|
|
|
s1 = longint_type;
|
|
|
|
d1 = int_type;
|
|
|
|
s2 = longreal_type;
|
|
|
|
d2 = real_type;
|
1987-05-27 10:16:03 +00:00
|
|
|
}
|
|
|
|
else {
|
1987-07-30 13:37:39 +00:00
|
|
|
d1 = longint_type;
|
|
|
|
s1 = int_type;
|
|
|
|
d2 = longreal_type;
|
|
|
|
s2 = real_type;
|
1987-05-27 10:16:03 +00:00
|
|
|
}
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (tp == s1) {
|
1991-03-18 16:30:49 +00:00
|
|
|
MkCoercion(&(arglink->nd_LEFT), d1);
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
else if (tp == s2) {
|
1991-03-18 16:30:49 +00:00
|
|
|
MkCoercion(&(arglink->nd_LEFT), d2);
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
1987-05-27 10:16:03 +00:00
|
|
|
else {
|
1991-03-18 16:30:49 +00:00
|
|
|
df_error(arg, "unexpected parameter type", edf);
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1987-05-27 10:16:03 +00:00
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
free_it = 1;
|
1987-05-27 10:16:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1986-04-23 22:12:22 +00:00
|
|
|
case S_HIGH:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getarg(&arglink, T_ARRAY|T_STRING|T_CHAR, 0, edf))) {
|
1986-11-17 11:41:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arg->nd_type->tp_fund == T_ARRAY) {
|
|
|
|
exp->nd_type = IndexType(arg->nd_type);
|
|
|
|
if (! IsConformantArray(arg->nd_type)) {
|
|
|
|
arg->nd_type = exp->nd_type;
|
1991-03-12 16:52:00 +00:00
|
|
|
isconstant = 1;
|
1987-07-22 17:02:54 +00:00
|
|
|
}
|
1986-10-22 15:38:24 +00:00
|
|
|
break;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arg->nd_symb != STRING) {
|
|
|
|
df_error(arg,"array parameter expected", edf);
|
1991-03-12 16:52:00 +00:00
|
|
|
return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = getnode(Value);
|
|
|
|
exp->nd_type = card_type;
|
1986-11-17 11:41:28 +00:00
|
|
|
/* Notice that we could disallow HIGH("") here by checking
|
1991-03-18 16:30:49 +00:00
|
|
|
that arg->nd_type->tp_fund != T_CHAR || arg->nd_INT != 0.
|
1986-11-17 11:41:28 +00:00
|
|
|
??? For the time being, we don't. !!!
|
|
|
|
Maybe the empty string should not be allowed at all.
|
|
|
|
*/
|
1991-03-18 16:30:49 +00:00
|
|
|
exp->nd_INT = arg->nd_type->tp_fund == T_CHAR ? 0 :
|
|
|
|
arg->nd_SLE - 1;
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_symb = INTEGER;
|
|
|
|
exp->nd_lineno = (*expp)->nd_lineno;
|
|
|
|
(*expp)->nd_RIGHT = 0;
|
|
|
|
FreeNode(*expp);
|
|
|
|
*expp = exp;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_MAX:
|
|
|
|
case S_MIN:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getname(&arglink, D_ISTYPE, T_DISCRETE, edf))) {
|
1986-06-17 12:04:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
exp->nd_type = arg->nd_type;
|
1991-03-12 16:52:00 +00:00
|
|
|
isconstant = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ODD:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! (arg = getarg(&arglink, T_INTORCARD, 0, edf))) return 0;
|
|
|
|
MkCoercion(&(arglink->nd_LEFT), BaseType(arg->nd_type));
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = bool_type;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arglink->nd_LEFT->nd_class == Value) isconstant = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ORD:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! (arg = getarg(&arglink, T_NOSUB, 0, edf))) return 0;
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = card_type;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arg->nd_class == Value) {
|
|
|
|
arg->nd_type = card_type;
|
1988-04-06 18:14:50 +00:00
|
|
|
free_it = 1;
|
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
1987-10-21 11:29:52 +00:00
|
|
|
#ifndef STRICT_3RD_ED
|
1986-06-20 14:36:49 +00:00
|
|
|
case S_NEW:
|
|
|
|
case S_DISPOSE:
|
|
|
|
{
|
|
|
|
static int warning_given = 0;
|
|
|
|
|
|
|
|
if (!warning_given) {
|
|
|
|
warning_given = 1;
|
1987-10-19 11:28:37 +00:00
|
|
|
if (! options['3'])
|
1991-03-12 16:52:00 +00:00
|
|
|
node_warning(exp, W_OLDFASHIONED, "NEW and DISPOSE are obsolete");
|
1987-10-19 11:28:37 +00:00
|
|
|
else
|
1991-03-12 16:52:00 +00:00
|
|
|
node_error(exp, "NEW and DISPOSE are obsolete");
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = 0;
|
1991-03-18 16:30:49 +00:00
|
|
|
arg = getvariable(&arglink, edf, D_USED|D_DEFINED);
|
|
|
|
if (! arg) return 0;
|
|
|
|
if (! (arg->nd_type->tp_fund == T_POINTER)) {
|
|
|
|
df_error(arg, "pointer variable expected", edf);
|
1991-03-12 16:52:00 +00:00
|
|
|
return 0;
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
/* Now, make it look like a call to ALLOCATE or DEALLOCATE */
|
1991-03-18 16:30:49 +00:00
|
|
|
arglink->nd_RIGHT = arg = getnode(Link);
|
|
|
|
arg->nd_lineno = exp->nd_lineno;
|
|
|
|
arg->nd_symb = ',';
|
|
|
|
arg->nd_LEFT = getnode(Value);
|
|
|
|
arg = arg->nd_LEFT;
|
|
|
|
arg->nd_INT = PointedtoType(arglink->nd_LEFT->nd_type)->tp_size;
|
|
|
|
arg->nd_symb = INTEGER;
|
|
|
|
arg->nd_lineno = exp->nd_lineno;
|
|
|
|
arg->nd_type = card_type;
|
|
|
|
/* Ignore other arguments to NEW and/or DISPOSE ??? */
|
|
|
|
|
|
|
|
FreeNode(exp->nd_LEFT);
|
|
|
|
exp->nd_LEFT = arg = getnode(Name);
|
|
|
|
arg->nd_symb = IDENT;
|
|
|
|
arg->nd_lineno = exp->nd_lineno;
|
|
|
|
arg->nd_IDF = str2idf(edf->df_value.df_stdname==S_NEW ?
|
|
|
|
"ALLOCATE" : "DEALLOCATE", 0);
|
1986-07-10 16:27:26 +00:00
|
|
|
return ChkCall(expp);
|
1987-10-19 11:28:37 +00:00
|
|
|
#endif
|
1986-06-20 14:36:49 +00:00
|
|
|
|
1986-04-23 22:12:22 +00:00
|
|
|
case S_TSIZE: /* ??? */
|
|
|
|
case S_SIZE:
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = intorcard_type;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getname(&arglink,D_FIELD|D_VARIABLE|D_ISTYPE,0,edf))) {
|
1986-11-17 11:41:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! IsConformantArray(arg->nd_type)) isconstant = 1;
|
1987-11-09 16:11:04 +00:00
|
|
|
#ifndef NOSTRICT
|
1991-03-12 16:52:00 +00:00
|
|
|
else node_warning(exp,
|
1986-11-28 11:59:08 +00:00
|
|
|
W_STRICT,
|
|
|
|
"%s on conformant array",
|
1991-03-18 16:30:49 +00:00
|
|
|
edf->df_idf->id_text);
|
1988-04-26 10:14:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef STRICT_3RD_ED
|
|
|
|
if (! options['3'] && edf->df_value.df_stdname == S_TSIZE) {
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arg = arglink->nd_RIGHT) {
|
|
|
|
node_warning(arg,
|
1988-04-26 10:14:01 +00:00
|
|
|
W_OLDFASHIONED,
|
|
|
|
"TSIZE with multiple parameters, only first parameter used");
|
1991-03-18 16:30:49 +00:00
|
|
|
FreeNode(arg);
|
|
|
|
arglink->nd_RIGHT = 0;
|
1988-04-26 10:14:01 +00:00
|
|
|
}
|
|
|
|
}
|
1987-11-09 10:17:20 +00:00
|
|
|
#endif
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
1987-05-27 10:16:03 +00:00
|
|
|
case S_TRUNCD:
|
1986-04-23 22:12:22 +00:00
|
|
|
case S_TRUNC:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! getarg(&arglink, T_REAL, 0, edf)) return 0;
|
|
|
|
MkCoercion(&(arglink->nd_LEFT),
|
1988-04-06 18:14:50 +00:00
|
|
|
edf->df_value.df_stdname == S_TRUNCD ?
|
|
|
|
longint_type : card_type);
|
1987-07-30 13:37:39 +00:00
|
|
|
free_it = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_VAL:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getname(&arglink, D_ISTYPE, T_NOSUB, edf))) {
|
1986-04-23 22:12:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
exp->nd_type = arg->nd_def->df_type;
|
|
|
|
exp->nd_RIGHT = arglink->nd_RIGHT;
|
|
|
|
arglink->nd_RIGHT = 0;
|
|
|
|
FreeNode(arglink);
|
|
|
|
arglink = exp;
|
1988-04-06 18:14:50 +00:00
|
|
|
/* fall through */
|
|
|
|
case S_CHR:
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! getarg(&arglink, T_CARDINAL, 0, edf)) return 0;
|
1988-04-06 18:14:50 +00:00
|
|
|
if (edf->df_value.df_stdname == S_CHR) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = char_type;
|
1988-04-06 18:14:50 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
if (exp->nd_type != int_type) {
|
1991-03-18 16:30:49 +00:00
|
|
|
MkCoercion(&(arglink->nd_LEFT), exp->nd_type);
|
1988-04-06 18:14:50 +00:00
|
|
|
free_it = 1;
|
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ADR:
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = address_type;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! getarg(&arglink, 0, 1, edf)) return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_DEC:
|
|
|
|
case S_INC:
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = 0;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (! (arg = getvariable(&arglink, edf, D_USED|D_DEFINED))) return 0;
|
|
|
|
if (! (arg->nd_type->tp_fund & T_DISCRETE)) {
|
|
|
|
df_error(arg,"illegal parameter type", edf);
|
1991-03-12 16:52:00 +00:00
|
|
|
return 0;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
if (arglink->nd_RIGHT) {
|
|
|
|
if (! getarg(&arglink, T_INTORCARD, 0, edf)) return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_HALT:
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_EXCL:
|
|
|
|
case S_INCL:
|
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp;
|
|
|
|
t_node *dummy;
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_type = 0;
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(arg = getvariable(&arglink, edf, D_USED|D_DEFINED))) return 0;
|
|
|
|
tp = arg->nd_type;
|
1986-04-23 22:12:22 +00:00
|
|
|
if (tp->tp_fund != T_SET) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(arg, "SET parameter expected", edf);
|
|
|
|
return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
if (!(dummy = getarg(&arglink, 0, 0, edf))) return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!ChkAssCompat(&dummy, ElementType(tp), "EXCL/INCL")) {
|
1986-04-28 18:06:58 +00:00
|
|
|
/* What type of compatibility do we want here?
|
|
|
|
apparently assignment compatibility! ??? ???
|
1987-07-30 13:37:39 +00:00
|
|
|
But we don't want the coercion in the tree, because
|
|
|
|
we don't want a range check here. We want a SET
|
|
|
|
error.
|
1986-04-28 18:06:58 +00:00
|
|
|
*/
|
1986-04-23 22:12:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-18 16:30:49 +00:00
|
|
|
MkCoercion(&(arglink->nd_LEFT), word_type);
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
1986-07-10 16:27:26 +00:00
|
|
|
crash("(ChkStandard)");
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
|
|
|
|
1991-03-18 16:30:49 +00:00
|
|
|
arg = arglink;
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (arg->nd_RIGHT) {
|
|
|
|
df_error(arg->nd_RIGHT, "too many parameters supplied", edf);
|
|
|
|
return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (isconstant) {
|
|
|
|
cstcall(expp, edf->df_value.df_stdname);
|
|
|
|
return 1;
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
if (free_it) {
|
1991-03-12 16:52:00 +00:00
|
|
|
*expp = arg->nd_LEFT;
|
|
|
|
exp->nd_RIGHT = arg;
|
|
|
|
arg->nd_LEFT = 0;
|
|
|
|
FreeNode(exp);
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
STATIC int
|
1987-07-30 13:37:39 +00:00
|
|
|
ChkCast(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-05-30 18:48:00 +00:00
|
|
|
{
|
|
|
|
/* Check a cast and perform it if the argument is constant.
|
|
|
|
If the sizes don't match, only complain if at least one of them
|
|
|
|
has a size larger than the word size.
|
|
|
|
If both sizes are equal to or smaller than the word size, there
|
|
|
|
is no problem as such values take a word on the EM stack
|
|
|
|
anyway.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *exp = *expp;
|
|
|
|
register t_node *arg = exp->nd_RIGHT;
|
|
|
|
register t_type *lefttype = exp->nd_LEFT->nd_type;
|
|
|
|
t_def *df = exp->nd_LEFT->nd_def;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if ((! arg) || arg->nd_RIGHT) {
|
|
|
|
df_error(exp, "type cast must have 1 parameter", df);
|
|
|
|
return 0;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (! ChkExpression(&(arg->nd_LEFT))) return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
MkCoercion(&(arg->nd_LEFT), BaseType(arg->nd_LEFT->nd_type));
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
arg = arg->nd_LEFT;
|
1987-07-21 13:54:33 +00:00
|
|
|
if (arg->nd_type->tp_size != lefttype->tp_size &&
|
1986-05-30 18:48:00 +00:00
|
|
|
(arg->nd_type->tp_size > word_size ||
|
1987-07-21 13:54:33 +00:00
|
|
|
lefttype->tp_size > word_size)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(exp, "unequal sizes in type cast", df);
|
|
|
|
return 0;
|
1987-09-24 13:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsConformantArray(arg->nd_type)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
df_error(exp,
|
1987-09-24 13:07:31 +00:00
|
|
|
"type transfer function on conformant array not supported",
|
|
|
|
df);
|
1991-03-12 16:52:00 +00:00
|
|
|
return 0;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
exp->nd_RIGHT->nd_LEFT = 0;
|
|
|
|
FreeNode(exp);
|
1986-05-30 18:48:00 +00:00
|
|
|
if (arg->nd_class == Value) {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = arg;
|
1990-01-18 10:12:38 +00:00
|
|
|
if (lefttype->tp_fund == T_SET) {
|
|
|
|
/* User deserves what he gets here ... */
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = getnode(Set);
|
|
|
|
exp->nd_set = MkSet((unsigned)(lefttype->set_sz));
|
|
|
|
exp->nd_set[0] = arg->nd_INT;
|
|
|
|
exp->nd_lineno = arg->nd_lineno;
|
|
|
|
FreeNode(arg);
|
1990-01-18 10:12:38 +00:00
|
|
|
}
|
1988-04-06 18:14:50 +00:00
|
|
|
}
|
|
|
|
else {
|
1991-03-12 16:52:00 +00:00
|
|
|
exp = getnode(Uoper);
|
|
|
|
exp->nd_symb = CAST;
|
|
|
|
exp->nd_lineno = arg->nd_lineno;
|
|
|
|
exp->nd_RIGHT = arg;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
*expp = exp;
|
|
|
|
exp->nd_type = lefttype;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
1986-06-04 09:01:48 +00:00
|
|
|
|
|
|
|
TryToString(nd, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
|
|
|
t_type *tp;
|
1986-06-04 09:01:48 +00:00
|
|
|
{
|
1986-06-17 12:04:05 +00:00
|
|
|
/* Try a coercion from character constant to string.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
static char buf[8];
|
1986-09-25 19:39:06 +00:00
|
|
|
|
|
|
|
assert(nd->nd_symb == STRING);
|
|
|
|
|
1986-06-04 09:01:48 +00:00
|
|
|
if (tp->tp_fund == T_ARRAY && nd->nd_type == char_type) {
|
1987-07-30 13:37:39 +00:00
|
|
|
buf[0] = nd->nd_INT;
|
1986-06-04 09:01:48 +00:00
|
|
|
nd->nd_type = standard_type(T_STRING, 1, (arith) 2);
|
1991-03-06 10:52:34 +00:00
|
|
|
nd->nd_SSTR =
|
1986-06-04 09:01:48 +00:00
|
|
|
(struct string *) Malloc(sizeof(struct string));
|
1991-03-12 16:52:00 +00:00
|
|
|
nd->nd_STR = Salloc(buf, (unsigned) word_size);
|
1986-06-04 09:01:48 +00:00
|
|
|
nd->nd_SLE = 1;
|
|
|
|
}
|
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
STATIC int
|
|
|
|
no_desig(expp)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
node_error(*expp, "designator expected");
|
1986-06-26 09:39:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1989-03-20 13:32:06 +00:00
|
|
|
add_flags(expp, flags)
|
1991-03-12 16:52:00 +00:00
|
|
|
t_node **expp;
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
(*expp)->nd_def->df_flags |= flags;
|
1986-06-26 09:39:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
extern int PNodeCrash();
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
int (*ExprChkTable[])() = {
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkValue,
|
|
|
|
ChkArr,
|
|
|
|
ChkBinOper,
|
|
|
|
ChkUnOper,
|
|
|
|
ChkArrow,
|
1987-05-18 15:57:33 +00:00
|
|
|
ChkFunCall,
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkExSelOrName,
|
|
|
|
PNodeCrash,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkSet,
|
1989-03-20 13:32:06 +00:00
|
|
|
add_flags,
|
1991-03-12 16:52:00 +00:00
|
|
|
PNodeCrash,
|
|
|
|
ChkExSelOrName,
|
|
|
|
PNodeCrash,
|
1986-06-17 12:04:05 +00:00
|
|
|
};
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
int (*DesigChkTable[])() = {
|
1987-04-29 10:22:07 +00:00
|
|
|
no_desig,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkArr,
|
1986-06-26 09:39:36 +00:00
|
|
|
no_desig,
|
|
|
|
no_desig,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkArrow,
|
1986-06-26 09:39:36 +00:00
|
|
|
no_desig,
|
1991-03-12 16:52:00 +00:00
|
|
|
ChkSelOrName,
|
|
|
|
PNodeCrash,
|
1986-06-26 09:39:36 +00:00
|
|
|
no_desig,
|
1989-03-20 13:32:06 +00:00
|
|
|
add_flags,
|
1991-03-12 16:52:00 +00:00
|
|
|
PNodeCrash,
|
|
|
|
ChkSelOrName,
|
|
|
|
PNodeCrash,
|
1986-06-26 09:39:36 +00:00
|
|
|
};
|