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 module SM
= Ast_defs.ShapeMap
12 class ['self
] iter_defs_base
=
14 inherit [_
] Ast_defs.iter_defs
16 method private on_shape_map
17 : 'a
. ('env
-> 'a
-> unit) -> 'env
-> 'a
SM.t
-> unit =
18 fun f env x
-> SM.iter
(self#on_shape_map_entry f env
) x
20 method private on_shape_map_entry
21 : 'a
. ('env
-> 'a
-> unit) -> 'env
-> SM.key
-> 'a
-> unit =
23 self#on_shape_field_name env key
;
27 class virtual ['self
] reduce_defs_base
=
29 inherit [_
] Ast_defs.reduce_defs
31 method private on_shape_map
32 : 'a
. ('env
-> 'a
-> 'acc
) -> 'env
-> 'a
SM.t
-> 'acc
=
35 (fun k d acc
-> self#plus acc
(self#on_shape_map_entry f env k d
))
38 method private on_shape_map_entry
39 : 'a
. ('env
-> 'a
-> 'acc
) -> 'env
-> SM.key
-> 'a
-> 'acc
=
41 self#plus
(self#on_shape_field_name env key
) (f env data
)
44 class ['self
] map_defs_base
=
46 inherit [_
] Ast_defs.map_defs
48 method private on_shape_map
49 : 'a 'b
. ('env
-> 'a
-> 'b
) -> 'env
-> 'a
SM.t
-> 'b
SM.t
=
51 let map_entry key data acc
=
52 let key = self#on_shape_field_name env
key in
53 let data = f env
data in
56 SM.fold
map_entry x
SM.empty
59 class ['self
] endo_defs_base
=
61 inherit [_
] Ast_defs.endo_defs
63 method private on_shape_map
64 : 'a 'b
. ('env
-> 'a
-> 'b
) -> 'env
-> 'a
SM.t
-> 'b
SM.t
=
66 (* FIXME: Should be possible to write a true (more efficient) endo
67 implementation rather than copying map *)
68 let map_entry key data acc
=
69 let key = self#on_shape_field_name env
key in
70 let data = f env
data in
73 SM.fold
map_entry x
SM.empty