Browse Source

added @:generic and @:rttiInfos, give errors on corresponding implementations when -D haxe3 is set

Simon Krajewski 13 years ago
parent
commit
849e73cee1
3 changed files with 29 additions and 11 deletions
  1. 20 9
      codegen.ml
  2. 8 2
      std/haxe/FastList.hx
  3. 1 0
      typeload.ml

+ 20 - 9
codegen.ml

@@ -217,7 +217,7 @@ let rec build_generic ctx c p tl =
 		let path = (match follow t with
 		let path = (match follow t with
 			| TInst (c,_) -> c.cl_path
 			| TInst (c,_) -> c.cl_path
 			| TEnum (e,_) -> e.e_path
 			| TEnum (e,_) -> e.e_path
-			| TMono _ -> error "Type parameter must be explicit when creating a haxe.rtti.Generic instance" p
+			| TMono _ -> error "Type parameter must be explicit when creating a generic instance" p
 			| _ -> error "Type parameter must be a class or enum instance" p
 			| _ -> error "Type parameter must be a class or enum instance" p
 		) in
 		) in
 		match path with
 		match path with
@@ -291,7 +291,7 @@ let rec build_generic ctx c p tl =
 		cg.cl_constructor <- (match c.cl_constructor, c.cl_super with
 		cg.cl_constructor <- (match c.cl_constructor, c.cl_super with
 			| None, None -> None
 			| None, None -> None
 			| Some c, _ -> Some (build_field c)
 			| Some c, _ -> Some (build_field c)
-			| _ -> error "Please define a constructor for this class in order to use haxe.rtti.Generic" c.cl_pos
+			| _ -> error "Please define a constructor for this class in order to use it as generic" c.cl_pos
 		);
 		);
 		cg.cl_implements <- List.map (fun (i,tl) ->
 		cg.cl_implements <- List.map (fun (i,tl) ->
 			(match follow (build_type (TInst (i, List.map build_type tl))) with
 			(match follow (build_type (TInst (i, List.map build_type tl))) with
@@ -468,6 +468,7 @@ let on_inherit ctx c p h =
 		extend_remoting ctx c t p true false;
 		extend_remoting ctx c t p true false;
 		false
 		false
 	| HImplements { tpackage = ["haxe";"rtti"]; tname = "Generic"; tparams = [] } ->
 	| HImplements { tpackage = ["haxe";"rtti"]; tname = "Generic"; tparams = [] } ->
+		if Common.defined ctx.com "haxe3" then error ("Implementing haxe.rtti.Generic is deprecated in haxe 3, please use @:generic instead") c.cl_pos;
 		if c.cl_types <> [] then c.cl_kind <- KGeneric;
 		if c.cl_types <> [] then c.cl_kind <- KGeneric;
 		false
 		false
 	| HExtends { tpackage = ["haxe";"xml"]; tname = "Proxy"; tparams = [TPExpr(EConst (String file),p);TPType t] } ->
 	| HExtends { tpackage = ["haxe";"xml"]; tname = "Proxy"; tparams = [TPExpr(EConst (String file),p);TPType t] } ->
@@ -558,12 +559,22 @@ let add_field_inits com c =
 			| _ ->
 			| _ ->
 				assert false
 				assert false
 
 
-let rec has_rtti c =
-	List.exists (function (t,pl) ->
-		match t, pl with
-		| { cl_path = ["haxe";"rtti"],"Infos" },[] -> true
-		| _ -> false
-	) c.cl_implements || (match c.cl_super with None -> false | Some (c,_) -> has_rtti c)
+let has_rtti ctx c =
+	let rec has_rtti_new c = 
+		has_meta ":rttiInfos" c.cl_meta || match c.cl_super with None -> false | Some (csup,_) -> has_rtti_new csup
+	in
+	let rec has_rtti_old c =
+		List.exists (function (t,pl) ->
+			match t, pl with
+			| { cl_path = ["haxe";"rtti"],"Infos" },[] -> true
+			| _ -> false
+		) c.cl_implements || (match c.cl_super with None -> false | Some (c,_) -> has_rtti_old c)
+	in
+	if Common.defined ctx.com "haxe3" then begin
+		if has_rtti_old c then error ("Implementing haxe.rtti.Infos is deprecated in haxe 3, please use @:rttiInfos instead") c.cl_pos;
+		has_rtti_new c
+	end else
+		has_rtti_old c || has_rtti_new c
 
 
 let restore c =
 let restore c =
 	let meta = c.cl_meta and path = c.cl_path and ext = c.cl_extern in
 	let meta = c.cl_meta and path = c.cl_path and ext = c.cl_extern in
@@ -593,7 +604,7 @@ let on_generate ctx t =
 				c.cl_path <- parse_path name;
 				c.cl_path <- parse_path name;
 			| _ -> ()
 			| _ -> ()
 		) c.cl_meta;
 		) c.cl_meta;
-		if has_rtti c && not (PMap.mem "__rtti" c.cl_statics) then begin
+		if has_rtti ctx c && not (PMap.mem "__rtti" c.cl_statics) then begin
 			let f = mk_field "__rtti" ctx.t.tstring c.cl_pos in
 			let f = mk_field "__rtti" ctx.t.tstring c.cl_pos in
 			let str = Genxml.gen_type_string ctx.com t in
 			let str = Genxml.gen_type_string ctx.com t in
 			f.cf_expr <- Some (mk (TConst (TString str)) f.cf_type c.cl_pos);
 			f.cf_expr <- Some (mk (TConst (TString str)) f.cf_type c.cl_pos);

+ 8 - 2
std/haxe/FastList.hx

@@ -31,7 +31,10 @@ class FastCell<T> #if (flash9 || cpp) implements haxe.rtti.Generic #end {
 }
 }
 
 
 #if cpp
 #if cpp
