Skip to content

Commit

Permalink
rename CheckWritable to IsWritable, and invert its output since it's …
Browse files Browse the repository at this point in the history
…always negated
  • Loading branch information
RicardoLuis0 authored and coelckers committed Jan 20, 2023
1 parent da06212 commit d4e9438
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/common/scripting/backend/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/common/scripting/backend/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit d4e9438

Please sign in to comment.