From 944ae2bc09497f52ad6e81354b4f74bc6ece67d5 Mon Sep 17 00:00:00 2001 From: Marisa Heit Date: Sat, 1 Oct 2016 21:47:15 -0500 Subject: [PATCH] Only generate the self==stateowner check inside action functions --- src/thingdef/thingdef.cpp | 2 +- src/thingdef/thingdef_expression.cpp | 2 +- src/zscript/vmbuilder.cpp | 3 ++- src/zscript/vmbuilder.h | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 635637149..32d4f1ce0 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -288,7 +288,7 @@ static void FinishThingdef() if (func == nullptr) { - VMFunctionBuilder buildit; + VMFunctionBuilder buildit(true); assert(tcall->Proto != nullptr); diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index 695b12799..72a4ae30b 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -3373,7 +3373,7 @@ FxExpression *FxClassMember::Resolve(FCompileContext &ctx) ExpEmit FxClassMember::Emit(VMFunctionBuilder *build) { - if (~membervar->Flags & VARF_Native) + if (build->IsActionFunc && ~membervar->Flags & VARF_Native) { // Check if this is a user-defined variable. // As of right now, FxClassMember is only ever used with FxSelf. // This very user variable was defined in stateowner so if diff --git a/src/zscript/vmbuilder.cpp b/src/zscript/vmbuilder.cpp index eb49ffb14..8d7b5a8c1 100644 --- a/src/zscript/vmbuilder.cpp +++ b/src/zscript/vmbuilder.cpp @@ -6,7 +6,7 @@ // //========================================================================== -VMFunctionBuilder::VMFunctionBuilder() +VMFunctionBuilder::VMFunctionBuilder(bool selfcheck) { NumIntConstants = 0; NumFloatConstants = 0; @@ -14,6 +14,7 @@ VMFunctionBuilder::VMFunctionBuilder() NumStringConstants = 0; MaxParam = 0; ActiveParam = 0; + IsActionFunc = selfcheck; } //========================================================================== diff --git a/src/zscript/vmbuilder.h b/src/zscript/vmbuilder.h index 2d8721acc..ed2516c2a 100644 --- a/src/zscript/vmbuilder.h +++ b/src/zscript/vmbuilder.h @@ -23,7 +23,7 @@ public: friend class VMFunctionBuilder; }; - VMFunctionBuilder(); + VMFunctionBuilder(bool checkself = false); ~VMFunctionBuilder(); VMScriptFunction *MakeFunction(); @@ -60,6 +60,9 @@ public: // Track available registers. RegAvailability Registers[4]; + // For use by DECORATE's self/stateowner sanitizer. + bool IsActionFunc; + private: struct AddrKonst {