Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CN] Add parsing of a->b expressions in CN assertions #396

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions backend/cn/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ let rec free_in_expr (CNExpr (_loc, expr_)) =
free_in_exprs es
| CNExpr_memberof (e, _id) ->
free_in_expr e
| CNExpr_arrow (e, _id) ->
free_in_expr e
| CNExpr_record members ->
free_in_exprs (List.map snd members)
| CNExpr_struct (_tag, members) ->
Expand Down Expand Up @@ -625,10 +627,6 @@ module EffectfulTranslation = struct







let rec translate_cn_pat env locally_bound (CNPat (loc, pat_), bt) =
match pat_ with
| CNPat_wild ->
Expand Down Expand Up @@ -710,6 +708,9 @@ module EffectfulTranslation = struct
| CNExpr_memberof (e, xs) ->
let@ e = self e in
translate_member_access loc env e xs
| CNExpr_arrow (e, xs) -> (* Desugar a->b as ( *a).b *)
let@ e = self (CNExpr (loc, CNExpr_deref e)) in
translate_member_access loc env e xs
| CNExpr_record members ->
let@ members = ListM.mapsndM self members in
let bts = List.map_snd IT.bt members in
Expand Down
3 changes: 3 additions & 0 deletions frontend/model/cabs_to_ail.lem
Original file line number Diff line number Diff line change
Expand Up @@ -4189,6 +4189,9 @@ let rec desugar_cn_expr (CNExpr loc expr_) =
| CNExpr_memberof e ident_membr ->
CNExpr_memberof <$> desugar_cn_expr e
<*> (E.return ident_membr)
| CNExpr_arrow e ident_membr ->
CNExpr_arrow <$> desugar_cn_expr e
<*> (E.return ident_membr)
| CNExpr_record members ->
CNExpr_record <$> sort_record_members desugar_cn_expr members
| CNExpr_struct tag members ->
Expand Down
1 change: 1 addition & 0 deletions frontend/model/cn.lem
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type cn_expr_ 'a 'ty =
| CNExpr_var of 'a
| CNExpr_list of list (cn_expr 'a 'ty)
| CNExpr_memberof of cn_expr 'a 'ty * Symbol.identifier
| CNExpr_arrow of cn_expr 'a 'ty * Symbol.identifier
| CNExpr_record of list (Symbol.identifier * cn_expr 'a 'ty)
| CNExpr_struct of 'a * list (Symbol.identifier * cn_expr 'a 'ty)
| CNExpr_memberupdates of cn_expr 'a 'ty * list (Symbol.identifier * cn_expr 'a 'ty)
Expand Down
6 changes: 5 additions & 1 deletion ocaml_frontend/cn_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ module MakePp (Conf: PP_CN) = struct
| CNExpr_list es ->
Dnode (pp_ctor "CNExpr_list", List.map dtree_of_cn_expr es)
| CNExpr_memberof (e, z) ->
Dnode (pp_ctor "CNExpr_member",
Dnode (pp_ctor "CNExpr_memberof",
[dtree_of_cn_expr e;
Dleaf (pp_identifier z)])
| CNExpr_arrow (e, z) ->
Dnode (pp_ctor "CNExpr_arrow",
[dtree_of_cn_expr e;
Dleaf (pp_identifier z)])
| CNExpr_record members ->
Expand Down
3 changes: 3 additions & 0 deletions parsers/c/c_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,9 @@ prim_expr:
| e= prim_expr DOT member=cn_variable
{ Cerb_frontend.Cn.(CNExpr ( Cerb_location.(region ($startpos, $endpos) (PointCursor $startpos($2)))
, CNExpr_memberof (e, member))) }
| e= prim_expr MINUS_GT member=cn_variable
{ Cerb_frontend.Cn.(CNExpr ( Cerb_location.(region ($startpos, $endpos) (PointCursor $startpos($2)))
, CNExpr_arrow (e, member))) }
| e= delimited(LPAREN, expr, RPAREN)
{ e }
| CN_ARRAY_SHIFT LT ty=ctype GT LPAREN base=expr COMMA index=expr RPAREN
Expand Down
Loading
Loading