mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 13:31:37 +00:00
Add mDefFileNo to Classes/Structs
This commit is contained in:
parent
f6128f0e9e
commit
5ba1e96d29
8 changed files with 32 additions and 23 deletions
|
@ -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);
|
assert(size >= Size);
|
||||||
PClass *type;
|
PClass *type;
|
||||||
|
@ -571,7 +571,7 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size, bool *newlycre
|
||||||
type->Size = size;
|
type->Size = size;
|
||||||
if (size != TentativeClass)
|
if (size != TentativeClass)
|
||||||
{
|
{
|
||||||
NewClassType(type);
|
NewClassType(type, fileno);
|
||||||
if (newlycreated) *newlycreated = true;
|
if (newlycreated) *newlycreated = true;
|
||||||
type->Virtuals = Virtuals;
|
type->Virtuals = Virtuals;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
~PClass();
|
~PClass();
|
||||||
void InsertIntoHash(bool native);
|
void InsertIntoHash(bool native);
|
||||||
DObject *CreateNew();
|
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 InitializeActorInfo();
|
||||||
void BuildFlatPointers();
|
void BuildFlatPointers();
|
||||||
|
|
|
@ -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)
|
: PContainerType(name, outer)
|
||||||
{
|
{
|
||||||
mDescriptiveName.Format("%sStruct<%s>", isnative? "Native" : "", name.GetChars());
|
mDescriptiveName.Format("%sStruct<%s>", isnative? "Native" : "", name.GetChars());
|
||||||
Size = 0;
|
Size = 0;
|
||||||
isNative = isnative;
|
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;
|
size_t bucket;
|
||||||
if (outer == nullptr) outer = Namespaces.GlobalNamespace;
|
if (outer == nullptr) outer = Namespaces.GlobalNamespace;
|
||||||
PType *stype = TypeTable.FindType(NAME_Struct, (intptr_t)outer, name.GetIndex(), &bucket);
|
PType *stype = TypeTable.FindType(NAME_Struct, (intptr_t)outer, name.GetIndex(), &bucket);
|
||||||
if (stype == nullptr)
|
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);
|
TypeTable.AddType(stype, NAME_Struct, (intptr_t)outer, name.GetIndex(), bucket);
|
||||||
}
|
}
|
||||||
return static_cast<PStruct *>(stype);
|
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);
|
assert(cls->VMType == nullptr);
|
||||||
Descriptor = cls;
|
Descriptor = cls;
|
||||||
|
@ -3284,6 +3285,7 @@ PClassType::PClassType(PClass *cls)
|
||||||
ScopeFlags = ParentType->ScopeFlags;
|
ScopeFlags = ParentType->ScopeFlags;
|
||||||
}
|
}
|
||||||
cls->VMType = this;
|
cls->VMType = this;
|
||||||
|
mDefFileNo = fileno;
|
||||||
mDescriptiveName.Format("Class<%s>", cls->TypeName.GetChars());
|
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;
|
size_t bucket;
|
||||||
PType *ptype = TypeTable.FindType(NAME_Object, 0, cls->TypeName.GetIndex(), &bucket);
|
PType *ptype = TypeTable.FindType(NAME_Object, 0, cls->TypeName.GetIndex(), &bucket);
|
||||||
if (ptype == nullptr)
|
if (ptype == nullptr)
|
||||||
{
|
{
|
||||||
ptype = new PClassType(cls);
|
ptype = new PClassType(cls, fileno);
|
||||||
TypeTable.AddType(ptype, NAME_Object, 0, cls->TypeName.GetIndex(), bucket);
|
TypeTable.AddType(ptype, NAME_Object, 0, cls->TypeName.GetIndex(), bucket);
|
||||||
}
|
}
|
||||||
return static_cast<PClassType *>(ptype);
|
return static_cast<PClassType *>(ptype);
|
||||||
|
|
|
@ -596,13 +596,14 @@ public:
|
||||||
class PStruct : public PContainerType
|
class PStruct : public PContainerType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PStruct(FName name, PTypeBase *outer, bool isnative = false);
|
PStruct(FName name, PTypeBase *outer, bool isnative = false, int fileno = 0);
|
||||||
|
|
||||||
bool isNative;
|
bool isNative;
|
||||||
bool isOrdered = false;
|
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.
|
// 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 *mConstructor = nullptr;
|
||||||
VMFunction *mDestructor = nullptr;
|
VMFunction *mDestructor = nullptr;
|
||||||
|
int mDefFileNo;
|
||||||
|
|
||||||
PField *AddField(FName name, PType *type, uint32_t flags=0) override;
|
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;
|
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:
|
public:
|
||||||
PClass *Descriptor;
|
PClass *Descriptor;
|
||||||
PClassType *ParentType;
|
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 *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;
|
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);
|
PPointer *NewPointer(PClass *type, bool isconst = false);
|
||||||
PClassPointer *NewClassPointer(PClass *restrict);
|
PClassPointer *NewClassPointer(PClass *restrict);
|
||||||
PEnum *NewEnum(FName name, PTypeBase *outer);
|
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);
|
PPrototype *NewPrototype(const TArray<PType *> &rettypes, const TArray<PType *> &argtypes);
|
||||||
PClassType *NewClassType(PClass *cls);
|
PClassType *NewClassType(PClass *cls, int fileno);
|
||||||
|
|
||||||
// Built-in types -----------------------------------------------------------
|
// Built-in types -----------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -720,11 +720,11 @@ void ZCCCompiler::CreateStructTypes()
|
||||||
}
|
}
|
||||||
else if (s->strct->Flags & ZCC_Native)
|
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
|
else
|
||||||
{
|
{
|
||||||
s->strct->Type = NewStruct(s->NodeName(), outer);
|
s->strct->Type = NewStruct(s->NodeName(), outer, false, AST.FileNo);
|
||||||
}
|
}
|
||||||
if (s->strct->Flags & ZCC_Version)
|
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());
|
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;
|
me->SourceLumpName = *c->cls->SourceName;
|
||||||
}
|
}
|
||||||
else
|
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);
|
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)
|
if (newclass == nullptr)
|
||||||
{
|
{
|
||||||
Error(c->cls, "Class name %s already exists", c->NodeName().GetChars());
|
Error(c->cls, "Class name %s already exists", c->NodeName().GetChars());
|
||||||
}
|
}
|
||||||
else
|
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());
|
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)
|
if (c->Type() == nullptr)
|
||||||
{
|
{
|
||||||
// create a placeholder so that the compiler can continue looking for errors.
|
// 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)
|
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());
|
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.
|
// 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());
|
c->cls->Symbol = Create<PSymbolType>(c->NodeName(), c->Type());
|
||||||
OutNamespace->Symbols.AddSymbol(c->cls->Symbol);
|
OutNamespace->Symbols.AddSymbol(c->cls->Symbol);
|
||||||
Classes.Push(c);
|
Classes.Push(c);
|
||||||
|
@ -944,7 +944,7 @@ void ZCCCompiler::CreateClassTypes()
|
||||||
for (auto c : OrigClasses)
|
for (auto c : OrigClasses)
|
||||||
{
|
{
|
||||||
Error(c->cls, "Class %s has circular inheritance", FName(c->NodeName()).GetChars());
|
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());
|
c->cls->Symbol = Create<PSymbolType>(c->NodeName(), c->Type());
|
||||||
OutNamespace->Symbols.AddSymbol(c->cls->Symbol);
|
OutNamespace->Symbols.AddSymbol(c->cls->Symbol);
|
||||||
Classes.Push(c);
|
Classes.Push(c);
|
||||||
|
|
|
@ -407,6 +407,10 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
|
||||||
int lumpnum = baselump;
|
int lumpnum = baselump;
|
||||||
auto fileno = fileSystem.GetFileContainer(lumpnum);
|
auto fileno = fileSystem.GetFileContainer(lumpnum);
|
||||||
|
|
||||||
|
FString file = fileSystem.GetFileFullPath(lumpnum);
|
||||||
|
|
||||||
|
state.FileNo = fileno;
|
||||||
|
|
||||||
if (TokenMap.CountUsed() == 0)
|
if (TokenMap.CountUsed() == 0)
|
||||||
{
|
{
|
||||||
InitTokenMap();
|
InitTokenMap();
|
||||||
|
|
|
@ -628,6 +628,7 @@ struct ZCC_AST
|
||||||
FMemArena SyntaxArena;
|
FMemArena SyntaxArena;
|
||||||
struct ZCC_TreeNode *TopNode;
|
struct ZCC_TreeNode *TopNode;
|
||||||
VersionInfo ParseVersion;
|
VersionInfo ParseVersion;
|
||||||
|
int FileNo;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ZCCParseState : public ZCC_AST
|
struct ZCCParseState : public ZCC_AST
|
||||||
|
|
|
@ -3539,11 +3539,11 @@ void FinishDehPatch ()
|
||||||
// Retry until we find a free name. This is unlikely to happen but not impossible.
|
// Retry until we find a free name. This is unlikely to happen but not impossible.
|
||||||
mysnprintf(typeNameBuilder, countof(typeNameBuilder), "DehackedPickup%d", nameindex++);
|
mysnprintf(typeNameBuilder, countof(typeNameBuilder), "DehackedPickup%d", nameindex++);
|
||||||
bool newlycreated;
|
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();
|
if (newlycreated) subclass->InitializeDefaults();
|
||||||
}
|
}
|
||||||
while (subclass == nullptr);
|
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);
|
AActor *defaults2 = GetDefaultByType (subclass);
|
||||||
memcpy ((void *)defaults2, (void *)defaults1, sizeof(AActor));
|
memcpy ((void *)defaults2, (void *)defaults1, sizeof(AActor));
|
||||||
|
|
Loading…
Reference in a new issue