compiler/libec: Improved handling 64 bit constants
authorJerome St-Louis <jerome@ecere.com>
Wed, 14 May 2014 01:01:42 +0000 (21:01 -0400)
committerJerome St-Louis <jerome@ecere.com>
Wed, 14 May 2014 01:01:42 +0000 (21:01 -0400)
- Fixed 64 bit types to compute using 64 bit operators
- Not printing 0 as 0LL anymore
- Typing 65536LL as 64 bit
- Keeping constant qualifier on named types (e.g. const uint64)

compiler/bootstrap/libec/bootstrap/ast.c
compiler/bootstrap/libec/bootstrap/pass15.c
compiler/libec/src/ast.ec
compiler/libec/src/pass15.ec

index 593cdcd..9349097 100644 (file)
@@ -4161,11 +4161,13 @@ struct Symbol * symbol = spec->name ? FindType(curContext, spec->name) : (((void
 
 if(symbol && symbol->type)
 {
+unsigned int isConstant = specType->constant;
 struct Type * dummy = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Type);
 
 *dummy = *specType;
 FreeType(dummy);
 CopyTypeInto(specType, symbol->type);
+specType->constant = isConstant;
 specType->typeName = __ecereNameSpace__ecere__sys__CopyString(symbol->type->name);
 }
 else if(!isTypedef)
index 7ca7afa..00b10d0 100644 (file)
@@ -1472,16 +1472,20 @@ extern int sprintf(char * , char * , ...);
 
 extern int __ecereNameSpace__ecere__com__GetRuntimePlatform(void);
 
+extern char *  strcat(char * , const char * );
+
 extern char *  __ecereNameSpace__ecere__sys__CopyString(char *  string);
 
 char * PrintInt(long long result)
 {
 char temp[100];
 
-if(result > (((long long)0x7fffffffffffffffLL)))
-sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "0x%I64XLL" : "0x%llXLL"), result);
+if(result > (((int)0x7fffffff)))
+sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "0x%I64X" : "0x%llX"), result);
 else
-sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "%I64dLL" : "%lldLL"), result);
+sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "%I64d" : "%lld"), result);
+if(result > (((int)0x7fffffff)) || result < (((int)0x80000000)))
+strcat(temp, "LL");
 return __ecereNameSpace__ecere__sys__CopyString(temp);
 }
 
@@ -3204,8 +3208,6 @@ classSym->declaring--;
 }
 }
 
-extern char *  strcat(char * , const char * );
-
 extern struct ModuleImport * FindModule(struct __ecereNameSpace__ecere__com__Instance * moduleToFind);
 
 extern struct ModuleImport * mainModule;
@@ -10771,12 +10773,12 @@ case 4:
 if(type->isSigned)
 {
 op.i64 = __ecereNameSpace__ecere__com___strtoi64(exp->constant, (((void *)0)), 0);
-op.ops = intOps;
+op.ops = int64Ops;
 }
 else
 {
 op.ui64 = __ecereNameSpace__ecere__com___strtoui64(exp->constant, (((void *)0)), 0);
-op.ops = uintOps;
+op.ops = uint64Ops;
 }
 op.kind = 4;
 break;
@@ -14124,9 +14126,10 @@ type->isSigned = 0x1;
 else
 {
 unsigned int isSigned = constant[0] == '-';
-long long i64 = strtoll(constant, (((void *)0)), 0);
-uint64 ui64 = strtoull(constant, (((void *)0)), 0);
-unsigned int is64Bit = 0x0;
+char * endP = (((void *)0));
+long long i64 = strtoll(constant, &endP, 0);
+uint64 ui64 = strtoull(constant, &endP, 0);
+unsigned int is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
 
 if(isSigned)
 {
index 206e967..b2c9036 100644 (file)
@@ -2378,12 +2378,15 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
                Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
                if(symbol && symbol.type)
                {
+                  // Keep constant qualifier
+                  bool isConstant = specType.constant;
                   // Free Type Contents:
                   Type dummy { };
                   *dummy = *specType;
                   FreeType(dummy);
 
                   CopyTypeInto(specType, symbol.type);
+                  specType.constant = isConstant;
                   specType.typeName = CopyString(symbol.type.name);
                }
                else if(!isTypedef) // !specType.kind)    // TESTING THIS FOR enum / typedef problem
index 1d2837c..9a61162 100644 (file)
@@ -201,10 +201,12 @@ static void ReplaceClassMembers(Expression exp, Class _class)
 public char * PrintInt(int64 result)
 {
    char temp[100];
-   if(result > MAXINT64)
-      sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
+   if(result > MAXINT)
+      sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
    else
-      sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
+      sprintf(temp, FORMAT64D /*"%I64d"*/, result);
+   if(result > MAXINT || result < MININT)
+      strcat(temp, "LL");
    return CopyString(temp);
 }
 
@@ -4354,12 +4356,12 @@ public Operand GetOperand(Expression exp)
                if(type.isSigned)
                {
                   op.i64 = (int64)_strtoi64(exp.constant, null, 0);
-                  op.ops = intOps;
+                  op.ops = int64Ops;
                }
                else
                {
                   op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
-                  op.ops = uintOps;
+                  op.ops = uint64Ops;
                }
                op.kind = int64Type;
                break;
@@ -5130,17 +5132,17 @@ static bool Promote(Operand op, TypeKind kind, bool isSigned)
       case int64Type:
          if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
             op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
-         result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
+            result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
          break;
       case floatType:
          if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
             op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
-         result = GetOpFloat(op, &op.f);
+            result = GetOpFloat(op, &op.f);
          break;
       case doubleType:
          if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
             op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
-         result = GetOpDouble(op, &op.d);
+            result = GetOpDouble(op, &op.d);
          break;
       case pointerType:
          if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
@@ -7873,9 +7875,10 @@ void ProcessExpressionType(Expression exp)
                else
                {
                   bool isSigned = constant[0] == '-';
-                  int64 i64 = strtoll(constant, null, 0);
-                  uint64 ui64 = strtoull(constant, null, 0);
-                  bool is64Bit = false;
+                  char * endP = null;
+                  int64 i64 = strtoll(constant, &endP, 0);
+                  uint64 ui64 = strtoull(constant, &endP, 0);
+                  bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
                   if(isSigned)
                   {
                      if(i64 < MININT)