From 01d1c0c806ce9c42b38d10058edb39eb051a2854 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 3 Sep 2014 11:04:25 -0700 Subject: [PATCH] Add a flag for warnings-as-errors. --- sourcepawn/compiler/libpawnc.cpp | 2 +- sourcepawn/compiler/sc.h | 1 + sourcepawn/compiler/sc1.cpp | 4 ++++ sourcepawn/compiler/sc5.cpp | 14 +++++++++++--- sourcepawn/compiler/scvars.cpp | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sourcepawn/compiler/libpawnc.cpp b/sourcepawn/compiler/libpawnc.cpp index f99086d9..31e7c30c 100644 --- a/sourcepawn/compiler/libpawnc.cpp +++ b/sourcepawn/compiler/libpawnc.cpp @@ -74,7 +74,7 @@ static const char *prefix[3]={ "error", "fatal error", "warning" }; if (number!=0) { int idx; - if (number < 160) + if (number < 160 || (number >= 200 && sc_warnings_are_errors)) idx = 0; else if (number < 200) idx = 1; diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 42020bca..79c7a4f9 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -912,6 +912,7 @@ extern int pc_tag_nullfunc_t; /* the null function type */ extern int pc_anytag; /* global any tag */ extern int glbstringread; /* last global string read */ extern int sc_require_newdecls; /* only newdecls are allowed */ +extern bool sc_warnings_are_errors; extern constvalue sc_automaton_tab; /* automaton table */ extern constvalue sc_state_tab; /* state table */ diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index d2d88c20..86fe6936 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -944,6 +944,9 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam case 'e': strlcpy(ename,option_value(ptr),_MAX_PATH); /* set name of error file */ break; + case 'E': + sc_warnings_are_errors = true; + break; #if defined __WIN32__ || defined _WIN32 || defined _Windows case 'H': hwndFinish=(HWND)atoi(option_value(ptr)); @@ -1312,6 +1315,7 @@ static void about(void) pc_printf(" -t TAB indent size (in character positions, default=%d)\n",sc_tabsize); pc_printf(" -v verbosity level; 0=quiet, 1=normal, 2=verbose (default=%d)\n",verbosity); pc_printf(" -w disable a specific warning by its number\n"); + pc_printf(" -E treat warnings as errors\n"); pc_printf(" -X abstract machine size limit in bytes\n"); pc_printf(" -XD abstract machine data/stack size limit in bytes\n"); pc_printf(" -\\ use '\\' for escape characters\n"); diff --git a/sourcepawn/compiler/sc5.cpp b/sourcepawn/compiler/sc5.cpp index 64d2a649..e161ed1a 100644 --- a/sourcepawn/compiler/sc5.cpp +++ b/sourcepawn/compiler/sc5.cpp @@ -1,3 +1,4 @@ +// vim: set ts=8 sts=2 sw=2 tw=99 et: /* Pawn compiler - Error message system * In fact a very simple system, using only 'panic mode'. * @@ -81,6 +82,8 @@ static short lastfile; int errline = sErrLine; sErrLine = -1; + bool is_warning = (number >= 200 && !sc_warnings_are_errors); + /* errflag is reset on each semicolon. * In a two-pass compiler, an error should not be reported twice. Therefore * the error reporting is enabled only in the second pass (and only when @@ -113,8 +116,13 @@ static short lastfile; errnum++; /* a fatal error also counts as an error */ } else { msg=warnmsg[number-200]; - pre=prefix[2]; - warnnum++; + if (sc_warnings_are_errors) { + pre=prefix[0]; + errnum++; + } else { + pre=prefix[2]; + warnnum++; + } } /* if */ assert(errstart<=fline); @@ -164,7 +172,7 @@ static short lastfile; errorcount=0; lastline=fline; lastfile=fcurrent; - if (number<200) + if (!is_warning) errorcount++; if (errorcount>=3) error(167); /* too many error/warning messages on one line */ diff --git a/sourcepawn/compiler/scvars.cpp b/sourcepawn/compiler/scvars.cpp index 0f030923..3f1a5131 100644 --- a/sourcepawn/compiler/scvars.cpp +++ b/sourcepawn/compiler/scvars.cpp @@ -94,6 +94,7 @@ int pc_optimize=sOPTIMIZE_NOMACRO; /* (peephole) optimization level */ int pc_memflags=0; /* special flags for the stack/heap usage */ int sc_showincludes=0; /* show include files */ int sc_require_newdecls=0; /* Require new-style declarations */ +bool sc_warnings_are_errors=false; constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */ constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */