コード例 #1
0
        private static void FixupConstantPoolIndex(ClassFileWriter writer, byte[] typeAnnotations, object[] constantPool, ref int pos)
        {
            ushort index = ReadUInt16BE(typeAnnotations, ref pos);
            object item  = constantPool[index];

            if (item is int)
            {
                index = writer.AddInt((int)item);
            }
            else if (item is long)
            {
                index = writer.AddLong((long)item);
            }
            else if (item is float)
            {
                index = writer.AddFloat((float)item);
            }
            else if (item is double)
            {
                index = writer.AddDouble((double)item);
            }
            else if (item is string)
            {
                index = writer.AddUtf8((string)item);
            }
            else
            {
                throw new IndexOutOfRangeException();
            }
            typeAnnotations[pos - 2] = (byte)(index >> 8);
            typeAnnotations[pos - 1] = (byte)(index >> 0);
        }
コード例 #2
0
    private static byte[] GetAnnotationDefault(IKVM.StubGen.ClassFileWriter classFile, TypeWrapper type)
    {
        MemoryStream mem = new MemoryStream();

        IKVM.StubGen.BigEndianStream bes = new IKVM.StubGen.BigEndianStream(mem);
        if (type == PrimitiveTypeWrapper.BOOLEAN)
        {
            bes.WriteByte((byte)'Z');
            bes.WriteUInt16(0);
        }
        else if (type == PrimitiveTypeWrapper.BYTE)
        {
            bes.WriteByte((byte)'B');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.CHAR)
        {
            bes.WriteByte((byte)'C');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.SHORT)
        {
            bes.WriteByte((byte)'S');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.INT)
        {
            bes.WriteByte((byte)'I');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.FLOAT)
        {
            bes.WriteByte((byte)'F');
            bes.WriteUInt16(classFile.AddFloat(0));
        }
        else if (type == PrimitiveTypeWrapper.LONG)
        {
            bes.WriteByte((byte)'J');
            bes.WriteUInt16(classFile.AddLong(0));
        }
        else if (type == PrimitiveTypeWrapper.DOUBLE)
        {
            bes.WriteByte((byte)'D');
            bes.WriteUInt16(classFile.AddDouble(0));
        }
        else if (type == CoreClasses.java.lang.String.Wrapper)
        {
            bes.WriteByte((byte)'s');
            bes.WriteUInt16(classFile.AddUtf8(""));
        }
        else if ((type.Modifiers & Modifiers.Enum) != 0)
        {
            bes.WriteByte((byte)'e');
            bes.WriteUInt16(classFile.AddUtf8("L" + type.Name.Replace('.', '/') + ";"));
            bes.WriteUInt16(classFile.AddUtf8("__unspecified"));
        }
        else if (type == CoreClasses.java.lang.Class.Wrapper)
        {
            bes.WriteByte((byte)'c');
            bes.WriteUInt16(classFile.AddUtf8("Likvm/internal/__unspecified;"));
        }
        else if (type.IsArray)
        {
            bes.WriteByte((byte)'[');
            bes.WriteUInt16(0);
        }
        else
        {
            throw new InvalidOperationException();
        }
        return(mem.ToArray());
    }
コード例 #3
0
ファイル: StubGenerator.cs プロジェクト: T0pp3r/ikvm-fork
 private static void WriteAnnotationElementValue(ClassFileWriter classFile, BigEndianStream bes, CustomAttributeTypedArgument value)
 {
     if (value.ArgumentType == Types.Boolean)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)value.Value ? 1 : 0));
     }
     else if (value.ArgumentType == Types.Byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)value.Value));
     }
     else if (value.ArgumentType == Types.Char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)value.Value));
     }
     else if (value.ArgumentType == Types.Int16)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)value.Value));
     }
     else if (value.ArgumentType == Types.Int32)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)value.Value));
     }
     else if (value.ArgumentType == Types.Single)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)value.Value));
     }
     else if (value.ArgumentType == Types.Int64)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)value.Value));
     }
     else if (value.ArgumentType == Types.Double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)value.Value));
     }
     else if (value.ArgumentType == Types.String)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)value.Value));
     }
     else if (value.ArgumentType == Types.Object.MakeArrayType())
     {
         CustomAttributeTypedArgument[] array = (CustomAttributeTypedArgument[])value.Value;
         byte type = (byte)array[0].Value;
         if (type == AnnotationDefaultAttribute.TAG_ARRAY)
         {
             bes.WriteByte((byte)'[');
             bes.WriteUInt16((ushort)(array.Length - 1));
             for (int i = 1; i < array.Length; i++)
             {
                 WriteAnnotationElementValue(classFile, bes, array[i]);
             }
         }
         else if (type == AnnotationDefaultAttribute.TAG_CLASS)
         {
             bes.WriteByte((byte)'c');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ENUM)
         {
             bes.WriteByte((byte)'e');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16(classFile.AddUtf8((string)array[2].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ANNOTATION)
         {
             bes.WriteByte((byte)'@');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16((ushort)((array.Length - 2) / 2));
             for (int i = 2; i < array.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)array[i].Value));
                 WriteAnnotationElementValue(classFile, bes, array[i + 1]);
             }
         }
         else
         {
             Warning("Warning: incorrect annotation default element tag: " + type);
         }
     }
     else
     {
         Warning("Warning: incorrect annotation default element type: " + value.ArgumentType);
     }
 }
