Base class for computing size of C data types. The algorithm is implemented as a class to allow a particular implementation to fine tune the calculation. We need here an open recursion, since type is inherently recursive.

The entry method is the bits method.

method bits : Bap_c_type.t -> bits option

returns a size of the data type representation if type definition is complete. Otherwise None is returned. The size is computed with respect to padding and alignment restructions.

method alignment : Bap_c_type.t -> Bap.Std.size

alignment t calculates an alignment restriction for data type t. The default alignment rules are the following:

  • if type is scalar then the alignment is sizeof(t);
  • if type is elt[] then the alignment is sizeof(elt);
  • if type is structure or union, the the alignment of is the maximum alignment of a field;
  • if type is function, then alignment is equal to sizeof pointer
  • if type is void then alignment is 8 bits.
method padding : Bap_c_type.t -> bits -> Bap.Std.size option

padding t off computes a required padding at given offset that should be inserted before value of type t to satisfy the alignment restriction for t, as determined by the alignment method.

array spec if array spec is complete, then returns a product of the bitwidth of array size and array's element type, otherwise returns None

if spec is complete then returns a size of the biggest element, including padding

if spec is complete then returns a total size of the structure, including padding.

method integer : Bap_c_type.integer -> Bap.Std.size
method pointer : Bap.Std.addr_size
method enum : (string * int64 option) list -> Bap.Std.size
method real : Bap_c_type.real -> [ `r32 | `r64 | `r128 ]
method complex : Bap_c_type.complex -> Bap.Std.size
method floating : Bap_c_type.floating -> Bap.Std.size
method basic : Bap_c_type.basic -> Bap.Std.size
method scalar : Bap_c_type.scalar -> Bap.Std.size