diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 1ce7d6acf3..b9f1aa54c4 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -12748,16 +12748,15 @@ ExpEmit FxFunctionPtrCast::Emit(VMFunctionBuilder *build) FxLocalVariableDeclaration::FxLocalVariableDeclaration(PType *type, FName name, FxExpression *initval, int varflags, const FScriptPosition &p) :FxExpression(EFX_LocalVariableDeclaration, p) { - // Local FVector isn't different from Vector - if (type == TypeFVector2) type = TypeVector2; - else if (type == TypeFVector3) type = TypeVector3; - else if (type == TypeFVector4) type = TypeVector4; - else if (type == TypeFQuaternion) type = TypeQuaternion; + if(type != type->GetLocalType()) + { + ScriptPosition.Message(MSG_WARNING, "Type '%s' not allowed in local variables, changing to '%s'", type->DescriptiveName(), type->GetLocalType()->DescriptiveName()); + } - ValueType = type; + ValueType = type->GetLocalType(); VarFlags = varflags; Name = name; - RegCount = type->RegCount; + RegCount = ValueType->RegCount; Init = initval; clearExpr = nullptr; } diff --git a/src/common/scripting/core/types.cpp b/src/common/scripting/core/types.cpp index d99f7eb13f..6b15cb7350 100644 --- a/src/common/scripting/core/types.cpp +++ b/src/common/scripting/core/types.cpp @@ -401,6 +401,7 @@ void PType::StaticInit() TypeFVector2->RegType = REGT_FLOAT; TypeFVector2->RegCount = 2; TypeFVector2->isOrdered = true; + TypeFVector2->SetLocalType(TypeVector2); TypeFVector3 = new PStruct(NAME_FVector3, nullptr); TypeFVector3->AddField(NAME_X, TypeFloat32); @@ -415,6 +416,7 @@ void PType::StaticInit() TypeFVector3->RegType = REGT_FLOAT; TypeFVector3->RegCount = 3; TypeFVector3->isOrdered = true; + TypeFVector3->SetLocalType(TypeVector3); TypeFVector4 = new PStruct(NAME_FVector4, nullptr); TypeFVector4->AddField(NAME_X, TypeFloat32); @@ -431,6 +433,7 @@ void PType::StaticInit() TypeFVector4->RegType = REGT_FLOAT; TypeFVector4->RegCount = 4; TypeFVector4->isOrdered = true; + TypeFVector4->SetLocalType(TypeVector4); TypeQuaternion = new PStruct(NAME_Quat, nullptr); @@ -464,6 +467,7 @@ void PType::StaticInit() TypeFQuaternion->RegType = REGT_FLOAT; TypeFQuaternion->RegCount = 4; TypeFQuaternion->isOrdered = true; + TypeFQuaternion->SetLocalType(TypeQuaternion); Namespaces.GlobalNamespace->Symbols.AddSymbol(Create(NAME_sByte, TypeSInt8)); diff --git a/src/common/scripting/core/types.h b/src/common/scripting/core/types.h index 69d73bd779..2568367e6e 100644 --- a/src/common/scripting/core/types.h +++ b/src/common/scripting/core/types.h @@ -110,6 +110,11 @@ public: EScopeFlags ScopeFlags = (EScopeFlags)0; bool SizeKnown = true; + PType * LocalType = nullptr; + + PType * SetLocalType(PType * LocalType) { this->LocalType = LocalType; return this; } + PType * GetLocalType() { return LocalType ? LocalType : this; } + PType(unsigned int size = 1, unsigned int align = 1); virtual ~PType(); virtual bool isNumeric() { return false; }