def __init__(self, field_role, name_for_methods, property_name, type_name, wrapper_pointer_name, field_template, size, default_value, custom_copy, custom_compare, mutable, getter_method_name, setter_method_name, initial_method_name, computed_style_custom_functions, **kwargs): name_source = NameStyleConverter(name_for_methods) self.name = name_source.to_class_data_member() self.property_name = property_name self.type_name = type_name self.wrapper_pointer_name = wrapper_pointer_name self.alignment_type = self.wrapper_pointer_name or self.type_name self.field_template = field_template self.size = size self.default_value = default_value self.custom_copy = custom_copy self.custom_compare = custom_compare self.mutable = mutable self.group = None # Method names self.getter_method_name = getter_method_name self.setter_method_name = setter_method_name self.internal_getter_method_name = name_source.to_function_name( suffix='internal') self.internal_mutable_method_name = name_source.to_function_name( prefix='mutable', suffix='internal') self.internal_setter_method_name = NameStyleConverter( setter_method_name).to_function_name(suffix='internal') self.initial_method_name = initial_method_name self.resetter_method_name = name_source.to_function_name( prefix='reset') self.computed_style_custom_functions = computed_style_custom_functions # Only bitfields have sizes. self.is_bit_field = self.size is not None # Field role: one of these must be true self.is_property = field_role == 'property' self.is_inherited_flag = field_role == 'inherited_flag' assert (self.is_property, self.is_inherited_flag).count(True) == 1, \ 'Field role has to be exactly one of: property, inherited_flag' if not self.is_inherited_flag: self.is_inherited = kwargs.pop('inherited') self.is_independent = kwargs.pop('independent') self.is_semi_independent_variable = kwargs.pop( 'semi_independent_variable') assert self.is_inherited or not self.is_independent, \ 'Only inherited fields can be independent' self.is_inherited_method_name = name_source.to_function_name( suffix=['is', 'inherited']) assert len(kwargs) == 0, \ 'Unexpected arguments provided to Field: ' + str(kwargs)
def __init__(self, name, subgroups, fields): self.name = name self.subgroups = subgroups self.fields = fields self.parent = None converter = NameStyleConverter(name or '') self.type_name = converter.to_class_name(prefix='style', suffix='data') self.member_name = converter.to_class_data_member(suffix='data') self.num_32_bit_words_for_bit_fields = _num_32_bit_words_for_bit_fields( field for field in fields if field.is_bit_field) # Recursively get all the fields in the subgroups as well self.all_fields = _flatten_list(subgroup.all_fields for subgroup in subgroups) + fields # Ensure that all fields/subgroups on this group link to it for field in fields: field.group = self for subgroup in subgroups: subgroup.parent = self
def _data_member_name(str_or_converter): converter = NameStyleConverter(str_or_converter) if type( str_or_converter) is str else str_or_converter return converter.to_class_data_member(prefix='is', suffix='enabled')