From 32ee9414b9766e3efb4c2a9a57455191b73c880e Mon Sep 17 00:00:00 2001 From: Iavor Diatchki Date: Wed, 7 Aug 2024 08:36:07 -0700 Subject: [PATCH] Update pretty printing of structs to match input notation: To set field `x` of struct/record `s` to `v` we write: `{x: v, ..s}` --- backend/cn/lib/terms.ml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/backend/cn/lib/terms.ml b/backend/cn/lib/terms.ml index 93aa2f22d..a9440b3f4 100644 --- a/backend/cn/lib/terms.ml +++ b/backend/cn/lib/terms.ml @@ -150,7 +150,7 @@ let rec pp_pattern (Pat (pat_, _bt, _)) = (* Precedences: Reference: https://en.cppreference.com/w/c/language/operator_precedence - The number we use are `16 - p` where `p` is the reference in the table. + The number we use are `16 - p` where `p` is the precedence in the table. We do this so bigger numbers are higher precedence. Highest @@ -296,12 +296,7 @@ let pp ^^^ rbrace | StructMember (t, member) -> wrap_after 15 (aux 15 t ^^ dot ^^ Id.pp member) | StructUpdate ((t, member), v) -> - braces - (!^"..." - ^^ aux 0 t - ^^ comma - ^^^ (Pp.group @@ dot ^^ Id.pp member ^^^ equals) - ^^^ align (aux 0 v)) + braces (dot ^^ Id.pp member ^^ colon ^^^ aux 0 v ^^ comma ^^^ !^".." ^^ aux 0 t) | Record members -> align @@ lbrace @@ -315,12 +310,7 @@ let pp ^^^ rbrace | RecordMember (t, member) -> wrap_after 15 (aux 15 t ^^ dot ^^ Id.pp member) | RecordUpdate ((t, member), v) -> - braces - (!^"..." - ^^ aux 0 t - ^^ comma - ^^^ (Pp.group @@ dot ^^ Id.pp member ^^^ equals) - ^^^ align (aux 0 v)) + braces (dot ^^ Id.pp member ^^ colon ^^^ aux 0 v ^^ comma ^^^ !^".." ^^ aux 0 t) | Cast (cbt, t) -> wrap_after 14 (align @@ parens (BaseTypes.pp cbt) ^^ aux 14 t) | MemberShift (t, _tag, member) -> wrap_after 14 (ampersand ^^ aux 15 t ^^ (!^"-" ^^ rangle ()) ^^ Id.pp member)