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); } }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.String); bes.WriteUInt16(string_index); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Utf8); bes.WriteUtf8(str); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Integer); bes.WriteUInt32((uint)v); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Methodref); bes.WriteUInt16(class_index); bes.WriteUInt16(name_and_type_index); }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32((uint)(2 + 2 + 4 + code.Length + 2 + 2)); bes.WriteUInt16(max_stack); bes.WriteUInt16(max_locals); bes.WriteUInt32((uint)code.Length); for (int i = 0; i < code.Length; i++) { bes.WriteByte(code[i]); } bes.WriteUInt16(0); // no exceptions bes.WriteUInt16(0); // no attributes }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Double); bes.WriteDouble(v); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Long); bes.WriteInt64(v); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.NameAndType); bes.WriteUInt16(name_index); bes.WriteUInt16(descriptor_index); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Class); bes.WriteUInt16(name_index); }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32((uint)(mem.Length + 2)); bes.WriteUInt16(count); foreach (byte b in mem.ToArray()) { bes.WriteByte(b); } }
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((string)arr[1])); bes.WriteUInt16(classFile.AddUtf8((string)arr[2])); return; } else if (AnnotationDefaultAttribute.TAG_ARRAY.Equals(arr[0])) { bes.WriteByte(AnnotationDefaultAttribute.TAG_ARRAY); object[] elemarr = (object[])arr[1]; bes.WriteUInt16((ushort)elemarr.Length); foreach (object elem in elemarr) { WriteElementValue(bes, elem); } return; } } throw new NotImplementedException(val.GetType().FullName); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Float); bes.WriteFloat(v); }
public override void Write(BigEndianStream bes) { base.Write(bes); uint length = 1; foreach (RuntimeVisibleAnnotationsAttribute attr in parameters) { length += attr.Length; } bes.WriteUInt32(length); bes.WriteByte((byte)parameters.Count); foreach (RuntimeVisibleAnnotationsAttribute attr in parameters) { attr.WriteImpl(bes); } }
private static void WriteAnnotationElementValue(IKVM.StubGen.ClassFileWriter classFile, IKVM.StubGen.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 { Console.Error.WriteLine("Warning: incorrect annotation default element tag: " + type); } } else { Console.Error.WriteLine("Warning: incorrect annotation default element type: " + value.ArgumentType); } }
public override void Write(BigEndianStream bes) { base.Write(bes); if (flags == null || names == null || flags.Length != names.Length) { // write a malformed MethodParameters attribute bes.WriteUInt32(0); return; } bes.WriteUInt32((uint)(1 + names.Length * 4)); bes.WriteByte((byte)names.Length); for (int i = 0; i < names.Length; i++) { bes.WriteUInt16(names[i]); bes.WriteUInt16(flags[i]); } }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32((uint)(1 + names.Length * 4)); bes.WriteByte((byte)names.Length); foreach (ushort idx in names) { bes.WriteUInt16(idx); bes.WriteUInt16(0); } }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32((uint)(buf.Length)); foreach (byte b in buf) { bes.WriteByte(b); } }
internal void WriteImpl(BigEndianStream bes) { bes.WriteUInt16(count); foreach (byte b in mem.ToArray()) { bes.WriteByte(b); } }
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(); }
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)); } }
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()); }