scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 6fe9948519b756f46cb42fa132b158541f024222
parent 6b79855c62dc196ceb55fc0e585f6feb27db2fda
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  6 Jan 2016 20:07:10 +0100

Remove TINT field in limits struct

Having this field was a problem because it made impossible
to take a value of the union without checking the type
which generates this limits. This complexity is not needed,
because TUINT can cover the maximum of any integer type,
and in the case of the min, we only have to negate the value.

Diffstat:
Mcc1/cc1.h | 6++----
Mcc1/fold.c | 6+++---
Mcc1/lex.c | 4++--
Mcc1/types.c | 16++++++++--------
4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -35,13 +35,11 @@ typedef struct input Input; struct limits { union { - TINT i; - TUINT u; + TUINT i; TFLOAT f; } max; union { - TINT i; - TUINT u; + TUINT i; TFLOAT f; } min; }; diff --git a/cc1/fold.c b/cc1/fold.c @@ -21,7 +21,7 @@ static bool addi(TINT l, TINT r, Type *tp) { struct limits *lim = getlimits(tp); - TINT max = lim->max.i, min = lim->min.i; + TINT max = lim->max.i, min = -lim->min.i; if (l < 0 && r < 0 && l >= min - r || l == 0 || @@ -69,7 +69,7 @@ static bool muli(TINT l, TINT r, Type *tp) { struct limits *lim = getlimits(tp); - TINT max = lim->max.i, min = lim->min.i; + TINT max = lim->max.i, min = -lim->min.i; if (l > -1 && l <= 1 || r > -1 && r <= 1 || @@ -106,7 +106,7 @@ divi(TINT l, TINT r, Type *tp) { struct limits *lim = getlimits(tp); - if (r == 0 || l == lim->min.i && r == -1) { + if (r == 0 || l == -lim->min.i && r == -1) { warn("overflow in constant expression"); return 0; } diff --git a/cc1/lex.c b/cc1/lex.c @@ -266,7 +266,7 @@ readint(char *s, int base, int sign, Symbol *sym) int c; lim = getlimits(tp); - max = (tp->sign) ? lim->max.u : lim->max.i; + max = lim->max.i; if (*s == '0') ++s; if (toupper(*s) == 'X') @@ -295,7 +295,7 @@ readint(char *s, int base, int sign, Symbol *sym) } sym->type = tp; lim = getlimits(tp); - max = (tp->sign) ? lim->max.u : lim->max.i; + max = lim->max.i; goto repeat; } diff --git a/cc1/types.c b/cc1/types.c @@ -19,20 +19,20 @@ static struct limits limits[][4] = { { { /* 0 = unsigned 1 byte */ - .min.u = 0, - .max.u = 255 + .min.i = 0, + .max.i = 255 }, { /* 1 = unsigned 2 bytes */ - .min.u = 0, - .max.u = 65535u + .min.i = 0, + .max.i = 65535u }, { /* 2 = unsigned 4 bytes */ - .min.u = 0, - .max.u = 4294967295u + .min.i = 0, + .max.i = 4294967295u }, { /* 3 = unsigned 8 bytes */ - .min.u = 0, - .max.u = 18446744073709551615u + .min.i = 0, + .max.i = 18446744073709551615u } }, {