From 4dd38ffd82e4e352e0d1619d7a9859dcacd81c1f Mon Sep 17 00:00:00 2001 From: Y_Less Date: Thu, 4 Oct 2018 13:59:30 +0200 Subject: [PATCH 1/3] `#pragma nodestruct var, names` --- source/compiler/sc.h | 1 + source/compiler/sc1.c | 2 +- source/compiler/sc2.c | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index e417ae9..bf5b074 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -232,6 +232,7 @@ typedef struct s_symbol { #define uENUMFIELD 0x040 #define uMISSING 0x080 #define uFORWARD 0x100 +#define uNODESTRUCT 0x200 /* "no destruct(or)", not "node struct" */ /* uRETNONE is not stored in the "usage" field of a symbol. It is * used during parsing a function, to detect a mix of "return;" and * "return value;" in a few special cases. diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index fcec5ec..c6e38ec 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4962,7 +4962,7 @@ static void destructsymbols(symbol *root,int level) int savepri=FALSE; symbol *sym=root->next; while (sym!=NULL && sym->compound>=level) { - if ((sym->ident==iVARIABLE || sym->ident==iARRAY) && !(sym->vclass==sSTATIC && sym->fnumber==-1)) { + if ((sym->ident==iVARIABLE || sym->ident==iARRAY) && !(sym->vclass==sSTATIC && sym->fnumber==-1) && !(sym->usage&uNODESTRUCT)) { char symbolname[16]; symbol *opsym; cell elements; diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 3398c59..1cd81e8 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1268,6 +1268,33 @@ static int command(void) if (comma) lptr++; } while (comma); + } else if (strcmp(str,"nodestruct")==0) { + char name[sNAMEMAX+1]; + int i,comma; + symbol *sym; + do { + /* get the name */ + while (*lptr<=' ' && *lptr!='\0') + lptr++; + for (i=0; iusage |= uNODESTRUCT; + } else { + error(17,name); /* undefined symbol */ + } /* if */ + /* see if a comma follows the name */ + while (*lptr<=' ' && *lptr!='\0') + lptr++; + comma= (*lptr==','); + if (comma) + lptr++; + } while (comma); } else if (strcmp(str,"naked")==0) { pc_naked=TRUE; } else if (strcmp(str,"warning")==0) { From 351d0086adbbebb2c1665403cbb61e66d28a28b3 Mon Sep 17 00:00:00 2001 From: Y_Less Date: Thu, 4 Oct 2018 14:07:39 +0200 Subject: [PATCH 2/3] Test `#pragma nodestruct` --- source/compiler/tests/gh_258.meta | 6 ++++++ source/compiler/tests/gh_258.pwn | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 source/compiler/tests/gh_258.meta create mode 100644 source/compiler/tests/gh_258.pwn diff --git a/source/compiler/tests/gh_258.meta b/source/compiler/tests/gh_258.meta new file mode 100644 index 0000000..9bb01eb --- /dev/null +++ b/source/compiler/tests/gh_258.meta @@ -0,0 +1,6 @@ +{ + 'test_type': 'output_check', + 'errors': """ + gh_258.pwn(11) : warning 203: symbol is never used: "operator~(Tag:)" + """ +} diff --git a/source/compiler/tests/gh_258.pwn b/source/compiler/tests/gh_258.pwn new file mode 100644 index 0000000..a0a2174 --- /dev/null +++ b/source/compiler/tests/gh_258.pwn @@ -0,0 +1,9 @@ +operator~(Tag:var[], size) { +} + +main() { + new Tag:a; + #pragma unused a + #pragma nodestruct a +} + From 65a391c30f331d576d5a64d9ff50cf989fee01be Mon Sep 17 00:00:00 2001 From: Y_Less Date: Thu, 4 Oct 2018 17:16:32 +0200 Subject: [PATCH 3/3] Wrong line number in 258 test --- source/compiler/tests/gh_258.meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/tests/gh_258.meta b/source/compiler/tests/gh_258.meta index 9bb01eb..c583575 100644 --- a/source/compiler/tests/gh_258.meta +++ b/source/compiler/tests/gh_258.meta @@ -1,6 +1,6 @@ { 'test_type': 'output_check', 'errors': """ - gh_258.pwn(11) : warning 203: symbol is never used: "operator~(Tag:)" + gh_258.pwn(10) : warning 203: symbol is never used: "operator~(Tag:)" """ }