Add mDefFileNo to Classes/Structs

This commit is contained in:
Ricardo Luís Vaz Silva 2023-01-19 23:58:16 -03:00 committed by Christoph Oelckers
parent f6128f0e9e
commit 5ba1e96d29
8 changed files with 32 additions and 23 deletions

View file

@ -531,7 +531,7 @@ void PClass::Derive(PClass *newclass, FName name)
//
//==========================================================================
PClass *PClass::CreateDerivedClass(FName name, unsigned int size, bool *newlycreated)
PClass *PClass::CreateDerivedClass(FName name, unsigned int size, bool *newlycreated, int fileno)
{
assert(size >= Size);
PClass *type;
@ -571,7 +571,7 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size, bool *newlycre
type->Size = size;
if (size != TentativeClass)
{
NewClassType(type);
NewClassType(type, fileno);
if (newlycreated) *newlycreated = true;
type->Virtuals = Virtuals;
}

View file

@ -80,7 +80,7 @@ public:
~PClass();
void InsertIntoHash(bool native);
DObject *CreateNew();
PClass *CreateDerivedClass(FName name, unsigned int size, bool *newlycreated = nullptr);
PClass *CreateDerivedClass(FName name, unsigned int size, bool *newlycreated = nullptr, int fileno = 0);
void InitializeActorInfo();
void BuildFlatPointers();

View file

@ -3009,12 +3009,13 @@ PMapIterator *NewMapIterator(PType *keyType, PType *valueType)
//
//==========================================================================
PStruct::PStruct(FName name, PTypeBase *outer, bool isnative)
PStruct::PStruct(FName name, PTypeBase *outer, bool isnative, int fileno)
: PContainerType(name, outer)
{
mDescriptiveName.Format("%sStruct<%s>", isnative? "Native" : "", name.GetChars());
Size = 0;
isNative = isnative;
mDefFileNo = fileno;
}
//==========================================================================
@ -3166,14 +3167,14 @@ PField *PStruct::AddNativeField(FName name, PType *type, size_t address, uint32_
//
//==========================================================================
PStruct *NewStruct(FName name, PTypeBase *outer, bool native)
PStruct *NewStruct(FName name, PTypeBase *outer, bool native, int fileno)
{
size_t bucket;
if (outer == nullptr) outer = Namespaces.GlobalNamespace;
PType *stype = TypeTable.FindType(NAME_Struct, (intptr_t)outer, name.GetIndex(), &bucket);
if (stype == nullptr)
{
stype = new PStruct(name, outer, native);
stype = new PStruct(name, outer, native, fileno);
TypeTable.AddType(stype, NAME_Struct, (intptr_t)outer, name.GetIndex(), bucket);
}
return static_cast<PStruct *>(stype);
@ -3271,7 +3272,7 @@ PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *>
//
//==========================================================================
PClassType::PClassType(PClass *cls)
PClassType::PClassType(PClass *cls, int fileno)
{
assert(cls->VMType == nullptr);
Descriptor = cls;
@ -3284,6 +3285,7 @@ PClassType::PClassType(PClass *cls)
ScopeFlags = ParentType->ScopeFlags;
}
cls->VMType = this;
mDefFileNo = fileno;
mDescriptiveName.Format("Class<%s>", cls->TypeName.GetChars());
}
@ -3317,13 +3319,13 @@ PField *PClassType::AddNativeField(FName name, PType *type, size_t address, uint
//
//==========================================================================
PClassType *NewClassType(PClass *cls)
PClassType *NewClassType(PClass *cls, int fileno)
{
size_t bucket;
PType *ptype = TypeTable.FindType(NAME_Object, 0, cls->TypeName.GetIndex(), &bucket);
if (ptype == nullptr)
{
ptype = new PClassType(cls);
ptype = new PClassType(cls, fileno);
TypeTable.AddType(ptype, NAME_Object, 0, cls->TypeName.GetIndex(), bucket);
}
return static_cast<PClassType *>(ptype);

View file

@ -596,13 +596,14 @@ public:
class PStruct : public PContainerType
{
public:
PStruct(FName name, PTypeBase *outer, bool isnative = false);
PStruct(FName name, PTypeBase *outer, bool isnative = false, int fileno = 0);
bool isNative;
bool isOrdered = false;
// Some internal structs require explicit construction and destruction of fields the VM cannot handle directly so use these two functions for it.
VMFunction *mConstructor = nullptr;
VMFunction *mDestructor = nullptr;
int mDefFileNo;
PField *AddField(FName name, PType *type, uint32_t flags=0) override;
PField *AddNativeField(FName name, PType *type, size_t address, uint32_t flags = 0, int bitvalue = 0) override;
@ -635,8 +636,9 @@ class PClassType : public PContainerType
public:
PClass *Descriptor;
PClassType *ParentType;
int mDefFileNo;
PClassType(PClass *cls = nullptr);
PClassType(PClass *cls = nullptr, int fileno = 0);
PField *AddField(FName name, PType *type, uint32_t flags = 0) override;
PField *AddNativeField(FName name, PType *type, size_t address, uint32_t flags = 0, int bitvalue = 0) override;
};
@ -657,9 +659,9 @@ PPointer *NewPointer(PType *type, bool isconst = false);
PPointer *NewPointer(PClass *type, bool isconst = false);
PClassPointer *NewClassPointer(PClass *restrict);
PEnum *NewEnum(FName name, PTypeBase *outer);
PStruct *NewStruct(FName name, PTypeBase *outer, bool native = false);
PStruct *NewStruct(FName name, PTypeBase *outer, bool native = false, int fileno = 0);
PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
PClassType *NewClassType(PClass *cls);
PClassType *NewClassType(PClass *cls, int fileno);
// Built-in types -----------------------------------------------------------

View file

@ -720,11 +720,11 @@ void ZCCCompiler::CreateStructTypes()
}
else if (s->strct->Flags & ZCC_Native)
{
s->strct->Type = NewStruct(s->NodeName(), outer, true);
s->strct->Type = NewStruct(s->NodeName(), outer, true, AST.FileNo);
}
else
{
s->strct->Type = NewStruct(s->NodeName(), outer);
s->strct->Type = NewStruct(s->NodeName(), outer, false, AST.FileNo);
}
if (s->strct->Flags & ZCC_Version)
{
@ -832,7 +832,7 @@ void ZCCCompiler::CreateClassTypes()
{
DPrintf(DMSG_SPAMMY, "Registered %s as native with parent %s\n", me->TypeName.GetChars(), parent->TypeName.GetChars());
}
c->cls->Type = NewClassType(me);
c->cls->Type = NewClassType(me, AST.FileNo);
me->SourceLumpName = *c->cls->SourceName;
}
else
@ -844,14 +844,14 @@ void ZCCCompiler::CreateClassTypes()
{
Error(c->cls, "Parent class %s of %s not accessible to ZScript version %d.%d.%d", parent->TypeName.GetChars(), c->NodeName().GetChars(), mVersion.major, mVersion.minor, mVersion.revision);
}
auto newclass = parent->CreateDerivedClass(c->NodeName(), TentativeClass);
auto newclass = parent->CreateDerivedClass(c->NodeName(), TentativeClass, nullptr, AST.FileNo);
if (newclass == nullptr)
{
Error(c->cls, "Class name %s already exists", c->NodeName().GetChars());
}
else
{
c->cls->Type = NewClassType(newclass);
c->cls->Type = NewClassType(newclass, AST.FileNo);
DPrintf(DMSG_SPAMMY, "Created class %s with parent %s\n", c->Type()->TypeName.GetChars(), c->ClassType()->ParentClass->TypeName.GetChars());
}
}
@ -864,7 +864,7 @@ void ZCCCompiler::CreateClassTypes()
if (c->Type() == nullptr)
{
// create a placeholder so that the compiler can continue looking for errors.
c->cls->Type = NewClassType(parent->FindClassTentative(c->NodeName()));
c->cls->Type = NewClassType(parent->FindClassTentative(c->NodeName()), AST.FileNo);
}
if (c->cls->Flags & ZCC_Abstract)
@ -928,7 +928,7 @@ void ZCCCompiler::CreateClassTypes()
{
Error(c->cls, "Class %s has unknown base class %s", c->NodeName().GetChars(), FName(c->cls->ParentName->Id).GetChars());
// create a placeholder so that the compiler can continue looking for errors.
c->cls->Type = NewClassType(RUNTIME_CLASS(DObject)->FindClassTentative(c->NodeName()));
c->cls->Type = NewClassType(RUNTIME_CLASS(DObject)->FindClassTentative(c->NodeName()), AST.FileNo);
c->cls->Symbol = Create<PSymbolType>(c->NodeName(), c->Type());
OutNamespace->Symbols.AddSymbol(c->cls->Symbol);
Classes.Push(c);
@ -944,7 +944,7 @@ void ZCCCompiler::CreateClassTypes()
for (auto c : OrigClasses)
{
Error(c->cls, "Class %s has circular inheritance", FName(c->NodeName()).GetChars());
c->cls->Type = NewClassType(RUNTIME_CLASS(DObject)->FindClassTentative(c->NodeName()));
c->cls->Type = NewClassType(RUNTIME_CLASS(DObject)->FindClassTentative(c->NodeName()), AST.FileNo);
c->cls->Symbol = Create<PSymbolType>(c->NodeName(), c->Type());
OutNamespace->Symbols.AddSymbol(c->cls->Symbol);
Classes.Push(c);

View file

@ -407,6 +407,10 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
int lumpnum = baselump;
auto fileno = fileSystem.GetFileContainer(lumpnum);
FString file = fileSystem.GetFileFullPath(lumpnum);
state.FileNo = fileno;
if (TokenMap.CountUsed() == 0)
{
InitTokenMap();

View file

@ -628,6 +628,7 @@ struct ZCC_AST
FMemArena SyntaxArena;
struct ZCC_TreeNode *TopNode;
VersionInfo ParseVersion;
int FileNo;
};
struct ZCCParseState : public ZCC_AST

View file

@ -3539,11 +3539,11 @@ void FinishDehPatch ()
// Retry until we find a free name. This is unlikely to happen but not impossible.
mysnprintf(typeNameBuilder, countof(typeNameBuilder), "DehackedPickup%d", nameindex++);
bool newlycreated;
subclass = static_cast<PClassActor *>(dehtype->CreateDerivedClass(typeNameBuilder, dehtype->Size, &newlycreated));
subclass = static_cast<PClassActor *>(dehtype->CreateDerivedClass(typeNameBuilder, dehtype->Size, &newlycreated, 0));
if (newlycreated) subclass->InitializeDefaults();
}
while (subclass == nullptr);
NewClassType(subclass); // This needs a VM type to work as intended.
NewClassType(subclass, 0); // This needs a VM type to work as intended.
AActor *defaults2 = GetDefaultByType (subclass);
memcpy ((void *)defaults2, (void *)defaults1, sizeof(AActor));