Enable ocamlformat for parts of hphp/hack
[hiphop-php.git] / hphp / hack / src / ast / ast_defs.ml
blobf275ee45d50132a3a835ce6f02dd9c39422b44ee
1 (**
2 * Copyright (c) 2017, 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 include Ast_defs_visitors_ancestors
12 (*****************************************************************************)
13 (* The Abstract Syntax Tree *)
14 (*****************************************************************************)
16 type pos = (Pos.t[@visitors.opaque])
18 and id = pos * string
20 and pstring = pos * string
22 and shape_field_name =
23 | SFlit_int of pstring
24 | SFlit_str of pstring
25 | SFclass_const of id * pstring
27 and variance =
28 | Covariant
29 | Contravariant
30 | Invariant
32 and constraint_kind =
33 | Constraint_as
34 | Constraint_eq
35 | Constraint_super
36 | Constraint_pu_from
38 and reified = bool
40 and class_kind =
41 | Cabstract
42 | Cnormal
43 | Cinterface
44 | Ctrait
45 | Cenum
46 | Crecord
48 and param_kind = Pinout
50 and og_null_flavor =
51 | OG_nullthrows
52 | OG_nullsafe
54 and fun_kind =
55 | FSync
56 | FAsync
57 | FGenerator
58 | FAsyncGenerator
59 | FCoroutine
61 and bop =
62 | Plus
63 | Minus
64 | Star
65 | Slash
66 | Eqeq
67 | Eqeqeq
68 | Starstar
69 | Diff
70 | Diff2
71 | Ampamp
72 | Barbar
73 | LogXor
74 | Lt
75 | Lte
76 | Gt
77 | Gte
78 | Dot
79 | Amp
80 | Bar
81 | Ltlt
82 | Gtgt
83 | Percent
84 | Xor
85 | Cmp
86 | QuestionQuestion
87 | Eq of bop option
89 and uop =
90 | Utild
91 | Unot
92 | Uplus
93 | Uminus
94 | Uincr
95 | Udecr
96 | Upincr
97 | Updecr
98 | Uref
99 | Usilence
100 [@@deriving
101 show { with_path = false },
102 visitors
104 name = "iter_defs";
105 variety = "iter";
106 nude = true;
107 visit_prefix = "on_";
108 ancestors = ["iter_defs_base"];
110 visitors
112 name = "endo_defs";
113 variety = "endo";
114 nude = true;
115 visit_prefix = "on_";
116 ancestors = ["endo_defs_base"];
118 visitors
120 name = "reduce_defs";
121 variety = "reduce";
122 nude = true;
123 visit_prefix = "on_";
124 ancestors = ["reduce_defs_base"];
126 visitors
128 name = "map_defs";
129 variety = "map";
130 nude = true;
131 visit_prefix = "on_";
132 ancestors = ["map_defs_base"];
135 (* This type is not used in the AST so no visitor is generated for it *)
136 type fun_decl_kind =
137 | FDeclAsync
138 | FDeclSync
139 | FDeclCoroutine
140 [@@deriving show { with_path = false }]
142 (*****************************************************************************)
143 (* Helpers *)
144 (*****************************************************************************)
146 let string_of_class_kind = function
147 | Cabstract -> "an abstract class"
148 | Cnormal -> "a class"
149 | Cinterface -> "an interface"
150 | Ctrait -> "a trait"
151 | Cenum -> "an enum"
152 | Crecord -> "a record"
154 let string_of_param_kind = function
155 | Pinout -> "inout"
157 module ShapeField = struct
158 type t = shape_field_name
160 (* We include span information in shape_field_name to improve error
161 * messages, but we don't want it being used in the comparison, so
162 * we have to write our own compare. *)
163 let compare x y =
164 match (x, y) with
165 | SFlit_int (_, s1), SFlit_int (_, s2) -> Pervasives.compare s1 s2
166 | SFlit_str (_, s1), SFlit_str (_, s2) -> Pervasives.compare s1 s2
167 | SFclass_const ((_, s1), (_, s1')), SFclass_const ((_, s2), (_, s2')) ->
168 Pervasives.compare (s1, s1') (s2, s2')
169 | SFlit_int _, _ -> -1
170 | SFlit_str _, SFlit_int _ -> 1
171 | SFlit_str _, _ -> -1
172 | SFclass_const _, _ -> 1
175 module ShapeMap = struct
176 include MyMap.Make (ShapeField)
178 let map_and_rekey m f1 f2 =
179 fold (fun k v acc -> add (f1 k) (f2 v) acc) m empty
181 let pp _ fmt _ = Format.pp_print_string fmt "[ShapeMap]"
184 module ShapeSet = Set.Make (ShapeField)