- fixed: The compile context for constant evaluation did not initialize its Version member.

This commit is contained in:
Christoph Oelckers 2022-08-03 08:44:38 +02:00
parent f7f9746a0f
commit 5cee2b5803
7 changed files with 19 additions and 19 deletions

View file

@ -12,19 +12,19 @@ struct VersionInfo
uint16_t minor;
uint32_t revision;
bool operator <=(const VersionInfo& o) const
constexpr bool operator <=(const VersionInfo& o) const
{
return o.major > this->major || (o.major == this->major && o.minor > this->minor) || (o.major == this->major && o.minor == this->minor && o.revision >= this->revision);
}
bool operator >=(const VersionInfo& o) const
constexpr bool operator >=(const VersionInfo& o) const
{
return o.major < this->major || (o.major == this->major && o.minor < this->minor) || (o.major == this->major && o.minor == this->minor && o.revision <= this->revision);
}
bool operator > (const VersionInfo& o) const
constexpr bool operator > (const VersionInfo& o) const
{
return o.major < this->major || (o.major == this->major && o.minor < this->minor) || (o.major == this->major && o.minor == this->minor && o.revision < this->revision);
}
bool operator < (const VersionInfo& o) const
constexpr bool operator < (const VersionInfo& o) const
{
return o.major > this->major || (o.major == this->major && o.minor > this->minor) || (o.major == this->major && o.minor == this->minor && o.revision > this->revision);
}
@ -32,7 +32,7 @@ struct VersionInfo
};
// Cannot be a constructor because Lemon would puke on it.
inline VersionInfo MakeVersion(unsigned int ma, unsigned int mi, unsigned int re = 0)
constexpr VersionInfo MakeVersion(unsigned int ma, unsigned int mi, unsigned int re = 0)
{
return{ (uint16_t)ma, (uint16_t)mi, (uint32_t)re };
}

View file

@ -104,8 +104,8 @@ FCompileContext::FCompileContext(PNamespace *cg, PFunction *fnc, PPrototype *ret
if (fnc != nullptr) Class = fnc->OwningClass;
}
FCompileContext::FCompileContext(PNamespace *cg, PContainerType *cls, bool fromdecorate)
: ReturnProto(nullptr), Function(nullptr), Class(cls), FromDecorate(fromdecorate), StateIndex(-1), StateCount(0), Lump(-1), CurGlobals(cg)
FCompileContext::FCompileContext(PNamespace *cg, PContainerType *cls, bool fromdecorate, const VersionInfo& info)
: ReturnProto(nullptr), Function(nullptr), Class(cls), FromDecorate(fromdecorate), StateIndex(-1), StateCount(0), Lump(-1), CurGlobals(cg), Version(info)
{
}

View file

@ -93,7 +93,7 @@ struct FCompileContext
FString VersionString;
FCompileContext(PNamespace *spc, PFunction *func, PPrototype *ret, bool fromdecorate, int stateindex, int statecount, int lump, const VersionInfo &ver);
FCompileContext(PNamespace *spc, PContainerType *cls, bool fromdecorate); // only to be used to resolve constants!
FCompileContext(PNamespace *spc, PContainerType *cls, bool fromdecorate, const VersionInfo& ver); // only to be used to resolve constants!
PSymbol *FindInClass(FName identifier, PSymbolTable *&symt);
PSymbol *FindInSelfClass(FName identifier, PSymbolTable *&symt);

View file

