Exemplo n.º 1
0
        public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
        {
            Value left  = ((Value)binaryOperatorExpression.Left.AcceptVisitor(this, null)).GetPermanentReference();
            Value right = ((Value)binaryOperatorExpression.Right.AcceptVisitor(this, null)).GetPermanentReference();

            if (!left.IsReference && left.Type.FullName != right.Type.FullName)
            {
                throw new GetValueException(string.Format("Type {0} expected, {1} seen", left.Type.FullName, right.Type.FullName));
            }

            Value val = Eval.NewObjectNoConstructor(DebugType.Create(context.Process, null, typeof(bool).FullName));

            try {
                switch (binaryOperatorExpression.Op)
                {
                case BinaryOperatorType.Equality:
                    val.PrimitiveValue = Equals(right.PrimitiveValue, left.PrimitiveValue);
                    break;

                case BinaryOperatorType.InEquality:
                    val.PrimitiveValue = !Equals(right.PrimitiveValue, left.PrimitiveValue);
                    break;

//				case BinaryOperatorType.Add :
//					val.PrimitiveValue = (right.PrimitiveValue.ToString() + left.PrimitiveValue.ToString());
//					break;
//				case BinaryOperatorType.GreaterThan :
//					val.PrimitiveValue = (right.PrimitiveValue > left.PrimitiveValue);
//					break;
//				case BinaryOperatorType.LessThanOrEqual :
//					val.PrimitiveValue = (right.PrimitiveValue <= left.PrimitiveValue);
//					break;
//				case BinaryOperatorType.GreaterThanOrEqual :
//					val.PrimitiveValue = (right.PrimitiveValue >= left.PrimitiveValue);
//					break;
                default:
                    throw new NotImplementedException("BinaryOperator: " + binaryOperatorExpression.Op);
                }
            } catch (NotImplementedException e) {
                throw e;
            } catch (System.Exception e2) {
                throw new GetValueException(e2.Message);
            }

            return(val);
        }
Exemplo n.º 2
0
 public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
 {
     if (primitiveExpression.Value == null)
     {
         return(Eval.CreateValue(context.Process, null));
     }
     else if (primitiveExpression.Value is string)
     {
         return(Eval.NewString(context.Process, primitiveExpression.Value as string));
     }
     else
     {
         Value val = Eval.NewObjectNoConstructor(DebugType.Create(context.Process, null, primitiveExpression.Value.GetType().FullName));
         val.PrimitiveValue = primitiveExpression.Value;
         return(val);
     }
 }
Exemplo n.º 3
0
        public Value GetPermanentReference()
        {
            ICorDebugValue corValue = this.CorValue;

            if (this.Type.IsClass)
            {
                corValue = this.CorObjectValue.CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
            }
            if (this.Type.IsValueType || this.Type.IsPrimitive)
            {
                if (!corValue.Is <ICorDebugReferenceValue>())
                {
                    // Box the value type
                    if (this.Type.IsPrimitive)
                    {
                        // Get value type for the primive type
                        object o = this.PrimitiveValue;
                        corValue = Eval.NewObjectNoConstructor(DebugType.Create(process, null, this.Type.FullName)).RawCorValue;
                        this.SetPrimitiveValue(o);
                    }
                    else
                    {
                        corValue = Eval.NewObjectNoConstructor(this.Type).RawCorValue;
                    }
                    // Make the reference to box permanent
                    corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
                    // Create new value
                    Value newValue = new Value(process, new IExpirable[] {},
                                               new IMutable[] {}, delegate { return(corValue); });
                    // Copy the data inside the box
                    newValue.CorGenericValue.RawValue = this.CorGenericValue.RawValue;
                    return(newValue);
                }
                else
                {
                    // Make the reference to box permanent
                    corValue = corValue.CastTo <ICorDebugReferenceValue>().Dereference().CastTo <ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo <ICorDebugValue>();
                }
            }
            return(new Value(process, new IExpirable[] {},
                             new IMutable[] {}, delegate { return corValue; }));
        }
Exemplo n.º 4
0
        public void SetValue(Value newValue)
        {
            ICorDebugValue corValue    = this.CorValue;
            ICorDebugValue newCorValue = newValue.CorValue;

            if (corValue.Is <ICorDebugReferenceValue>())
            {
                if (newCorValue.Is <ICorDebugObjectValue>())
                {
                    ICorDebugValue box = Eval.NewObjectNoConstructor(newValue.Type).CorValue;
                    newCorValue = box;
                }
                corValue.CastTo <ICorDebugReferenceValue>().SetValue(newCorValue.CastTo <ICorDebugReferenceValue>().Value);
            }
            else
            {
                corValue.CastTo <ICorDebugGenericValue>().RawValue =
                    newCorValue.CastTo <ICorDebugGenericValue>().RawValue;
            }
        }