From: johanknol Date: Thu, 11 Oct 2001 11:51:14 +0000 (+0000) Subject: more fixes for the constant values X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=11a6db511db5f9e09ddd0f07a828ec2d1125d6f8;p=fw%2Fsdcc more fixes for the constant values git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1386 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 47bf56b5..b253154f 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -123,9 +123,9 @@ typedef struct specifier union { /* Values if constant or enum */ - int v_int; /* int and char values */ + short int v_int; /* int and char values */ char *v_char; /* character string */ - unsigned v_uint; /* unsigned int const value */ + unsigned short v_uint; /* unsigned int const value */ long v_long; /* long constant value */ unsigned long v_ulong; /* unsigned long constant val */ double v_float; /* floating point constant value */ diff --git a/src/SDCCval.c b/src/SDCCval.c index bf97fabf..819b8144 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -355,6 +355,7 @@ value *cheapestVal (value *val) { if (sval<0) { if (sval>=-128) { SPEC_NOUN(val->type)=V_CHAR; + SPEC_CVAL(val->type).v_int &= 0xff; SPEC_LONG(val->type)=0; } else { if (sval>=-32768) { @@ -865,23 +866,26 @@ floatFromVal (value * val) if (SPEC_NOUN (val->etype) == V_FLOAT) return (double) SPEC_CVAL (val->etype).v_float; - else + + if (SPEC_LONG (val->etype)) { - if (SPEC_LONG (val->etype)) - { - if (SPEC_USIGN (val->etype)) - return (double) SPEC_CVAL (val->etype).v_ulong; - else - return (double) SPEC_CVAL (val->etype).v_long; - } + if (SPEC_USIGN (val->etype)) + return (double) SPEC_CVAL (val->etype).v_ulong; else - { - if (SPEC_USIGN (val->etype)) - return (double) SPEC_CVAL (val->etype).v_uint; - else - return (double) SPEC_CVAL (val->etype).v_int; - } + return (double) SPEC_CVAL (val->etype).v_long; } + + if (SPEC_NOUN(val->etype)==V_INT) { + if (SPEC_USIGN (val->etype)) + return (double) SPEC_CVAL (val->etype).v_uint; + else + return (double) SPEC_CVAL (val->etype).v_int; + } else { // SPEC_NOUN==V_CHAR + if (SPEC_USIGN (val->etype)) + return (double) ((unsigned char)SPEC_CVAL (val->etype).v_uint); + else + return (double) ((signed char)SPEC_CVAL (val->etype).v_int); + } } @@ -909,8 +913,13 @@ valUnaryPM (value * val) SPEC_CVAL (val->etype).v_uint = 0-SPEC_CVAL (val->etype).v_uint; else SPEC_CVAL (val->etype).v_int = -SPEC_CVAL (val->etype).v_int; + if (SPEC_NOUN (val->etype)==V_CHAR) { + SPEC_CVAL (val->etype).v_uint &= 0xff; + } } } + // -(unsigned 3) now really is signed + SPEC_USIGN(val->etype)=0; return val; } @@ -934,6 +943,9 @@ valComplement (value * val) SPEC_CVAL (val->etype).v_uint = ~SPEC_CVAL (val->etype).v_uint; else SPEC_CVAL (val->etype).v_int = ~SPEC_CVAL (val->etype).v_int; + if (SPEC_NOUN (val->etype)==V_CHAR) { + SPEC_CVAL (val->etype).v_uint &= 0xff; + } } return val; } @@ -958,6 +970,9 @@ valNot (value * val) SPEC_CVAL (val->etype).v_uint = !SPEC_CVAL (val->etype).v_uint; else SPEC_CVAL (val->etype).v_int = !SPEC_CVAL (val->etype).v_int; + if (SPEC_NOUN (val->etype)==V_CHAR) { + SPEC_CVAL (val->etype).v_uint &= 0xff; + } } return val; } @@ -1435,17 +1450,12 @@ valCastLiteral (sym_link * dtype, double fval) else { if (SPEC_USIGN (val->etype)) - if (SPEC_NOUN (val->etype)==V_CHAR) { - SPEC_CVAL (val->etype).v_uint = (unsigned char)fval; - } else { - SPEC_CVAL (val->etype).v_uint = (unsigned short)fval; - } + SPEC_CVAL (val->etype).v_uint = (unsigned short)fval; else - if (SPEC_NOUN (val->etype)==V_CHAR) { - SPEC_CVAL (val->etype).v_int = (char)fval; - } else { - SPEC_CVAL (val->etype).v_int = (short)fval; - } + SPEC_CVAL (val->etype).v_int = (short)fval; + if (SPEC_NOUN (val->etype)==V_CHAR) { + SPEC_CVAL (val->etype).v_uint &= 0xff; + } } } return val;