From 5cee2b5803e66e3ea0faeb0ed7850f2c3716bea3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 3 Aug 2022 08:44:38 +0200 Subject: [PATCH] - fixed: The compile context for constant evaluation did not initialize its Version member. --- src/common/engine/sc_man.h | 10 +++++----- src/common/scripting/backend/codegen.cpp | 4 ++-- src/common/scripting/backend/codegen.h | 2 +- src/common/scripting/frontend/zcc_compile.cpp | 12 ++++++------ src/r_data/models.cpp | 2 +- src/scripting/decorate/thingdef_exp.cpp | 2 +- src/scripting/zscript/zcc_compile_doom.cpp | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/common/engine/sc_man.h b/src/common/engine/sc_man.h index a39b8f5c36..62b9f03343 100644 --- a/src/common/engine/sc_man.h +++ b/src/common/engine/sc_man.h @@ -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 }; } diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index efd3ac2378..04fdfe22df 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -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) { } diff --git a/src/common/scripting/backend/codegen.h b/src/common/scripting/backend/codegen.h index 0bf71e5a5c..39cc347ae4 100644 --- a/src/common/scripting/backend/codegen.h +++ b/src/common/scripting/backend/codegen.h @@ -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); diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 79b5feb801..16940339a4 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -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) diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index ae487687a8..cc7497dd7c 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -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(); } diff --git a/src/scripting/decorate/thingdef_exp.cpp b/src/scripting/decorate/thingdef_exp.cpp index 40e106baa1..2658ebe184 100644 --- a/src/scripting/decorate/thingdef_exp.cpp +++ b/src/scripting/decorate/thingdef_exp.cpp @@ -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); } diff --git a/src/scripting/zscript/zcc_compile_doom.cpp b/src/scripting/zscript/zcc_compile_doom.cpp index cc19533a17..4a6fa7dc91 100644 --- a/src/scripting/zscript/zcc_compile_doom.cpp +++ b/src/scripting/zscript/zcc_compile_doom.cpp @@ -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(sl->Duration);