aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2010-07-10 14:59:54 -0700
committerPatrick Walton <[email protected]>2010-07-12 10:40:37 -0700
commitb172862d21f16095a5cf11a8938f3cea24e9bf58 (patch)
tree076d2e3059506aaaa3c88dec13e542f506bdb9dc /src
parentFix post-stmt drop calculations. Closes #106. (diff)
downloadrust-b172862d21f16095a5cf11a8938f3cea24e9bf58.tar.xz
rust-b172862d21f16095a5cf11a8938f3cea24e9bf58.zip
Add a ty_children function to enumerate the children of any type
Diffstat (limited to 'src')
-rw-r--r--src/boot/fe/ast.ml26
-rw-r--r--src/boot/util/common.ml1
2 files changed, 26 insertions, 1 deletions
diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml
index 92aad667..f00db117 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 168c9f0a..0ea39e2d 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.
*)