Hack codegen: static closures, ordering of inline functions and classes
[hiphop-php.git] / hphp / hack / src / hhbc / emit_typedef.ml
blobc660c9a538787040a624397b6f57e96f60dc0764
1 (**
2 * Copyright (c) 2017, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
9 *)
11 open Core
13 let kind_to_type_info ~tparams ~namespace k =
14 match k with
15 | Ast.Alias h | Ast.NewType h ->
16 Emit_type_hint.hint_to_type_info
17 ~skipawaitable:false ~nullable:false
18 ~always_extended:false ~tparams ~namespace h
20 let emit_typedef : Ast.typedef -> Hhas_typedef.t =
21 fun ast_typedef ->
22 let namespace = ast_typedef.Ast.t_namespace in
23 let typedef_name, _ =
24 Hhbc_id.Class.elaborate_id namespace ast_typedef.Ast.t_id in
25 let tparams = Emit_body.tparams_to_strings ast_typedef.Ast.t_tparams in
26 let typedef_type_info =
27 kind_to_type_info ~tparams ~namespace ast_typedef.Ast.t_kind in
28 Hhas_typedef.make
29 typedef_name
30 typedef_type_info
32 let emit_typedefs_from_program ast =
33 List.filter_map ast
34 (fun d -> match d with Ast.Typedef td -> Some (emit_typedef td) | _ -> None)