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 []
+1 -1
View File
@@ -203,7 +203,7 @@ class Version1Format(ISFormatTable):
update = self._lookup_enum(dictionary['name'])
elif type_name == 'bitfield':
update = {'start_bit': dictionary['bit_position'], 'end_bit': dictionary['bit_length']}
update['subtype'] = self._interdict_to_template(dictionary['type'])
update['base_type'] = self._interdict_to_template(dictionary['type'])
native_template.update_vol(**update) # pylint: disable=W0142
return native_template
+2 -2
View File
@@ -46,10 +46,10 @@ class NativeTable(interfaces.symbols.NativeTableInterface):
additional = {"count": 0, "subtype": self.get_type('void')}
elif type_name == 'enum':
obj = objects.Enumeration
additional = {"subtype": self.get_type('int'), "choices": {}}
additional = {"base_type": self.get_type('int'), "choices": {}}
elif type_name == 'bitfield':
obj = objects.BitField
additional = {"start_bit": 0, "end_bit": 0}
additional = {"start_bit": 0, "end_bit": 0, "base_type": self.get_type('int')}
elif type_name == 'string':
obj = objects.String
additional = {"max_length": 0}