Skip to content

Commit b172862

Browse files
committed
Add a ty_children function to enumerate the children of any type
1 parent b3cf793 commit b172862

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/boot/fe/ast.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,32 @@ and fmt_crate (ff:Format.formatter) (c:crate) : unit =
13391339
let (view,items) = c.node.crate_items in
13401340
fmt_mod_view ff view;
13411341
fmt_mod_items ff items
1342+
;;
1343+
1344+
let ty_children (ty:ty) : ty array =
1345+
let children_of_ty_tag ty_tag = Array.concat (htab_vals ty_tag) in
1346+
let children_of_ty_fn ty_fn =
1347+
let (ty_sig, _) = ty_fn in
1348+
let in_slots = ty_sig.sig_input_slots in
1349+
let slots = Array.append in_slots [| ty_sig.sig_output_slot |] in
1350+
arr_filter_some (Array.map (fun slot -> slot.slot_ty) slots)
1351+
in
1352+
match ty with
1353+
TY_tup tys -> tys
1354+
| TY_vec ty' | TY_chan ty' | TY_port ty' | TY_box ty' | TY_mutable ty'
1355+
| TY_constrained (ty', _) ->
1356+
[| ty' |]
1357+
| TY_rec fields -> Array.map snd fields
1358+
| TY_tag ty_tag -> children_of_ty_tag ty_tag
1359+
| TY_iso ty_iso -> children_of_ty_tag (ty_iso.iso_group.(ty_iso.iso_index))
1360+
| TY_fn ty_fn -> children_of_ty_fn ty_fn
1361+
| TY_obj (_, methods) ->
1362+
Array.concat (List.map children_of_ty_fn (htab_vals methods))
1363+
| TY_any | TY_nil | TY_bool | TY_mach _ | TY_int | TY_uint | TY_char
1364+
| TY_str | TY_idx _ | TY_task | TY_native _ | TY_param _
1365+
| TY_named _ | TY_type ->
1366+
[| |]
1367+
;;
13421368

13431369
let sprintf_expr = sprintf_fmt fmt_expr;;
13441370
let sprintf_name = sprintf_fmt fmt_name;;

src/boot/util/common.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ let bool_of_option x =
341341
Some _ -> true
342342
| None -> false
343343

344-
345344
(*
346345
* Auxiliary stack functions.
347346
*)

0 commit comments

Comments
 (0)