getter/setter for variables

This commit is contained in:
Jaime Humberto Macias Bustamante
2025-05-15 01:17:11 -07:00
parent 932e643dc9
commit 22d6404799
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -65,6 +65,9 @@ enum abstract ScriptObjectType(UInt8) {
class DeclaredVar {
public var r:Dynamic;
public var depth:Int;
// TODO: getter/setter for variables
public var getter:FieldPropertyAccess = null;
public var setter:FieldPropertyAccess = null;
}
@:structInit
@@ -878,7 +881,7 @@ class Interp {
};
customClassFields.push(fd);
case EVar(n, t, e, isPublic, isStatic, isPrivate, isFinal, isInline, getter, setter):
case EVar(n, t, e, isPublic, isStatic, _, isFinal, _, getter, setter):
var varAcc:Array<FieldAccess> = [];
if (isPublic) varAcc.push(APublic);
if (isStatic) varAcc.push(AStatic);
@@ -1020,7 +1023,7 @@ class Interp {
}
case EIdent(id):
return resolve(id);
case EVar(n, _, e, isPublic, isStatic):
case EVar(n, _, e, isPublic, isStatic, _, isFinal, _, getter, setter):
declared.push({n: n, old: locals.get(n), depth: depth});
locals.set(n, {r: (e == null) ? null : expr(e), depth: depth});
if (depth == 0) {
+1 -1
View File
@@ -902,7 +902,7 @@ class Parser {
error(ECustom("Property requires type-hint or initialization"), p1, tokenMax);
nextType = null;
mk(EVar(ident, t, e, nextIsPublic, nextIsStatic, nextIsPrivate, id == "final", nextIsInline), p1, (e == null) ? tokenMax : pmax(e));
mk(EVar(ident, t, e, nextIsPublic, nextIsStatic, nextIsPrivate, id == "final", nextIsInline, get, set), p1, (e == null) ? tokenMax : pmax(e));
case "while":
var econd = parseExpr();
var e = parseExpr();