diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index a816ab437c..bfcf83e53b 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -177,12 +177,9 @@ void FCompileContext::CheckReturn(PPrototype *proto, FScriptPosition &pos) } } -// [ZZ] I find it really dumb that something called CheckReadOnly returns false for readonly. renamed. -bool FCompileContext::CheckWritable(int flags) +bool FCompileContext::IsWritable(int flags) { - if (!(flags & VARF_ReadOnly)) return false; - if (!(flags & VARF_InternalAccess)) return true; - return fileSystem.GetFileContainer(Lump) != 0; + return !(flags & VARF_ReadOnly) || ((flags & VARF_InternalAccess) && fileSystem.GetFileContainer(Lump) == 0); } FxLocalVariableDeclaration *FCompileContext::FindLocalVariable(FName name) @@ -6730,7 +6727,7 @@ FxExpression *FxLocalVariable::Resolve(FCompileContext &ctx) bool FxLocalVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = !ctx.CheckWritable(Variable->VarFlags); + if (writable != nullptr) *writable = ctx.IsWritable(Variable->VarFlags); return true; } @@ -6885,7 +6882,7 @@ FxGlobalVariable::FxGlobalVariable(PField* mem, const FScriptPosition &pos) bool FxGlobalVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = AddressWritable && !ctx.CheckWritable(membervar->Flags); + if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags); return true; } @@ -7078,7 +7075,7 @@ FxStackVariable::~FxStackVariable() bool FxStackVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = AddressWritable && !ctx.CheckWritable(membervar->Flags); + if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags); return true; } @@ -7180,7 +7177,7 @@ bool FxStructMember::RequestAddress(FCompileContext &ctx, bool *writable) else if (writable != nullptr) { // [ZZ] original check. - bool bWritable = (AddressWritable && !ctx.CheckWritable(membervar->Flags) && + bool bWritable = (AddressWritable && ctx.IsWritable(membervar->Flags) && (!classx->ValueType->isPointer() || !classx->ValueType->toPointer()->IsConst)); // [ZZ] implement write barrier between different scopes if (bWritable) diff --git a/src/common/scripting/backend/codegen.h b/src/common/scripting/backend/codegen.h index 1ce5529b31..a52b546aeb 100644 --- a/src/common/scripting/backend/codegen.h +++ b/src/common/scripting/backend/codegen.h @@ -101,7 +101,7 @@ struct FCompileContext void HandleJumps(int token, FxExpression *handler); void CheckReturn(PPrototype *proto, FScriptPosition &pos); - bool CheckWritable(int flags); + bool IsWritable(int flags); FxLocalVariableDeclaration *FindLocalVariable(FName name); };