private void ComputeSequentialLayout(MosaType type)
{
Debug.Assert(type != null, @"No type given.");
if (typeSizes.ContainsKey(type))
return;
// Instance size
int typeSize = 0;
// Receives the size/alignment
int packingSize = type.PackingSize ?? NativePointerAlignment;
if (type.BaseType != null)
{
if (!type.IsValueType)
{
typeSize = GetTypeSize(type.BaseType);
}
}
foreach (MosaField field in type.Fields)
{
if (!field.IsStatic)
{
// Set the field address
fieldOffsets.Add(field, typeSize);
int fieldSize = GetFieldSize(field);
typeSize += fieldSize;
// Pad the field in the type
if (packingSize != 0)
{
int padding = (packingSize - (typeSize % packingSize)) % packingSize;
typeSize += padding;
}
}
}
typeSizes.Add(type, typeSize);
}