Exemplo n.º 1
0
        Value Visit(ConversionResolveResult result)
        {
            if (result.IsError)
            {
                throw new GetValueException("Cannot convert from '{0}' to '{1}'.", new CSharpAmbience().ConvertType(result.Input.Type), new CSharpAmbience().ConvertType(result.Type));
            }
            var val = Convert(result.Input);

            if (result.Conversion.IsBoxingConversion)
            {
                return(val);
            }
            if (result.Conversion.IsIdentityConversion)
            {
                return(val);
            }
            if (result.Conversion.IsNumericConversion)
            {
                var convVal = CSharpPrimitiveCast.Cast(ReflectionHelper.GetTypeCode(result.Type), val.PrimitiveValue, false);
                return(Eval.CreateValue(evalThread, convVal));
            }
            if (result.Conversion.IsUserDefined)
            {
                return(InvokeMethod(null, result.Conversion.Method, val));
            }
            if (result.Conversion.IsReferenceConversion && result.Conversion.IsImplicit)
            {
                return(val);
            }
            if (result.Conversion.IsNullLiteralConversion)
            {
                return(val);
            }
            throw new GetValueException("conversion '{0}' not implemented!", result.Conversion);
        }
Exemplo n.º 2
0
        /// <remarks>
        /// See $7.10.10 of C# 4 Spec for details.
        /// </remarks>
        Value Visit(TypeIsResolveResult result)
        {
            var  importedType = NullableType.GetUnderlyingType(Import(result.TargetType));
            var  val          = Convert(result.Input);
            var  conversions  = CSharpConversions.Get(debuggerTypeSystem);
            bool evalResult   = false;

            if (!val.IsNull)
            {
                IType inputType = NullableType.GetUnderlyingType(val.Type);
                if (inputType.Equals(importedType))
                {
                    evalResult = true;
                }
                else if (conversions.IsImplicitReferenceConversion(inputType, importedType))
                {
                    evalResult = true;
                }
                else if (conversions.IsBoxingConversion(inputType, importedType))
                {
                    evalResult = true;
                }
            }
            return(Eval.CreateValue(evalThread, evalResult));
        }
Exemplo n.º 3
0
 public Value Convert(ResolveResult result)
 {
     if (result.IsCompileTimeConstant && !result.IsError)
     {
         return(Eval.CreateValue(evalThread, result.ConstantValue));
     }
     return(Visit((dynamic)result));
 }
Exemplo n.º 4
0
 public Value Convert(ResolveResult result)
 {
     if (result.IsCompileTimeConstant && !result.IsError)
     {
         var type = Import(result.Type);
         if (type == null)
         {
             throw new GetValueException("Error: cannot find '{0}'.", result.Type.FullName);
         }
         return(Eval.CreateValue(evalThread, result.ConstantValue, type));
     }
     return(Visit((dynamic)result));
 }
Exemplo n.º 5
0
        public static Value MakeValue(object obj)
        {
            Value v = null;

            if (!(obj is string))
            {
                v = Eval.CreateValue(WorkbenchServiceFactory.DebuggerManager.DebuggedProcess, obj);
                v.SetPrimitiveValue(obj);
            }
            else
            {
                v = Eval.NewString(WorkbenchServiceFactory.DebuggerManager.DebuggedProcess, obj as string);
            }
            return(v);
        }
Exemplo n.º 6
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.º 7
0
        Value Visit(ResolveResult result)
        {
            if (result is ErrorResolveResult)
            {
                var err = (ErrorResolveResult)result;
                if (!string.IsNullOrWhiteSpace(err.Message))
                {
                    throw new GetValueException(err.Message);
                }
            }

            if (result.IsError)
            {
                throw new GetValueException("Unknown error");
            }
            if (result.ConstantValue == null && result.Type.Equals(SpecialType.NullType))
            {
                return(Eval.CreateValue(evalThread, null));
            }
            throw new GetValueException("Unsupported language construct: " + result.GetType().Name);
        }
