Przeglądaj źródła

Merge branch 'development' into genpy

Conflicts:
	std/haxe/io/Bytes.hx
Simon Krajewski 11 lat temu
rodzic
commit
1aa00e9b5c
9 zmienionych plików z 687 dodań i 611 usunięć
  1. 7 1
      filters.ml
  2. 599 599
      gencpp.ml
  3. 8 6
      std/UInt.hx
  4. 25 0
      std/cpp/NativeArray.hx
  5. 23 1
      std/haxe/io/Bytes.hx
  6. 1 1
      tests/unit/issues/Issue2619.hx
  7. 20 0
      tests/unit/issues/Issue2859.hx
  8. 1 1
      typeload.ml
  9. 3 2
      typer.ml

+ 7 - 1
filters.ml

@@ -1118,7 +1118,13 @@ let run com tctx main =
 	if not (Common.defined com Define.As3 || dce_mode = "no" || Common.defined com Define.DocGen) then Dce.run com main (dce_mode = "full" && not (Common.defined com Define.Interp));
 	(* always filter empty abstract implementation classes (issue #1885) *)
 	List.iter (fun mt -> match mt with
-		| TClassDecl({cl_kind = KAbstractImpl _} as c) when c.cl_ordered_statics = [] && c.cl_ordered_fields = [] && not (Meta.has Meta.Used c.cl_meta) -> c.cl_extern <- true
+		| TClassDecl({cl_kind = KAbstractImpl _} as c) ->
+			let is_runtime_field cf =
+				not (Meta.has Meta.Enum cf.cf_meta)
+			in
+			(* also filter abstract implementation classes that have only @:enum fields (issue #2858) *)
+			if not (Meta.has Meta.Used c.cl_meta) || not (List.exists is_runtime_field c.cl_ordered_statics) then
+				c.cl_extern <- true
 		| _ -> ()
 	) com.types;
 	(* PASS 3: type filters *)

Plik diff jest za duży
+ 599 - 599
gencpp.ml


+ 8 - 6
std/UInt.hx

@@ -20,7 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#if ((flash9 || flash9doc || cs) && !doc_gen)
+#if (flash9 || flash9doc || cs || doc_gen)
 /**
 	The unsigned Int type is only defined for Flash9 and C#. It's currently
 	handled the same as a normal Int.
@@ -31,7 +31,8 @@
 	The unsigned Int type is only defined for Flash9 and C#.
 	Simulate it for other platforms.
 **/
-abstract UInt(Int) from Int to Int {
+@:coreType
+abstract UInt from Int {
 
 	@:op(A + B) private static inline function add(a:UInt, b:UInt):UInt {
 		return a.toInt() + b.toInt();
@@ -200,10 +201,6 @@ abstract UInt(Int) from Int to Int {
 		return Std.string(toFloat());
 	}
 
-	private inline function toInt():Int {
-		return this;
-	}
-
 	@:to private inline function toFloat():Float {
 		var int = toInt();
 		if (int < 0) {
@@ -215,5 +212,10 @@ abstract UInt(Int) from Int to Int {
 			return int + 0.0;
 		}
 	}
+
+	@:to private inline function toInt():Int {
+		return cast this;
+	}
+
 }
 #end

+ 25 - 0
std/cpp/NativeArray.hx

@@ -0,0 +1,25 @@
+package cpp;
+
+class NativeArray {
+
+	public static inline function blit<T>( ioDestArray:Array<T>,
+		inDestElement:Int, inSourceArray:Array<T>,
+		inSourceElement:Int, inElementCount:Int ): Void  {
+	untyped ioDestArray.blit(inDestElement, inSourceArray, inSourceElement, inElementCount);
+	};
+
+	public static inline function zero<T>( ioDestArray:Array<T>, ?inFirst:Int, ?inElements:Int ) {
+		untyped ioDestArray.zero(inFirst, inElements);
+	};
+
+	public static inline function unsafeGet<T>( inDestArray:Array<T>, inIndex:Int) : T {
+		return untyped inDestArray.__unsafe_get(inIndex);
+	}
+	public static inline function unsafeSet<T>( ioDestArray:Array<T>, inIndex:Int, inValue:T) : T {
+		return untyped ioDestArray.__unsafe_set(inIndex,inValue);
+	}
+
+	public static inline function memcmp<T>( inArrayA:Array<T>, inArrayB:Array<T>) : Int {
+		return untyped inArrayA.memcmp(inArrayB);
+	}
+}

+ 23 - 1
std/haxe/io/Bytes.hx

@@ -21,6 +21,10 @@
  */
 package haxe.io;
 
+#if cpp
+using cpp.NativeArray;
+#end
+
 class Bytes {
 
 	public var length(default,null) : Int;
@@ -89,6 +93,8 @@ class Bytes {
 		cs.system.Array.Copy(src.b, srcpos, b, pos, len);
 		#elseif python
 		python.Syntax.pythonCode("self.b[pos:pos+len] = src.b[srcpos:srcpos+len]");
+		#elseif cpp
+		b.blit(pos, src.b, srcpos, len);
 		#else
 		var b1 = b;
 		var b2 = src.b;
@@ -116,6 +122,8 @@ class Bytes {
 		pos += len&~3;
 		for( i in 0...len&3 )
 			set(pos++,value);
+		#elseif cpp
+		untyped __global__.__hxcpp_memory_memset(b,pos,len,value);
 		#else
 		for( i in 0...len )
 			set(pos++, value);
@@ -183,6 +191,8 @@ class Bytes {
 		return untyped __php__("$this->b < $other->b ? -1 : ($this->b == $other->b ? 0 : 1)");
 		//#elseif cs
 		//TODO: memcmp if unsafe flag is on
+		#elseif cpp
+		return b.memcmp(other.b);
 		#else
 		var b1 = b;
 		var b2 = other.b;
@@ -204,6 +214,9 @@ class Bytes {
 		#elseif flash9
 		b.position = pos;
 		return b.readDouble();
+		#elseif cpp
+		if( pos < 0 || pos + 8 > length ) throw Error.OutsideBounds;
+		return untyped __global__.__hxcpp_memory_get_double(b,pos);
 		#else
 		var b = new haxe.io.BytesInput(this,pos,8);
 		return b.readDouble();
@@ -216,6 +229,9 @@ class Bytes {
 		#elseif flash9
 		b.position = pos;
 		return b.readFloat();
+		#elseif cpp
+		if( pos < 0 || pos + 4 > length ) throw Error.OutsideBounds;
+		return untyped __global__.__hxcpp_memory_get_float(b,pos);
 		#else
 		var b = new haxe.io.BytesInput(this,pos,4);
 		return b.readFloat();
@@ -228,6 +244,9 @@ class Bytes {
 		#elseif flash9
 		b.position = pos;
 		b.writeDouble(v);
+		#elseif cpp
+		if( pos < 0 || pos + 8 > length ) throw Error.OutsideBounds;
+		untyped __global__.__hxcpp_memory_set_double(b,pos,v);
 		#else
 		throw "Not supported";
 		#end
@@ -239,6 +258,9 @@ class Bytes {
 		#elseif flash9
 		b.position = pos;
 		b.writeFloat(v);
+		#elseif cpp
+		if( pos < 0 || pos + 4 > length ) throw Error.OutsideBounds;
+		untyped __global__.__hxcpp_memory_set_float(b,pos,v);
 		#else
 		throw "Not supported";
 		#end
@@ -451,7 +473,7 @@ class Bytes {
 		#elseif php
 		return untyped __call__("ord", b[pos]);
 		#elseif cpp
-		return untyped b[pos];
+		return untyped b.unsafeGet(pos);
 		#elseif java
 		return untyped b[pos] & 0xFF;
 		#else

+ 1 - 1
tests/unit/issues/Issue2619.hx

@@ -1,7 +1,7 @@
 package unit.issues;
 import unit.Test;
 
-private abstract A(String) {
+private abstract A(String) to String {
 	public function new(s) this = s;
 }
 

+ 20 - 0
tests/unit/issues/Issue2859.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+private abstract Error(String) {
+    public function new(message:String) {
+        this = message;
+    }
+}
+
+class Issue2859 extends Test {
+	function test() {
+        try {
+            throw new Error("hello");
+        } catch (e:Error) {
+			unit.TestType.typedAs(e, (null:Error));
+            func(e);
+        }
+    }
+
+    static function func(e:Error) { }
+}

+ 1 - 1
typeload.ml

@@ -1099,7 +1099,7 @@ let set_heritance ctx c herits p =
 				intf.cl_build();
 				if is_parent c intf then error "Recursive class" p;
 				if c.cl_interface then error "Interfaces cannot implement another interface (use extends instead)" p;
-				if not intf.cl_interface then error "You can only implements an interface" p;
+				if not intf.cl_interface then error "You can only implement an interface" p;
 				process_meta intf;
 				c.cl_implements <- (intf, params) :: c.cl_implements;
 				if not !has_interf then begin

+ 3 - 2
typer.ml

@@ -2857,12 +2857,13 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				| TDynamic _ -> "",t
 				| _ -> error "Catch type must be a class, an enum or Dynamic" (pos e)
 			in
-			let name,t = loop t in
+			let name,t2 = loop t in
 			if v.[0] = '$' then display_error ctx "Catch variable names starting with a dollar are not allowed" p;
-			check_unreachable acc t (pos e);
+			check_unreachable acc t2 (pos e);
 			let locals = save_locals ctx in
 			let v = add_local ctx v t in
 			let e = type_expr ctx e with_type in
+			v.v_type <- t2;
 			locals();
 			if with_type <> NoValue then unify ctx e.etype e1.etype e.epos;
 			if PMap.mem name ctx.locals then error ("Local variable " ^ name ^ " is preventing usage of this type here") e.epos;

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików