2 * Copyright (c) 2017, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
10 include Ast_defs_visitors_ancestors
12 (*****************************************************************************)
13 (* The Abstract Syntax Tree *)
14 (*****************************************************************************)
16 type pos
= (Pos.t
[@visitors
.opaque
])
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
48 and param_kind
= Pinout
101 show
{ with_path
= false },
107 visit_prefix
= "on_";
108 ancestors
= ["iter_defs_base"];
115 visit_prefix
= "on_";
116 ancestors
= ["endo_defs_base"];
120 name
= "reduce_defs";
123 visit_prefix
= "on_";
124 ancestors
= ["reduce_defs_base"];
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 *)
140 [@@deriving show
{ with_path
= false }]
142 (*****************************************************************************)
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"
152 | Crecord
-> "a record"
154 let string_of_param_kind = function
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. *)
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
)