Esempio n. 1
0
 /// <summary>
 ///     Constructs a new
 ///     <see cref="FieldWriter" />
 ///     .
 /// </summary>
 /// <param name="symbolTable">
 ///     where the constants used in this FieldWriter must be stored.
 /// </param>
 /// <param name="access">
 ///     the field's access flags (see
 ///     <see cref="Opcodes" />
 ///     ).
 /// </param>
 /// <param name="name">the field's name.</param>
 /// <param name="descriptor">
 ///     the field's descriptor (see
 ///     <see cref="Type" />
 ///     ).
 /// </param>
 /// <param name="signature">
 ///     the field's signature. May be
 ///     <literal>null</literal>
 ///     .
 /// </param>
 /// <param name="constantValue">
 ///     the field's constant value. May be
 ///     <literal>null</literal>
 ///     .
 /// </param>
 internal FieldWriter(SymbolTable symbolTable, AccessFlags access, string name, string descriptor
                      , string signature, object constantValue)
     : base(VisitorAsmApiVersion.Asm7)
 {
     // Note: fields are ordered as in the field_info structure, and those related to attributes are
     // ordered as in Section 4.7 of the JVMS.
     // -----------------------------------------------------------------------------------------------
     // Constructor
     // -----------------------------------------------------------------------------------------------
     /* latest api = */
     this.symbolTable = symbolTable;
     accessFlags      = access;
     nameIndex        = symbolTable.AddConstantUtf8(name);
     descriptorIndex  = symbolTable.AddConstantUtf8(descriptor);
     if (signature != null)
     {
         signatureIndex = symbolTable.AddConstantUtf8(signature);
     }
     if (constantValue != null)
     {
         constantValueIndex = symbolTable.AddConstant(constantValue).index;
     }
 }
Esempio n. 2
0
 /* useNamedValues = */
 // -----------------------------------------------------------------------------------------------
 // Implementation of the AnnotationVisitor abstract class
 // -----------------------------------------------------------------------------------------------
 public override void Visit(string name, object value)
 {
     // Case of an element_value with a const_value_index, class_info_index or array_index field.
     // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1.
     ++numElementValuePairs;
     if (useNamedValues)
     {
         annotation.PutShort(symbolTable.AddConstantUtf8(name));
     }
     if (value is string)
     {
         annotation.Put12('s', symbolTable.AddConstantUtf8((string)value));
     }
     else if (value is byte)
     {
         annotation.Put12('B', symbolTable.AddConstantInteger((byte)value).index);
     }
     else if (value is bool)
     {
         var booleanValue = (bool)value ? 1 : 0;
         annotation.Put12('Z', symbolTable.AddConstantInteger(booleanValue).index);
     }
     else if (value is char)
     {
         annotation.Put12('C', symbolTable.AddConstantInteger((char)value).index);
     }
     else if (value is short)
     {
         annotation.Put12('S', symbolTable.AddConstantInteger((short)value).index);
     }
     else if (value is Type)
     {
         annotation.Put12('c', symbolTable.AddConstantUtf8(((Type)value).GetDescriptor()));
     }
     else if (value is byte[])
     {
         var byteArray = (byte[])value;
         annotation.Put12('[', byteArray.Length);
         foreach (var byteValue in byteArray)
         {
             annotation.Put12('B', symbolTable.AddConstantInteger(byteValue).index);
         }
     }
     else if (value is bool[])
     {
         var booleanArray = (bool[])value;
         annotation.Put12('[', booleanArray.Length);
         foreach (var booleanValue in booleanArray)
         {
             annotation.Put12('Z', symbolTable.AddConstantInteger(booleanValue ? 1 : 0).index);
         }
     }
     else if (value is short[])
     {
         var shortArray = (short[])value;
         annotation.Put12('[', shortArray.Length);
         foreach (var shortValue in shortArray)
         {
             annotation.Put12('S', symbolTable.AddConstantInteger(shortValue).index);
         }
     }
     else if (value is char[])
     {
         var charArray = (char[])value;
         annotation.Put12('[', charArray.Length);
         foreach (var charValue in charArray)
         {
             annotation.Put12('C', symbolTable.AddConstantInteger(charValue).index);
         }
     }
     else if (value is int[])
     {
         var intArray = (int[])value;
         annotation.Put12('[', intArray.Length);
         foreach (var intValue in intArray)
         {
             annotation.Put12('I', symbolTable.AddConstantInteger(intValue).index);
         }
     }
     else if (value is long[])
     {
         var longArray = (long[])value;
         annotation.Put12('[', longArray.Length);
         foreach (var longValue in longArray)
         {
             annotation.Put12('J', symbolTable.AddConstantLong(longValue).index);
         }
     }
     else if (value is float[])
     {
         var floatArray = (float[])value;
         annotation.Put12('[', floatArray.Length);
         foreach (var floatValue in floatArray)
         {
             annotation.Put12('F', symbolTable.AddConstantFloat(floatValue).index);
         }
     }
     else if (value is double[])
     {
         var doubleArray = (double[])value;
         annotation.Put12('[', doubleArray.Length);
         foreach (var doubleValue in doubleArray)
         {
             annotation.Put12('D', symbolTable.AddConstantDouble(doubleValue).index);
         }
     }
     else
     {
         var symbol = symbolTable.AddConstant(value);
         annotation.Put12(".s.IFJDCS"[symbol.tag], symbol.index);
     }
 }