Переглянути джерело

[java/cs] requested changes to java/c# : @:core_api on Array and Date; standardized Xml enum

Caue Waneck 13 роки тому
батько
коміт
db247b557b

+ 1 - 1
genjava.ml

@@ -1495,7 +1495,7 @@ let configure gen =
   let rcf_static_find = mk_static_field_access_infer (get_cl (get_type gen (["haxe";"lang"], "FieldLookup"))) "findHash" Ast.null_pos [] in
   (*let rcf_static_lookup = mk_static_field_access_infer (get_cl (get_type gen (["haxe";"lang"], "FieldLookup"))) "lookupHash" Ast.null_pos [] in*)
   
-  let can_be_float t = match follow t with
+  let can_be_float t = match follow (real_type t) with
     | TInst({ cl_path = (["haxe"], "Int32")}, [] )
     | TInst({ cl_path = ([], "Int") }, []) 
     | TInst({ cl_path = ([], "Float") }, []) -> true

+ 14 - 2
std/cs/Lib.hx

@@ -3,9 +3,8 @@ import system.Type;
 
 /**
 	Platform-specific C# Library. Provides some platform-specific functions for the C# target,
-	such as conversion from haxe types to native types.
+	such as conversion from haxe types to native types and vice-versa.
 **/
-
 class Lib 
 {
 	@:keep private static var decimalSeparator:String;
@@ -101,8 +100,21 @@ class Lib
 		return untyped obj.GetType();
 	}
 	
+	/**
+		Returns a Haxe Array of a native Array.
+		It won't copy the contents of the native array, so unless any operation triggers an array resize,
+		all changes made to the Haxe array will affect the native array argument.
+	**/
 	public static function array<T>(native:cs.NativeArray<T>):Array<T>
 	{
 		return untyped Array.ofNative(native);
 	}
+	
+	/**
+		Allocates a new Haxe Array with a predetermined size
+	**/
+	public static function arrayAlloc<T>(size:Int):Array<T>
+	{
+		return untyped Array.alloc(size);
+	}
 }

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
std/cs/_std/Array.hx


+ 1 - 6
std/cs/_std/Date.hx

@@ -2,12 +2,7 @@ package;
 import system.DateTime;
 import haxe.Int64;
 
