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 virtual and override attribute in Function #2333

Merged
merged 2 commits into from
Mar 28, 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
40 changes: 40 additions & 0 deletions slither/core/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None:
self._pure: bool = False
self._payable: bool = False
self._visibility: Optional[str] = None
self._virtual: bool = False
self._overrides: Optional[List[int]] = None

self._is_implemented: Optional[bool] = None
self._is_empty: Optional[bool] = None
Expand Down Expand Up @@ -441,6 +443,44 @@ def payable(self) -> bool:
def payable(self, p: bool):
self._payable = p

# endregion
###################################################################################
###################################################################################
# region Virtual
###################################################################################
###################################################################################

@property
def virtual(self) -> bool:
"""
Note for Solidity < 0.6.0 it will always be false
bool: True if the function is virtual
"""
return self._virtual

@virtual.setter
def virtual(self, v: bool):
self._virtual = v

@property
def override(self) -> bool:
"""
Note for Solidity < 0.6.0 it will always be false
bool: True if the function overrides a base function
"""
return self._overrides is not None

@property
def overrides(self) -> Optional[List[int]]:
"""
Optional[List[int]]: List of the overridden functions id
"""
return self._overrides

@overrides.setter
def overrides(self, o: List[Tuple[str, str]]):
self._overrides = o

# endregion
###################################################################################
###################################################################################
Expand Down
11 changes: 9 additions & 2 deletions slither/solc_parsing/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ def _analyze_attributes(self) -> None:
else:
attributes = self._functionNotParsed["attributes"]

if "payable" in attributes:
self._function.payable = attributes["payable"]
if "stateMutability" in attributes:
if attributes["stateMutability"] == "payable":
self._function.payable = True
Expand Down Expand Up @@ -242,6 +240,15 @@ def _analyze_attributes(self) -> None:
if "payable" in attributes:
self._function.payable = attributes["payable"]

if "baseFunctions" in attributes:
overrides = []
for o in attributes["baseFunctions"]:
overrides.append(o)
self._function.overrides = overrides

if "virtual" in attributes:
self._function.virtual = attributes["virtual"]

def analyze_params(self) -> None:
# Can be re-analyzed due to inheritance
if self._params_was_analyzed:
Expand Down
Loading