@ -68,7 +68,7 @@ const char * ZCCCompiler::GetStringConst(FxExpression *ex, FCompileContext &ctx)
int ZCCCompiler::IntConstFromNode(ZCC_TreeNode *node, PContainerType *cls)
{
FCompileContext ctx(OutNamespace, cls, false);
FCompileContext ctx(OutNamespace, cls, false, mVersion);
FxExpression *ex = new FxIntCast(ConvertNode(node), false);
ex = ex->Resolve(ctx);
if (ex == nullptr) return 0;
@ -82,7 +82,7 @@ int ZCCCompiler::IntConstFromNode(ZCC_TreeNode *node, PContainerType *cls)
FString ZCCCompiler::StringConstFromNode(ZCC_TreeNode *node, PContainerType *cls)
{
FCompileContext ctx(OutNamespace, cls, false);
FCompileContext ctx(OutNamespace, cls, false, mVersion);
FxExpression *ex = new FxStringCast(ConvertNode(node));
ex = ex->Resolve(ctx);
if (ex == nullptr) return "";
@ -1144,7 +1144,7 @@ void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant)
bool ZCCCompiler::CompileConstant(ZCC_ConstantWork *work)
{
FCompileContext ctx(OutNamespace, work->cls, false);
FCompileContext ctx(OutNamespace, work->cls, false, mVersion);
FxExpression *exp = ConvertNode(work->node->Value);
try
{
@ -1185,7 +1185,7 @@ void ZCCCompiler::CompileArrays(ZCC_StructWork *work)
ConvertNodeList(values, sas->Values);
bool fail = false;
FCompileContext ctx(OutNamespace, work->Type(), false);
FCompileContext ctx(OutNamespace, work->Type(), false, mVersion);
char *destmem = (char *)ClassDataAllocator.Alloc(values.Size() * ztype->Align);
memset(destmem, 0, values.Size() * ztype->Align);
@ -2014,7 +2014,7 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize,
indices = std::move(fixedIndices);
}
FCompileContext ctx(OutNamespace, cls, false);
FCompileContext ctx(OutNamespace, cls, false, mVersion);
for (auto index : indices)
{
// There is no float->int casting here.
@ -2347,7 +2347,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
FxExpression *x = new FxTypeCast(ConvertNode(p->Default), type, false);
FCompileContext ctx(OutNamespace, c->Type(), false);
FCompileContext ctx(OutNamespace, c->Type(), false, mVersion);
x = x->Resolve(ctx);
if (x != nullptr)

View file

@ -280,7 +280,7 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
//[SM] - if we added any models for the frame to also render, then we also need to update modelsAmount for this smf
if (actor->modelData != nullptr)
{
if (actor->modelData->modelIDs.Size() > modelsamount)
if (actor->modelData->modelIDs.Size() > (unsigned)modelsamount)
modelsamount = actor->modelData->modelIDs.Size();
}

View file

@ -83,7 +83,7 @@ FxExpression *ParseExpression (FScanner &sc, PClassActor *cls, PNamespace *spc)
if (spc)
{
PClassType *vmtype = nullptr == cls ? nullptr : cls->VMType;
FCompileContext ctx(spc, vmtype, true);
FCompileContext ctx(spc, vmtype, true, MakeVersion(0,0));
data = data->Resolve(ctx);
}

View file

@ -242,7 +242,7 @@ void ZCCDoomCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *pr
const char * p = prop->params;
auto exp = property->Values;
FCompileContext ctx(OutNamespace, bag.Info->VMType, false);
FCompileContext ctx(OutNamespace, bag.Info->VMType, false, mVersion);
while (true)
{
FPropParam conv;
@ -425,7 +425,7 @@ void ZCCDoomCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *
}
auto exp = property->Values;
FCompileContext ctx(OutNamespace, bag.Info->VMType, false);
FCompileContext ctx(OutNamespace, bag.Info->VMType, false, mVersion);
for (auto f : prop->Variables)
{
void *addr;
@ -907,7 +907,7 @@ void ZCCDoomCompiler::CompileStates()
{
state.sprite = GetSpriteIndex(sl->Sprite->GetChars());
}
FCompileContext ctx(OutNamespace, c->Type(), false);
FCompileContext ctx(OutNamespace, c->Type(), false, mVersion);
if (CheckRandom(sl->Duration))
{
auto func = static_cast<ZCC_ExprFuncCall *>(sl->Duration);