From 9d4179ca06bdf9c2a3015abc4bcb99f8fd08ea48 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sun, 5 Mar 2017 00:52:43 +0200 Subject: [PATCH] Protected on methods of StaticEventHandler is completely useless --- src/scripting/backend/codegen.cpp | 7 +++++++ src/scripting/thingdef.cpp | 7 +++++++ wadsrc/static/zscript/events.txt | 10 +++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index eb92fe974..c9c391ac6 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -6082,6 +6082,13 @@ FxExpression *FxIdentifier::ResolveMember(FCompileContext &ctx, PStruct *classct ScriptPosition.Message(MSG_ERROR, "Private member %s not accessible", vsym->SymbolName.GetChars()); return nullptr; } + PClass* cls_ctx = dyn_cast(classctx); + PClass* cls_target = dyn_cast(objtype); + if ((vsym->Flags & VARF_Protected) && (!cls_ctx || !cls_target || cls_ctx->IsDescendantOf(cls_target))) + { + ScriptPosition.Message(MSG_ERROR, "Protected member %s not accessible", vsym->SymbolName.GetChars()); + return nullptr; + } auto x = isclass ? new FxClassMember(object, vsym, ScriptPosition) : new FxStructMember(object, vsym, ScriptPosition); object = nullptr; diff --git a/src/scripting/thingdef.cpp b/src/scripting/thingdef.cpp index c0e444893..b61c9f4ae 100644 --- a/src/scripting/thingdef.cpp +++ b/src/scripting/thingdef.cpp @@ -195,6 +195,8 @@ PFunction *FindClassMemberFunction(PStruct *selfcls, PStruct *funccls, FName nam if (symbol != nullptr) { + PClass* cls_ctx = dyn_cast(selfcls); + PClass* cls_target = dyn_cast(funccls); if (funcsym == nullptr) { sc.Message(MSG_ERROR, "%s is not a member function of %s", name.GetChars(), selfcls->TypeName.GetChars()); @@ -204,6 +206,11 @@ PFunction *FindClassMemberFunction(PStruct *selfcls, PStruct *funccls, FName nam // private access is only allowed if the symbol table belongs to the class in which the current function is being defined. sc.Message(MSG_ERROR, "%s is declared private and not accessible", symbol->SymbolName.GetChars()); } + else if ((funcsym->Variants[0].Flags & VARF_Protected) && (!cls_ctx || !cls_target || cls_ctx->IsDescendantOf((PClass*)cls_target))) + { + sc.Message(MSG_ERROR, "%s is declared protected and not accessible", symbol->SymbolName.GetChars()); + return nullptr; + } else if (funcsym->Variants[0].Flags & VARF_Deprecated) { sc.Message(MSG_WARNING, "Call to deprecated function %s", symbol->SymbolName.GetChars()); diff --git a/wadsrc/static/zscript/events.txt b/wadsrc/static/zscript/events.txt index c1f59a60e..03c2de90f 100755 --- a/wadsrc/static/zscript/events.txt +++ b/wadsrc/static/zscript/events.txt @@ -283,12 +283,12 @@ class StaticEventHandler : Object native play { // static event handlers CAN register other static event handlers. // unlike EventHandler.Create that will not create them. - clearscope protected static native StaticEventHandler Create(class type); - clearscope protected static native StaticEventHandler CreateOnce(class type); - clearscope protected static native StaticEventHandler Find(Class type); // just for convenience. who knows. + clearscope static native StaticEventHandler Create(class type); + clearscope static native StaticEventHandler CreateOnce(class type); + clearscope static native StaticEventHandler Find(Class type); // just for convenience. who knows. - clearscope protected static native bool Register(StaticEventHandler handler); - clearscope protected static native bool Unregister(StaticEventHandler handler); + clearscope static native bool Register(StaticEventHandler handler); + clearscope static native bool Unregister(StaticEventHandler handler); // these are called when the handler gets registered or unregistered // you can set Order/IsUiProcessor here.