Module Attribute

module Attribute: sig .. end
Attributes in both low- and high-level forms. It also provides conversion functions between levels as well as i/o functions for low-level.


Low-level form

type info = {
   name_index :Utils.u2;
   length :Utils.u4;
   data :string;
}
Represents an attribute as defined in the class file format specification.

Exception

type error = 
| Invalid_code_attribute
| Invalid_code_length
| Defined_twice of string
| Invalid_field_attribute
| Invalid_method_attribute
| Invalid_class_attribute
| Invalid_package_attribute
| Invalid_module_attribute
| Invalid_constant_value
| Invalid_enclosing_method
| Invalid_local_variable_table
| Invalid_local_variable_type_table
| Invalid_list_length
| Invalid_attribute_name_value
| Invalid_exception_name
| Invalid_exception
| Invalid_inner_class
| Invalid_outer_class
| Invalid_signature
| Invalid_source_file
| Invalid_stack_map_frame
| Invalid_stack_map_verification_type
| Invalid_bootstrap_method_handle
| Invalid_bootstrap_argument
| Invalid_module
| Invalid_module_dependency_kind
| Missing_module_attribute
exception Exception of error
val string_of_error : error -> string

I/O functions

val read_info : InputStream.t -> info
read_info st reads an attribute from st. Raises InputStream.Exception if an i/o error occurs.
val write_info : OutputStream.t -> info -> unit
write_info st a writes an attribute a onto st. Raises OutputStream.Exception if an i/o error occurs.

High-level form

