Merge pull request #1175 from crytic/dev-isdynamic

Type.is_dynamic
pull/1343/head
Feist Josselin 2 years ago committed by GitHub
commit 13a15d8fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      slither/core/solidity_types/array_type.py
  2. 4
      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. 4
      slither/core/solidity_types/type_alias.py
  7. 4
      slither/core/solidity_types/type_information.py
  8. 4
      slither/core/solidity_types/user_defined_type.py

@ -29,6 +29,10 @@ 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

@ -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,10 @@ 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"):

@ -35,6 +35,10 @@ class TypeInformation(Type):
""" """
return 32, True return 32, True
@property
def is_dynamic(self) -> bool:
raise NotImplementedError
def __str__(self): def __str__(self):
return f"type({self.type.name})" return f"type({self.type.name})"

@ -20,6 +20,10 @@ class UserDefinedType(Type):
super().__init__() super().__init__()
self._type = t self._type = t
@property
def is_dynamic(self) -> bool:
return False
@property @property
def type(self) -> Union["Contract", "Enum", "Structure"]: def type(self) -> Union["Contract", "Enum", "Structure"]:
return self._type return self._type

Loading…
Cancel
Save