Ejemplo n.º 1
0
        public int GetMemberIndex(IMemberReference reference)
        {
            int classIndex       = GetClassIndex(reference.DeclaringClass);
            int nameAndTypeIndex = GetNameAndTypeIndex(reference.Name, reference.Descriptor);

            MemberRefInfo memberRefInfo;

            switch (reference)
            {
            case IField _:
                memberRefInfo = new FieldRefInfo((ushort)classIndex, (ushort)nameAndTypeIndex);
                break;

            case IMethod _:
                memberRefInfo = new MethodRefInfo((ushort)classIndex, (ushort)nameAndTypeIndex);
                break;

            default:
                throw new NotSupportedException();
            }

            if (!_memberRefInfos.TryGetValue(memberRefInfo, out int index))
            {
                index = AddConstant(memberRefInfo);
                _memberRefInfos.Add(memberRefInfo, index);
            }

            return(index);
        }
Ejemplo n.º 2
0
        private void AnalyzeFieldRef(FieldRefInfo fri, CodeDescriptor code)
        {
            Type fieldType = fri.Field.FieldType;

            object[] attrs = fieldType.GetCustomAttributes(typeof(MapToIntrinsicType), false);
            if (attrs.Length == 0)
            {
                if (fri.IsWritten && !fieldType.IsValueType)
                {
                    ReportError("Illegal write access to field " +
                                fri.Field.Name + " of class " + fri.Field.DeclaringType.Name + ": At runtime, " +
                                "only value types may be written.");
                    return;
                }
                if (fri.IsWritten && fri.Field.IsStatic)
                {
                    ReportError("Illegal write access to field " +
                                fri.Field.Name + " of class " + fri.Field.DeclaringType.Name + ": At runtime, " +
                                "only non-static fields may be written.");
                    return;
                }
                if (fri.IsRead && !fieldType.IsValueType && !fieldType.IsArray)
                {
                    //FIXME
                    // E.g. DesignContext.Instance is allowed...

                    /*
                     * ReportError("Illegal read access to field " + fri.Field.Name + " of class " +
                     *  fri.Field.DeclaringType.Name + ": At runtime, only value types and arrays " +
                     *  "may be accessed.");
                     * */
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads a single field reference at the current position of the provided reader.
        /// </summary>
        /// <param name="reader">The reader to use.</param>
        /// <returns>The field reference that was read.</returns>
        public new static FieldRefInfo FromReader(IBigEndianReader reader)
        {
            var info = new FieldRefInfo
            {
                StartOffset = reader.Position - 1
            };

            info.ReadRemainingFields(reader);
            return(info);
        }
Ejemplo n.º 4
0
        internal FieldReference(JavaClassImage classImage, FieldRefInfo fieldRefInfo)
        {
            _name = new LazyValue <string>(() =>
            {
                var constantInfo = classImage.ClassFile.ConstantPool.ResolveConstant(fieldRefInfo.NameAndTypeIndex);
                return(constantInfo is NameAndTypeInfo nameAndTypeInfo
                    ? classImage.ClassFile.ConstantPool.ResolveString(nameAndTypeInfo.NameIndex) ??
                       $"<<<INVALID({nameAndTypeInfo.NameIndex})>>>"
                    : $"<<<INVALID({fieldRefInfo.NameAndTypeIndex})>>>");
            });

            _descriptor = new LazyValue <FieldDescriptor>(() =>
            {
                var constantInfo = classImage.ClassFile.ConstantPool.ResolveConstant(fieldRefInfo.NameAndTypeIndex);
                return(constantInfo is NameAndTypeInfo nameAndTypeInfo
                    ? classImage.ResolveFieldDescriptor(nameAndTypeInfo.DescriptorIndex)
                    : null);
            });

            _declaringClass = new LazyValue <ClassReference>(() =>
                                                             classImage.ResolveClass(fieldRefInfo.ClassIndex));
        }
Ejemplo n.º 5
0
 private void AnalyzeFieldRef(FieldRefInfo fri, CodeDescriptor code)
 {
     Type fieldType = fri.Field.FieldType;
     object[] attrs = fieldType.GetCustomAttributes(typeof(MapToIntrinsicType), false);
     if (attrs.Length == 0)
     {
         if (fri.IsWritten && !fieldType.IsValueType)
         {
             ReportError("Illegal write access to field " +
                 fri.Field.Name + " of class " + fri.Field.DeclaringType.Name + ": At runtime, " +
                 "only value types may be written.");
             return;
         }
         if (fri.IsWritten && fri.Field.IsStatic)
         {
             ReportError("Illegal write access to field " +
                 fri.Field.Name + " of class " + fri.Field.DeclaringType.Name + ": At runtime, " +
                 "only non-static fields may be written.");
             return;
         }
         if (fri.IsRead && !fieldType.IsValueType && !fieldType.IsArray)
         {
             //FIXME
             // E.g. DesignContext.Instance is allowed...
             /*
             ReportError("Illegal read access to field " + fri.Field.Name + " of class " +
                 fri.Field.DeclaringType.Name + ": At runtime, only value types and arrays " +
                 "may be accessed.");
              * */
             return;
         }
     }
 }