Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private Java.Field CompileField(InterField field)
        {
            Messages.Verbose("    Compiling field {0}...", field.ToString());
            Java.Field result = new Java.Field();

            if (field.IsPublic)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Public;
            }
            else if (field.IsProtected)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Protected;
            }
            else
            {
                result.AccessFlags |= Java.FieldAccessFlags.Private;
            }

            if (field.IsStatic)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Static;
            }

            //if it will be readonly, we will get error in CopyTo method of ValueType
            if (((field.IsReadonly) || (field.IsLiteral)) && (!field.DeclaringType.IsValueType))
            {
                result.AccessFlags |= Java.FieldAccessFlags.Final;
            }
            if (field.IsVolatile)
            {
                result.AccessFlags |= Java.FieldAccessFlags.Volatile;
            }

            result.Name       = FieldNameToJava(field.Name);
            result.Descriptor = GetFieldDescriptor(field.FieldType);

            if ((field.IsStatic) && (field.IsThreadLocal))
            {
                result.Descriptor = "L" + TypeNameToJava(ClassNames.JavaLangThreadLocal.ClassName) + ";";
            }

            if (field.Constatnt != null)
            {
                Java.Constant constVal = null;

                if (field.Constatnt is byte)
                {
                    constVal = new Java.Constants.Integer((byte)field.Constatnt);
                }
                else if (field.Constatnt is sbyte)
                {
                    constVal = new Java.Constants.Integer((sbyte)field.Constatnt);
                }
                else if (field.Constatnt is short)
                {
                    constVal = new Java.Constants.Integer((short)field.Constatnt);
                }
                else if (field.Constatnt is ushort)
                {
                    constVal = new Java.Constants.Integer((ushort)field.Constatnt);
                }
                else if (field.Constatnt is int)
                {
                    constVal = new Java.Constants.Integer((int)field.Constatnt);
                }
                else if (field.Constatnt is uint)
                {
                    constVal = new Java.Constants.Integer(unchecked ((int)((uint)field.Constatnt)));
                }
                else if (field.Constatnt is char)
                {
                    constVal = new Java.Constants.Integer((char)field.Constatnt);
                }
                else if (field.Constatnt is bool)
                {
                    constVal = new Java.Constants.Integer((bool)field.Constatnt ? 1 : 0);
                }
                else if (field.Constatnt is long)
                {
                    constVal = new Java.Constants.Long((long)field.Constatnt);
                }
                else if (field.Constatnt is ulong)
                {
                    constVal = new Java.Constants.Long(unchecked ((long)((ulong)field.Constatnt)));
                }
                else if (field.Constatnt is float)
                {
                    constVal = new Java.Constants.Float((float)field.Constatnt);
                }
                else if (field.Constatnt is double)
                {
                    constVal = new Java.Constants.Double((double)field.Constatnt);
                }
                else if (field.Constatnt is string)
                {
                    constVal = new Java.Constants.String((string)field.Constatnt);
                }

                if (constVal != null)
                {
                    result.Attributes.Add(new Java.Attributes.ConstantValue(constVal));
                }
            }

            return(result);
        }