Skip to content

Commit

Permalink
VirtualVariable: Add some accessors for type safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfish committed Jan 24, 2025
1 parent fcbd80f commit 08fdf83
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ailment/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,25 @@ def stack_offset(self) -> int:
def tmp_idx(self) -> int | None:
return self.oident if self.was_tmp else None

@property
def parameter_category(self) -> VirtualVariableCategory | None:
if self.was_parameter:
assert isinstance(self.oident, tuple)
return self.oident[0]
return None

@property
def parameter_reg_offset(self) -> int | None:
if self.was_parameter and self.parameter_category == VirtualVariableCategory.REGISTER:
return self.oident[1]
return None

@property
def parameter_stack_offset(self) -> int | None:
if self.was_parameter and self.parameter_category == VirtualVariableCategory.STACK:
return self.oident[1]
return None

def likes(self, other):
return (
isinstance(other, VirtualVariable)
Expand Down

0 comments on commit 08fdf83

Please sign in to comment.