Browse Source

[cs] get rid of `@:functionCode` on Reflect and Type

Simon Krajewski 10 years ago
parent
commit
003657a650
2 changed files with 49 additions and 68 deletions
  1. 9 20
      std/cs/_std/Reflect.hx
  2. 40 48
      std/cs/_std/Type.hx

+ 9 - 20
std/cs/_std/Reflect.hx

@@ -122,41 +122,30 @@ import cs.system.reflection.*;
 		return cs.internal.Runtime.compare(a, b);
 		return cs.internal.Runtime.compare(a, b);
 	}
 	}
 
 
-	@:functionCode('
+	@:access(cs.internal.Closure)
+	public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool
+	{
 		if (f1 == f2)
 		if (f1 == f2)
 			return true;
 			return true;
 
 
-		if (f1 is haxe.lang.Closure && f2 is haxe.lang.Closure)
+		if (Std.is(f1, Closure) && Std.is(f2, Closure))
 		{
 		{
-			haxe.lang.Closure f1c = (haxe.lang.Closure) f1;
-			haxe.lang.Closure f2c = (haxe.lang.Closure) f2;
+			var f1c:Closure = cast f1;
+			var f2c:Closure = cast f2;
 
 
-			return haxe.lang.Runtime.refEq(f1c.obj, f2c.obj) && f1c.field.Equals(f2c.field);
+			return Runtime.refEq(f1c.obj, f2c.obj) && f1c.field == f2c.field;
 		}
 		}
 
 
-		return false;
-	')
-	public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool
-	{
 		return false;
 		return false;
 	}
 	}
 
 
-	@:functionCode('
-		return v != null && !(v is haxe.lang.Enum || v is haxe.lang.Function || v is System.ValueType);
-	')
 	public static function isObject( v : Dynamic ) : Bool
 	public static function isObject( v : Dynamic ) : Bool
 	{
 	{
-		return false;
+		return v != null && !(Std.is(v, HxEnum) || Std.is(v, Function) || Std.is(v, cs.system.ValueType));
 	}
 	}
 
 
-	@:functionCode('
-		return v != null && (v is haxe.lang.Enum || v is System.Enum);
-	')
 	public static function isEnumValue( v : Dynamic ) : Bool {
 	public static function isEnumValue( v : Dynamic ) : Bool {
-		return switch(Type.typeof(v)) {
-			case TEnum(_): true;
-			case _: false;
-		}
+		return v != null && (Std.is(v, HxEnum) || Std.is(v, cs.system.Enum));
 	}
 	}
 
 
 	public static function deleteField( o : Dynamic, field : String ) : Bool
 	public static function deleteField( o : Dynamic, field : String ) : Bool

+ 40 - 48
std/cs/_std/Type.hx

@@ -22,6 +22,7 @@
 import cs.Lib;
 import cs.Lib;
 import cs.internal.HxObject;
 import cs.internal.HxObject;
 import cs.internal.Runtime;
 import cs.internal.Runtime;
+import cs.internal.Function;
 import cs.Flags;
 import cs.Flags;
 import cs.system.Object;
 import cs.system.Object;
 import cs.system.reflection.*;
 import cs.system.reflection.*;
@@ -267,59 +268,50 @@ using StringTools;
 		return cs.Lib.array(cs.system.Enum.GetNames(untyped e));
 		return cs.Lib.array(cs.system.Enum.GetNames(untyped e));
 	}
 	}
 
 
-	@:functionCode('
+	public static function typeof( v : Dynamic ) : ValueType {
 		if (v == null) return ValueType.TNull;
 		if (v == null) return ValueType.TNull;
 
 
-        System.Type t = v as System.Type;
-        if (t != null)
-        {
-            //class type
-            return ValueType.TObject;
-        }
-
-        t = v.GetType();
-        if (t.IsEnum)
-            return ValueType.TEnum(t);
-        if (t.IsValueType)
-        {
-            System.IConvertible vc = v as System.IConvertible;
-            if (vc != null)
-            {
-                switch (vc.GetTypeCode())
-                {
-                    case System.TypeCode.Boolean: return ValueType.TBool;
-                    case System.TypeCode.Double:
-						double d = vc.ToDouble(null);
-						if (d >= int.MinValue && d <= int.MaxValue && d == vc.ToInt32(null))
+		var t:cs.system.Type = cs.Lib.as(v, cs.system.Type);
+		if (t != null) {
+			//class type
+			return ValueType.TObject;
+		}
+
+		t = v.GetType();
+		if (t.IsEnum)
+			return ValueType.TEnum(cast t);
+		if (t.IsValueType) {
+			var vc:cs.system.IConvertible = cast v;
+			if (vc != null) {
+				switch (vc.GetTypeCode()) {
+					case cs.system.TypeCode.Boolean: return ValueType.TBool;
+					case cs.system.TypeCode.Double:
+						var d:Float = vc.ToDouble(null);
+						if (d >= cs.system.Int32.MinValue && d <= cs.system.Int32.MaxValue && d == vc.ToInt32(null))
 							return ValueType.TInt;
 							return ValueType.TInt;
 						else
 						else
 							return ValueType.TFloat;
 							return ValueType.TFloat;
-                    case System.TypeCode.Int32:
-                        return ValueType.TInt;
-                    default:
-                        return ValueType.TClass(t);
-                }
-            } else {
-                return ValueType.TClass(t);
-            }
-        }
-
-        if (v is haxe.lang.IHxObject)
-        {
-            if (v is haxe.lang.DynamicObject)
-                return ValueType.TObject;
-            else if (v is haxe.lang.Enum)
-                return ValueType.TEnum(t);
-            return ValueType.TClass(t);
-        } else if (v is haxe.lang.Function) {
-            return ValueType.TFunction;
-        } else {
-            return ValueType.TClass(t);
-        }
-	')
-	public static function typeof( v : Dynamic ) : ValueType
-	{
-		return null;
+					case cs.system.TypeCode.Int32:
+						return ValueType.TInt;
+					default:
+						return ValueType.TClass(cast t);
+				}
+			} else {
+				return ValueType.TClass(cast t);
+			}
+		}
+
+		if (Std.is(v, IHxObject)) {
+			if (Std.is(v, DynamicObject))
+				return ValueType.TObject;
+			else if (Std.is(v, HxEnum))
+				return ValueType.TEnum(cast t);
+			return ValueType.TClass(cast t);
+		} else if (Std.is(v, Function)) {
+			return ValueType.TFunction;
+		} else {
+			return ValueType.TClass(cast t);
+		}
 	}
 	}
 
 
 	public static function enumEq<T>( a : T, b : T ) : Bool
 	public static function enumEq<T>( a : T, b : T ) : Bool