From adfefdcf2ef0d69b1c1b0a1f253db47f7232921d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Fri, 7 Feb 2025 19:47:30 -0300 Subject: [PATCH] add unsafe clearscope, to allow declaring clearscope fields outside of gzdoom.pk3 --- src/common/scripting/frontend/zcc-parse.lemon | 1 + src/common/scripting/frontend/zcc_compile.cpp | 4 +- src/common/scripting/frontend/zcc_parser.h | 51 ++++++++++--------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/common/scripting/frontend/zcc-parse.lemon b/src/common/scripting/frontend/zcc-parse.lemon index 72dbc35fa43..ab46782aacd 100644 --- a/src/common/scripting/frontend/zcc-parse.lemon +++ b/src/common/scripting/frontend/zcc-parse.lemon @@ -1314,6 +1314,7 @@ decl_flag(X) ::= VARARG(T). { X.Int = ZCC_VarArg; X.SourceLoc = T.SourceLoc; decl_flag(X) ::= UI(T). { X.Int = ZCC_UIFlag; X.SourceLoc = T.SourceLoc; } decl_flag(X) ::= PLAY(T). { X.Int = ZCC_Play; X.SourceLoc = T.SourceLoc; } decl_flag(X) ::= CLEARSCOPE(T). { X.Int = ZCC_ClearScope; X.SourceLoc = T.SourceLoc; } +decl_flag(X) ::= UNSAFE(T) LPAREN CLEARSCOPE RPAREN. { X.Int = ZCC_UnsafeClearScope; X.SourceLoc = T.SourceLoc; } decl_flag(X) ::= VIRTUALSCOPE(T). { X.Int = ZCC_VirtualScope; X.SourceLoc = T.SourceLoc; } func_const(X) ::= . { X.Int = 0; X.SourceLoc = stat->sc->GetMessageLine(); } diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 51591c399e4..8a432e8c103 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -1508,7 +1508,7 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArrayFlags & ZCC_Play) varflags = FScopeBarrier::ChangeSideInFlags(varflags, FScopeBarrier::Side_Play); - if (field->Flags & ZCC_ClearScope) + if (field->Flags & (ZCC_ClearScope | ZCC_UnsafeClearScope)) varflags = FScopeBarrier::ChangeSideInFlags(varflags, FScopeBarrier::Side_PlainData); } else @@ -2315,7 +2315,7 @@ void ZCCCompiler::SetImplicitArgs(TArray* args, TArray* argfla if (funcflags & VARF_Method) { // implied self pointer - if (args != nullptr) args->Push(NewPointer(cls, !!(funcflags & VARF_ReadOnly))); + if (args != nullptr) args->Push(NewPointer(cls, (funcflags & VARF_SafeConst))); if (argflags != nullptr) argflags->Push(VARF_Implicit | VARF_ReadOnly); if (argnames != nullptr) argnames->Push(NAME_self); } diff --git a/src/common/scripting/frontend/zcc_parser.h b/src/common/scripting/frontend/zcc_parser.h index cf2574c2888..47ab2d65fae 100644 --- a/src/common/scripting/frontend/zcc_parser.h +++ b/src/common/scripting/frontend/zcc_parser.h @@ -41,31 +41,32 @@ struct ZCCToken // Variable / Function / Class modifiers enum { - ZCC_Native = 1 << 0, - ZCC_Static = 1 << 1, - ZCC_Private = 1 << 2, - ZCC_Protected = 1 << 3, - ZCC_Latent = 1 << 4, - ZCC_Final = 1 << 5, - ZCC_Meta = 1 << 6, - ZCC_Action = 1 << 7, - ZCC_Deprecated = 1 << 8, - ZCC_ReadOnly = 1 << 9, - ZCC_FuncConst = 1 << 10, - ZCC_Abstract = 1 << 11, - ZCC_Extension = 1 << 12, - ZCC_Virtual = 1 << 13, - ZCC_Override = 1 << 14, - ZCC_Transient = 1 << 15, - ZCC_VarArg = 1 << 16, - ZCC_UIFlag = 1 << 17, // there's also token called ZCC_UI - ZCC_Play = 1 << 18, - ZCC_ClearScope = 1 << 19, - ZCC_VirtualScope = 1 << 20, - ZCC_Version = 1 << 21, - ZCC_Internal = 1 << 22, - ZCC_Sealed = 1 << 23, - ZCC_FuncConstUnsafe = 1 << 24, + ZCC_Native = 1 << 0, + ZCC_Static = 1 << 1, + ZCC_Private = 1 << 2, + ZCC_Protected = 1 << 3, + ZCC_Latent = 1 << 4, + ZCC_Final = 1 << 5, + ZCC_Meta = 1 << 6, + ZCC_Action = 1 << 7, + ZCC_Deprecated = 1 << 8, + ZCC_ReadOnly = 1 << 9, + ZCC_FuncConst = 1 << 10, + ZCC_Abstract = 1 << 11, + ZCC_Extension = 1 << 12, + ZCC_Virtual = 1 << 13, + ZCC_Override = 1 << 14, + ZCC_Transient = 1 << 15, + ZCC_VarArg = 1 << 16, + ZCC_UIFlag = 1 << 17, // there's also token called ZCC_UI + ZCC_Play = 1 << 18, + ZCC_ClearScope = 1 << 19, + ZCC_VirtualScope = 1 << 20, + ZCC_Version = 1 << 21, + ZCC_Internal = 1 << 22, + ZCC_Sealed = 1 << 23, + ZCC_FuncConstUnsafe = 1 << 24, + ZCC_UnsafeClearScope = 1 << 25, }; // Function parameter modifiers