WIP/PoC type.isdynamic

pull/1175/head
feliam 3 years ago
parent 75a9766c35
commit 9e9f0d9c26
  1. 5
      slither/core/solidity_types/array_type.py
  2. 6
      slither/core/solidity_types/elementary_type.py
  3. 4
      slither/core/solidity_types/function_type.py
  4. 4
      slither/core/solidity_types/mapping_type.py
  5. 5
      slither/core/solidity_types/type.py
  6. 3
      slither/core/solidity_types/type_alias.py
  7. 5
      slither/core/solidity_types/user_defined_type.py

@ -29,6 +29,11 @@ class ArrayType(Type):
def type(self) -> Type: def type(self) -> Type:
return self._type return self._type
@property
def is_dynamic(self) -> bool:
return self.length is None
@property @property
def length(self) -> Optional[Expression]: def length(self) -> Optional[Expression]:
return self._length return self._length

@ -163,6 +163,10 @@ class ElementaryType(Type):
t = "bytes1" t = "bytes1"
self._type = t self._type = t
@property
def is_dynamic(self) -> bool:
return self._type in ("bytes", "string")
@property @property
def type(self) -> str: def type(self) -> str:
return self._type return self._type
@ -188,7 +192,7 @@ class ElementaryType(Type):
return int(8) return int(8)
if t == "address": if t == "address":
return int(160) return int(160)
if t.startswith("bytes"): if t.startswith("bytes") and t != "bytes":
return int(t[len("bytes") :]) return int(t[len("bytes") :])
return None return None

@ -32,6 +32,10 @@ class FunctionType(Type):
def storage_size(self) -> Tuple[int, bool]: def storage_size(self) -> Tuple[int, bool]:
return 24, False return 24, False
@property
def is_dynamic(self) -> bool:
return False
def __str__(self): def __str__(self):
# Use x.type # Use x.type
# x.name may be empty # x.name may be empty

@ -23,6 +23,10 @@ class MappingType(Type):
def storage_size(self) -> Tuple[int, bool]: def storage_size(self) -> Tuple[int, bool]:
return 32, True return 32, True
@property
def is_dynamic(self) -> bool:
return True
def __str__(self): def __str__(self):
return f"mapping({str(self._from)} => {str(self._to)})" return f"mapping({str(self._from)} => {str(self._to)})"

@ -14,3 +14,8 @@ class Type(SourceMapping, metaclass=abc.ABCMeta):
:return: (int, bool) - the number of bytes this type will require, and whether it must start in :return: (int, bool) - the number of bytes this type will require, and whether it must start in
a new slot regardless of whether the current slot can still fit it a new slot regardless of whether the current slot can still fit it
""" """
@property
@abc.abstractmethod
def is_dynamic(self) -> bool:
""" True if the size of the type is dynamic"""

@ -22,6 +22,9 @@ class TypeAlias(Type):
def __hash__(self): def __hash__(self):
return hash(str(self)) return hash(str(self))
@property
def is_dynamic(self) -> bool:
return self.underlying_type.is_dynamic
class TypeAliasTopLevel(TypeAlias, TopLevel): class TypeAliasTopLevel(TypeAlias, TopLevel):
def __init__(self, underlying_type: Type, name: str, scope: "FileScope"): def __init__(self, underlying_type: Type, name: str, scope: "FileScope"):

@ -20,10 +20,15 @@ class UserDefinedType(Type):
super().__init__() super().__init__()
self._type = t self._type = t
@property
def is_dynamic(self) -> bool:
raise NotImplemented
@property @property
def type(self) -> Union["Contract", "Enum", "Structure"]: def type(self) -> Union["Contract", "Enum", "Structure"]:
return self._type return self._type
@property @property
def storage_size(self) -> Tuple[int, bool]: def storage_size(self) -> Tuple[int, bool]:
from slither.core.declarations.structure import Structure from slither.core.declarations.structure import Structure

Loading…
Cancel
Save