From e7c7313f77656d237dda5775f94a19560fc9cd57 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 29 Sep 2014 15:54:39 +0200 Subject: [PATCH] Compiler: Add a flag for warnings-as-errors --- compiler/libpc300/libpawnc.c | 12 ++++++++++-- compiler/libpc300/sc.h | 1 + compiler/libpc300/sc1.c | 4 ++++ compiler/libpc300/sc5.c | 14 +++++++++++--- compiler/libpc300/scvars.c | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/compiler/libpc300/libpawnc.c b/compiler/libpc300/libpawnc.c index cd4d496d..c1d1f597 100755 --- a/compiler/libpc300/libpawnc.c +++ b/compiler/libpc300/libpawnc.c @@ -52,7 +52,7 @@ void extern __attribute__((visibility("default"))) EXCOMPILER(int argc, char **argv) # endif { - pc_compile(argc, argv); + pc_compile(argc, argv); } #endif /* PAWNC_DLL */ @@ -112,8 +112,16 @@ static char *prefix[3]={ "error", "fatal error", "warning" }; if (number!=0) { char *pre; + int idx; - pre=prefix[number/100]; + if (number < 100 || (number >= 200 && sc_warnings_are_errors)) + idx = 0; + else if (number < 200) + idx = 1; + else + idx = 2; + + pre=prefix[idx]; if (firstline>=0) pc_printf("%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number); else diff --git a/compiler/libpc300/sc.h b/compiler/libpc300/sc.h index 9eb47438..2d8c8c24 100755 --- a/compiler/libpc300/sc.h +++ b/compiler/libpc300/sc.h @@ -798,6 +798,7 @@ SC_VDECL int rational_digits; /* number of fractional digits */ SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */ SC_VDECL short sc_is_utf8; /* is this source file in UTF-8 encoding */ SC_VDECL char *pc_deprecate; /* if non-NULL, mark next declaration as deprecated */ +SC_VDECL int sc_warnings_are_errors; SC_VDECL constvalue sc_automaton_tab; /* automaton table */ SC_VDECL constvalue sc_state_tab; /* state table */ diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index d66d6ed2..ffe84699 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -1052,6 +1052,9 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam strncpy(ename,option_value(ptr),_MAX_PATH); /* set name of error file */ ename[_MAX_PATH-1]='\0'; break; + case 'E': + sc_warnings_are_errors = 1; + break; #if defined __WIN32__ || defined _WIN32 || defined _Windows case 'H': hwndFinish=(HWND)atoi(option_value(ptr)); @@ -1399,6 +1402,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(" -\\ use '\\' for escape characters\n"); pc_printf(" -^ use '^' for escape characters\n"); diff --git a/compiler/libpc300/sc5.c b/compiler/libpc300/sc5.c index e5f74c90..b6234ee5 100755 --- a/compiler/libpc300/sc5.c +++ b/compiler/libpc300/sc5.c @@ -75,6 +75,9 @@ static short lastfile; char *msg,*pre,*filename; va_list argptr; char string[128]; + int is_warning; + + 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 @@ -103,8 +106,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 */ strexpand(string,(unsigned char *)msg,sizeof string,SCPACK_TABLE); @@ -164,7 +172,7 @@ static short lastfile; errorcount=0; lastline=fline; lastfile=fcurrent; - if (number<200) + if (!is_warning) errorcount++; if (errorcount>=3) error(107); /* too many error/warning messages on one line */ diff --git a/compiler/libpc300/scvars.c b/compiler/libpc300/scvars.c index 1c297060..8afba17f 100755 --- a/compiler/libpc300/scvars.c +++ b/compiler/libpc300/scvars.c @@ -87,6 +87,7 @@ SC_VDEFINE int sc_allowproccall=0; /* allow/detect tagnames in lex() */ SC_VDEFINE short sc_is_utf8=FALSE; /* is this source file in UTF-8 encoding */ SC_VDEFINE char *pc_deprecate = NULL;/* if non-null, mark next declaration as deprecated */ SC_VDEFINE int sc_showincludes=0; /* show include files */ +SC_VDEFINE int sc_warnings_are_errors=0; SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */ SC_VDEFINE constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */