Browse Source

[cs] Added String reflection, fixed Issue #940
[java/cs] Added substring function

Caue Waneck 13 years ago
parent
commit
a239d96923

+ 1 - 0
gencs.ml

@@ -282,6 +282,7 @@ struct
         | TCall( ( { eexpr = TField(ef, ("indexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("indexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("lastIndexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("lastIndexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("split" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("split" as field)) } ), args )
+        | TCall( ( { eexpr = TField(ef, ("substring" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("substr" as field)) } ), args ) when is_string ef.etype ->
         | TCall( ( { eexpr = TField(ef, ("substr" as field)) } ), args ) when is_string ef.etype ->
           { e with eexpr = TCall(mk_static_field_access_infer string_ext field e.epos [], [run ef] @ (List.map run args)) }
           { e with eexpr = TCall(mk_static_field_access_infer string_ext field e.epos [], [run ef] @ (List.map run args)) }
         
         

+ 1 - 0
genjava.ml

@@ -509,6 +509,7 @@ struct
         | TCall( ( { eexpr = TField(ef, ("split" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("split" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("indexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("indexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("lastIndexOf" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("lastIndexOf" as field)) } ), args )
+        | TCall( ( { eexpr = TField(ef, ("substring" as field)) } ), args )
         | TCall( ( { eexpr = TField(ef, ("substr" as field)) } ), args ) when is_string ef.etype ->
         | TCall( ( { eexpr = TField(ef, ("substr" as field)) } ), args ) when is_string ef.etype ->
           { e with eexpr = TCall(mk_static_field_access_infer string_ext field e.epos [], [run ef] @ (List.map run args)) }
           { e with eexpr = TCall(mk_static_field_access_infer string_ext field e.epos [], [run ef] @ (List.map run args)) }
         
         

+ 3 - 24
std/cs/_std/Reflect.hx

@@ -121,31 +121,10 @@ import haxe.lang.Function;
 			Array<object> ret = new Array<object>();
 			Array<object> ret = new Array<object>();
 				((haxe.lang.IHxObject) o).__hx_getFields(ret);
 				((haxe.lang.IHxObject) o).__hx_getFields(ret);
 			return ret;
 			return ret;
+		} else if (o is System.Type) {
+			return Type.getClassFields( (System.Type) o);
 		} else {
 		} else {
-			Array<object> ret = new Array<object>();
-			
-			if (o is System.Type)
-			{
-				System.Type cl = (System.Type) o;
-				
-				foreach(System.Reflection.FieldInfo fi in cl.GetFields(System.Reflection.BindingFlags.Static))
-				{
-					ret.push(fi.Name);
-				}
-				
-				string last = null;
-				foreach(System.Reflection.MethodInfo mi in cl.GetMethods(System.Reflection.BindingFlags.Static))
-				{
-					string name = mi.Name;
-					if (!last.Equals(name))
-					{
-						ret.push(name);
-						last = name;
-					}
-				}
-			}
-			
-			return ret;
+			return new Array<object>();
 		}
 		}
 	')
 	')
 	public static function fields( o : Dynamic ) : Array<String>
 	public static function fields( o : Dynamic ) : Array<String>

+ 8 - 0
std/cs/_std/String.hx

@@ -84,6 +84,14 @@ extern class String implements ArrayAccess<Char16> {
 		If [len] is not specified, it takes all the remaining characters.
 		If [len] is not specified, it takes all the remaining characters.
 	**/
 	**/
 	function substr( pos : Int, ?len : Int ) : String;
 	function substr( pos : Int, ?len : Int ) : String;
+	
+	/**
+		Returns a part of the String, taking from [startIndex] to [endIndex] - 1.
+		If [endIndex] is not specified, length is used.
+		If [startIndex] or [endIndex] is smaller than 0, than 0 is used.
+		If [startIndex] > [endIndex] then they are swaped.
+	**/
+	function substring( startIndex : Int, ?endIndex : Int ) : String;
 
 
 	/**
 	/**
 		Returns the String itself.
 		Returns the String itself.

+ 11 - 0
std/cs/_std/Type.hx

@@ -178,6 +178,11 @@ enum ValueType {
 	}
 	}
 	
 	
 	@:functionBody('
 	@:functionBody('
+		if (c == typeof(string))
+		{
+			return haxe.lang.StringRefl.fields;
+		}
+		
 		Array<object> ret = new Array<object>();
 		Array<object> ret = new Array<object>();
 
 
         System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance);
         System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance);
@@ -198,6 +203,12 @@ enum ValueType {
 	
 	
 	@:functionBody('
 	@:functionBody('
 		Array<object> ret = new Array<object>();
 		Array<object> ret = new Array<object>();
+		
+		if (c == typeof(string))
+		{
+			ret.push("fromCharCode");
+			return ret;
+		}
 
 
         System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
         System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
         for (int i = 0; i < mis.Length; i++)
         for (int i = 0; i < mis.Length; i++)

+ 1 - 1
std/cs/_std/haxe/lang/Function.hx

@@ -44,7 +44,7 @@ package haxe.lang;
 	private var field:String;
 	private var field:String;
 	private var hash:Int;
 	private var hash:Int;
 	
 	
-	public function new(obj, field, hash)
+	public function new(obj:Dynamic, field, hash)
 	{
 	{
 		super(-1, -1);
 		super(-1, -1);
 		this.obj = obj;
 		this.obj = obj;

+ 16 - 0
std/cs/_std/haxe/lang/Runtime.hx

@@ -215,9 +215,15 @@ import system.Type;
 		System.Reflection.BindingFlags bf;
 		System.Reflection.BindingFlags bf;
         if (t == null)
         if (t == null)
 		{
 		{
+			string s = obj as string;
+			if (s != null)
+				return haxe.lang.StringRefl.handleGetField(s, field, throwErrors);
 			t = obj.GetType();
 			t = obj.GetType();
 			bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
 			bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
 		} else {
 		} else {
+			if (obj == typeof(string) && field.Equals("fromCharCode"))
+				return new haxe.lang.Closure(typeof(haxe.lang.StringExt), field, 0);
+			
 			obj = null;
 			obj = null;
 			bf = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
 			bf = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
 		}
 		}
@@ -256,9 +262,14 @@ import system.Type;
 		System.Reflection.BindingFlags bf;
 		System.Reflection.BindingFlags bf;
         if (t == null)
         if (t == null)
 		{
 		{
+			string s = obj as string;
+			if (s != null)
+				return haxe.lang.StringRefl.handleGetField(s, field, false) != null;
 			t = obj.GetType();
 			t = obj.GetType();
 			bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
 			bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
 		} else {
 		} else {
+			if (t == typeof(string))
+				return field.Equals("fromCharCode");
 			obj = null;
 			obj = null;
 			bf = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
 			bf = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
 		}
 		}
@@ -444,9 +455,14 @@ import system.Type;
 		System.Type t = obj as System.Type;
 		System.Type t = obj as System.Type;
 		if (t == null)
 		if (t == null)
 		{
 		{
+			string s = obj as string;
+			if (s != null)
+				return haxe.lang.StringRefl.handleCallField(s, field, args);
 			t = obj.GetType();
 			t = obj.GetType();
 			bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
 			bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
 		} else {
 		} else {
+			if (t == typeof(string) && field.Equals("fromCharCode"))
+				return haxe.lang.StringExt.fromCharCode(toInt(args[0]));
 			obj = null;
 			obj = null;
 			bf = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
 			bf = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
 		}
 		}

File diff suppressed because it is too large
+ 0 - 0
std/cs/_std/haxe/lang/StringExt.hx


+ 8 - 2
std/java/_std/String.hx

@@ -83,6 +83,14 @@ extern class String {
 		If [len] is not specified, it takes all the remaining characters.
 		If [len] is not specified, it takes all the remaining characters.
 	**/
 	**/
 	function substr( pos : Int, ?len : Int ) : String;
 	function substr( pos : Int, ?len : Int ) : String;
+	
+	/**
+		Returns a part of the String, taking from [startIndex] to [endIndex] - 1.
+		If [endIndex] is not specified, length is used.
+		If [startIndex] or [endIndex] is smaller than 0, than 0 is used.
+		If [startIndex] > [endIndex] then they are swaped.
+	**/
+	function substring( startIndex : Int, ?endIndex : Int ) : String;
 
 
 	/**
 	/**
 		Returns the String itself.
 		Returns the String itself.
@@ -92,8 +100,6 @@ extern class String {
 	private function compareTo( anotherString : String ) : Int;
 	private function compareTo( anotherString : String ) : Int;
 	
 	
 	private function codePointAt( idx : Int ) : Int;
 	private function codePointAt( idx : Int ) : Int;
-	
-	private function substring( begin : Int, end : Int ) : String;
 
 
 	static function fromCharCode( code : Int ) : String;
 	static function fromCharCode( code : Int ) : String;
 
 

+ 1 - 1
std/java/_std/haxe/lang/Runtime.hx

@@ -153,7 +153,7 @@ package haxe.lang;
 		if (o instanceof java.lang.Class)
 		if (o instanceof java.lang.Class)
 		{
 		{
 			if (o == java.lang.String.class)
 			if (o == java.lang.String.class)
-				return field == "fromCharCode";
+				return field.equals("fromCharCode");
 			
 			
 			cl = (java.lang.Class) o;
 			cl = (java.lang.Class) o;
 		} else if (o instanceof java.lang.String) {
 		} else if (o instanceof java.lang.String) {

File diff suppressed because it is too large
+ 0 - 0
std/java/_std/haxe/lang/StringExt.hx


Some files were not shown because too many files changed in this diff