add some .mli files
[hiphop-php.git] / hphp / hack / src / typing / typing_generic.ml
blob4483119ecf923a8b61ac184dfe1c41d3f74f6f16
1 (*
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 open Hh_prelude
11 open Typing_defs
13 (* Module checking if a type is generic, I like to use an exception for this sort
14 * of things, the code is more readable (subjective :-), and the exception never
15 * escapes anyway.
17 module IsGeneric : sig
18 (* Give back the position and name of a generic type parameter if found *)
19 val ty : decl_ty -> (Pos.t * string) option
20 end = struct
21 exception Found of Pos.t * string
23 let ty x =
24 let rec ty t =
25 match get_node t with
26 | Tgeneric (x, _args) -> raise (Found (get_pos t, x))
27 | Tthis -> ()
28 | Tmixed -> ()
29 | Tdynamic
30 | Tany _
31 | Terr
32 | Tnonnull
33 | Tprim _ ->
35 | Tvar _ -> ()
36 | Toption x -> ty x
37 | Tlike x -> ty x
38 | Tfun fty ->
39 List.iter (List.map fty.ft_params (fun x -> x.fp_type.et_type)) ty;
40 ty fty.ft_ret.et_type;
41 (match fty.ft_arity with
42 | Fvariadic { fp_type = var_ty; _ } -> ty var_ty.et_type
43 | _ -> ())
44 | Ttuple tyl
45 | Tunion tyl
46 | Tintersection tyl ->
47 List.iter tyl ty
48 | Tapply (_, tyl) -> List.iter tyl ty
49 | Taccess (t, _) -> ty t
50 | Tdarray (t1, t2)
51 | Tvarray_or_darray (t1, t2) ->
52 ty t1;
53 ty t2
54 | Tvarray t -> ty t
55 | Tshape (_, fdm) -> ShapeFieldMap.iter (fun _ v -> ty v) fdm
57 try
58 ty x;
59 None
60 with Found (p, x) -> Some (p, x)
61 end
63 let is_generic = IsGeneric.ty