Beispiel #1
0
 public StaticFieldValueLocation(DmdType type, ThreadMirror thread, FieldInfoMirror field)
 {
     Type        = type ?? throw new ArgumentNullException(nameof(type));
     this.thread = thread ?? throw new ArgumentNullException(nameof(thread));
     this.field  = field ?? throw new ArgumentNullException(nameof(field));
     Debug.Assert(field.IsStatic);
 }
Beispiel #2
0
 public ReferenceTypeFieldValueLocation(DmdType type, ObjectMirror objectMirror, FieldInfoMirror field)
 {
     Type = type ?? throw new ArgumentNullException(nameof(type));
     this.objectMirror = objectMirror ?? throw new ArgumentNullException(nameof(objectMirror));
     this.field        = field ?? throw new ArgumentNullException(nameof(field));
     Debug.Assert(!field.IsStatic);
 }
Beispiel #3
0
        public FieldValueReference(EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType, string vname, ObjectValueFlags vflags, FieldReferenceBatch batch = null) : base(ctx)
        {
            this.field         = field;
            this.obj           = obj;
            this.declaringType = declaringType;
            this.vname         = vname;
            this.batch         = batch;
            flags = vflags;

            if (field.IsStatic)
            {
                this.obj = null;
            }

            var objectMirror = obj as ObjectMirror;

            if (objectMirror != null)
            {
                EnsureContextHasDomain(objectMirror.Domain);
            }

            flags |= GetFlags(field);

            if (obj is PrimitiveValue)
            {
                flags |= ObjectValueFlags.ReadOnly;
            }
        }
Beispiel #4
0
        internal static ObjectValueFlags GetFlags(FieldInfoMirror field)
        {
            var flags = ObjectValueFlags.Field;

            if (field.IsStatic)
            {
                flags |= ObjectValueFlags.Global;
            }

            if (field.IsPublic)
            {
                flags |= ObjectValueFlags.Public;
            }
            else if (field.IsPrivate)
            {
                flags |= ObjectValueFlags.Private;
            }
            else if (field.IsFamily)
            {
                flags |= ObjectValueFlags.Protected;
            }
            else if (field.IsFamilyAndAssembly)
            {
                flags |= ObjectValueFlags.Internal;
            }
            else if (field.IsFamilyOrAssembly)
            {
                flags |= ObjectValueFlags.InternalProtected;
            }

            return(flags);
        }
Beispiel #5
0
        public FieldValueReference(EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType, string vname, ObjectValueFlags vflags, FieldReferenceBatch batch = null) : base(ctx)
        {
            this.field         = field;
            this.obj           = obj;
            this.declaringType = declaringType;
            this.vname         = vname;
            this.batch         = batch;

            if (field.IsStatic)
            {
                this.obj = null;
            }

            var objectMirror = obj as ObjectMirror;

            if (objectMirror != null)
            {
                EnsureContextHasDomain(objectMirror.Domain);
            }

            flags = GetFlags(field);

            // if `vflags` already has an origin specified, we need to unset the `Field` flag which is always returned by GetFlags().
            if ((vflags & ObjectValueFlags.OriginMask) != 0)
            {
                flags &= ~ObjectValueFlags.Field;
            }

            flags |= vflags;

            if (obj is PrimitiveValue)
            {
                flags |= ObjectValueFlags.ReadOnly;
            }
        }
Beispiel #6
0
 ValueTypeFieldValueLocation(ValueTypeFieldValueLocation other)
 {
     Type = other.Type.GetElementType();
     containingLocation = other.containingLocation;
     field      = other.field;
     valueIndex = other.valueIndex;
     structType = other.structType;
 }
Beispiel #7
0
 public object GetValue(FieldInfoMirror field)
 {
     lock (locker) {
         if (results == null || fields.Count != results.Length)
         {
             results = ((ObjectMirror)obj).GetValues(fields);
         }
         return(results [fields.IndexOf(field)]);
     }
 }
Beispiel #8
0
 public ValueTypeFieldValueLocation(DmdType type, ValueLocation containingLocation, StructMirror structMirror, FieldInfoMirror field)
 {
     Type = type ?? throw new ArgumentNullException(nameof(type));
     this.containingLocation = containingLocation ?? throw new ArgumentNullException(nameof(containingLocation));
     this.field = field ?? throw new ArgumentNullException(nameof(field));
     structType = structMirror.Type;
     Debug.Assert(!field.IsStatic);
     Debug.Assert(field.DeclaringType == structType);
     Debug.Assert(containingLocation.Load() is StructMirror);
     valueIndex = GetValueIndex(field);
     if ((uint)valueIndex >= (uint)structMirror.Fields.Length)
     {
         throw new InvalidOperationException();
     }
 }
Beispiel #9
0
        static int GetValueIndex(FieldInfoMirror field)
        {
            int index = 0;

            foreach (var f in field.DeclaringType.GetFields())
            {
                if (f.IsStatic || f.IsLiteral)
                {
                    continue;
                }
                if (f == field)
                {
                    return(index);
                }
                index++;
            }
            throw new InvalidOperationException();
        }
        protected override ValueReference GetMember(EvaluationContext ctx, object t, object co, string name)
        {
            TypeMirror type = (TypeMirror)t;

            while (type != null)
            {
                FieldInfoMirror field = type.GetField(name);
                if (field != null)
                {
                    return(new FieldValueReference(ctx, field, co, type));
                }
                PropertyInfoMirror prop = type.GetProperty(name);
                if (prop != null)
                {
                    return(new PropertyValueReference(ctx, prop, co, type, null));
                }
                type = type.BaseType;
            }
            return(null);
        }
Beispiel #11
0
        static FieldInfoMirror[] GetFields(TypeMirror monoType, int length)
        {
            var fields = new FieldInfoMirror[length];
            int w      = 0;

            foreach (var f in monoType.GetFields())
            {
                if (f.IsStatic || f.IsLiteral)
                {
                    continue;
                }
                if (w >= fields.Length)
                {
                    return(null);
                }
                fields[w++] = f;
            }
            if (w != length)
            {
                return(null);
            }
            return(fields);
        }
 public FieldValueReference(EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType, string vname, ObjectValueFlags vflags) : base(ctx)
 {
     this.field         = field;
     this.obj           = obj;
     this.declaringType = declaringType;
     this.vname         = vname;
     flags = vflags;
     if (field.IsStatic)
     {
         flags   |= ObjectValueFlags.Global;
         this.obj = null;
     }
     if (field.IsPublic)
     {
         flags |= ObjectValueFlags.Public;
     }
     else if (field.IsPrivate)
     {
         flags |= ObjectValueFlags.Private;
     }
     else if (field.IsFamily)
     {
         flags |= ObjectValueFlags.Protected;
     }
     else if (field.IsFamilyAndAssembly)
     {
         flags |= ObjectValueFlags.Internal;
     }
     else if (field.IsFamilyOrAssembly)
     {
         flags |= ObjectValueFlags.InternalProtected;
     }
     if (obj is PrimitiveValue)
     {
         flags |= ObjectValueFlags.ReadOnly;
     }
 }
 public FieldValueReference(EvaluationContext ctx, FieldInfoMirror field, object obj, TypeMirror declaringType)
     : this(ctx, field, obj, declaringType, null, ObjectValueFlags.Field)
 {
 }
Beispiel #14
0
 public void Add(FieldInfoMirror fieldVal)
 {
     lock (locker) {
         fields.Add(fieldVal);
     }
 }