Просмотр исходного кода

[cs] get rid of most "untyped __cs__" calls, use proper code generation instead

Dan Korostelev 11 лет назад
Родитель
Сommit
51eba26adc
7 измененных файлов с 14 добавлено и 18 удалено
  1. 4 4
      std/StringTools.hx
  2. 1 3
      std/cs/_std/Std.hx
  3. 3 4
      std/cs/_std/Sys.hx
  4. 1 1
      std/cs/_std/Type.hx
  5. 1 1
      std/haxe/Log.hx
  6. 3 3
      std/haxe/Resource.hx
  7. 1 2
      std/haxe/unit/TestRunner.hx

+ 4 - 4
std/StringTools.hx

@@ -33,7 +33,7 @@ class StringTools {
 	/**
 		Encode an URL by using the standard format.
 	**/
-	public static function urlEncode( s : String ) : String untyped {
+	#if !java inline #end public static function urlEncode( s : String ) : String untyped {
 		#if flash9
 			return __global__["encodeURIComponent"](s);
 		#elseif flash
@@ -49,7 +49,7 @@ class StringTools {
 				return untyped __java__("java.net.URLEncoder.encode(s, \"UTF-8\")")
 			catch (e:Dynamic) throw e;
 		#elseif cs
-			return untyped __cs__("System.Uri.EscapeUriString(s)");
+			return cs.system.Uri.EscapeUriString(s);
 		#else
 			return null;
 		#end
@@ -58,7 +58,7 @@ class StringTools {
 	/**
 		Decode an URL using the standard format.
 	**/
-	public static function urlDecode( s : String ) : String untyped {
+	#if !java inline #end public static function urlDecode( s : String ) : String untyped {
 		#if flash9
 			return __global__["decodeURIComponent"](s.split("+").join(" "));
 		#elseif flash
@@ -74,7 +74,7 @@ class StringTools {
 				return untyped __java__("java.net.URLDecoder.decode(s, \"UTF-8\")")
 			catch (e:Dynamic) throw e;
 		#elseif cs
-			return untyped __cs__("System.Uri.UnescapeDataString(s)");
+			return cs.system.Uri.UnescapeDataString(s);
 		#else
 			return null;
 		#end

+ 1 - 3
std/cs/_std/Std.hx

@@ -47,9 +47,7 @@ import cs.internal.Exceptions;
 				return true;
 		}
 
-		var clv:cs.system.Type = untyped __cs__('v.GetType()');
-
-		return clt.IsAssignableFrom(clv);
+		return clt.IsAssignableFrom(cs.Lib.nativeType(v));
 	}
 
 	public static function string( s : Dynamic ) : String {

+ 3 - 4
std/cs/_std/Sys.hx

@@ -161,16 +161,15 @@ class Sys {
 		return Environment.TickCount / 1000;
 	}
 
-	public static function executablePath() : String
+	public static inline function executablePath() : String
 	{
-		//TODO: add extern references
-		return untyped __cs__('System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase');
+		return cs.system.reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
 	}
 
 	public static function getChar( echo : Bool ) : Int
 	{
 		#if !(Xbox || CF || MF) //Xbox, Compact Framework, Micro Framework
-		return untyped __cs__('((int) System.Console.ReadKey(!echo).KeyChar)');
+		return cast(cs.system.Console.ReadKey(!echo).KeyChar, Int);
 		#else
 		return -1;
 		#end

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

@@ -271,7 +271,7 @@ import cs.internal.Runtime;
 	public static function getEnumConstructs( e : Enum<Dynamic> ) : Array<String> {
 		if (Reflect.hasField(e, "constructs"))
 			return untyped e.constructs.copy();
-		return untyped __cs__("new Array<object>(System.Enum.GetNames(e))");
+		return cs.Lib.array(cs.system.Enum.GetNames(cs.Lib.nativeType(e)));
 	}
 
 	@:functionCode('

+ 1 - 1
std/haxe/Log.hx

@@ -90,7 +90,7 @@ class Log {
 				str = v;
 			}
 			#if cs
-			untyped __cs__("System.Console.WriteLine(str)");
+			cs.system.Console.WriteLine(str);
 			#elseif java
 			untyped __java__("java.lang.System.out.println(str)");
 			#end

+ 3 - 3
std/haxe/Resource.hx

@@ -46,7 +46,7 @@ class Resource {
 		if (paths != null)
 			return paths;
 		var p = new haxe.ds.StringMap();
-		var all:cs.NativeArray<String> = untyped __cs__("typeof(haxe.Resource).Assembly.GetManifestResourceNames()");
+		var all = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceNames();
 		for (i in 0...all.Length)
 		{
 			var path = all[i];
@@ -88,7 +88,7 @@ class Resource {
 		return stream.readAll().toString();
 		#elseif cs
 		var path = getPaths().get(name);
-		var str:cs.system.io.Stream = untyped __cs__("typeof(haxe.Resource).Assembly.GetManifestResourceStream(path)");
+		var str = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceStream(path);
 		if (str != null)
 			return new cs.io.NativeInput(str).readAll().toString();
 		return null;
@@ -122,7 +122,7 @@ class Resource {
 		return stream.readAll();
 		#elseif cs
 		var path = getPaths().get(name);
-		var str:cs.system.io.Stream = untyped __cs__("typeof(haxe.Resource).Assembly.GetManifestResourceStream(path)");
+		var str = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceStream(path);
 		if (str != null)
 			return new cs.io.NativeInput(str).readAll();
 		return null;

+ 1 - 2
std/haxe/unit/TestRunner.hx

@@ -80,8 +80,7 @@ class TestRunner {
 				__js__("console").log(msg); // document-less js (which may include a line break)
 
 		#elseif cs
-			var str:String = v;
-			untyped __cs__("System.Console.Write(str)");
+			cs.system.Console.Write(v);
 		#elseif java
 			var str:String = v;
 			untyped __java__("java.lang.System.out.print(str)");