def _update_layout_with_field_attributes(self, layout, attributes):
    """A method that modifies a given layout with the given field attributes.

    Args:
      layout: an object representing a layout.
      attributes: a list of objects representing field attributes.
    """
    attributes_alignment = self._compound_type_bit_alignment()

    for attribute in attributes:
      if string_util.attribute_name_match(attribute.name, 'packed'):
        layout.bit_alignment = self._compound_type_bit_alignment()
      elif string_util.attribute_name_match(attribute.name, 'aligned'):
        byte_alignment = self._expression_evaluator.evaluate(
            expression=attribute.parameters[0],
        )
        attributes_alignment = self._lcm(
            attributes_alignment,
            8 * byte_alignment,
        )

    layout.bit_alignment = self._lcm(
        layout.bit_alignment,
        attributes_alignment,
    )
 def _get_attributes_alignment(self, attributes):
   bit_alignment = self._base_alignment()
   for attribute in attributes:
     if string_util.attribute_name_match(attribute.name, 'aligned'):
       expression = attribute.parameters[0]
       byte_alignment = self._expression_evaluator.evaluate(expression)
       bit_alignment = self._lcm(bit_alignment, 8 * byte_alignment)
   return bit_alignment
 def visit_c_typedef(self, typedef):
   layout = typedef.type_definition.accept(self)
   for attribute in typedef.attributes:
     if string_util.attribute_name_match(attribute.name, 'aligned'):
       expression = attribute.parameters[0]
       byte_alignment = self._expression_evaluator.evaluate(expression)
       layout.bit_alignment = 8 * byte_alignment
   return layout
Beispiel #4
0
 def _get_attributes_alignment(self, attributes):
     bit_alignment = self._base_alignment()
     for attribute in attributes:
         if string_util.attribute_name_match(attribute.name, 'aligned'):
             expression = attribute.parameters[0]
             byte_alignment = self._expression_evaluator.evaluate(
                 expression)
             bit_alignment = self._lcm(bit_alignment, 8 * byte_alignment)
     return bit_alignment
Beispiel #5
0
 def visit_c_typedef(self, typedef):
     layout = typedef.type_definition.accept(self)
     for attribute in typedef.attributes:
         if string_util.attribute_name_match(attribute.name, 'aligned'):
             expression = attribute.parameters[0]
             byte_alignment = self._expression_evaluator.evaluate(
                 expression)
             layout.bit_alignment = 8 * byte_alignment
     return layout
 def test_with_variants_of_the_same_name(self):
   variants = (
       'some_name',
       '__some_name',
       'some_name__',
       '__some_name__',
   )
   for variant1 in variants:
     for variant2 in variants:
       self.assertTrue(string_util.attribute_name_match(variant1, variant2))
 def test_with_variants_of_the_same_name(self):
     variants = (
         'some_name',
         '__some_name',
         'some_name__',
         '__some_name__',
     )
     for variant1 in variants:
         for variant2 in variants:
             self.assertTrue(
                 string_util.attribute_name_match(variant1, variant2))
    def _update_layout_with_field_attributes(self, layout, attributes):
        """A method that modifies a given layout with the given field attributes.

    Args:
      layout: an object representing a layout.
      attributes: a list of objects representing field attributes.
    """
        attributes_alignment = self._compound_type_bit_alignment()

        for attribute in attributes:
            if string_util.attribute_name_match(attribute.name, 'packed'):
                layout.bit_alignment = self._compound_type_bit_alignment()
            elif string_util.attribute_name_match(attribute.name, 'aligned'):
                byte_alignment = self._expression_evaluator.evaluate(
                    expression=attribute.parameters[0], )
                attributes_alignment = self._lcm(
                    attributes_alignment,
                    8 * byte_alignment,
                )

        layout.bit_alignment = self._lcm(
            layout.bit_alignment,
            attributes_alignment,
        )
 def test_with_variants_of_different_names(self):
   variants1 = (
       'some_name_1',
       '__some_name_1',
       'some_name_1__',
       '__some_name_1__',
   )
   variants2 = (
       'some_name_2',
       '__some_name_2',
       'some_name_2__',
       '__some_name_2__',
   )
   for variant1 in variants1:
     for variant2 in variants2:
       self.assertFalse(string_util.attribute_name_match(variant1, variant2))
 def test_with_variants_of_different_names(self):
     variants1 = (
         'some_name_1',
         '__some_name_1',
         'some_name_1__',
         '__some_name_1__',
     )
     variants2 = (
         'some_name_2',
         '__some_name_2',
         'some_name_2__',
         '__some_name_2__',
     )
     for variant1 in variants1:
         for variant2 in variants2:
             self.assertFalse(
                 string_util.attribute_name_match(variant1, variant2))
Beispiel #11
0
 def _is_alignment_overriden(self, type_definition):
     if hasattr(type_definition, 'attributes'):
         for attribute in type_definition.attributes:
             if string_util.attribute_name_match(attribute.name, 'aligned'):
                 return True
     return False
Beispiel #12
0
 def _is_packed(self, attributes):
     for attribute in attributes:
         if string_util.attribute_name_match(attribute.name, 'packed'):
             return True
     return False
 def _is_alignment_overriden(self, type_definition):
   if hasattr(type_definition, 'attributes'):
     for attribute in type_definition.attributes:
       if string_util.attribute_name_match(attribute.name, 'aligned'):
         return True
   return False
 def _is_packed(self, attributes):
   for attribute in attributes:
     if string_util.attribute_name_match(attribute.name, 'packed'):
       return True
   return False