Skip to content

Commit

Permalink
remove @:overload from Reflect.makeVarArgs (#11853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn authored Dec 5, 2024
1 parent dbce1dc commit f1fd471
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 288 deletions.
3 changes: 1 addition & 2 deletions std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,5 @@ extern class Reflect {
Transform a function taking an array of arguments into a function that can
be called with any number of arguments.
**/
@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic;
static function makeVarArgs<T>(f:Array<Dynamic>->T):Dynamic;
}
100 changes: 45 additions & 55 deletions std/cpp/_std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ import cpp.ObjectType;
@:coreApi
@:analyzer(ignore)
class Reflect {
public static function hasField(o:Dynamic, field:String):Bool
untyped {
return o != null && o.__HasField(field);
}
public static function hasField(o:Dynamic, field:String):Bool untyped {
return o != null && o.__HasField(field);
}

public static function field(o:Dynamic, field:String):Dynamic
untyped {
return (o == null) ? null : o.__Field(field, untyped __cpp__("::hx::paccNever"));
}
public static function field(o:Dynamic, field:String):Dynamic untyped {
return (o == null) ? null : o.__Field(field, untyped __cpp__("::hx::paccNever"));
}

public static function setField(o:Dynamic, field:String, value:Dynamic):Void
untyped {
if (o != null)
o.__SetField(field, value, untyped __cpp__("::hx::paccNever"));
}
public static function setField(o:Dynamic, field:String, value:Dynamic):Void untyped {
if (o != null)
o.__SetField(field, value, untyped __cpp__("::hx::paccNever"));
}

public static function getProperty(o:Dynamic, field:String):Dynamic {
return (o == null) ? null : o.__Field(field, untyped __cpp__("::hx::paccAlways"));
Expand All @@ -50,32 +47,29 @@ class Reflect {
o.__SetField(field, value, untyped __cpp__("::hx::paccAlways"));
}

public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic
untyped {
if (func != null && func.__GetType() == ObjectType.vtString) {
if (o == null)
throw cpp.ErrorConstants.invalidObject;
func = o.__Field(func, untyped __cpp__("::hx::paccDynamic"));
}
if (func == null)
throw cpp.ErrorConstants.nullFunctionPointer;
untyped func.__SetThis(o);
return untyped func.__Run(args);
}

public static function fields(o:Dynamic):Array<String>
untyped {
public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic untyped {
if (func != null && func.__GetType() == ObjectType.vtString) {
if (o == null)
return new Array();
var a:Array<String> = [];
o.__GetFields(a);
return a;
throw cpp.ErrorConstants.invalidObject;
func = o.__Field(func, untyped __cpp__("::hx::paccDynamic"));
}
if (func == null)
throw cpp.ErrorConstants.nullFunctionPointer;
untyped func.__SetThis(o);
return untyped func.__Run(args);
}

public static function isFunction(f:Dynamic):Bool
untyped {
return f != null && f.__GetType() == ObjectType.vtFunction;
}
public static function fields(o:Dynamic):Array<String> untyped {
if (o == null)
return new Array();
var a:Array<String> = [];
o.__GetFields(a);
return a;
}

public static function isFunction(f:Dynamic):Bool untyped {
return f != null && f.__GetType() == ObjectType.vtFunction;
}

public static function compare<T>(a:T, b:T):Int {
return (a == b) ? 0 : (((a : Dynamic) > (b : Dynamic)) ? 1 : -1);
Expand All @@ -89,25 +83,22 @@ class Reflect {
return untyped __global__.__hxcpp_same_closure(f1, f2);
}

public static function isObject(v:Dynamic):Bool
untyped {
if (v == null)
return false;
var t:Int = v.__GetType();
return t == ObjectType.vtObject || t == ObjectType.vtClass || t == ObjectType.vtString || t == ObjectType.vtArray;
}
public static function isObject(v:Dynamic):Bool untyped {
if (v == null)
return false;
var t:Int = v.__GetType();
return t == ObjectType.vtObject || t == ObjectType.vtClass || t == ObjectType.vtString || t == ObjectType.vtArray;
}

public static function isEnumValue(v:Dynamic):Bool
untyped {
return v != null && v.__GetType() == ObjectType.vtEnum;
}
public static function isEnumValue(v:Dynamic):Bool untyped {
return v != null && v.__GetType() == ObjectType.vtEnum;
}

public static function deleteField(o:Dynamic, field:String):Bool
untyped {
if (o == null)
return false;
return untyped __global__.__hxcpp_anon_remove(o, field);
}
public static function deleteField(o:Dynamic, field:String):Bool untyped {
if (o == null)
return false;
return untyped __global__.__hxcpp_anon_remove(o, field);
}

public static function copy<T>(o:Null<T>):Null<T> {
if (o == null)
Expand All @@ -122,8 +113,7 @@ class Reflect {
return o2;
}

@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
public static function makeVarArgs<T>(f:Array<Dynamic>->T):Dynamic {
return untyped __global__.__hxcpp_create_var_args(f);
}
}
123 changes: 56 additions & 67 deletions std/flash/_std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,57 @@
* DEALINGS IN THE SOFTWARE.
*/
@:coreApi class Reflect {
public static function hasField(o:Dynamic, field:String):Bool
untyped {
return o.hasOwnProperty(field);
}
public static function hasField(o:Dynamic, field:String):Bool untyped {
return o.hasOwnProperty(field);
}

public static function field(o:Dynamic, field:String):Dynamic
untyped {
return o != null && __in__(field, o) ? o[field] : null;
}
public static function field(o:Dynamic, field:String):Dynamic untyped {
return o != null && __in__(field, o) ? o[field] : null;
}

public inline static function setField(o:Dynamic, field:String, value:Dynamic):Void
untyped {
o[field] = value;
}
public inline static function setField(o:Dynamic, field:String, value:Dynamic):Void untyped {
o[field] = value;
}

public static function getProperty(o:Dynamic, field:String):Dynamic
untyped {
if (o == null)
return null;
var getter = 'get_$field';
if (__in__(getter, o)) {
return o[getter]();
}
return __in__(field, o) ? o[field] : null;
public static function getProperty(o:Dynamic, field:String):Dynamic untyped {
if (o == null)
return null;
var getter = 'get_$field';
if (__in__(getter, o)) {
return o[getter]();
}
return __in__(field, o) ? o[field] : null;
}

public static function setProperty(o:Dynamic, field:String, value:Dynamic):Void
untyped {
var setter = 'set_$field';
if (__in__(setter, o)) {
o[setter](value);
} else {
o[field] = value;
}
public static function setProperty(o:Dynamic, field:String, value:Dynamic):Void untyped {
var setter = 'set_$field';
if (__in__(setter, o)) {
o[setter](value);
} else {
o[field] = value;
}
}

public inline static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic
untyped {
return func.apply(o, args);
}
public inline static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic untyped {
return func.apply(o, args);
}

public static function fields(o:Dynamic):Array<String>
untyped {
if (o == null)
return new Array();
var i = 0;
var a = [];
while (untyped __has_next__(o, i)) {
var prop = untyped __forin__(o, i);
if (o.hasOwnProperty(prop))
a.push(prop);
}
return a;
public static function fields(o:Dynamic):Array<String> untyped {
if (o == null)
return new Array();
var i = 0;
var a = [];
while (untyped __has_next__(o, i)) {
var prop = untyped __forin__(o, i);
if (o.hasOwnProperty(prop))
a.push(prop);
}
return a;
}

public static function isFunction(f:Dynamic):Bool
untyped {
return __typeof__(f) == "function";
}
public static function isFunction(f:Dynamic):Bool untyped {
return __typeof__(f) == "function";
}

public static function compare<T>(a:T, b:T):Int {
var a:Dynamic = a;
Expand All @@ -90,28 +82,26 @@
return f1 == f2; // VM-level closures
}

public static function isObject(v:Dynamic):Bool
untyped {
if (v == null)
return false;
var t = __typeof__(v);
if (t == "object") {
return !isEnumValue(v);
}
return (t == "string");
public static function isObject(v:Dynamic):Bool untyped {
if (v == null)
return false;
var t = __typeof__(v);
if (t == "object") {
return !isEnumValue(v);
}
return (t == "string");
}

public static function isEnumValue(v:Dynamic):Bool {
return try v.__enum__ == true catch (e:Dynamic) false;
}

public static function deleteField(o:Dynamic, field:String):Bool
untyped {
if (o.hasOwnProperty(field) != true)
return false;
__delete__(o, field);
return true;
}
public static function deleteField(o:Dynamic, field:String):Bool untyped {
if (o.hasOwnProperty(field) != true)
return false;
__delete__(o, field);
return true;
}

public static function copy<T>(o:Null<T>):Null<T> {
if (o == null)
Expand All @@ -122,8 +112,7 @@
return o2;
}

@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
public static function makeVarArgs<T>(f:Array<Dynamic>->T):Dynamic {
return function(__arguments__) {
return f(__arguments__);
};
Expand Down
3 changes: 1 addition & 2 deletions std/hl/_std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ class Reflect {
return null;
}

@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
extern public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic;
extern public static function makeVarArgs<T>(f:Array<Dynamic>->T):Dynamic;

@:ifFeature("Reflect.makeVarArgs") static function _makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
return hl.Api.makeVarArgs(function(args:hl.NativeArray<Dynamic>) {
Expand Down
44 changes: 20 additions & 24 deletions std/js/_std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,33 @@
o[cast field] = value;
}

public static function getProperty(o:Dynamic, field:String):Dynamic
untyped {
var tmp;
return if (o == null) __define_feature__("Reflect.getProperty",
null) else if (o.__properties__ && (tmp = o.__properties__["get_" + field])) o[tmp]() else o[field];
}
public static function getProperty(o:Dynamic, field:String):Dynamic untyped {
var tmp;
return if (o == null) __define_feature__("Reflect.getProperty",
null) else if (o.__properties__ && (tmp = o.__properties__["get_" + field])) o[tmp]() else o[field];
}

public static function setProperty(o:Dynamic, field:String, value:Dynamic):Void
untyped {
var tmp;
if (o.__properties__ && (tmp = o.__properties__["set_" + field]))
o[tmp](value)
else
o[field] = __define_feature__("Reflect.setProperty", value);
}
public static function setProperty(o:Dynamic, field:String, value:Dynamic):Void untyped {
var tmp;
if (o.__properties__ && (tmp = o.__properties__["set_" + field]))
o[tmp](value)
else
o[field] = __define_feature__("Reflect.setProperty", value);
}

public inline static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic {
return (cast func : js.lib.Function).apply(o, args);
}

public static function fields(o:Dynamic):Array<String> {
var a = [];
if (o != null)
untyped {
var hasOwnProperty = js.lib.Object.prototype.hasOwnProperty;
js.Syntax.code("for( var f in o ) {");
if (f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o, f))
a.push(f);
js.Syntax.code("}");
}
if (o != null) untyped {
var hasOwnProperty = js.lib.Object.prototype.hasOwnProperty;
js.Syntax.code("for( var f in o ) {");
if (f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o, f))
a.push(f);
js.Syntax.code("}");
}
return a;
}

Expand Down Expand Up @@ -112,8 +109,7 @@
return o2;
}

@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
public static function makeVarArgs<T>(f:Array<Dynamic>->T):Dynamic {
return function() {
var a = untyped Array.prototype.slice.call(js.Syntax.code("arguments"));
return f(a);
Expand Down
Loading

0 comments on commit f1fd471

Please sign in to comment.