Sfoglia il codice sorgente

proxy creation cleanup

ncannasse 9 anni fa
parent
commit
f48f1e5f5d
1 ha cambiato i file con 28 aggiunte e 18 eliminazioni
  1. 28 18
      hxd/net/Macros.hx

+ 28 - 18
hxd/net/Macros.hx

@@ -113,6 +113,7 @@ class Macros {
 	}
 	}
 
 
 	static function getPropType( t : haxe.macro.Type ) : PropType {
 	static function getPropType( t : haxe.macro.Type ) : PropType {
+		var isProxy = false;
 		var desc = switch( t ) {
 		var desc = switch( t ) {
 		case TAbstract(a, pl):
 		case TAbstract(a, pl):
 			switch( a.toString() ) {
 			switch( a.toString() ) {
@@ -132,11 +133,13 @@ class Macros {
 				var t = getPropType(pl[0]);
 				var t = getPropType(pl[0]);
 				if( t == null )
 				if( t == null )
 					return null;
 					return null;
+				isProxy = true;
 				PArray(t);
 				PArray(t);
 			case "hxd.net.MapProxy", "hxd.net.MapProxy2":
 			case "hxd.net.MapProxy", "hxd.net.MapProxy2":
 				var k = getPropType(pl[0]);
 				var k = getPropType(pl[0]);
 				var v = getPropType(pl[1]);
 				var v = getPropType(pl[1]);
 				if( k == null || v == null ) return null;
 				if( k == null || v == null ) return null;
+				isProxy = true;
 				PMap(k,v);
 				PMap(k,v);
 			case name:
 			case name:
 				var t2 = Context.followWithAbstracts(t, true);
 				var t2 = Context.followWithAbstracts(t, true);
@@ -171,8 +174,11 @@ class Macros {
 			case name if( StringTools.startsWith(name, "hxd.net.ObjProxy_") ):
 			case name if( StringTools.startsWith(name, "hxd.net.ObjProxy_") ):
 				var fields = c.get().fields.get();
 				var fields = c.get().fields.get();
 				for( f in fields )
 				for( f in fields )
-					if( f.name == "__value" )
-						return getPropType(f.type);
+					if( f.name == "__value" ) {
+						var t = getPropType(f.type);
+						t.isProxy = true;
+						return t;
+					}
 				throw "assert";
 				throw "assert";
 			default:
 			default:
 				if( isSerializable(c) )
 				if( isSerializable(c) )
@@ -198,10 +204,12 @@ class Macros {
 		default:
 		default:
 			return null;
 			return null;
 		}
 		}
-		return {
+		var p : PropType = {
 			d : desc,
 			d : desc,
 			t : t.toComplexType(),
 			t : t.toComplexType(),
 		};
 		};
+		if( isProxy ) p.isProxy = isProxy;
+		return p;
 	}
 	}
 
 
 	static function isNullable( t : PropType ) {
 	static function isNullable( t : PropType ) {
@@ -604,7 +612,7 @@ class Macros {
 	}
 	}
 
 
 	static function needProxy( t : PropType ) {
 	static function needProxy( t : PropType ) {
-		if( t == null )
+		if( t == null || t.isProxy )
 			return false;
 			return false;
 		switch( t.d ) {
 		switch( t.d ) {
 		case PMap(_), PArray(_), PObj(_):
 		case PMap(_), PArray(_), PObj(_):
@@ -614,6 +622,13 @@ class Macros {
 		}
 		}
 	}
 	}
 
 
+	static function checkProxy( p : PropType ) {
+		if( needProxy(p) ) {
+			p.isProxy = true;
+			p.t = toProxy(p);
+		}
+	}
+
 	static function toProxy( p : PropType ) {
 	static function toProxy( p : PropType ) {
 		if( !p.isProxy )
 		if( !p.isProxy )
 			return p.t;
 			return p.t;
@@ -763,7 +778,6 @@ class Macros {
 			var fname = f.f.name;
 			var fname = f.f.name;
 			var bitID = startFID++;
 			var bitID = startFID++;
 			var ftype : PropType;
 			var ftype : PropType;
-			var proxy = false;
 			switch( f.f.kind ) {
 			switch( f.f.kind ) {
 			case FVar(t, e):
 			case FVar(t, e):
 				if( t == null ) t = quickInferType(e);
 				if( t == null ) t = quickInferType(e);
@@ -771,10 +785,7 @@ class Macros {
 				var tt = Context.resolveType(t, pos);
 				var tt = Context.resolveType(t, pos);
 				ftype = getPropField(tt, f.f.meta);
 				ftype = getPropField(tt, f.f.meta);
 				if( ftype == null ) ftype = { t : t, d : PUnknown };
 				if( ftype == null ) ftype = { t : t, d : PUnknown };
-				if( needProxy(ftype) ) {
-					proxy = true;
-					ftype.t = toProxy(ftype);
-				}
+				checkProxy(ftype);
 				f.f.kind = FProp("default", "set", ftype.t, e);
 				f.f.kind = FProp("default", "set", ftype.t, e);
 			case FProp(get, set, t, e):
 			case FProp(get, set, t, e):
 				if( t == null ) t = quickInferType(e);
 				if( t == null ) t = quickInferType(e);
@@ -782,10 +793,7 @@ class Macros {
 				var tt = Context.resolveType(t, pos);
 				var tt = Context.resolveType(t, pos);
 				ftype = getPropField(tt, f.f.meta);
 				ftype = getPropField(tt, f.f.meta);
 				if( ftype == null ) ftype = { t : t, d : PUnknown };
 				if( ftype == null ) ftype = { t : t, d : PUnknown };
-				if( needProxy(ftype) ) {
-					proxy = true;
-					ftype.t = toProxy(ftype);
-				}
+				checkProxy(ftype);
 				if( set == "null" )
 				if( set == "null" )
 					Context.warning("Null setter is not respected when using NetworkSerializable", pos);
 					Context.warning("Null setter is not respected when using NetworkSerializable", pos);
 				else if( set != "default" && set != "set" )
 				else if( set != "default" && set != "set" )
@@ -802,7 +810,7 @@ class Macros {
 				if( this.$fname != v ) {
 				if( this.$fname != v ) {
 					$markExpr;
 					$markExpr;
 					this.$fname = v;
 					this.$fname = v;
-					${if( proxy ) macro this.$fname.bindHost(this,$v{bitID}) else macro {}};
+					${if( ftype.isProxy ) macro this.$fname.bindHost(this,$v{bitID}) else macro {}};
 				};
 				};
 
 
 			var found = false;
 			var found = false;
@@ -1052,11 +1060,13 @@ class Macros {
 			return p.t;
 			return p.t;
 		switch( p.d ) {
 		switch( p.d ) {
 		case PArray(k):
 		case PArray(k):
-			var name = needProxy(k) ? "ArrayProxy2" : "ArrayProxy";
-			return TPath( { pack : ["hxd", "net"], name : "ArrayProxy", sub : name, params : [TPType(toProxy(k))] } );
+			checkProxy(k);
+			var name = k.isProxy ? "ArrayProxy2" : "ArrayProxy";
+			return TPath( { pack : ["hxd", "net"], name : "ArrayProxy", sub : name, params : [TPType(k.t)] } );
 		case PMap(k, v):
 		case PMap(k, v):
-			var name = needProxy(v) ? "MapProxy2" : "MapProxy";
-			return TPath( { pack : ["hxd", "net"], name : "MapProxy", sub : name, params : [TPType(k.t),TPType(toProxy(v))] } );
+			checkProxy(v);
+			var name = k.isProxy ? "MapProxy2" : "MapProxy";
+			return TPath( { pack : ["hxd", "net"], name : "MapProxy", sub : name, params : [TPType(k.t),TPType(v.t)] } );
 		case PObj(fields):
 		case PObj(fields):
 			// define type
 			// define type
 			var name = "ObjProxy_";
 			var name = "ObjProxy_";