type constant_value = 
| Long_value of int64 (*long constant*)
| Float_value of float (*float constant*)
| Double_value of float (*double constant*)
| Boolean_value of bool (*boolean constant*)
| Byte_value of int (*byte constant*)
| Character_value of int (*char constant*)
| Short_value of int (*short constant*)
| Integer_value of int32 (*int constant*)
| String_value of Utils.UTF8.t (*string constant*)
Constant values used by ConstantValue attribute.
val equal_constant_value : constant_value -> constant_value -> bool
Equality over constant values.
val compare_constant_value : constant_value -> constant_value -> int
Comparison over constant values.
val hash_constant_value : constant_value -> int
Hash function over constant values.
type verification_type_info = 
| Top_variable_info (*top type.*)
| Integer_variable_info (*int type.*)
| Float_variable_info (*float type.*)
| Long_variable_info (*long type.*)
| Double_variable_info (*double type.*)
| Null_variable_info (*null value type.*)
| Uninitialized_this_variable_info (*uninitialized type (for this).*)
| Object_variable_info of [ `Array_type of Descriptor.array_type
| `Class_or_interface of Name.for_class ]
(*Object type (parameter is the class name).*)
| Uninitialized_variable_info of Utils.u2 (*uninitialized type (parameter is the code offset of the new instruction that created the object).*)
Verification types.
val equal_verification_type_info : verification_type_info -> verification_type_info -> bool
Equality over verification type informations.
val compare_verification_type_info : verification_type_info -> verification_type_info -> int
Comparison over verification type informations.
val hash_verification_type_info : verification_type_info -> int
Hash function over verification type informations.
type stack_map_frame = 
| Same_frame of Utils.u2 (*Same locals, operand stack is empty (parameter is code offset).*)
| Same_locals_1_stack_item_frame of Utils.u2 * verification_type_info (*Same locals with one stack item (parameters are code offset and type of stack item).*)
| Chop_1_frame of Utils.u2 (*Frame choped by 1 local element, operand stack is empty (parameter is code offset).*)
| Chop_2_frame of Utils.u2 (*Frame choped by 2 local elements, operand stack is empty (parameter is code offset).*)
| Chop_3_frame of Utils.u2 (*Frame choped by 3 local elements, operand stack is empty (parameter is code offset).*)
| Append_1_frame of Utils.u2 * verification_type_info (*Frame appended by 1 local element, operand stack is empty (parameters are code offset and type of additional element).*)
| Append_2_frame of Utils.u2 * verification_type_info
* verification_type_info
(*Frame appended by 2 local elements, operand stack is empty (parameters are code offset and types of additional elements).*)
| Append_3_frame of Utils.u2 * verification_type_info
* verification_type_info * verification_type_info
(*Frame appended by 3 local elements, operand stack is empty (parameters are code offset and types of additional elements).*)
| Full_frame of Utils.u2 * verification_type_info list
* verification_type_info list
(*Full frame definition (parameters are code offset and lists of locals and stack elements).*)
Stack map frame modifications.
val equal_stack_map_frame : stack_map_frame -> stack_map_frame -> bool
Equality over stack map frames.
val compare_stack_map_frame : stack_map_frame -> stack_map_frame -> int
Comparison over stack map frames.
val hash_stack_map_frame : stack_map_frame -> int
Hash function over stack map frames.
type dependency_kind = 
| Optional_dependency (*The dependency is optional.*)
| Same_class_loader (*Both modules must be loaded by the same class loader.*)
| Not_observable (*The depended module types are not observable from the depending module.*)
The kinds of module-to-module dependencies.
type t = [ `AnnotationDefault of Annotation.element_value
| `BootstrapMethods of Bootstrap.method_specifier list
| `Code of code_value
| `ConstantValue of constant_value
| `Deprecated
| `EnclosingMethod of enclosing_method_value
| `Exceptions of Name.for_class list
| `InnerClasses of inner_class_element list
| `LineNumberTable of (Utils.u2 * Utils.u2) list
| `LocalVariableTable of local_variable_table_element list
| `LocalVariableTypeTable of local_variable_type_table_element list
| `Module of Utils.UTF8.t * Utils.UTF8.t
| `ModulePermits of (Utils.UTF8.t * Utils.UTF8.t) list
| `ModuleProvides of (Utils.UTF8.t * Utils.UTF8.t) list
| `ModuleRequires of
(Utils.UTF8.t * Utils.UTF8.t * dependency_kind) list
| `RuntimeInvisibleAnnotations of Annotation.t list
| `RuntimeInvisibleParameterAnnotations of Annotation.t list list
| `RuntimeInvisibleTypeAnnotations of Annotation.extended list
| `RuntimeVisibleAnnotations of Annotation.t list
| `RuntimeVisibleParameterAnnotations of Annotation.t list list
| `RuntimeVisibleTypeAnnotations of Annotation.extended list
| `Signature of signature
| `SourceDebugExtension of Utils.UTF8.t
| `SourceFile of Utils.UTF8.t
| `StackMapTable of stack_map_frame list
| `Synthetic
| `Unknown of Utils.UTF8.t * string ]
type signature = [ `Class of Signature.class_signature
| `Field of Signature.field_type_signature
| `Method of Signature.method_signature ]
type code_attribute = [ `LineNumberTable of (Utils.u2 * Utils.u2) list
| `LocalVariableTable of local_variable_table_element list
| `LocalVariableTypeTable of local_variable_type_table_element list
| `StackMapTable of stack_map_frame list
| `Unknown of Utils.UTF8.t * string ]
type code_value = {
   max_stack :Utils.u2;
   max_locals :Utils.u2;
   code :Instruction.t list;
   exception_table :exception_table_element list;
   attributes :code_attribute list;
}
type exception_table_element = {
   try_start :Utils.u2;
   try_end :Utils.u2;
   catch :Utils.u2;
   caught :Name.for_class option;
}
type inner_class_element = {
   inner_class :Name.for_class option;
   outer_class :Name.for_class option;
   inner_name :Utils.UTF8.t option;
   inner_flags :AccessFlag.for_inner_class list;
}
type enclosing_method_value = {
   innermost_class :Name.for_class;
   enclosing_method :(Name.for_method * Descriptor.for_method) option;
}
type local_variable_table_element = {
   local_start :Utils.u2;
   local_length :Utils.u2;
   local_name :Utils.UTF8.t;
   local_descriptor :Descriptor.for_field;
   local_index :Utils.u2;
}
type local_variable_type_table_element = {
   local_type_start :Utils.u2;
   local_type_length :Utils.u2;
   local_type_name :Utils.UTF8.t;
   local_type_signature :Signature.field_type_signature;
   local_type_index :Utils.u2;
}
val equal_signature : signature -> signature -> bool
Equality over signatures.
val compare_signature : signature -> signature -> int
Comparison over signatures.
val hash_signature : signature -> int
Hash function over signatures.
val equal_code_attribute : code_attribute -> code_attribute -> bool
Equality over code attributes.
val compare_code_attribute : code_attribute -> code_attribute -> int
Comparison over code attributes.
val hash_code_attribute : code_attribute -> int
Hash function over code attributes.
val equal_code_value : code_value -> code_value -> bool
Equality over code values.
val compare_code_value : code_value -> code_value -> int
Comparison over code values.
val hash_code_value : code_value -> int
Hash function over code values.
val equal_exception_table_element : exception_table_element ->
exception_table_element -> bool
Equality over exception table elements.
val compare_exception_table_element : exception_table_element -> exception_table_element -> int
Comparison over exception table elements.
val hash_exception_table_element : exception_table_element -> int
Hash function over exception table elements.
val equal_inner_class_element : inner_class_element -> inner_class_element -> bool
Equality over inner class elements.
val compare_inner_class_element : inner_class_element -> inner_class_element -> int
Comparison over inner class elements.
val hash_inner_class_element : inner_class_element -> int
Hash function over inner class elements.
val equal_enclosing_method_value : enclosing_method_value -> enclosing_method_value -> bool
Equality over enclosing method values.
val compare_enclosing_method_value : enclosing_method_value -> enclosing_method_value -> int
Comparison over enclosing method values.
val hash_enclosing_method_value : enclosing_method_value -> int
Hash function over enclosing method values.
val equal_local_variable_table_element : local_variable_table_element ->
local_variable_table_element -> bool
Equality over local variable table elements.
val compare_local_variable_table_element : local_variable_table_element ->
local_variable_table_element -> int
Comparison over local variable table elements.
val hash_local_variable_table_element : local_variable_table_element -> int
Hash function over local variable table elements.
val equal_local_variable_type_table_element : local_variable_type_table_element ->
local_variable_type_table_element -> bool
Equality over local variable type table elements.
val compare_local_variable_type_table_element : local_variable_type_table_element ->
local_variable_type_table_element -> int
Comparison over local variable type table elements.
val hash_local_variable_type_table_element : local_variable_type_table_element -> int
Hash function over local variable type table elements.
val equal : t -> t -> bool
Equality over attributes.
val compare : t -> t -> int
Comparison over attributes.
val hash : t -> int
Hash function over attributes.
type for_field = [ `ConstantValue of constant_value
| `Deprecated
| `RuntimeInvisibleAnnotations of Annotation.t list
| `RuntimeInvisibleTypeAnnotations of Annotation.extended list
| `RuntimeVisibleAnnotations of Annotation.t list
| `RuntimeVisibleTypeAnnotations of Annotation.extended list
| `Signature of [ `Field of Signature.field_type_signature ]
| `Synthetic
| `Unknown of Utils.UTF8.t * string ]
Possible attributes for a field.
type for_method = [ `AnnotationDefault of Annotation.element_value
| `Code of code_value
| `Deprecated
| `Exceptions of Name.for_class list
| `RuntimeInvisibleAnnotations of Annotation.t list
| `RuntimeInvisibleParameterAnnotations of Annotation.t list list
| `RuntimeInvisibleTypeAnnotations of Annotation.extended list
| `RuntimeVisibleAnnotations of Annotation.t list
| `RuntimeVisibleParameterAnnotations of Annotation.t list list
| `RuntimeVisibleTypeAnnotations of Annotation.extended list
| `Signature of [ `Method of Signature.method_signature ]
| `Synthetic
| `Unknown of Utils.UTF8.t * string ]
Possible attributes for a method.
type for_class = [ `BootstrapMethods of Bootstrap.method_specifier list
| `Deprecated
| `EnclosingMethod of enclosing_method_value
| `InnerClasses of inner_class_element list
| `Module of Utils.UTF8.t * Utils.UTF8.t
| `RuntimeInvisibleAnnotations of Annotation.t list
| `RuntimeInvisibleTypeAnnotations of Annotation.extended list
| `RuntimeVisibleAnnotations of Annotation.t list
| `RuntimeVisibleTypeAnnotations of Annotation.extended list
| `Signature of [ `Class of Signature.class_signature ]
| `SourceDebugExtension of Utils.UTF8.t
| `SourceFile of Utils.UTF8.t
| `Synthetic
| `Unknown of Utils.UTF8.t * string ]
Possible attributes for a class.
type for_package = [ `Module of Utils.UTF8.t * Utils.UTF8.t
| `RuntimeInvisibleAnnotations of Annotation.t list
| `RuntimeVisibleAnnotations of Annotation.t list
| `SourceFile of Utils.UTF8.t
| `Unknown of Utils.UTF8.t * string ]
Possible attributes for a package.
type for_module = [ `Module of Utils.UTF8.t * Utils.UTF8.t
| `ModulePermits of (Utils.UTF8.t * Utils.UTF8.t) list
| `ModuleProvides of (Utils.UTF8.t * Utils.UTF8.t) list
| `ModuleRequires of
(Utils.UTF8.t * Utils.UTF8.t * dependency_kind) list
| `RuntimeInvisibleAnnotations of Annotation.t list
| `RuntimeVisibleAnnotations of Annotation.t list
| `SourceFile of Utils.UTF8.t
| `Unknown of Utils.UTF8.t * string ]
Possible attributes for a module.
type enclosing_element = 
| Class (*Kind of classes.*)
| Method (*Kind of methods.*)
| Field (*Kind of fields.*)
| Package (*Kind of package.*)
| Module (*Kind of module.*)
Kinds of elements.

Conversion functions

val string_of_verification_type_info : verification_type_info -> string
Converts the passed verification type information into a string.
val verification_type_info_of_parameter_descriptor : Descriptor.for_parameter -> verification_type_info
Converts the passed descriptor into a verification type information.
val check_code_attributes : t list -> code_attribute list
Checks that the passed list is a valid one for a code attribute. The list is returned if it is valid, raising Exception otherwise.
val check_field_attributes : t list -> for_field list
Checks that the passed list is a valid one for a field. The list is returned if it is valid, raising Exception otherwise.
val check_method_attributes : t list -> for_method list
Checks that the passed list is a valid one for a method. The list is returned if it is valid, raising Exception otherwise.
val check_class_attributes : t list -> for_class list
Checks that the passed list is a valid one for a class. The list is returned if it is valid, raising Exception otherwise.
val check_package_attributes : t list -> for_package list
Checks that the passed list is a valid one for a package. The list is returned if it is valid, raising Exception otherwise.
val check_module_attributes : t list -> for_module list
Checks that the passed list is a valid one for a module. The list is returned if it is valid, raising Exception otherwise.
val decode : enclosing_element ->
Bootstrap.methods -> ConstantPool.t -> info -> t
Converts from a low-level into a high-level form according to passed pool, and method bootstrap information. Raises Exception if an error occurs during conversion.
val encode : Bootstrap.methods -> ConstantPool.extendable -> t -> info
Converts from a high-level into a low-level form, using passed pool. Raises Exception if an error occurs during conversion.
val compare_according_to_significance : t -> t -> int
Comparison over attributes, to be used for user-intended output.
val version_bounds : t -> Version.bounds
Returns the version bounds for the passed attribute.

Common extractors

val extract_code : t list -> code_value
Returns the contents of the Code attribute from the passed list. Raises Not_found if no such attribute exists.
val extract_exceptions : t list -> Name.for_class list
Returns the contents of the Exceptions attribute from the passed list. Raises Not_found if no such attribute exists.
val extract_class_signature : for_class list -> Signature.class_signature
Returns the contents of the Signature attribute from the passed list. Raises Not_found if no such attribute exists.
val extract_bootstrap_info : t list -> Bootstrap.method_specifier list
Returns the contents of the BootstrapMethods attribute from the passed list. Raises Not_found if no such attribute exists.
val extract_field_signature : for_field list -> Signature.field_type_signature
Returns the contents of the Signature attribute from the passed list. Raises Not_found if no such attribute exists.
val extract_method_signature : for_method list -> Signature.method_signature
Returns the contents of the Signature attribute from the passed list. Raises Not_found if no such attribute exists.
val extract_annotations : t list -> Annotation.t list
Returns the list of annotations from the passed list. Returns the empty list if no such annotation exists.