From 5ba1e96d29b6bc2393dfa694d2ca1d8221278ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Thu, 19 Jan 2023 23:58:16 -0300 Subject: [PATCH] Add mDefFileNo to Classes/Structs --- src/common/objects/dobjtype.cpp | 4 ++-- src/common/objects/dobjtype.h | 2 +- src/common/scripting/core/types.cpp | 14 ++++++++------ src/common/scripting/core/types.h | 10 ++++++---- src/common/scripting/frontend/zcc_compile.cpp | 16 ++++++++-------- src/common/scripting/frontend/zcc_parser.cpp | 4 ++++ src/common/scripting/frontend/zcc_parser.h | 1 + src/gamedata/d_dehacked.cpp | 4 ++-- 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/common/objects/dobjtype.cpp b/src/common/objects/dobjtype.cpp index 0ac7bc8add..549a9b1014 100644 --- a/src/common/objects/dobjtype.cpp +++ b/src/common/objects/dobjtype.cpp @@ -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; } diff --git a/src/common/objects/dobjtype.h b/src/common/objects/dobjtype.h index a21ab8c797..db3e5b9742 100644 --- a/src/common/objects/dobjtype.h +++ b/src/common/objects/dobjtype.h @@ -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(); diff --git a/src/common/scripting/core/types.cpp b/src/common/scripting/core/types.cpp index 838275dad5..41671a98fe 100644 --- a/src/common/scripting/core/types.cpp +++ b/src/common/scripting/core/types.cpp @@ -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(stype); @@ -3271,7 +3272,7 @@ PPrototype *NewPrototype(const TArray &rettypes, const TArray // //========================================================================== -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(ptype); diff --git a/src/common/scripting/core/types.h b/src/common/scripting/core/types.h index 03ac8d89ee..f4ac3447d6 100644 --- a/src/common/scripting/core/types.h +++ b/src/common/scripting/core/types.h @@ -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 &rettypes, const TArray &argtypes); -PClassType *NewClassType(PClass *cls); +PClassType *NewClassType(PClass *cls, int fileno); // Built-in types ----------------------------------------------------------- diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 4c8b54792c..ffba4c301d 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -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(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(c->NodeName(), c->Type()); OutNamespace->Symbols.AddSymbol(c->cls->Symbol); Classes.Push(c); diff --git a/src/common/scripting/frontend/zcc_parser.cpp b/src/common/scripting/frontend/zcc_parser.cpp index f1a3e8d1fe..cedeb53fb5 100644 --- a/src/common/scripting/frontend/zcc_parser.cpp +++ b/src/common/scripting/frontend/zcc_parser.cpp @@ -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(); diff --git a/src/common/scripting/frontend/zcc_parser.h b/src/common/scripting/frontend/zcc_parser.h index 69276b768c..25a60d9ad2 100644 --- a/src/common/scripting/frontend/zcc_parser.h +++ b/src/common/scripting/frontend/zcc_parser.h @@ -628,6 +628,7 @@ struct ZCC_AST FMemArena SyntaxArena; struct ZCC_TreeNode *TopNode; VersionInfo ParseVersion; + int FileNo; }; struct ZCCParseState : public ZCC_AST diff --git a/src/gamedata/d_dehacked.cpp b/src/gamedata/d_dehacked.cpp index 2351536162..442068a679 100644 --- a/src/gamedata/d_dehacked.cpp +++ b/src/gamedata/d_dehacked.cpp @@ -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(dehtype->CreateDerivedClass(typeNameBuilder, dehtype->Size, &newlycreated)); + subclass = static_cast(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));