Exemplo n.º 8
0
 public static string FormatValue(Thread evalThread, Value val)
 {
     if (val.IsNull)
     {
         return("null");
     }
     else if (val.Type.Kind == TypeKind.Array)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(new CSharpAmbience().ConvertType(val.Type));
         sb.Append(" {");
         bool first = true;
         int  size  = val.ArrayLength;
         for (int i = 0; i < size; i++)
         {
             if (!first)
             {
                 sb.Append(", ");
             }
             first = false;
             sb.Append(FormatValue(evalThread, val.GetElementAtPosition(i)));
         }
         sb.Append("}");
         return(sb.ToString());
     }
     else if (val.Type.GetAllBaseTypeDefinitions().Any(def => def.IsKnownType(KnownTypeCode.ICollection)))
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(new CSharpAmbience().ConvertType(val.Type));
         sb.Append(" {");
         val = val.GetPermanentReference(evalThread);
         var countProp = val.Type.GetProperties(p => p.Name == "Count" && !p.IsExplicitInterfaceImplementation).Single();
         int count     = (int)val.GetMemberValue(evalThread, countProp).PrimitiveValue;
         for (int i = 0; i < count; i++)
         {
             if (i > 0)
             {
                 sb.Append(", ");
             }
             var   itemProperty = val.Type.GetProperties(p => p.IsIndexer && p.Name == "Item" && !p.IsExplicitInterfaceImplementation).Single();
             Value item         = val.GetPropertyValue(evalThread, itemProperty, Eval.CreateValue(evalThread, i));
             sb.Append(FormatValue(evalThread, item));
         }
         sb.Append("}");
         return(sb.ToString());
     }
     else if (val.Type.IsKnownType(KnownTypeCode.String) || val.Type.IsPrimitiveType())
     {
         return(TextWriterTokenWriter.PrintPrimitiveValue(val.PrimitiveValue));
     }
     else
     {
         return(val.InvokeToString(evalThread));
     }
 }
Exemplo n.º 9
0
        Value VisitBinaryOperator(OperatorResolveResult result, BinaryOperatorType operatorType, bool checkForOverflow = false)
        {
            Debug.Assert(result.Operands.Count == 2);
            Debug.Assert(operatorType != BinaryOperatorType.ConditionalAnd && operatorType != BinaryOperatorType.ConditionalOr && operatorType != BinaryOperatorType.NullCoalescing);
            var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread);
            var rhs = Convert(result.Operands[1]).GetPermanentReference(evalThread);

            if (result.UserDefinedOperatorMethod != null)
            {
                return(InvokeMethod(null, result.UserDefinedOperatorMethod, lhs, rhs));
            }
            var            lhsRR    = lhs.ToResolveResult(context);
            var            rhsRR    = rhs.ToResolveResult(context);
            CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem).WithCheckForOverflow(checkForOverflow);
            var            val      = resolver.ResolveBinaryOperator(operatorType, lhsRR, rhsRR);

            if (val.IsCompileTimeConstant)
            {
                return(Convert(val));
            }
            switch (operatorType)
            {
            case BinaryOperatorType.Equality:
            case BinaryOperatorType.InEquality:
                bool equality = (operatorType == BinaryOperatorType.Equality);
                if (lhsRR.Type.IsKnownType(KnownTypeCode.String) && rhsRR.Type.IsKnownType(KnownTypeCode.String))
                {
                    if (lhs.IsNull || rhs.IsNull)
                    {
                        bool bothNull = lhs.IsNull && rhs.IsNull;
                        return(Eval.CreateValue(evalThread, equality ? bothNull : !bothNull));
                    }
                    else
                    {
                        bool equal = (string)lhs.PrimitiveValue == (string)rhs.PrimitiveValue;
                        return(Eval.CreateValue(evalThread, equality ? equal : !equal));
                    }
                }
                if (lhsRR.Type.IsReferenceType != false && rhsRR.Type.IsReferenceType != false)
                {
                    // Reference comparison
                    if (lhs.IsNull || rhs.IsNull)
                    {
                        bool bothNull = lhs.IsNull && rhs.IsNull;
                        return(Eval.CreateValue(evalThread, equality ? bothNull : !bothNull));
                    }
                    else
                    {
                        bool equal = lhs.Address == rhs.Address;
                        return(Eval.CreateValue(evalThread, equality ? equal : !equal));
                    }
                }
                goto default;

            case BinaryOperatorType.Add:
                if (lhsRR.Type.IsKnownType(KnownTypeCode.String) || rhsRR.Type.IsKnownType(KnownTypeCode.String))
                {
                    var method = debuggerTypeSystem.FindType(KnownTypeCode.String)
                                 .GetMethods(m => m.Name == "Concat" && m.Parameters.Count == 2)
                                 .Single(m => m.Parameters.All(p => p.Type.IsKnownType(KnownTypeCode.Object)));
                    return(InvokeMethod(null, method, lhs, rhs));
                }
                goto default;

            default:
                throw new GetValueException("Operator {0} is not supported for {1} and {2}!", operatorType, new CSharpAmbience().ConvertType(lhsRR.Type), new CSharpAmbience().ConvertType(rhsRR.Type));
            }
        }
