@@ -158,7 +158,11 @@ let is_order_inc = function Ord_aux (Ord_inc, _) -> true | Ord_aux (Ord_dec, _)
158158
159159let is_order_dec o = not (is_order_inc o)
160160
161- let string_of_id = function Id_aux (Id v , _ ) -> v | Id_aux (Operator v , _ ) -> " (operator " ^ v ^ " )"
161+ let string_of_id = function
162+ | Id_aux (And_bool, _ ) -> " and_bool"
163+ | Id_aux (Or_bool, _ ) -> " or_bool"
164+ | Id_aux (Id v , _ ) -> v
165+ | Id_aux (Operator v , _ ) -> " (operator " ^ v ^ " )"
162166
163167let lvar_typ ?loc :(l = Parse_ast. Unknown ) = function
164168 | Local (_ , typ ) -> typ
@@ -197,6 +201,13 @@ let rec is_gen_loc = function
197201 | Parse_ast. Hint (_ , l1 , l2 ) -> is_gen_loc l1 || is_gen_loc l2
198202 | Parse_ast. Range _ -> false
199203
204+ let mk_and_bool ?loc :(l = Parse_ast. Unknown ) () = Id_aux (And_bool , l)
205+ let mk_or_bool ?loc :(l = Parse_ast. Unknown ) () = Id_aux (Or_bool , l)
206+
207+ let is_and_bool = function Id_aux (And_bool , _ ) -> true | _ -> false
208+
209+ let is_or_bool = function Id_aux (Or_bool , _ ) -> true | _ -> false
210+
200211let mk_id ?loc :(l = Parse_ast. Unknown ) str = Id_aux (Id str, l)
201212
202213let mk_nc ?loc :(l = Parse_ast. Unknown ) nc_aux = NC_aux (nc_aux, l)
@@ -306,10 +317,16 @@ module Id = struct
306317 type t = id
307318 let compare id1 id2 =
308319 match (id1, id2) with
320+ | Id_aux (And_bool, _ ), Id_aux (And_bool, _ ) -> 0
321+ | Id_aux (Or_bool, _ ), Id_aux (Or_bool, _ ) -> 0
309322 | Id_aux (Id x , _ ), Id_aux (Id y , _ ) -> String. compare x y
310323 | Id_aux (Operator x , _ ), Id_aux (Operator y , _ ) -> String. compare x y
311- | Id_aux (Id _ , _ ), Id_aux (Operator _ , _ ) -> - 1
312- | Id_aux (Operator _ , _ ), Id_aux (Id _ , _ ) -> 1
324+ | Id_aux (Id _ , _ ), _ -> - 1
325+ | _ , Id_aux (Id _ , _ ) -> 1
326+ | Id_aux (Operator _ , _ ), _ -> - 1
327+ | _ , Id_aux (Operator _ , _ ) -> 1
328+ | Id_aux (And_bool, _ ), _ -> - 1
329+ | _ , Id_aux (And_bool, _ ) -> 1
313330end
314331
315332let lex_ord f g x1 x2 y1 y2 = match f x1 x2 with 0 -> g y1 y2 | n -> n
@@ -1102,6 +1119,8 @@ type id_chunk = Id_chunk_int of int | Id_chunk_string of string
11021119let split_id =
11031120 let open Ast in
11041121 function
1122+ | Id_aux (And_bool, _ ) -> [Id_chunk_string " and_bool" ]
1123+ | Id_aux (Or_bool, _ ) -> [Id_chunk_string " or_bool" ]
11051124 | Id_aux (Id id , _ ) ->
11061125 let pos = ref 0 in
11071126 let is_number = ref false in
@@ -1156,25 +1175,35 @@ let natural_sort_ids ids =
11561175 let ids = List. stable_sort (fun (n1 , _ ) (n2 , _ ) -> split_id_compare n1 n2) ids in
11571176 List. map snd ids
11581177
1159- let deinfix = function Id_aux (Id v , l ) -> Id_aux (Operator v, l) | Id_aux (Operator v , l ) -> Id_aux ( Operator v, l)
1178+ let deinfix = function Id_aux (Id v , l ) -> Id_aux (Operator v, l) | id -> id
11601179
1161- let infix_swap = function Id_aux (Id v , l ) -> Id_aux (Operator v, l) | Id_aux (Operator v , l ) -> Id_aux ( Id v, l)
1180+ let infix_swap = function Id_aux (Operator v , l ) -> Id_aux (Id v, l) | id -> deinfix id
11621181
11631182let id_of_kid = function Kid_aux (Var v , l ) -> Id_aux (Id (String. sub v 1 (String. length v - 1 )), l)
11641183
1165- let kid_of_id = function Id_aux (Id v , l ) -> Kid_aux (Var (" '" ^ v), l) | Id_aux (Operator _ , _ ) -> assert false
1184+ let kid_of_id = function Id_aux (Id v , l ) -> Kid_aux (Var (" '" ^ v), l) | _ -> assert false
11661185
11671186let prepend_id str = function
11681187 | Id_aux (Id v , l ) -> Id_aux (Id (str ^ v), l)
11691188 | Id_aux (Operator v , l ) -> Id_aux (Operator (str ^ v), l)
1189+ | Id_aux ((And_bool | Or_bool ), l ) ->
1190+ Reporting. unreachable l __POS__
1191+ " Attempted to construct prepended identifier from short-circuiting boolean operator"
11701192
11711193let append_id id str =
1172- match id with Id_aux (Id v , l ) -> Id_aux (Id (v ^ str), l) | Id_aux (Operator v , l ) -> Id_aux (Operator (v ^ str), l)
1194+ match id with
1195+ | Id_aux (Id v , l ) -> Id_aux (Id (v ^ str), l)
1196+ | Id_aux (Operator v , l ) -> Id_aux (Operator (v ^ str), l)
1197+ | Id_aux ((And_bool | Or_bool ), l ) ->
1198+ Reporting. unreachable l __POS__
1199+ " Attempted to construct appended identifier from short-circuiting boolean operator"
11731200
11741201let remove_id_suffix id str =
11751202 match id with
11761203 | Id_aux (Id v , l ) -> remove_suffix v str |> Option. map (fun s -> Id_aux (Id s, l))
11771204 | Id_aux (Operator v , l ) -> remove_suffix v str |> Option. map (fun s -> Id_aux (Operator s, l))
1205+ | Id_aux ((And_bool | Or_bool ), l ) ->
1206+ Reporting. unreachable l __POS__ " Attempted to remove suffix from short-circuiting boolean operator"
11781207
11791208let prepend_kid str = function
11801209 | Kid_aux (Var v , l ) -> Kid_aux (Var (" '" ^ str ^ String. sub v 1 (String. length v - 1 )), l)
0 commit comments