From 19630b0d4eea6278d36fa0caf39b831467fe2688 Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 12 Mar 2020 00:58:10 +0000 Subject: [PATCH] Add missing diagnostic information for getactor/setactor Internally, there are several different permutations of the opcodes that implement CON_GETACTOR and CON_SETACTOR. This maps the internal opcodes back to the external keywords that generated them and makes sure they all have the script line number attached to them for use in diagnostic warning and error messages. git-svn-id: https://svn.eduke32.com/eduke32@8719 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gamedef.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index dbffb79e6..812612898 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -840,14 +840,31 @@ const tokenmap_t iter_tokens [] = { "walofsec", ITER_WALLSOFSECTOR }, }; -char const * VM_GetKeywordForID(int32_t id) +// some keywords generate different opcodes depending on the context the keyword is used in +// keywords_for_private_opcodes[] resolves those opcodes to the publicly facing keyword that can generate them +static const tokenmap_t keywords_for_private_opcodes[] = { - // could be better but this is only called for diagnostics, ayy lmao + { "getactor", CON_GETSPRITEEXT }, + { "getactor", CON_GETACTORSTRUCT }, + { "getactor", CON_GETSPRITESTRUCT }, + + { "setactor", CON_SETSPRITEEXT }, + { "setactor", CON_SETACTORSTRUCT }, + { "setactor", CON_SETSPRITESTRUCT }, +}; + +char const *VM_GetKeywordForID(int32_t id) +{ + // could be better, but this is used strictly for diagnostic warning and error messages for (tokenmap_t const & keyword : vm_keywords) if (keyword.val == id) return keyword.token; - return ""; + for (tokenmap_t const & keyword : keywords_for_private_opcodes) + if (keyword.val == id) + return keyword.token; + + return ""; } #endif @@ -3277,11 +3294,11 @@ DO_DEFSTATE: if (label.offset != -1 && (label.flags & (LABEL_WRITEFUNC|LABEL_HASPARM2)) == 0) { if (labelNum >= ACTOR_SPRITEEXT_BEGIN) - *ins = CON_SETSPRITEEXT; + *ins = CON_SETSPRITEEXT | LINE_NUMBER; else if (labelNum >= ACTOR_STRUCT_BEGIN) - *ins = CON_SETACTORSTRUCT; + *ins = CON_SETACTORSTRUCT | LINE_NUMBER; else - *ins = CON_SETSPRITESTRUCT; + *ins = CON_SETSPRITESTRUCT | LINE_NUMBER; } scriptWriteValue(label.lId); @@ -3308,11 +3325,11 @@ DO_DEFSTATE: if (label.offset != -1 && (label.flags & (LABEL_READFUNC|LABEL_HASPARM2)) == 0) { if (labelNum >= ACTOR_SPRITEEXT_BEGIN) - *ins = CON_GETSPRITEEXT; + *ins = CON_GETSPRITEEXT | LINE_NUMBER; else if (labelNum >= ACTOR_STRUCT_BEGIN) - *ins = CON_GETACTORSTRUCT; + *ins = CON_GETACTORSTRUCT | LINE_NUMBER; else - *ins = CON_GETSPRITESTRUCT; + *ins = CON_GETSPRITESTRUCT | LINE_NUMBER; } scriptWriteValue(label.lId);