ide/debugger/watches: Fixed evaluating casted indexed arrays
[sdk] / ide / src / debugger / debugTools.ec
index 12b7d64..e7a0815 100644 (file)
@@ -1,7 +1,5 @@
 import "ide"
 
-#include <math.h>
-
 static Map<String, uintptr> oneArgFns
 { [
    { "sqrt", (uintptr)sqrt },
@@ -23,7 +21,6 @@ static Map<String, uintptr> oneArgFns
    { "floor", (uintptr)floor },
    { "ceil", (uintptr)ceil },
    { "fabs", (uintptr)sqrt }
-
 ] };
 
 static Map<String, uintptr> twoArgFns
@@ -157,11 +154,27 @@ void DebugComputeExpression(Expression exp)
          Expression expNew;
          TypeKind kind = dummyType;
          Type dataType = exp.expType;
-
-         char temp[1024];
-         uint64 address;
+         uint64 address = 0;
          bool hasAddress;
          bool isPointer = false;
+         bool evaluate = false;
+         bool evaluateAddress = false;
+         String idString = null;
+         if(exp.identifier.string)
+         {
+            const String start = (exp.identifier.string[0] == ':' && exp.identifier.string[1] == ':') ? exp.identifier.string + 2 : exp.identifier.string;
+            if(strstr(start, "::"))
+            {
+               char prefix[] = "__ecereNameSpace__";
+               int len = strlen(start);
+               idString = new char[len + sizeof(prefix)];
+               memcpy(idString, prefix, sizeof(prefix) - 1);
+               memcpy(idString + sizeof(prefix) - 1, start, len + 1);
+               ChangeCh(idString + sizeof(prefix) - 1, ':', '_');
+            }
+            else
+               idString = CopyString(exp.identifier.string);
+         }
 
          if(dataType && dataType.kind == classType && dataType._class.registered)
          {
@@ -183,7 +196,6 @@ void DebugComputeExpression(Expression exp)
             kind = dataType.kind;
          else
             exp.type = symbolErrorExp;
-         temp[0] = '\0';
          switch(kind)
          {
             case intPtrType: case intSizeType: case _BoolType:
@@ -193,14 +205,16 @@ void DebugComputeExpression(Expression exp)
             case structType:
             case pointerType:
             case unionType:
-               sprintf(temp, "&%s", exp.identifier.string);
+               evaluate = true;
+               evaluateAddress = true;
                break;
             case classType:
                if(exp.byReference && dataType._class && dataType._class.registered && dataType._class.registered.type == structClass)
                // if(!dataType._class || !dataType._class.registered || dataType._class.registered.type != structClass || exp.byReference)
-                  strcpy(temp, exp.identifier.string);
+                  evaluateAddress = false;
                else
-                  sprintf(temp, "&%s", exp.identifier.string);
+                  evaluateAddress = true;
+               evaluate = true;
                break;
             case functionType:
             case ellipsisType:
@@ -210,8 +224,17 @@ void DebugComputeExpression(Expression exp)
             case dummyType:
                break;
          }
-         if(temp[0])
+         if(evaluate)
          {
+            char temp[1024];
+            if(evaluateAddress)
+            {
+               temp[0] = '&';
+               strcpy(temp + 1, idString);
+            }
+            else
+               strcpy(temp, idString);
+
             evaluation = Debugger::EvaluateExpression(temp, &evalError);
             if(evaluation)
             {
@@ -232,7 +255,7 @@ void DebugComputeExpression(Expression exp)
             {
                case charType:
                   delete evaluation;
-                  evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
+                  evaluation = Debugger::EvaluateExpression(idString, &evalError);
                   if(evaluation)
                   {
                      //int c, len;
@@ -260,7 +283,7 @@ void DebugComputeExpression(Expression exp)
                case enumType:
                case pointerType:
                   delete evaluation;
-                  evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
+                  evaluation = Debugger::EvaluateExpression(idString, &evalError);
                   if(evaluation)
                   {
                      if(kind == pointerType)
@@ -278,7 +301,7 @@ void DebugComputeExpression(Expression exp)
                      int size;
                      char format;
                      delete evaluation;
-                     //evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
+                     //evaluation = Debugger::EvaluateExpression(idString, &evalError);
                      size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
                      format = GetGdbFormatChar(exp.expType);
                      evaluation = Debugger::ReadMemory(address, size, format, &evalError);
@@ -289,14 +312,14 @@ void DebugComputeExpression(Expression exp)
                case structType:
                case unionType:
                case functionType:
-                  //evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
+                  //evaluation = Debugger::EvaluateExpression(idString, &evalError);
                   delete evaluation;
                   break;
                case arrayType:
                {
                   // for classType  --> if(_class.type == structClass) ?
                   //char temp[1024];
-                  //sprintf(temp, "&%s", exp.identifier.string);
+                  //sprintf(temp, "&%s", idString);
                   //evaluation = Debugger::EvaluateExpression(temp, &evalError);
                   break;
                }
@@ -306,15 +329,18 @@ void DebugComputeExpression(Expression exp)
                // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
                case dummyType:
                   delete evaluation;
-                  evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
+                  evaluation = Debugger::EvaluateExpression(idString, &evalError);
                   break;
             }
          }
          switch(evalError)
          {
             case dummyExp:
-               if(evaluation)
+               if(evaluation && (exp.type != symbolErrorExp || !exp.identifier || !idString || strcmp(evaluation, idString)))
                {
+                  char * lt = strchr(evaluation, '<');
+                  if(lt) *lt = 0;
+
                   // Going back to parsing the expression string so as to catch inf/-inf/nan/-nan etc.
                   expNew = ParseExpressionString(evaluation);
                   //expNew = MkExpConstant(evaluation);
@@ -327,6 +353,13 @@ void DebugComputeExpression(Expression exp)
                   {
                      expNew.expType = expNew.destType;
                      expNew.destType.refCount++;
+                     // For negative values parsed as opExp
+                     if(expNew.type == opExp && expNew.op.op == '-' && !expNew.op.exp1 && expNew.op.exp2)
+                     {
+                        expNew.op.exp2.expType = expNew.destType;
+                        expNew.destType.refCount++;
+                        expNew.op.exp2.isConstant = true;
+                     }
                   }
                   else
                      ProcessExpressionType(expNew);
@@ -362,7 +395,456 @@ void DebugComputeExpression(Expression exp)
       }
       case instanceExp:
       {
-         ComputeInstantiation(exp);
+         Instantiation inst = exp.instance;
+         MembersInit members;
+         Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
+         Class _class = classSym ? classSym.registered : null;
+         DataMember curMember = null;
+         Class curClass = null;
+         DataMember subMemberStack[256];
+         int subMemberStackPos = 0;
+         uint64 bits = 0;
+
+         if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
+         {
+            // Don't recompute the instantiation...
+            // Non Simple classes will have become constants by now
+            if(inst.data)
+               return;
+
+            if(_class.type == normalClass || _class.type == noHeadClass)
+            {
+               inst.data = (byte *)eInstance_New(_class);
+               if(_class.type == normalClass)
+                  ((Instance)inst.data)._refCount++;
+            }
+            else
+               inst.data = new0 byte[_class.structSize];
+         }
+
+         if(inst.members)
+         {
+            for(members = inst.members->first; members; members = members.next)
+            {
+               switch(members.type)
+               {
+                  case dataMembersInit:
+                  {
+                     if(members.dataMembers)
+                     {
+                        MemberInit member;
+                        for(member = members.dataMembers->first; member; member = member.next)
+                        {
+                           Identifier ident = member.identifiers ? member.identifiers->first : null;
+                           bool found = false;
+
+                           Property prop = null;
+                           DataMember dataMember = null;
+                           uint dataMemberOffset;
+
+                           if(!ident)
+                           {
+                              eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
+                              if(curMember)
+                              {
+                                 if(curMember.isProperty)
+                                 {
+                                    prop = (Property)curMember; // TOFIX: (eC II ? THe mss
+                                 }
+                                 else
+                                 {
+                                    dataMember = curMember;
+
+                                    // CHANGED THIS HERE
+                                    eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, GetPrivateModule(), null, null);
+
+                                    // 2013/17/29 -- It seems that this was missing here!
+                                    if(_class.type == normalClass)
+                                       dataMemberOffset += _class.base.structSize;
+                                    // dataMemberOffset = dataMember.offset;
+                                 }
+                                 found = true;
+                              }
+                           }
+                           else
+                           {
+                              prop = eClass_FindProperty(_class, ident.string, GetPrivateModule());
+                              if(prop)
+                              {
+                                 found = true;
+                                 if(prop.memberAccess == publicAccess)
+                                 {
+                                    curMember = (DataMember)prop;
+                                    curClass = prop._class;
+                                 }
+                              }
+                              else
+                              {
+                                 DataMember _subMemberStack[256];
+                                 int _subMemberStackPos = 0;
+
+                                 // FILL MEMBER STACK
+                                 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, GetPrivateModule(), _subMemberStack, &_subMemberStackPos);
+
+                                 if(dataMember)
+                                 {
+                                    found = true;
+                                    if(dataMember.memberAccess == publicAccess)
+                                    {
+                                       curMember = dataMember;
+                                       curClass = dataMember._class;
+                                       memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
+                                       subMemberStackPos = _subMemberStackPos;
+                                    }
+                                 }
+                              }
+                           }
+
+                           if(found && member.initializer && member.initializer.type == expInitializer)
+                           {
+                              Expression value = member.initializer.exp;
+                              Type type = null;
+                              bool deepMember = false;
+                              if(prop)
+                              {
+                                 type = prop.dataType;
+                              }
+                              else if(dataMember)
+                              {
+                                 if(!dataMember.dataType)
+                                    dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
+
+                                 type = dataMember.dataType;
+                              }
+
+                              if(ident && ident.next)
+                              {
+                                 deepMember = true;
+
+                                 // for(; ident && type; ident = ident.next)
+                                 for(ident = ident.next; ident && type; ident = ident.next)
+                                 {
+                                    if(type.kind == classType)
+                                    {
+                                       prop = eClass_FindProperty(type._class.registered,
+                                          ident.string, GetPrivateModule());
+                                       if(prop)
+                                          type = prop.dataType;
+                                       else
+                                       {
+                                          dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
+                                             ident.string, &dataMemberOffset, GetPrivateModule(), null, null);
+                                          if(dataMember)
+                                             type = dataMember.dataType;
+                                       }
+                                    }
+                                    else if(type.kind == structType || type.kind == unionType)
+                                    {
+                                       Type memberType;
+                                       for(memberType = type.members.first; memberType; memberType = memberType.next)
+                                       {
+                                          if(!strcmp(memberType.name, ident.string))
+                                          {
+                                             type = memberType;
+                                             break;
+                                          }
+                                       }
+                                    }
+                                 }
+                              }
+                              if(value)
+                              {
+                                 FreeType(value.destType);
+                                 value.destType = type;
+                                 if(type) type.refCount++;
+                                 DebugComputeExpression(value);
+                              }
+                              if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
+                              {
+                                 if(type.kind == classType)
+                                 {
+                                    Class _class = type._class.registered;
+                                    if(_class.type == bitClass || _class.type == unitClass ||
+                                       _class.type == enumClass)
+                                    {
+                                       if(!_class.dataType)
+                                          _class.dataType = ProcessTypeString(_class.dataTypeString, false);
+                                       type = _class.dataType;
+                                    }
+                                 }
+
+                                 if(dataMember)
+                                 {
+                                    void * ptr = inst.data + dataMemberOffset;
+
+                                    if(value.type == constantExp)
+                                    {
+                                       switch(type.kind)
+                                       {
+                                          case intType:
+                                          {
+                                             GetInt(value, (int*)ptr);
+                                             break;
+                                          }
+                                          case int64Type:
+                                          {
+                                             GetInt64(value, (int64*)ptr);
+                                             break;
+                                          }
+                                          case intPtrType:
+                                          {
+                                             GetIntPtr(value, (intptr*)ptr);
+                                             break;
+                                          }
+                                          case intSizeType:
+                                          {
+                                             GetIntSize(value, (intsize*)ptr);
+                                             break;
+                                          }
+                                          case floatType:
+                                          {
+                                             GetFloat(value, (float*)ptr);
+                                             break;
+                                          }
+                                          case doubleType:
+                                          {
+                                             GetDouble(value, (double *)ptr);
+                                             break;
+                                          }
+                                       }
+                                    }
+                                    else if(value.type == instanceExp)
+                                    {
+                                       if(type.kind == classType)
+                                       {
+                                          Class _class = type._class.registered;
+                                          if(_class.type == structClass)
+                                          {
+                                             ComputeTypeSize(type);
+                                             if(value.instance.data)
+                                                memcpy(ptr, value.instance.data, type.size);
+                                          }
+                                       }
+                                    }
+                                 }
+                                 else if(prop)
+                                 {
+                                    if(value.type == instanceExp && value.instance.data)
+                                    {
+                                       if(type.kind == classType)
+                                       {
+                                          Class _class = type._class.registered;
+                                          if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
+                                          {
+                                             void (*Set)(void *, void *) = (void *)prop.Set;
+                                             Set(inst.data, value.instance.data);
+                                             PopulateInstance(inst);
+                                          }
+                                       }
+                                    }
+                                    else if(value.type == constantExp)
+                                    {
+                                       switch(type.kind)
+                                       {
+                                          case doubleType:
+                                          {
+                                             void (*Set)(void *, double) = (void *)prop.Set;
+                                             Set(inst.data, strtod(value.constant, null) );
+                                             break;
+                                          }
+                                          case floatType:
+                                          {
+                                             void (*Set)(void *, float) = (void *)prop.Set;
+                                             Set(inst.data, (float)(strtod(value.constant, null)));
+                                             break;
+                                          }
+                                          case intType:
+                                          {
+                                             void (*Set)(void *, int) = (void *)prop.Set;
+                                             Set(inst.data, (int)strtol(value.constant, null, 0));
+                                             break;
+                                          }
+                                          case int64Type:
+                                          {
+                                             void (*Set)(void *, int64) = (void *)prop.Set;
+                                             Set(inst.data, _strtoi64(value.constant, null, 0));
+                                             break;
+                                          }
+                                          case intPtrType:
+                                          {
+                                             void (*Set)(void *, intptr) = (void *)prop.Set;
+                                             Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
+                                             break;
+                                          }
+                                          case intSizeType:
+                                          {
+                                             void (*Set)(void *, intsize) = (void *)prop.Set;
+                                             Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
+                                             break;
+                                          }
+                                       }
+                                    }
+                                    else if(value.type == stringExp)
+                                    {
+                                       char temp[1024];
+                                       ReadString(temp, value.string);
+                                       ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
+                                    }
+                                 }
+                              }
+                              else if(!deepMember && type && _class.type == unitClass)
+                              {
+                                 if(prop)
+                                 {
+                                    // Only support converting units to units for now...
+                                    if(value.type == constantExp)
+                                    {
+                                       if(type.kind == classType)
+                                       {
+                                          Class _class = type._class.registered;
+                                          if(_class.type == unitClass)
+                                          {
+                                             if(!_class.dataType)
+                                                _class.dataType = ProcessTypeString(_class.dataTypeString, false);
+                                             type = _class.dataType;
+                                          }
+                                       }
+                                       // TODO: Assuming same base type for units...
+                                       switch(type.kind)
+                                       {
+                                          case floatType:
+                                          {
+                                             float fValue;
+                                             float (*Set)(float) = (void *)prop.Set;
+                                             GetFloat(member.initializer.exp, &fValue);
+                                             exp.constant = PrintFloat(Set(fValue));
+                                             exp.type = constantExp;
+                                             break;
+                                          }
+                                          case doubleType:
+                                          {
+                                             double dValue;
+                                             double (*Set)(double) = (void *)prop.Set;
+                                             GetDouble(member.initializer.exp, &dValue);
+                                             exp.constant = PrintDouble(Set(dValue));
+                                             exp.type = constantExp;
+                                             break;
+                                          }
+                                       }
+                                    }
+                                 }
+                              }
+                              else if(!deepMember && type && _class.type == bitClass)
+                              {
+                                 if(prop)
+                                 {
+                                    if(value.type == instanceExp && value.instance.data)
+                                    {
+                                       unsigned int (*Set)(void *) = (void *)prop.Set;
+                                       bits = Set(value.instance.data);
+                                    }
+                                    else if(value.type == constantExp)
+                                    {
+                                    }
+                                 }
+                                 else if(dataMember)
+                                 {
+                                    BitMember bitMember = (BitMember) dataMember;
+                                    Type type;
+                                    int part = 0;
+                                    GetInt(value, &part);
+                                    bits = (bits & ~bitMember.mask);
+                                    if(!bitMember.dataType)
+                                       bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
+
+                                    type = bitMember.dataType;
+
+                                    if(type.kind == classType && type._class && type._class.registered)
+                                    {
+                                       if(!type._class.registered.dataType)
+                                          type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
+                                       type = type._class.registered.dataType;
+                                    }
+
+                                    switch(type.kind)
+                                    {
+                                       case _BoolType:
+                                       case charType:
+                                          if(type.isSigned)
+                                             bits |= ((char)part << bitMember.pos);
+                                          else
+                                             bits |= ((unsigned char)part << bitMember.pos);
+                                          break;
+                                       case shortType:
+                                          if(type.isSigned)
+                                             bits |= ((short)part << bitMember.pos);
+                                          else
+                                             bits |= ((unsigned short)part << bitMember.pos);
+                                          break;
+                                       case intType:
+                                       case longType:
+                                          if(type.isSigned)
+                                             bits |= ((int)part << bitMember.pos);
+                                          else
+                                             bits |= ((unsigned int)part << bitMember.pos);
+                                          break;
+                                       case int64Type:
+                                          if(type.isSigned)
+                                             bits |= ((int64)part << bitMember.pos);
+                                          else
+                                             bits |= ((uint64)part << bitMember.pos);
+                                          break;
+                                       case intPtrType:
+                                          if(type.isSigned)
+                                          {
+                                             bits |= ((intptr)part << bitMember.pos);
+                                          }
+                                          else
+                                          {
+                                             bits |= ((uintptr)part << bitMember.pos);
+                                          }
+                                          break;
+                                       case intSizeType:
+                                          if(type.isSigned)
+                                          {
+                                             bits |= ((ssize_t)(intsize)part << bitMember.pos);
+                                          }
+                                          else
+                                          {
+                                             bits |= ((size_t) (uintsize)part << bitMember.pos);
+                                          }
+                                          break;
+                                    }
+                                 }
+                              }
+                           }
+                           else
+                           {
+                              if(_class && _class.type == unitClass)
+                              {
+                                 DebugComputeExpression(member.initializer.exp);
+                                 exp.constant = member.initializer.exp.constant;
+                                 exp.type = constantExp;
+
+                                 member.initializer.exp.constant = null;
+                              }
+                           }
+                        }
+                     }
+                     break;
+                  }
+               }
+            }
+         }
+         if(_class && _class.type == bitClass)
+         {
+            exp.constant = PrintHexUInt(bits);
+            exp.type = constantExp;
+         }
+         if(exp.type != instanceExp)
+         {
+            FreeInstance(inst);
+         }
          break;
       }
       /*
@@ -372,7 +854,7 @@ void DebugComputeExpression(Expression exp)
       case opExp:
       {
          Expression expError = null;
-         Expression exp1, exp2 = null;
+         Expression exp1 = null, exp2 = null;
          Operand op1 = { 0 }, op2 = { 0 };
 
          /*
@@ -503,6 +985,12 @@ void DebugComputeExpression(Expression exp)
                         if(op2.type) op2.type.refCount++;
                      }
                   }
+                  else
+                  {
+                     exp1 = exp.op.exp1;
+                     op1 = GetOperand(exp1);
+                     if(op1.type) op1.type.refCount++;
+                  }
                }
             }
             else if(exp.op.exp2)
@@ -752,27 +1240,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(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
+                     {
+                        if(e1.type == extensionCompoundExp)
+                           e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
+                        else
+                           e1 = e1.list->last;
+                     }
+                     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(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
+                     if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
                      {
-                        if(e.type == extensionCompoundExp)
-                           e = ((Statement)e.compound.compound.statements->last).expressions->last;
+                        if(e2.type == extensionCompoundExp)
+                           e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
                         else
-                           e = e.list->last;
+                           e2 = e2.list->last;
                      }
-                     else if(e.type == castExp)
-                        e = e.cast.exp;
+                     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;
@@ -780,7 +1280,7 @@ void DebugComputeExpression(Expression exp)
                         if(tmp)
                         {
                            len -= tmp - (e.string + 1);
-                           newString = new char[2 + len];
+                           newString = new char[2 + len + 1];
                            newString[0] = '\"';
                            memcpy(newString + 1, tmp, len);
                            newString[1 + len] = '\"';
@@ -797,24 +1297,44 @@ 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 = 0;
+                     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);
                         }
                      }
                   }
@@ -899,6 +1419,7 @@ void DebugComputeExpression(Expression exp)
             Expression prev = exp.prev, next = exp.next;
             char * evaluation = null;
             ExpressionType evalError = dummyExp;
+            Type dataType = exp.index.exp.expType ? exp.index.exp.expType.type : null;
 
             if(!exp.index.exp.isConstant)
                exp.isConstant = false;
@@ -909,12 +1430,12 @@ void DebugComputeExpression(Expression exp)
             // 4 == size = ComputeTypeSize(exp.index.exp.expType);
             // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
 
-            size = ComputeTypeSize(exp.expType);
-            if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
+            size = ComputeTypeSize(dataType);
+            if(dataType && dataType.type && dataType.kind == arrayType)
                // For multilevels arrays
                format = 'x';
             else
-               format = GetGdbFormatChar(exp.expType);
+               format = GetGdbFormatChar(dataType);
 
             for(e = exp.index.index->first; e; e = e.next)
             {
@@ -1256,7 +1777,7 @@ void DebugComputeExpression(Expression exp)
                convertTo = _class;
                _class = classSym ? classSym.registered : null;
                if(_class)
-                  prop = eClass_FindProperty(_class, convertTo.name, _class.module.application);
+                  prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
             }
 
             //DebugComputeExpression(memberExp);
@@ -1293,24 +1814,25 @@ void DebugComputeExpression(Expression exp)
                            case floatType:
                            {
                               float value;
-                              float (*Get)(float) = (void *)prop.Get;
+                              float (*Get)(float) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
                               GetFloat(memberExp, &value);
+
+                              FreeExpContents(exp);
                               exp.constant = PrintFloat(Get ? Get(value) : value);
                               exp.type = constantExp;
+                              exp.isConstant = true;
                               supported = true;
                               break;
                            }
                            case doubleType:
                            {
                               double value;
-                              double (*Get)(double);
+                              double (*Get)(double) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
                               GetDouble(memberExp, &value);
 
-                              if(convertTo)
-                                 Get = (void *)prop.Set;
-                              else
-                                 Get = (void *)prop.Get;
+                              FreeExpContents(exp);
                               exp.constant = PrintDouble(Get ? Get(value) : value);
+                              exp.isConstant = true;
                               exp.type = constantExp;
                               supported = true;
                               break;
@@ -1323,6 +1845,8 @@ void DebugComputeExpression(Expression exp)
                         {
                            Expression value = memberExp;
                            Type type = prop.dataType;
+                           exp.member.exp = null;
+
                            if(_class.type == structClass)
                            {
                               switch(type.kind)
@@ -1333,13 +1857,15 @@ void DebugComputeExpression(Expression exp)
                                     if(propertyClass.type == structClass && value.type == instanceExp)
                                     {
                                        void (*Set)(void *, void *) = (void *)prop.Set;
+                                       FreeExpContents(exp);
                                        exp.instance = Instantiation
                                        {
                                           data = new0 byte[_class.structSize];
-                                          _class = MkSpecifierName/*MkClassName*/(_class.name);
+                                          _class = MkSpecifierName(_class.name);
                                           loc = exp.loc;
-                                          exp.type = instanceExp;
                                        };
+                                       exp.type = instanceExp;
+
                                        Set(exp.instance.data, value.instance.data);
                                        PopulateInstance(exp.instance);
                                        supported = true;
@@ -1351,6 +1877,8 @@ void DebugComputeExpression(Expression exp)
                                     int intValue;
                                     void (*Set)(void *, int) = (void *)prop.Set;
 
+                                    GetInt(value, &intValue);
+                                    FreeExpContents(exp);
                                     exp.instance = Instantiation
                                     {
                                        data = new0 byte[_class.structSize];
@@ -1359,8 +1887,6 @@ void DebugComputeExpression(Expression exp)
                                     };
                                     exp.type = instanceExp;
 
-                                    GetInt(value, &intValue);
-
                                     Set(exp.instance.data, intValue);
                                     PopulateInstance(exp.instance);
                                     supported = true;
@@ -1371,6 +1897,8 @@ void DebugComputeExpression(Expression exp)
                                     int64 intValue;
                                     void (*Set)(void *, int64) = (void *)prop.Set;
 
+                                    GetInt64(value, &intValue);
+                                    FreeExpContents(exp);
                                     exp.instance = Instantiation
                                     {
                                        data = new0 byte[_class.structSize];
@@ -1379,18 +1907,38 @@ void DebugComputeExpression(Expression exp)
                                     };
                                     exp.type = instanceExp;
 
-                                    GetInt64(value, &intValue);
-
                                     Set(exp.instance.data, intValue);
                                     PopulateInstance(exp.instance);
                                     supported = true;
                                     break;
                                  }
