Generate visitors for AAST defs
[hiphop-php.git] / hphp / hack / src / annotated_ast / aast_defs.src.ml
blobcb92949ac24a3b443d736bf9fdd3ab92bb51e1bf
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 include Aast_defs_visitors_ancestors
13 module ShapeMap = Ast.ShapeMap
15 type 'a shape_map = 'a ShapeMap.t [@@deriving show]
17 type local_id = Local_id.t [@visitors.opaque]
18 and lid = Pos.t * local_id
19 and sid = Ast.id
21 and is_terminal = bool
23 and call_type =
24 | Cnormal [@visitors.name "call_type_Cnormal"] (* when the call looks like f() *)
25 | Cuser_func [@visitors.name "call_type_Cuser_func"] (* when the call looks like call_user_func(...) *)
27 and is_coroutine = bool
28 and is_reactive = bool
30 and hint = Pos.t * hint_
31 and variadic_hint =
32 | Hvariadic of hint option
33 | Hnon_variadic
34 and hint_ =
35 | Hoption of hint
36 | Hfun of is_reactive * is_coroutine * hint list * Ast.param_kind option list * variadic_hint * hint
37 | Htuple of hint list
38 | Happly of sid * hint list
39 | Hshape of nast_shape_info
41 (* This represents the use of a type const. Type consts are accessed like
42 * regular consts in Hack, i.e.
44 * [self | static | Class]::TypeConst
46 * Class => Happly "Class"
47 * self => Happly of the class of definition
48 * static => Habstr ("static",
49 * Habstr ("this", (Constraint_as, Happly of class of definition)))
50 * Type const access can be chained such as
52 * Class::TC1::TC2::TC3
54 * We resolve the root of the type access chain as a type as follows.
56 * This will result in the following representation
58 * Haccess (Happly "Class", ["TC1", "TC2", "TC3"])
60 | Haccess of hint * sid list
62 (* The following constructors don't exist in the AST hint type *)
63 | Hany
64 | Hmixed
65 | Habstr of string
66 | Harray of hint option * hint option
67 | Hdarray of hint * hint
68 | Hvarray of hint
69 | Hvarray_or_darray of hint
70 | Hprim of tprim
71 | Hthis
73 (* AST types such as Happly("int", []) are resolved to Hprim values *)
74 and tprim =
75 | Tvoid
76 | Tint
77 | Tbool
78 | Tfloat
79 | Tstring
80 | Tresource
81 | Tnum
82 | Tarraykey
83 | Tnoreturn
85 and shape_field_info = {
86 sfi_optional: bool;
87 sfi_hint : hint;
90 and nast_shape_info = {
91 nsi_allows_unknown_fields : bool;
92 nsi_field_map : shape_field_info shape_map;
95 and kvc_kind = [
96 | `Map
97 | `ImmMap
98 | `Dict ]
99 [@visitors.opaque]
102 and vc_kind = [
103 | `Vector
104 | `ImmVector
105 | `Vec
106 | `Set
107 | `ImmSet
108 | `Pair
109 | `Keyset ]
110 [@visitors.opaque]
112 and tparam = Ast.variance * sid * (Ast.constraint_kind * hint) list
114 and visibility =
115 | Private [@visitors.name "visibility_Private"]
116 | Public [@visitors.name "visibility_Public"]
117 | Protected [@visitors.name "visibility_Protected"]
119 and typedef_visibility =
120 | Transparent
121 | Opaque
123 and enum_ = {
124 e_base : hint;
125 e_constraint : hint option;
129 and instantiated_sid = sid * hint list
131 and where_constraint = hint * Ast.constraint_kind * hint
132 [@@deriving
133 show,
134 visitors {
135 name="iter_defs";
136 variety = "iter";
137 nude=true;
138 visit_prefix="on_";
139 ancestors=["iter_defs_base"];
141 visitors {
142 name="reduce_defs";
143 variety = "reduce";
144 nude=true;
145 visit_prefix="on_";
146 ancestors=["reduce_defs_base"];
148 visitors {
149 name="map_defs";
150 variety = "map";
151 nude=true;
152 visit_prefix="on_";
153 ancestors=["map_defs_base"];
155 visitors {
156 name="endo_defs";
157 variety = "endo";
158 nude=true;
159 visit_prefix="on_";
160 ancestors=["endo_defs_base"];
163 type id = lid [@@deriving show]
164 type pstring = Ast.pstring [@@deriving show]
165 type shape_field_name = Ast.shape_field_name [@@deriving show]
167 type og_null_flavor = Ast.og_null_flavor =
168 | OG_nullthrows
169 | OG_nullsafe
171 let pp_og_null_flavor fmt flavor =
172 Format.pp_print_string fmt @@
173 match flavor with
174 | OG_nullthrows -> "OG_nullthrows"
175 | OG_nullsafe -> "OG_nullsafe"
177 let pp_kvc_kind fmt _ = Format.pp_print_string fmt "<kvc_kind>"
178 let pp_vc_kind fmt _ = Format.pp_print_string fmt "<vc_kind>"