From 7da4e0d03dfc68498e385ef42417db3289ae277e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 6 Nov 2016 23:10:23 +0100 Subject: [PATCH] - removed a parsing hack for the old internal definitions. - fixed: The state cast hack for DECORATE could not properly create state constants. Instead they were passed to FxRuntimeStateIndex without resolving them to something constant. This adds proper handling of constant indices within that class. --- src/scripting/codegeneration/codegen.cpp | 24 +++++++++++++++++++---- src/scripting/decorate/thingdef_parse.cpp | 8 ++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index 61b23cc158..fa9fe13c9b 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -8101,11 +8101,27 @@ FxExpression *FxRuntimeStateIndex::Resolve(FCompileContext &ctx) delete this; return nullptr; } - else if (Index->isConstant() && static_cast(Index)->GetValue().GetInt() <= 0) + else if (Index->isConstant()) { - ScriptPosition.Message(MSG_ERROR, "State index must be positive"); - delete this; - return nullptr; + int index = static_cast(Index)->GetValue().GetInt(); + if (index < 0 || (index == 0 && !ctx.FromDecorate)) + { + ScriptPosition.Message(MSG_ERROR, "State index must be positive"); + delete this; + return nullptr; + } + else if (index == 0) + { + auto x = new FxConstant((FState*)nullptr, ScriptPosition); + delete this; + return x->Resolve(ctx); + } + else + { + auto x = new FxStateByIndex(index, ScriptPosition); + delete this; + return x->Resolve(ctx); + } } else if (Index->ValueType->GetRegType() != REGT_INT) { // Float. diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index b344a12283..4308950600 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -181,15 +181,11 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c { if (sc.String[0] == 0 || sc.Compare("None")) { - x = new FxConstant((FState*)NULL, sc); + x = new FxConstant((FState*)nullptr, sc); } else if (sc.Compare("*")) { - if (constant) - { - x = new FxConstant((FState*)(intptr_t)-1, sc); - } - else sc.ScriptError("Invalid state name '*'"); + sc.ScriptError("Invalid state name '*'"); } else {