Browse Source

added support for platform-dependent typedef

Nicolas Cannasse 18 years ago
parent
commit
84148a86b9
3 changed files with 47 additions and 15 deletions
  1. 9 8
      std/haxe/rtti/Type.hx
  2. 7 3
      std/haxe/rtti/XmlParser.hx
  3. 31 4
      std/tools/haxedoc/HtmlPrinter.hx

+ 9 - 8
std/haxe/rtti/Type.hx

@@ -73,6 +73,7 @@ typedef Enum = {> TypeInfos,
 
 
 typedef Typedef = {> TypeInfos,
 typedef Typedef = {> TypeInfos,
 	var type : Type;
 	var type : Type;
+	var types : Hash<Type>; // by platform
 }
 }
 
 
 enum TypeTree {
 enum TypeTree {
@@ -85,7 +86,7 @@ enum TypeTree {
 typedef TypeRoot = Array<TypeTree>
 typedef TypeRoot = Array<TypeTree>
 
 
 class TypeApi {
 class TypeApi {
-	
+
 	public static function typeInfos( t : TypeTree ) : TypeInfos {
 	public static function typeInfos( t : TypeTree ) : TypeInfos {
 		var inf : TypeInfos;
 		var inf : TypeInfos;
 		switch( t ) {
 		switch( t ) {
@@ -96,14 +97,14 @@ class TypeApi {
 		}
 		}
 		return inf;
 		return inf;
 	}
 	}
-	
+
 	public static function isVar( t : Type ) {
 	public static function isVar( t : Type ) {
 		return switch( t ) {
 		return switch( t ) {
 		case TFunction(_,_): false;
 		case TFunction(_,_): false;
 		default: true;
 		default: true;
 		}
 		}
 	}
 	}
-	
+
 	static function leq<T>( f : T -> T -> Bool, l1 : List<T>, l2 : List<T> ) {
 	static function leq<T>( f : T -> T -> Bool, l1 : List<T>, l2 : List<T> ) {
 		var it = l2.iterator();
 		var it = l2.iterator();
 		for( e1 in l1 ) {
 		for( e1 in l1 ) {
@@ -117,7 +118,7 @@ class TypeApi {
 			return false;
 			return false;
 		return true;
 		return true;
 	}
 	}
-	
+
 	public static function rightsEq( r1 : Rights, r2 : Rights ) {
 	public static function rightsEq( r1 : Rights, r2 : Rights ) {
 		if( r1 == r2 )
 		if( r1 == r2 )
 			return true;
 			return true;
@@ -132,7 +133,7 @@ class TypeApi {
 		}
 		}
 		return false;
 		return false;
 	}
 	}
-	
+
 	public static function typeEq( t1 : Type, t2 : Type ) {
 	public static function typeEq( t1 : Type, t2 : Type ) {
 		switch( t1 ) {
 		switch( t1 ) {
 		case TUnknown: return t2 == TUnknown;
 		case TUnknown: return t2 == TUnknown;
@@ -181,7 +182,7 @@ class TypeApi {
 		}
 		}
 		return false;
 		return false;
 	}
 	}
-	
+
 	public static function fieldEq( f1 : ClassField, f2 : ClassField ) {
 	public static function fieldEq( f1 : ClassField, f2 : ClassField ) {
 		if( f1.name != f2.name )
 		if( f1.name != f2.name )
 			return false;
 			return false;
@@ -201,7 +202,7 @@ class TypeApi {
 			return false;
 			return false;
 		return true;
 		return true;
 	}
 	}
-	
+
 	public static function constructorEq( c1 : EnumField, c2: EnumField ) {
 	public static function constructorEq( c1 : EnumField, c2: EnumField ) {
 		if( c1.name != c2.name )
 		if( c1.name != c2.name )
 			return false;
 			return false;
@@ -213,5 +214,5 @@ class TypeApi {
 			return false;
 			return false;
 		return true;
 		return true;
 	}
 	}
-	
+
 }
 }

+ 7 - 3
std/haxe/rtti/XmlParser.hx

@@ -117,10 +117,10 @@ class XmlParser {
 	}
 	}
 
 
 	function mergeTypedefs( t : Typedef, t2 : Typedef ) {
 	function mergeTypedefs( t : Typedef, t2 : Typedef ) {
-		if( !TypeApi.typeEq(t.type,t2.type) )
+		if( curplatform == null )
 			return false;
 			return false;
-		if( curplatform != null )
-			t.platforms.add(curplatform);
+		t.platforms.add(curplatform);
+		t.types.set(curplatform,t2.type);
 		return true;
 		return true;
 	}
 	}
 
 
@@ -351,6 +351,9 @@ class XmlParser {
 				doc = c.innerData;
 				doc = c.innerData;
 			else
 			else
 				t = xtype(c);
 				t = xtype(c);
+		var types = new Hash();
+		if( curplatform != null )
+			types.set(curplatform,t);
 		return {
 		return {
 			path : mkPath(x.att.path),
 			path : mkPath(x.att.path),
 			module : if( x.has.module ) mkPath(x.att.module) else null,
 			module : if( x.has.module ) mkPath(x.att.module) else null,
@@ -358,6 +361,7 @@ class XmlParser {
 			isPrivate : x.x.exists("private"),
 			isPrivate : x.x.exists("private"),
 			params : mkTypeParams(x.att.params),
 			params : mkTypeParams(x.att.params),
 			type : t,
 			type : t,
+			types : types,
 			platforms : defplat(),
 			platforms : defplat(),
 		};
 		};
 	}
 	}

+ 31 - 4
std/tools/haxedoc/HtmlPrinter.hx

@@ -336,11 +336,33 @@ class HtmlPrinter {
 		}
 		}
 		print('</div>');
 		print('</div>');
 		processInfos(t);
 		processInfos(t);
-		switch( t.type ) {
+		if( t.platforms.length == 0 ) {
+			processTypedefType(t.type,t.platforms,t.platforms);
+			return;
+		}
+		var platforms = new List();
+		for( p in t.platforms )
+			platforms.add(p);
+		for( p in t.types.keys() ) {
+			var td = t.types.get(p);
+			var support = new List();
+			for( p2 in platforms )
+				if( TypeApi.typeEq(td,t.types.get(p2)) ) {
+					platforms.remove(p2);
+					support.add(p2);
+				}
+			if( support.length == 0 )
+				continue;
+			processTypedefType(td,t.platforms,support);
+		}
+	}
+
+	function processTypedefType(t,all,platforms) {
+		switch( t ) {
 		case TAnonymous(fields):
 		case TAnonymous(fields):
 			print('<dl>');
 			print('<dl>');
 			for( f in fields ) {
 			for( f in fields ) {
-				processClassField(t.platforms,{
+				processClassField(all,{
 					name : f.name,
 					name : f.name,
 					type : f.t,
 					type : f.t,
 					isPublic : true,
 					isPublic : true,
@@ -348,13 +370,18 @@ class HtmlPrinter {
 					get : RNormal,
 					get : RNormal,
 					set : RNormal,
 					set : RNormal,
 					params : null,
 					params : null,
-					platforms : t.platforms,
+					platforms : platforms,
 				},false);
 				},false);
 			}
 			}
 			print('</dl>');
 			print('</dl>');
 		default:
 		default:
+			if( all.length != platforms.length ) {
+				print('<div class="platforms">Defined in ');
+				display(platforms,output,", ");
+				print('</div>');
+			}
 			print('<div class="typedef">= ');
 			print('<div class="typedef">= ');
-			processType(t.type);
+			processType(t);
 			print('</div>');
 			print('</div>');
 		}
 		}
 	}
 	}