Skip to content
Snippets Groups Projects
Commit 9372a84f authored by nilfit's avatar nilfit
Browse files

fix printing of enum expressions

parent 81de7472
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,8 @@ module Rust = struct
| Eassign of pvsymbol * rsymbol * pvsymbol
| Etup of expr list
| Eenum of rsymbol * expr list
(* TODO change the rsymbol for Estruct to just an ident so the printer
* doesn't have to do anything smart *)
| Estruct of rsymbol * rsymbol list * expr list (* Rs { r1: e1, r2: e2 } *)
| Eblock of expr list
| Ecall of rsymbol * expr list
......@@ -281,6 +283,7 @@ module MLToRust = struct
else e in
let el = List.mapi (maybe_box rs) el in
Rust.Eenum (rs, el)
(* FIXME seems to use the name of the type instead of the variant *)
| rsl ->
let maybe_box (rs: rsymbol) (e: Rust.expr) =
if Sid.contains boxes.box_fields rs.rs_name then box_expr e
......@@ -720,13 +723,12 @@ module Print = struct
(print_list comma (print_ty info)) argl
(print_ty info) res
(* TODO why not use rs.rs_name? *)
(* find ident of a struct by its rsymbol *)
let struct_id rs =
(* find ident of a struct type by its rsymbol *)
let rs_type_ident rs =
(match rs.rs_cty.cty_result.ity_node with
| Ity.Ityreg reg -> reg.reg_its.its_ts.ts_name
| Ity.Ityapp (its, _, _) -> its.its_ts.ts_name
| Ity.Ityvar _ -> raise (TODO "struct_id: var"))
| Ity.Ityvar _ -> raise (TODO "rs_type_ident: var"))
let rec print_pat info fmt pat =
match pat with
......@@ -735,7 +737,7 @@ module Print = struct
fprintf fmt "%s%a" (if mut then "mut " else "") (print_lident info) id
(* TODO ref are still not mut *)
| Pde_str (rs, rsl, pl) ->
fprintf fmt "@[<hov 2>%a { %a }@]" (print_uident info) (struct_id rs)
fprintf fmt "@[<hov 2>%a { %a }@]" (print_uident info) (rs_type_ident rs)
(print_list2 comma colon (print_rs info) (print_pat info))
(rsl, pl)
| Pde_enum (ls, []) -> fprintf fmt "%a" (print_uident info) ls.ls_name
......@@ -772,12 +774,12 @@ module Print = struct
fprintf fmt "%a.%a = %a" (print_lident info) (pv_name rho)
(print_lident info) rs.rs_name (print_lident info) (pv_name pv)
| Etup el -> fprintf fmt "(%a)" (print_list comma (print_expr info)) el
| Eenum (rs, []) -> print_uident info fmt (struct_id rs)
| Eenum (rs, []) -> print_uident info fmt rs.rs_name
| Eenum (rs, el) ->
fprintf fmt "%a (%a)" (print_uident info) (struct_id rs)
fprintf fmt "%a (%a)" (print_uident info) rs.rs_name
(print_list comma (print_expr info)) el
| Estruct (rs, fl, el) ->
fprintf fmt "@[<hov 2>%a { %a }@]" (print_uident info) (struct_id rs)
fprintf fmt "@[<hov 2>%a { %a }@]" (print_uident info) (rs_type_ident rs)
(print_list2 comma colon (print_rs info) (print_expr info)) (fl, el)
| Eblock el ->
fprintf fmt "@[<hov 2>{@\n%a@]@\n}" (print_list semi (print_expr info)) el
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment