X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCval.c;h=72c73a1888cc1d7e21dc2dfc1ed413326f2686c6;hb=7b340d1916ee8ff306b1d0fa1c3a0921cec831dd;hp=ad57890f48fc701686527ade74e0bb6c417a5dfc;hpb=fd60845cbca46308dd26f0930bc09efb47a43b25;p=fw%2Fsdcc diff --git a/src/SDCCval.c b/src/SDCCval.c index ad57890f..72c73a18 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -348,10 +348,9 @@ value *cheapestVal (value *val) { if (sval<0) { if (sval>=-32768) { SPEC_LONG(val->type)=0; - SPEC_CVAL(val->type).v_int = sval & 0xffff; + SPEC_CVAL(val->type).v_int = sval; if (sval>=-128) { SPEC_NOUN(val->type)=V_CHAR; - SPEC_CVAL(val->type).v_int &= 0xff; } } } else { // sval>=0 @@ -890,10 +889,32 @@ floatFromVal (value * val) return (double) SPEC_CVAL (val->etype).v_long; } - if (SPEC_USIGN (val->etype)) - return (double) SPEC_CVAL (val->etype).v_uint; - else - return (double) SPEC_CVAL (val->etype).v_int; + 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; + } + + if (SPEC_NOUN (val->etype) == 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; + } + + if (IS_BITVAR(val->etype)) { + return (double) SPEC_CVAL (val->etype).v_ulong; + } + + if (SPEC_NOUN (val->etype) == V_VOID) { + return (double) SPEC_CVAL (val->etype).v_ulong; + } + + // we are lost ! + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "floatFromVal: unknown value"); + return 0; } @@ -925,6 +946,12 @@ valUnaryPM (value * val) } // -(unsigned 3) now really is signed SPEC_USIGN(val->etype)=0; + // -(unsigned char)135 now really is an int + if (SPEC_NOUN(val->etype) == V_CHAR) { + if (SPEC_CVAL(val->etype).v_int < -128) { + SPEC_NOUN(val->etype) = V_INT; + } + } return val; } @@ -948,10 +975,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; - } } + // ~(unsigned 3) now really is signed + SPEC_USIGN(val->etype)=0; return val; } @@ -975,9 +1001,6 @@ 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; } @@ -1423,9 +1446,6 @@ valCastLiteral (sym_link * dtype, double fval) SPEC_CVAL (val->etype).v_uint = (unsigned short)l; else SPEC_CVAL (val->etype).v_int = (short)l; - if (SPEC_NOUN (val->etype)==V_CHAR) { - SPEC_CVAL (val->etype).v_uint &= 0xff; - } } } return val; @@ -1443,7 +1463,7 @@ getNelements (sym_link * type, initList * ilist) if (!ilist) return 0; - if (ilist->type == INIT_DEEP) + while (ilist->type == INIT_DEEP) ilist = ilist->init.deep; /* if type is a character array and there is only one @@ -1454,7 +1474,7 @@ getNelements (sym_link * type, initList * ilist) value *v = (iast->type == EX_VALUE ? iast->opval.val : NULL); if (!v) { - werror (W_INIT_WRONG); + werror (E_CONST_EXPECTED); return 0; }