瀏覽代碼

[java/cs] Several fixes to Type API

Caue Waneck 13 年之前
父節點
當前提交
4ad37ea771
共有 7 個文件被更改,包括 46 次插入11 次删除
  1. 3 2
      gencommon.ml
  2. 19 3
      gencs.ml
  3. 1 1
      std/cs/_std/Reflect.hx
  4. 6 1
      std/cs/_std/Type.hx
  5. 15 2
      std/cs/_std/haxe/lang/Runtime.hx
  6. 1 1
      std/java/_std/Reflect.hx
  7. 1 1
      std/java/_std/haxe/lang/Function.hx

+ 3 - 2
gencommon.ml

@@ -6641,9 +6641,10 @@ struct
       (* 
         if it is first_dynamic, then we need to enumerate the dynamic fields
       *)
-      let if_not_inst = if is_some cl.cl_dynamic && is_first_dynamic cl then
+      let if_not_inst = if is_some cl.cl_dynamic && is_first_dynamic cl then begin
+        has_value := true;
         Some (enumerate_dynamic_fields ctx cl mk_push)
-      else
+      end else
         None
       in
       

+ 19 - 3
gencs.ml

@@ -130,7 +130,7 @@ struct
           in
           let obj = run obj in
           (match follow_module follow md with
-            | TClassDecl({ cl_path = ([], "Float") }) ->
+            | TClassDecl{ cl_path = ([], "Float") } ->
               (* on the special case of seeing if it is a Float, we need to test if both it is a float and if it is an Int *)
               let mk_is local =
                 mk_paren {
@@ -153,6 +153,15 @@ struct
                   }
               in
               ret
+            | TClassDecl{ cl_path = ([], "Int") } ->
+              {
+                eexpr = TCall(
+                  mk_static_field_access_infer runtime_cl "isInt" e.epos [],
+                  [ obj ]
+                );
+                etype = basic.tbool;
+                epos = e.epos
+              }
             | _ ->
               mk_is obj md
           )
@@ -1719,7 +1728,14 @@ let configure gen =
   run_filters gen;
   (* after the filters have been run, add all hashed fields to FieldLookup *)
   
-  let hashes = Hashtbl.fold (fun i s acc -> (i,s) :: acc) rcf_ctx.rcf_hash_fields [] in
+  let normalize_i i =
+    let i = Int32.of_int (i) in
+    if i < Int32.zero then
+      Int32.logor (Int32.logand i (Int32.of_int 0x3FFFFFFF)) (Int32.shift_left Int32.one 30)
+    else i
+  in
+  
+  let hashes = Hashtbl.fold (fun i s acc -> (normalize_i i,s) :: acc) rcf_ctx.rcf_hash_fields [] in
   let hashes = List.sort (fun (i,s) (i2,s2) -> compare i i2) hashes in
   
   let flookup_cl = get_cl (get_type gen (["haxe";"lang"], "FieldLookup")) in
@@ -1731,7 +1747,7 @@ let configure gen =
     let fields = PMap.find "fields" cl.cl_statics in
     
     field_ids.cf_expr <- Some (change_array { 
-      eexpr = TArrayDecl(List.map (fun (i,s) -> { eexpr = TConst(TInt ( Int32.of_int i)); etype = basic.tint; epos = field_ids.cf_pos }) hashes);
+      eexpr = TArrayDecl(List.map (fun (i,s) -> { eexpr = TConst(TInt (i)); etype = basic.tint; epos = field_ids.cf_pos }) hashes);
       etype = basic.tarray basic.tint;
       epos = field_ids.cf_pos
     });

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

@@ -137,7 +137,7 @@ import haxe.lang.Function;
 				foreach(System.Reflection.MethodInfo mi in cl.GetMethods(System.Reflection.BindingFlags.Static))
 				{
 					string name = mi.Name;
-					if (last != name)
+					if (!last.Equals(name))
 					{
 						ret.push(name);
 						last = name;

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

@@ -183,6 +183,8 @@ enum ValueType {
         System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance);
         for (int i = 0; i < mis.Length; i++)
         {
+			if (mis[i] is System.Reflection.PropertyInfo)
+                continue;
 			string n = mis[i].Name;
 			if (!n.StartsWith("__hx_") && n[0] != \'.\')
 				ret.push(mis[i].Name);
@@ -239,7 +241,10 @@ enum ValueType {
                 {
                     case System.TypeCode.Boolean: return ValueType.TBool;
                     case System.TypeCode.Double:
-                        return ValueType.TFloat;
+						if (vc.ToDouble(null) == vc.ToInt32(null))
+							return ValueType.TInt;
+						else
+							return ValueType.TFloat;
                     case System.TypeCode.Int32:
                         return ValueType.TInt;
                     default:

+ 15 - 2
std/cs/_std/haxe/lang/Runtime.hx

@@ -123,6 +123,19 @@ import system.Type;
 		return 0;
 	}
 	
+	@:functionBody('
+			System.IConvertible cv1 = obj as System.IConvertible;
+			if (cv1 != null)
+			{
+				return cv1.ToDouble(null) == cv1.ToInt32(null);
+			}
+			return false;
+	')
+	public static function isInt(obj:Dynamic):Bool
+	{
+		return false;
+	}
+	
 	@:functionBody('
 			System.IConvertible cv1 = v1 as System.IConvertible;
 			if (cv1 != null)
@@ -217,8 +230,8 @@ import system.Type;
 			System.Reflection.PropertyInfo prop = t.GetProperty(field, bf);
 			if (prop == null)
 			{
-				System.Reflection.MethodInfo m = t.GetMethod(field, bf);
-				if (m != null)
+				System.Reflection.MemberInfo[] m = t.GetMember(field, bf);
+				if (m.Length > 0)
 				{
 					return new haxe.lang.Closure(obj, field, 0);
 				} else {

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

@@ -120,7 +120,7 @@ import java.Boot;
 		if (o instanceof haxe.lang.IHxObject)
 		{
 			Array<String> ret = new Array<String>();
-			((haxe.lang.IHxObject) o).__hx_getFields(ret);
+				((haxe.lang.IHxObject) o).__hx_getFields(ret);
 			return ret;
 		} else {
 			Array<String> ret = new Array<String>();

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

@@ -54,6 +54,6 @@ import haxe.lang.Runtime;
 	
 	override public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic 
 	{
-		return Runtime.slowCallField(this.obj, this.field, dynArgs);
+		return Runtime.callField(obj, field, dynArgs);
 	}
 }