Compiler: Add a flag for warnings-as-errors

This commit is contained in:
Arkshine 2014-09-29 15:54:39 +02:00
parent ae2699ca98
commit e7c7313f77
5 changed files with 27 additions and 5 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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<num> TAB indent size (in character positions, default=%d)\n",sc_tabsize);
pc_printf(" -v<num> verbosity level; 0=quiet, 1=normal, 2=verbose (default=%d)\n",verbosity);
pc_printf(" -w<num> disable a specific warning by its number\n");
pc_printf(" -E treat warnings as errors\n");
pc_printf(" -X<num> abstract machine size limit in bytes\n");
pc_printf(" -\\ use '\\' for escape characters\n");
pc_printf(" -^ use '^' for escape characters\n");

View File

@ -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 */

View File

@ -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 */