From cf21bb15246d09e0f8becc83a1d8ddd37b1971a7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 8 Jun 2016 10:46:35 +0200 Subject: [PATCH] - reinstated abort-on-error for any problem that gets reported during DECORATE code generation. - fixed: DECORATE allowed a silent conversion from names to integers. In old versions the name was converted to 0, since the scripting branch to the name index. Reverted to the old behavior but added a warning message. --- src/thingdef/thingdef.cpp | 2 +- src/thingdef/thingdef_exp.h | 2 +- src/thingdef/thingdef_expression.cpp | 49 ++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index a24e8831c..4bb247f94 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -431,11 +431,11 @@ void LoadActors () FScanner sc(lump); ParseDecorate (sc); } + FinishThingdef(); if (FScriptPosition::ErrorCounter > 0) { I_Error("%d errors while parsing DECORATE scripts", FScriptPosition::ErrorCounter); } - FinishThingdef(); timer.Unclock(); if (!batchrun) Printf("DECORATE parsing took %.2f ms\n", timer.TimeMS()); // Base time: ~52 ms diff --git a/src/thingdef/thingdef_exp.h b/src/thingdef/thingdef_exp.h index 9ec605626..ac6b7eda3 100644 --- a/src/thingdef/thingdef_exp.h +++ b/src/thingdef/thingdef_exp.h @@ -208,7 +208,7 @@ public: virtual bool isConstant() const; virtual void RequestAddress(); virtual VMFunction *GetDirectFunction(); - bool IsNumeric() const { return ValueType->GetRegType() == REGT_INT || ValueType->GetRegType() == REGT_FLOAT; } + bool IsNumeric() const { return ValueType != TypeName && (ValueType->GetRegType() == REGT_INT || ValueType->GetRegType() == REGT_FLOAT); } bool IsPointer() const { return ValueType->GetRegType() == REGT_POINTER; } virtual ExpEmit Emit(VMFunctionBuilder *build); diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index c888f97d5..2e60dfa97 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -358,10 +358,22 @@ FxExpression *FxIntCast::Resolve(FCompileContext &ctx) if (basex->ValueType->GetRegType() == REGT_INT) { - FxExpression *x = basex; - basex = NULL; - delete this; - return x; + if (basex->ValueType != TypeName) + { + FxExpression *x = basex; + basex = NULL; + delete this; + return x; + } + else + { + // Ugh. This should abort, but too many mods fell into this logic hole somewhere, so this seroious error needs to be reduced to a warning. :( + if (!basex->isConstant()) ScriptPosition.Message(MSG_WARNING, "Numeric type expected, got a name"); + else ScriptPosition.Message(MSG_WARNING, "Numeric type expected, got \"%s\"", static_cast(basex)->GetValue().GetName().GetChars()); + FxExpression * x = new FxConstant(0, ScriptPosition); + delete this; + return x; + } } else if (basex->ValueType->GetRegType() == REGT_FLOAT) { @@ -374,12 +386,9 @@ FxExpression *FxIntCast::Resolve(FCompileContext &ctx) } return this; } - else - { - ScriptPosition.Message(MSG_ERROR, "Numeric type expected"); - delete this; - return NULL; - } + ScriptPosition.Message(MSG_ERROR, "Numeric type expected"); + delete this; + return NULL; } //========================================================================== @@ -443,14 +452,26 @@ FxExpression *FxFloatCast::Resolve(FCompileContext &ctx) } else if (basex->ValueType->GetRegType() == REGT_INT) { - if (basex->isConstant()) + if (basex->ValueType != TypeName) { - ExpVal constval = static_cast(basex)->GetValue(); - FxExpression *x = new FxConstant(constval.GetFloat(), ScriptPosition); + if (basex->isConstant()) + { + ExpVal constval = static_cast(basex)->GetValue(); + FxExpression *x = new FxConstant(constval.GetFloat(), ScriptPosition); + delete this; + return x; + } + return this; + } + else + { + // Ugh. This should abort, but too many mods fell into this logic hole somewhere, so this seroious error needs to be reduced to a warning. :( + if (!basex->isConstant()) ScriptPosition.Message(MSG_WARNING, "Numeric type expected, got a name"); + else ScriptPosition.Message(MSG_WARNING, "Numeric type expected, got \"%s\"", static_cast(basex)->GetValue().GetName().GetChars()); + FxExpression *x = new FxConstant(0.0, ScriptPosition); delete this; return x; } - return this; } else {