소스 검색

added enumEq.

Nicolas Cannasse 18 년 전
부모
커밋
cd6a5a0633
2개의 변경된 파일42개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      doc/CHANGES.txt
  2. 41 0
      std/Type.hx

+ 1 - 0
doc/CHANGES.txt

@@ -14,6 +14,7 @@
 	fixed Type.typeof on some flash9 instances
 	no more dontUseCache (haxe.Serializer.USE_CACHE, default to false)
 	small genxml/haxedoc improvements
+	added Type.enumEq
 
 2007-01-01: 1.10
 	fix in haxe.remoting.SocketConnection.readAnswer

+ 41 - 0
std/Type.hx

@@ -420,6 +420,8 @@ class Type {
 					return TEnum(c);
 				return TClass(c);
 			} catch( e : Dynamic ) {
+				if( cname == "builtin.as$0::MethodClosure" || cname.indexOf("-") != -1 )
+					return TFunction;
 				return if( c == null ) TFunction else TClass(c);
 			}
 		}
@@ -461,5 +463,44 @@ class Type {
 		#end
 	}
 
+	/**
+		Recursively compare two enums constructors and parameters.
+	**/
+	public static function enumEq<T>( a : T, b : T ) : Bool untyped {
+		if( a == b )
+			return true;
+		#if neko
+		try {
+			if( a.__enum__ == null || a.tag != b.tag )
+				return false;
+		} catch( e : Dynamic ) {
+			return false;
+		}
+		for( i in 0...__dollar__asize(a.args) )
+			if( !enumEq(a.args[i],b.args[i]) )
+				return false;
+		#else flash9
+		try {
+			if( a.tag != b.tag )
+				return false;
+			for( i in 0...a.params.length )
+				if( !enumEq(a.params[i],b.params[i]) )
+					return false;
+		} catch( e : Dynamic ) {
+			return false;
+		}
+		#else true
+		if( a[0] != b[0] )
+			return false;
+		for( i in 1...a.length )
+			if( !enumEq(a[i],b[i]) )
+				return false;
+		var e = a.__enum__;
+		if( e != b.__enum__ || e == null )
+			return false;
+		#end
+		return true;
+	}
+
 }