Commit 0db1c7f8 authored by Mário Pereira's avatar Mário Pereira

Extraction: removed useless None when applying function with optional arguments.

Example taken from the VOCaL project:
  let make (dummy [@ocaml:optional]: option 'a) (n: int63) (x: 'a) : t 'a
    ...

  let init (dummy [@ocaml:named]: 'a) (n: int63) (f: int63 -> 'a) : t 'a
  = let a = make None n dummy in
    ...

Now the resulting OCaml code is as follows:
  let init ~dummy:(dummy: 'a) (n: int) (f: (int) -> 'a) : 'a t =
    let a = make  n dummy in
    ...
parent ae6fb7ac
......@@ -303,13 +303,15 @@ module Print = struct
let rec print_apply_args info fmt = function
| expr :: exprl, pv :: pvl ->
if is_optional ~labels:(pv_name pv).id_label then
fprintf fmt "?%s:%a" (pv_name pv).id_string
(print_expr ~paren:true info) expr
begin match expr.e_node with
| Eapp (rs, _)
when query_syntax info.info_syn rs.rs_name = Some "None" -> ()
| _ -> fprintf fmt "?%s:%a" (pv_name pv).id_string
(print_expr ~paren:true info) expr end
else if is_named ~labels:(pv_name pv).id_label then
fprintf fmt "~%s:%a" (pv_name pv).id_string
(print_expr ~paren:true info) expr
else
fprintf fmt "%a" (print_expr ~paren:true info) expr;
else fprintf fmt "%a" (print_expr ~paren:true info) expr;
if exprl <> [] then fprintf fmt "@ ";
print_apply_args info fmt (exprl, pvl)
| [], _ -> ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment