ide/debugger/watches: Improved + and - pointer operations
authorJerome St-Louis <jerome@ecere.com>
Mon, 19 May 2014 00:57:41 +0000 (20:57 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 19 May 2014 01:07:22 +0000 (21:07 -0400)
- Fixed potential regressions on: (Expression *)((byte *)newExp + (uint)((byte *)memberExpPtr - (byte *)exp))
- Fixed pointer addresses to always print as hex and small differences to print as decimal (e.g.  (Expression *)(memberExpPtr + 1))
- Proper handling of negative differences
- Fixed handling of offset on the left side operand

compiler/bootstrap/libec/bootstrap/pass15.c
compiler/libec/src/pass15.ec
ide/src/debugger/Debugger.ec
ide/src/debugger/debugTools.ec

index df084c3..0260064 100644 (file)
@@ -1526,9 +1526,11 @@ char * PrintHexUInt(uint64 result)
 char temp[100];
 
 if(result > (0xffffffff))
-sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "0x%I64XLL" : "0x%llXLL"), result);
+sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "0x%I64X" : "0x%llX"), result);
 else
 sprintf(temp, ((__ecereNameSpace__ecere__com__GetRuntimePlatform() == 1) ? "0x%I64X" : "0x%llX"), result);
+if(result > (0xffffffff))
+strcat(temp, "LL");
 return __ecereNameSpace__ecere__sys__CopyString(temp);
 }
 
index 704bd72..25e9b65 100644 (file)
@@ -243,9 +243,11 @@ public char * PrintHexUInt(uint64 result)
 {
    char temp[100];
    if(result > MAXDWORD)
-      sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
+      sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
    else
       sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
+   if(result > MAXDWORD)
+      strcat(temp, "LL");
    return CopyString(temp);
 }
 
index b89f538..233e153 100644 (file)
@@ -193,7 +193,7 @@ static void strescpy(char * d, char * s)
    d[k] = '\0';
 }
 
-static char * CopyUnescapedSystemPath(char * p)
+/*static char * CopyUnescapedSystemPath(char * p)
 {
    int len = strlen(p);
    char * d = new char[len + 1];
@@ -202,7 +202,7 @@ static char * CopyUnescapedSystemPath(char * p)
    ChangeCh(d, '/', '\\');
 #endif
    return d;
-}
+}*/
 
 static char * CopyUnescapedUnixPath(char * p)
 {
@@ -249,7 +249,7 @@ static char * StripCurlies(char * string)
       return string;
 }
 
-static int StringGetInt(char * string, int start)
+/*static int StringGetInt(char * string, int start)
 {
    char number[8];
    int i, len = strlen(string);
@@ -262,7 +262,7 @@ static int StringGetInt(char * string, int start)
          break;
    }
    return atoi(number);
-}
+}*/
 
 static int TokenizeList(char * string, const char seperator, Array<char *> tokens)
 {
index fdd5439..da91746 100644 (file)
@@ -1199,27 +1199,39 @@ void DebugComputeExpression(Expression exp)
                 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
             {
                bool valid = false;
-               // TODO: Support 1 + pointer
-               if((exp.op.op == '+' || exp.op.op == '-') && exp2.expType && op2.type && op2.type.kind == intType)
+               if((exp.op.op == '+' || exp.op.op == '-') && (op2.type || op1.type))
                {
-                  Expression e = exp1;
-                  while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
+                  Expression e1 = exp1, e2 = exp2;
+                  while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
                   {
-                     if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
+                     if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
                      {
-                        if(e.type == extensionCompoundExp)
-                           e = ((Statement)e.compound.compound.statements->last).expressions->last;
+                        if(e1.type == extensionCompoundExp)
+                           e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
                         else
-                           e = e.list->last;
+                           e1 = e1.list->last;
                      }
-                     else if(e.type == castExp)
-                        e = e.cast.exp;
+                     else if(e1.type == castExp)
+                        e1 = e1.cast.exp;
+                  }
+                  while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
+                  {
+                     if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
+                     {
+                        if(e2.type == extensionCompoundExp)
+                           e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
+                        else
+                           e2 = e2.list->last;
+                     }
+                     else if(e2.type == castExp)
+                        e2 = e2.cast.exp;
                   }
 
-                  if(e.type == stringExp)
+                  if((e1.type == stringExp && op2.type && op2.type.kind == intType) || (e2.type == stringExp && op1.type && op1.type.kind == intType))
                   {
-                     uint64 offset = (exp.op.op == '+') ? op2.i64 : -op2.i64;
+                     uint64 offset = ((exp.op.op == '+') ? 1 : -1) * (e1.type == stringExp ? op2.i64 : op1.i64);
                      String newString = null;
+                     Expression e = e1.type == stringExp ? e1 : e2;
                      if(e.string)
                      {
                         int len = strlen(e.string) - 2;
@@ -1244,24 +1256,45 @@ void DebugComputeExpression(Expression exp)
                      else
                         exp.type = dereferenceErrorExp;
                   }
-                  else if(op1.type)
+                  // Can't add 2 pointers...
+                  else if(exp.op.op != '+' ||
+                     !((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) &&
+                       (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
                   {
-                     // TODO: Do pointer operations
-                     if(exp1.expType && exp1.expType.type)
+                     bool op1IsPointer = exp1.expType.kind == pointerType || exp1.expType.kind == arrayType;
+                     bool op2IsPointer = exp2.expType.kind == pointerType || exp2.expType.kind == arrayType;
+                     bool addressResult = !op1IsPointer || !op2IsPointer;
+                     uint size;
+                     int op = exp.op.op;
+                     valid = true;
+                     if(op1IsPointer)
+                        size = ComputeTypeSize(exp1.expType.type);
+                     else if(op2IsPointer)
+                        size = ComputeTypeSize(exp2.expType.type);
+
+                     if(addressResult && size)
                      {
-                        uint size = ComputeTypeSize(exp1.expType.type);
-                        if(size)
+                       if(op1IsPointer) op2.ui64 *= size;
+                       else if(op1IsPointer) op1.ui64 *= size;
+                     }
+
+                     CallOperator(exp, exp1, exp2, op1, op2);
+                     if(exp.type == constantExp)
+                     {
+                        if(addressResult)
                         {
-                           valid = true;
-                           op1.ui64 /= exp1.expType.type.size;
-                           CallOperator(exp, exp1, exp2, op1, op2);
-                           if(exp.type == constantExp)
-                           {
-                              exp.address = _strtoui64(exp.constant, null, 0);
-                              exp.address *= size;
-                              if(op1.type.kind == arrayType)
-                                 exp.hasAddress = true;
-                           }
+                           exp.address = _strtoui64(exp.constant, null, 0);
+                           delete exp.constant;
+                           exp.constant = PrintHexUInt64(exp.address);
+                           if(op1.type.kind == arrayType || op2.type.kind == arrayType)
+                              exp.hasAddress = true;
+                        }
+                        else
+                        {
+                           int64 v = _strtoi64(exp.constant, null, 0);
+                           if(size) v /= size;
+                           delete exp.constant;
+                           exp.constant = PrintInt(v);
                         }
                      }
                   }