super Custom Class check + null check optimization

This commit is contained in:
Jaime Humberto Macias Bustamante
2025-05-07 11:03:22 -07:00
parent 05577f7559
commit c7160d05fd
2 changed files with 23 additions and 9 deletions
+11 -3
View File
@@ -264,6 +264,7 @@ class Interp {
return switch(Tools.expr(e2))
{
// TODO: type check for custom classes
case EIdent("Class"):
Std.isOfType(expr1, Class);
case EIdent("Map") | EIdent("IMap"):
@@ -280,7 +281,10 @@ class Interp {
public function setVar(name:String, v:Dynamic):Void {
if (_inCustomClass && _proxy.superClass != null) {
if (_proxy.superHasField(name)) {
if (_proxy.superIsCustomClass) {
cast(_proxy.superClass, CustomClass).hset(name, v);
}
else if (_proxy.superHasField(name)) {
Reflect.setProperty(_proxy.superClass, name, v);
}
}
@@ -1790,8 +1794,12 @@ class Interp {
// Custom logic to handle super calls to prevent infinite recursion
if(_inCustomClass) {
// Force call super function.
if(o == _proxy.superClass)
return call(o, Reflect.field(_proxy.superClass, '_HX_SUPER__${f}'), args);
if(o == _proxy.superClass) {
if(_proxy.superIsCustomClass)
cast(_proxy.superClass, CustomClass).callFunction(f, args);
else
return call(o, Reflect.field(_proxy.superClass, '_HX_SUPER__${f}'), args);
}
}
else if (o is CustomClass) {
_nextCallObject = null;
+12 -6
View File
@@ -27,6 +27,10 @@ class CustomClass implements IHScriptCustomAccessBehaviour {
public var superClass:Dynamic;
public var superConstructor(default, null):Dynamic;
public var superIsCustomClass(get, never):Bool;
private function get_superIsCustomClass():Bool
return (superClass != null && superClass is CustomClass);
public var className(get, never):String;
private function get_className():String {
return __class.toString();
@@ -41,8 +45,8 @@ class CustomClass implements IHScriptCustomAccessBehaviour {
public var __allowSetGet:Bool = false;
private var isInline:Bool = false;
private var ogVariables:Map<String, Dynamic>;
private var isInline(default, null):Bool = false;
private var ogVariables(default, null):Map<String, Dynamic>;
public function new(__class:CustomClassDecl, args:Array<Dynamic>, ?extendFieldDecl:Map<String, Dynamic>, ?ogInterp:Interp, ?callNew:Bool = true) {
this.__class = __class;
@@ -235,7 +239,7 @@ class CustomClass implements IHScriptCustomAccessBehaviour {
// Field check
private function hasField(name:String):Bool {
return __cachedFieldDecls != null ? __cachedFieldDecls.exists(name) : false;
return __cachedFieldDecls.exists(name);
}
private function getField(name:String):FieldDecl {
@@ -243,15 +247,15 @@ class CustomClass implements IHScriptCustomAccessBehaviour {
}
private function hasVar(name:String):Bool {
return __cachedVarDecls != null ? __cachedVarDecls.exists(name) : false;
return __cachedVarDecls.exists(name);
}
private function getVar(name:String):VarDecl {
return __cachedVarDecls != null ? __cachedVarDecls.get(name) : null;
return __cachedVarDecls.get(name);
}
private function hasFunction(name:String):Bool {
return __cachedFunctionDecls != null ? __cachedFunctionDecls.exists(name) : false;
return __cachedFunctionDecls.exists(name);
}
private function getFunction(name:String):Function {
@@ -277,6 +281,8 @@ class CustomClass implements IHScriptCustomAccessBehaviour {
if (__superClassFieldList == null) {
var realFields = Reflect.fields(superClass).concat(Type.getInstanceFields(Type.getClass(superClass)));
__superClassFieldList = realFields;
// TODO: macro-based superclass iteration for Custom Class as superclass
}
return __superClassFieldList.indexOf(name) != -1;