+                                 case floatType:
+                                 {
+                                    float floatValue;
+                                    void (*Set)(void *, float) = (void *)prop.Set;
+
+                                    GetFloat(value, &floatValue);
+                                    FreeExpContents(exp);
+                                    exp.instance = Instantiation
+                                    {
+                                       data = new0 byte[_class.structSize];
+                                       _class = MkSpecifierName/*MkClassName*/(_class.name);
+                                       loc = exp.loc;
+                                    };
+                                    exp.type = instanceExp;
+
+                                    Set(exp.instance.data, floatValue);
+                                    PopulateInstance(exp.instance);
+                                    supported = true;
+                                    break;
+                                 }
                                  case doubleType:
                                  {
                                     double doubleValue;
                                     void (*Set)(void *, double) = (void *)prop.Set;
 
+                                    GetDouble(value, &doubleValue);
+                                    FreeExpContents(exp);
                                     exp.instance = Instantiation
                                     {
                                        data = new0 byte[_class.structSize];
@@ -1399,8 +1947,6 @@ void DebugComputeExpression(Expression exp)
                                     };
                                     exp.type = instanceExp;
 
-                                    GetDouble(value, &doubleValue);
-
                                     Set(exp.instance.data, doubleValue);
                                     PopulateInstance(exp.instance);
                                     supported = true;
@@ -1419,6 +1965,7 @@ void DebugComputeExpression(Expression exp)
                                     {
                                        unsigned int (*Set)(void *) = (void *)prop.Set;
                                        unsigned int bits = Set(value.instance.data);
+                                       FreeExpContents(exp);
                                        exp.constant = PrintHexUInt(bits);
                                        exp.type = constantExp;
                                        supported = true;
@@ -1432,6 +1979,7 @@ void DebugComputeExpression(Expression exp)
 
                                        GetUInt(memberExp, &value);
                                        bits = Set(value);
+                                       FreeExpContents(exp);
                                        exp.constant = PrintHexUInt(bits);
                                        exp.type = constantExp;
                                        supported = true;
@@ -1439,6 +1987,7 @@ void DebugComputeExpression(Expression exp)
                                  }
                               }
                            }