コード例 #4
0
ファイル: StubGenerator.cs プロジェクト: T0pp3r/ikvm-fork
 private static byte[] GetAnnotationDefault(ClassFileWriter classFile, TypeWrapper type)
 {
     MemoryStream mem = new MemoryStream();
     BigEndianStream bes = new BigEndianStream(mem);
     if (type == PrimitiveTypeWrapper.BOOLEAN)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.BYTE)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.CHAR)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.SHORT)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.INT)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.FLOAT)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat(0));
     }
     else if (type == PrimitiveTypeWrapper.LONG)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong(0));
     }
     else if (type == PrimitiveTypeWrapper.DOUBLE)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble(0));
     }
     else if (type == CoreClasses.java.lang.String.Wrapper)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8(""));
     }
     else if ((type.Modifiers & Modifiers.Enum) != 0)
     {
         bes.WriteByte((byte)'e');
         bes.WriteUInt16(classFile.AddUtf8("L" + type.Name.Replace('.', '/') + ";"));
         bes.WriteUInt16(classFile.AddUtf8("__unspecified"));
     }
     else if (type == CoreClasses.java.lang.Class.Wrapper)
     {
         bes.WriteByte((byte)'c');
         bes.WriteUInt16(classFile.AddUtf8("Likvm/internal/__unspecified;"));
     }
     else if (type.IsArray)
     {
         bes.WriteByte((byte)'[');
         bes.WriteUInt16(0);
     }
     else
     {
         throw new InvalidOperationException();
     }
     return mem.ToArray();
 }
コード例 #5
0
 private void WriteElementValue(BigEndianStream bes, object val)
 {
     if (val is object[])
     {
         object[] arr = (object[])val;
         if (AnnotationDefaultAttribute.TAG_ENUM.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ENUM);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
             bes.WriteUInt16(classFile.AddUtf8((string)arr[2]));
         }
         else if (AnnotationDefaultAttribute.TAG_ARRAY.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ARRAY);
             bes.WriteUInt16((ushort)(arr.Length - 1));
             for (int i = 1; i < arr.Length; i++)
             {
                 WriteElementValue(bes, arr[i]);
             }
         }
         else if (AnnotationDefaultAttribute.TAG_CLASS.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_CLASS);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
         }
         else if (AnnotationDefaultAttribute.TAG_ANNOTATION.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ANNOTATION);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
             bes.WriteUInt16((ushort)((arr.Length - 2) / 2));
             for (int i = 2; i < arr.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)arr[i]));
                 WriteElementValue(bes, arr[i + 1]);
             }
         }
     }
     else if (val is bool)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)val ? 1 : 0));
     }
     else if (val is byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)val));
     }
     else if (val is char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)val));
     }
     else if (val is short)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)val));
     }
     else if (val is int)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)val));
     }
     else if (val is long)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)val));
     }
     else if (val is float)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)val));
     }
     else if (val is double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)val));
     }
     else if (val is string)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)val));
     }
 }
コード例 #6
0
 private static void WriteAnnotationElementValue(ClassFileWriter classFile, BigEndianStream bes, CustomAttributeTypedArgument value)
 {
     if (value.ArgumentType == Types.Boolean)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)value.Value ? 1 : 0));
     }
     else if (value.ArgumentType == Types.Byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)value.Value));
     }
     else if (value.ArgumentType == Types.Char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)value.Value));
     }
     else if (value.ArgumentType == Types.Int16)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)value.Value));
     }
     else if (value.ArgumentType == Types.Int32)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)value.Value));
     }
     else if (value.ArgumentType == Types.Single)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)value.Value));
     }
     else if (value.ArgumentType == Types.Int64)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)value.Value));
     }
     else if (value.ArgumentType == Types.Double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)value.Value));
     }
     else if (value.ArgumentType == Types.String)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)value.Value));
     }
     else if (value.ArgumentType == Types.Object.MakeArrayType())
     {
         CustomAttributeTypedArgument[] array = (CustomAttributeTypedArgument[])value.Value;
         byte type = (byte)array[0].Value;
         if (type == AnnotationDefaultAttribute.TAG_ARRAY)
         {
             bes.WriteByte((byte)'[');
             bes.WriteUInt16((ushort)(array.Length - 1));
             for (int i = 1; i < array.Length; i++)
             {
                 WriteAnnotationElementValue(classFile, bes, array[i]);
             }
         }
         else if (type == AnnotationDefaultAttribute.TAG_CLASS)
         {
             bes.WriteByte((byte)'c');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ENUM)
         {
             bes.WriteByte((byte)'e');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16(classFile.AddUtf8((string)array[2].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ANNOTATION)
         {
             bes.WriteByte((byte)'@');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16((ushort)((array.Length - 2) / 2));
             for (int i = 2; i < array.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)array[i].Value));
                 WriteAnnotationElementValue(classFile, bes, array[i + 1]);
             }
         }
         else
         {
             Warning("Warning: incorrect annotation default element tag: " + type);
         }
     }
     else
     {
         Warning("Warning: incorrect annotation default element type: " + value.ArgumentType);
     }
 }
コード例 #7
0
ファイル: StubGenerator.cs プロジェクト: Semogj/ikvm-fork
		private static void FixupConstantPoolIndex(ClassFileWriter writer, byte[] typeAnnotations, object[] constantPool, ref int pos)
		{
			ushort index = ReadUInt16BE(typeAnnotations, ref pos);
			object item = constantPool[index];
			if (item is int)
			{
				index = writer.AddInt((int)item);
			}
			else if (item is long)
			{
				index = writer.AddLong((long)item);
			}
			else if (item is float)
			{
				index = writer.AddFloat((float)item);
			}
			else if (item is double)
			{
				index = writer.AddDouble((double)item);
			}
			else if (item is string)
			{
				index = writer.AddUtf8((string)item);
			}
			else
			{
				throw new IndexOutOfRangeException();
			}
			typeAnnotations[pos - 2] = (byte)(index >> 8);
			typeAnnotations[pos - 1] = (byte)(index >> 0);
		}