rework how vector local type restrictions are managed

This commit is contained in:
Ricardo Luís Vaz Silva 2025-03-02 14:45:00 -03:00
parent f1b5ba09e0
commit 6b8736fb30
3 changed files with 15 additions and 7 deletions

View file

@ -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;
}

View file

@ -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<PSymbolType>(NAME_sByte, TypeSInt8));

View file

@ -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; }