+                           FreeExpression(value);
                         }
                         else
                         {
@@ -1456,6 +2005,7 @@ void DebugComputeExpression(Expression exp)
                                     {
                                        void (*Get)(unsigned int, void *) = (void *)prop.Get;
 
+                                       FreeExpContents(exp);
                                        exp.instance = Instantiation
                                        {
                                           data = new0 byte[_class.structSize];
@@ -1482,7 +2032,10 @@ void DebugComputeExpression(Expression exp)
                            }
                            else if(_class.type == structClass)
                            {
-                              char * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
+                              byte * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
+                              if(value)
+                                 memberExp.instance.data = null;
+
                               switch(type.kind)
                               {
                                  case classType:
@@ -1492,6 +2045,7 @@ void DebugComputeExpression(Expression exp)
                                     {
                                        void (*Get)(void *, void *) = (void *)prop.Get;
 
+                                       FreeExpContents(exp);
                                        exp.instance = Instantiation
                                        {
                                           data = new0 byte[_class.structSize];
@@ -1507,6 +2061,8 @@ void DebugComputeExpression(Expression exp)
                                     break;
                                  }
                               }
+
+                              delete value;
                            }
                            /*else
                            {
@@ -1520,6 +2076,7 @@ void DebugComputeExpression(Expression exp)
                                     {
                                        void *(*Get)(void *) = (void *)prop.Get;
 
+                                       FreeExpContents(exp);
                                        exp.instance = Instantiation
                                        {
                                           data = Get(value, exp.instance.data);     ?????
@@ -1544,7 +2101,7 @@ void DebugComputeExpression(Expression exp)
                }
                else if(member)
                {
-                  if(memberExp.hasAddress || memberExp.type == constantExp)
+                  if(memberExp.hasAddress || memberExp.type == constantExp || (memberExp.type == instanceExp && memberExp.instance && memberExp.instance.data))
                   //if(memberExp.expType && memberExp.expType.kind == intType)  // && !exp.index.exp.expType.isSigned
                   {
                      if(_class.type == bitClass)
@@ -1578,7 +2135,6 @@ void DebugComputeExpression(Expression exp)
                         char format;
                         int size;
                         Expression expNew;
-                        TypeKind kind = dummyType;
                         Type dataType = member.dataType;
 
                         if(!dataType)
@@ -1627,8 +2183,55 @@ void DebugComputeExpression(Expression exp)
 
                            address += offset;
 
-                           if(!gotAddress)
+                           if(memberExp.type == instanceExp)
+                           {
+                              String constant = null;
+                              byte * data = memberExp.instance.data + offset;
+                              switch(dataType.kind)
+                              {
+                                 case charType:
+                                    if(dataType.isSigned)
+                                       constant = PrintChar(*(char *)data);
+                                    else
+                                       constant = PrintUChar(*(byte *)data);
+                                    break;
+                                 case shortType:
+                                    if(dataType.isSigned)
+                                       constant = PrintShort(*(short *)data);
+                                    else
+                                       constant = PrintUShort(*(uint16 *)data);
+                                    break;
+                                 case intType:
+                                    if(dataType.isSigned)
+                                       constant = PrintInt(*(int *)data);
+                                    else
+                                       constant = PrintUInt(*(uint *)data);
+                                    break;
+                                 case longType:
+                                 case int64Type:
+                                    if(dataType.isSigned)
+                                       constant = PrintInt64(*(int64 *)data);
+                                    else
+                                       constant = PrintUInt64(*(uint64 *)data);
+                                    break;
+                                 case floatType: constant = PrintFloat(*(float *)data); break;
+                                 case doubleType: constant = PrintDouble(*(double *)data); break;
+                              }
+                              if(constant)
+                              {
+                                 FreeExpContents(exp);
+                                 exp.constant = constant;
+                                 exp.type = constantExp;
+                                 exp.isConstant = true;
+                              }
+                              else
+                                 exp.type = unknownErrorExp;
+                           }
+                           else if(!gotAddress)
+                           {
+                              FreeExpContents(exp);
                               exp.type = unknownErrorExp;
+                           }
                            else if((dataType.kind == classType && dataType._class &&
                                  (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
                               (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
@@ -1704,7 +2307,6 @@ void DebugComputeExpression(Expression exp)
                         int size = memberType.size;
                         Expression expNew;
                         Type dataType = memberType;
-                        TypeKind kind = dummyType;
 
                         if(dataType.kind == classType && dataType._class.registered &&
                               (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
@@ -1833,7 +2435,17 @@ void DebugComputeExpression(Expression exp)
          {
             exp.hasAddress = exp.cast.exp.hasAddress;
             exp.address = exp.cast.exp.address;
-            if(exp.cast.exp.type == constantExp && exp.expType)
+            if(exp.cast.exp.type == instanceExp && exp.cast.exp.expType && exp.expType && exp.cast.exp.expType.kind == classType && exp.expType.kind == classType &&
+               exp.cast.exp.expType._class && exp.expType._class && exp.cast.exp.expType._class.registered && exp.expType._class.registered &&
+               exp.cast.exp.expType._class.registered == exp.expType._class.registered)
+            {
+               Instantiation inst = exp.cast.exp.instance;
+               exp.cast.exp.instance = null;
+               FreeExpContents(exp);
+               exp.instance = inst;
+               exp.type = instanceExp;
+            }
+            else if(exp.cast.exp.type == constantExp && exp.expType)
             {
                Type type = exp.expType;
                if(type.kind == classType && type._class && type._class.registered)
@@ -2097,3 +2709,231 @@ void DebugComputeExpression(Expression exp)
       }
    }
 }
+
+void ApplyUnitConverters(Expression exp)
+{
+   Property convert = null;
+   Type type = exp.expType;
+   bool useGet = false;
+   if(type.kind == classType && type._class && type._class.registered)
+   {
+      Class _class = type._class.registered;
+      if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
+      {
+         if(_class.type == unitClass && _class.base.type == unitClass)
+         {
+            Property p;
+            for(p = _class.conversions.first; p; p = p.next)
+            {
+               if(!strcmp(p.name, _class.base.fullName))
+               {
+                  convert = p;
+                  break;
+               }
+               else
+               {
+                  Class c = eSystem_FindClass(_class.module, p.name);
+                  if(c)
+                  {
+                     Property p2;
+                     for(p2 = c.conversions.first; p2; p2 = p2.next)
+                     {
+                        if(!strcmp(p2.name, _class.base.fullName))
+                        {
+                           convert = p;
+                           break;
+                        }
+                     }
+                  }
+                  if(convert)
+                     break;
+               }
+            }
+         }
+
+         if(!_class.dataType)
+            _class.dataType = ProcessTypeString(_class.dataTypeString, false);
+         type = _class.dataType;
+      }
+   }
+   if(convert)
+   {
+      switch(type.kind)
+      {
+         case charType:
+            if(type.isSigned)
+            {
+               char value = 0;
+               if(GetChar(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintChar(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            else
+            {
+               unsigned char value = 0;
+               if(GetUChar(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintUChar(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            break;
+         case shortType:
+            if(type.isSigned)
+            {
+               short value = 0;
+               if(GetShort(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintShort(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            else
+            {
+               unsigned short value = 0;
+               if(GetUShort(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintUShort(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            break;
+         case intType:
+            if(type.isSigned)
+            {
+               int value = 0;
+               if(GetInt(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintInt(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            else
+            {
+               unsigned int value = 0;
+               if(GetUInt(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintUInt(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            break;
+         case int64Type:
+            if(type.isSigned)
+            {
+               int64 value = 0;
+               if(GetInt64(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintInt64(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            else
+            {
+               uint64 value = 0;
+               if(GetUInt64(exp, &value))
+               {
+                  FreeExpContents(exp);
+                  exp.constant = PrintUInt64(value);
+                  exp.type = constantExp;
+                  exp.isConstant = true;
+               }
+            }
+            break;
+         case pointerType:
+         case classType:
+         {
+            uint64 value = 0;
+            if(GetUInt64(exp, &value))
+            {
+               FreeExpContents(exp);
+               if(type.kind == pointerType || type.kind == classType)
+                  exp.constant = PrintHexUInt64(value);
+               else
+                  exp.constant = PrintUInt64(value);
+               exp.type = constantExp;
+               exp.isConstant = true;
+            }
+            break;
+         }
+         case floatType:
+         {
+            float value = 0;
+            if(exp.type == constantExp && exp.constant &&
+               (!strcmpi(exp.constant, "nan") ||
+               !strcmpi(exp.constant, "-nan") ||
+               !strcmpi(exp.constant, "inf") ||
+               !strcmpi(exp.constant, "-inf")))
+            {
+               String constant = exp.constant;
+               exp.constant = null;
+               FreeExpContents(exp);
+               exp.constant = constant;
+               exp.type = constantExp;
+               exp.isConstant = true;
+            }
+            else if(GetFloat(exp, &value))
+            {
+               if(convert)
+               {
+                  float (*convertFn)(float) = (useGet ? (void *)convert.Get : (void *)convert.Set);
+                  if(convertFn)
+                     value = convertFn(value);
+               }
+               FreeExpContents(exp);
+               exp.constant = PrintFloat(value);
+               exp.type = constantExp;
+               exp.isConstant = true;
+            }
+            break;
+         }
+         case doubleType:
+         {
+            double value = 0;
+            if(exp.type == constantExp && exp.constant &&
+               (!strcmpi(exp.constant, "nan") ||
+               !strcmpi(exp.constant, "-nan") ||
+               !strcmpi(exp.constant, "inf") ||
+               !strcmpi(exp.constant, "-inf")))
+            {
+               String constant = exp.constant;
+               exp.constant = null;
+               FreeExpContents(exp);
+               exp.constant = constant;
+               exp.type = constantExp;
+               exp.isConstant = true;
+            }
+            else if(GetDouble(exp, &value))
+            {
+               if(convert)
+               {
+                  double (*convertFn)(double) = (useGet ? (void *)convert.Get : (void *)convert.Set);
+                  if(convertFn)
+                     value = convertFn(value);
+               }
+               FreeExpContents(exp);
+               exp.constant = PrintDouble(value);
+               exp.type = constantExp;
+               exp.isConstant = true;
+            }
+            break;
+         }
+      }
+   }
+}