Exemplo n.º 10
0
        /// <remarks> 'getValue' really should return cached value, because we do Eval to create indices. </remarks>
        static IEnumerable <TreeNode> GetIListChildren(Func <Value> getValue)
        {
            IProperty itemProp;
            int       count = 0;

            try {
                Value list      = getValue();
                IType iListType = list.Type.GetAllBaseTypeDefinitions().FirstOrDefault(t => t.FullName == typeof(IList).FullName);
                itemProp = iListType.GetProperties(p => p.Name == "Item").Single();
                // Do not get string representation since it can be printed in hex
                count = (int)list.GetPropertyValue(WindowsDebugger.EvalThread, iListType.GetProperties(p => p.Name == "Count").Single()).PrimitiveValue;
            } catch (GetValueException e) {
                return(new [] { new TreeNode(null, "(error)", e.Message, string.Empty, null) });
            }
            if (count == 0)
            {
                return(new [] { new TreeNode("(empty)", null) });
            }
            else
            {
                return(Enumerable.Range(0, count).Select(i => new ValueNode(ClassBrowserIconService.Field, "[" + i + "]", () => getValue().GetPropertyValue(WindowsDebugger.EvalThread, itemProp, Eval.CreateValue(WindowsDebugger.EvalThread, i)))));
            }
        }
Exemplo n.º 11
0
 protected override Value EvaluateInternal(StackFrame context)
 {
     return(Eval.CreateValue(context.Process, this.Value));
 }
Exemplo n.º 12
0
        public void Refresh()
        {
            try     {
                // clear ListView
                listView.ItemsSource = null;

                Value shownValue = getValue();

                ParameterizedType iListType, iEnumerableType;
                IType             itemType;
                // Value is IList
                if (shownValue.Type.ResolveIListImplementation(out iListType, out itemType))
                {
                    // Ok
                }
                else
                {
                    // Value is IEnumerable
                    if (shownValue.Type.ResolveIEnumerableImplementation(out iEnumerableType, out itemType))
                    {
                        shownValue = DebuggerHelpers.CreateListFromIEnumerable(shownValue);
                        shownValue.Type.ResolveIListImplementation(out iListType, out itemType);
                        //var ilistDef = iEnumerableType.Compilation.FindType(typeof(List<>)).GetDefinition();
                        //var ilistType = new ParameterizedType(ilistDef, ienumerableType.TypeArguments);
                    }
                    else
                    {
                        // Not IList or IEnumerable<T> - can't be displayed in GridVisualizer
                        return;
                    }
                }
                shownValue = shownValue.GetPermanentReference(WindowsDebugger.EvalThread);

                var       members         = itemType.GetFieldsAndNonIndexedProperties().Where(m => m.IsPublic && !m.IsStatic).ToList();
                IProperty indexerProperty = iListType.GetProperties(p => p.Name == "Item").Single();
                int       rowCount        = (int)shownValue.GetPropertyValue(WindowsDebugger.EvalThread, iListType.GetProperties(p => p.Name == "Count").Single()).PrimitiveValue;
                int       columnCount     = members.Count + 1;

                var rowCollection = new VirtualizingCollection <VirtualizingCollection <string> >(
                    rowCount,
                    (rowIndex) => new VirtualizingCollection <string>(
                        columnCount,
                        (columnIndex) => {
                    if (columnIndex == columnCount - 1)
                    {
                        return("[" + rowIndex + "]");
                    }
                    try {
                        var rowValue = shownValue.GetPropertyValue(WindowsDebugger.EvalThread, indexerProperty, Eval.CreateValue(WindowsDebugger.EvalThread, rowIndex));
                        return(rowValue.GetMemberValue(WindowsDebugger.EvalThread, members[columnIndex]).InvokeToString(WindowsDebugger.EvalThread));
                    } catch (GetValueException e) {
                        return("Exception: " + e.Message);
                    }
                }
                        )
                    );
                this.listView.ItemsSource = rowCollection;

                InitializeColumns((GridView)this.listView.View, members);

                GridViewColumnHider columnHider = new GridViewColumnHider((GridView)this.listView.View);
                cmbColumns.ItemsSource = columnHider.HideableColumns;
            } catch (GetValueException e) {
                MessageService.ShowMessage(e.Message);
            }
        }