Пример #1
0
        public short AddConstantClass(Type c)
        {
            if (c == null) return 0;

            var nameIndex = AddConstantUtf8(c.GetDescriptor(true));
            var classConst = ConstantPool.OfType<CompileConstantClass>().FirstOrDefault(x => x.NameIndex == nameIndex);

            if (classConst == null)
            {
                classConst = new CompileConstantClass { PoolIndex = nextConstantIndex++, NameIndex = nameIndex };

                ConstantPool.Add(classConst);
            }

            return classConst.PoolIndex;
        }
Пример #2
0
        private static CompileConstant[] ReadConstants(EndianBinaryReader reader)
        {
            short constantCount = reader.ReadInt16();
            var constants = new CompileConstant[constantCount];

            for (int i = 1; i < constantCount; i++)
            {
                var tag = (CompileConstants)reader.ReadByte();
                switch (tag)
                {
                    case CompileConstants.Class:
                        constants[i] = new CompileConstantClass().Read(reader);
                        break;
                    case CompileConstants.Fieldref:
                        constants[i] = new CompileConstantFieldref().Read(reader);
                        break;
                    case CompileConstants.Methodref:
                        constants[i] = new CompileConstantMethodref().Read(reader);
                        break;
                    case CompileConstants.InterfaceMethodref:
                        constants[i] = new CompileConstantInterfaceMethodref().Read(reader);
                        break;
                    case CompileConstants.String:
                        constants[i] = new CompileConstantString().Read(reader);
                        break;
                    case CompileConstants.Integer:
                        constants[i] = new CompileConstantInteger().Read(reader);
                        break;
                    case CompileConstants.Float:
                        constants[i] = new CompileConstantFloat().Read(reader);
                        break;
                    case CompileConstants.Long:
                        constants[i] = new CompileConstantLong().Read(reader);
                        i++; // The next slot is invalid
                        break;
                    case CompileConstants.Double:
                        constants[i] = new CompileConstantDouble().Read(reader);
                        i++; // The next slot is invalid
                        break;
                    case CompileConstants.NameAndType:
                        constants[i] = new CompileConstantNameAndType().Read(reader);
                        break;
                    case CompileConstants.Utf8:
                        constants[i] = new CompileConstantUtf8().Read(reader);
                        break;
                    case CompileConstants.MethodHandle:
                        constants[i] = new CompileConstantMethodHandle().Read(reader);
                        break;
                    case CompileConstants.MethodType:
                        constants[i] = new CompileConstantMethodType().Read(reader);
                        break;
                    case CompileConstants.InvokeDynamic:
                        constants[i] = new CompileConstantInvokeDynamic().Read(reader);
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }

            return constants;
        }