23
23
24
24
(* * Basic elements of class files. *)
25
25
26
- (* * {2 Definition of basic types and descriptors.} *)
26
+ (* * {1 Definition of basic types and descriptors.} *)
27
27
28
28
(* * Type representing a class name. e.g. [java.lang.Object] *)
29
29
type class_name
@@ -34,6 +34,11 @@ type class_name
34
34
have the same [method_signature]. *)
35
35
type method_signature
36
36
37
+ (* * Type representing a method descriptor.
38
+ A method descriptor contains the types of parameters and the method
39
+ return type. *)
40
+ type method_descriptor
41
+
37
42
(* * Type representing a field signature.
38
43
A field signature contains the field name and the field type. *)
39
44
type field_signature
@@ -92,19 +97,6 @@ type java_basic_type = [
92
97
| other_num
93
98
]
94
99
95
- (* * Method handle type. *)
96
- type method_handle_kind = [
97
- | `GetField
98
- | `GetStatic
99
- | `PutField
100
- | `PutStatic
101
- | `InvokeVirtual
102
- | `InvokeStatic
103
- | `InvokeSpecial
104
- | `NewInvokeSpecial
105
- | `InvokeInterface
106
- ]
107
-
108
100
(* * Java object type *)
109
101
type object_type =
110
102
| TClass of class_name
@@ -114,15 +106,18 @@ type object_type =
114
106
and value_type =
115
107
| TBasic of java_basic_type
116
108
| TObject of object_type
117
-
109
+
110
+ (* * Abstract datatype for Java strings *)
111
+ type jstr
112
+
118
113
(* * Version number of the class file. Extract of the specification: An
119
114
implementation of Java 1.k sould support class file formats of
120
115
versions in the range of 45.0 through 44+k.0 inclusive. E.g. Java
121
116
1.6 implementations support class file formats of versions up to
122
117
50.0. *)
123
118
type version = {major :int ; minor :int ; }
124
119
125
- (* * {2 Basic types manipulation.} *)
120
+ (* * {1 Basic types manipulation.} *)
126
121
127
122
(* * Creating and manipulating {!class_name} values. *)
128
123
@@ -185,6 +180,20 @@ val ms_compare : method_signature -> method_signature -> int
185
180
(* * Returns [true] if two method signatures are equal, [false] otherwise. *)
186
181
val ms_equal : method_signature -> method_signature -> bool
187
182
183
+ (* * Creating and manipulating {!method_descriptor} values. *)
184
+
185
+ (* * Builds a [method_descriptor]. *)
186
+ val make_md : value_type list * value_type option -> method_descriptor
187
+
188
+ (* * Splits a [method_descriptor] into arguments list and return type. *)
189
+ val md_split : method_descriptor -> value_type list * value_type option
190
+
191
+ (* * Returns the [method_descriptor] arguments list. *)
192
+ val md_args : method_descriptor -> value_type list
193
+
194
+ (* * Returns the [method_descriptor] return type. *)
195
+ val md_rtype : method_descriptor -> value_type option
196
+
188
197
(* * Creating and manipulating {!field_signature} values. *)
189
198
190
199
(* * Builds a [field_signature]. *)
@@ -236,7 +245,57 @@ val cms_compare : class_method_signature -> class_method_signature -> int
236
245
(* * Returns [true] if two [class_method_signature] are equal, [false] otherwise. *)
237
246
val cms_equal : class_method_signature -> class_method_signature -> bool
238
247
239
- (* * {2 Constant pool.} *)
248
+ (* * Builds a [jstr]. *)
249
+ val make_jstr : string -> jstr
250
+
251
+ (* * Returns a [string] where all characters outside the ASCII printable range (32..126) are escaped. *)
252
+ val jstr_pp : jstr -> string
253
+
254
+ (* * Returns the original [string]. *)
255
+ val jstr_raw : jstr -> string
256
+
257
+ (* * {1 Bootstrap method and method handle types.} *)
258
+
259
+ (* * Features introduced in Java 8 to implement lambdas. *)
260
+
261
+ type jmethod_or_interface = [
262
+ | `Method of class_name * method_signature
263
+ | `InterfaceMethod of class_name * method_signature
264
+ ]
265
+
266
+ (* * Method handle. cf JVM Spec se8 §4.4.8. *)
267
+ type method_handle = [
268
+ | `GetField of class_name * field_signature
269
+ | `GetStatic of class_name * field_signature
270
+ | `PutField of class_name * field_signature
271
+ | `PutStatic of class_name * field_signature
272
+ | `InvokeVirtual of object_type * method_signature
273
+ | `NewInvokeSpecial of class_name * method_signature
274
+ | `InvokeStatic of jmethod_or_interface
275
+ | `InvokeSpecial of jmethod_or_interface
276
+ | `InvokeInterface of class_name * method_signature
277
+ ]
278
+
279
+ (* * Bootstrap argument. cf JVM Spec se8 §4.7.23. *)
280
+ type bootstrap_argument = [
281
+ | `String of jstr
282
+ | `Class of object_type
283
+ | `Int of int32
284
+ | `Long of int64
285
+ | `Float of float
286
+ | `Double of float
287
+ | `MethodHandle of method_handle
288
+ | `MethodType of method_descriptor
289
+ ]
290
+
291
+ (* * Bootstrap method called by the [invokedynamic] instruction.
292
+ cf JVM Spec se8 §4.7.23. *)
293
+ type bootstrap_method = {
294
+ bm_ref : method_handle ;
295
+ bm_args : bootstrap_argument list ;
296
+ }
297
+
298
+ (* * {1 Constant pool.} *)
240
299
241
300
(* * You should not need this for normal usage, as the
242
301
parsing/unparsing functions take care of the constant pool. This
@@ -245,44 +304,30 @@ val cms_equal : class_method_signature -> class_method_signature -> bool
245
304
246
305
type bootstrap_method_index = int
247
306
248
- (* * Method descriptor. *)
249
- type method_descriptor = value_type list * value_type option
250
-
251
307
(* * Signatures parsed from CONSTANT_NameAndType_info structures. *)
252
308
type descriptor =
253
309
| SValue of value_type
254
310
| SMethod of method_descriptor
255
311
256
- (* * Abstract datatype for Java strings *)
257
- type jstr
258
- val make_jstr : string -> jstr
259
- val jstr_pp : jstr -> string
260
- val jstr_raw : jstr -> string
261
-
262
- (* * Constant value. *)
263
- type constant_value =
312
+ (* * Constant pool values. *)
313
+ type constant =
264
314
| ConstString of jstr
265
315
| ConstInt of int32
266
316
| ConstFloat of float
267
317
| ConstLong of int64
268
318
| ConstDouble of float
269
319
| ConstClass of object_type
270
-
271
- (* * Constant. *)
272
- type constant =
273
- | ConstValue of constant_value
274
320
| ConstField of (class_name * field_signature )
275
321
| ConstMethod of (object_type * method_signature )
276
322
| ConstInterfaceMethod of (class_name * method_signature )
277
323
| ConstMethodType of method_descriptor
278
- | ConstMethodHandle of method_handle_kind * constant
324
+ | ConstMethodHandle of method_handle
279
325
| ConstInvokeDynamic of bootstrap_method_index * method_signature
280
326
| ConstNameAndType of string * descriptor
281
327
| ConstStringUTF8 of string
282
328
| ConstUnusable
283
329
284
-
285
- (* * {2 Stackmaps} *)
330
+ (* * {1 Stackmaps} *)
286
331
287
332
(* * Verification type. *)
288
333
type verification_type =
@@ -299,7 +344,7 @@ type verification_type =
299
344
(* * Stackmap type. *)
300
345
type stackmap = (int * verification_type list * verification_type list )
301
346
302
- (* * {2 Errors} *)
347
+ (* * {1 Errors} *)
303
348
304
349
(* * The library may throw the following exceptions, in addition to [Invalid_argument].
305
350
Any other exception (in particular, an [Assert_failure])
@@ -313,7 +358,7 @@ exception No_class_found of string
313
358
exception Class_structure_error of string
314
359
315
360
316
- (* * {2 Annotations} *)
361
+ (* * {1 Annotations} *)
317
362
318
363
(* * [element_value] represents a constant value, either a number, a string, a
319
364
class, an enum, an array of [element_value]s or another annotation. *)
@@ -344,7 +389,7 @@ and annotation = {
344
389
}
345
390
346
391
347
- (* * {2 Containers.} *)
392
+ (* * {1 Containers.} *)
348
393
349
394
(* * This module allows to build maps of elements indexed by [class_name] values. *)
350
395
module ClassMap : GenericMap .GenericMapSig with type key = class_name
382
427
end
383
428
384
429
385
- (* * {2 Tuning JavaLib.} *)
430
+ (* * {1 Tuning JavaLib.} *)
386
431
387
432
(* * [set_permissive true] disables some checking in JavaLib. It can
388
433
allow to parse some files that do not strictly comply with the
0 commit comments