diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 92e37333a2..45dc4ee48d 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -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 &rettypes, const TArray &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 &rettypes, const TArray &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(proto); +} + /* PFunction **************************************************************/ IMPLEMENT_CLASS(PFunction) diff --git a/src/dobjtype.h b/src/dobjtype.h index e3fb2603a0..a927a32989 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -425,12 +425,16 @@ class PPrototype : public PCompoundType { DECLARE_CLASS(PPrototype, PCompoundType); public: + PPrototype(const TArray &rettypes, const TArray &argtypes); + TArray ArgumentTypes; TArray 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 &rettypes, const TArray &argtypes); // Built-in types -----------------------------------------------------------