feat: which contracts' function defs are overridden with refs

pull/2376/head
alpharush 8 months ago
parent 86de16140d
commit 757d892517
  1. 12
      slither/core/declarations/function.py
  2. 13
      slither/solc_parsing/declarations/function.py
  3. 2
      slither/solc_parsing/slither_compilation_unit_solc.py

@ -127,7 +127,7 @@ class Function(SourceMapping, metaclass=ABCMeta): # pylint: disable=too-many-pu
self._payable: bool = False
self._visibility: Optional[str] = None
self._virtual: bool = False
self._overrides: Optional[List[int]] = None
self._overrides: List["Contract"] = []
self._is_implemented: Optional[bool] = None
self._is_empty: Optional[bool] = None
@ -463,22 +463,22 @@ class Function(SourceMapping, metaclass=ABCMeta): # pylint: disable=too-many-pu
self._virtual = v
@property
def override(self) -> bool:
def is_overriden(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
return len(self._overrides) > 0
@property
def overrides(self) -> Optional[List[int]]:
def overrides(self) -> List["Contract"]:
"""
Optional[List[int]]: List of the overridden functions id
List["Contract"]: List of which parent contracts' functions definitions are overridden
"""
return self._overrides
@overrides.setter
def overrides(self, o: List[Tuple[str, str]]):
def overrides(self, o: List["Contract"]):
self._overrides = o
# endregion

@ -240,10 +240,17 @@ class FunctionSolc(CallerContextExpression):
if "payable" in attributes:
self._function.payable = attributes["payable"]
if "baseFunctions" in attributes:
if "overrides" in attributes and isinstance(attributes["overrides"], dict):
overrides = []
for o in attributes["baseFunctions"]:
overrides.append(o)
for override in attributes["overrides"].get("overrides", []):
refId = override["referencedDeclaration"]
overridden_contract = self.slither_parser._contracts_by_id.get(refId, None)
if overridden_contract:
overridden_contract.add_reference_from_raw_source(
override["src"], self.compilation_unit
)
overrides.append(overridden_contract)
self._function.overrides = overrides
if "virtual" in attributes:

@ -79,7 +79,7 @@ class SlitherCompilationUnitSolc(CallerContextExpression):
self._compilation_unit: SlitherCompilationUnit = compilation_unit
self._contracts_by_id: Dict[int, ContractSolc] = {}
self._contracts_by_id: Dict[int, Contract] = {}
self._parsed = False
self._analyzed = False
self._is_compact_ast = False

Loading…
Cancel
Save