コード例 #1
0
        /// <summary>
        ///     Returns the total size in bytes of all the attributes that correspond to the given field,
        ///     method or class access flags and signature.
        /// </summary>
        /// <remarks>
        ///     Returns the total size in bytes of all the attributes that correspond to the given field,
        ///     method or class access flags and signature. This size includes the 6 header bytes
        ///     (attribute_name_index and attribute_length) per attribute. Also adds the attribute type names
        ///     to the constant pool.
        /// </remarks>
        /// <param name="symbolTable">
        ///     where the constants used in the attributes must be stored.
        /// </param>
        /// <param name="accessFlags">some field, method or class access flags.</param>
        /// <param name="signatureIndex">
        ///     the constant pool index of a field, method of class signature.
        /// </param>
        /// <returns>
        ///     the size of all the attributes in bytes. This size includes the size of the attribute
        ///     headers.
        /// </returns>
        internal static int ComputeAttributesSize(SymbolTable symbolTable, AccessFlags accessFlags
                                                  , int signatureIndex)
        {
            var size = 0;

            // Before Java 1.5, synthetic fields are represented with a Synthetic attribute.
            if (accessFlags.HasFlagFast(AccessFlags.Synthetic) && symbolTable.GetMajorVersion
                    () < OpcodesConstants.V1_5)
            {
                // Synthetic attributes always use 6 bytes.
                symbolTable.AddConstantUtf8(Constants.Synthetic);
                size += 6;
            }

            if (signatureIndex != 0)
            {
                // Signature attributes always use 8 bytes.
                symbolTable.AddConstantUtf8(Constants.Signature);
                size += 8;
            }

            // ACC_DEPRECATED is ASM specific, the ClassFile format uses a Deprecated attribute instead.
            if (accessFlags.HasFlagFast(AccessFlags.Deprecated))
            {
                // Deprecated attributes always use 6 bytes.
                symbolTable.AddConstantUtf8(Constants.Deprecated);
                size += 6;
            }

            return(size);
        }
コード例 #2
0
 /// <summary>
 ///     Constructs a new
 ///     <see cref="TraceSignatureVisitor" />
 ///     .
 /// </summary>
 /// <param name="accessFlags">
 ///     for class type signatures, the access flags of the class.
 /// </param>
 public TraceSignatureVisitor(AccessFlags accessFlags)
     : base(VisitorAsmApiVersion.Asm7)
 {
     /* latest api = */
     isInterface = accessFlags.HasFlagFast(AccessFlags.Interface);
     declaration = new StringBuilder();
 }
コード例 #3
0
 /// <summary>
 ///     Puts all the attributes that correspond to the given field, method or class access flags and
 ///     signature, in the given byte vector.
 /// </summary>
 /// <remarks>
 ///     Puts all the attributes that correspond to the given field, method or class access flags and
 ///     signature, in the given byte vector. This includes the 6 header bytes (attribute_name_index and
 ///     attribute_length) per attribute.
 /// </remarks>
 /// <param name="symbolTable">
 ///     where the constants used in the attributes must be stored.
 /// </param>
 /// <param name="accessFlags">some field, method or class access flags.</param>
 /// <param name="signatureIndex">
 ///     the constant pool index of a field, method of class signature.
 /// </param>
 /// <param name="output">where the attributes must be written.</param>
 internal static void PutAttributes(SymbolTable symbolTable, AccessFlags accessFlags, int
                                    signatureIndex, ByteVector output)
 {
     // Before Java 1.5, synthetic fields are represented with a Synthetic attribute.
     if (accessFlags.HasFlagFast(AccessFlags.Synthetic) && symbolTable.GetMajorVersion
             () < OpcodesConstants.V1_5)
     {
         output.PutShort(symbolTable.AddConstantUtf8(Constants.Synthetic)).PutInt(0);
     }
     if (signatureIndex != 0)
     {
         output.PutShort(symbolTable.AddConstantUtf8(Constants.Signature)).PutInt(2).PutShort
             (signatureIndex);
     }
     if (accessFlags.HasFlagFast(AccessFlags.Deprecated))
     {
         output.PutShort(symbolTable.AddConstantUtf8(Constants.Deprecated)).PutInt(0);
     }
 }
