-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from leonardt/rebind-bv
Rebind bv
- Loading branch information
Showing
5 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from .adt_meta import BoundMeta | ||
from .bit_vector_abc import AbstractBitVectorMeta, AbstractBitVector | ||
|
||
from .util import _issubclass | ||
|
||
def rebind_bitvector(adt, bv_type: AbstractBitVectorMeta): | ||
if _issubclass(adt, AbstractBitVector): | ||
if adt.is_sized: | ||
return bv_type[adt.size] | ||
else: | ||
return bv_type | ||
elif isinstance(adt, BoundMeta): | ||
new_adt = adt | ||
for field in adt.fields: | ||
new_field = rebind_bitvector(field, bv_type) | ||
new_adt = new_adt.rebind(field, new_field) | ||
return new_adt | ||
else: | ||
return adt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters