From 8dc11317dd72d0da5f18dbe0a85261444cd5c7d3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 12 Apr 2017 17:42:10 +0200 Subject: [PATCH] - Moved WriteFields into SymbolTable as well. --- src/dobjtype.cpp | 23 ++--------------------- src/scripting/symbols.cpp | 26 +++++++++++++++++++++++++- src/scripting/symbols.h | 1 + 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index b9ad1e57d1..bca6d7f103 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -2280,25 +2280,6 @@ PMap *NewMap(PType *keytype, PType *valuetype) IMPLEMENT_CLASS(PStruct, false, false) -//========================================================================== -// -// WriteFields -// -//========================================================================== - -static void WriteFields(FSerializer &ar, const void *addr, const TArray &fields) -{ - for (unsigned i = 0; i < fields.Size(); ++i) - { - const PField *field = fields[i]; - // Skip fields without or with native serialization - if (!(field->Flags & (VARF_Transient | VARF_Meta))) - { - field->Type->WriteValue(ar, field->SymbolName.GetChars(), (const uint8_t *)addr + field->Offset); - } - } -} - //========================================================================== // // PStruct - Default Constructor @@ -2369,7 +2350,7 @@ void PStruct::WriteValue(FSerializer &ar, const char *key,const void *addr) cons { if (ar.BeginObject(key)) { - WriteFields(ar, addr, Fields); + Symbols.WriteFields(ar, addr); ar.EndObject(); } } @@ -2642,7 +2623,7 @@ static void RecurseWriteFields(const PClass *type, FSerializer &ar, const void * key.Format("class:%s", type->TypeName.GetChars()); if (ar.BeginObject(key.GetChars())) { - WriteFields(ar, addr, type->Fields); + type->Symbols.WriteFields(ar, addr); ar.EndObject(); } break; diff --git a/src/scripting/symbols.cpp b/src/scripting/symbols.cpp index 8b641ac55b..57b5201134 100644 --- a/src/scripting/symbols.cpp +++ b/src/scripting/symbols.cpp @@ -265,11 +265,35 @@ PField *PSymbolTable::AddField(FName name, PType *type, uint32_t flags, unsigned return field; } +//========================================================================== +// +// PClass :: WriteFields +// +//========================================================================== + +void PSymbolTable::WriteFields(FSerializer &ar, const void *addr, const void *def) const +{ + auto it = MapType::ConstIterator(Symbols); + MapType::ConstPair *pair; + + while (it.NextPair(pair)) + { + const PField *field = dyn_cast(pair->Value); + // Skip fields without or with native serialization + if (field && !(field->Flags & (VARF_Transient | VARF_Meta))) + { + // todo: handle defaults in WriteValue + //auto defp = def == nullptr ? nullptr : (const uint8_t *)def + field->Offset; + field->Type->WriteValue(ar, field->SymbolName.GetChars(), (const uint8_t *)addr + field->Offset); + } + } +} + + //========================================================================== // // PClass :: ReadFields // -// This will need some changes later. //========================================================================== bool PSymbolTable::ReadFields(FSerializer &ar, void *addr, const char *TypeName) const diff --git a/src/scripting/symbols.h b/src/scripting/symbols.h index f21ec749ea..bc9053cb33 100644 --- a/src/scripting/symbols.h +++ b/src/scripting/symbols.h @@ -217,6 +217,7 @@ struct PSymbolTable PSymbol *AddSymbol (PSymbol *sym); PField *AddField(FName name, PType *type, uint32_t flags, unsigned &Size, unsigned *Align = nullptr); bool ReadFields(FSerializer &ar, void *addr, const char *TypeName) const; + void WriteFields(FSerializer &ar, const void *addr, const void *def = nullptr) const; // Similar to AddSymbol but always succeeds. Returns the symbol that used // to be in the table with this name, if any.