- Added NewStruct() function.

This commit is contained in:
Randy Heit 2013-08-07 20:14:27 -05:00
parent 0ec33191aa
commit 7e24f6b00c
2 changed files with 46 additions and 0 deletions

View file

@ -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<PStruct *>(stype);
}
/* PPrototype *************************************************************/
IMPLEMENT_CLASS(PPrototype)

View file

@ -412,10 +412,14 @@ class PStruct : public PNamedType
{
DECLARE_CLASS(PStruct, PNamedType);
public:
PStruct(FName name, DObject *outer);
TArray<PField *> 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 -----------------------------------------------------------