-/**
- * ...
- * @author waneck
- */
-
-class Date 
+@:core_api class Date 
 {
 	private var date:DateTime;
 	

+ 1 - 1
std/cs/_std/EReg.hx

@@ -77,7 +77,7 @@ import system.text.regularExpressions.Regex;
 
 	public function split( s : String ) : Array<String> {
 		if (isGlobal)
-			return Array.ofNative(regex.Split(s));
+			return cs.Lib.array(regex.Split(s));
 		var m = regex.Match(s);
 		return untyped [s.Substring(0, m.Index), s.Substring(m.Index + m.Length)];
 	}

+ 19 - 15
std/cs/_std/Xml.hx

@@ -23,14 +23,18 @@
  * DAMAGE.
  */
 
-enum XmlType {
-	Element;
-	PCData;
-	CData;
-	Comment;
-	DocType;
-	Prolog;
-	Document;
+@:native("_Xml.RealXmlType")
+extern enum XmlType {
+}
+
+private enum RealXmlType {
+        Element;
+        PCData;
+        CData;
+        Comment;
+        DocType;
+        Prolog;
+        Document;
 }
 
 @:core_api class Xml {
@@ -333,13 +337,13 @@ enum XmlType {
 	}
 
 	static function __init__() : Void untyped {
-		Xml.Element = XmlType.Element;
-		Xml.PCData = XmlType.PCData;
-		Xml.CData = XmlType.CData;
-		Xml.Comment = XmlType.Comment;
-		Xml.DocType = XmlType.DocType;
-		Xml.Prolog = XmlType.Prolog;
-		Xml.Document = XmlType.Document;
+		Xml.Element = cast RealXmlType.Element;
+		Xml.PCData = cast RealXmlType.PCData;
+		Xml.CData = cast RealXmlType.CData;
+		Xml.Comment = cast RealXmlType.Comment;
+		Xml.DocType = cast RealXmlType.DocType;
+		Xml.Prolog = cast RealXmlType.Prolog;
+		Xml.Document = cast RealXmlType.Document;
 	}
 
 }

+ 33 - 1
std/java/Lib.hx

@@ -1,9 +1,19 @@
 package java;
 
+/**
+	Platform-specific Java Library. Provides some platform-specific functions for the Java target,
+	such as conversion from haxe types to native types and vice-versa.
+**/
 //we cannot use the java package for custom classes, so we're redefining it as "haxe.java.Lib"
 @:native('haxe.java.Lib') class Lib 
 {
-
+	
+	/**
+		Returns a native array from the supplied Array. This native array is unsafe to be written on,
+		as it may or may not be linked to the actual Array implementation.
+		
+		If equalLengthRequired is true, the result might be a copy of an array with the correct size.
+	**/
 	public static function toNativeReadOnlyArray<T>(arr:Array<T>, equalLengthRequired:Bool):NativeArray<T>
 	{
 		var native:NativeArray<T> = untyped arr.__a;
@@ -15,11 +25,20 @@ package java;
 		}
 	}
 	
+	/**
+		Returns a System.Type equivalent to the Haxe Class<> type.
+		
+		Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail.
+		This may change in the future, so use this function whenever you need to perform such conversion.
+	**/
 	public static function toNativeType<T>(cl:Class<T>):java.lang.Class<T>
 	{
 		return untyped cl;
 	}	
 	
+	/**
+		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
+	**/
 	@:functionBody('
 		return (java.lang.Class<T>) obj.getClass();
 	')
@@ -28,8 +47,21 @@ package java;
 		return null;
 	}
 	
+	/**
+		Returns a Haxe Array of a native Array.
+		It won't copy the contents of the native array, so unless any operation triggers an array resize,
+		all changes made to the Haxe array will affect the native array argument.
+	**/
 	public static function array<T>(native:java.NativeArray<T>):Array<T>
 	{
 		return untyped Array.ofNative(native);
 	}
+	
+	/**
+		Allocates a new Haxe Array with a predetermined size
+	**/
+	public static function arrayAlloc<T>(size:Int):Array<T>
+	{
+		return untyped Array.alloc(size);
+	}
 }

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
std/java/_std/Array.hx


+ 1 - 5
std/java/_std/Date.hx

@@ -1,12 +1,8 @@
 package;
 import haxe.Int64;
 
-/**
- * ...
- * @author waneck
- */
 @:SuppressWarnings("deprecation")
-class Date 
+@:core_api class Date 
 {
 	private var date:java.util.Date;
 	

+ 1 - 1
std/java/_std/EReg.hx

@@ -147,7 +147,7 @@ class EReg {
 	{
 		if (isGlobal)
 		{
-			return Array.ofNative(matcher.pattern().split(s));
+			return java.Lib.array(matcher.pattern().split(s));
 		} else {
 			var m = matcher;
 			m.reset(s);

+ 19 - 15
std/java/_std/Xml.hx

@@ -23,14 +23,18 @@
  * DAMAGE.
  */
 
-enum XmlType {
-	Element;
-	PCData;
-	CData;
-	Comment;
-	DocType;
-	Prolog;
-	Document;
+@:native("_Xml.RealXmlType")
+extern enum XmlType {
+}
+
+private enum RealXmlType {
+        Element;
+        PCData;
+        CData;
+        Comment;
+        DocType;
+        Prolog;
+        Document;
 }
 
 @:core_api class Xml {
@@ -333,13 +337,13 @@ enum XmlType {
 	}
 
 	static function __init__() : Void untyped {
-		Xml.Element = XmlType.Element;
-		Xml.PCData = XmlType.PCData;
-		Xml.CData = XmlType.CData;
-		Xml.Comment = XmlType.Comment;
-		Xml.DocType = XmlType.DocType;
-		Xml.Prolog = XmlType.Prolog;
-		Xml.Document = XmlType.Document;
+		Xml.Element = cast RealXmlType.Element;
+		Xml.PCData = cast RealXmlType.PCData;
+		Xml.CData = cast RealXmlType.CData;
+		Xml.Comment = cast RealXmlType.Comment;
+		Xml.DocType = cast RealXmlType.DocType;
+		Xml.Prolog = cast RealXmlType.Prolog;
+		Xml.Document = cast RealXmlType.Document;
 	}
 
 }

Деякі файли не було показано, через те що забагато файлів було змінено