-
Notifications
You must be signed in to change notification settings - Fork 1k
#2586 use enum to track variable location instead of string #2682
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
Open
nsiregar
wants to merge
5
commits into
crytic:dev
Choose a base branch
from
nsiregar:2586-use-enum-track-var-location
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4cecb25
add VariableLocation enum for LocalVariable class
nsiregar f36d7dc
update state variable to use VariableLocation enum
nsiregar 2546eee
set comparison to enum value
nsiregar d2698c5
update test_ssa_generation property check
nsiregar 9ecc744
Merge branch 'dev' into 2586-use-enum-track-var-location
nsiregar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
from typing import Optional, TYPE_CHECKING | ||
|
||
from slither.core.variables.variable import Variable | ||
from slither.core.solidity_types.user_defined_type import UserDefinedType | ||
from slither.core.solidity_types.mapping_type import MappingType | ||
from slither.core.solidity_types.elementary_type import ElementaryType | ||
import enum | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from slither.core.declarations.structure import Structure | ||
from slither.core.solidity_types.elementary_type import ElementaryType | ||
from slither.core.solidity_types.mapping_type import MappingType | ||
from slither.core.solidity_types.user_defined_type import UserDefinedType | ||
from slither.core.variables.variable import Variable | ||
|
||
if TYPE_CHECKING: # type: ignore | ||
from slither.core.declarations import Function | ||
|
||
|
||
class VariableLocation(enum.Enum): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's missing a possible field |
||
MEMORY = "memory" | ||
CALLDATA = "calldata" | ||
STORAGE = "storage" | ||
REFERENCE_TO_STORAGE = "reference_to_storage" | ||
TRANSIENT = "transient" | ||
|
||
|
||
class LocalVariable(Variable): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
self._location: Optional[str] = None | ||
self._location: Optional[VariableLocation] = None | ||
self._function: Optional["Function"] = None | ||
|
||
def set_function(self, function: "Function") -> None: | ||
|
@@ -25,16 +33,16 @@ def function(self) -> "Function": | |
assert self._function | ||
return self._function | ||
|
||
def set_location(self, loc: str) -> None: | ||
def set_location(self, loc: VariableLocation) -> None: | ||
self._location = loc | ||
|
||
@property | ||
def location(self) -> Optional[str]: | ||
def location(self) -> Optional[VariableLocation]: | ||
""" | ||
Variable Location | ||
Can be storage/memory or default | ||
Returns: | ||
(str) | ||
(VariableLocation) | ||
""" | ||
return self._location | ||
|
||
|
@@ -53,14 +61,14 @@ def is_storage(self) -> bool: | |
# pylint: disable=import-outside-toplevel | ||
from slither.core.solidity_types.array_type import ArrayType | ||
|
||
if self.location == "memory": | ||
if self.location == VariableLocation.MEMORY.value: | ||
return False | ||
if self.location == "calldata": | ||
if self.location == VariableLocation.CALLDATA.value: | ||
return False | ||
# Use by slithIR SSA | ||
if self.location == "reference_to_storage": | ||
if self.location == VariableLocation.REFERENCE_TO_STORAGE.value: | ||
return False | ||
if self.location == "storage": | ||
if self.location == VariableLocation.STORAGE.value: | ||
return True | ||
|
||
if isinstance(self.type, (ArrayType, MappingType)): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please import only Enum from enum and not the entire module