- do not declare PNamedType::Outer as DObject.

Ultimately we may have to get a fully qualified name out of this, so Outer should be a type that can handle this feature. The new class for this is currently used as base for PType and PSymbol so that PNamedType inherits from it and maybe later a namespace symbol can, too.
This commit is contained in:
Christoph Oelckers 2016-10-07 13:59:29 +02:00
parent ee66d22034
commit 06ca41f8b5
2 changed files with 46 additions and 14 deletions

View File

@ -670,6 +670,20 @@ void PNamedType::GetTypeIDs(intptr_t &id1, intptr_t &id2) const
id2 = TypeName;
}
//==========================================================================
//
// PNamedType :: QualifiedName
//
//==========================================================================
FString PNamedType::QualifiedName() const
{
FString out;
if (Outer != nullptr) out = Outer->QualifiedName();
out << "::" << TypeName;
return out;
}
/* PInt *******************************************************************/
IMPLEMENT_CLASS(PInt)
@ -1752,7 +1766,7 @@ PEnum::PEnum()
//
//==========================================================================
PEnum::PEnum(FName name, DObject *outer)
PEnum::PEnum(FName name, PTypeBase *outer)
: PNamedType(name, outer), ValueType(NULL)
{
}
@ -1766,7 +1780,7 @@ PEnum::PEnum(FName name, DObject *outer)
//
//==========================================================================
PEnum *NewEnum(FName name, DObject *outer)
PEnum *NewEnum(FName name, PTypeBase *outer)
{
size_t bucket;
PType *etype = TypeTable.FindType(RUNTIME_CLASS(PEnum), (intptr_t)outer, (intptr_t)name, &bucket);
@ -2149,7 +2163,7 @@ PStruct::PStruct()
//
//==========================================================================
PStruct::PStruct(FName name, DObject *outer)
PStruct::PStruct(FName name, PTypeBase *outer)
: PNamedType(name, outer)
{
}
@ -2310,7 +2324,7 @@ size_t PStruct::PropagateMark()
//
//==========================================================================
PStruct *NewStruct(FName name, DObject *outer)
PStruct *NewStruct(FName name, PTypeBase *outer)
{
size_t bucket;
PType *stype = TypeTable.FindType(RUNTIME_CLASS(PStruct), (intptr_t)outer, (intptr_t)name, &bucket);
@ -3360,6 +3374,7 @@ CCMD(typetable)
// Symbol tables ------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(PTypeBase);
IMPLEMENT_ABSTRACT_CLASS(PSymbol);
IMPLEMENT_CLASS(PSymbolConst);
IMPLEMENT_CLASS(PSymbolConstNumeric);

View File

@ -22,12 +22,28 @@ typedef std::pair<const class PType *, unsigned> FTypeAndOffset;
// Symbol information -------------------------------------------------------
class PSymbol : public DObject
class PTypeBase : public DObject
{
DECLARE_ABSTRACT_CLASS(PSymbol, DObject);
DECLARE_ABSTRACT_CLASS(PTypeBase, DObject)
public:
virtual FString QualifiedName() const
{
return "";
}
};
class PSymbol : public PTypeBase
{
DECLARE_ABSTRACT_CLASS(PSymbol, PTypeBase);
public:
virtual ~PSymbol();
virtual FString QualifiedName() const
{
return SymbolName.GetChars();
}
FName SymbolName;
protected:
@ -153,13 +169,13 @@ extern PSymbolTable GlobalSymbols;
struct ZCC_ExprConstant;
class PClassType;
class PType : public DObject
class PType : public PTypeBase
{
//DECLARE_ABSTRACT_CLASS_WITH_META(PType, DObject, PClassType);
// We need to unravel the _WITH_META macro, since PClassType isn't defined yet,
// and we can't define it until we've defined PClass. But we can't define that
// without defining PType.
DECLARE_ABSTRACT_CLASS(PType, DObject)
DECLARE_ABSTRACT_CLASS(PType, PTypeBase)
HAS_OBJECT_POINTERS;
protected:
enum { MetaClassNum = CLASSREG_PClassType };
@ -332,14 +348,15 @@ class PNamedType : public PCompoundType
DECLARE_ABSTRACT_CLASS(PNamedType, PCompoundType);
HAS_OBJECT_POINTERS;
public:
DObject *Outer; // object this type is contained within
PTypeBase *Outer; // object this type is contained within
FName TypeName; // this type's name
PNamedType() : Outer(NULL) {}
PNamedType(FName name, DObject *outer) : Outer(outer), TypeName(name) {}
PNamedType(FName name, PTypeBase *outer) : Outer(outer), TypeName(name) {}
virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
virtual FString QualifiedName() const;
};
// Basic types --------------------------------------------------------------
@ -533,7 +550,7 @@ class PEnum : public PNamedType
DECLARE_CLASS(PEnum, PNamedType);
HAS_OBJECT_POINTERS;
public:
PEnum(FName name, DObject *outer);
PEnum(FName name, PTypeBase *outer);
PType *ValueType;
TMap<FName, int> Values;
@ -610,7 +627,7 @@ class PStruct : public PNamedType
{
DECLARE_CLASS(PStruct, PNamedType);
public:
PStruct(FName name, DObject *outer);
PStruct(FName name, PTypeBase *outer);
TArray<PField *> Fields;
@ -822,8 +839,8 @@ PDynArray *NewDynArray(PType *type);
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);
PEnum *NewEnum(FName name, PTypeBase *outer);
PStruct *NewStruct(FName name, PTypeBase *outer);
PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
// Built-in types -----------------------------------------------------------