Beispiel #1
0
        protected override bool CompareEqwals(Constant c)
        {
            FieldRef Another = (FieldRef)c;

            return((Class == Another.Class) && (Name == Another.Name) && (Descriptor == Another.Descriptor));
        }
        public ConstantPool Read(BinaryReader Reader)
        {
            ushort Count = Reader.ReadUInt16BE();

            ResultPool     = new ConstantPool();
            FiledConsts    = new bool[Count];
            FiledConsts[0] = true;
            RawData        = new byte[Count][];

            for (int i = 1; i < Count; i++)
            {
                Constant    Result = null;
                ConstantTag Tag    = (ConstantTag)Reader.ReadByte();

                switch (Tag)
                {
                case ConstantTag.Utf8:                  Result = new Constants.Utf8(); break;

                case ConstantTag.Integer:               Result = new Constants.Integer(); break;

                case ConstantTag.Float:                 Result = new Constants.Float(); break;

                case ConstantTag.Long:                  Result = new Constants.Long(); break;

                case ConstantTag.Double:                Result = new Constants.Double(); break;

                case ConstantTag.Class:                 Result = new Constants.Class(); break;

                case ConstantTag.String:                Result = new Constants.String(); break;

                case ConstantTag.FieldRef:              Result = new Constants.FieldRef(); break;

                case ConstantTag.MethodRef:             Result = new Constants.MethodRef(); break;

                case ConstantTag.InterfaceMethodRef:    Result = new Constants.InterfaceMethodRef(); break;

                case ConstantTag.NameAndType:           Result = new Constants.NameAndType(); break;

                case ConstantTag.MethodHandle:          Result = new Constants.MethodHandle(); break;

                case ConstantTag.MethodType:            Result = new Constants.MethodType(); break;

                case ConstantTag.InvokeDynamic:         Result = new Constants.InvokeDynamic(); break;
                }

                if (Result == null)
                {
                    ResultPool.ForceAddConstant(new Constants.Skip(), (ushort)i);
                    Messages.Message(MessageCode.JavaUnknownConstantTag, ((byte)Tag).ToString());
                    continue;
                }

                RawData[i] = Result.ReadData(Reader);
                ResultPool.ForceAddConstant(Result, (ushort)i);
                if (Result.Is8Byte())
                {
                    FiledConsts[++i] = true;
                }
            }

            for (int i = 1; i < Count; i++)
            {
                GetFilledConstant((ushort)i);
            }

            return(ResultPool);
        }
Beispiel #3
0
        private void GenerateLocalByRefType(JavaPrimitiveType type)
        {
            GenerateBaseByRefType(type);

            string valueFieldDesc = "L" + TypeNameToJava(ClassNames.JavaObject) + ";";

            if (type != JavaPrimitiveType.Ref)
            {
                valueFieldDesc = JavaPrimitive2FieldChar[(int)type].ToString();
            }

            Java.Class javaClass = new Java.Class();
            javaClass.AccessFlag = Java.ClassAccessFlag.Final | Java.ClassAccessFlag.Public | Java.ClassAccessFlag.Super;
            javaClass.ThisClass  = TypeNameToJava(new JavaByRefType(ByRefPlace.Local, type).ToString());
            javaClass.SuperClass = TypeNameToJava(new JavaByRefType(ByRefPlace.Unknown, type).ToString());

            Java.Field valueField = new Java.Field();
            valueField.AccessFlags = Java.FieldAccessFlags.Private;
            valueField.Name        = "value";
            valueField.Descriptor  = valueFieldDesc;
            javaClass.Fields.Add(valueField);

            Java.Constants.FieldRef  valueRef     = new Java.Constants.FieldRef(javaClass.ThisClass, "value", valueFieldDesc);
            Java.Constants.MethodRef superCtorRef =
                new Java.Constants.MethodRef(javaClass.SuperClass, ClassNames.JavaConstructorMethodName, "()V");

            Java.Method ctor = new Java.Method();
            ctor.AccessFlags = Java.MethodAccessFlags.Public;
            ctor.Name        = ClassNames.JavaConstructorMethodName;
            ctor.Descriptor  = "(" + valueFieldDesc + ")V";
            ctor.Attributes.Add(new JavaBytecodeWriter()
                                .Add(OpCodes.aload_0)
                                .Add(OpCodes.invokespecial, superCtorRef)
                                .Add(OpCodes.aload_0)
                                .AddLoad(type, 1)
                                .Add(OpCodes.putfield, valueRef)
                                .AddReturn(JavaPrimitiveType.Void)
                                .End(javaClass.ConstantPool)
                                );
            javaClass.Methods.Add(ctor);

            Java.Method get = new Method();
            get.AccessFlags = Java.MethodAccessFlags.Public;
            get.Name        = ClassNames.ByRef.GetValueMethodName;
            get.Descriptor  = "()" + valueFieldDesc;
            get.Attributes.Add(new JavaBytecodeWriter()
                               .Add(OpCodes.aload_0)
                               .Add(OpCodes.getfield, valueRef)
                               .AddReturn(type)
                               .End(javaClass.ConstantPool));
            javaClass.Methods.Add(get);

            Java.Method set = new Method();
            set.AccessFlags = MethodAccessFlags.Public;
            set.Name        = ClassNames.ByRef.SetValueMethodName;
            set.Descriptor  = "(" + valueFieldDesc + ")V";
            set.Attributes.Add(new JavaBytecodeWriter()
                               .Add(OpCodes.aload_0)
                               .AddLoad(type, 1)
                               .Add(OpCodes.putfield, valueRef)
                               .AddReturn(JavaPrimitiveType.Void)
                               .End(javaClass.ConstantPool));
            javaClass.Methods.Add(set);

            WriteClass(javaClass);
        }