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
|
|
|
|
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 "const.h"
|
|
|
|
#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"
|
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();
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
STATIC int
|
1986-11-17 11:41:28 +00:00
|
|
|
Xerror(nd, mess, edf)
|
|
|
|
struct node *nd;
|
|
|
|
char *mess;
|
1986-11-17 13:08:18 +00:00
|
|
|
register struct def *edf;
|
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-07-30 13:37:39 +00:00
|
|
|
else node_error(nd, "%s", mess);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MkCoercion(pnd, tp)
|
|
|
|
struct node **pnd;
|
|
|
|
register struct type *tp;
|
|
|
|
{
|
|
|
|
register struct node *nd = *pnd;
|
|
|
|
register struct type *nd_tp = nd->nd_type;
|
|
|
|
extern int pass_1;
|
|
|
|
int w = 0;
|
|
|
|
|
|
|
|
if (nd_tp == tp) return;
|
|
|
|
if (nd_tp->tp_fund == T_STRING) return;
|
|
|
|
nd_tp = BaseType(nd_tp);
|
|
|
|
if (nd->nd_class == Value) {
|
|
|
|
switch(tp->tp_fund) {
|
|
|
|
case T_REAL:
|
|
|
|
if (nd_tp->tp_fund == T_REAL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto Out;
|
|
|
|
case T_SUBRANGE:
|
|
|
|
if (! chk_bounds(tp->sub_lb, nd->nd_INT,
|
|
|
|
BaseType(tp)->tp_fund) ||
|
|
|
|
! chk_bounds(nd->nd_INT, tp->sub_ub,
|
|
|
|
BaseType(tp)->tp_fund)) {
|
|
|
|
node_warning(nd,
|
|
|
|
W_ORDINARY,
|
|
|
|
"might cause range bound error");
|
|
|
|
w = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_ENUMERATION:
|
|
|
|
case T_CHAR:
|
|
|
|
if (nd->nd_INT < 0 || nd->nd_INT >= tp->enm_ncst) {
|
|
|
|
node_warning(nd,
|
|
|
|
W_ORDINARY,
|
|
|
|
"might cause range bound error");
|
|
|
|
w = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_INTORCARD:
|
|
|
|
case T_CARDINAL:
|
|
|
|
case T_POINTER:
|
|
|
|
if ((nd_tp->tp_fund == T_INTEGER &&
|
|
|
|
nd->nd_INT < 0) ||
|
|
|
|
(nd->nd_INT & ~full_mask[(int)(tp->tp_size)])) {
|
|
|
|
node_warning(nd,
|
|
|
|
W_ORDINARY,
|
|
|
|
"might cause conversion error");
|
|
|
|
w = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_INTEGER: {
|
|
|
|
long i = ~int_mask[(int)(tp->tp_size)];
|
|
|
|
long j = nd->nd_INT & i;
|
|
|
|
|
|
|
|
if ((nd_tp->tp_fund == T_INTEGER &&
|
|
|
|
j != i && j != 0) ||
|
|
|
|
(nd_tp->tp_fund != T_INTEGER && j)) {
|
|
|
|
node_warning(nd,
|
|
|
|
W_ORDINARY,
|
|
|
|
"might cause conversion error");
|
|
|
|
w = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!w || pass_1) {
|
|
|
|
nd->nd_type = tp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Out:
|
|
|
|
*pnd = nd = MkNode(Uoper, NULLNODE, nd, &(nd->nd_token));
|
|
|
|
nd->nd_symb = COERCION;
|
|
|
|
nd->nd_type = tp;
|
1986-11-17 11:41:28 +00:00
|
|
|
}
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkVariable(expp)
|
1986-06-26 09:39:36 +00:00
|
|
|
register struct node *expp;
|
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check that "expp" indicates an item that can be
|
|
|
|
assigned to.
|
|
|
|
*/
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
return ChkDesignator(expp) &&
|
|
|
|
( expp->nd_class != Def ||
|
|
|
|
( expp->nd_def->df_kind & (D_FIELD|D_VARIABLE)) ||
|
|
|
|
Xerror(expp, "variable expected", expp->nd_def));
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkArrow(expp)
|
1986-06-26 09:39:36 +00:00
|
|
|
register struct node *expp;
|
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check an application of the '^' operator.
|
|
|
|
The operand must be a variable of a pointer type.
|
|
|
|
*/
|
1986-06-26 09:39:36 +00:00
|
|
|
register struct type *tp;
|
|
|
|
|
|
|
|
assert(expp->nd_class == Arrow);
|
|
|
|
assert(expp->nd_symb == '^');
|
|
|
|
|
|
|
|
expp->nd_type = error_type;
|
|
|
|
|
1986-07-10 16:27:26 +00:00
|
|
|
if (! ChkVariable(expp->nd_right)) return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
tp = expp->nd_right->nd_type;
|
|
|
|
|
|
|
|
if (tp->tp_fund != T_POINTER) {
|
1986-11-17 11:41:28 +00:00
|
|
|
node_error(expp, "\"^\": illegal operand");
|
1986-06-26 09:39:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
expp->nd_type = RemoveEqual(PointedtoType(tp));
|
1986-06-26 09:39:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkArr(expp)
|
1986-06-26 09:39:36 +00:00
|
|
|
register struct 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-07-30 13:37:39 +00:00
|
|
|
register struct type *tpl;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
assert(expp->nd_class == Arrsel);
|
|
|
|
assert(expp->nd_symb == '[');
|
|
|
|
|
|
|
|
expp->nd_type = error_type;
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! (ChkVariable(expp->nd_left) & ChkExpression(expp->nd_right))) {
|
|
|
|
return 0;
|
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
tpl = expp->nd_left->nd_type;
|
|
|
|
|
|
|
|
if (tpl->tp_fund != T_ARRAY) {
|
1986-10-06 20:36:30 +00:00
|
|
|
node_error(expp, "not indexing an ARRAY type");
|
1986-06-26 09:39:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
expp->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
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
return ChkAssCompat(&(expp->nd_right),
|
|
|
|
BaseType(IndexType(tpl)),
|
|
|
|
"index type");
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
#ifdef DEBUG
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkValue(expp)
|
1986-06-17 12:04:05 +00:00
|
|
|
struct node *expp;
|
|
|
|
{
|
|
|
|
switch(expp->nd_symb) {
|
|
|
|
case REAL:
|
|
|
|
case STRING:
|
|
|
|
case INTEGER:
|
|
|
|
return 1;
|
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
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
#endif
|
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
|
|
|
ChkLinkOrName(expp)
|
1986-04-08 18:15:46 +00:00
|
|
|
register struct node *expp;
|
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Check either an ID or a construction of the form
|
|
|
|
ID.ID [ .ID ]*
|
|
|
|
*/
|
1986-06-26 09:39:36 +00:00
|
|
|
register struct def *df;
|
|
|
|
|
1986-08-26 14:33:24 +00:00
|
|
|
expp->nd_type = error_type;
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
if (expp->nd_class == Name) {
|
|
|
|
expp->nd_def = lookfor(expp, CurrVis, 1);
|
|
|
|
expp->nd_class = Def;
|
1986-09-25 19:39:06 +00:00
|
|
|
expp->nd_type = RemoveEqual(expp->nd_def->df_type);
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
|
|
|
else if (expp->nd_class == Link) {
|
1986-10-06 20:36:30 +00:00
|
|
|
/* A selection from a record or a module.
|
|
|
|
Modules also have a record type.
|
|
|
|
*/
|
1986-06-26 09:39:36 +00:00
|
|
|
register struct node *left = expp->nd_left;
|
|
|
|
|
|
|
|
assert(expp->nd_symb == '.');
|
|
|
|
|
1986-07-10 16:27:26 +00:00
|
|
|
if (! ChkDesignator(left)) return 0;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(left, "illegal selection", left->nd_def);
|
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
|
|
|
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(df = lookup(expp->nd_IDF, left->nd_type->rec_scope, 1))) {
|
1986-06-26 09:39:36 +00:00
|
|
|
id_not_declared(expp);
|
|
|
|
return 0;
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
expp->nd_def = df;
|
|
|
|
expp->nd_type = RemoveEqual(df->df_type);
|
|
|
|
expp->nd_class = Def;
|
|
|
|
if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) {
|
|
|
|
/* Fields of a record are always D_QEXPORTED,
|
|
|
|
so ...
|
|
|
|
*/
|
1986-11-17 11:41:28 +00:00
|
|
|
Xerror(expp, "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)) {
|
|
|
|
return 1;
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
FreeNode(left);
|
|
|
|
expp->nd_left = 0;
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
assert(expp->nd_class == Def);
|
|
|
|
|
1987-07-13 11:49:32 +00:00
|
|
|
return expp->nd_def->df_kind != D_ERROR;
|
1987-07-13 10:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
|
|
|
ChkExLinkOrName(expp)
|
|
|
|
register struct node *expp;
|
|
|
|
{
|
|
|
|
/* Check either an ID or an ID.ID [.ID]* occurring in an
|
|
|
|
expression.
|
|
|
|
*/
|
|
|
|
register struct def *df;
|
|
|
|
|
|
|
|
if (! ChkLinkOrName(expp)) return 0;
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
df = expp->nd_def;
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
if (df->df_type->tp_fund == T_SET) {
|
|
|
|
expp->nd_class = Set;
|
|
|
|
}
|
|
|
|
else expp->nd_class = Value;
|
1986-06-26 09:39:36 +00:00
|
|
|
if (df->df_kind == D_ENUM) {
|
|
|
|
expp->nd_INT = df->enm_val;
|
|
|
|
expp->nd_symb = INTEGER;
|
|
|
|
}
|
|
|
|
else {
|
1986-10-06 20:36:30 +00:00
|
|
|
unsigned int ln = expp->nd_lineno;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
|
|
|
assert(df->df_kind == D_CONST);
|
1987-07-30 13:37:39 +00:00
|
|
|
expp->nd_token = df->con_const;
|
1986-06-26 09:39:36 +00:00
|
|
|
expp->nd_lineno = ln;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
if (!(df->df_kind & D_VALUE)) {
|
1986-11-17 11:41:28 +00:00
|
|
|
Xerror(expp, "value expected", df);
|
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.
|
|
|
|
*/
|
1986-10-06 20:36:30 +00:00
|
|
|
node_error(expp, "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
|
1987-07-21 13:54:33 +00:00
|
|
|
ChkEl(expr, tp)
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node **expr;
|
1987-07-21 13:54:33 +00:00
|
|
|
struct type *tp;
|
|
|
|
{
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
return ChkExpression(*expr) && ChkCompat(expr, tp, "set element");
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
|
|
|
ChkElement(expp, tp, set)
|
1987-05-11 14:38:37 +00:00
|
|
|
struct node **expp;
|
1987-07-21 13:54:33 +00:00
|
|
|
struct 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-05-11 14:38:37 +00:00
|
|
|
register struct node *expr = *expp;
|
1987-07-21 13:54:33 +00:00
|
|
|
register unsigned int i;
|
|
|
|
arith lo, hi, 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.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! (ChkEl(&(expr->nd_left), tp) &
|
|
|
|
ChkEl(&(expr->nd_right), tp))) {
|
1986-04-08 23:34:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1987-07-30 13:37:39 +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
|
|
|
|
1987-07-30 13:37:39 +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-07-30 13:37:39 +00:00
|
|
|
if (! ChkEl(expp, tp)) return 0;
|
|
|
|
expr = *expp;
|
1987-07-21 13:54:33 +00:00
|
|
|
if (expr->nd_class != Value) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
low = high = expr->nd_INT;
|
|
|
|
}
|
|
|
|
if (low > high) {
|
|
|
|
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
|
|
|
|
1987-07-21 13:54:33 +00:00
|
|
|
getbounds(tp, &lo, &hi);
|
|
|
|
if (low < lo || high > hi) {
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkSet(expp)
|
1986-06-17 12:04:05 +00:00
|
|
|
register struct 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
|
|
|
*/
|
1986-06-17 12:04:05 +00:00
|
|
|
register struct type *tp;
|
|
|
|
register struct node *nd;
|
|
|
|
register struct def *df;
|
|
|
|
unsigned size;
|
1987-05-11 14:38:37 +00:00
|
|
|
int retval = 1;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
assert(expp->nd_symb == SET);
|
|
|
|
|
1987-05-11 14:38:37 +00:00
|
|
|
expp->nd_class = Set;
|
1987-08-03 09:09:07 +00:00
|
|
|
expp->nd_type = error_type;
|
1987-05-11 14:38:37 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
/* First determine the type of the set
|
|
|
|
*/
|
|
|
|
if (nd = expp->nd_left) {
|
|
|
|
/* A type was given. Check it out
|
|
|
|
*/
|
1986-07-10 16:27:26 +00:00
|
|
|
if (! ChkDesignator(nd)) return 0;
|
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)) {
|
1986-10-06 20:36:30 +00:00
|
|
|
if (df->df_kind != D_ERROR) {
|
1987-07-13 10:30:37 +00:00
|
|
|
Xerror(nd, "not a SET type", df);
|
1986-10-06 20:36:30 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tp = df->df_type;
|
1986-11-17 11:41:28 +00:00
|
|
|
FreeNode(nd);
|
1986-06-17 12:04:05 +00:00
|
|
|
expp->nd_left = 0;
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
else tp = bitset_type;
|
|
|
|
expp->nd_type = tp;
|
|
|
|
|
|
|
|
nd = expp->nd_right;
|
|
|
|
|
|
|
|
/* 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
|
|
|
*/
|
|
|
|
size = tp->tp_size * (sizeof(arith) / word_size);
|
1987-05-11 14:38:37 +00:00
|
|
|
expp->nd_set = (arith *) Malloc(size);
|
|
|
|
clear((char *) (expp->nd_set) , size);
|
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 == ',');
|
|
|
|
|
1987-05-11 14:38:37 +00:00
|
|
|
if (!ChkElement(&(nd->nd_left), ElementType(tp),
|
1987-07-30 13:37:39 +00:00
|
|
|
expp->nd_set)) {
|
1987-05-11 14:38:37 +00:00
|
|
|
retval = 0;
|
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
nd = nd->nd_right;
|
|
|
|
}
|
|
|
|
|
1987-05-11 14:38:37 +00:00
|
|
|
if (expp->nd_class == Set) {
|
1986-06-17 12:04:05 +00:00
|
|
|
FreeNode(expp->nd_right);
|
|
|
|
expp->nd_right = 0;
|
|
|
|
}
|
1987-05-11 14:38:37 +00:00
|
|
|
return retval;
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
STATIC struct node *
|
|
|
|
nextarg(argp, edf)
|
|
|
|
struct node **argp;
|
|
|
|
struct def *edf;
|
|
|
|
{
|
|
|
|
register struct node *arg = (*argp)->nd_right;
|
|
|
|
|
|
|
|
if (! arg) {
|
|
|
|
return (struct node *)Xerror(*argp, "too few arguments supplied", edf);
|
|
|
|
}
|
|
|
|
|
|
|
|
*argp = arg;
|
|
|
|
return arg->nd_left;
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC struct node *
|
1986-11-17 11:41:28 +00:00
|
|
|
getarg(argp, bases, designator, edf)
|
1986-05-30 18:48:00 +00:00
|
|
|
struct node **argp;
|
1986-11-17 11:41:28 +00:00
|
|
|
struct 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.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node *left = nextarg(argp, edf);
|
1986-04-10 01:08:49 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!left || (designator ? !ChkVariable(left) : !ChkExpression(left))) {
|
1986-04-10 01:08:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
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-07-30 13:37:39 +00:00
|
|
|
struct type *tp = BaseType(left->nd_type);
|
|
|
|
|
|
|
|
MkCoercion(&((*argp)->nd_left), tp);
|
|
|
|
left = (*argp)->nd_left;
|
|
|
|
if (!(tp->tp_fund & bases)) {
|
|
|
|
return (struct node *)Xerror(left, "unexpected parameter type", edf);
|
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
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC struct node *
|
1986-11-17 11:41:28 +00:00
|
|
|
getname(argp, kinds, bases, edf)
|
1986-05-30 18:48:00 +00:00
|
|
|
struct node **argp;
|
1986-11-17 11:41:28 +00:00
|
|
|
struct 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".
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node *left = nextarg(argp, edf);
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!left || ! ChkDesignator(left)) return 0;
|
1986-11-26 16:40:45 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (left->nd_class != Def) {
|
|
|
|
return (struct node *)Xerror(left, "identifier expected", edf);
|
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))) {
|
|
|
|
return (struct node *)Xerror(left, "unexpected parameter type", edf);
|
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
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkProcCall(expp)
|
1986-10-06 20:36:30 +00:00
|
|
|
struct node *expp;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
|
|
|
/* Check a procedure call
|
|
|
|
*/
|
|
|
|
register struct node *left;
|
1986-11-17 11:41:28 +00:00
|
|
|
struct def *edf = 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
register struct paramlist *param;
|
1986-11-17 11:41:28 +00:00
|
|
|
int retval = 1;
|
|
|
|
int cnt = 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
left = expp->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
|
|
|
|
*/
|
|
|
|
while (expp->nd_right) {
|
|
|
|
getarg(&expp, 0, 0, edf);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
expp->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
|
|
|
|
*/
|
1987-07-16 19:51:40 +00:00
|
|
|
for (param = ParamList(left->nd_type); param; param = param->par_next) {
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getarg(&expp, 0, IsVarParam(param), edf))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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),
|
1987-07-30 13:37:39 +00:00
|
|
|
&(expp->nd_left),
|
|
|
|
edf)) {
|
1986-11-17 11:41:28 +00:00
|
|
|
retval = 0;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
if (expp->nd_right) {
|
1986-11-17 11:41:28 +00:00
|
|
|
Xerror(expp->nd_right, "too many parameters supplied", edf);
|
1986-11-26 16:40:45 +00:00
|
|
|
while (expp->nd_right) {
|
|
|
|
getarg(&expp, 0, 0, edf);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
1987-05-18 15:57:33 +00:00
|
|
|
int
|
|
|
|
ChkFunCall(expp)
|
|
|
|
register struct node *expp;
|
|
|
|
{
|
|
|
|
/* Check a call that must have a result
|
|
|
|
*/
|
|
|
|
|
1987-08-03 09:09:07 +00:00
|
|
|
if (! ChkCall(expp)) return 0;
|
|
|
|
|
1987-05-18 15:57:33 +00:00
|
|
|
if (expp->nd_type == 0) {
|
|
|
|
node_error(expp, "function call expected");
|
|
|
|
expp->nd_type = error_type;
|
1987-08-03 09:09:07 +00:00
|
|
|
return 0;
|
1987-05-18 15:57:33 +00:00
|
|
|
}
|
1987-08-03 09:09:07 +00:00
|
|
|
return 1;
|
1987-05-18 15:57:33 +00:00
|
|
|
}
|
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkCall(expp)
|
1986-04-08 18:15:46 +00:00
|
|
|
register struct node *expp;
|
|
|
|
{
|
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.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node *left = expp->nd_left;
|
1986-07-10 16:27:26 +00:00
|
|
|
STATIC int ChkStandard();
|
|
|
|
STATIC int ChkCast();
|
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
|
|
|
|
*/
|
1986-11-17 13:08:18 +00:00
|
|
|
if (ChkDesignator(left)) {
|
|
|
|
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
|
|
|
|
1986-11-26 16:40:45 +00:00
|
|
|
if (IsProcCall(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
|
|
|
}
|
1986-11-17 13:08:18 +00:00
|
|
|
else node_error(left, "procedure, type, or function expected");
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
1986-11-17 13:08:18 +00:00
|
|
|
return ChkProcCall(expp);
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC struct type *
|
1986-06-06 02:22:09 +00:00
|
|
|
ResultOfOperation(operator, tp)
|
|
|
|
struct type *tp;
|
|
|
|
{
|
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
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkAddress(tpl, tpr)
|
1986-06-17 12:04:05 +00:00
|
|
|
register struct type *tpl, *tpr;
|
|
|
|
{
|
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
|
|
|
|
of type cardinal.
|
|
|
|
*/
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
if (tpl == address_type) {
|
1986-10-06 20:36:30 +00:00
|
|
|
return tpr == address_type || (tpr->tp_fund & T_CARDINAL);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tpr == address_type) {
|
1986-10-06 20:36:30 +00:00
|
|
|
return (tpl->tp_fund & T_CARDINAL);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkBinOper(expp)
|
1986-04-08 18:15:46 +00:00
|
|
|
register struct node *expp;
|
|
|
|
{
|
1986-04-10 01:08:49 +00:00
|
|
|
/* Check a binary operation.
|
1986-04-08 18:15:46 +00:00
|
|
|
*/
|
1986-06-10 13:18:52 +00:00
|
|
|
register struct node *left, *right;
|
1987-08-03 09:09:07 +00:00
|
|
|
register struct type *tpl, *tpr;
|
1986-06-06 02:22:09 +00:00
|
|
|
int allowed;
|
1986-11-17 11:41:28 +00:00
|
|
|
int retval;
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1986-06-10 13:18:52 +00:00
|
|
|
left = expp->nd_left;
|
|
|
|
right = expp->nd_right;
|
|
|
|
|
1986-11-17 11:41:28 +00:00
|
|
|
retval = ChkExpression(left) & ChkExpression(right);
|
1986-06-10 13:18:52 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
tpl = BaseType(left->nd_type);
|
|
|
|
tpr = BaseType(right->nd_type);
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
if (tpl == intorcard_type) {
|
|
|
|
if (tpr == int_type || tpr == card_type) {
|
1986-04-23 22:12:22 +00:00
|
|
|
left->nd_type = tpl = tpr;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tpr == intorcard_type) {
|
|
|
|
if (tpl == int_type || tpl == card_type) {
|
1986-04-23 22:12:22 +00:00
|
|
|
right->nd_type = tpr = tpl;
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
1986-06-06 02:22:09 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
expp->nd_type = ResultOfOperation(expp->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.
|
|
|
|
*/
|
1986-04-08 18:15:46 +00:00
|
|
|
if (expp->nd_symb == IN) {
|
1987-06-18 15:46:08 +00:00
|
|
|
if (tpr->tp_fund != T_SET) {
|
|
|
|
node_error(expp, "\"IN\": right operand must be a set");
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
node_error(left, "type incompatibility in IN");
|
1986-04-08 18:15:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(expp->nd_left), word_type);
|
|
|
|
left = expp->nd_left;
|
1986-04-23 22:12:22 +00:00
|
|
|
if (left->nd_class == Value && right->nd_class == Set) {
|
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;
|
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
allowed = AllowedTypes(expp->nd_symb);
|
1986-09-25 19:39:06 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
if (!(tpr->tp_fund & allowed) || !(tpl->tp_fund & allowed)) {
|
|
|
|
if (!((T_CARDINAL & allowed) &&
|
|
|
|
ChkAddress(tpl, tpr))) {
|
1986-11-17 11:41:28 +00:00
|
|
|
node_error(expp, "\"%s\": illegal operand type(s)",
|
|
|
|
symbol2str(expp->nd_symb));
|
1986-10-06 20:36:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (expp->nd_type->tp_fund & T_CARDINAL) {
|
|
|
|
expp->nd_type = address_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
if (Boolean(expp->nd_symb) && tpl != bool_type) {
|
1986-11-17 11:41:28 +00:00
|
|
|
node_error(expp, "\"%s\": illegal operand type(s)",
|
|
|
|
symbol2str(expp->nd_symb));
|
1986-09-25 19:39:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
|
|
|
|
/* Operands must be compatible (distilled from Def 8.2)
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!TstCompat(tpr, tpl)) {
|
|
|
|
node_error(expp,"\"%s\": incompatible types",
|
|
|
|
symbol2str(expp->nd_symb));
|
1986-10-06 20:36:30 +00:00
|
|
|
return 0;
|
1986-06-06 02:22:09 +00:00
|
|
|
}
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(expp->nd_left), tpl);
|
|
|
|
MkCoercion(&(expp->nd_right), tpr);
|
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
if (tpl->tp_fund == T_SET) {
|
|
|
|
if (left->nd_class == Set && right->nd_class == Set) {
|
|
|
|
cstset(expp);
|
1986-04-08 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
1986-06-06 02:22:09 +00:00
|
|
|
else if ( tpl->tp_fund != T_REAL &&
|
|
|
|
left->nd_class == Value && right->nd_class == Value) {
|
|
|
|
cstbin(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)
|
1986-04-08 18:15:46 +00:00
|
|
|
register struct node *expp;
|
|
|
|
{
|
1986-04-10 01:08:49 +00:00
|
|
|
/* Check an unary operation.
|
1986-04-08 18:15:46 +00:00
|
|
|
*/
|
1986-04-28 18:06:58 +00:00
|
|
|
register struct node *right = expp->nd_right;
|
1986-06-10 13:18:52 +00:00
|
|
|
register struct type *tpr;
|
|
|
|
|
1986-07-10 16:27:26 +00:00
|
|
|
if (! ChkExpression(right)) return 0;
|
1986-10-06 20:36:30 +00:00
|
|
|
expp->nd_type = tpr = BaseType(right->nd_type);
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(expp->nd_right), tpr);
|
|
|
|
right = expp->nd_right;
|
|
|
|
|
1986-07-10 16:27:26 +00:00
|
|
|
if (tpr == address_type) tpr = card_type;
|
1986-04-08 18:15:46 +00:00
|
|
|
|
|
|
|
switch(expp->nd_symb) {
|
|
|
|
case '+':
|
1987-06-18 15:46:08 +00:00
|
|
|
if (!(tpr->tp_fund & T_NUMERIC)) break;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case '(':
|
|
|
|
*expp = *right;
|
|
|
|
free_node(right);
|
|
|
|
return 1;
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
case '-':
|
1986-04-11 11:57:19 +00:00
|
|
|
if (tpr->tp_fund & T_INTORCARD) {
|
1987-05-27 10:16:03 +00:00
|
|
|
if (tpr == intorcard_type || tpr == card_type) {
|
1986-05-14 09:03:51 +00:00
|
|
|
expp->nd_type = int_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;
|
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) {
|
1986-06-04 09:01:48 +00:00
|
|
|
if (*(right->nd_REL) == '-') (right->nd_REL)++;
|
|
|
|
else (right->nd_REL)--;
|
1986-05-28 18:36:51 +00:00
|
|
|
expp->nd_class = Value;
|
1986-06-04 09:01:48 +00:00
|
|
|
expp->nd_symb = REAL;
|
|
|
|
expp->nd_REL = right->nd_REL;
|
1986-04-28 18:06:58 +00:00
|
|
|
FreeNode(right);
|
1986-04-08 18:15:46 +00:00
|
|
|
expp->nd_right = 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
1986-04-18 17:53:47 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
case NOT:
|
|
|
|
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
|
|
|
}
|
1986-11-17 11:41:28 +00:00
|
|
|
node_error(expp, "\"%s\": illegal operand", symbol2str(expp->nd_symb));
|
1986-04-08 18:15:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC struct node *
|
1986-11-17 11:41:28 +00:00
|
|
|
getvariable(argp, edf)
|
1986-05-30 18:48:00 +00:00
|
|
|
struct node **argp;
|
1986-11-17 11:41:28 +00:00
|
|
|
struct 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".
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node *left = nextarg(argp, edf);
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!left || !ChkVariable(left)) return 0;
|
1986-10-06 20:36:30 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
return 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)
|
|
|
|
register struct node *expp;
|
1986-04-23 22:12:22 +00:00
|
|
|
{
|
|
|
|
/* Check a call of a standard procedure or function
|
|
|
|
*/
|
1986-05-30 18:48:00 +00:00
|
|
|
struct node *arg = expp;
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node *left = expp->nd_left;
|
|
|
|
register struct def *edf = left->nd_def;
|
|
|
|
int free_it = 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
assert(left->nd_class == Def);
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1987-08-03 09:09:07 +00:00
|
|
|
expp->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:
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getarg(&arg, T_NUMERIC, 0, edf))) return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(arg->nd_left), BaseType(left->nd_type));
|
|
|
|
left = arg->nd_left;
|
1986-04-23 22:12:22 +00:00
|
|
|
expp->nd_type = left->nd_type;
|
1986-06-04 09:01:48 +00:00
|
|
|
if (left->nd_class == Value &&
|
|
|
|
expp->nd_type->tp_fund != T_REAL) {
|
|
|
|
cstcall(expp, S_ABS);
|
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CAP:
|
|
|
|
expp->nd_type = char_type;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getarg(&arg, T_CHAR, 0, edf))) return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
if (left->nd_class == Value) cstcall(expp, S_CAP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CHR:
|
|
|
|
expp->nd_type = char_type;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(arg->nd_left), char_type);
|
|
|
|
free_it = 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:
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! getarg(&arg, T_INTORCARD, 0, edf)) return 0;
|
|
|
|
if (edf->df_value.df_stdname == S_FLOAT) {
|
|
|
|
MkCoercion(&(arg->nd_left), card_type);
|
|
|
|
}
|
|
|
|
MkCoercion(&(arg->nd_left),
|
|
|
|
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: {
|
|
|
|
struct type *tp;
|
1987-07-30 13:37:39 +00:00
|
|
|
struct type *s1, *s2, *d1, *d2;
|
1987-05-27 10:16:03 +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
|
|
|
}
|
|
|
|
|
|
|
|
if (!(left = getarg(&arg, 0, 0, edf))) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tp = BaseType(left->nd_type);
|
1987-07-30 13:37:39 +00:00
|
|
|
if (tp == s1) {
|
|
|
|
MkCoercion(&(arg->nd_left), d1);
|
|
|
|
}
|
|
|
|
else if (tp == s2) {
|
|
|
|
MkCoercion(&(arg->nd_left), d2);
|
|
|
|
}
|
1987-05-27 10:16:03 +00:00
|
|
|
else {
|
|
|
|
Xerror(left, "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:
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getarg(&arg, T_ARRAY|T_STRING|T_CHAR, 0, edf))) {
|
|
|
|
return 0;
|
|
|
|
}
|
1986-10-22 15:38:24 +00:00
|
|
|
if (left->nd_type->tp_fund == T_ARRAY) {
|
1986-06-26 09:39:36 +00:00
|
|
|
expp->nd_type = IndexType(left->nd_type);
|
1987-07-22 17:02:54 +00:00
|
|
|
if (! IsConformantArray(left->nd_type)) {
|
|
|
|
cstcall(expp, S_MAX);
|
|
|
|
}
|
1986-10-22 15:38:24 +00:00
|
|
|
break;
|
|
|
|
}
|
1986-11-17 11:41:28 +00:00
|
|
|
if (left->nd_symb != STRING) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(left,"array parameter expected", edf);
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
1986-11-17 11:41:28 +00:00
|
|
|
expp->nd_type = card_type;
|
1986-10-22 15:38:24 +00:00
|
|
|
expp->nd_class = Value;
|
1986-11-17 11:41:28 +00:00
|
|
|
/* Notice that we could disallow HIGH("") here by checking
|
|
|
|
that left->nd_type->tp_fund != T_CHAR || left->nd_INT != 0.
|
|
|
|
??? For the time being, we don't. !!!
|
|
|
|
Maybe the empty string should not be allowed at all.
|
|
|
|
*/
|
1986-10-22 15:38:24 +00:00
|
|
|
expp->nd_INT = left->nd_type->tp_fund == T_CHAR ? 0 :
|
|
|
|
left->nd_SLE - 1;
|
|
|
|
expp->nd_symb = INTEGER;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_MAX:
|
|
|
|
case S_MIN:
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getname(&arg, D_ISTYPE, T_DISCRETE, edf))) {
|
1986-06-17 12:04:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
expp->nd_type = left->nd_type;
|
1987-07-30 13:37:39 +00:00
|
|
|
cstcall(expp,edf->df_value.df_stdname);
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ODD:
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! (left = getarg(&arg, T_INTORCARD, 0, edf))) return 0;
|
|
|
|
MkCoercion(&(arg->nd_left), BaseType(left->nd_type));
|
1986-04-23 22:12:22 +00:00
|
|
|
expp->nd_type = bool_type;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (arg->nd_left->nd_class == Value) cstcall(expp, S_ODD);
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ORD:
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! getarg(&arg, T_DISCRETE, 0, edf)) return 0;
|
|
|
|
MkCoercion(&(arg->nd_left), card_type);
|
|
|
|
free_it = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
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;
|
1986-11-17 11:41:28 +00:00
|
|
|
node_warning(expp, W_OLDFASHIONED, "NEW and DISPOSE are obsolete");
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
1987-08-03 09:09:07 +00:00
|
|
|
expp->nd_type = 0;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (! (left = getvariable(&arg, edf))) return 0;
|
1986-06-20 14:36:49 +00:00
|
|
|
if (! (left->nd_type->tp_fund == T_POINTER)) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(left, "pointer variable expected", edf);
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
/* Now, make it look like a call to ALLOCATE or DEALLOCATE */
|
|
|
|
{
|
|
|
|
struct token dt;
|
|
|
|
struct node *nd;
|
|
|
|
|
1987-07-13 10:30:37 +00:00
|
|
|
dt.TOK_INT = PointedtoType(left->nd_type)->tp_size;
|
|
|
|
dt.tk_symb = INTEGER;
|
|
|
|
dt.tk_lineno = left->nd_lineno;
|
|
|
|
nd = MkLeaf(Value, &dt);
|
1986-06-20 14:36:49 +00:00
|
|
|
nd->nd_type = card_type;
|
1987-07-13 10:30:37 +00:00
|
|
|
dt.tk_symb = ',';
|
|
|
|
arg->nd_right = MkNode(Link, nd, NULLNODE, &dt);
|
1986-06-20 14:36:49 +00:00
|
|
|
/* Ignore other arguments to NEW and/or DISPOSE ??? */
|
|
|
|
|
|
|
|
FreeNode(expp->nd_left);
|
1987-07-13 10:30:37 +00:00
|
|
|
dt.tk_symb = IDENT;
|
|
|
|
dt.tk_lineno = expp->nd_left->nd_lineno;
|
1987-07-30 13:37:39 +00:00
|
|
|
dt.TOK_IDF = str2idf(edf->df_value.df_stdname==S_NEW ?
|
1986-06-20 14:36:49 +00:00
|
|
|
"ALLOCATE" : "DEALLOCATE", 0);
|
1987-07-13 10:30:37 +00:00
|
|
|
expp->nd_left = MkLeaf(Name, &dt);
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
1986-07-10 16:27:26 +00:00
|
|
|
return ChkCall(expp);
|
1986-06-20 14:36:49 +00:00
|
|
|
|
1986-04-23 22:12:22 +00:00
|
|
|
case S_TSIZE: /* ??? */
|
|
|
|
case S_SIZE:
|
|
|
|
expp->nd_type = intorcard_type;
|
1986-11-28 11:59:08 +00:00
|
|
|
if (!(left = getname(&arg,D_FIELD|D_VARIABLE|D_ISTYPE,0,edf))) {
|
1986-11-17 11:41:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-11-28 11:59:08 +00:00
|
|
|
if (! IsConformantArray(left->nd_type)) cstcall(expp, S_SIZE);
|
|
|
|
else node_warning(expp,
|
|
|
|
W_STRICT,
|
|
|
|
"%s on conformant array",
|
|
|
|
expp->nd_left->nd_def->df_idf->id_text);
|
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:
|
|
|
|
expp->nd_type = card_type;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (edf->df_value.df_stdname == S_TRUNCD) {
|
|
|
|
expp->nd_type = longint_type;
|
|
|
|
}
|
|
|
|
if (! getarg(&arg, T_REAL, 0, edf)) return 0;
|
|
|
|
MkCoercion(&(arg->nd_left), expp->nd_type);
|
|
|
|
free_it = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_VAL:
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getname(&arg, D_ISTYPE, T_DISCRETE, edf))) {
|
1986-04-23 22:12:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
expp->nd_type = left->nd_def->df_type;
|
1986-04-23 22:12:22 +00:00
|
|
|
expp->nd_right = arg->nd_right;
|
|
|
|
arg->nd_right = 0;
|
|
|
|
FreeNode(arg);
|
1986-05-30 18:48:00 +00:00
|
|
|
arg = expp;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0;
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(arg->nd_left), expp->nd_type);
|
|
|
|
free_it = 1;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ADR:
|
|
|
|
expp->nd_type = address_type;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! getarg(&arg, 0, 1, edf)) return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_DEC:
|
|
|
|
case S_INC:
|
|
|
|
expp->nd_type = 0;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (! (left = getvariable(&arg, edf))) return 0;
|
1986-05-30 18:48:00 +00:00
|
|
|
if (! (left->nd_type->tp_fund & T_DISCRETE)) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(left,"illegal parameter type", edf);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
if (arg->nd_right) {
|
1986-11-17 11:41:28 +00:00
|
|
|
if (! getarg(&arg, T_INTORCARD, 0, edf)) return 0;
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_HALT:
|
|
|
|
expp->nd_type = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_EXCL:
|
|
|
|
case S_INCL:
|
|
|
|
{
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct type *tp;
|
|
|
|
struct node *dummy;
|
1986-04-23 22:12:22 +00:00
|
|
|
|
|
|
|
expp->nd_type = 0;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (!(left = getvariable(&arg, edf))) return 0;
|
1986-05-30 18:48:00 +00:00
|
|
|
tp = left->nd_type;
|
1986-04-23 22:12:22 +00:00
|
|
|
if (tp->tp_fund != T_SET) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(arg, "SET parameter expected", edf);
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
if (!(dummy = getarg(&arg, 0, 0, edf))) return 0;
|
|
|
|
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;
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
MkCoercion(&(arg->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
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->nd_right) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(arg->nd_right, "too many parameters supplied", edf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free_it) {
|
|
|
|
FreeNode(expp->nd_left);
|
|
|
|
*expp = *(arg->nd_left);
|
|
|
|
arg->nd_left = 0;
|
|
|
|
FreeNode(arg);
|
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)
|
|
|
|
register struct 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.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct node *left = expp->nd_left;
|
1986-05-30 18:48:00 +00:00
|
|
|
register struct node *arg = expp->nd_right;
|
1987-07-30 13:37:39 +00:00
|
|
|
register struct type *lefttype = left->nd_type;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
if ((! arg) || arg->nd_right) {
|
1987-07-30 13:37:39 +00:00
|
|
|
return Xerror(expp, "type cast must have 1 parameter", left->nd_def);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
if (! ChkExpression(arg->nd_left)) return 0;
|
|
|
|
|
|
|
|
MkCoercion(&(arg->nd_left), BaseType(arg->nd_left->nd_type));
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1987-07-30 13:37:39 +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)) {
|
1986-11-17 11:41:28 +00:00
|
|
|
Xerror(expp, "unequal sizes in type cast", left->nd_def);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->nd_class == Value) {
|
|
|
|
FreeNode(left);
|
|
|
|
expp->nd_right->nd_left = 0;
|
|
|
|
FreeNode(expp->nd_right);
|
|
|
|
*expp = *arg;
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
expp->nd_type = lefttype;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
1986-06-04 09:01:48 +00:00
|
|
|
|
|
|
|
TryToString(nd, tp)
|
1986-12-01 10:06:53 +00:00
|
|
|
register struct node *nd;
|
1986-06-04 09:01:48 +00:00
|
|
|
struct type *tp;
|
|
|
|
{
|
1986-06-17 12:04:05 +00:00
|
|
|
/* Try a coercion from character constant to string.
|
|
|
|
*/
|
1987-07-30 13:37:39 +00:00
|
|
|
static char buf[2];
|
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);
|
|
|
|
nd->nd_token.tk_data.tk_str =
|
|
|
|
(struct string *) Malloc(sizeof(struct string));
|
1987-07-30 13:37:39 +00:00
|
|
|
nd->nd_STR = Salloc(buf, 2);
|
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)
|
|
|
|
struct node *expp;
|
|
|
|
{
|
|
|
|
node_error(expp, "designator expected");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
1986-11-17 11:41:28 +00:00
|
|
|
done_before()
|
1986-06-26 09:39:36 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
extern int NodeCrash();
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
int (*ExprChkTable[])() = {
|
1986-10-06 20:36:30 +00:00
|
|
|
#ifdef DEBUG
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkValue,
|
1986-10-06 20:36:30 +00:00
|
|
|
#else
|
|
|
|
done_before,
|
|
|
|
#endif
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkArr,
|
|
|
|
ChkBinOper,
|
|
|
|
ChkUnOper,
|
|
|
|
ChkArrow,
|
1987-05-18 15:57:33 +00:00
|
|
|
ChkFunCall,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkExLinkOrName,
|
1986-06-17 12:04:05 +00:00
|
|
|
NodeCrash,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkSet,
|
1986-06-17 12:04:05 +00:00
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkExLinkOrName,
|
1986-06-20 14:36:49 +00:00
|
|
|
NodeCrash
|
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,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkLinkOrName,
|
1986-06-26 09:39:36 +00:00
|
|
|
NodeCrash,
|
|
|
|
no_desig,
|
|
|
|
done_before,
|
|
|
|
NodeCrash,
|
1986-07-10 16:27:26 +00:00
|
|
|
ChkLinkOrName,
|
1986-06-26 09:39:36 +00:00
|
|
|
done_before
|
|
|
|
};
|