Browse Source

[comp-server] Merge changes from compserver branch. See #3350

Cauê Waneck 10 years ago
parent
commit
ca3a08430f
4 changed files with 48 additions and 22 deletions
  1. 33 13
      filters.ml
  2. 13 7
      gencommon.ml
  3. 1 1
      gencs.ml
  4. 1 1
      genjava.ml

+ 33 - 13
filters.ml

@@ -703,24 +703,44 @@ let check_unification ctx e t =
 (* Saves a class state so it can be restored later, e.g. after DCE or native path rewrite *)
 let save_class_state ctx t = match t with
 	| TClassDecl c ->
-		let meta = c.cl_meta and path = c.cl_path and ext = c.cl_extern in
-		let fl = c.cl_fields and ofl = c.cl_ordered_fields and st = c.cl_statics and ost = c.cl_ordered_statics in
-		let cst = c.cl_constructor and over = c.cl_overrides in
-		let oflk = List.map (fun f -> f.cf_kind,f.cf_expr,f.cf_type) ofl in
-		let ostk = List.map (fun f -> f.cf_kind,f.cf_expr,f.cf_type) ost in
+		let mk_field_restore f =
+			let rec mk_overload_restore f =
+				f.cf_kind,f.cf_expr,f.cf_type,f.cf_meta
+			in
+			( f,mk_overload_restore f, List.map (fun f -> f,mk_overload_restore f) f.cf_overloads )
+		in
+		let restore_field (f,res,overloads) =
+			let restore_field (f,(kind,expr,t,meta)) =
+				f.cf_kind <- kind; f.cf_expr <- expr; f.cf_type <- t; f.cf_meta <- meta;
+				f
+			in
+			let f = restore_field (f,res) in
+			f.cf_overloads <- List.map restore_field overloads;
+			f
+		in
+		let mk_pmap lst =
+			List.fold_left (fun pmap f -> PMap.add f.cf_name f pmap) PMap.empty lst
+		in
+
+		let meta = c.cl_meta and path = c.cl_path and ext = c.cl_extern and over = c.cl_overrides in
+		let sup = c.cl_super and impl = c.cl_implements in
+		let csr = Option.map (mk_field_restore) c.cl_constructor in
+		let ofr = List.map (mk_field_restore) c.cl_ordered_fields in
+		let osr = List.map (mk_field_restore) c.cl_ordered_statics in
+		let init = c.cl_init in
 		c.cl_restore <- (fun() ->
+			c.cl_super <- sup;
+			c.cl_implements <- impl;
 			c.cl_meta <- meta;
 			c.cl_extern <- ext;
 			c.cl_path <- path;
-			c.cl_fields <- fl;
-			c.cl_ordered_fields <- ofl;
-			c.cl_statics <- st;
-			c.cl_ordered_statics <- ost;
-			c.cl_constructor <- cst;
+			c.cl_init <- init;
+			c.cl_ordered_fields <- List.map restore_field ofr;
+			c.cl_ordered_statics <- List.map restore_field osr;
+			c.cl_fields <- mk_pmap c.cl_ordered_fields;
+			c.cl_statics <- mk_pmap c.cl_ordered_statics;
+			c.cl_constructor <- Option.map restore_field csr;
 			c.cl_overrides <- over;
-			(* DCE might modify the cf_kind, so let's restore it as well *)
-			List.iter2 (fun f (k,e,t) -> f.cf_kind <- k; f.cf_expr <- e; f.cf_type <- t;) ofl oflk;
-			List.iter2 (fun f (k,e,t) -> f.cf_kind <- k; f.cf_expr <- e; f.cf_type <- t;) ost ostk;
 		)
 	| _ ->
 		()

+ 13 - 7
gencommon.ml

@@ -107,6 +107,10 @@ let follow_once t =
 
 let t_empty = TAnon({ a_fields = PMap.empty; a_status = ref (Closed) })
 
+let tmp_count = ref 0
+
+let reset_temps () = tmp_count := 0
+
 (* the undefined is a special var that works like null, but can have special meaning *)
 let v_undefined = alloc_var "__undefined__" t_dynamic
 
@@ -827,6 +831,7 @@ let run_filters_from gen t filters =
 
 				gen.gcurrent_classfield <- None;
 				let rec process_field f =
+					reset_temps();
 					gen.gcurrent_classfield <- Some(f);
 					List.iter (fun fn -> fn()) gen.gon_classfield_start;
 
@@ -840,10 +845,10 @@ let run_filters_from gen t filters =
 				List.iter process_field c.cl_ordered_fields;
 				List.iter process_field c.cl_ordered_statics;
 
-				gen.gcurrent_classfield <- None;
 				(match c.cl_constructor with
 				| None -> ()
 				| Some f -> process_field f);
+				gen.gcurrent_classfield <- None;
 				(match c.cl_init with
 				| None -> ()
 				| Some e ->
@@ -858,7 +863,7 @@ let run_filters gen =
 	gen.gcon.error <- (fun msg pos -> has_errors := true; last_error msg pos);
 	(* first of all, we have to make sure that the filters won't trigger a major Gc collection *)
 	let t = Common.timer "gencommon_filters" in
-	(if Common.defined gen.gcon Define.GencommonDebug then debug_mode := true);
+	(if Common.defined gen.gcon Define.GencommonDebug then debug_mode := true else debug_mode := false);
 	let run_filters filter =
 		let rec loop acc mds =
 			match mds with
@@ -1179,7 +1184,6 @@ let mk_paren e =
 	match e.eexpr with | TParenthesis _ -> e | _ -> { e with eexpr=TParenthesis(e) }
 
 (* private *)
-let tmp_count = ref 0
 
 let get_real_fun gen t =
 	match follow t with
@@ -1211,8 +1215,6 @@ let ensure_local gen block name e =
 			block := { e with eexpr = TVar(var, Some e); etype = gen.gcon.basic.tvoid; } :: !block;
 			{ e with eexpr = TLocal var }
 
-let reset_temps () = tmp_count := 0
-
 let follow_module follow_func md = match md with
 	| TClassDecl _
 	| TEnumDecl _
@@ -6575,7 +6577,12 @@ struct
 					let et = e.etype in
 					let base_type = match follow et with
 						| TInst({ cl_path = ([], "Array") } as cl, bt) -> gen.greal_type_param (TClassDecl cl) bt
-						| _ -> assert false
+						| _ ->
+							gen.gcon.warning (debug_type et) e.epos;
+							(match gen.gcurrent_class with
+								| Some cl -> print_endline (path_s cl.cl_path)
+								| _ -> ());
+							assert false
 					in
 					let base_type = List.hd base_type in
 					{ e with eexpr = TArrayDecl( List.map (fun e -> handle (run e) base_type e.etype) el ); etype = et }
@@ -9121,7 +9128,6 @@ struct
 
 			cl.cl_super <- Some(super,[]);
 			cl.cl_extern <- en.e_extern;
-			en.e_extern <- true;
 			en.e_meta <- (Meta.Class, [], pos) :: en.e_meta;
 			cl.cl_module <- en.e_module;
 			cl.cl_meta <- ( Meta.Enum, [], pos ) :: cl.cl_meta;

+ 1 - 1
gencs.ml

@@ -2591,7 +2591,7 @@ let configure gen =
 				end;
 				(not cl.cl_extern)
 			| TEnumDecl e ->
-				if not e.e_extern then begin
+				if not e.e_extern && not (Meta.has Meta.Class e.e_meta) then begin
 					(if no_root && len w = 0 then write w "using haxe.root;\n"; newline w;);
 					gen_enum w e;
 					newline w;

+ 1 - 1
genjava.ml

@@ -2004,7 +2004,7 @@ let configure gen =
 				end;
 				(not cl.cl_extern)
 			| TEnumDecl e ->
-				if not e.e_extern then begin
+				if not e.e_extern && not (Meta.has Meta.Class e.e_meta) then begin
 					gen_enum w e;
 					newline w;
 					newline w