コード例 #4
0
        /// <summary>
        ///     Puts the content of the record component generated by this RecordComponentWriter into the given
        ///     ByteVector.
        /// </summary>
        /// <param name="output">where the record_component_info structure must be put.</param>
        internal void PutRecordComponentInfo(ByteVector output)
        {
            output.PutShort(nameIndex).PutShort(descriptorIndex);
            // Compute and put the attributes_count field.
            // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS.
            var attributesCount = 0;

            if (signatureIndex != 0)
            {
                ++attributesCount;
            }
            if (accessFlags.HasFlagFast(AccessFlags.Deprecated))
            {
                ++attributesCount;
            }
            if (lastRuntimeVisibleAnnotation != null)
            {
                ++attributesCount;
            }
            if (lastRuntimeInvisibleAnnotation != null)
            {
                ++attributesCount;
            }
            if (lastRuntimeVisibleTypeAnnotation != null)
            {
                ++attributesCount;
            }
            if (lastRuntimeInvisibleTypeAnnotation != null)
            {
                ++attributesCount;
            }
            if (firstAttribute != null)
            {
                attributesCount += firstAttribute.GetAttributeCount();
            }
            output.PutShort(attributesCount);
            Attribute.PutAttributes(symbolTable, accessFlags, signatureIndex, output);
            AnnotationWriter.PutAnnotations(symbolTable, lastRuntimeVisibleAnnotation, lastRuntimeInvisibleAnnotation
                                            , lastRuntimeVisibleTypeAnnotation, lastRuntimeInvisibleTypeAnnotation, output);
            if (firstAttribute != null)
            {
                firstAttribute.PutAttributes(symbolTable, output);
            }
        }
コード例 #5
0
        /// <summary>
        ///     Puts the content of the field_info JVMS structure generated by this FieldWriter into the given
        ///     ByteVector.
        /// </summary>
        /// <param name="output">where the field_info structure must be put.</param>
        internal void PutFieldInfo(ByteVector output)
        {
            var useSyntheticAttribute = symbolTable.GetMajorVersion() < OpcodesConstants.V1_5;
            // Put the access_flags, name_index and descriptor_index fields.
            var mask = useSyntheticAttribute ? AccessFlags.Synthetic : 0;

            output.PutShort((int)(accessFlags & ~mask)).PutShort(nameIndex).PutShort(descriptorIndex
                                                                                     );
            // Compute and put the attributes_count field.
            // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS.
            var attributesCount = 0;

            if (constantValueIndex != 0)
            {
                ++attributesCount;
            }
            if (accessFlags.HasFlagFast(AccessFlags.Synthetic) && useSyntheticAttribute)
            {
                ++attributesCount;
            }
            if (signatureIndex != 0)
            {
                ++attributesCount;
            }
            if (accessFlags.HasFlagFast(AccessFlags.Deprecated))
            {
                ++attributesCount;
            }
            if (lastRuntimeVisibleAnnotation != null)
            {
                ++attributesCount;
            }
            if (lastRuntimeInvisibleAnnotation != null)
            {
                ++attributesCount;
            }
            if (lastRuntimeVisibleTypeAnnotation != null)
            {
                ++attributesCount;
            }
            if (lastRuntimeInvisibleTypeAnnotation != null)
            {
                ++attributesCount;
            }
            if (firstAttribute != null)
            {
                attributesCount += firstAttribute.GetAttributeCount();
            }
            output.PutShort(attributesCount);
            // Put the field_info attributes.
            // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS.
            if (constantValueIndex != 0)
            {
                output.PutShort(symbolTable.AddConstantUtf8(Constants.Constant_Value)).PutInt(2)
                .PutShort(constantValueIndex);
            }
            Attribute.PutAttributes(symbolTable, accessFlags, signatureIndex, output);
            AnnotationWriter.PutAnnotations(symbolTable, lastRuntimeVisibleAnnotation, lastRuntimeInvisibleAnnotation
                                            , lastRuntimeVisibleTypeAnnotation, lastRuntimeInvisibleTypeAnnotation, output);
            if (firstAttribute != null)
            {
                firstAttribute.PutAttributes(symbolTable, output);
            }
        }