more fixes for the constant values
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 11 Oct 2001 11:51:14 +0000 (11:51 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 11 Oct 2001 11:51:14 +0000 (11:51 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1386 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCsymt.h
src/SDCCval.c

index 47bf56b58af963b294539bb7139e50155cdcf31a..b253154f955047f3d373b21e07778de117e012bc 100644 (file)
@@ -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 */
index bf97fabfa121549cdeee3adea9ed390ebb54e61c..819b8144e0ed6af3ac8274f8ab35a14c02572aba 100644 (file)
@@ -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;