Skip to content

Commit

Permalink
feat: add is_dynamic_size attribute to type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Oct 10, 2020
1 parent b1fbdcd commit 67f8890
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vyper/context/types/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class BaseTypeDefinition:
If `True`, the value of this object cannot be modified after assignment.
"""

is_dynamic_size = False

def __init__(
self,
location: DataLocation = DataLocation.UNSET,
Expand Down
8 changes: 8 additions & 0 deletions vyper/context/types/indexable/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def __init__(
def __repr__(self):
return f"{self.value_type}[{self.length}]"

@property
def is_dynamic_size(self):
return self.value_type.is_dynamic_size

def get_index_type(self, node):
if isinstance(node, vy_ast.Int):
if node.value < 0:
Expand Down Expand Up @@ -107,6 +111,10 @@ def __init__(self, value_type: Tuple[BaseTypeDefinition, ...]) -> None:
def __repr__(self):
return self._id

@property
def is_dynamic_size(self):
return any(i for i in self.self.value_type if i.is_dynamic_size)

def get_index_type(self, node):
if not isinstance(node, vy_ast.Int):
raise InvalidType("Tuple indexes must be literals", node)
Expand Down
4 changes: 4 additions & 0 deletions vyper/context/types/meta/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(
for key, type_ in members.items():
self.add_member(key, type_)

@property
def is_dynamic_size(self):
return any(i for i in self.members.values() if i.is_dynamic_size)

def compare_type(self, other):
return super().compare_type(other) and self._id == other._id

Expand Down
2 changes: 2 additions & 0 deletions vyper/context/types/value/array_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class _ArrayValueDefinition(ValueTypeDefinition):
is applied to a literal definition.
"""

is_dynamic_size = True

def __repr__(self):
return f"{self._id}[{self.length}]"

Expand Down

0 comments on commit 67f8890

Please sign in to comment.