From 52092b1480f10f9ea2c72fe3b4d847088851c893 Mon Sep 17 00:00:00 2001 From: Arnaud DABY-SEESARAM Date: Tue, 20 Dec 2022 15:24:55 +0100 Subject: [PATCH] [cprint] code reduction --- src/cprint.ml | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/cprint.ml b/src/cprint.ml index 3df57af..fb56053 100644 --- a/src/cprint.ml +++ b/src/cprint.ml @@ -241,30 +241,23 @@ let cp_main_fn fmt (prog, sts) = cp_array vl in let rec cp_inputs fmt (f, l) = - match f, l with - | _, [] -> () - | true, h :: t -> - Format.fprintf fmt ", %s%a" - (Utils.name_of_var h) - cp_inputs (true, t) - | false, h :: t -> - Format.fprintf fmt "%s%a" + match l with + | [] -> () + | h :: t -> + (if f + then Format.fprintf fmt ", %s%a" + else Format.fprintf fmt "%s%a") (Utils.name_of_var h) cp_inputs (true, t) in let cp_scanf fmt vl = let rec cp_scanf_str fmt (b, vl) = - match b, vl with - | _, [] -> () - | true, h :: t -> - Format.fprintf fmt " %s%a" - (match h with - | IVar _ -> "%d" - | BVar _ -> "%c" - | RVar _ -> "%lf") - cp_scanf_str (true, t) - | false, h :: t -> - Format.fprintf fmt "%s%a" + match vl with + | [] -> () + | h :: t -> + (if b + then Format.fprintf fmt " %s%a" + else Format.fprintf fmt "%s%a") (match h with | IVar _ -> "%d" | BVar _ -> "%c" @@ -286,17 +279,12 @@ let cp_main_fn fmt (prog, sts) = in let cp_printf fmt vl = let rec cp_printf_str fmt (b, vl) = - match b, vl with - | _, [] -> () - | true, h :: t -> - Format.fprintf fmt " %s%a" - (match h with - | IVar _ -> "%d" - | BVar _ -> "%c" - | RVar _ -> "%f") - cp_printf_str (true, t) - | false, h :: t -> - Format.fprintf fmt "%s%a" + match vl with + | [] -> () + | h :: t -> + (if b + then Format.fprintf fmt " %s%a" + else Format.fprintf fmt "%s%a") (match h with | IVar _ -> "%d" | BVar _ -> "%c"