From 5c09e9c3e4cb8cbe0065ba107bb200588fed22f1 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Fri, 13 Feb 2026 17:51:57 +0100 Subject: [PATCH] refact: consolidate redundant properties --- src/arch/z80/visitor/translator.py | 2 +- src/symbols/arrayaccess.py | 13 ++----------- src/symbols/call.py | 11 ++++++----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/arch/z80/visitor/translator.py b/src/arch/z80/visitor/translator.py index 41841be81..b01bd9da0 100644 --- a/src/arch/z80/visitor/translator.py +++ b/src/arch/z80/visitor/translator.py @@ -443,7 +443,7 @@ def visit_LETARRAYSUBSTR(self, node): self.runtime_call(RuntimeLabel.LETSUBSTR, 0) def visit_ARRAYACCESS(self, node): - yield self.visit(node.arglist) + yield self.visit(node.args) def visit_STRSLICE(self, node): yield self.visit(node.string) diff --git a/src/symbols/arrayaccess.py b/src/symbols/arrayaccess.py index f5bbe90da..d6c79bc6f 100644 --- a/src/symbols/arrayaccess.py +++ b/src/symbols/arrayaccess.py @@ -52,15 +52,6 @@ def entry(self, value: SymbolID): def type_(self): return self.entry.type_ - @property - def arglist(self) -> SymbolARGLIST: - return self.children[1] - - @arglist.setter - def arglist(self, value: SymbolARGLIST): - assert isinstance(value, SymbolARGLIST) - self.children[1] = value - @property def scope(self): return self.entry.scope @@ -80,7 +71,7 @@ def offset(self) -> int | None: offset = 0 # Now we must typecast each argument to a u16 (POINTER) type # i is the dimension ith index, b is the bound - for i, b in zip(self.arglist, self.entry.bounds): + for i, b in zip(self.args, self.entry.bounds): tmp = i.children[0] if check.is_number(tmp) or check.is_const(tmp): offset = offset * b.count + (tmp.value - b.lower) @@ -131,4 +122,4 @@ def make_node(cls, id_: str, arglist: SymbolARGLIST, lineno: int, filename: str) @classmethod def copy_from(cls, other: Self) -> Self | None: - return cls(entry=other.entry, arglist=other.arglist, lineno=other.lineno, filename=other.filename) + return cls(entry=other.entry, arglist=other.args, lineno=other.lineno, filename=other.filename) diff --git a/src/symbols/call.py b/src/symbols/call.py index f646b79cb..9cb789e20 100644 --- a/src/symbols/call.py +++ b/src/symbols/call.py @@ -33,7 +33,7 @@ class SymbolCALL(Symbol): def __init__(self, entry: SymbolID, arglist: Iterable[SymbolARGUMENT], lineno: int, filename: str): assert isinstance(entry, SymbolID) assert all(isinstance(x, SymbolARGUMENT) for x in arglist) - assert entry.class_ in (CLASS.array, CLASS.function, CLASS.sub, CLASS.unknown) + assert entry.class_ in {CLASS.array, CLASS.function, CLASS.sub, CLASS.unknown} super().__init__() self.entry = entry @@ -55,7 +55,7 @@ def __init__(self, entry: SymbolID, arglist: Iterable[SymbolARGUMENT], lineno: i arg.value.ref.is_dynamically_accessed = True @property - def entry(self): + def entry(self) -> SymbolID: return self.children[0] @entry.setter @@ -67,13 +67,13 @@ def entry(self, value: SymbolID): self.children[0] = value @property - def args(self): + def args(self) -> SymbolARGLIST: return self.children[1] @args.setter - def args(self, value): + def args(self, value: SymbolARGLIST): assert isinstance(value, SymbolARGLIST) - if self.children is None or not self.children: + if not self.children: self.children = [None] if len(self.children) < 2: @@ -104,6 +104,7 @@ def make_node(cls, id_: str, params, lineno: int, filename: str) -> Self | None: else: # All functions go to global scope by default if entry.token != "FUNCTION": entry = entry.to_function(lineno) + gl.SYMBOL_TABLE.move_to_global_scope(id_) result = cls(entry, params, lineno, filename) gl.FUNCTION_CALLS.append(result)