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
(_
, _
)) as id
), then_stmt
, else_stmt
))] ->
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
(e1
, ta
, el
, unpacked_element
)) ->
78 self#on_Call env e1 ta el unpacked_element
79 | (_
, Binop
(Ast_defs.Eq None
, e1
, rhs
)) ->
80 self#on_Binop env
(Ast_defs.Eq None
) e1 rhs
81 | _
-> super#on_expr env e
84 class virtual ['state
] iter_with_state
=
86 inherit [_
] Aast.iter
as super
90 (state
: 'state
) (ctx
: Provider_context.t
) (program
: Nast.program
) =
91 self#on_list
(fun () -> self#go_def state ctx
) () program
93 method go_def state ctx x
= self#on_def
(def_env ctx x
, state
) x
95 method! on_fun_
(env
, state
) x
= super#on_fun_
(fun_env env x
, state
) x
100 method at_fun_
: env
-> Nast.fun_
-> unit
102 method at_class_
: env
-> Nast.class_
-> unit
104 method at_method_
: env
-> Nast.method_
-> unit
106 method at_record_def
: env
-> Nast.record_def
-> unit
108 method at_expr
: env
-> Nast.expr
-> unit
110 method at_stmt
: env
-> Nast.stmt
-> unit
112 method at_hint
: env
-> hint
-> unit
114 method at_contexts
: env
-> contexts
-> unit
116 method at_typedef
: env
-> Nast.typedef
-> unit
118 method at_gconst
: env
-> Nast.gconst
-> unit
121 class virtual handler_base
: handler
=
123 method at_fun_ _ _
= ()
125 method at_class_ _ _
= ()
127 method at_method_ _ _
= ()
129 method at_record_def _ _
= ()
131 method at_expr _ _
= ()
133 method at_stmt _ _
= ()
135 method at_hint _ _
= ()
137 method at_contexts _ _
= ()
139 method at_typedef _ _
= ()
141 method at_gconst _ _
= ()
144 let iter_with (handlers
: handler list
) : iter
=
146 inherit iter
as super
148 method! on_fun_ env x
=
149 List.iter handlers
(fun v
-> v#at_fun_ env x
);
152 method! on_class_ env x
=
153 List.iter handlers
(fun v
-> v#at_class_ env x
);
154 super#on_class_ env x
156 method! on_method_ env x
=
157 List.iter handlers
(fun v
-> v#at_method_ env x
);
158 super#on_method_ env x
160 method! on_record_def env x
=
161 List.iter handlers
(fun v
-> v#at_record_def env x
);
162 super#on_record_def env x
164 method! on_expr env x
=
165 List.iter handlers
(fun v
-> v#at_expr env x
);
168 method! on_stmt env x
=
169 List.iter handlers
(fun v
-> v#at_stmt env x
);
172 method! on_hint env h
=
173 List.iter handlers
(fun v
-> v#at_hint env h
);
176 method! on_contexts env cl
=
177 List.iter handlers
(fun v
-> v#at_contexts env cl
);
178 super#on_contexts env cl
180 method! on_typedef env t
=
181 List.iter handlers
(fun v
-> v#at_typedef env t
);
182 super#on_typedef env t
184 method! on_gconst env gconst
=
185 List.iter handlers
(fun v
-> v#at_gconst env gconst
);
186 super#on_gconst env gconst