1987-03-10 17:51:10 +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".
|
|
|
|
*/
|
1986-03-10 13:07:55 +00:00
|
|
|
/* $Header$ */
|
|
|
|
/* EXPRESSION TREE HANDLING */
|
|
|
|
|
1986-09-24 13:53:16 +00:00
|
|
|
#include "nofloat.h"
|
|
|
|
#include "botch_free.h"
|
1987-01-24 00:25:56 +00:00
|
|
|
#include <alloc.h>
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "idf.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "label.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "decspecs.h"
|
1986-03-19 12:31:05 +00:00
|
|
|
#include "declar.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "sizes.h"
|
1986-04-02 08:37:17 +00:00
|
|
|
#include "level.h"
|
1987-03-25 23:14:43 +00:00
|
|
|
#include "noRoption.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
extern char *symbol2str();
|
|
|
|
extern char options[];
|
|
|
|
|
|
|
|
int
|
|
|
|
rank_of(oper)
|
|
|
|
int oper;
|
|
|
|
{
|
|
|
|
/* The rank of the operator oper is returned.
|
|
|
|
*/
|
|
|
|
switch (oper) {
|
|
|
|
default:
|
|
|
|
return 0; /* INT2INT etc. */
|
|
|
|
case '[':
|
|
|
|
case '(':
|
|
|
|
case '.':
|
|
|
|
case ARROW:
|
|
|
|
case PARCOMMA:
|
|
|
|
return 1;
|
|
|
|
case '!':
|
|
|
|
case PLUSPLUS:
|
|
|
|
case MINMIN:
|
|
|
|
case CAST:
|
|
|
|
case SIZEOF:
|
|
|
|
return 2; /* monadic */
|
|
|
|
case '*':
|
|
|
|
case '/':
|
|
|
|
case '%':
|
|
|
|
return 3;
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
return 4;
|
|
|
|
case LEFT:
|
|
|
|
case RIGHT:
|
|
|
|
return 5;
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
case LESSEQ:
|
|
|
|
case GREATEREQ:
|
|
|
|
return 6;
|
|
|
|
case EQUAL:
|
|
|
|
case NOTEQUAL:
|
|
|
|
return 7;
|
|
|
|
case '&':
|
|
|
|
return 8;
|
|
|
|
case '^':
|
|
|
|
return 9;
|
|
|
|
case '|':
|
|
|
|
return 10;
|
|
|
|
case AND:
|
|
|
|
return 11;
|
|
|
|
case OR:
|
|
|
|
return 12;
|
|
|
|
case '?':
|
|
|
|
case ':':
|
|
|
|
return 13;
|
|
|
|
case '=':
|
|
|
|
case PLUSAB:
|
|
|
|
case MINAB:
|
|
|
|
case TIMESAB:
|
|
|
|
case DIVAB:
|
|
|
|
case MODAB:
|
|
|
|
case RIGHTAB:
|
|
|
|
case LEFTAB:
|
|
|
|
case ANDAB:
|
|
|
|
case XORAB:
|
|
|
|
case ORAB:
|
|
|
|
return 14;
|
|
|
|
case ',':
|
|
|
|
return 15;
|
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
1987-03-25 23:14:43 +00:00
|
|
|
#ifndef NOROPTION
|
1986-03-10 13:07:55 +00:00
|
|
|
int
|
1986-09-29 14:01:34 +00:00
|
|
|
rank_of_expression(ex)
|
|
|
|
register struct expr *ex;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* Returns the rank of the top node in the expression.
|
|
|
|
*/
|
1986-09-29 14:01:34 +00:00
|
|
|
if (!ex || (ex->ex_flags & EX_PARENS) || ex->ex_class != Oper)
|
1986-03-10 13:07:55 +00:00
|
|
|
return 0;
|
1986-09-29 14:01:34 +00:00
|
|
|
return rank_of(ex->OP_OPER);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_conditional(expr, oper, pos_descr)
|
1987-02-09 23:19:42 +00:00
|
|
|
register struct expr *expr;
|
1986-03-10 13:07:55 +00:00
|
|
|
char *pos_descr;
|
|
|
|
{
|
|
|
|
/* Warn if restricted C is in effect and the expression expr,
|
|
|
|
which occurs at the position pos_descr, is not lighter than
|
|
|
|
the operator oper.
|
|
|
|
*/
|
|
|
|
if (options['R'] && rank_of_expression(expr) >= rank_of(oper))
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(expr, "%s %s is ungrammatical",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(expr->OP_OPER), pos_descr);
|
|
|
|
}
|
1987-03-25 23:14:43 +00:00
|
|
|
#endif
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
dot2expr(expp)
|
1987-02-09 23:19:42 +00:00
|
|
|
struct expr **expp;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* The token in dot is converted into an expression, a
|
|
|
|
pointer to which is stored in *expp.
|
|
|
|
*/
|
1987-02-09 23:19:42 +00:00
|
|
|
register struct expr *ex = new_expr();
|
|
|
|
|
|
|
|
*expp = ex;
|
|
|
|
ex->ex_file = dot.tk_file;
|
|
|
|
ex->ex_line = dot.tk_line;
|
1986-03-10 13:07:55 +00:00
|
|
|
switch (DOT) {
|
|
|
|
case IDENTIFIER:
|
1987-02-09 23:19:42 +00:00
|
|
|
idf2expr(ex);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case STRING:
|
1987-02-09 23:19:42 +00:00
|
|
|
string2expr(ex);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case INTEGER:
|
1987-02-09 23:19:42 +00:00
|
|
|
int2expr(ex);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case FLOATING:
|
1987-02-09 23:19:42 +00:00
|
|
|
float2expr(ex);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
|
|
|
crash("bad conversion to expression");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
idf2expr(expr)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* Dot contains an identifier which is turned into an
|
|
|
|
expression.
|
|
|
|
Note that this constitutes an applied occurrence of
|
|
|
|
the identifier.
|
|
|
|
*/
|
|
|
|
register struct idf *idf = dot.tk_idf; /* != 0*/
|
|
|
|
register struct def *def = idf->id_def;
|
|
|
|
|
|
|
|
if (def == 0) {
|
1986-09-29 14:01:34 +00:00
|
|
|
if (AHEAD == '(') /* function call, declare name IMPLICITly */
|
|
|
|
add_def(idf, IMPLICIT, funint_type, level); /* RM 13 */
|
1986-03-10 13:07:55 +00:00
|
|
|
else {
|
|
|
|
if (!is_anon_idf(idf))
|
|
|
|
error("%s undefined", idf->id_text);
|
1986-09-29 14:01:34 +00:00
|
|
|
/* declare idf anyway */
|
1986-03-10 13:07:55 +00:00
|
|
|
add_def(idf, 0, error_type, level);
|
|
|
|
}
|
|
|
|
def = idf->id_def;
|
|
|
|
}
|
|
|
|
/* now def != 0 */
|
|
|
|
if (def->df_type->tp_fund == LABEL) {
|
1986-03-27 18:17:48 +00:00
|
|
|
expr_error(expr, "illegal use of label %s", idf->id_text);
|
1986-09-02 15:22:54 +00:00
|
|
|
expr->ex_type = error_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
def->df_used = 1;
|
|
|
|
expr->ex_type = def->df_type;
|
1986-03-27 18:17:48 +00:00
|
|
|
if (expr->ex_type == error_type)
|
|
|
|
expr->ex_flags |= EX_ERROR;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
expr->ex_lvalue =
|
|
|
|
( def->df_type->tp_fund == FUNCTION ||
|
|
|
|
def->df_type->tp_fund == ARRAY ||
|
|
|
|
def->df_sc == ENUM
|
|
|
|
) ? 0 : 1;
|
|
|
|
expr->ex_class = Value;
|
|
|
|
if (def->df_sc == ENUM) {
|
1986-04-02 08:37:17 +00:00
|
|
|
expr->VL_CLASS = Const;
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->VL_VALUE = def->df_address;
|
|
|
|
}
|
1986-04-02 08:37:17 +00:00
|
|
|
else
|
|
|
|
if (def->df_sc == STATIC && def->df_level >= L_LOCAL) {
|
|
|
|
expr->VL_CLASS = Label;
|
|
|
|
expr->VL_LBL = def->df_address;
|
|
|
|
expr->VL_VALUE = (arith)0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
expr->VL_CLASS = Name;
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->VL_IDF = idf;
|
|
|
|
expr->VL_VALUE = (arith)0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string2expr(expr)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* Dot contains a string which is turned into an expression.
|
|
|
|
*/
|
|
|
|
expr->ex_type = string_type;
|
|
|
|
expr->ex_lvalue = 0;
|
|
|
|
expr->ex_class = String;
|
1986-03-25 16:40:43 +00:00
|
|
|
expr->SG_VALUE = dot.tk_bts;
|
|
|
|
expr->SG_LEN = dot.tk_len;
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->SG_DATLAB = 0;
|
|
|
|
}
|
|
|
|
|
1986-07-18 21:10:42 +00:00
|
|
|
int2expr(expr)
|
|
|
|
struct expr *expr;
|
|
|
|
{
|
|
|
|
/* Dot contains an integer constant which is turned
|
|
|
|
into an expression.
|
|
|
|
*/
|
|
|
|
fill_int_expr(expr, dot.tk_ival, dot.tk_fund);
|
|
|
|
}
|
|
|
|
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-07-18 21:10:42 +00:00
|
|
|
float2expr(expr)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr;
|
1986-07-18 21:10:42 +00:00
|
|
|
{
|
|
|
|
/* Dot contains a floating point constant which is turned
|
|
|
|
into an expression.
|
|
|
|
*/
|
|
|
|
expr->ex_type = double_type;
|
|
|
|
expr->ex_class = Float;
|
|
|
|
expr->FL_VALUE = dot.tk_fval;
|
|
|
|
expr->FL_DATLAB = 0;
|
|
|
|
}
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-07-18 21:10:42 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
struct expr*
|
|
|
|
intexpr(ivalue, fund)
|
|
|
|
arith ivalue;
|
1986-09-24 13:53:16 +00:00
|
|
|
int fund;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* The value ivalue is turned into an integer expression of
|
|
|
|
the size indicated by fund.
|
|
|
|
*/
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr = new_expr();
|
1986-03-14 16:15:16 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->ex_file = dot.tk_file;
|
|
|
|
expr->ex_line = dot.tk_line;
|
1986-07-18 21:10:42 +00:00
|
|
|
fill_int_expr(expr, ivalue, fund);
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
fill_int_expr(ex, ivalue, fund)
|
|
|
|
register struct expr *ex;
|
1986-07-18 21:10:42 +00:00
|
|
|
arith ivalue;
|
1986-09-24 13:53:16 +00:00
|
|
|
int fund;
|
1986-07-18 21:10:42 +00:00
|
|
|
{
|
|
|
|
/* Details derived from ivalue and fund are put into the
|
1986-09-29 14:01:34 +00:00
|
|
|
constant integer expression ex.
|
1986-07-18 21:10:42 +00:00
|
|
|
*/
|
1986-03-10 13:07:55 +00:00
|
|
|
switch (fund) {
|
|
|
|
case INT:
|
1986-09-29 14:01:34 +00:00
|
|
|
ex->ex_type = int_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1988-07-07 15:02:47 +00:00
|
|
|
case INTEGER:
|
|
|
|
if (ivalue >= 0 && ivalue <= max_int) {
|
|
|
|
ex->ex_type = int_type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*FALL THROUGH*/
|
1986-03-10 13:07:55 +00:00
|
|
|
case LONG:
|
1987-12-03 11:12:02 +00:00
|
|
|
ex->ex_type =
|
|
|
|
(ivalue & (1L << (8*long_size - 1))) ? ulong_type
|
|
|
|
: long_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case UNSIGNED:
|
1986-03-17 17:47:04 +00:00
|
|
|
/* We cannot make a test like
|
|
|
|
ivalue <= max_unsigned
|
|
|
|
because, if
|
|
|
|
sizeof(long) == int_size
|
|
|
|
holds, max_unsigned may be a negative long in
|
|
|
|
which case the comparison results in an unexpected
|
|
|
|
answer. We assume that the type "unsigned long"
|
|
|
|
is not part of portable C !
|
1986-03-10 13:07:55 +00:00
|
|
|
*/
|
1987-12-03 11:12:02 +00:00
|
|
|
ex->ex_type =
|
|
|
|
(ivalue & ~max_int) ?
|
|
|
|
( (ivalue & ~max_unsigned) ?
|
|
|
|
( ivalue & (1L<<(8*long_size-1)) ?
|
|
|
|
ulong_type : long_type
|
|
|
|
) : uint_type
|
|
|
|
) : int_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("(intexpr) bad fund %s\n", symbol2str(fund));
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
ex->ex_class = Value;
|
|
|
|
ex->VL_CLASS = Const;
|
|
|
|
ex->VL_VALUE = ivalue;
|
|
|
|
cut_size(ex);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct expr *
|
|
|
|
new_oper(tp, e1, oper, e2)
|
|
|
|
struct type *tp;
|
1987-02-09 23:19:42 +00:00
|
|
|
register struct expr *e1, *e2;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* A new expression is constructed which consists of the
|
|
|
|
operator oper which has e1 and e2 as operands; for a
|
|
|
|
monadic operator e1 == NILEXPR.
|
|
|
|
During the construction of the right recursive initialisation
|
|
|
|
tree it is possible for e2 to be NILEXPR.
|
|
|
|
*/
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr = new_expr();
|
|
|
|
register struct oper *op;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-03-14 16:15:16 +00:00
|
|
|
if (e2) {
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *e = e2;
|
1986-03-14 16:15:16 +00:00
|
|
|
|
|
|
|
while (e->ex_class == Oper && e->OP_LEFT)
|
|
|
|
e = e->OP_LEFT;
|
|
|
|
expr->ex_file = e->ex_file;
|
|
|
|
expr->ex_line = e->ex_line;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (e1) {
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *e = e1;
|
1986-03-14 16:15:16 +00:00
|
|
|
|
|
|
|
while (e->ex_class == Oper && e->OP_RIGHT)
|
|
|
|
e = e->OP_RIGHT;
|
|
|
|
expr->ex_file = e->ex_file;
|
|
|
|
expr->ex_line = e->ex_line;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else {
|
1986-03-14 16:15:16 +00:00
|
|
|
expr->ex_file = dot.tk_file;
|
|
|
|
expr->ex_line = dot.tk_line;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
expr->ex_type = tp;
|
|
|
|
expr->ex_class = Oper;
|
|
|
|
/* combine depths and flags of both expressions */
|
|
|
|
if (e2) {
|
|
|
|
int e1_depth = e1 ? e1->ex_depth : 0;
|
|
|
|
int e1_flags = e1 ? e1->ex_flags : 0;
|
|
|
|
|
|
|
|
expr->ex_depth =
|
1986-09-29 14:01:34 +00:00
|
|
|
(e1_depth > e2->ex_depth ? e1_depth : e2->ex_depth) + 1;
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->ex_flags = (e1_flags | e2->ex_flags) & ~EX_PARENS;
|
|
|
|
}
|
|
|
|
op = &expr->ex_object.ex_oper;
|
|
|
|
op->op_type = tp;
|
|
|
|
op->op_oper = oper;
|
|
|
|
op->op_left = e1;
|
|
|
|
op->op_right = e2;
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
chk_cst_expr(expp)
|
|
|
|
register struct expr **expp;
|
|
|
|
{
|
|
|
|
/* The expression expr is checked for constancy.
|
|
|
|
|
|
|
|
There are 6 places where constant expressions occur in C:
|
|
|
|
1. after #if
|
|
|
|
2. in a global initialization
|
|
|
|
3. as size in an array declaration
|
|
|
|
4. as value in an enum declaration
|
|
|
|
5. as width in a bit field
|
|
|
|
6. as case value in a switch
|
|
|
|
|
|
|
|
The constant expression in a global initialization is
|
|
|
|
handled separately (by IVAL()).
|
|
|
|
|
|
|
|
There are various disparate restrictions on each of
|
|
|
|
the others in the various C compilers. I have tried some
|
|
|
|
hypotheses to unify them, but all have failed.
|
|
|
|
|
|
|
|
This routine will give a warning for those operators
|
|
|
|
not allowed by K&R, under the R-option only. The anomalies
|
|
|
|
are cast, logical operators and the expression comma.
|
|
|
|
Special problems (of which there is only one, sizeof in
|
|
|
|
Preprocessor #if) have to be dealt with locally
|
1986-03-14 16:15:16 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
Note that according to K&R the negation ! is illegal in
|
|
|
|
constant expressions and is indeed rejected by the
|
|
|
|
Ritchie compiler.
|
|
|
|
*/
|
|
|
|
register struct expr *expr = *expp;
|
|
|
|
register int fund = expr->ex_type->tp_fund;
|
|
|
|
register int flags = expr->ex_flags;
|
1986-09-24 13:53:16 +00:00
|
|
|
int err = 0;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
print_expr("constant_expression", expr);
|
|
|
|
#endif DEBUG
|
|
|
|
if ( fund != CHAR && fund != SHORT && fund != INT &&
|
|
|
|
fund != ENUM && fund != LONG
|
1986-09-29 14:01:34 +00:00
|
|
|
)
|
1986-03-10 13:07:55 +00:00
|
|
|
expr_error(expr, "non-numerical constant expression"), err++;
|
|
|
|
else
|
|
|
|
if (!is_ld_cst(expr))
|
|
|
|
expr_error(expr, "expression is not constant"), err++;
|
1987-03-25 23:14:43 +00:00
|
|
|
#ifndef NOROPTION
|
1986-03-10 13:07:55 +00:00
|
|
|
if (options['R']) {
|
|
|
|
if (flags & EX_CAST)
|
1986-09-29 14:01:34 +00:00
|
|
|
expr_warning(expr, "cast in constant expression");
|
1986-03-10 13:07:55 +00:00
|
|
|
if (flags & EX_LOGICAL)
|
|
|
|
expr_warning(expr,
|
|
|
|
"logical operator in constant expression");
|
|
|
|
if (flags & EX_COMMA)
|
|
|
|
expr_warning(expr,
|
|
|
|
"expression comma in constant expression");
|
|
|
|
}
|
1987-03-25 23:14:43 +00:00
|
|
|
#endif NOROPTION
|
1986-09-12 09:16:07 +00:00
|
|
|
if (err)
|
1986-03-14 16:15:16 +00:00
|
|
|
erroneous2int(expp);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init_expression(eppp, expr)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr ***eppp, *expr;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* The expression expr is added to the tree designated
|
|
|
|
indirectly by **eppp.
|
|
|
|
The natural form of a tree representing an
|
|
|
|
initial_value_list is right-recursive, ie. with the
|
|
|
|
left-most comma as main operator. The iterative grammar in
|
|
|
|
expression.g, however, tends to produce a left-recursive
|
|
|
|
tree, ie. one with the right-most comma as its main
|
|
|
|
operator.
|
|
|
|
To produce a right-recursive tree from the iterative
|
|
|
|
grammar, we keep track of the address of the pointer where
|
|
|
|
the next expression must be hooked in.
|
|
|
|
*/
|
|
|
|
**eppp = new_oper(void_type, expr, INITCOMMA, NILEXPR);
|
|
|
|
*eppp = &(**eppp)->OP_RIGHT;
|
|
|
|
}
|
|
|
|
|
1986-03-14 16:15:16 +00:00
|
|
|
int
|
|
|
|
is_ld_cst(expr)
|
|
|
|
register struct expr *expr;
|
|
|
|
{
|
|
|
|
/* An expression is a `load-time constant' if it is of the form
|
|
|
|
<idf> +/- <integral> or <integral>.
|
|
|
|
*/
|
|
|
|
return expr->ex_lvalue == 0 && expr->ex_class == Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
is_cp_cst(expr)
|
|
|
|
register struct expr *expr;
|
|
|
|
{
|
|
|
|
/* An expression is a `compile-time constant' if it is a
|
|
|
|
load-time constant, and the idf is not there.
|
|
|
|
*/
|
1986-04-02 08:37:17 +00:00
|
|
|
return is_ld_cst(expr) && expr->VL_CLASS == Const;
|
1986-03-14 16:15:16 +00:00
|
|
|
}
|
|
|
|
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-14 16:15:16 +00:00
|
|
|
int
|
|
|
|
is_fp_cst(expr)
|
|
|
|
register struct expr *expr;
|
|
|
|
{
|
|
|
|
/* An expression is a `floating-point constant' if it consists
|
|
|
|
of the float only.
|
|
|
|
*/
|
|
|
|
return expr->ex_class == Float;
|
|
|
|
}
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-14 16:15:16 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
free_expression(expr)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* The expression expr is freed recursively.
|
|
|
|
*/
|
1986-09-29 14:01:34 +00:00
|
|
|
if (expr) {
|
|
|
|
if (expr->ex_class == Oper) {
|
|
|
|
free_expression(expr->OP_LEFT);
|
|
|
|
free_expression(expr->OP_RIGHT);
|
|
|
|
}
|
|
|
|
free_expr(expr);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|