X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCval.c;h=59cb58726ea60b3de136a709c625dc62848d7fef;hb=8d09250d917acd806df3a7b05e9aee699f570cac;hp=31b4159c0e09a9d632b410cbac3cfedcdf3312a7;hpb=bcc933a064068f6edf24d85f7b1cd0d4a812fb13;p=fw%2Fsdcc diff --git a/src/SDCCval.c b/src/SDCCval.c index 31b4159c..59cb5872 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -39,7 +39,7 @@ newValue () { value *val; - val = Safe_calloc (1, sizeof (value)); + val = Safe_alloc (sizeof (value)); return val; } @@ -53,7 +53,7 @@ newiList (int type, void *ilist) initList *nilist; - nilist = Safe_calloc (1, sizeof (initList)); + nilist = Safe_alloc (sizeof (initList)); nilist->type = type; nilist->lineno = yylineno; @@ -139,7 +139,7 @@ convertIListToConstList(initList *src, literalList **lList) } else { - newL = Safe_malloc(sizeof(literalList)); + newL = Safe_alloc(sizeof(literalList)); newL->literalValue = val; newL->count = 1; newL->next = NULL; @@ -175,7 +175,7 @@ copyLiteralList(literalList *src) while (src) { - newL = Safe_malloc(sizeof(literalList)); + newL = Safe_alloc(sizeof(literalList)); newL->literalValue = src->literalValue; newL->count = src->count; @@ -312,6 +312,61 @@ symbolVal (symbol * sym) return val; } +/*--------------------------------------------------------------------*/ +/* cheapestVal - convert a val to the cheapest as possible value */ +/*--------------------------------------------------------------------*/ +value *cheapestVal (value *val) { + long sval=0; + unsigned long uval=0; + + if (IS_FLOAT(val->type) || IS_CHAR(val->type)) + return val; + + if (SPEC_LONG(val->type)) { + if (SPEC_USIGN(val->type)) { + uval=SPEC_CVAL(val->type).v_ulong; + } else { + sval=SPEC_CVAL(val->type).v_long; + } + } else { + if (SPEC_USIGN(val->type)) { + uval=SPEC_CVAL(val->type).v_uint; + } else { + sval=SPEC_CVAL(val->type).v_int; + } + } + + if (SPEC_USIGN(val->type)) { + if (uval<=0xffff) { + SPEC_LONG(val->type)=0; + SPEC_CVAL(val->type).v_uint = uval; + if (uval<=0xff) { + SPEC_NOUN(val->type)=V_CHAR; + } + } + } else { // not unsigned + if (sval<0) { + if (sval>=-32768) { + SPEC_LONG(val->type)=0; + SPEC_CVAL(val->type).v_int = sval; + if (sval>=-128) { + SPEC_NOUN(val->type)=V_CHAR; + } + } + } else { // sval>=0 + SPEC_USIGN(val->type)=1; + if (sval<=65535) { + SPEC_LONG(val->type)=0; + SPEC_CVAL(val->type).v_int = sval; + if (sval<=255) { + SPEC_NOUN(val->type)=V_CHAR; + } + } + } + } + return val; +} + /*-----------------------------------------------------------------*/ /* valueFromLit - creates a value from a literal */ /*-----------------------------------------------------------------*/ @@ -337,9 +392,9 @@ value * constFloatVal (char *s) { value *val = newValue (); - float sval; + double sval; - if (sscanf (s, "%f", &sval) != 1) + if (sscanf (s, "%lf", &sval) != 1) { werror (E_INVALID_FLOAT_CONST, s); return constVal ("0"); @@ -355,31 +410,24 @@ constFloatVal (char *s) } /*-----------------------------------------------------------------*/ -/* constVal - converts a INTEGER constant into a value */ +/* constVal - converts an INTEGER constant into a cheapest value */ /*-----------------------------------------------------------------*/ -value * -constVal (char *s) +value *constVal (char *s) { value *val; short hex = 0, octal = 0; char scanFmt[10]; int scI = 0; - unsigned long sval; + double dval; val = newValue (); /* alloc space for value */ val->type = val->etype = newLink (); /* create the spcifier */ val->type->class = SPECIFIER; - SPEC_NOUN (val->type) = V_INT; SPEC_SCLS (val->type) = S_LITERAL; - - /* set the _unsigned flag if 'uU' found */ - if (strchr (s, 'u') || strchr (s, 'U')) - SPEC_USIGN (val->type) = 1; - - /* set the _long flag if 'lL' is found */ - if (strchr (s, 'l') || strchr (s, 'L')) - SPEC_LONG (val->type) = 1; + // let's start with an unsigned char + SPEC_NOUN (val->type) = V_CHAR; + SPEC_USIGN (val->type) = 1; hex = ((strchr (s, 'x') || strchr (s, 'X')) ? 1 : 0); @@ -390,49 +438,72 @@ constVal (char *s) /* create the scan string */ scanFmt[scI++] = '%'; + scanFmt[scI++] = 'l'; + if (octal) scanFmt[scI++] = 'o'; else if (hex) scanFmt[scI++] = 'x'; - else if (SPEC_USIGN (val->type)) - scanFmt[scI++] = 'u'; else - scanFmt[scI++] = 'd'; + scanFmt[scI++] = 'f'; scanFmt[scI++] = '\0'; - /* if hex or octal then set the unsigned flag */ - if (hex || octal) - { - SPEC_USIGN (val->type) = 1; - sscanf (s, scanFmt, &sval); + if (octal || hex) { + unsigned long sval; + sscanf (s, scanFmt, &sval); + dval=sval; + } else { + sscanf (s, scanFmt, &dval); + } + + /* Setup the flags first */ + /* set the _long flag if 'lL' is found */ + if (strchr (s, 'l') || strchr (s, 'L')) { + SPEC_NOUN (val->type) = V_INT; + SPEC_LONG (val->type) = 1; + } + + if (dval<0) { // "-28u" will still be signed and negative + SPEC_USIGN (val->type) = 0; + if (dval<-128) { // check if we have to promote to int + SPEC_NOUN (val->type) = V_INT; } - else - sval = atol (s); + if (dval<-32768) { // check if we have to promote to long int + SPEC_LONG (val->type) = 1; + } + } else { // >=0 + if (dval>0xff) { // check if we have to promote to int + SPEC_NOUN (val->type) = V_INT; + } + if (dval>0xffff) { // check if we have to promote to long int + SPEC_LONG (val->type) = 1; + } + } - // check if we have to promote to long - if (SPEC_LONG (val->type) || - (SPEC_USIGN(val->type) && sval>0xffff) || - (!SPEC_USIGN(val->type) && ((long)sval>32767 || (long)sval<-32768))) { + if (SPEC_LONG (val->type)) + { if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = sval; + { + SPEC_CVAL (val->type).v_ulong = dval; + } else - SPEC_CVAL (val->type).v_long = sval; - SPEC_LONG (val->type) = 1; - return val; + { + SPEC_CVAL (val->type).v_long = dval; + } } - - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_uint = sval; else - SPEC_CVAL (val->type).v_int = sval; - - - // check if we can make it a char - if ((SPEC_USIGN(val->type) && sval < 256) || - (!SPEC_USIGN(val->type) && ((long)sval<127 && (long)sval>-128))) { - SPEC_NOUN (val->etype) = V_CHAR; - } + { + if (SPEC_USIGN (val->type)) + { + SPEC_CVAL (val->type).v_uint = dval; + } + else + { + SPEC_CVAL (val->type).v_int = dval; + } + } + return val; } @@ -441,40 +512,34 @@ constVal (char *s) /param src Pointer to 'x' from start of hex character value */ -char hexEscape(char **src) - +unsigned char hexEscape(char **src) { -char *s ; -unsigned long value ; - -(*src)++ ; /* Skip over the 'x' */ -s = *src ; /* Save for error detection */ - -value = strtol (*src, src, 16); - -if (s == *src) - { - // no valid hex found - werror(E_INVALID_HEX); - } - -else - { - if (value > 255) - { - werror(W_ESC_SEQ_OOR_FOR_CHAR); + char *s ; + unsigned long value ; + + (*src)++ ; /* Skip over the 'x' */ + s = *src ; /* Save for error detection */ + + value = strtol (*src, src, 16); + + if (s == *src) { + // no valid hex found + werror(E_INVALID_HEX); + } else { + if (value > 255) { + werror(W_ESC_SEQ_OOR_FOR_CHAR); } } - -return (char) value; + return (char) value; } + /*------------------------------------------------------------------*/ /* octalEscape - process an octal constant of max three digits */ /* return the octal value, throw a warning for illegal octal */ /* adjust src to point at the last proccesed char */ /*------------------------------------------------------------------*/ -char octalEscape (char **str) { +unsigned char octalEscape (char **str) { int digits; unsigned value=0; @@ -604,7 +669,7 @@ strVal (char *s) SPEC_NOUN (val->etype) = V_CHAR; SPEC_SCLS (val->etype) = S_LITERAL; - SPEC_CVAL (val->etype).v_char = Safe_calloc (1, strlen (s) + 1); + SPEC_CVAL (val->etype).v_char = Safe_alloc (strlen (s) + 1); DCL_ELEM (val->type) = copyStr (SPEC_CVAL (val->etype).v_char, s); return val; @@ -681,7 +746,7 @@ copyValueChain (value * src) } /*------------------------------------------------------------------*/ -/* copyValue - copies contents of a vlue to a fresh one */ +/* copyValue - copies contents of a value to a fresh one */ /*------------------------------------------------------------------*/ value * copyValue (value * src) @@ -711,6 +776,7 @@ charVal (char *s) val->type = val->etype = newLink (); val->type->class = SPECIFIER; SPEC_NOUN (val->type) = V_CHAR; + SPEC_USIGN(val->type) = 1; SPEC_SCLS (val->type) = S_LITERAL; s++; /* get rid of quotation */ @@ -762,20 +828,20 @@ charVal (char *s) case '5' : case '6' : case '7' : - SPEC_CVAL (val->type).v_int = octalEscape(&s); + SPEC_CVAL (val->type).v_uint = octalEscape(&s); break; case 'x': - SPEC_CVAL (val->type).v_int = hexEscape(&s) ; + SPEC_CVAL (val->type).v_uint = hexEscape(&s) ; break; default: - SPEC_CVAL (val->type).v_int = *s; + SPEC_CVAL (val->type).v_uint = (unsigned char)*s; break; } } else /* not a backslash */ - SPEC_CVAL (val->type).v_int = *s; + SPEC_CVAL (val->type).v_uint = (unsigned char)*s; return val; } @@ -793,7 +859,7 @@ valFromType (sym_link * type) } /*------------------------------------------------------------------*/ -/* floatFromVal - value to unsinged integer conversion */ +/* floatFromVal - value to double float conversion */ /*------------------------------------------------------------------*/ double floatFromVal (value * val) @@ -814,28 +880,42 @@ 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; + } + + 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; + } + + // we are lost ! + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "floatFromVal: unknown value"); + return 0; } /*------------------------------------------------------------------*/ -/* valUnaryPM - dones the unary +/- operation on a constant */ +/* valUnaryPM - does the unary +/- operation on a constant */ /*------------------------------------------------------------------*/ value * valUnaryPM (value * val) @@ -860,8 +940,9 @@ valUnaryPM (value * val) SPEC_CVAL (val->etype).v_int = -SPEC_CVAL (val->etype).v_int; } } + // -(unsigned 3) now really is signed + SPEC_USIGN(val->etype)=0; return val; - } /*------------------------------------------------------------------*/ @@ -927,8 +1008,8 @@ valMult (value * lval, value * rval) SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) || IS_FLOAT (rval->etype) ? V_FLOAT : V_INT); SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); - SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); + SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) & SPEC_USIGN (rval->etype)); + SPEC_LONG (val->type) = 1; if (IS_FLOAT (val->type)) SPEC_CVAL (val->type).v_float = floatFromVal (lval) * floatFromVal (rval); @@ -943,17 +1024,8 @@ valMult (value * lval, value * rval) SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) * (long) floatFromVal (rval); } - else - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) * - (unsigned) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) * - (int) floatFromVal (rval); - } } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -972,12 +1044,12 @@ valDiv (value * lval, value * rval) /* create a new value */ val = newValue (); - val->type = val->etype = ((floatFromVal (lval) / floatFromVal (rval)) < 256 ? - newCharLink () : newIntLink ()); - if (IS_FLOAT (lval->etype) || IS_FLOAT (rval->etype)) - SPEC_NOUN (val->etype) = V_FLOAT; + val->type = val->etype = newLink(); + val->type->class = SPECIFIER; + SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) || + IS_FLOAT (rval->etype) ? V_FLOAT : V_INT); SPEC_SCLS (val->etype) = S_LITERAL; - SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); + SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) & SPEC_USIGN (rval->etype)); SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); if (IS_FLOAT (val->type)) @@ -987,7 +1059,8 @@ valDiv (value * lval, value * rval) if (SPEC_LONG (val->type)) { if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) / + SPEC_CVAL (val->type).v_ulong = + (unsigned long) floatFromVal (lval) / (unsigned long) floatFromVal (rval); else SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) / @@ -995,15 +1068,16 @@ valDiv (value * lval, value * rval) } else { - if (SPEC_USIGN (val->type)) + if (SPEC_USIGN (val->type)) { SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) / (unsigned) floatFromVal (rval); - else + } else { SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) / (int) floatFromVal (rval); + } } } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -1020,7 +1094,7 @@ valMod (value * lval, value * rval) val->type->class = SPECIFIER; SPEC_NOUN (val->type) = V_INT; /* type is int */ SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); + SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) & SPEC_USIGN (rval->etype)); SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); if (SPEC_LONG (val->type)) @@ -1034,15 +1108,16 @@ valMod (value * lval, value * rval) } else { - if (SPEC_USIGN (val->type)) + if (SPEC_USIGN (val->type)) { SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) % (unsigned) floatFromVal (rval); - else + } else { SPEC_CVAL (val->type).v_int = (unsigned) floatFromVal (lval) % (unsigned) floatFromVal (rval); + } } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -1060,8 +1135,12 @@ valPlus (value * lval, value * rval) SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) || IS_FLOAT (rval->etype) ? V_FLOAT : V_INT); SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); - SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); + SPEC_USIGN (val->type) = + SPEC_USIGN (lval->etype) && + SPEC_USIGN (rval->etype) && + (floatFromVal(lval)+floatFromVal(rval))>=0; + + SPEC_LONG (val->type) = 1; if (IS_FLOAT (val->type)) SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval); @@ -1076,17 +1155,8 @@ valPlus (value * lval, value * rval) SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) + (long) floatFromVal (rval); } - else - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) + - (unsigned) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) + - (int) floatFromVal (rval); - } } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -1104,7 +1174,11 @@ valMinus (value * lval, value * rval) SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) || IS_FLOAT (rval->etype) ? V_FLOAT : V_INT); SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); + SPEC_USIGN (val->type) = + SPEC_USIGN (lval->etype) && + SPEC_USIGN (rval->etype) && + (floatFromVal(lval)-floatFromVal(rval))>=0; + SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); if (IS_FLOAT (val->type)) @@ -1113,23 +1187,27 @@ valMinus (value * lval, value * rval) { if (SPEC_LONG (val->type)) { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) - + if (SPEC_USIGN (val->type)) { + SPEC_CVAL (val->type).v_ulong = + (unsigned long) floatFromVal (lval) - (unsigned long) floatFromVal (rval); - else + } else { SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) - (long) floatFromVal (rval); + } } else { - if (SPEC_USIGN (val->type)) + if (SPEC_USIGN (val->type)) { SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) - (unsigned) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) - (int) floatFromVal (rval); + } else { + SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) - + (int) floatFromVal (rval); + } } } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -1142,57 +1220,24 @@ valShift (value * lval, value * rval, int lr) /* create a new value */ val = newValue (); - val->type = val->etype = newLink (); - val->type->class = SPECIFIER; - SPEC_NOUN (val->type) = V_INT; /* type is int */ + val->type = val->etype = newIntLink (); SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ - SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) | SPEC_USIGN (rval->etype)); - SPEC_LONG (val->type) = (SPEC_LONG (lval->etype) | SPEC_LONG (rval->etype)); + SPEC_USIGN (val->type) = (SPEC_USIGN (lval->etype) & SPEC_USIGN (rval->etype)); + SPEC_LONG (val->type) = 1; - if (lr) - { - if (SPEC_LONG (val->type)) - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) << - (unsigned long) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) << - (long) floatFromVal (rval); - } - else - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) << - (unsigned) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) << - (int) floatFromVal (rval); - } - } - else + if (SPEC_LONG (val->type)) { - if (SPEC_LONG (val->type)) - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_ulong = (unsigned long) floatFromVal (lval) >> - (unsigned long) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_long = (long) floatFromVal (lval) >> - (long) floatFromVal (rval); - } + if (SPEC_USIGN (val->type)) + SPEC_CVAL (val->type).v_ulong = lr ? + (unsigned long) floatFromVal (lval) << (unsigned long) floatFromVal (rval) : \ + (unsigned long) floatFromVal (lval) >> (unsigned long) floatFromVal (rval); else - { - if (SPEC_USIGN (val->type)) - SPEC_CVAL (val->type).v_uint = (unsigned) floatFromVal (lval) >> - (unsigned) floatFromVal (rval); - else - SPEC_CVAL (val->type).v_int = (int) floatFromVal (lval) >> - (int) floatFromVal (rval); - } + SPEC_CVAL (val->type).v_long = lr ? + (long) floatFromVal (lval) << (long) floatFromVal (rval) : \ + (long) floatFromVal (lval) >> (long) floatFromVal (rval); } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -1207,7 +1252,8 @@ valCompare (value * lval, value * rval, int ctype) val = newValue (); val->type = val->etype = newCharLink (); val->type->class = SPECIFIER; - SPEC_NOUN (val->type) = V_INT; /* type is int */ + SPEC_NOUN (val->type) = V_CHAR; /* type is char */ + SPEC_USIGN (val->type) = 1; SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ switch (ctype) @@ -1320,7 +1366,7 @@ valBitwise (value * lval, value * rval, int op) break; } - return val; + return cheapestVal(val); } /*------------------------------------------------------------------*/ @@ -1336,6 +1382,7 @@ valLogicAndOr (value * lval, value * rval, int op) val->type = val->etype = newCharLink (); val->type->class = SPECIFIER; SPEC_SCLS (val->type) = S_LITERAL; /* will remain literal */ + SPEC_USIGN (val->type) = 0; switch (op) { @@ -1368,31 +1415,27 @@ valCastLiteral (sym_link * dtype, double fval) SPEC_SCLS (val->etype) = S_LITERAL; /* if it is not a specifier then we can assume that */ /* it will be an unsigned long */ - if (!IS_SPEC (val->type)) - { + if (!IS_SPEC (val->type)) { SPEC_CVAL (val->etype).v_ulong = (unsigned long) fval; return val; - } + } if (SPEC_NOUN (val->etype) == V_FLOAT) - SPEC_CVAL (val->etype).v_float = fval; - else - { - if (SPEC_LONG (val->etype)) - { + SPEC_CVAL (val->etype).v_float = fval; + else { + unsigned long l = fval; + if (SPEC_LONG (val->etype)) { if (SPEC_USIGN (val->etype)) - SPEC_CVAL (val->etype).v_ulong = (unsigned long) fval; + SPEC_CVAL (val->etype).v_ulong = (unsigned long) l; else - SPEC_CVAL (val->etype).v_long = (long) fval; - } - else - { + SPEC_CVAL (val->etype).v_long = (long) l; + } else { if (SPEC_USIGN (val->etype)) - SPEC_CVAL (val->etype).v_uint = (unsigned int) fval; + SPEC_CVAL (val->etype).v_uint = (unsigned short)l; else - SPEC_CVAL (val->etype).v_int = (int) fval; - } - } + SPEC_CVAL (val->etype).v_int = (short)l; + } + } return val; } @@ -1419,7 +1462,7 @@ getNelements (sym_link * type, initList * ilist) value *v = (iast->type == EX_VALUE ? iast->opval.val : NULL); if (!v) { - werror (E_INIT_WRONG); + werror (W_INIT_WRONG); return 0; }