From f1da832ae967190515dff3d865c166d40fb212e0 Mon Sep 17 00:00:00 2001 From: Y_Less Date: Tue, 24 Oct 2017 21:18:07 +0200 Subject: [PATCH] -E warnings as errors. --- source/compiler/libpawnc.c | 3 +++ source/compiler/sc.h | 2 ++ source/compiler/sc1.c | 17 +++++++++++++++++ source/compiler/sc5.c | 21 ++++++++++++++++++++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/source/compiler/libpawnc.c b/source/compiler/libpawnc.c index 78be777..b3d56c8 100644 --- a/source/compiler/libpawnc.c +++ b/source/compiler/libpawnc.c @@ -134,6 +134,9 @@ static char *prefix[3]={ "error", "fatal error", "warning" }; char *pre; pre=prefix[number/100]; + if (number>=200 && pc_geterrorwarnings()){ + pre=prefix[0]; + } if (firstline>=0) fprintf(stderr,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number); else diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 9d68b0e..171c3f1 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -485,6 +485,8 @@ int pc_addtag(char *name); int pc_enablewarning(int number,int enable); int pc_pushwarnings(); int pc_popwarnings(); +void pc_seterrorwarnings(int enable); +int pc_geterrorwarnings(); /* * Functions called from the compiler (to be implemented by you) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 5822946..d61d29a 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -221,6 +221,9 @@ static char *prefix[3]={ "error", "fatal error", "warning" }; char *pre; pre=prefix[number/100]; + if (number>=200 && pc_geterrorwarnings()){ + pre=prefix[0]; + } if (firstline>=0) fprintf(stderr,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number); else @@ -1159,6 +1162,19 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam if (sc_asmfile && verbosity>1) verbosity=1; break; + case 'E': + switch (*option_value(ptr)) { + case '+': + pc_seterrorwarnings(1); + break; + case '-': + pc_seterrorwarnings(0); + break; + default: + pc_seterrorwarnings(2); + break; + } + break; case 'w': i=(int)strtol(option_value(ptr),(char **)&ptr,10); if (*ptr=='-') @@ -1450,6 +1466,7 @@ static void about(void) pc_printf(" -X abstract machine size limit in bytes\n"); pc_printf(" -XD abstract machine data/stack size limit in bytes\n"); pc_printf(" -Z[+/-] run in compatibility mode (default=%c)\n",pc_compat ? '+' : '-'); + pc_printf(" -E[+/-] turn warnings in to errors\n"); pc_printf(" -\\ use '\\' for escape characters\n"); pc_printf(" -^ use '^' for escape characters\n"); pc_printf(" -;[+/-] require a semicolon to end each statement (default=%c)\n", sc_needsemicolon ? '+' : '-'); diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index 8f81319..0208f79 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -203,6 +203,7 @@ static struct s_warnstack { static int errflag; static int errstart; /* line number at which the instruction started */ static int errline; /* forced line number for the error message */ +static int errwarn; /* error * @@ -249,6 +250,11 @@ static short lastfile; msg=fatalmsg[number-100]; pre=prefix[1]; errnum++; /* a fatal error also counts as an error */ + } else if (errwarn) { + msg=warnmsg[number-200]; + pre=prefix[0]; + errflag=TRUE; + errnum++; } else { msg=warnmsg[number-200]; pre=prefix[2]; @@ -303,7 +309,7 @@ static short lastfile; errorcount=0; lastline=fline; lastfile=fcurrent; - if (number<200) + if (number<200 || errwarn) errorcount++; if (errorcount>=3) error(107); /* too many error/warning messages on one line */ @@ -401,3 +407,16 @@ int pc_popwarnings() return TRUE; } +/* pc_seterrorwarnings() + * Make warnings errors (or not). + */ +void pc_seterrorwarnings(int enable) +{ + errwarn = enable; +} + +int pc_geterrorwarnings() +{ + return errwarn; +} +