From fcdeea683bd7c1f1971bee678cd8bb13f7aa9d90 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 14 Aug 2014 20:58:13 +0200 Subject: [PATCH] Compiler: Add #warning directive. Basically same as error but as warning. Imported from SA-MP: https://github.com/Zeex/pawn/commit/1bd6be93e06ff0e56d264e633b23c7d899b034e0 Example: #warning don't eat egg. Result: warning.sma(1) : warning 234: user warning: don't eat egg. --- compiler/libpc300/sc.h | 21 +++++++++++---------- compiler/libpc300/sc2.c | 10 +++++++++- compiler/libpc300/sc5-in.scp | 3 ++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/compiler/libpc300/sc.h b/compiler/libpc300/sc.h index a0341786..76127af5 100755 --- a/compiler/libpc300/sc.h +++ b/compiler/libpc300/sc.h @@ -286,7 +286,7 @@ typedef struct s_stringpair { */ #define tFIRST 256 /* value of first multi-character operator */ #define tMIDDLE 280 /* value of last multi-character operator */ -#define tLAST 325 /* value of last multi-character match-able token */ +#define tLAST 326 /* value of last multi-character match-able token */ /* multi-character operators */ #define taMULT 256 /* *= */ #define taDIV 257 /* /= */ @@ -360,17 +360,18 @@ typedef struct s_stringpair { #define tpPRAGMA 323 #define tpTRYINCLUDE 324 #define tpUNDEF 325 +#define tpWARNING 326 /* semicolon is a special case, because it can be optional */ -#define tTERM 326 /* semicolon or newline */ -#define tENDEXPR 327 /* forced end of expression */ +#define tTERM 327 /* semicolon or newline */ +#define tENDEXPR 328 /* forced end of expression */ /* other recognized tokens */ -#define tNUMBER 328 /* integer number */ -#define tRATIONAL 329 /* rational number */ -#define tSYMBOL 330 -#define tLABEL 331 -#define tSTRING 332 -#define tEXPR 333 /* for assigment to "lastst" only */ -#define tEMPTYBLOCK 334 /* empty blocks for AM bug 4825 */ +#define tNUMBER 329 /* integer number */ +#define tRATIONAL 330 /* rational number */ +#define tSYMBOL 331 +#define tLABEL 332 +#define tSTRING 333 +#define tEXPR 334 /* for assigment to "lastst" only */ +#define tEMPTYBLOCK 335 /* empty blocks for AM bug 4825 */ /* (reversed) evaluation of staging buffer */ #define sSTARTREORDER 0x01 diff --git a/compiler/libpc300/sc2.c b/compiler/libpc300/sc2.c index 2017d4a4..88290444 100755 --- a/compiler/libpc300/sc2.c +++ b/compiler/libpc300/sc2.c @@ -1351,6 +1351,14 @@ static int command(void) if (!SKIPPING) error(111,lptr); /* user error */ break; + case tpWARNING: + while (*lptr<=' ' && *lptr!='\0') + lptr++; + if (!SKIPPING) { + str=strtok((char*)lptr, "\n"); + error(234, str != NULL ? str : lptr); /* user warning, and remove unnecessary newline */ + } + break; default: error(31); /* unknown compiler directive */ ret=SKIPPING ? CMD_CONDFALSE : CMD_NONE; /* process as normal line */ @@ -1831,7 +1839,7 @@ char *sc_tokens[] = { "sleep", "state", "static", "stock", "switch", "tagof", "while", "#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput", "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma", - "#tryinclude", "#undef", + "#tryinclude", "#undef", "#warning", ";", ";", "-integer value-", "-rational value-", "-identifier-", "-label-", "-string-" }; diff --git a/compiler/libpc300/sc5-in.scp b/compiler/libpc300/sc5-in.scp index 12e98370..869ae3df 100644 --- a/compiler/libpc300/sc5-in.scp +++ b/compiler/libpc300/sc5-in.scp @@ -238,7 +238,7 @@ static char *fatalmsg[] = { /*108*/ "codepage mapping file not found\n", /*109*/ "invalid path: \"%s\"\n", /*110*/ "assertion failed: %s\n", -/*111*/ "user error: %s\n", +/*111*/ "user error: %s\n" #else "c\224\241\222a\206from \327le\335", "c\224\241writ\200\277 \327le\335", @@ -291,6 +291,7 @@ static char *warnmsg[] = { /*231*/ "state specification on forward declaration is ignored\n", /*232*/ "output file is written, but with compact encoding disabled\n" /*233*/ "symbol \"%s\" is marked as deprecated: %s\n", +/*234*/ "user warning: %s\n" #else "\345 \274tr\240\226\233\277 %\206\273\337c\367\305", "\222\323i\231\300\344\224t/\314cr\375\364",