Added PStruct::AddField()

This commit is contained in:
Randy Heit 2013-08-08 22:16:13 -05:00
parent 476a98652c
commit 6c1f3a1396
2 changed files with 32 additions and 0 deletions

View file

@ -920,6 +920,34 @@ PStruct::PStruct(FName name, DObject *outer)
{
}
//==========================================================================
//
// PStruct :: AddField
//
// Appends a new field to the end of a struct.
//
//==========================================================================
PField *PStruct::AddField(FName name, PType *type)
{
PField *field = new PField(name, type);
// The new field is added to the end of this struct, alignment permitting.
field->FieldOffset = (Size + (type->Align - 1)) & ~(type->Align - 1);
// Enlarge this struct to enclose the new field.
Size = field->FieldOffset + type->Size;
// This struct's alignment is the same as the largest alignment of any of
// its fields.
Align = MAX(Align, type->Align);
Fields.Push(field);
Symbols.AddSymbol(field);
return field;
}
//==========================================================================
//
// PStruct :: PropagateMark

View file

@ -325,6 +325,8 @@ class PField : public PSymbol
DECLARE_CLASS(PField, PSymbol);
HAS_OBJECT_POINTERS
public:
PField(FName name, PType *type) : PSymbol(name), FieldOffset(0), FieldType(type) {}
unsigned int FieldOffset;
PType *FieldType;
};
@ -411,6 +413,8 @@ public:
TArray<PField *> Fields;
PSymbolTable Symbols;
PField *AddField(FName name, PType *type);
size_t PropagateMark();
protected:
PStruct();