2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
12 module CE
= Common_exns
13 module List
= Core_list
18 let errors = ref [] in
20 let unsupported (p
, m
) =
21 errors := (CE.ConversionError
(p
, m
)) :: !errors;
24 let detect_invalid_attributes p attributes
=
25 if List.exists ~f
:(fun { ua_name
; _
} -> "__Memoize" = snd ua_name
) attributes
26 then unsupported (p
, "__Memoize is currently not supported.")
29 let detect_invalid_fun_kind p
= function
30 | FSync
| FGenerator
-> ()
31 | FAsync
| FAsyncGenerator
->
32 unsupported (p
, "async is currently not supported.") in
34 let detect_invalid_fun {f_user_attributes
; f_fun_kind
; f_name
= (p
, _
); _
} =
35 detect_invalid_attributes p f_user_attributes
;
36 detect_invalid_fun_kind p f_fun_kind
in
38 let detect_invalid_method {m_user_attributes
; m_fun_kind
; m_name
= (p
, _
); _
} =
39 detect_invalid_attributes p m_user_attributes
;
40 detect_invalid_fun_kind p m_fun_kind
in
42 let detect_invalid_collection p name afields
=
43 match (base_collection_str name
, afields
) with
44 | (Some
"\\HH\\Pair", [AFvalue _
; AFvalue _
]) -> ()
45 | (Some
"\\HH\\Pair", _
) ->
46 unsupported (p
, "Invalid initialization of Pair")
47 | (Some
"\\HH\\Map", _
) | (Some
"\\HH\\ImmMap", _
) ->
48 (** TODO: task 10395133. support dict *)
49 List.iter ~f
:begin function
52 unsupported (p
, "Invalid Initialization of " ^ name
)
55 unsupported (p
, "Unsupported collection type " ^ name
)
58 let detect_invalid_expr = function
60 unsupported (p
, "await is currently not supported.")
61 | (_
, Collection
((p
, name
), afields
)) ->
62 detect_invalid_collection p name afields
;
66 let detect_invalid_class_var = function
67 | ((p
, _
), Some
(_
, Collection _
)) ->
68 let m = "Collection initializers in instance variables are currently" ^
73 let detect_invalid_class_elt = function
74 | ClassVars
(kinds
, _
, class_vars
) when not
(List.mem kinds Static
) ->
75 List.iter ~f
:detect_invalid_class_var class_vars
;
79 let detect_invalid_class = function
80 | {c_name
= (p
, _
); c_kind
= Ctrait
; c_implements
= _
::_
; _
} ->
82 "Traits implementing interfaces are currently not supported. ")
85 let mapper = M.mk_program_mapper
{ M.default_mapper
with
86 M.k_class_
= (fun (k
, _
) c
->
87 detect_invalid_class c
;
89 M.k_class_elt
= (fun (k
, _
) _ elt
->
90 detect_invalid_class_elt elt
;
93 M.k_fun_
= (fun (k
, _
) fun_
->
94 detect_invalid_fun fun_
;
96 M.k_method_
= (fun (k
, _
) _ method_
->
97 detect_invalid_method method_
;
99 M.k_expr
= (fun (k
, _
) e
-> detect_invalid_expr e
; k e
);
101 ignore
(mapper program
);
102 if not
(List.is_empty
!errors)
103 then raise
(CE.CompoundError
!errors);
104 program
(* this mapper does no mapping *)