From 7e24f6b00c0bc4df12ce03ac2b5672f5914d10ed Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 7 Aug 2013 20:14:27 -0500 Subject: [PATCH] - Added NewStruct() function. --- src/dobjtype.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/dobjtype.h | 5 +++++ 2 files changed, 46 insertions(+) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index bcc68931ff..e9892ea2e9 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -899,6 +899,27 @@ PMap *NewMap(PType *keytype, PType *valuetype) IMPLEMENT_CLASS(PStruct) +//========================================================================== +// +// PStruct - Default Constructor +// +//========================================================================== + +PStruct::PStruct() +{ +} + +//========================================================================== +// +// PStruct - Parameterized Constructor +// +//========================================================================== + +PStruct::PStruct(FName name, DObject *outer) +: PNamedType(name, outer) +{ +} + //========================================================================== // // PStruct :: PropagateMark @@ -915,6 +936,26 @@ size_t PStruct::PropagateMark() return marked + Super::PropagateMark(); } +//========================================================================== +// +// NewStruct +// Returns a PStruct for the given name and container, making sure not to +// create duplicates. +// +//========================================================================== + +PStruct *NewStruct(FName name, DObject *outer) +{ + size_t bucket; + PType *stype = TypeTable.FindType(RUNTIME_CLASS(PStruct), (intptr_t)outer, (intptr_t)name, &bucket); + if (stype == NULL) + { + stype = new PStruct(name, outer); + TypeTable.AddType(stype, RUNTIME_CLASS(PStruct), (intptr_t)outer, (intptr_t)name, bucket); + } + return static_cast(stype); +} + /* PPrototype *************************************************************/ IMPLEMENT_CLASS(PPrototype) diff --git a/src/dobjtype.h b/src/dobjtype.h index 68ed6168dd..25e81ceb5d 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -412,10 +412,14 @@ class PStruct : public PNamedType { DECLARE_CLASS(PStruct, PNamedType); public: + PStruct(FName name, DObject *outer); + TArray Fields; PSymbolTable Symbols; size_t PropagateMark(); +protected: + PStruct(); }; class PPrototype : public PCompoundType @@ -585,6 +589,7 @@ PPointer *NewPointer(PType *type); PClassPointer *NewClassPointer(PClass *restrict); PClassWaitingForParent *NewUnknownClass(FName myname, FName parentname); PEnum *NewEnum(FName name, DObject *outer); +PStruct *NewStruct(FName name, DObject *outer); // Built-in types -----------------------------------------------------------