~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to src/core/Mono.Debugging/Mono.Debugging.Evaluation/ObjectValueAdaptor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.2.6 upstream) (1.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100202113959-s4exdz7er7igylz2
Tags: 2.2.1+dfsg-1
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
                
81
81
                string GetDisplayTypeName (string typeName, int idx, int end)
82
82
                {
83
 
                        int i = typeName.IndexOf ('[', idx, end - idx);
84
 
                        int ci = typeName.IndexOf (',', idx, end - idx);
 
83
                        int i = typeName.IndexOf ('[', idx, end - idx);  // Bracket may be an array start or a generic arg definition start
 
84
                        int ci = typeName.IndexOf (',', idx, end - idx); // Text after comma is the assembly name
85
85
                        
86
86
                        List<string> genericArgs = null;
87
 
                        string array = null;
 
87
                        string array = string.Empty;
88
88
                        int te = end;
89
89
                        if (i != -1) te = i;
90
90
                        if (ci != -1 && ci < te) te = ci;
97
97
                        }
98
98
                        if (i != -1) {
99
99
                                // Is array
100
 
                                int ea = typeName.IndexOf (']', i);
101
 
                                array = typeName.Substring (i, ea - i + 1);
 
100
                                while (i < end && typeName [i] == '[') {
 
101
                                        int ea = typeName.IndexOf (']', i);
 
102
                                        array += typeName.Substring (i, ea - i + 1);
 
103
                                        i = ea + 1;
 
104
                                }
102
105
                        }
103
106
                        
104
107
                        if (genericArgs == null)
198
201
                public abstract object[] GetTypeArgs (EvaluationContext ctx, object type);
199
202
                public abstract object GetBaseType (EvaluationContext ctx, object type);
200
203
                
 
204
                public virtual bool IsFlagsEnumType (EvaluationContext ctx, object type)
 
205
                {
 
206
                        return true;
 
207
                }
 
208
                
 
209
                public virtual IEnumerable<EnumMember> GetEnumMembers (EvaluationContext ctx, object type)
 
210
                {
 
211
                        object longType = GetType (ctx, "System.Int64");
 
212
                        TypeValueReference tref = new TypeValueReference (ctx, type);
 
213
                        foreach (ValueReference cr in tref.GetChildReferences ()) {
 
214
                                object c = Cast (ctx, cr.Value, longType);
 
215
                                long val = (long) TargetObjectToObject (ctx, c);
 
216
                                EnumMember em = new EnumMember () { Name = cr.Name, Value = val };
 
217
                                yield return em;
 
218
                        }
 
219
                }
 
220
                
201
221
                public object GetBaseType (EvaluationContext ctx, object type, bool includeObjectClass)
202
222
                {
203
223
                        object bt = GetBaseType (ctx, type);
234
254
                {
235
255
                        return default (object);
236
256
                }
 
257
                
 
258
                public virtual object ForceLoadType (EvaluationContext ctx, string typeName)
 
259
                {
 
260
                        return null;
 
261
                }
237
262
 
238
263
                public abstract object CreateValue (EvaluationContext ctx, object value);
239
264
 
272
297
                        else {
273
298
                                TypeDisplayData tdata = GetTypeDisplayData (ctx, GetValueType (ctx, obj));
274
299
                                
275
 
                                string tvalue;
 
300
                                EvaluationResult tvalue;
276
301
                                if (!string.IsNullOrEmpty (tdata.ValueDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
277
 
                                        tvalue = EvaluateDisplayString (ctx, obj, tdata.ValueDisplayString);
 
302
                                        tvalue = new EvaluationResult (EvaluateDisplayString (ctx, obj, tdata.ValueDisplayString));
278
303
                                else
279
304
                                        tvalue = ctx.Evaluator.TargetObjectToExpression (ctx, obj);
280
305
                                
612
637
                                return null;
613
638
                        } else if (IsArray (ctx, obj)) {
614
639
                                ICollectionAdaptor adaptor = CreateArrayAdaptor (ctx, obj);
615
 
                                StringBuilder tn = new StringBuilder (GetDisplayTypeName (GetTypeName (ctx, adaptor.ElementType)));
 
640
                                string ename = GetDisplayTypeName (GetTypeName (ctx, adaptor.ElementType));
616
641
                                int[] dims = adaptor.GetDimensions ();
617
 
                                tn.Append ("[");
 
642
                                StringBuilder tn = new StringBuilder ("[");
618
643
                                for (int n=0; n<dims.Length; n++) {
619
644
                                        if (n>0)
620
645
                                                tn.Append (',');
621
646
                                        tn.Append (dims[n]);
622
647
                                }
623
648
                                tn.Append ("]");
624
 
                                return new LiteralExp (tn.ToString ());
 
649
                                int i = ename.LastIndexOf ('>');
 
650
                                if (i == -1) i = 0;
 
651
                                i = ename.IndexOf ('[', i);
 
652
                                if (i != -1)
 
653
                                        return new EvaluationResult ("{" + ename.Substring (0, i) + tn + ename.Substring (i) + "}");
 
654
                                else
 
655
                                        return new EvaluationResult ("{" + ename + tn + "}");
 
656
                        }
 
657
                        else if (IsEnum (ctx, obj)) {
 
658
                                object type = GetValueType (ctx, obj);
 
659
                                object longType = GetType (ctx, "System.Int64");
 
660
                                object c = Cast (ctx, obj, longType);
 
661
                                long val = (long) TargetObjectToObject (ctx, c);
 
662
                                long rest = val;
 
663
                                string typeName = GetTypeName (ctx, type);
 
664
                                string composed = string.Empty;
 
665
                                string composedDisplay = string.Empty;
 
666
                                foreach (EnumMember em in GetEnumMembers (ctx, type)) {
 
667
                                        if (em.Value == val)
 
668
                                                return new EvaluationResult (typeName + "." + em.Name, em.Name);
 
669
                                        else {
 
670
                                                if ((rest & em.Value) == em.Value) {
 
671
                                                        rest &= ~em.Value;
 
672
                                                        if (composed.Length > 0) {
 
673
                                                                composed += "|";
 
674
                                                                composedDisplay += "|";
 
675
                                                        }
 
676
                                                        composed += typeName + "." + em.Name;
 
677
                                                        composedDisplay += em.Name;
 
678
                                                }
 
679
                                        }
 
680
                                }
 
681
                                if (IsFlagsEnumType (ctx, type) && rest == 0 && composed.Length > 0)
 
682
                                        return new EvaluationResult (composed, composedDisplay);
 
683
                                else
 
684
                                        return new EvaluationResult (val.ToString ());
 
685
                        }
 
686
                        else if (GetValueTypeName (ctx, obj) == "System.Decimal") {
 
687
                                string res = CallToString (ctx, obj);
 
688
                                // This returns the decimal formatted using the current culture. It has to be converted to invariant culture.
 
689
                                decimal dec = decimal.Parse (res);
 
690
                                res = dec.ToString (System.Globalization.CultureInfo.InvariantCulture);
 
691
                                return new EvaluationResult (res);
625
692
                        }
626
693
                        else if (IsClassInstance (ctx, obj)) {
627
694
                                TypeDisplayData tdata = GetTypeDisplayData (ctx, GetValueType (ctx, obj));
628
695
                                if (!string.IsNullOrEmpty (tdata.ValueDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
629
 
                                        return new LiteralExp (EvaluateDisplayString (ctx, obj, tdata.ValueDisplayString));
 
696
                                        return new EvaluationResult (EvaluateDisplayString (ctx, obj, tdata.ValueDisplayString));
630
697
                                // Return the type name
631
698
                                if (ctx.Options.AllowToStringCalls)
632
 
                                        return new LiteralExp ("{" + CallToString (ctx, obj) + "}");
 
699
                                        return new EvaluationResult ("{" + CallToString (ctx, obj) + "}");
633
700
                                if (!string.IsNullOrEmpty (tdata.TypeDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
634
 
                                        return new LiteralExp ("{" + EvaluateDisplayString (ctx, obj, tdata.TypeDisplayString) + "}");
635
 
                                return new LiteralExp ("{" + GetDisplayTypeName (GetValueTypeName (ctx, obj)) + "}");
 
701
                                        return new EvaluationResult ("{" + EvaluateDisplayString (ctx, obj, tdata.TypeDisplayString) + "}");
 
702
                                return new EvaluationResult ("{" + GetDisplayTypeName (GetValueTypeName (ctx, obj)) + "}");
636
703
                        }
637
 
                        return new LiteralExp ("{" + CallToString (ctx, obj) + "}");
 
704
                        return new EvaluationResult ("{" + CallToString (ctx, obj) + "}");
 
705
                }
 
706
 
 
707
                public object Convert (EvaluationContext ctx, object obj, object targetType)
 
708
                {
 
709
                        if (obj == null)
 
710
                                return null;
 
711
                        object res = TryConvert (ctx, obj, targetType);
 
712
                        if (res != null)
 
713
                                return res;
 
714
                        else
 
715
                                throw new EvaluatorException ("Can't convert an object of type '{0}' to type '{1}'", GetValueTypeName (ctx, obj), GetTypeName (ctx, targetType));
 
716
                }
 
717
 
 
718
                public virtual object TryConvert (EvaluationContext ctx, object obj, object targetType)
 
719
                {
 
720
                        return TryCast (ctx, obj, targetType);
638
721
                }
639
722
 
640
723
                public virtual object Cast (EvaluationContext ctx, object obj, object targetType)
641
724
                {
642
 
                        return obj;
 
725
                        if (obj == null)
 
726
                                return null;
 
727
                        object res = TryCast (ctx, obj, targetType);
 
728
                        if (res != null)
 
729
                                return res;
 
730
                        else
 
731
                                throw new EvaluatorException ("Can't cast an object of type '{0}' to type '{1}'", GetValueTypeName (ctx, obj), GetTypeName (ctx, targetType));
643
732
                }
644
733
 
645
734
                public virtual string CallToString (EvaluationContext ctx, object obj)
769
858
                                else
770
859
                                        return ObjectValue.CreateUnknown (exp);
771
860
                        }
772
 
                        catch (NotSupportedExpressionException) {
 
861
                        catch (ImplicitEvaluationDisabledException) {
773
862
                                return ObjectValue.CreateImplicitNotSupported (ctx.ExpressionValueSource, new ObjectPath (exp), "", ObjectValueFlags.None);
774
863
                        }
 
864
                        catch (NotSupportedExpressionException ex) {
 
865
                                return ObjectValue.CreateNotSupported (ctx.ExpressionValueSource, new ObjectPath (exp), ex.Message, "", ObjectValueFlags.None);
 
866
                        }
775
867
                        catch (EvaluatorException ex) {
776
868
                                return ObjectValue.CreateError (ctx.ExpressionValueSource, new ObjectPath (exp), "", ex.Message, ObjectValueFlags.None);
777
869
                        }
858
950
                                names [oval.Name] = new KeyValuePair<ObjectValue, ValueReference> (oval, val);
859
951
                }
860
952
        }
 
953
        
 
954
        public struct EnumMember
 
955
        {
 
956
                public string Name { get; set; }
 
957
                public long Value { get; set; }
 
958
        }
861
959
}