Пример #1
0
        public static MemberExpression FindMember(Thread target, TargetStructType stype,
							   TargetStructObject instance, string name,
							   bool search_static, bool search_instance)
        {
            again:
            TargetClass klass = stype.GetClass (target);
            if (klass != null) {
                TargetMemberInfo member = klass.FindMember (
                    target, name, search_static, search_instance);
                if (member != null)
                    return new StructAccessExpression (stype, instance, member);

                ArrayList methods = new ArrayList ();
                bool is_instance = false;
                bool is_static = false;

                TargetMethodInfo[] klass_methods = klass.GetMethods (target);
                if (klass_methods != null) {
                    foreach (TargetMethodInfo method in klass_methods) {
                        if (method.IsStatic && !search_static)
                            continue;
                        if (!method.IsStatic && !search_instance)
                            continue;
                        if (method.Name != name)
                            continue;

                        methods.Add (method.Type);
                        if (method.IsStatic)
                            is_static = true;
                        else
                            is_instance = true;
                    }
                }

                if (methods.Count > 0) {
                    TargetFunctionType[] funcs = new TargetFunctionType [methods.Count];
                    methods.CopyTo (funcs, 0);
                    return new MethodGroupExpression (
                        stype, instance, name, funcs, is_instance, is_static);
                }
            }

            TargetClassType ctype = stype as TargetClassType;
            if (ctype != null) {
                TargetMemberInfo member = ctype.FindMember (
                    name, search_static, search_instance);

                if (member != null)
                    return new StructAccessExpression (ctype, instance, member);

                ArrayList methods = new ArrayList ();
                bool is_instance = false;
                bool is_static = false;

                if (name == ".ctor") {
                    foreach (TargetMethodInfo method in ctype.Constructors) {
                        if (method.IsStatic)
                            continue;
                        methods.Add (method.Type);
                        is_instance = true;
                    }
                } else if (name == ".cctor") {
                    foreach (TargetMethodInfo method in ctype.Constructors) {
                        if (!method.IsStatic)
                            continue;
                        methods.Add (method.Type);
                        is_static = true;
                    }
                } else {
                    foreach (TargetMethodInfo method in ctype.Methods) {
                        if (method.IsStatic && !search_static)
                            continue;
                        if (!method.IsStatic && !search_instance)
                            continue;
                        if (method.Name != name)
                            continue;

                        methods.Add (method.Type);
                        if (method.IsStatic)
                            is_static = true;
                        else
                            is_instance = true;
                    }
                }

                if (methods.Count > 0) {
                    TargetFunctionType[] funcs = new TargetFunctionType [methods.Count];
                    methods.CopyTo (funcs, 0);
                    return new MethodGroupExpression (
                        ctype, instance, name, funcs, is_instance, is_static);
                }
            }

            if (stype.HasParent) {
                stype = stype.GetParentType (target);
                if (instance != null) {
                    instance = instance.GetParentObject (target);
                    if (instance == null)
                        return null;
                }
                goto again;
            }

            return null;
        }
Пример #2
0
        public StructAccessExpression(TargetStructType type,
					       TargetStructObject instance,
					       TargetMemberInfo member)
        {
            this.Type = type;
            this.Member = member;
            this.instance = instance;
            resolved = true;
        }
Пример #3
0
        public MethodGroupExpression(TargetStructType stype, TargetStructObject instance,
					      string name, TargetFunctionType[] methods,
					      bool is_instance, bool is_static)
        {
            this.stype = stype;
            this.instance = instance;
            this.name = name;
            this.methods = methods;
            this.is_instance = is_instance;
            this.is_static = is_static;
            resolved = true;
        }
		static bool TryParentCast (MdbEvaluationContext ctx, TargetStructType source_type, TargetStructType target_type)
		{
			if (source_type == target_type)
				return true;

			if (!source_type.HasParent)
				return false;

			TargetStructType parent_type = source_type.GetParentType (ctx.Thread);
			return TryParentCast (ctx, parent_type, target_type);
		}
		static TargetStructObject TryParentCast (MdbEvaluationContext ctx, TargetStructObject source, TargetStructType source_type, TargetStructType target_type)
		{
			if (source_type == target_type)
				return source;

			if (!source_type.HasParent)
				return null;

			TargetStructType parent_type = source_type.GetParentType (ctx.Thread);
			source = TryParentCast (ctx, source, parent_type, target_type);
			if (source == null)
				return null;

			return source.GetParentObject (ctx.Thread) as TargetClassObject;
		}
		static bool ImplicitReferenceConversionExists (MdbEvaluationContext ctx,
							       TargetStructType source,
							       TargetStructType target)
		{
			if (source == target)
				return true;

			if (source.Module.Name.StartsWith ("mscorlib,") && target.Module.Name.StartsWith ("mscorlib,")) {
				Type t1 = Type.GetType (source.Name);
				Type t2 = Type.GetType (target.Name);
				return t2.IsAssignableFrom (t1);
			}
			
			if (!source.HasParent)
				return false;

			TargetStructType parent_type = source.GetParentType (ctx.Thread);
			return ImplicitReferenceConversionExists (ctx, parent_type, target);
		}