Added NewPrototype() function

This commit is contained in:
Randy Heit 2013-08-09 22:48:02 -05:00
parent f18c7b8959
commit 3e46e6376c
2 changed files with 47 additions and 0 deletions

View file

@ -991,6 +991,27 @@ PStruct *NewStruct(FName name, DObject *outer)
IMPLEMENT_CLASS(PPrototype)
//==========================================================================
//
// PPrototype - Default Constructor
//
//==========================================================================
PPrototype::PPrototype()
{
}
//==========================================================================
//
// PPrototype - Parameterized Constructor
//
//==========================================================================
PPrototype::PPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes)
: ArgumentTypes(argtypes), ReturnTypes(rettypes)
{
}
//==========================================================================
//
// PPrototype :: IsMatch
@ -1031,6 +1052,27 @@ size_t PPrototype::PropagateMark()
Super::PropagateMark();
}
//==========================================================================
//
// NewPrototype
//
// Returns a PPrototype for the given return and argument types, making sure
// not to create duplicates.
//
//==========================================================================
PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes)
{
size_t bucket;
PType *proto = TypeTable.FindType(RUNTIME_CLASS(PPrototype), (intptr_t)&argtypes, (intptr_t)&rettypes, &bucket);
if (proto == NULL)
{
proto = new PPrototype(rettypes, argtypes);
TypeTable.AddType(proto, RUNTIME_CLASS(PPrototype), (intptr_t)&argtypes, (intptr_t)&rettypes, bucket);
}
return static_cast<PPrototype *>(proto);
}
/* PFunction **************************************************************/
IMPLEMENT_CLASS(PFunction)

View file

@ -425,12 +425,16 @@ class PPrototype : public PCompoundType
{
DECLARE_CLASS(PPrototype, PCompoundType);
public:
PPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
TArray<PType *> ArgumentTypes;
TArray<PType *> ReturnTypes;
size_t PropagateMark();
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
protected:
PPrototype();
};
// TBD: Should we really support overloading?
@ -589,6 +593,7 @@ PClassPointer *NewClassPointer(PClass *restrict);
PClassWaitingForParent *NewUnknownClass(FName myname, FName parentname);
PEnum *NewEnum(FName name, DObject *outer);
PStruct *NewStruct(FName name, DObject *outer);
PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
// Built-in types -----------------------------------------------------------