2 * Copyright (c) 2018, 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.
13 module SN
= Naming_special_names
17 inherit [_
] Aast.iter
as super
20 method go
(ctx
: Provider_context.t
) (program
: Nast.program
) =
21 self#on_list
(fun () -> self#go_def ctx
) () program
23 method go_def ctx x
= self#on_def
(def_env ctx x
) x
25 method! on_fun_ env x
= super#on_fun_
(fun_env env x
) x
27 method! on_method_ env x
= super#on_method_
(method_env env x
) x
29 method! on_class_ env x
= super#on_class_
(class_env env x
) x
31 method! on_Try env b cl fb
=
32 self#on_block
{ env
with is_finally
= true } fb
;
33 super#on_Try env b cl fb
35 method! on_Do env
= super#on_Do
{ env
with control_context
= LoopContext
}
37 method! on_While env
=
38 super#on_While
{ env
with control_context
= LoopContext
}
40 method! on_For env
= super#on_For
{ env
with control_context
= LoopContext
}
42 method! on_Foreach env
=
43 super#on_Foreach
{ env
with control_context
= LoopContext
}
45 method! on_Switch env
=
46 super#on_Switch
{ env
with control_context
= SwitchContext
}
49 super#on_Efun
{ env
with is_finally
= false; control_context
= Toplevel
}
52 super#on_Lfun
{ env
with is_finally
= false; control_context
= Toplevel
}
54 method! on_Obj_get env
=
55 super#on_Obj_get
{ env
with array_append_allowed
= false }
57 method! on_Array_get env
=
58 super#on_Array_get
{ env
with array_append_allowed
= false }
60 method! on_Binop env op e1 e2
=
63 self#on_expr
{ env
with array_append_allowed
= true } e1
;
65 | _
-> super#on_Binop env op e1 e2
67 method! on_func_body env fb
=
69 | [(_
, If
(((_
, Id
(_
, c
)) as id
), then_stmt
, else_stmt
))] ->
70 super#on_expr
{ env
with rx_is_enabled_allowed
= SN.Rx.is_enabled c
} id
;
71 self#on_block env then_stmt
;
72 self#on_block env else_stmt
73 | _
-> super#on_func_body env fb
75 method! on_expr env e
=
77 | (_
, Call
(ct
, ((_
, Id
(_
, cn
)) as e1
), ta
, el
, unpacked_element
))
78 when String.equal cn
SN.Rx.move
->
80 { env
with rx_move_allowed
= false }
86 | (_
, Call
(ct
, e1
, ta
, el
, unpacked_element
)) ->
88 { env
with rx_move_allowed
= true }
94 | (_
, Binop
(Ast_defs.Eq None
, e1
, rhs
)) ->
96 { env
with rx_move_allowed
= true }
100 | _
-> super#on_expr
{ env
with rx_move_allowed
= false } e
103 class virtual ['state
] iter_with_state
=
105 inherit [_
] Aast.iter
as super
109 (state
: 'state
) (ctx
: Provider_context.t
) (program
: Nast.program
) =
110 self#on_list
(fun () -> self#go_def state ctx
) () program
112 method go_def state ctx x
= self#on_def
(def_env ctx x
, state
) x
114 method! on_fun_
(env
, state
) x
= super#on_fun_
(fun_env env x
, state
) x
119 method at_fun_
: env
-> Nast.fun_
-> unit
121 method at_class_
: env
-> Nast.class_
-> unit
123 method at_method_
: env
-> Nast.method_
-> unit
125 method at_record_def
: env
-> Nast.record_def
-> unit
127 method at_expr
: env
-> Nast.expr
-> unit
129 method at_stmt
: env
-> Nast.stmt
-> unit
131 method at_hint
: env
-> hint
-> unit
133 method at_typedef
: env
-> Nast.typedef
-> unit
135 method at_method_redeclaration
: env
-> Nast.method_redeclaration
-> unit
137 method at_gconst
: env
-> Nast.gconst
-> unit
140 class virtual handler_base
: handler
=
142 method at_fun_ _ _
= ()
144 method at_class_ _ _
= ()
146 method at_method_ _ _
= ()
148 method at_record_def _ _
= ()
150 method at_expr _ _
= ()
152 method at_stmt _ _
= ()
154 method at_hint _ _
= ()
156 method at_typedef _ _
= ()
158 method at_method_redeclaration _ _
= ()
160 method at_gconst _ _
= ()
163 let iter_with (handlers
: handler list
) : iter
=
165 inherit iter
as super
167 method! on_fun_ env x
=
168 List.iter handlers
(fun v
-> v#at_fun_ env x
);
171 method! on_class_ env x
=
172 List.iter handlers
(fun v
-> v#at_class_ env x
);
173 super#on_class_ env x
175 method! on_method_ env x
=
176 List.iter handlers
(fun v
-> v#at_method_ env x
);
177 super#on_method_ env x
179 method! on_record_def env x
=
180 List.iter handlers
(fun v
-> v#at_record_def env x
);
181 super#on_record_def env x
183 method! on_expr env x
=
184 List.iter handlers
(fun v
-> v#at_expr env x
);
187 method! on_stmt env x
=
188 List.iter handlers
(fun v
-> v#at_stmt env x
);
191 method! on_hint env h
=
192 List.iter handlers
(fun v
-> v#at_hint env h
);
195 method! on_typedef env t
=
196 List.iter handlers
(fun v
-> v#at_typedef env t
);
197 super#on_typedef env t
199 method! on_method_redeclaration env mr
=
200 List.iter handlers
(fun v
-> v#at_method_redeclaration env mr
);
201 super#on_method_redeclaration env mr
203 method! on_gconst env gconst
=
204 List.iter handlers
(fun v
-> v#at_gconst env gconst
);
205 super#on_gconst env gconst