Ver Fonte

allow feature DCE on all platforms and rename @:feature to @:ifFeature

Simon Krajewski há 13 anos atrás
pai
commit
539bf889ba
6 ficheiros alterados com 19 adições e 10 exclusões
  1. 12 4
      dce.ml
  2. 1 1
      std/flash8/_std/Std.hx
  3. 3 3
      std/js/Boot.hx
  4. 1 1
      std/neko/Boot.hx
  5. 1 1
      std/neko/_std/Std.hx
  6. 1 0
      std/php/_std/Xml.hx

+ 12 - 4
dce.ml

@@ -70,15 +70,23 @@ let keep_whole_class dce c =
 		| { cl_path = [],"Array" } -> not (dce.com.platform = Js)
 		| _ -> false)
 
+(* check if a metadata contains @:ifFeature with a used feature argument *)
+let has_used_feature com meta =
+	try
+		let _,el,_ = get_meta ":ifFeature" meta in
+		List.exists (fun e -> match fst e with
+			| EConst(String s) when Common.has_feature com s -> true
+			| _ -> false
+		) el
+	with Not_found ->
+		false
+
 (* check if a field is kept *)
 let keep_field dce cf =
 	has_meta ":keep" cf.cf_meta
 	|| has_meta ":used" cf.cf_meta
 	|| cf.cf_name = "__init__"
-	|| dce.com.platform = Js && (try (match get_meta ":feature" cf.cf_meta with
-			| (_,[EConst(String s),_],_) -> Common.has_feature dce.com s
-			| _ -> raise Not_found)
-		with Not_found -> false)
+	|| has_used_feature dce.com cf.cf_meta
 
 (* marking *)
 

+ 1 - 1
std/flash8/_std/Std.hx

@@ -25,7 +25,7 @@
 
 @:coreApi class Std {
 
-	@:feature("typed_cast")
+	@:ifFeature("typed_cast")
 	public static function is( v : Dynamic, t : Dynamic ) : Bool {
 		return untyped flash.Boot.__instanceof(v,t);
 	}

+ 3 - 3
std/js/Boot.hx

@@ -71,7 +71,7 @@ class Boot {
 		return untyped __define_feature__("js.Boot.getClass", o.__class__);
 	}
 
-	@:feature("has_enum")
+	@:ifFeature("has_enum")
 	private static function __string_rec(o,s:String) {
 		untyped {
 			if( o == null )
@@ -159,7 +159,7 @@ class Boot {
 		return __interfLoop(cc.__super__,cl);
 	}
 
-	@:feature("typed_catch") private static function __instanceof(o : Dynamic,cl) {
+	@:ifFeature("typed_catch") private static function __instanceof(o : Dynamic,cl) {
 		untyped {
 			try {
 				if( __js__("o instanceof cl") ) {
@@ -195,7 +195,7 @@ class Boot {
 		}
 	}
 
-	@:feature("typed_cast") private static function __cast(o : Dynamic, t : Dynamic) {
+	@:ifFeature("typed_cast") private static function __cast(o : Dynamic, t : Dynamic) {
 		if (__instanceof(o, t)) return o;
 		else throw "Cannot cast " +Std.string(o) + " to " +Std.string(t);
 	}

+ 1 - 1
std/neko/Boot.hx

@@ -68,7 +68,7 @@ class Boot {
 		return __interfLoop(cc.__super__,cl);
 	}
 
-	@:feature("typed_catch")
+	@:ifFeature("typed_catch")
 	private static function __instanceof(o,cl) {
 		untyped {
 			if( cl == Dynamic )

+ 1 - 1
std/neko/_std/Std.hx

@@ -25,7 +25,7 @@
 
 @:coreApi class Std {
 
-	@:feature("typed_cast")
+	@:ifFeature("typed_cast")
 	public static function is( v : Dynamic, t : Dynamic ) : Bool {
 		return untyped neko.Boot.__instanceof(v,t);
 	}

+ 1 - 0
std/php/_std/Xml.hx

@@ -221,6 +221,7 @@ enum XmlType {
 	}
 
 	// TODO: check correct transform function
+	@:ifFeature("Xml.parse")
 	public function set( att : String, value : String ) : Void {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";