2
0
Эх сурвалжийг харах

[java/cs] fixed interfaces with variables lookup. By now they are done by Reflection.

Caue Waneck 13 жил өмнө
parent
commit
f2b01b4de1
3 өөрчлөгдсөн 70 нэмэгдсэн , 0 устгасан
  1. 66 0
      gencommon.ml
  2. 2 0
      gencs.ml
  3. 2 0
      genjava.ml

+ 66 - 0
gencommon.ml

@@ -8389,6 +8389,72 @@ struct
     gen.gmodule_filters#add ~name:name ~priority:(PCustom priority) map
   
 end;;
+
+(* ******************************************* *)
+(* Interface Variables Removal Modf *)
+(* ******************************************* *)
+
+(*
+  
+  This module filter will take care of sanitizing interfaces for targets that do not support
+  variables declaration in interfaces. By now this will mean that if anything is typed as the interface,
+  and a variable access is made, a FNotFound will be returned for the field_access, so
+  the field will be only accessible by reflection.
+  Speed-wise, ideally it would be best to create getProp/setProp functions in this case and change
+  the AST to call them when accessing by interface. (TODO)
+  But right now it will be accessed by reflection.
+  
+  dependencies:
+    
+  
+*)
+
+module InterfaceVarsDeleteModf =
+struct
+
+  let name = "interface_vars"
+  
+  let priority = solve_deps name []
+  
+  let run gen =
+    let run md = match md with
+      | TClassDecl ( { cl_interface = true } as cl ) ->
+        let to_add = ref [] in
+        let fields = List.filter (fun cf -> 
+          match cf.cf_kind with
+            | Var vkind ->
+              (match vkind.v_read with
+                | AccCall str ->
+                  let newcf = mk_class_field str (TFun([],cf.cf_type)) true cf.cf_pos (Method MethNormal) [] in
+                  to_add := newcf :: !to_add;
+                | _ -> ()
+              );
+              (match vkind.v_write with
+                | AccCall str ->
+                  let newcf = mk_class_field str (TFun(["val",false,cf.cf_type],cf.cf_type)) true cf.cf_pos (Method MethNormal) [] in
+                  to_add := newcf :: !to_add;
+                | _ -> ()
+              );
+              cl.cl_fields <- PMap.remove cf.cf_name cl.cl_fields;
+              false
+            | _ -> true
+        ) cl.cl_ordered_fields in
+        cl.cl_ordered_fields <- !to_add @ fields;
+        List.iter (fun cf -> cl.cl_fields <- PMap.add cf.cf_name cf cl.cl_fields) !to_add;
+        
+        md
+      | _ -> md
+    in
+    run
+  
+  let configure gen =
+    let run = run gen in
+    let map md = Some(run md) in
+    gen.gmodule_filters#add ~name:name ~priority:(PCustom priority) map
+  
+  
+end;;
+
 (*
 (* ******************************************* *)
 (* Example *)

+ 2 - 0
gencs.ml

@@ -1092,6 +1092,8 @@ let configure gen =
   
   EnumToClass.configure gen (Some (fun e -> mk_cast gen.gcon.basic.tint e)) false true (get_cl (Hashtbl.find gen.gtypes (["haxe";"lang"],"Enum")) );
   
+  InterfaceVarsDeleteModf.configure gen;
+  
   let dynamic_object = (get_cl (Hashtbl.find gen.gtypes (["haxe";"lang"],"DynamicObject")) ) in
   
   let object_iface = get_cl (Hashtbl.find gen.gtypes (["haxe";"lang"],"IHxObject")) in

+ 2 - 0
genjava.ml

@@ -1409,6 +1409,8 @@ let configure gen =
   
   EnumToClass.configure gen (None) false true (get_cl (Hashtbl.find gen.gtypes (["haxe";"lang"],"Enum")) );
   
+  InterfaceVarsDeleteModf.configure gen;
+  
   let dynamic_object = (get_cl (Hashtbl.find gen.gtypes (["haxe";"lang"],"DynamicObject")) ) in
   
   let object_iface = get_cl (Hashtbl.find gen.gtypes (["haxe";"lang"],"IHxObject")) in