-private class FastListIterator<T> extends cpp.FastIterator<T>, implements haxe.rtti.Generic {
+#if haxe3
+@:generic
+#end
+private class FastListIterator<T> extends cpp.FastIterator<T>#if !haxe3 , implements haxe.rtti.Generic #end {
 	public var current : FastCell<T>;
 	public var current : FastCell<T>;
 	override public function hasNext():Bool { return current!=null; }
 	override public function hasNext():Bool { return current!=null; }
 	override public function next():T { var result = current.elt; current = current.next; return result; }
 	override public function next():T { var result = current.elt; current = current.next; return result; }
@@ -44,7 +47,10 @@ private class FastListIterator<T> extends cpp.FastIterator<T>, implements haxe.r
 /**
 /**
 	A linked-list of elements. A different class is created for each container used in platforms where it matters
 	A linked-list of elements. A different class is created for each container used in platforms where it matters
 **/
 **/
-class FastList<T> #if (flash9 || cpp) implements haxe.rtti.Generic #end {
+#if haxe3 && (flash9 || cpp)
+@:generic
+#end
+class FastList<T> #if !haxe3 && (flash9 || cpp) implements haxe.rtti.Generic #end {
 
 
 	public var head : FastCell<T>;
 	public var head : FastCell<T>;
 
 

+ 1 - 0
typeload.ml

@@ -853,6 +853,7 @@ let init_class ctx c p herits fields =
 	let ctx = { ctx with type_params = c.cl_types } in
 	let ctx = { ctx with type_params = c.cl_types } in
 	c.cl_extern <- List.mem HExtern herits;
 	c.cl_extern <- List.mem HExtern herits;
 	c.cl_interface <- List.mem HInterface herits;
 	c.cl_interface <- List.mem HInterface herits;
+	if has_meta ":generic" c.cl_meta && c.cl_types <> [] then c.cl_kind <- KGeneric;
 	if c.cl_path = (["haxe";"macro"],"MacroType") then c.cl_kind <- KMacroType;
 	if c.cl_path = (["haxe";"macro"],"MacroType") then c.cl_kind <- KMacroType;
 	set_heritance ctx c herits p;
 	set_heritance ctx c herits p;
 	let fields = ref fields in
 	let fields = ref fields in