コード例 #1
0
        /// <exception cref="System.IO.IOException"/>
        public override void InitContent(DataInputFullStream data, ConstantPool pool)
        {
            int method_number = data.ReadUnsignedShort();

            for (int i = 0; i < method_number; ++i)
            {
                int bootstrap_method_ref             = data.ReadUnsignedShort();
                int num_bootstrap_arguments          = data.ReadUnsignedShort();
                List <PooledConstant> list_arguments = new List <PooledConstant>();
                for (int j = 0; j < num_bootstrap_arguments; ++j)
                {
                    int bootstrap_argument_ref = data.ReadUnsignedShort();
                    list_arguments.Add(pool.GetConstant(bootstrap_argument_ref));
                }
                methodRefs.Add(pool.GetLinkConstant(bootstrap_method_ref));
                methodArguments.Add(list_arguments);
            }
        }
コード例 #2
0
ファイル: AttributeFactory.cs プロジェクト: molunshang/JVM
        public static IAttribute ReadAttribute(this ClassReader reader, ConstantPool pool)
        {
            var nameIndex = reader.ReadU2();
            var length    = reader.ReadU4();
            var name      = pool.GetUtf8String(nameIndex);

            if (!Enum.TryParse <AttributeType>(name, true, out var type))
            {
                type = AttributeType.Unparsed;
            }
            switch (type)
            {
            case AttributeType.Deprecated:
                return(new DeprecatedAttribute());

            case AttributeType.Synthetic:
                return(new SyntheticAttribute());

            case AttributeType.SourceFile:
                var fileNameIndex = reader.ReadU2();
                return(new SourceFileAttribute(pool.GetUtf8String(fileNameIndex)));

            case AttributeType.ConstantValue:
                var constantIndex = reader.ReadU2();
                return(new ConstantValueAttribute(pool.GetConstant(constantIndex)));

            case AttributeType.Code:
                ushort stack = reader.ReadU2(), locals = reader.ReadU2();
                var    codelength = reader.ReadU4();
                var    code       = reader.ReadBytes((int)codelength);
                return(new CodeAttribute(stack, locals, code, ReadExceptionTables(reader), ReadAttributes(reader, pool)));

            case AttributeType.Exceptions:
                return(new ExceptionsAttribute(reader.ReadU2S()));

            case AttributeType.LineNumberTable:
                return(new LineNumberTableAttribute(ReadLineNumberTableEntrys(reader)));

            case AttributeType.LocalVariableTable:
                return(new LocalVariableTableAttribute(ReadLocalVariableTableEntrys(reader)));
            }
            return(new UnparsedAttribute(reader.ReadBytes((int)length)));
        }