Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StateVariable location #2585

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions slither/core/variables/state_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StateVariable(ContractLevel, Variable):
def __init__(self) -> None:
super().__init__()
self._node_initialization: Optional["Node"] = None
self._location: Optional[str] = None

def is_declared_by(self, contract: "Contract") -> bool:
"""
Expand All @@ -21,6 +22,19 @@ def is_declared_by(self, contract: "Contract") -> bool:
"""
return self.contract == contract

def set_location(self, loc: str) -> None:
self._location = loc

@property
def location(self) -> Optional[str]:
"""
Variable Location
Can be default or transient
Returns:
(str)
"""
return self._location

# endregion
###################################################################################
###################################################################################
Expand Down
15 changes: 15 additions & 0 deletions slither/solc_parsing/variables/state_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ def underlying_variable(self) -> StateVariable:
# Todo: Not sure how to overcome this with mypy
assert isinstance(self._variable, StateVariable)
return self._variable

def _analyze_variable_attributes(self, attributes: Dict) -> None:
"""
Variable Location
Can be default or transient
"""
if "storageLocation" in attributes:
self.underlying_variable.set_location(attributes["storageLocation"])
else:
# We don't have to support legacy ast
# as transient location was added in 0.8.28
# and we know it must be default
self.underlying_variable.set_location("default")

super()._analyze_variable_attributes(attributes)