Add mDefFileNo to Fields

This commit is contained in:
Ricardo Luís Vaz Silva 2023-01-20 00:03:49 -03:00 committed by Christoph Oelckers
parent 5ba1e96d29
commit da06212134
5 changed files with 16 additions and 12 deletions

View file

@ -591,13 +591,13 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size, bool *newlycre
//
//==========================================================================
PField *PClass::AddField(FName name, PType *type, uint32_t flags)
PField *PClass::AddField(FName name, PType *type, uint32_t flags, int fileno)
{
PField *field;
if (!(flags & VARF_Meta))
{
unsigned oldsize = Size;
field = VMType->Symbols.AddField(name, type, flags, Size);
field = VMType->Symbols.AddField(name, type, flags, Size, nullptr, fileno);
// Only initialize the defaults if they have already been created.
// For ZScript this is not the case, it will first define all fields before
@ -612,7 +612,7 @@ PField *PClass::AddField(FName name, PType *type, uint32_t flags)
{
// Same as above, but a different data storage.
unsigned oldsize = MetaSize;
field = VMType->Symbols.AddField(name, type, flags, MetaSize);
field = VMType->Symbols.AddField(name, type, flags, MetaSize, nullptr, fileno);
if (field != nullptr && !(flags & VARF_Native) && Meta != nullptr)
{

View file

@ -45,7 +45,7 @@ public:
bool ReadAllFields(FSerializer &ar, void *addr) const;
int FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc, bool exactReturnType);
PSymbol *FindSymbol(FName symname, bool searchparents) const;
PField *AddField(FName name, PType *type, uint32_t flags);
PField *AddField(FName name, PType *type, uint32_t flags, int fileno = 0);
void InitializeDefaults();
static void StaticInit();

View file

@ -137,7 +137,6 @@ PField::PField()
{
}
PField::PField(FName name, PType *type, uint32_t flags, size_t offset, int bitvalue)
: PSymbol(name), Offset(offset), Type(type), Flags(flags)
{
@ -331,10 +330,12 @@ PSymbol *PSymbolTable::AddSymbol (PSymbol *sym)
//
//==========================================================================
PField *PSymbolTable::AddField(FName name, PType *type, uint32_t flags, unsigned &Size, unsigned *Align)
PField *PSymbolTable::AddField(FName name, PType *type, uint32_t flags, unsigned &Size, unsigned *Align, int fileno)
{
PField *field = Create<PField>(name, type, flags);
field->mDefFileNo = fileno;
// The new field is added to the end of this struct, alignment permitting.
field->Offset = (Size + (type->Align - 1)) & ~(type->Align - 1);
@ -365,10 +366,12 @@ PField *PSymbolTable::AddField(FName name, PType *type, uint32_t flags, unsigned
//
//==========================================================================
PField *PSymbolTable::AddNativeField(FName name, PType *type, size_t address, uint32_t flags, int bitvalue)
PField *PSymbolTable::AddNativeField(FName name, PType *type, size_t address, uint32_t flags, int bitvalue, int fileno)
{
PField *field = Create<PField>(name, type, flags | VARF_Native | VARF_Transient, address, bitvalue);
field->mDefFileNo = fileno;
if (AddSymbol(field) == nullptr)
{ // name is already in use
field->Destroy();

View file

@ -78,6 +78,7 @@ public:
uint32_t Flags;
int BitValue;
FString DeprecationMessage;
int mDefFileNo = 0;
protected:
PField();
};
@ -212,8 +213,8 @@ struct PSymbolTable
// a symbol with the same name is already in the table. This symbol is
// not copied and will be freed when the symbol table is destroyed.
PSymbol *AddSymbol (PSymbol *sym);
PField *AddField(FName name, PType *type, uint32_t flags, unsigned &Size, unsigned *Align = nullptr);
PField *AddNativeField(FName name, PType *type, size_t address, uint32_t flags, int bitvalue);
PField *AddField(FName name, PType *type, uint32_t flags, unsigned &Size, unsigned *Align = nullptr, int fileno = 0);
PField *AddNativeField(FName name, PType *type, size_t address, uint32_t flags, int bitvalue, int fileno = 0);
bool ReadFields(FSerializer &ar, void *addr, const char *TypeName) const;
void WriteFields(FSerializer &ar, const void *addr, const void *def = nullptr) const;

View file

@ -3156,7 +3156,7 @@ PField *PStruct::AddField(FName name, PType *type, uint32_t flags)
PField *PStruct::AddNativeField(FName name, PType *type, size_t address, uint32_t flags, int bitvalue)
{
return Symbols.AddNativeField(name, type, address, flags, bitvalue);
return Symbols.AddNativeField(name, type, address, flags, bitvalue, mDefFileNo);
}
//==========================================================================
@ -3297,7 +3297,7 @@ PClassType::PClassType(PClass *cls, int fileno)
PField *PClassType::AddField(FName name, PType *type, uint32_t flags)
{
return Descriptor->AddField(name, type, flags);
return Descriptor->AddField(name, type, flags, mDefFileNo);
}
//==========================================================================
@ -3308,7 +3308,7 @@ PField *PClassType::AddField(FName name, PType *type, uint32_t flags)
PField *PClassType::AddNativeField(FName name, PType *type, size_t address, uint32_t flags, int bitvalue)
{
auto field = Symbols.AddNativeField(name, type, address, flags, bitvalue);
auto field = Symbols.AddNativeField(name, type, address, flags, bitvalue, mDefFileNo);
if (field != nullptr) Descriptor->Fields.Push(field);
return field;
}