[cprint] code reduction

This commit is contained in:
Arnaud DABY-SEESARAM 2022-12-20 15:24:55 +01:00
parent f121f55432
commit 52092b1480

View File

@ -241,30 +241,23 @@ let cp_main_fn fmt (prog, sts) =
cp_array vl cp_array vl
in in
let rec cp_inputs fmt (f, l) = let rec cp_inputs fmt (f, l) =
match f, l with match l with
| _, [] -> () | [] -> ()
| true, h :: t -> | h :: t ->
Format.fprintf fmt ", %s%a" (if f
(Utils.name_of_var h) then Format.fprintf fmt ", %s%a"
cp_inputs (true, t) else Format.fprintf fmt "%s%a")
| false, h :: t ->
Format.fprintf fmt "%s%a"
(Utils.name_of_var h) (Utils.name_of_var h)
cp_inputs (true, t) cp_inputs (true, t)
in in
let cp_scanf fmt vl = let cp_scanf fmt vl =
let rec cp_scanf_str fmt (b, vl) = let rec cp_scanf_str fmt (b, vl) =
match b, vl with match vl with
| _, [] -> () | [] -> ()
| true, h :: t -> | h :: t ->
Format.fprintf fmt " %s%a" (if b
(match h with then Format.fprintf fmt " %s%a"
| IVar _ -> "%d" else Format.fprintf fmt "%s%a")
| BVar _ -> "%c"
| RVar _ -> "%lf")
cp_scanf_str (true, t)
| false, h :: t ->
Format.fprintf fmt "%s%a"
(match h with (match h with
| IVar _ -> "%d" | IVar _ -> "%d"
| BVar _ -> "%c" | BVar _ -> "%c"
@ -286,17 +279,12 @@ let cp_main_fn fmt (prog, sts) =
in in
let cp_printf fmt vl = let cp_printf fmt vl =
let rec cp_printf_str fmt (b, vl) = let rec cp_printf_str fmt (b, vl) =
match b, vl with match vl with
| _, [] -> () | [] -> ()
| true, h :: t -> | h :: t ->
Format.fprintf fmt " %s%a" (if b
(match h with then Format.fprintf fmt " %s%a"
| IVar _ -> "%d" else Format.fprintf fmt "%s%a")
| BVar _ -> "%c"
| RVar _ -> "%f")
cp_printf_str (true, t)
| false, h :: t ->
Format.fprintf fmt "%s%a"
(match h with (match h with
| IVar _ -> "%d" | IVar _ -> "%d"
| BVar _ -> "%c" | BVar _ -> "%c"