|
@@ -8470,111 +8470,6 @@ struct
|
|
|
EnumToClassExprf.configure gen t opt_get_native_enum_tag
|
|
|
end;;
|
|
|
|
|
|
-(* ******************************************* *)
|
|
|
-(* IteratorsInterface *)
|
|
|
-(* ******************************************* *)
|
|
|
-(*
|
|
|
- This module will handle with Iterators and Iterables.
|
|
|
- At first, a module filter will receive a Iterator<T> and Iterable<T> interface, which will be implemented
|
|
|
- if hasNext(), next() or iterator() fields are detected with the correct type.
|
|
|
- At this part a custom function will be called which can adequate the class fields so they are compatible with
|
|
|
- native Iterators as well
|
|
|
-
|
|
|
- dependencies:
|
|
|
- None.
|
|
|
-*)
|
|
|
-module IteratorsInterface =
|
|
|
-struct
|
|
|
- let name = "iterators_interface"
|
|
|
- (* TODO later
|
|
|
- (* ******************************************* *)
|
|
|
- (* IteratorsInterfaceModf *)
|
|
|
- (* ******************************************* *)
|
|
|
- (*
|
|
|
- The module filter for Iterators Interface, which will implement the iterator/iterable interface on each
|
|
|
- class that conforms with the typedefs Iterator<> and Iterable<>
|
|
|
-
|
|
|
- It's a very simple module and it will rely on cast detection to work correctly. This is so that
|
|
|
- when the
|
|
|
-
|
|
|
- dependencies:
|
|
|
- Must run at the Module Filters, so cast detection can detect a cast to the interface and we can
|
|
|
- *)
|
|
|
- module IteratorsInterfaceModf =
|
|
|
- struct
|
|
|
- let name = "iterators_interface_modf"
|
|
|
-
|
|
|
- let conforms_cfs has_next next =
|
|
|
- try (match follow has_next.cf_type with
|
|
|
- | TFun([],ret) when
|
|
|
- (match follow ret with | TAbstract({ a_path = ([], "Bool") }, []) -> () | _ -> raise Not_found) ->
|
|
|
- ()
|
|
|
- | _ -> raise Not_found);
|
|
|
- (match follow next.cf_type with
|
|
|
- | TFun([], ret) -> ret
|
|
|
- | _ -> raise Not_found
|
|
|
- )
|
|
|
-
|
|
|
- let conforms_type_iterator t =
|
|
|
- try match follow t with
|
|
|
- | TInst(cl,params) ->
|
|
|
- let has_next = PMap.find "hasNext" cl.cl_fields in
|
|
|
- let next = PMap.find "next" cl.cl_fields in
|
|
|
- Some (conforms_cfs has_next next)
|
|
|
- | TAnon(anon) ->
|
|
|
- let has_next = PMap.find "hasNext" anon.a_fields in
|
|
|
- let next = PMap.find "next" anon.a_fields in
|
|
|
- Some (conforms_cfs has_next next)
|
|
|
- | _ -> None
|
|
|
- with | Not_found -> None
|
|
|
-
|
|
|
- let conforms_as_iterable cl =
|
|
|
- try
|
|
|
- let iterator = PMap.find "iterator" cl.cl_fields in
|
|
|
- match follow iterator.cf_type with
|
|
|
- | TFun([], ret) -> conforms_type_iterator ret
|
|
|
- | _ -> None
|
|
|
- with | Not_found -> None
|
|
|
-
|
|
|
- let conforms_as_iterator cl =
|
|
|
- try
|
|
|
- let has_next = PMap.find "hasNext" cl.cl_fields in
|
|
|
- let next = PMap.find "next" cl.cl_fields in
|
|
|
- Some (conforms_cfs has_next next)
|
|
|
- with | Not_found -> None
|
|
|
-
|
|
|
- let priority = solve_deps name []
|
|
|
-
|
|
|
- let traverse gen iterator_iface iterable_iface on_found_iterator on_found_iterable =
|
|
|
- let rec run md =
|
|
|
- match md with
|
|
|
- | TClassDecl cl when not cl.cl_extern && is_hxgen cl ->
|
|
|
- let conforms_iterator = conforms_as_iterator cl in
|
|
|
- let conforms_iterable = conforms_as_iterable cl in
|
|
|
- if is_some conforms_iterator then begin
|
|
|
- let it_t = get conforms_iterator in
|
|
|
- cl.cl_interfaces <- (iterator_iface, [it_t]);
|
|
|
- on_found_iterator cl
|
|
|
- end;
|
|
|
- if is_some conforms_iterable then begin
|
|
|
- let it_t = get conforms_iterable in
|
|
|
- cl.cl_interfaces <- (iterable_iface, [it_t]);
|
|
|
- on_found_iterable cl
|
|
|
- end;
|
|
|
-
|
|
|
- md
|
|
|
- | _ -> md
|
|
|
- in
|
|
|
- run
|
|
|
-
|
|
|
- let configure gen (mapping_func:texpr->texpr) =
|
|
|
- let map e = Some(mapping_func e) in
|
|
|
- gen.gexpr_filters#add ~name:name ~priority:(PCustom priority) map
|
|
|
-
|
|
|
- end;;
|
|
|
- *)
|
|
|
-end;;
|
|
|
-
|
|
|
|
|
|
(* ******************************************* *)
|
|
|
(* SwitchToIf *)
|