@@ -20,11 +20,20 @@ let string_of_cst = function
20
20
| Pconst_string (s , _ , _ ) -> Some s
21
21
| _ -> None
22
22
23
+ let int_of_cst = function
24
+ | Pconst_integer (i , None) -> Some (int_of_string i)
25
+ | _ -> None
26
+
23
27
let string_of_payload = function
24
28
| PStr [{pstr_desc= Pstr_eval ({pexp_desc= Pexp_constant c},_)}] ->
25
29
string_of_cst c
26
30
| _ -> None
27
31
32
+ let int_of_payload = function
33
+ | PStr [{pstr_desc= Pstr_eval ({pexp_desc= Pexp_constant c},_)}] ->
34
+ int_of_cst c
35
+ | _ -> None
36
+
28
37
let string_of_opt_payload p =
29
38
match string_of_payload p with
30
39
| Some s -> s
@@ -285,3 +294,73 @@ let has_unboxed attr =
285
294
286
295
let has_boxed attr =
287
296
List. exists (check [" ocaml.boxed" ; " boxed" ]) attr
297
+
298
+ let parse_empty_payload attr =
299
+ match attr.attr_payload with
300
+ | PStr [] -> Some ()
301
+ | _ ->
302
+ warn_payload attr.attr_loc attr.attr_name.txt
303
+ " No attribute payload was expected" ;
304
+ None
305
+
306
+ let parse_int_payload attr =
307
+ match int_of_payload attr.attr_payload with
308
+ | Some i -> Some i
309
+ | None ->
310
+ warn_payload attr.attr_loc attr.attr_name.txt
311
+ " A constant payload of type int was expected" ;
312
+ None
313
+
314
+ let clflags_attribute_without_payload attr ~name clflags_ref =
315
+ if String. equal attr.attr_name.txt name
316
+ || String. equal attr.attr_name.txt (" ocaml." ^ name)
317
+ then begin
318
+ match parse_empty_payload attr with
319
+ | Some () -> clflags_ref := true
320
+ | None -> ()
321
+ end
322
+
323
+ let clflags_attribute_with_int_payload attr ~name clflags_ref =
324
+ if String. equal attr.attr_name.txt name
325
+ || String. equal attr.attr_name.txt (" ocaml." ^ name)
326
+ then begin
327
+ match parse_int_payload attr with
328
+ | Some i -> clflags_ref := i
329
+ | None -> ()
330
+ end
331
+
332
+ let nolabels_attribute attr =
333
+ clflags_attribute_without_payload attr
334
+ ~name: " nolabels" Clflags. classic
335
+
336
+ let inline_attribute attr =
337
+ if String. equal attr.attr_name.txt " inline"
338
+ || String. equal attr.attr_name.txt " ocaml.inline"
339
+ then begin
340
+ let err_msg =
341
+ " Either specify an integer, or the form accepted by '-inline' in quotes"
342
+ in
343
+ match string_of_payload attr.attr_payload with
344
+ | Some s ->
345
+ Clflags.Float_arg_helper. parse s err_msg Clflags. inline_threshold
346
+ | None ->
347
+ match int_of_payload attr.attr_payload with
348
+ | Some i ->
349
+ let s = string_of_int i in
350
+ Clflags.Float_arg_helper. parse s err_msg Clflags. inline_threshold
351
+ | None -> warn_payload attr.attr_loc attr.attr_name.txt err_msg
352
+ end
353
+
354
+ let afl_inst_ratio_attribute attr =
355
+ clflags_attribute_with_int_payload attr
356
+ ~name: " afl_inst_ratio" Clflags. afl_inst_ratio
357
+
358
+ let parse_standard_interface_attributes attr =
359
+ warning_attribute attr;
360
+ nolabels_attribute attr
361
+
362
+ let parse_standard_implementation_attributes attr =
363
+ warning_attribute attr;
364
+ nolabels_attribute attr;
365
+ inline_attribute attr;
366
+ afl_inst_ratio_attribute attr
0 commit comments