Skip to content

Commit 491d76b

Browse files
alleystoughtonstrub
authored andcommitted
Fixing issues with the pretty printing of operators relating to parsing
(in the case of qualified unary operators) and unnecessary qualification (both when given no arguments and when given arguments). close #854
1 parent ab8469c commit 491d76b

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

src/ecPrinting.ml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ let pp_string fmt x =
487487
let pp_path fmt p =
488488
Format.fprintf fmt "%s" (P.tostring p)
489489

490-
let pp_xpath fmt (xp: P.xpath) =
490+
let pp_xpath fmt (xp: P.xpath) =
491491
Format.fprintf fmt "%s" (P.x_tostring xp)
492492

493493
(* -------------------------------------------------------------------- *)
@@ -776,6 +776,10 @@ let priority_of_unop =
776776
| _ ->
777777
None
778778

779+
(* -------------------------------------------------------------------- *)
780+
let is_unop name =
781+
(priority_of_unop name) <> None
782+
779783
(* -------------------------------------------------------------------- *)
780784
let is_binop name =
781785
(priority_of_binop name) <> None
@@ -903,7 +907,7 @@ let pp_opname (fmt : Format.formatter) ((nm, op) : symbol list * symbol) =
903907
if op.[0] = '*' || op.[String.length op - 1] = '*'
904908
then Format.sprintf "( %s )" op
905909
else Format.sprintf "(%s)" op
906-
end else if is_pstop op then
910+
end else if is_pstop op || (is_unop op && nm <> []) then
907911
Format.sprintf "(%s)" op
908912
else op
909913

@@ -1085,10 +1089,11 @@ let pp_opapp
10851089
((pred : [`Expr | `Form]),
10861090
(op : EcPath.path),
10871091
(tvi : EcTypes.ty list),
1088-
(es : 'a list))
1092+
(es : 'a list),
1093+
(tyopt : ty option))
10891094
=
10901095
let (nm, opname) =
1091-
PPEnv.op_symb ppe op (Some (pred, tvi, (List.map t_ty es, None))) in
1096+
PPEnv.op_symb ppe op (Some (pred, tvi, (List.map t_ty es, tyopt))) in
10921097

10931098
let pp_tuple_sub ppe prec fmt e =
10941099
match is_tuple e with
@@ -1842,7 +1847,8 @@ and pp_form_core_r
18421847
(fmt : Format.formatter)
18431848
(f : form)
18441849
=
1845-
let pp_opapp ppe (outer : opprec * iassoc) (fmt : Format.formatter) (op, tys, es) =
1850+
let pp_opapp ppe (outer : opprec * iassoc) (fmt : Format.formatter)
1851+
(op, tys, es, tyopt) =
18461852
let rec dt_sub f =
18471853
match destr_app f with
18481854
| ({ f_node = Fop (p, tvi) }, args) -> Some (p, tvi, args)
@@ -1872,7 +1878,7 @@ and pp_form_core_r
18721878
in
18731879
pp_opapp ppe f_ty
18741880
(dt_sub, pp_form_r, is_trm, is_tuple, is_proj)
1875-
lower_left outer fmt (`Form, op, tys, es)
1881+
lower_left outer fmt (`Form, op, tys, es, tyopt)
18761882
in
18771883

18781884
match f.f_node with
@@ -1935,18 +1941,18 @@ and pp_form_core_r
19351941
pp_let ~fv:f2.f_fv ppe pp_form_r outer fmt (lp, f1, f2)
19361942

19371943
| Fop (op, tvi) ->
1938-
pp_opapp ppe outer fmt (op, tvi, [])
1944+
pp_opapp ppe outer fmt (op, tvi, [], Some f.f_ty)
19391945

19401946
| Fapp ({f_node = Fop (op, _)},
19411947
[{f_node = Fapp ({f_node = Fop (op', tys)}, [f1; f2])}])
19421948
when EcPath.p_equal op EcCoreLib.CI_Bool.p_not
19431949
&& EcPath.p_equal op' EcCoreLib.CI_Bool.p_eq
19441950
->
19451951
let negop = EcPath.pqoname (EcPath.prefix op') "<>" in
1946-
pp_opapp ppe outer fmt (negop, tys, [f1; f2])
1952+
pp_opapp ppe outer fmt (negop, tys, [f1; f2], Some f.f_ty)
19471953

19481954
| Fapp ({f_node = Fop (p, tys)}, args) ->
1949-
pp_opapp ppe outer fmt (p, tys, args)
1955+
pp_opapp ppe outer fmt (p, tys, args, Some f.f_ty)
19501956

19511957
| Fapp (e, args) ->
19521958
pp_app ppe ~pp_first:pp_form_r ~pp_sub:pp_form_r outer fmt (e, args)
@@ -2859,9 +2865,9 @@ let pp_i_blk (_ppe : PPEnv.t) fmt _ =
28592865
let pp_i_abstract (_ppe : PPEnv.t) fmt id =
28602866
Format.fprintf fmt "%s" (EcIdent.name id)
28612867

2862-
let pp_abs_uses (ppe : PPEnv.t) fmt (aus: abs_uses) =
2863-
let pp_pv_ty ppe fmt (pv, ty) =
2864-
Format.fprintf fmt "(%a : %a)" (pp_pv ppe) pv (pp_type ppe) ty
2868+
let pp_abs_uses (ppe : PPEnv.t) fmt (aus: abs_uses) =
2869+
let pp_pv_ty ppe fmt (pv, ty) =
2870+
Format.fprintf fmt "(%a : %a)" (pp_pv ppe) pv (pp_type ppe) ty
28652871
in
28662872
let on_empty fmt () = Format.fprintf fmt "None" in
28672873
Format.fprintf fmt "{ calls: %a, reads: %a, writes: %a }"
@@ -3313,7 +3319,7 @@ module PPGoal = struct
33133319
(None, fun fmt -> pp_form ppe fmt f)
33143320

33153321
| EcBaseLogic.LD_abs_st aus ->
3316-
(None, fun fmt -> Format.fprintf fmt "statement %a"
3322+
(None, fun fmt -> Format.fprintf fmt "statement %a"
33173323
(pp_abs_uses ppe) aus)
33183324

33193325
in (ppe, (id, pdk))

0 commit comments

Comments
 (0)