1989-09-25 14:28: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".
|
|
|
|
*/
|
1994-06-27 08:03:14 +00:00
|
|
|
/* $Id$ */
|
1989-09-25 14:28:10 +00:00
|
|
|
/* S E M A N T I C A N A L Y S I S -- C H A P T E R 3.3 */
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
#include <assert.h>
|
2013-05-12 19:45:55 +00:00
|
|
|
#include "parameters.h"
|
1989-09-25 14:28:10 +00:00
|
|
|
#include <flt_arith.h>
|
|
|
|
#include "arith.h"
|
2019-02-18 16:42:15 +00:00
|
|
|
#include "ch3.h"
|
2013-05-12 19:45:55 +00:00
|
|
|
#include "idf.h"
|
1989-09-25 14:28:10 +00:00
|
|
|
#include "proto.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "struct.h"
|
|
|
|
#include "label.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "Lpars.h"
|
2019-02-18 16:42:15 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "ch3bin.h"
|
1989-09-25 14:28:10 +00:00
|
|
|
#include "file_info.h"
|
|
|
|
|
|
|
|
extern char options[];
|
|
|
|
extern char *symbol2str();
|
|
|
|
extern struct type *qualifier_type();
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
|
1989-09-25 14:28:10 +00:00
|
|
|
/* Most expression-handling routines have a pointer to a
|
|
|
|
(struct type *) as first parameter. The object under the pointer
|
|
|
|
gets updated in the process.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
void ch3sel(struct expr **expp, int oper, struct idf *idf)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
/* The selector idf is applied to *expp; oper may be '.' or
|
|
|
|
ARROW.
|
|
|
|
*/
|
|
|
|
register struct expr *exp;
|
|
|
|
register struct type *tp;
|
|
|
|
register struct sdef *sd;
|
|
|
|
|
|
|
|
any2opnd(expp, oper);
|
|
|
|
exp = *expp;
|
|
|
|
tp = exp->ex_type;
|
|
|
|
if (oper == ARROW) {
|
|
|
|
if (tp->tp_fund == POINTER &&
|
|
|
|
( tp->tp_up->tp_fund == STRUCT ||
|
|
|
|
tp->tp_up->tp_fund == UNION)) /* normal case */
|
|
|
|
tp = tp->tp_up;
|
|
|
|
else { /* constructions like "12->selector" and
|
|
|
|
"char c; c->selector"
|
|
|
|
*/
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case POINTER:
|
|
|
|
break;
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
Begin to add `long long` to C compiler for linux386.
Add long long type, but without literals; you can't say '123LL' yet.
You can try constant operations, like `(long long)123 + 1`, but the
compiler's `arith` type might not be wide enough. Conversions,
shifts, and some other operations don't work in i386 ncg; I am using a
union instead of conversions:
union q {
long long ll;
unsigned long long ull;
int i[2];
};
Hack plat/linux386/descr to enable long long (size 8, alignment 4)
only for this platform. The default for other platforms is to disable
long long (size -1).
In lang/cem/cemcom.ansi,
- BigPars, SmallPars: Add default size, alignment of long long.
- align.h: Add lnglng_align.
- arith.c: Convert arithmetic operands to long long or unsigned long
long when necessary; avoid conversion from long long to long.
Allow long long as an arithmetic, integral, or logical operand.
- ch3.c: Handle long long like int and long when erroneously applying
a selector, like `long long ll; ll.member` or `ll->member`. Add
long long to integral and arithmetic types.
- code.c: Add long long to type stabs for debugging.
- conversion.c: Add long long to integral conversions.
- cstoper.c: Write masks up to full_mask[8]. Add FIXME comment.
- declar.g: Parse `long long` in code.
- decspecs.c: Understand long long in type declarations.
- eval.c: Add long long to operations, to generate code like `adi 8`.
Don't use `ldc` with constant over 4 bytes.
- ival.g: Allow long long in initializations.
- main.c: Set lnglng_type and related values.
- options.c: Add option like `-Vq8.4` to set long long to size 8,
alignment 4. I chose 'q', because Perl's pack and Ruby's
Array#pack use 'q' for 64-bit or long long values; it might be a
reference to BSD's old quad_t alias for long long.
- sizes.h: Add lnglng_size.
- stab.c: Allow long long when writing the type stab for debugging.
Switch from calculating the ranges to hardcoding them in strings;
add 8-byte ranges as a special case. This also hardcodes the
unsigned 4-byte range as "0;-1". Before it was either "0;-1" or
"0;4294967295", depending on sizeof(long) in the compiler.
- struct.c: Try long long bitfield, but it will probably give the
error, "bit field type long long does not fit in a word".
- switch.c: Update comment.
- tokenname.c: Define LNGLNG (long long) like LNGDBL (long double).
- type.c, type.str: Add lnglng_type and ulnglng_type. Add function
no_long_long() to check if long long is disabled.
2019-09-02 15:24:44 +00:00
|
|
|
case LNGLNG:
|
1989-09-25 14:28:10 +00:00
|
|
|
/* An error is given in idf2sdef() */
|
|
|
|
ch3cast(expp, CAST, pa_type);
|
|
|
|
sd = idf2sdef(idf, tp);
|
|
|
|
tp = sd->sd_stype;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
expr_error(exp, "-> applied to %s",
|
|
|
|
symbol2str(tp->tp_fund));
|
|
|
|
case ERRONEOUS:
|
|
|
|
exp->ex_type = error_type;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* oper == '.' */
|
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
exp = *expp;
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case POINTER: /* for int *p; p->next = ... */
|
|
|
|
case STRUCT:
|
|
|
|
case UNION:
|
|
|
|
break;
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
Begin to add `long long` to C compiler for linux386.
Add long long type, but without literals; you can't say '123LL' yet.
You can try constant operations, like `(long long)123 + 1`, but the
compiler's `arith` type might not be wide enough. Conversions,
shifts, and some other operations don't work in i386 ncg; I am using a
union instead of conversions:
union q {
long long ll;
unsigned long long ull;
int i[2];
};
Hack plat/linux386/descr to enable long long (size 8, alignment 4)
only for this platform. The default for other platforms is to disable
long long (size -1).
In lang/cem/cemcom.ansi,
- BigPars, SmallPars: Add default size, alignment of long long.
- align.h: Add lnglng_align.
- arith.c: Convert arithmetic operands to long long or unsigned long
long when necessary; avoid conversion from long long to long.
Allow long long as an arithmetic, integral, or logical operand.
- ch3.c: Handle long long like int and long when erroneously applying
a selector, like `long long ll; ll.member` or `ll->member`. Add
long long to integral and arithmetic types.
- code.c: Add long long to type stabs for debugging.
- conversion.c: Add long long to integral conversions.
- cstoper.c: Write masks up to full_mask[8]. Add FIXME comment.
- declar.g: Parse `long long` in code.
- decspecs.c: Understand long long in type declarations.
- eval.c: Add long long to operations, to generate code like `adi 8`.
Don't use `ldc` with constant over 4 bytes.
- ival.g: Allow long long in initializations.
- main.c: Set lnglng_type and related values.
- options.c: Add option like `-Vq8.4` to set long long to size 8,
alignment 4. I chose 'q', because Perl's pack and Ruby's
Array#pack use 'q' for 64-bit or long long values; it might be a
reference to BSD's old quad_t alias for long long.
- sizes.h: Add lnglng_size.
- stab.c: Allow long long when writing the type stab for debugging.
Switch from calculating the ranges to hardcoding them in strings;
add 8-byte ranges as a special case. This also hardcodes the
unsigned 4-byte range as "0;-1". Before it was either "0;-1" or
"0;4294967295", depending on sizeof(long) in the compiler.
- struct.c: Try long long bitfield, but it will probably give the
error, "bit field type long long does not fit in a word".
- switch.c: Update comment.
- tokenname.c: Define LNGLNG (long long) like LNGDBL (long double).
- type.c, type.str: Add lnglng_type and ulnglng_type. Add function
no_long_long() to check if long long is disabled.
2019-09-02 15:24:44 +00:00
|
|
|
case LNGLNG:
|
1989-09-25 14:28:10 +00:00
|
|
|
/* warning will be given by idf2sdef() */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!is_anon_idf(idf))
|
|
|
|
expr_error(exp, "selector %s applied to %s",
|
|
|
|
idf->id_text, symbol2str(tp->tp_fund));
|
|
|
|
case ERRONEOUS:
|
|
|
|
exp->ex_type = error_type;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sd = idf2sdef(idf, tp);
|
|
|
|
if (oper == '.') {
|
|
|
|
/* there are 3 cases in which the selection can be
|
|
|
|
performed compile-time:
|
|
|
|
I: n.sel (n either an identifier or a constant)
|
|
|
|
II: (e.s1).s2 (transformed into (e.(s1+s2)))
|
|
|
|
III: (e->s1).s2 (transformed into (e->(s1+s2)))
|
|
|
|
The code performing these conversions is
|
|
|
|
extremely obscure.
|
|
|
|
*/
|
|
|
|
if (exp->ex_class == Value) {
|
|
|
|
/* It is an object we know the address of; so
|
|
|
|
we can calculate the address of the
|
|
|
|
selected member
|
|
|
|
*/
|
|
|
|
exp->VL_VALUE += sd->sd_offset;
|
|
|
|
exp->ex_type = sd->sd_type;
|
|
|
|
exp->ex_lvalue = exp->ex_type->tp_fund != ARRAY;
|
|
|
|
if (exp->ex_type == error_type) {
|
|
|
|
exp->ex_flags |= EX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (exp->ex_class == Oper) {
|
|
|
|
struct oper *op = &(exp->ex_object.ex_oper);
|
|
|
|
|
|
|
|
if (op->op_oper == '.' || op->op_oper == ARROW) {
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(is_cp_cst(op->op_right));
|
1989-09-25 14:28:10 +00:00
|
|
|
op->op_right->VL_VALUE += sd->sd_offset;
|
|
|
|
exp->ex_type = sd->sd_type;
|
|
|
|
exp->ex_lvalue = exp->ex_type->tp_fund != ARRAY;
|
|
|
|
if (exp->ex_type == error_type) {
|
|
|
|
exp->ex_flags |= EX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exp = new_oper(sd->sd_type, exp, '.',
|
|
|
|
intexpr(sd->sd_offset, INT));
|
|
|
|
exp->ex_lvalue = sd->sd_type->tp_fund != ARRAY;
|
|
|
|
if (!exp->OP_LEFT->ex_lvalue)
|
|
|
|
exp->ex_flags |= EX_ILVALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* oper == ARROW */
|
1990-03-29 10:41:46 +00:00
|
|
|
if (is_ld_cst(exp)) {
|
|
|
|
exp->VL_VALUE += sd->sd_offset;
|
|
|
|
exp->ex_type = sd->sd_type;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exp = new_oper(sd->sd_type,
|
|
|
|
exp, oper, intexpr(sd->sd_offset, INT));
|
|
|
|
}
|
1989-09-25 14:28:10 +00:00
|
|
|
exp->ex_lvalue = (sd->sd_type->tp_fund != ARRAY);
|
|
|
|
exp->ex_flags &= ~EX_ILVALUE;
|
|
|
|
}
|
1991-06-13 15:56:14 +00:00
|
|
|
if ((sd->sd_type->tp_typequal & TQ_CONST)
|
|
|
|
|| (tp->tp_typequal & TQ_CONST))
|
1989-09-25 14:28:10 +00:00
|
|
|
exp->ex_flags |= EX_READONLY;
|
1991-06-13 15:56:14 +00:00
|
|
|
if ((sd->sd_type->tp_typequal & TQ_VOLATILE)
|
|
|
|
|| (tp->tp_typequal & TQ_VOLATILE))
|
1989-09-25 14:28:10 +00:00
|
|
|
exp->ex_flags |= EX_VOLATILE;
|
|
|
|
if (oper == '.' && exp->ex_flags & EX_READONLY) {
|
|
|
|
exp->ex_type = qualifier_type(exp->ex_type, TQ_CONST);
|
|
|
|
}
|
1990-04-02 15:57:51 +00:00
|
|
|
if (exp->ex_flags & EX_VOLATILE) {
|
|
|
|
exp->ex_type = qualifier_type(exp->ex_type, TQ_VOLATILE);
|
|
|
|
}
|
1989-09-25 14:28:10 +00:00
|
|
|
*expp = exp;
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
void ch3incr(struct expr **expp, int oper)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
/* The monadic prefix/postfix incr/decr operator oper is
|
|
|
|
applied to *expp.
|
|
|
|
*/
|
|
|
|
ch3asgn(expp, oper, intexpr((arith)1, INT));
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
void ch3cast(register struct expr **expp, int oper, register struct type *tp)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
/* The expression *expp is cast to type tp; the cast is
|
|
|
|
caused by the operator oper. If the cast has
|
|
|
|
to be passed on to run time, its left operand will be an
|
|
|
|
expression of class Type.
|
|
|
|
*/
|
|
|
|
register struct type *oldtp;
|
1990-10-23 14:13:10 +00:00
|
|
|
register struct expr *exp = *expp;
|
1989-11-27 11:37:11 +00:00
|
|
|
int qual_lev, ascompat = 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
if (oper == RETURN && tp->tp_fund == VOID) {
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_strict(exp, "return <expression> in function returning void");
|
|
|
|
exp->ex_type = void_type;
|
1989-09-25 14:28:10 +00:00
|
|
|
return;
|
|
|
|
}
|
1990-10-23 14:13:10 +00:00
|
|
|
if (exp->ex_type->tp_fund == FUNCTION) {
|
|
|
|
function2pointer(exp);
|
1989-12-12 12:52:03 +00:00
|
|
|
}
|
1990-10-23 14:13:10 +00:00
|
|
|
if (exp->ex_type->tp_fund == ARRAY)
|
|
|
|
array2pointer(exp);
|
|
|
|
if (exp->ex_class == String)
|
|
|
|
string2pointer(exp);
|
|
|
|
oldtp = exp->ex_type;
|
1989-09-25 14:28:10 +00:00
|
|
|
|
1990-10-23 14:13:10 +00:00
|
|
|
if (oldtp->tp_size <= 0 && oldtp->tp_fund != VOID) {
|
|
|
|
expr_error(exp,"incomplete type in expression");
|
1990-10-19 11:21:43 +00:00
|
|
|
}
|
|
|
|
|
1989-09-25 14:28:10 +00:00
|
|
|
#ifndef NOBITFIELD
|
|
|
|
if (oldtp->tp_fund == FIELD) {
|
|
|
|
field2arith(expp);
|
|
|
|
ch3cast(expp, oper, tp);
|
1989-11-17 11:28:38 +00:00
|
|
|
return;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
if (tp->tp_fund == FIELD) {
|
|
|
|
ch3cast(expp, oper, tp->tp_up);
|
1989-11-17 11:28:38 +00:00
|
|
|
return;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1989-11-27 11:37:11 +00:00
|
|
|
switch (oper) {
|
|
|
|
default: qual_lev = -1; break;
|
|
|
|
case CAST: qual_lev = -999; break; /* ??? hack */
|
|
|
|
case CASTAB:
|
|
|
|
case '=':
|
|
|
|
case RETURN: ascompat = 1; /* assignment compatibility */
|
|
|
|
/* fallthrough */
|
|
|
|
case '-':
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
case LESSEQ:
|
|
|
|
case GREATEREQ:
|
|
|
|
case EQUAL:
|
|
|
|
case NOTEQUAL:
|
|
|
|
case ':':
|
|
|
|
qual_lev = -2;
|
|
|
|
break;
|
|
|
|
}
|
1989-11-13 14:01:50 +00:00
|
|
|
|
1991-03-26 09:45:20 +00:00
|
|
|
if (equal_type(tp, oldtp, qual_lev, 0)) {
|
1989-09-25 14:28:10 +00:00
|
|
|
/* life is easy */
|
1989-11-27 11:37:11 +00:00
|
|
|
if (ascompat && tp->tp_fund == POINTER) {
|
1989-11-13 14:01:50 +00:00
|
|
|
if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal)
|
|
|
|
!= oldtp->tp_up->tp_typequal) {
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_strict( exp, "qualifier error");
|
1989-11-13 14:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp; /* so qualifiers are allright */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (tp->tp_fund == VOID) {
|
|
|
|
/* easy again */
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = void_type;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (is_arith_type(oldtp) && is_arith_type(tp)) {
|
|
|
|
int oldi = is_integral_type(oldtp);
|
|
|
|
int i = is_integral_type(tp);
|
|
|
|
|
|
|
|
if (oldi && i) {
|
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp;
|
|
|
|
else {
|
1989-09-25 14:28:10 +00:00
|
|
|
int2int(expp, tp);
|
1990-10-23 14:13:10 +00:00
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
int2int(expp, tp);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldi && !i) {
|
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp;
|
|
|
|
else {
|
1989-09-25 14:28:10 +00:00
|
|
|
int2float(expp, tp);
|
1990-10-23 14:13:10 +00:00
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
int2float(expp, tp);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!oldi && i) {
|
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp;
|
|
|
|
else {
|
1989-09-25 14:28:10 +00:00
|
|
|
float2int(expp, tp);
|
1990-10-23 14:13:10 +00:00
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
float2int(expp, tp);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* !oldi && !i */
|
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp;
|
|
|
|
else {
|
1989-09-25 14:28:10 +00:00
|
|
|
float2float(expp, tp);
|
1990-10-23 14:13:10 +00:00
|
|
|
}
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
float2float(expp, tp);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) {
|
1989-11-22 13:58:36 +00:00
|
|
|
switch (oper) {
|
|
|
|
case EQUAL:
|
|
|
|
case NOTEQUAL:
|
|
|
|
case '=':
|
|
|
|
case CASTAB:
|
|
|
|
case RETURN:
|
1989-12-12 12:52:03 +00:00
|
|
|
case ':':
|
1989-11-22 13:58:36 +00:00
|
|
|
if (tp->tp_up && oldtp->tp_up) {
|
|
|
|
if (tp->tp_up->tp_fund == VOID
|
|
|
|
&& oldtp->tp_up->tp_fund != FUNCTION) {
|
|
|
|
break; /* switch */
|
|
|
|
}
|
|
|
|
if (oldtp->tp_up->tp_fund == VOID
|
|
|
|
&& tp->tp_up->tp_fund != FUNCTION) {
|
|
|
|
break; /* switch */
|
|
|
|
}
|
1989-12-12 12:52:03 +00:00
|
|
|
if (oldtp->tp_up->tp_fund == VOID
|
1990-10-23 14:13:10 +00:00
|
|
|
&& is_cp_cst(exp)
|
Add long long literals like 123LL to ACK C.
For now, a long long literal must have the 'LL' or 'll' suffix. A
literal without 'LL' or 'll' acts as before: it may become unsigned
long but not long long. (For targets where int and long have the same
size, some literals change from unsigned int to unsigned long.)
Type `arith` may be too narrow for long long values. Add a second
type `writh` for wide arithmetic, and change some variables from arith
to writh. This may cause bugs if I forget to use writh, or if a
conversion from writh to arith overflows. I mark some conversions
with (arith) or (writh) casts.
- BigPars, SmallPars: Remove SPECIAL_ARITHMETICS. This feature
would change arith to a different type, but can't work, because it
would conflict with definitions of arith in both <em_arith.h> and
<flt_arith.h>.
- LLlex.c: Understand 'LL' or 'll' suffix. Cut size of constant when
it overflows writh, not only when it overflows the target machine's
types. (This cut might not be necessary, because we might cut it
again later.) When picking signed long or unsigned long, check the
target's long type, not the compiler's arith type; the old check
for `val >= 0` was broken where sizeof(arith) > 4.
- LLlex.h: Change struct token's tok_ival to writh, so it can hold a
long long literal.
- arith.c: Adjust to VL_VALUE being writh. Don't convert between
float and integer at compile-time if the integer might be too wide
for <flt_arith.h>. Add writh2str(), because writh might be too
wide for long2str().
- arith.h: Remove SPECIAL_ARITHMETICS. Declare full_mask[] here,
not in several *.c files. Declare writh2str().
- ch3.c, ch3bin.c, ch3mon.c, declarator.c, statement.g: Remove
obsolete casts. Adjust to VL_VALUE being writh.
- conversion.c, stab.c: Don't declare full_mask[].
- cstoper.c: Use writh for constant operations on VL_VALUE, and for
full_mask[].
- declar., field.c, ival.g: Add casts.
- dumpidf.c: Need to #include "parameters.h" before checking DEBUG.
Use writh2str, because "%ld" might not work.
- eval.c, eval.h: Add casts. Use writh when writing a wide constant
in EM.
- expr.c: Add and remove casts. In fill_int_expr(), make expression
from long long literal. In chk_cst_expr(), allow long long as
constant expression, so the compiler may accept `case 123LL:` in a
switch statement.
- expr.str: Change struct value's vl_value and struct expr's VL_VALUE
to writh, so an expression may have a long long value at compile
time.
- statement.g: Remove obsolete casts.
- switch.c, switch.str: Use writh in case entries for switch
statements, so `switch (ll) {...}` with long long ll works.
- tokenname.c: Add ULNGLNG so LLlex.c can use it for literals.
2019-09-05 02:14:38 +00:00
|
|
|
&& exp->VL_VALUE == 0)
|
1989-12-12 12:52:03 +00:00
|
|
|
break; /* switch */
|
1989-11-22 13:58:36 +00:00
|
|
|
}
|
|
|
|
/* falltrough */
|
|
|
|
default:
|
|
|
|
if (oper == CASTAB)
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_strict(exp, "incompatible pointers in call");
|
1989-11-22 13:58:36 +00:00
|
|
|
else
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_strict(exp, "incompatible pointers in %s",
|
1989-09-25 14:28:10 +00:00
|
|
|
symbol2str(oper));
|
1989-11-22 13:58:36 +00:00
|
|
|
break;
|
|
|
|
case CAST: break;
|
|
|
|
}
|
1989-09-25 14:28:10 +00:00
|
|
|
#ifdef LINT
|
|
|
|
if (oper != CAST)
|
|
|
|
lint_ptr_conv(oldtp->tp_up->tp_fund, tp->tp_up->tp_fund);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* LINT */
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp; /* free conversion */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldtp->tp_fund == POINTER && is_integral_type(tp)) {
|
|
|
|
/* from pointer to integral */
|
|
|
|
if (oper != CAST)
|
1990-11-02 09:23:27 +00:00
|
|
|
expr_strict(exp,
|
1989-09-25 14:28:10 +00:00
|
|
|
"illegal conversion of pointer to %s",
|
|
|
|
symbol2str(tp->tp_fund));
|
|
|
|
if (oldtp->tp_size > tp->tp_size)
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_warning(exp,
|
1989-09-25 14:28:10 +00:00
|
|
|
"conversion of pointer to %s loses accuracy",
|
|
|
|
symbol2str(tp->tp_fund));
|
1990-10-23 14:13:10 +00:00
|
|
|
if (oldtp->tp_size != tp->tp_size) {
|
1989-09-25 14:28:10 +00:00
|
|
|
int2int(expp, tp);
|
1990-10-23 14:13:10 +00:00
|
|
|
} else
|
|
|
|
exp->ex_type = tp;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (tp->tp_fund == POINTER && is_integral_type(oldtp)) {
|
|
|
|
/* from integral to pointer */
|
|
|
|
switch (oper) {
|
|
|
|
case CAST:
|
|
|
|
break;
|
|
|
|
case CASTAB:
|
|
|
|
case EQUAL:
|
|
|
|
case NOTEQUAL:
|
|
|
|
case '=':
|
|
|
|
case RETURN:
|
Add long long literals like 123LL to ACK C.
For now, a long long literal must have the 'LL' or 'll' suffix. A
literal without 'LL' or 'll' acts as before: it may become unsigned
long but not long long. (For targets where int and long have the same
size, some literals change from unsigned int to unsigned long.)
Type `arith` may be too narrow for long long values. Add a second
type `writh` for wide arithmetic, and change some variables from arith
to writh. This may cause bugs if I forget to use writh, or if a
conversion from writh to arith overflows. I mark some conversions
with (arith) or (writh) casts.
- BigPars, SmallPars: Remove SPECIAL_ARITHMETICS. This feature
would change arith to a different type, but can't work, because it
would conflict with definitions of arith in both <em_arith.h> and
<flt_arith.h>.
- LLlex.c: Understand 'LL' or 'll' suffix. Cut size of constant when
it overflows writh, not only when it overflows the target machine's
types. (This cut might not be necessary, because we might cut it
again later.) When picking signed long or unsigned long, check the
target's long type, not the compiler's arith type; the old check
for `val >= 0` was broken where sizeof(arith) > 4.
- LLlex.h: Change struct token's tok_ival to writh, so it can hold a
long long literal.
- arith.c: Adjust to VL_VALUE being writh. Don't convert between
float and integer at compile-time if the integer might be too wide
for <flt_arith.h>. Add writh2str(), because writh might be too
wide for long2str().
- arith.h: Remove SPECIAL_ARITHMETICS. Declare full_mask[] here,
not in several *.c files. Declare writh2str().
- ch3.c, ch3bin.c, ch3mon.c, declarator.c, statement.g: Remove
obsolete casts. Adjust to VL_VALUE being writh.
- conversion.c, stab.c: Don't declare full_mask[].
- cstoper.c: Use writh for constant operations on VL_VALUE, and for
full_mask[].
- declar., field.c, ival.g: Add casts.
- dumpidf.c: Need to #include "parameters.h" before checking DEBUG.
Use writh2str, because "%ld" might not work.
- eval.c, eval.h: Add casts. Use writh when writing a wide constant
in EM.
- expr.c: Add and remove casts. In fill_int_expr(), make expression
from long long literal. In chk_cst_expr(), allow long long as
constant expression, so the compiler may accept `case 123LL:` in a
switch statement.
- expr.str: Change struct value's vl_value and struct expr's VL_VALUE
to writh, so an expression may have a long long value at compile
time.
- statement.g: Remove obsolete casts.
- switch.c, switch.str: Use writh in case entries for switch
statements, so `switch (ll) {...}` with long long ll works.
- tokenname.c: Add ULNGLNG so LLlex.c can use it for literals.
2019-09-05 02:14:38 +00:00
|
|
|
if (is_cp_cst(exp) && exp->VL_VALUE == 0)
|
1989-09-25 14:28:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
1990-11-02 09:23:27 +00:00
|
|
|
expr_strict(exp,
|
1989-09-25 14:28:10 +00:00
|
|
|
"illegal conversion of %s to pointer",
|
|
|
|
symbol2str(oldtp->tp_fund));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (oldtp->tp_size > tp->tp_size)
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_warning(exp,
|
1989-09-25 14:28:10 +00:00
|
|
|
"conversion of %s to pointer loses accuracy",
|
|
|
|
symbol2str(oldtp->tp_fund));
|
1990-10-23 14:13:10 +00:00
|
|
|
if (oldtp->tp_size != tp->tp_size) {
|
1989-09-25 14:28:10 +00:00
|
|
|
int2int(expp, tp);
|
1990-10-23 14:13:10 +00:00
|
|
|
} else
|
|
|
|
exp->ex_type = tp;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldtp->tp_fund == ERRONEOUS) {
|
|
|
|
/* we just won't look */
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp; /* brute force */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldtp->tp_size == tp->tp_size && oper == CAST) {
|
1990-11-02 09:23:27 +00:00
|
|
|
expr_strict(exp, "dubious conversion based on equal size");
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_type = tp; /* brute force */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS)
|
1990-10-23 14:13:10 +00:00
|
|
|
expr_error(exp, "cannot convert %s to %s",
|
|
|
|
symbol2str(oldtp->tp_fund),
|
|
|
|
symbol2str(tp->tp_fund)
|
|
|
|
);
|
|
|
|
exp->ex_type = tp; /* brute force */
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
1990-10-23 14:13:10 +00:00
|
|
|
/* re-initialize exp, since *expp may have changed */
|
|
|
|
exp = *expp;
|
1989-09-25 14:28:10 +00:00
|
|
|
if (oper == CAST) {
|
1990-10-23 14:13:10 +00:00
|
|
|
exp->ex_flags |= EX_ILVALUE;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine whether two types are equal.
|
|
|
|
*/
|
2019-02-18 16:42:15 +00:00
|
|
|
int equal_type(register struct type *tp,register struct type *otp, int qual_lev, int diag)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
1989-11-13 14:01:50 +00:00
|
|
|
if (tp == otp)
|
1989-09-25 14:28:10 +00:00
|
|
|
return 1;
|
1989-10-18 13:12:31 +00:00
|
|
|
if (!tp
|
|
|
|
|| !otp
|
|
|
|
|| (tp->tp_fund != otp->tp_fund)
|
|
|
|
|| (tp->tp_unsigned != otp->tp_unsigned)
|
|
|
|
|| (tp->tp_align != otp->tp_align))
|
1989-09-25 14:28:10 +00:00
|
|
|
return 0;
|
1989-11-28 15:28:52 +00:00
|
|
|
if (tp->tp_size != otp->tp_size) {
|
|
|
|
if (tp->tp_fund != ARRAY
|
|
|
|
|| (tp->tp_size != -1 && otp->tp_size != -1))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1991-03-26 09:45:20 +00:00
|
|
|
if (qual_lev >= 0 && tp->tp_typequal != otp->tp_typequal) {
|
1991-10-17 13:27:53 +00:00
|
|
|
strict("missing or illegal qualifiers");
|
1989-11-13 14:01:50 +00:00
|
|
|
}
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
|
|
|
|
case FUNCTION:
|
|
|
|
/* If both types have parameter type lists, the type of
|
|
|
|
each parameter in the composite parameter type list
|
|
|
|
is the composite type of the corresponding paramaters.
|
|
|
|
*/
|
|
|
|
if (tp->tp_proto && otp->tp_proto) {
|
1991-03-26 09:45:20 +00:00
|
|
|
if (!equal_proto(tp->tp_proto, otp->tp_proto, diag))
|
1989-09-25 14:28:10 +00:00
|
|
|
return 0;
|
|
|
|
} else if (tp->tp_proto || otp->tp_proto) {
|
1991-03-26 09:45:20 +00:00
|
|
|
if (!legal_mixture(tp, otp, diag))
|
1989-09-25 14:28:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1991-03-26 09:45:20 +00:00
|
|
|
return equal_type(tp->tp_up, otp->tp_up, qual_lev + 1, diag);
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
case ARRAY:
|
|
|
|
/* If one type is an array of known size, the composite
|
|
|
|
type is an array of that size
|
|
|
|
*/
|
|
|
|
if (tp->tp_size != otp->tp_size &&
|
|
|
|
(tp->tp_size != -1 && otp->tp_size != -1))
|
|
|
|
return 0;
|
1991-03-26 09:45:20 +00:00
|
|
|
return equal_type(tp->tp_up, otp->tp_up, qual_lev/* ??? +1 */, diag);
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
case POINTER:
|
1991-03-26 09:45:20 +00:00
|
|
|
return equal_type(tp->tp_up, otp->tp_up, qual_lev + 1, diag);
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
case FIELD:
|
1991-03-26 09:45:20 +00:00
|
|
|
return equal_type(tp->tp_up, otp->tp_up, qual_lev/* ??? +1 */, diag);
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
case STRUCT:
|
|
|
|
case UNION:
|
|
|
|
case ENUM:
|
|
|
|
return tp->tp_idf == otp->tp_idf && tp->tp_sdef == otp->tp_sdef;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
int check_pseudoproto(register struct proto *pl,register struct proto *opl, int diag)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
int retval = 1;
|
|
|
|
|
|
|
|
if (pl->pl_flag & PL_ELLIPSIS) {
|
1991-03-26 09:45:20 +00:00
|
|
|
if (diag) {
|
|
|
|
error("illegal ellipsis terminator");
|
|
|
|
pl->pl_flag |= PL_ERRGIVEN;
|
|
|
|
opl->pl_flag |= PL_ERRGIVEN;
|
|
|
|
}
|
1989-10-19 14:53:25 +00:00
|
|
|
return 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
if (opl->pl_flag & PL_VOID) {
|
1992-03-02 14:37:37 +00:00
|
|
|
if (!(pl->pl_flag & PL_VOID)) {
|
|
|
|
if (diag) {
|
|
|
|
strict("function is defined without parameters");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
while (pl && opl) {
|
1991-03-26 09:45:20 +00:00
|
|
|
if (!equal_type(pl->pl_type, opl->pl_type, -1, diag)) {
|
|
|
|
if (diag) {
|
|
|
|
if (!(pl->pl_flag & PL_ERRGIVEN)
|
|
|
|
&& !(opl->pl_flag & PL_ERRGIVEN))
|
|
|
|
error("incorrect type for parameter %s of definition",
|
|
|
|
opl->pl_idf->id_text);
|
|
|
|
pl->pl_flag |= PL_ERRGIVEN;
|
|
|
|
opl->pl_flag |= PL_ERRGIVEN;
|
|
|
|
}
|
1989-10-19 14:53:25 +00:00
|
|
|
retval = 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
pl = pl->next;
|
|
|
|
opl = opl->next;
|
|
|
|
}
|
|
|
|
if (pl || opl) {
|
1991-03-26 09:45:20 +00:00
|
|
|
if (diag) error("incorrect number of parameters");
|
1989-10-19 14:53:25 +00:00
|
|
|
retval = 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
int legal_mixture(struct type *tp, struct type *otp, int diag)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
1991-03-27 12:46:37 +00:00
|
|
|
struct proto *pl = tp->tp_proto, *opl = otp->tp_proto;
|
1989-09-25 14:28:10 +00:00
|
|
|
int retval = 1;
|
1991-03-27 12:46:37 +00:00
|
|
|
register struct proto *prot;
|
1989-09-25 14:28:10 +00:00
|
|
|
int fund;
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert( (pl != 0) ^ (opl != 0));
|
1989-09-25 14:28:10 +00:00
|
|
|
if (pl) {
|
|
|
|
prot = pl;
|
|
|
|
} else {
|
|
|
|
prot = opl;
|
|
|
|
}
|
|
|
|
if (!opl && otp->tp_pseudoproto) {
|
1991-03-26 09:45:20 +00:00
|
|
|
return check_pseudoproto(tp->tp_proto, otp->tp_pseudoproto, diag);
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prot->pl_flag & PL_ELLIPSIS) {
|
1991-04-03 10:02:40 +00:00
|
|
|
if (prot->pl_flag & PL_ERRGIVEN) {
|
1989-09-25 14:28:10 +00:00
|
|
|
if (pl)
|
|
|
|
error("illegal ellipsis terminator");
|
|
|
|
else error("ellipsis terminator in previous (prototype) declaration");
|
1989-10-19 14:53:25 +00:00
|
|
|
prot->pl_flag |= PL_ERRGIVEN;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
1989-10-19 14:53:25 +00:00
|
|
|
return 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
while (prot) {
|
|
|
|
/* if (!(prot->pl_flag & PL_ELLIPSIS)) {} */
|
|
|
|
fund = prot->pl_type->tp_fund;
|
|
|
|
if (fund == CHAR || fund == SHORT || fund == FLOAT) {
|
1991-03-26 09:45:20 +00:00
|
|
|
if (diag && !(prot->pl_flag & PL_ERRGIVEN))
|
1989-09-25 14:28:10 +00:00
|
|
|
error("illegal %s parameter in %sdeclaration",
|
|
|
|
symbol2str(fund), (opl ? "previous (prototype) " : "" ));
|
|
|
|
prot->pl_flag |= PL_ERRGIVEN;
|
1989-10-19 14:53:25 +00:00
|
|
|
retval = 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
prot = prot->next;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
int equal_proto(register struct proto *pl, register struct proto *opl, int diag)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
if (pl == opl)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* If only one type is a function type with a parameter type list
|
|
|
|
(a function prototype), the composite type is a function
|
|
|
|
prototype with parameter type list.
|
|
|
|
*/
|
|
|
|
while ( pl && opl) {
|
|
|
|
|
1989-10-19 14:53:25 +00:00
|
|
|
if ((pl->pl_flag & ~PL_ERRGIVEN) != (opl->pl_flag & ~PL_ERRGIVEN) ||
|
1991-03-26 09:45:20 +00:00
|
|
|
!equal_type(pl->pl_type, opl->pl_type, -1, diag))
|
1989-09-25 14:28:10 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pl = pl->next;
|
|
|
|
opl = opl->next;
|
|
|
|
}
|
|
|
|
return !(pl || opl);
|
|
|
|
}
|
|
|
|
|
1990-04-02 15:57:51 +00:00
|
|
|
/* check if a type has a consqualified member */
|
2019-02-18 16:42:15 +00:00
|
|
|
int recurqual(struct type *tp, int qual)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
register struct sdef *sdf;
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
assert(tp);
|
1989-10-20 13:06:10 +00:00
|
|
|
|
1990-04-02 15:57:51 +00:00
|
|
|
if (tp->tp_typequal & qual) return 1;
|
1990-05-15 15:28:01 +00:00
|
|
|
switch(tp->tp_fund) {
|
|
|
|
case UNION:
|
|
|
|
case STRUCT:
|
|
|
|
case ENUM:
|
|
|
|
sdf = tp->tp_sdef;
|
|
|
|
while (sdf) {
|
|
|
|
if (recurqual(sdf->sd_type, qual))
|
|
|
|
return 1;
|
|
|
|
sdf = sdf->sd_sdef;
|
|
|
|
}
|
|
|
|
break;
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
void ch3asgn(struct expr **expp, int oper, struct expr *expr)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
/* The assignment operators.
|
|
|
|
"f op= e" should be interpreted as
|
|
|
|
"f = (typeof f)((typeof (f op e))f op (typeof (f op e))e)"
|
|
|
|
and not as "f = f op (typeof f)e".
|
|
|
|
Consider, for example, (i == 10) i *= 0.9; (i == 9), where
|
|
|
|
typeof i == int.
|
|
|
|
The resulting expression tree becomes:
|
|
|
|
op=
|
|
|
|
/ \
|
|
|
|
/ \
|
|
|
|
f (typeof (f op e))e
|
|
|
|
EVAL should however take care of evaluating (typeof (f op e))f
|
|
|
|
*/
|
|
|
|
register struct expr *exp = *expp;
|
|
|
|
int fund = exp->ex_type->tp_fund;
|
|
|
|
struct type *tp;
|
1989-10-19 19:29:39 +00:00
|
|
|
char *oper_string = symbol2str(oper);
|
1989-09-25 14:28:10 +00:00
|
|
|
|
|
|
|
/* We expect an lvalue */
|
1989-11-22 13:58:36 +00:00
|
|
|
if (fund == ARRAY || fund == FUNCTION) exp->ex_lvalue = 0;
|
1989-09-25 14:28:10 +00:00
|
|
|
if (!exp->ex_lvalue) {
|
1989-10-19 19:29:39 +00:00
|
|
|
expr_error(exp, "no lvalue in operand of %s", oper_string);
|
1989-09-25 14:28:10 +00:00
|
|
|
} else if (exp->ex_flags & EX_ILVALUE) {
|
1989-11-08 16:52:34 +00:00
|
|
|
expr_strict(exp, "incorrect lvalue in operand of %s", oper_string);
|
1989-09-25 14:28:10 +00:00
|
|
|
} else if (exp->ex_flags & EX_READONLY) {
|
1989-10-19 19:29:39 +00:00
|
|
|
expr_error(exp, "operand of %s is read-only", oper_string);
|
1989-09-25 14:28:10 +00:00
|
|
|
} else if (fund == STRUCT || fund == UNION) {
|
1990-04-02 15:57:51 +00:00
|
|
|
if (recurqual(exp->ex_type, TQ_CONST))
|
1990-04-06 15:37:16 +00:00
|
|
|
expr_error(exp,"operand of %s contains a const-qualified member",
|
1989-10-19 19:29:39 +00:00
|
|
|
oper_string);
|
1989-09-25 14:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oper == '=') {
|
|
|
|
ch3cast(&expr, oper, exp->ex_type);
|
|
|
|
tp = expr->ex_type;
|
|
|
|
}
|
|
|
|
else { /* turn e into e' where typeof(e') = typeof (f op e) */
|
|
|
|
struct expr *extmp = intexpr((arith)0, INT);
|
|
|
|
|
|
|
|
/* this is really $#@&*%$# ! */
|
|
|
|
/* if you correct this, please correct lint_new_oper() too */
|
|
|
|
extmp->ex_lvalue = 1;
|
|
|
|
extmp->ex_type = exp->ex_type;
|
|
|
|
ch3bin(&extmp, oper, expr);
|
|
|
|
/* Note that ch3bin creates a tree of the expression
|
|
|
|
((typeof (f op e))f op (typeof (f op e))e),
|
|
|
|
where f ~ extmp and e ~ expr.
|
|
|
|
We want to use (typeof (f op e))e.
|
1989-09-29 16:20:38 +00:00
|
|
|
Ch3bin does not create a tree if both operands
|
1989-09-25 14:28:10 +00:00
|
|
|
were illegal or constants!
|
|
|
|
*/
|
|
|
|
tp = extmp->ex_type; /* perform the arithmetic in type tp */
|
|
|
|
if (extmp->ex_class == Oper) {
|
|
|
|
expr = extmp->OP_RIGHT;
|
|
|
|
extmp->OP_RIGHT = NILEXPR;
|
|
|
|
free_expression(extmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
expr = extmp;
|
|
|
|
}
|
|
|
|
#ifndef NOBITFIELD
|
1989-10-19 19:29:39 +00:00
|
|
|
exp = new_oper(fund == FIELD ? exp->ex_type->tp_up : exp->ex_type,
|
|
|
|
exp, oper, expr);
|
1991-12-17 13:12:22 +00:00
|
|
|
#else /* NOBITFIELD */
|
1989-09-25 14:28:10 +00:00
|
|
|
exp = new_oper(exp->ex_type, exp, oper, expr);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1989-09-25 14:28:10 +00:00
|
|
|
exp->OP_TYPE = tp; /* for EVAL() */
|
1990-04-02 15:57:51 +00:00
|
|
|
exp->ex_flags |= EX_SIDEEFFECTS;
|
1989-09-25 14:28:10 +00:00
|
|
|
*expp = exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some interesting (?) questions answered.
|
|
|
|
*/
|
2019-02-18 16:42:15 +00:00
|
|
|
int is_integral_type(register struct type *tp)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case CHAR:
|
|
|
|
case SHORT:
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
Begin to add `long long` to C compiler for linux386.
Add long long type, but without literals; you can't say '123LL' yet.
You can try constant operations, like `(long long)123 + 1`, but the
compiler's `arith` type might not be wide enough. Conversions,
shifts, and some other operations don't work in i386 ncg; I am using a
union instead of conversions:
union q {
long long ll;
unsigned long long ull;
int i[2];
};
Hack plat/linux386/descr to enable long long (size 8, alignment 4)
only for this platform. The default for other platforms is to disable
long long (size -1).
In lang/cem/cemcom.ansi,
- BigPars, SmallPars: Add default size, alignment of long long.
- align.h: Add lnglng_align.
- arith.c: Convert arithmetic operands to long long or unsigned long
long when necessary; avoid conversion from long long to long.
Allow long long as an arithmetic, integral, or logical operand.
- ch3.c: Handle long long like int and long when erroneously applying
a selector, like `long long ll; ll.member` or `ll->member`. Add
long long to integral and arithmetic types.
- code.c: Add long long to type stabs for debugging.
- conversion.c: Add long long to integral conversions.
- cstoper.c: Write masks up to full_mask[8]. Add FIXME comment.
- declar.g: Parse `long long` in code.
- decspecs.c: Understand long long in type declarations.
- eval.c: Add long long to operations, to generate code like `adi 8`.
Don't use `ldc` with constant over 4 bytes.
- ival.g: Allow long long in initializations.
- main.c: Set lnglng_type and related values.
- options.c: Add option like `-Vq8.4` to set long long to size 8,
alignment 4. I chose 'q', because Perl's pack and Ruby's
Array#pack use 'q' for 64-bit or long long values; it might be a
reference to BSD's old quad_t alias for long long.
- sizes.h: Add lnglng_size.
- stab.c: Allow long long when writing the type stab for debugging.
Switch from calculating the ranges to hardcoding them in strings;
add 8-byte ranges as a special case. This also hardcodes the
unsigned 4-byte range as "0;-1". Before it was either "0;-1" or
"0;4294967295", depending on sizeof(long) in the compiler.
- struct.c: Try long long bitfield, but it will probably give the
error, "bit field type long long does not fit in a word".
- switch.c: Update comment.
- tokenname.c: Define LNGLNG (long long) like LNGDBL (long double).
- type.c, type.str: Add lnglng_type and ulnglng_type. Add function
no_long_long() to check if long long is disabled.
2019-09-02 15:24:44 +00:00
|
|
|
case LNGLNG:
|
1989-09-25 14:28:10 +00:00
|
|
|
case ENUM:
|
|
|
|
return 1;
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
case FIELD:
|
|
|
|
return is_integral_type(tp->tp_up);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1989-09-25 14:28:10 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 16:42:15 +00:00
|
|
|
int is_arith_type(register struct type *tp)
|
1989-09-25 14:28:10 +00:00
|
|
|
{
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case CHAR:
|
|
|
|
case SHORT:
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
Begin to add `long long` to C compiler for linux386.
Add long long type, but without literals; you can't say '123LL' yet.
You can try constant operations, like `(long long)123 + 1`, but the
compiler's `arith` type might not be wide enough. Conversions,
shifts, and some other operations don't work in i386 ncg; I am using a
union instead of conversions:
union q {
long long ll;
unsigned long long ull;
int i[2];
};
Hack plat/linux386/descr to enable long long (size 8, alignment 4)
only for this platform. The default for other platforms is to disable
long long (size -1).
In lang/cem/cemcom.ansi,
- BigPars, SmallPars: Add default size, alignment of long long.
- align.h: Add lnglng_align.
- arith.c: Convert arithmetic operands to long long or unsigned long
long when necessary; avoid conversion from long long to long.
Allow long long as an arithmetic, integral, or logical operand.
- ch3.c: Handle long long like int and long when erroneously applying
a selector, like `long long ll; ll.member` or `ll->member`. Add
long long to integral and arithmetic types.
- code.c: Add long long to type stabs for debugging.
- conversion.c: Add long long to integral conversions.
- cstoper.c: Write masks up to full_mask[8]. Add FIXME comment.
- declar.g: Parse `long long` in code.
- decspecs.c: Understand long long in type declarations.
- eval.c: Add long long to operations, to generate code like `adi 8`.
Don't use `ldc` with constant over 4 bytes.
- ival.g: Allow long long in initializations.
- main.c: Set lnglng_type and related values.
- options.c: Add option like `-Vq8.4` to set long long to size 8,
alignment 4. I chose 'q', because Perl's pack and Ruby's
Array#pack use 'q' for 64-bit or long long values; it might be a
reference to BSD's old quad_t alias for long long.
- sizes.h: Add lnglng_size.
- stab.c: Allow long long when writing the type stab for debugging.
Switch from calculating the ranges to hardcoding them in strings;
add 8-byte ranges as a special case. This also hardcodes the
unsigned 4-byte range as "0;-1". Before it was either "0;-1" or
"0;4294967295", depending on sizeof(long) in the compiler.
- struct.c: Try long long bitfield, but it will probably give the
error, "bit field type long long does not fit in a word".
- switch.c: Update comment.
- tokenname.c: Define LNGLNG (long long) like LNGDBL (long double).
- type.c, type.str: Add lnglng_type and ulnglng_type. Add function
no_long_long() to check if long long is disabled.
2019-09-02 15:24:44 +00:00
|
|
|
case LNGLNG:
|
1989-09-25 14:28:10 +00:00
|
|
|
case ENUM:
|
|
|
|
case FLOAT:
|
|
|
|
case DOUBLE:
|
|
|
|
case LNGDBL:
|
|
|
|
return 1;
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
case FIELD:
|
|
|
|
return is_arith_type(tp->tp_up);
|
1991-12-17 13:12:22 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1989-09-25 14:28:10 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|