Browse Source

drag more abstract information through XmlParser

Simon Krajewski 12 years ago
parent
commit
fca88c33b5
3 changed files with 22 additions and 16 deletions
  1. 5 3
      genxml.ml
  2. 3 2
      std/haxe/rtti/CType.hx
  3. 14 11
      std/haxe/rtti/XmlParser.hx

+ 5 - 3
genxml.ml

@@ -203,10 +203,12 @@ let rec gen_type_decl com pos t =
 	| TAbstractDecl a ->
 		let doc = gen_doc_opt a.a_doc in
 		let meta = gen_meta a.a_meta in
-		let sub = (match a.a_from with [] -> [] | l -> [node "from" [] (List.map (fun (t,_) -> gen_type t) l)]) in
-		let super = (match a.a_to with [] -> [] | l -> [node "to" [] (List.map (fun (t,_) -> gen_type t) l)]) in
+		let mk_cast (t,cfo) = node "icast" (match cfo with None -> [] | Some cf -> ["field",cf.cf_name]) [gen_type t] in
+		let sub = (match a.a_from with [] -> [] | l -> [node "from" [] (List.map mk_cast l)]) in
+		let super = (match a.a_to with [] -> [] | l -> [node "to" [] (List.map mk_cast l)]) in
 		let impl = (match a.a_impl with None -> [] | Some c -> [node "impl" [] [gen_type_decl com pos (TClassDecl c)]]) in
-		node "abstract" (gen_type_params pos a.a_private (tpath t) a.a_types a.a_pos m) (sub @ super @ doc @ meta @ impl)
+		let this = [node "this" [] [gen_type a.a_this]] in
+		node "abstract" (gen_type_params pos a.a_private (tpath t) a.a_types a.a_pos m) (sub @ this @ super @ doc @ meta @ impl)
 
 let att_str att =
 	String.concat "" (List.map (fun (a,v) -> Printf.sprintf " %s=\"%s\"" a v) att)

+ 3 - 2
std/haxe/rtti/CType.hx

@@ -109,9 +109,10 @@ typedef Typedef = {> TypeInfos,
 }
 
 typedef Abstractdef = {> TypeInfos,
-	var subs : Array<CType>;
-	var supers : Array<CType>;
+	var to : Array<{t:CType, field:Null<String>}>;
+	var from : Array<{t:CType, field:Null<String>}>;
 	var impl : Classdef;
+	var athis : CType;
 }
 
 enum TypeTree {

+ 14 - 11
std/haxe/rtti/XmlParser.hx

@@ -178,13 +178,13 @@ class XmlParser {
 	function mergeAbstracts( a : Abstractdef, a2 : Abstractdef ) {
 		if( curplatform == null )
 			return false;
-		if( a.subs.length != a2.subs.length || a.supers.length != a2.supers.length )
+		if( a.to.length != a2.to.length || a.from.length != a2.from.length )
 			return false;
-		for( i in 0...a.subs.length )
-			if( !TypeApi.typeEq(a.subs[i],a2.subs[i]) )
+		for( i in 0...a.to.length )
+			if( !TypeApi.typeEq(a.to[i].t,a2.to[i].t) )
 				return false;
-		for( i in 0...a.supers.length )
-			if( !TypeApi.typeEq(a.supers[i],a2.supers[i]) )
+		for( i in 0...a.from.length )
+			if( !TypeApi.typeEq(a.from[i].t,a2.from[i].t) )
 				return false;
 		if (a2.impl != null) mergeClasses(a.impl, a2.impl);
 		a.platforms.add(curplatform);
@@ -478,8 +478,8 @@ class XmlParser {
 	}
 
 	function xabstract( x : Fast ) : Abstractdef {
-		var doc = null, impl = null;
-		var meta = [], subs = [], supers = [];
+		var doc = null, impl = null, athis = null;
+		var meta = [], to = [], from = [];
 		for( c in x.elements )
 			switch( c.name ) {
 			case "haxe_doc":
@@ -488,12 +488,14 @@ class XmlParser {
 				meta = xmeta(c);
 			case "to":
 				for( t in c.elements )
-					subs.push(xtype(t));
+					to.push({t: xtype(new Fast(t.x.firstElement())), field: t.has.field ? t.att.field : null});
 			case "from":
 				for( t in c.elements )
-					supers.push(xtype(t));
+					from.push({t: xtype(new Fast(t.x.firstElement())), field: t.has.field ? t.att.field : null});
 			case "impl":
 				impl = xclass(c.node.resolve("class"));
+			case "this":
+				athis = xtype(new Fast(c.x.firstElement()));
 			default:
 				xerror(c);
 			}
@@ -506,8 +508,9 @@ class XmlParser {
 			params : mkTypeParams(x.att.params),
 			platforms : defplat(),
 			meta : meta,
-			subs : subs,
-			supers : supers,
+			athis : athis,
+			to : to,
+			from : from,
 			impl: impl
 		};
 	}