Pārlūkot izejas kodu

store features in modules, then commit them to common context before generation (see #3787)

Simon Krajewski 10 gadi atpakaļ
vecāks
revīzija
afe2d0bf5a
3 mainītis faili ar 17 papildinājumiem un 6 dzēšanām
  1. 5 2
      dce.ml
  2. 10 4
      filters.ml
  3. 2 0
      type.ml

+ 5 - 2
dce.ml

@@ -30,6 +30,7 @@ type dce = {
 	std_dirs : string list;
 	debug : bool;
 	follow_expr : dce -> texpr -> unit;
+	mutable curclass : tclass;
 	mutable added_fields : (tclass * tclass_field * bool) list;
 	mutable marked_fields : tclass_field list;
 	mutable marked_maybe_fields : tclass_field list;
@@ -321,7 +322,7 @@ and expr dce e =
 			mark_t dce e.epos v.v_type;
 		) vl;
 	| TCall ({eexpr = TLocal ({v_name = "__define_feature__"})},[{eexpr = TConst (TString ft)};e]) ->
-		Common.add_feature dce.com ft;
+		Hashtbl.replace dce.curclass.cl_module.m_extra.m_features ft true;
 		check_feature dce ft;
 		expr dce e
 	(* keep toString method when the class is argument to Std.string or haxe.Log.trace *)
@@ -416,6 +417,7 @@ let run com main full =
 		t_stack = [];
 		ts_stack = [];
 		features = Hashtbl.create 0;
+		curclass = null_class;
 	} in
 	begin match main with
 		| Some {eexpr = TCall({eexpr = TField(e,(FStatic(c,cf)))},_)} ->
@@ -477,7 +479,8 @@ let run com main full =
 				mark_t dce cf.cf_pos cf.cf_type
 			) cfl;
 			(* follow expressions to new types/fields *)
-			List.iter (fun (_,cf,_) ->
+			List.iter (fun (c,cf,_) ->
+				dce.curclass <- c;
 				opt (expr dce) cf.cf_expr;
 				List.iter (fun cf -> if cf.cf_expr <> None then opt (expr dce) cf.cf_expr) cf.cf_overloads
 			) cfl;

+ 10 - 4
filters.ml

@@ -681,10 +681,10 @@ let rename_local_vars ctx e =
 	loop e;
 	e
 
-let check_unification com e t =
+let check_unification ctx e t =
 	begin match follow e.etype,follow t with
 		| TEnum _,TDynamic _ ->
-			add_feature com "may_print_enum";
+			Hashtbl.replace ctx.curclass.cl_module.m_extra.m_features "may_print_enum" true;
 		| _ ->
 			()
 	end;
@@ -970,6 +970,11 @@ let promote_first_interface_to_super ctx t = match t with
 	| _ ->
 		()
 
+let commit_features ctx t =
+	let m = (t_infos t).mt_module in
+	Hashtbl.iter (fun k v ->
+		Common.add_feature ctx.com k;
+	) m.m_extra.m_features
 
 (* PASS 3 end *)
 
@@ -1044,7 +1049,7 @@ let run com tctx main =
 	if use_static_analyzer then begin
 		(* PASS 1: general expression filters *)
 		let filters = [
-			Codegen.UnificationCallback.run (check_unification com);
+			Codegen.UnificationCallback.run (check_unification tctx);
 			Codegen.AbstractCast.handle_abstract_casts tctx;
 			Optimizer.inline_constructors tctx;
 			Optimizer.reduce_expression tctx;
@@ -1063,7 +1068,7 @@ let run com tctx main =
 	end else begin
 		(* PASS 1: general expression filters *)
 		let filters = [
-			Codegen.UnificationCallback.run (check_unification com);
+			Codegen.UnificationCallback.run (check_unification tctx);
 			Codegen.AbstractCast.handle_abstract_casts tctx;
 			blockify_ast;
 			( if (Common.defined com Define.NoSimplify) || (Common.defined com Define.Cppia) ||
@@ -1132,5 +1137,6 @@ let run com tctx main =
 		add_meta_field;
 		check_void_field;
 		(match com.platform with | Cpp -> promote_first_interface_to_super | _ -> (fun _ _ -> ()) );
+		commit_features;
 	] in
 	List.iter (fun t -> List.iter (fun f -> f tctx t) type_filters) com.types

+ 2 - 0
type.ml

@@ -291,6 +291,7 @@ and module_def_extra = {
 	mutable m_binded_res : (string, string) PMap.t;
 	mutable m_macro_calls : string list;
 	mutable m_if_feature : (string *(tclass * tclass_field * bool)) list;
+	mutable m_features : (string,bool) Hashtbl.t;
 }
 
 and module_kind =
@@ -390,6 +391,7 @@ let module_extra file sign time kind =
 		m_binded_res = PMap.empty;
 		m_macro_calls = [];
 		m_if_feature = [];
+		m_features = Hashtbl.create 0;
 	}