bring back in a huge optimization
[fw/sdcc] / src / SDCCval.c
index 6d645ee200cfa4010ebe33ed34364520ce58b9ff..3b711c542394f3e45221643addc746e70f04d0d7 100644 (file)
 #include <limits.h>
 #include "newalloc.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define LONG_LONG __int64
-#else
-#define LONG_LONG long long
-#endif
-
 int cNestLevel;
 
 /*-----------------------------------------------------------------*/
@@ -425,7 +419,7 @@ value *constVal (char *s)
   short hex = 0, octal = 0;
   char scanFmt[10];
   int scI = 0;
-  LONG_LONG sval;
+  long sval;
 
   val = newValue ();           /* alloc space for value   */
 
@@ -436,10 +430,6 @@ value *constVal (char *s)
   SPEC_NOUN (val->type) = V_CHAR;
   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;
-
   hex = ((strchr (s, 'x') || strchr (s, 'X')) ? 1 : 0);
 
   /* set the octal flag   */
@@ -449,7 +439,6 @@ value *constVal (char *s)
   /* create the scan string */
   scanFmt[scI++] = '%';
 
-  scanFmt[scI++] = 'l';
   scanFmt[scI++] = 'l';
 
   if (octal)
@@ -463,14 +452,17 @@ value *constVal (char *s)
 
   sscanf (s, scanFmt, &sval);
 
+  /* Setup the flags first */
+  /* set the _long flag if 'lL' is found */
+  if (strchr (s, 'l') || strchr (s, 'L'))
+    SPEC_LONG (val->type) = 1;
+
   if (sval<0) { // "-28u" will still be signed and negative
     SPEC_USIGN (val->type) = 0;
     if (sval<-32768) { // check if we have to promote to long
       SPEC_NOUN (val->type) = V_INT;
       SPEC_LONG (val->type) = 1;
-      SPEC_CVAL (val->type).v_long=sval;
     } else {
-      SPEC_CVAL (val->type).v_int=sval;
       if (sval<-128) { // check if we have to promote to int
        SPEC_NOUN (val->type) = V_INT;
       }
@@ -479,15 +471,36 @@ value *constVal (char *s)
     if (sval>0xffff) { // check if we have to promote to long
       SPEC_NOUN (val->type) = V_INT;
       SPEC_LONG (val->type) = 1;
-      SPEC_CVAL (val->type).v_ulong=sval;
     } else {
-      SPEC_CVAL (val->type).v_uint=sval;
       if (sval>0xff) { // check if we have to promote to int
        SPEC_NOUN (val->type) = V_INT;
       }
     }
   }
 
+  if (SPEC_LONG (val->type))
+    {
+      if (SPEC_USIGN (val->type))
+        {
+          SPEC_CVAL (val->type).v_ulong = sval;
+        }
+      else
+        {
+          SPEC_CVAL (val->type).v_long = sval;
+        }
+    }
+  else
+    {
+      if (SPEC_USIGN (val->type))
+        {
+          SPEC_CVAL (val->type).v_uint = sval;
+        }
+      else
+        {
+          SPEC_CVAL (val->type).v_int = sval;
+        }
+    }
+
   return val;
 }