Browse Source

remove @:fakeEnum (#8189)

* remove @:fakeEnum

* error on @:fakeEnum enums
Dan Korostelev 6 years ago
parent
commit
a64246880e

+ 4 - 0
extra/CHANGES.txt

@@ -4,6 +4,10 @@
 
 	flash : updated Flash externs to version 32.0 (now using `final`, `enum abstract` and `haxe.extern.Rest`)
 
+	Removals:
+
+	all : remove support for `@:fakeEnum` enums
+
 2019-03-22: 4.0.0-rc.2
 
 	New features:

+ 1 - 6
src/codegen/genxml.ml

@@ -530,11 +530,6 @@ let generate_type com t =
 	| TEnumDecl e ->
 		print_meta e.e_meta;
 		p "extern enum %s {\n" (stype (TEnum(e,List.map snd e.e_params)));
-		let sort l =
-			let a = Array.of_list l in
-			Array.sort compare a;
-			Array.to_list a
-		in
 		List.iter (fun n ->
 			let c = PMap.find n e.e_constrs in
 			p "\t%s" c.ef_name;
@@ -542,7 +537,7 @@ let generate_type com t =
 			| TFun (args,_) -> p "(%s)" (String.concat ", " (List.map sparam (List.map (fun (a,o,t) -> a,(if o then Some (Ident "null") else None),t) args)))
 			| _ -> ());
 			p ";\n";
-		) (if Meta.has Meta.FakeEnum e.e_meta then sort e.e_names else e.e_names);
+		) e.e_names;
 		p "}\n"
 	| TTypeDecl t ->
 		print_meta t.t_meta;

+ 1 - 1
src/codegen/swfLoader.ml

@@ -366,7 +366,7 @@ let build_class com c file =
 		in
 		List.iter (function HExtends _ | HImplements _ -> raise Exit | _ -> ()) flags;
 		let constr = loop fields in
-		let name = "fakeEnum:" ^ String.concat "." (path.tpackage @ [path.tname]) in
+		let name = "enumAbstract:" ^ String.concat "." (path.tpackage @ [path.tname]) in
 		if not (Common.raw_defined com name) then raise Exit;
 		let native_path = s_type_path (path.tpackage, path.tname) in
 		let real_type = Option.get !real_type in

+ 0 - 2
src/core/meta.ml

@@ -45,7 +45,6 @@ type strict_meta =
 	| Exhaustive
 	| Expose
 	| Extern
-	| FakeEnum
 	| File
 	| FileXml
 	| Final
@@ -253,7 +252,6 @@ let get_info = function
 	| Exhaustive -> ":exhaustive",("",[UsedInternally])
 	| Expose -> ":expose",("Includes the class or field in Haxe exports",[HasParam "?Name=Class path";UsedOnEither [TClass;TClassField];Platforms [Js;Lua]])
 	| Extern -> ":extern",("Marks the field as extern so it is not generated",[UsedOn TClassField])
-	| FakeEnum -> ":fakeEnum",("Treat enum as collection of values of the specified type",[HasParam "Type name";UsedOn TEnum])
 	| File -> ":file",("Includes a given binary file into the target Swf and associates it with the class (must extend flash.utils.ByteArray)",[HasParam "File path";UsedOn TClass;Platform Flash])
 	| FileXml -> ":fileXml",("Include xml attribute snippet in Build.xml entry for file",[UsedOn TClass;Platform Cpp])
 	| Final -> ":final",("Prevents a class or interface from being extended or a method from being overriden",[UsedOnEither [TClass;TClassField]])

+ 1 - 16
src/generators/genas3.ml

@@ -277,22 +277,7 @@ let rec type_str ctx t p =
 		| [], "Bool" -> "Boolean"
 		| _ -> s_path ctx true a.a_path p)
 	| TEnum (e,_) ->
