|
@@ -8593,77 +8593,6 @@ struct
|
|
|
end;;
|
|
|
*)
|
|
|
|
|
|
- (* ******************************************* *)
|
|
|
- (* IteratorsInterfaceExprf *)
|
|
|
- (* ******************************************* *)
|
|
|
- (*
|
|
|
- The expression filter for Iterators. Will look for TFor, transform it into
|
|
|
- {
|
|
|
- var iterator = // in expression here
|
|
|
- while (iterator.hasNext())
|
|
|
- {
|
|
|
- var varName = iterator.next();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- dependencies:
|
|
|
- Must run before Dynamic fields access is run
|
|
|
-
|
|
|
- TODO: I think TFor is always rewritten to TWhile before getting into the generator nowadays,
|
|
|
- so this filter could probably be removed. Gotta ask Simon about it.
|
|
|
- *)
|
|
|
- module IteratorsInterfaceExprf =
|
|
|
- struct
|
|
|
- let name = "iterators_interface_exprf"
|
|
|
- let priority = solve_deps name [DBefore DynamicFieldAccess.priority]
|
|
|
-
|
|
|
- let mk_access gen v name pos =
|
|
|
- let field_t =
|
|
|
- try match follow v.v_type with
|
|
|
- | TInst(cl, params) ->
|
|
|
- let field = PMap.find name cl.cl_fields in
|
|
|
- apply_params cl.cl_params params field.cf_type
|
|
|
- | TAnon(anon) ->
|
|
|
- let field = PMap.find name anon.a_fields in
|
|
|
- field.cf_type
|
|
|
- | _ -> t_dynamic
|
|
|
- with | Not_found -> t_dynamic
|
|
|
- in
|
|
|
- { (mk_field_access gen (mk_local v pos) name pos) with etype = field_t }
|
|
|
-
|
|
|
- let configure gen =
|
|
|
- let basic = gen.gcon.basic in
|
|
|
- let rec run e =
|
|
|
- match e.eexpr with
|
|
|
- | TFor(var, in_expr, block) ->
|
|
|
- let in_expr = run in_expr in
|
|
|
- let temp = mk_temp gen "iterator" in_expr.etype in
|
|
|
- let block = [
|
|
|
- { eexpr = TVar(temp, Some(in_expr)); etype = basic.tvoid; epos = in_expr.epos };
|
|
|
- {
|
|
|
- eexpr = TWhile(
|
|
|
- { eexpr = TCall(mk_access gen temp "hasNext" in_expr.epos, []); etype = basic.tbool; epos = in_expr.epos },
|
|
|
- Type.concat ({
|
|
|
- eexpr = TVar(var, Some({ eexpr = TCall(mk_access gen temp "next" in_expr.epos, []); etype = var.v_type; epos = in_expr.epos }));
|
|
|
- etype = basic.tvoid;
|
|
|
- epos = in_expr.epos
|
|
|
- }) ( run block ),
|
|
|
- Ast.NormalWhile);
|
|
|
- etype = basic.tvoid;
|
|
|
- epos = e.epos
|
|
|
- }
|
|
|
- ] in
|
|
|
- { eexpr = TBlock(block); etype = e.etype; epos = e.epos }
|
|
|
- | _ ->
|
|
|
- Type.map_expr run e
|
|
|
- in
|
|
|
- let map e = Some(run e) in
|
|
|
- gen.gexpr_filters#add ~name:name ~priority:(PCustom priority) map
|
|
|
- end;;
|
|
|
-
|
|
|
- let configure gen =
|
|
|
- IteratorsInterfaceExprf.configure gen
|
|
|
-
|
|
|
end;;
|
|
|
|
|
|
|