Exemplo n.º 1
0
 def _array_handler(self, _cursor_type):
     """
     Handles all array types.
     Resolves it's element type and makes a Array typedesc.
     """
     # The element type has been previously declared
     # we need to get the canonical typedef, in some cases
     _type = _cursor_type.get_canonical()
     size = _type.get_array_size()
     if size == -1 and _type.kind == TypeKind.INCOMPLETEARRAY:
         size = 0
         # FIXME: Incomplete Array handling at end of record.
         # https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
         # FIXME VARIABLEARRAY DEPENDENTSIZEDARRAY
     _array_type = _type.get_array_element_type()  # .get_canonical()
     if self.is_fundamental_type(_array_type):
         _subtype = self.parse_cursor_type(_array_type)
     elif self.is_pointer_type(_array_type):
         # code.interact(local=locals())
         # pointers to POD have no declaration ??
         # FIXME test_struct_with_pointer x_n_t g[1]
         _subtype = self.parse_cursor_type(_array_type)
     elif self.is_array_type(_array_type):
         _subtype = self.parse_cursor_type(_array_type)
     else:
         _subtype_decl = _array_type.get_declaration()
         _subtype = self.parse_cursor(_subtype_decl)
         # if _subtype_decl.kind == CursorKind.NO_DECL_FOUND:
         #    pass
         #_subtype_name = self.get_unique_name(_subtype_decl)
         #_subtype = self.get_registered(_subtype_name)
     obj = typedesc.ArrayType(_subtype, size)
     obj.location = _subtype.location
     return obj
Exemplo n.º 2
0
 def ArrayType(self, attrs):
     # type, min?, max?
     typ = attrs["type"]
     min = attrs["min"]
     max = attrs["max"]
     if max == "ffffffffffffffff":
         max = "-1"
     return typedesc.ArrayType(typ, min, max)
Exemplo n.º 3
0
 def _make_padding(self,
                   members,
                   padding_nb,
                   offset,
                   length,
                   prev_member=None):
     """Make padding Fields for a specifed size."""
     name = 'PADDING_%d' % padding_nb
     padding_nb += 1
     log.debug("_make_padding: for %d bits", length)
     if (length % 8) != 0 or (prev_member is not None
                              and prev_member.is_bitfield):
         # add a padding to align with the bitfield type
         # then multiple bytes if required.
         # pad_length = (length % 8)
         typename = prev_member.type.name
         padding = typedesc.Field(
             name,
             typedesc.FundamentalType(typename, 1, 1),
             # offset, pad_length, is_bitfield=True)
             offset,
             length,
             is_bitfield=True,
             is_padding=True)
         members.append(padding)
         # check for multiple bytes
         # if (length//8) > 0:
         #    padding_nb = self._make_padding(members, padding_nb, offset+pad_length,
         #                            (length//8)*8, prev_member=padding)
         return padding_nb
     elif length > 8:
         pad_bytes = length / 8
         padding = typedesc.Field(name,
                                  typedesc.ArrayType(
                                      typedesc.FundamentalType(
                                          self.get_ctypes_name(
                                              TypeKind.CHAR_U), length, 1),
                                      pad_bytes),
                                  offset,
                                  length,
                                  is_padding=True)
         members.append(padding)
         return padding_nb
     # simple char padding
     padding = typedesc.Field(name,
                              typedesc.FundamentalType(
                                  self.get_ctypes_name(TypeKind.CHAR_U), 1,
                                  1),
                              offset,
                              length,
                              is_padding=True)
     members.append(padding)
     return padding_nb
Exemplo n.º 4
0
 def _make_padding(
         self, members, padding_nb, offset, length, prev_member=None):
     """Make padding Fields for a specifed size."""
     name = 'PADDING_%d' % padding_nb
     padding_nb += 1
     log.debug("_make_padding: for %d bits", length)
     if (length % 8) != 0 or (prev_member is not None and prev_member.is_bitfield):
         if length > 32:
             typename = "c_uint64"
         elif length > 16:
             typename = "c_uint32"
         elif length > 8:
             typename = "c_uint16"
         else:
             typename = "c_uint8"
         padding = typedesc.Field(name,
                                  typedesc.FundamentalType(typename, 1, 1),
                                  offset, length, is_bitfield=True, is_padding=True)
         members.append(padding)
         return padding_nb
     elif length > 8:
         pad_bytes = length // 8
         padding = typedesc.Field(name,
                                  typedesc.ArrayType(
                                      typedesc.FundamentalType(
                                          self.get_ctypes_name(TypeKind.CHAR_U), length, 1),
                                      pad_bytes),
                                  offset, length, is_padding=True)
         members.append(padding)
         return padding_nb
     # simple char padding
     padding = typedesc.Field(name,
                              typedesc.FundamentalType(
                                  self.get_ctypes_name(
                                      TypeKind.CHAR_U),
                                  1,
                                  1),
                              offset, length, is_padding=True)
     members.append(padding)
     return padding_nb