Refactor BitField subtype to base_type to match enums (and fix a minor enum typo too).

This commit is contained in:
Mike Auty
2016-12-18 16:12:08 +00:00
parent 45d37bb961
commit 54678823f8
3 changed files with 12 additions and 12 deletions
+9 -9
View File
@@ -213,25 +213,25 @@ class Pointer(Integer):
class BitField(PrimitiveObject, int):
"""Object containing a field which is made up of bits rather than whole bytes"""
def __new__(cls, context, type_name, object_info, struct_format, subtype = None, start_bit = 0, end_bit = 0,
def __new__(cls, context, type_name, object_info, struct_format, base_type = None, start_bit = 0, end_bit = 0,
**kwargs):
cls._check_type(subtype, Integer)
value = subtype(context = context,
type_name = type_name,
object_info = object_info,
struct_format = struct_format)
cls._check_type(base_type, Integer)
value = base_type(context = context,
type_name = type_name,
object_info = object_info,
struct_format = struct_format)
return cls._struct_type.__new__(cls, (value >> start_bit) & ((1 << end_bit) - 1))
def __init__(self, context, type_name, object_info, struct_format, subtype = None, start_bit = 0, end_bit = 0):
def __init__(self, context, type_name, object_info, struct_format, base_type = None, start_bit = 0, end_bit = 0):
super().__init__(context, type_name, object_info, struct_format)
self._vol['subtype'] = subtype
self._vol['subtype'] = base_type
self._vol['start_bit'] = start_bit
self._vol['end_bit'] = end_bit
@classmethod
def _template_children(cls, template):
"""Returns the subtype"""
if 'subtype' in template.vol:
if 'base_type' in template.vol:
return [template.vol.subtype]
return []