Exemplo n.º 1
0
        public static TargetObject ExplicitFundamentalConversion(MdbEvaluationContext ctx,
                                                                 TargetFundamentalObject obj,
                                                                 TargetFundamentalType type)
        {
            TargetObject retval = ImplicitFundamentalConversion(ctx, obj, type);

            if (retval != null)
            {
                return(retval);
            }

            FundamentalKind tkind = type.FundamentalKind;

            try {
                object value     = obj.GetObject(ctx.Thread);
                object new_value = ImplicitFundamentalConversion(value, tkind);
                if (new_value == null)
                {
                    return(null);
                }

                return(type.Language.CreateInstance(ctx.Thread, new_value));
            } catch {
                return(null);
            }
        }
Exemplo n.º 2
0
        public override TargetFundamentalObject CreateInstance(Thread thread, object obj)
        {
            TargetFundamentalType type = GetFundamentalType(obj.GetType());

            if (type == null)
            {
                return(null);
            }

            return(type.CreateInstance(thread, obj));
        }
Exemplo n.º 3
0
        public NativeLanguage(Process process, OperatingSystemBackend os, TargetInfo info)
        {
            this.process = process;
            this.os      = os;
            this.info    = info;

            this.type_hash = Hashtable.Synchronized(new Hashtable());

            integer_type  = new NativeFundamentalType(this, "int", FundamentalKind.Int32, 4);
            unsigned_type = new NativeFundamentalType(this, "unsigned int", FundamentalKind.UInt32, 4);
            long_type     = new NativeFundamentalType(this, "long", FundamentalKind.Int64, 8);
            ulong_type    = new NativeFundamentalType(this, "unsigned long", FundamentalKind.UInt64, 8);
            pointer_type  = new NativePointerType(this, "void *", info.TargetAddressSize);
            void_type     = new NativeOpaqueType(this, "void", 0);
            string_type   = new NativeStringType(this, info.TargetAddressSize);
        }
Exemplo n.º 4
0
        public NativeLanguage(Process process, OperatingSystemBackend os, TargetInfo info)
        {
            this.process = process;
            this.os = os;
            this.info = info;

            this.type_hash = Hashtable.Synchronized (new Hashtable ());

            integer_type = new NativeFundamentalType (this, "int", FundamentalKind.Int32, 4);
            unsigned_type = new NativeFundamentalType (this, "unsigned int", FundamentalKind.UInt32, 4);
            long_type = new NativeFundamentalType (this, "long", FundamentalKind.Int64, 8);
            ulong_type = new NativeFundamentalType (this, "unsigned long", FundamentalKind.UInt64, 8);
            pointer_type = new NativePointerType (this, "void *", info.TargetAddressSize);
            void_type = new NativeOpaqueType (this, "void", 0);
            string_type = new NativeStringType (this, info.TargetAddressSize);
        }
Exemplo n.º 5
0
        static TargetObject ImplicitFundamentalConversion(MdbEvaluationContext ctx,
                                                          TargetFundamentalObject obj,
                                                          TargetFundamentalType type)
        {
            FundamentalKind skind = obj.Type.FundamentalKind;
            FundamentalKind tkind = type.FundamentalKind;

            if (!ImplicitFundamentalConversionExists(skind, tkind))
            {
                return(null);
            }

            object value = obj.GetObject(ctx.Thread);

            object new_value = ImplicitFundamentalConversion(value, tkind);

            if (new_value == null)
            {
                return(null);
            }

            return(type.Language.CreateInstance(ctx.Thread, new_value));
        }
Exemplo n.º 6
0
        public static TargetObject Cast(MdbEvaluationContext ctx, TargetObject obj, TargetType targetType)
        {
            obj = ObjectUtil.GetRealObject(ctx, obj);

            if (obj.Type == targetType)
            {
                return(obj);
            }

            if (targetType is TargetObjectType || ObjectUtil.FixTypeName(targetType.Name) == "System.Object")
            {
                if (obj.Type.IsByRef)
                {
                    return(obj);
                }
                return(BoxValue(ctx, obj));
            }

            if (targetType is TargetPointerType)
            {
                throw new NotSupportedException();
            }

            if (targetType is TargetFundamentalType)
            {
                TargetFundamentalObject fobj = obj as TargetFundamentalObject;
                if (fobj == null)
                {
                    throw new NotSupportedException();
                }

                TargetFundamentalType ftype = targetType as TargetFundamentalType;
                TargetObject          ob    = ExplicitFundamentalConversion(ctx, fobj, ftype);
                if (ob == null)
                {
                    throw new NotSupportedException();
                }
                return(ob);
            }

            if (targetType is TargetNullableType)
            {
                TargetNullableType ntype = (TargetNullableType)targetType;
                if (obj.Kind == TargetObjectKind.Null)
                {
                    return(obj);
                }
                else if (obj.Kind != TargetObjectKind.Nullable)
                {
                    return(ImplicitConversion(ctx, obj, ntype.ElementType));
                }

                TargetNullableType ntype2 = (TargetNullableType)obj.Type;
                if (ImplicitConversionExists(ctx, ntype2.ElementType, ntype.ElementType))
                {
                    return(obj);
                }
            }

            TargetClassType   ctype  = ToClassType(targetType);
            TargetClassObject source = ToClassObject(ctx, obj);

            if (source == null)
            {
                throw new Exception(string.Format("Variable is not a class type."));
            }

            return(TryCast(ctx, source, ctype));
        }
Exemplo n.º 7
0
 static bool ImplicitFundamentalConversionExists(TargetFundamentalType source, TargetFundamentalType target)
 {
     return(ImplicitFundamentalConversionExists(
                source.FundamentalKind, target.FundamentalKind));
 }