소스 검색

prevent allocation of EnumValue for manual Type.enumIndex

Nicolas Cannasse 8 년 전
부모
커밋
0ab7dc2491
2개의 변경된 파일13개의 추가작업 그리고 6개의 파일을 삭제
  1. 12 5
      src/generators/genhl.ml
  2. 1 1
      std/hl/_std/Type.hx

+ 12 - 5
src/generators/genhl.ml

@@ -1378,6 +1378,13 @@ and make_string ctx s p =
 	op ctx (OSetField (s,1,reg_int ctx len));
 	s
 
+and get_enum_index ctx v =
+	let r = alloc_tmp ctx HI32 in
+	let re = eval_expr ctx v in
+	op ctx (ONullCheck re);
+	op ctx (OEnumIndex (r,re));
+	r
+
 and eval_var ctx v =
 	match captured_index ctx v with
 	| None -> alloc_var ctx v false
@@ -1858,11 +1865,7 @@ and eval_expr ctx e =
 				r
 			| _ -> abort "Constant string required" v.epos)
 		| "$enumIndex", [v] ->
-			let r = alloc_tmp ctx HI32 in
-			let re = eval_expr ctx v in
-			op ctx (ONullCheck re);
-			op ctx (OEnumIndex (r,re));
-			r
+			get_enum_index ctx v
 		| "$__mk_pos__", [{ eexpr = TConst (TString file) };min;max] ->
 			(* macros only - generated by reification *)
 			let rt = HAbstract ("macro_pos",alloc_string ctx "macro_pos") in
@@ -1878,6 +1881,10 @@ and eval_expr ctx e =
 			r
 		| _ ->
 			abort ("Unknown native call " ^ v.v_name) e.epos)
+	| TCall ({ eexpr = TField (_,FStatic ({ cl_path = [],"Type" },{ cf_name = "enumIndex" })) },[{ eexpr = TCast(v,_) }]) when (match follow v.etype with TEnum _ -> true | _ -> false) ->
+		get_enum_index ctx v
+	| TCall ({ eexpr = TField (_,FStatic ({ cl_path = [],"Type" },{ cf_name = "enumIndex" })) },[v]) when (match follow v.etype with TEnum _ -> true | _ -> false) ->
+		get_enum_index ctx v
 	| TCall (ec,args) ->
 		let tfun = real_type ctx ec in
 		let el() = eval_args ctx args tfun e.epos in

+ 1 - 1
std/hl/_std/Type.hx

@@ -237,7 +237,7 @@ class Type {
 		return cast hl.types.ArrayObj.alloc(arr);
 	}
 
-	@:extern public inline static function enumIndex( e : EnumValue ) : Int {
+	public static function enumIndex( e : EnumValue ) : Int {
 		return untyped $enumIndex(e);
 	}