From b172862d21f16095a5cf11a8938f3cea24e9bf58 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 10 Jul 2010 14:59:54 -0700 Subject: [PATCH] Add a ty_children function to enumerate the children of any type --- src/boot/fe/ast.ml | 26 ++++++++++++++++++++++++++ src/boot/util/common.ml | 1 - 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index 92aad667d01..f00db117a5f 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -1339,6 +1339,32 @@ and fmt_crate (ff:Format.formatter) (c:crate) : unit = let (view,items) = c.node.crate_items in fmt_mod_view ff view; fmt_mod_items ff items +;; + +let ty_children (ty:ty) : ty array = + let children_of_ty_tag ty_tag = Array.concat (htab_vals ty_tag) in + let children_of_ty_fn ty_fn = + let (ty_sig, _) = ty_fn in + let in_slots = ty_sig.sig_input_slots in + let slots = Array.append in_slots [| ty_sig.sig_output_slot |] in + arr_filter_some (Array.map (fun slot -> slot.slot_ty) slots) + in + match ty with + TY_tup tys -> tys + | TY_vec ty' | TY_chan ty' | TY_port ty' | TY_box ty' | TY_mutable ty' + | TY_constrained (ty', _) -> + [| ty' |] + | TY_rec fields -> Array.map snd fields + | TY_tag ty_tag -> children_of_ty_tag ty_tag + | TY_iso ty_iso -> children_of_ty_tag (ty_iso.iso_group.(ty_iso.iso_index)) + | TY_fn ty_fn -> children_of_ty_fn ty_fn + | TY_obj (_, methods) -> + Array.concat (List.map children_of_ty_fn (htab_vals methods)) + | TY_any | TY_nil | TY_bool | TY_mach _ | TY_int | TY_uint | TY_char + | TY_str | TY_idx _ | TY_task | TY_native _ | TY_param _ + | TY_named _ | TY_type -> + [| |] +;; let sprintf_expr = sprintf_fmt fmt_expr;; let sprintf_name = sprintf_fmt fmt_name;; diff --git a/src/boot/util/common.ml b/src/boot/util/common.ml index 168c9f0ad87..0ea39e2d5b2 100644 --- a/src/boot/util/common.ml +++ b/src/boot/util/common.ml @@ -341,7 +341,6 @@ let bool_of_option x = Some _ -> true | None -> false - (* * Auxiliary stack functions. *)