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); }
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; } } }
/// <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); }
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)); }
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; } } }