-		if e.e_extern then (match e.e_path with
-			| [], "Void" -> "void"
-			| [], "Bool" -> "Boolean"
-			| _ ->
-				let rec loop = function
-					| [] -> "Object"
-					| (Meta.FakeEnum,[Ast.EConst (Ast.Ident n),_],_) :: _ ->
-						(match n with
-						| "Int" -> "int"
-						| "UInt" -> "uint"
-						| _ -> n)
-					| _ :: l -> loop l
-				in
-				loop e.e_meta
-		) else
-			s_path ctx true e.e_path p
+		if e.e_extern then "Object" else s_path ctx true e.e_path p
 	| TInst ({ cl_path = ["flash"],"Vector" },[pt]) ->
 		(match pt with
 		| TInst({cl_kind = KTypeParameter _},_) -> "*"

+ 2 - 17
src/generators/genswf9.ml

@@ -239,12 +239,7 @@ let rec type_id ctx t =
 	| TEnum ({ e_path = ["flash"],"XmlType"; e_extern = true },_) ->
 		HMPath ([],"String")
 	| TEnum (e,_) ->
-		let rec loop = function
-			| [] -> type_path ctx e.e_path
-			| (Meta.FakeEnum,[Ast.EConst (Ast.Ident n),_],_) :: _ -> type_path ctx ([],n)
-			| _ :: l -> loop l
-		in
-		loop e.e_meta
+		type_path ctx e.e_path
 	| _ ->
 		HMPath ([],"Object")
 
@@ -271,17 +266,7 @@ let classify ctx t =
 	| TEnum ({ e_path = ["flash"],"XmlType"; e_extern = true },_) ->
 		KType (HMPath ([],"String"))
 	| TEnum (e,_) ->
-		let rec loop = function
-			| [] -> KType (type_id ctx t)
-			| (Meta.FakeEnum,[Ast.EConst (Ident n),_],_) :: _ ->
-				(match n with
-				| "Int" -> KInt
-				| "UInt" -> KUInt
-				| "String" -> KType (HMPath ([],"String"))
-				| _ -> assert false)
-			| _ :: l -> loop l
-		in
-		loop e.e_meta
+		KType (type_id ctx t)
 	| TAbstract ({ a_path = [],"UInt" },_) | TType ({ t_path = [],"UInt" },_) ->
 		KUInt
 	| TFun _ | TType ({ t_path = ["flash";"utils"],"Function" },[]) ->

+ 1 - 5
src/optimization/dce.ml

@@ -189,11 +189,7 @@ end
 
 let rec mark_enum dce e = if not (Meta.has Meta.Used e.e_meta) then begin
 	e.e_meta <- (Meta.Used,[],e.e_pos) :: e.e_meta;
-
-	(* do not generate has_enum feature for @:fakeEnum enums since they are not really enums *)
-	if not (Meta.has Meta.FakeEnum e.e_meta) then
-		check_and_add_feature dce "has_enum";
-
+	check_and_add_feature dce "has_enum";
 	check_feature dce (Printf.sprintf "%s.*" (s_type_path e.e_path));
 	PMap.iter (fun _ ef -> mark_t dce ef.ef_pos ef.ef_type) e.e_constrs;
 end

+ 4 - 12
src/typing/matcher.ml

@@ -112,10 +112,7 @@ module Constructor = struct
 		let p = pos con in
 		match fst con with
 		| ConEnum(en,ef) ->
-			if Meta.has Meta.FakeEnum en.e_meta then begin
-				let e_mt = TyperBase.type_module_type ctx (TEnumDecl en) None p in
- 				mk (TField(e_mt,FEnum(en,ef))) ef.ef_type p
- 			end else if match_debug then mk (TConst (TString ef.ef_name)) ctx.t.tstring p
+			if match_debug then mk (TConst (TString ef.ef_name)) ctx.t.tstring p
 			else mk (TConst (TInt (Int32.of_int ef.ef_index))) ctx.t.tint p
 		| ConConst ct -> make_const_texpr ctx.com.basic ct p
 		| ConArray i -> make_int ctx.com.basic i p
@@ -1200,7 +1197,6 @@ module TexprConverter = struct
 	type match_kind =
 		| SKValue
 		| SKEnum
-		| SKFakeEnum
 		| SKLength
 
 	exception Not_exhaustive
@@ -1230,7 +1226,6 @@ module TexprConverter = struct
 	let s_match_kind = function
 		| SKValue -> "value"
 		| SKEnum -> "enum"
-		| SKFakeEnum -> "fakeEnum"
 		| SKLength -> "length"
 
 	let unify_constructor ctx params t con =
@@ -1314,10 +1309,7 @@ module TexprConverter = struct
 				SKLength,Infinite
 			| TEnum(en,pl) ->
 				PMap.iter (fun _ ef -> add (ConEnum(en,ef),null_pos)) en.e_constrs;
-				if Meta.has Meta.FakeEnum en.e_meta then
-					SKFakeEnum,CompileTimeFinite
-				else
-					SKEnum,RunTimeFinite
+				SKEnum,RunTimeFinite
 			| TAnon _ ->
 				SKValue,CompileTimeFinite
 			| TInst(_,_) ->
@@ -1327,7 +1319,7 @@ module TexprConverter = struct
 		in
 		let kind,finiteness = loop t in
 		let compatible_kind con = match fst con with
-			| ConEnum _ -> kind = SKEnum || kind = SKFakeEnum
+			| ConEnum _ -> kind = SKEnum
 			| ConArray _ -> kind = SKLength
 			| _ -> kind = SKValue
 		in
@@ -1435,7 +1427,7 @@ module TexprConverter = struct
 							end
 						) cases in
 						let e_subject = match kind with
-							| SKValue | SKFakeEnum -> e_subject
+							| SKValue -> e_subject
 							| SKEnum -> if match_debug then mk_name_call e_subject else mk_index_call e_subject
 							| SKLength -> type_field_access ctx e_subject "length"
 						in

+ 1 - 0
src/typing/typeloadModule.ml

@@ -228,6 +228,7 @@ let module_pass_1 ctx m tdecls loadp =
 			pt := Some p;
 			let priv = List.mem EPrivate d.d_flags in
 			let path = make_path name priv in
+			if Meta.has (Meta.Custom ":fakeEnum") d.d_meta then error "@:fakeEnum enums is no longer supported in Haxe 4, use extern enum abstract instead" p;
 			let e = {
 				e_path = path;
 				e_module = m;

+ 1 - 1
std/haxe/macro/Compiler.hx

@@ -343,7 +343,7 @@ class Compiler {
 					continue;
 				}
 				if( StringTools.startsWith(r, "enum ") ) {
-					define("fakeEnum:" + r.substr(5));
+					define("enumAbstract:" + r.substr(5));
 					continue;
 				}
 				var rp = r.split(" : ");