Use symbols for fatal errors and bump them by 20 slots.

This commit is contained in:
David Anderson 2014-11-07 17:41:33 -08:00
parent 2c31b99ce3
commit a8796543af
9 changed files with 82 additions and 63 deletions

View File

@ -74,7 +74,7 @@ static const char *prefix[3]={ "error", "fatal error", "warning" };
if (number!=0) {
int idx;
if (number < 160 || (number >= 200 && sc_warnings_are_errors))
if (number < FIRST_FATAL_ERROR || (number >= 200 && sc_warnings_are_errors))
idx = 0;
else if (number < 200)
idx = 1;

View File

@ -938,4 +938,23 @@ typedef struct array_info_s
cell *base; /* &litq[startlit] */
} array_info_t;
enum FatalError {
FIRST_FATAL_ERROR = 180,
FATAL_ERROR_READ = FIRST_FATAL_ERROR,
FATAL_ERROR_WRITE,
FATAL_ERROR_ALLOC_OVERFLOW,
FATAL_ERROR_OOM,
FATAL_ERROR_INVALID_INSN,
FATAL_ERROR_INT_OVERFLOW,
FATAL_ERROR_SCRIPT_OVERFLOW,
FATAL_ERROR_OVERWHELMED_BY_BAD,
FATAL_ERROR_NO_CODEPAGE,
FATAL_ERROR_INVALID_PATH,
FATAL_ERROR_ASSERTION_FAILED,
FATAL_ERROR_USER_ERROR,
FATAL_ERRORS_TOTAL
};
#endif /* SC_H_INCLUDED */

View File

@ -218,17 +218,17 @@ int pc_compile(int argc, char *argv[])
sp_Globals = NewHashTable();
if (!sp_Globals)
error(163);
error(FATAL_ERROR_OOM);
/* allocate memory for fixed tables */
inpfname=(char*)malloc(_MAX_PATH);
if (inpfname==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
litq=(cell*)malloc(litmax*sizeof(cell));
if (litq==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
if (!phopt_init())
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
setopt(argc,argv,outfname,errfname,incfname,reportname,codepage);
strcpy(binfname,outfname);
@ -254,7 +254,7 @@ int pc_compile(int argc, char *argv[])
lcl_tabsize=sc_tabsize;
#if !defined NO_CODEPAGE
if (!cp_set(codepage)) /* set codepage */
error(168); /* codepage mapping file not found */
error(FATAL_ERROR_NO_CODEPAGE);
#endif
/* optionally create a temporary input file that is a collection of all
* input files
@ -271,7 +271,7 @@ int pc_compile(int argc, char *argv[])
tname=tempnam(NULL,"pawn");
#elif defined(MACOS) && !defined(__MACH__)
/* tempnam is not supported for the Macintosh CFM build. */
error(164,get_sourcefile(1));
error(FATAL_ERROR_INVALID_INSN,get_sourcefile(1));
tname=NULL;
sname=NULL;
#else
@ -287,7 +287,7 @@ int pc_compile(int argc, char *argv[])
pc_closesrc(ftmp);
remove(tname);
strcpy(inpfname,sname); /* avoid invalid filename */
error(160,sname);
error(FATAL_ERROR_READ,sname);
} /* if */
pc_writesrc(ftmp,(unsigned char*)"#file \"");
pc_writesrc(ftmp,(unsigned char*)sname);
@ -306,11 +306,11 @@ int pc_compile(int argc, char *argv[])
} /* if */
inpf_org=pc_opensrc(inpfname);
if (inpf_org==NULL)
error(160,inpfname);
error(FATAL_ERROR_READ,inpfname);
freading=TRUE;
outf=(FILE*)pc_openasm(outfname); /* first write to assembler file (may be temporary) */
if (outf==NULL)
error(161,outfname);
error(FATAL_ERROR_WRITE,outfname);
setconstants(); /* set predefined constants and tagnames */
for (i=0; i<skipinput; i++) /* skip lines in the input file */
if (pc_readsrc(inpf_org,pline,sLINEMAX)!=NULL)
@ -366,7 +366,7 @@ int pc_compile(int argc, char *argv[])
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" */
} else {
if (!plungequalifiedfile(incfname)) /* parse "prefix" include file */
error(160,incfname); /* cannot read from ... (fatal error) */
error(FATAL_ERROR_READ,incfname);
} /* if */
} /* if */
preprocess(); /* fetch first line */
@ -486,7 +486,7 @@ cleanup:
pc_printf("Total requirements:%8ld bytes\n", (long)code_idx+(long)glb_declared*sizeof(cell)+(long)pc_stksize*sizeof(cell));
} /* if */
if (flag_exceed)
error(166,pc_amxlimit+pc_amxram); /* this causes a jump back to label "cleanup" */
error(FATAL_ERROR_INT_OVERFLOW,pc_amxlimit+pc_amxram); /* this causes a jump back to label "cleanup" */
} /* if */
#endif
@ -1086,14 +1086,14 @@ static void parserespf(char *filename,char *oname,char *ename,char *pname,
long size;
if ((fp=fopen(filename,"r"))==NULL)
error(160,filename); /* error reading input file */
error(FATAL_ERROR_READ,filename);
/* load the complete file into memory */
fseek(fp,0L,SEEK_END);
size=ftell(fp);
fseek(fp,0L,SEEK_SET);
assert(size<INT_MAX);
if ((string=(char *)malloc((int)size+1))==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
/* fill with zeros; in MS-DOS, fread() may collapse CR/LF pairs to
* a single '\n', so the string size may be smaller than the file
* size. */
@ -1102,7 +1102,7 @@ static void parserespf(char *filename,char *oname,char *ename,char *pname,
fclose(fp);
/* allocate table for option pointers */
if ((argv=(char **)malloc(MAX_OPTIONS*sizeof(char*)))==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
/* fill the options table */
ptr=strtok(string," \t\r\n");
for (argc=1; argc<MAX_OPTIONS && ptr!=NULL; argc++) {
@ -1111,7 +1111,7 @@ static void parserespf(char *filename,char *oname,char *ename,char *pname,
ptr=strtok(NULL," \t\r\n");
} /* for */
if (ptr!=NULL)
error(162,"option table"); /* table overflow */
error(FATAL_ERROR_ALLOC_OVERFLOW,"option table");
/* parse the option table */
parseoptions(argc,argv,oname,ename,pname,rname,codepage);
/* free allocated memory */
@ -1221,7 +1221,7 @@ static void setconfig(char *root)
# if !defined NO_CODEPAGE
*ptr='\0';
if (!cp_path(path,"codepage"))
error(169,path); /* codepage path */
error(FATAL_ERROR_INVALID_PATH,path);
# endif /* !NO_CODEPAGE */
/* also copy the root path (for the XML documentation) */
@ -3160,7 +3160,7 @@ static void parse_old_array_dims(declinfo_t *decl, int flags)
type->size = needsub(&type->idxtag[type->numdim], enumrootp);
if (type->size > INT_MAX)
error(165);
error(FATAL_ERROR_INT_OVERFLOW);
type->dim[type->numdim++] = type->size;
} while (matchtoken('['));
@ -3994,7 +3994,7 @@ static void domethodmap(LayoutSpec spec)
methods = (methodmap_method_t **)realloc(map->methods, sizeof(methodmap_method_t *) * (map->nummethods + 1));
if (!methods) {
error(163);
error(FATAL_ERROR_OOM);
return;
}
map->methods = methods;
@ -4521,7 +4521,7 @@ static void decl_enum(int vclass)
enumsym->usage |= uENUMROOT;
/* start a new list for the element names */
if ((enumroot=(constvalue*)malloc(sizeof(constvalue)))==NULL)
error(163); /* insufficient memory (fatal error) */
error(FATAL_ERROR_OOM); /* insufficient memory (fatal error) */
memset(enumroot,0,sizeof(constvalue));
} else {
enumsym=NULL;
@ -4671,7 +4671,7 @@ static void attachstatelist(symbol *sym, int state_id)
constvalue *stateptr;
if (sym->states==NULL) {
if ((sym->states=(constvalue*)malloc(sizeof(constvalue)))==NULL)
error(163); /* insufficient memory (fatal error) */
error(FATAL_ERROR_OOM); /* insufficient memory (fatal error) */
memset(sym->states,0,sizeof(constvalue));
} /* if */
/* see whether the id already exists (add new state only if it does not
@ -5483,7 +5483,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag)
/* redimension the argument list, add the entry iVARARGS */
sym->dim.arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo));
if (sym->dim.arglist==0)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */
sym->dim.arglist[argcnt].ident=iVARARGS;
sym->dim.arglist[argcnt].hasdefault=FALSE;
@ -5492,7 +5492,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag)
sym->dim.arglist[argcnt].numtags=decl.type.numtags;
sym->dim.arglist[argcnt].tags=(int*)malloc(decl.type.numtags*sizeof decl.type.tags[0]);
if (sym->dim.arglist[argcnt].tags==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
memcpy(sym->dim.arglist[argcnt].tags,decl.type.tags,decl.type.numtags*sizeof decl.type.tags[0]);
} else {
if (argcnt>oldargcnt || sym->dim.arglist[argcnt].ident!=iVARARGS)
@ -5525,7 +5525,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag)
/* redimension the argument list, add the entry */
sym->dim.arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo));
if (sym->dim.arglist==0)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */
sym->dim.arglist[argcnt]=arg;
} else {
@ -5684,7 +5684,7 @@ static void doarg(declinfo_t *decl, int offset, int fpublic, int chkshadow, argi
cell val;
tokeninfo(&val,&name);
if ((arg->defvalue.size.symname=duplicatestring(name)) == NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
arg->defvalue.size.level=0;
if (size_tag_token==uSIZEOF || size_tag_token==uCOUNTOF) {
while (matchtoken('[')) {
@ -5709,7 +5709,7 @@ static void doarg(declinfo_t *decl, int offset, int fpublic, int chkshadow, argi
arg->numtags=type->numtags;
arg->tags=(int*)malloc(type->numtags * sizeof(type->tags[0]));
if (arg->tags==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM); /* insufficient memory */
memcpy(arg->tags, type->tags, type->numtags * sizeof(type->tags[0]));
argsym=findloc(decl->name);
if (argsym!=NULL) {
@ -6458,7 +6458,7 @@ static constvalue *insert_constval(constvalue *prev,constvalue *next,const char
constvalue *cur;
if ((cur=(constvalue*)malloc(sizeof(constvalue)))==NULL)
error(163); /* insufficient memory (fatal error) */
error(FATAL_ERROR_OOM); /* insufficient memory (fatal error) */
memset(cur,0,sizeof(constvalue));
if (name!=NULL) {
assert(strlen(name)<=sNAMEMAX);
@ -7758,7 +7758,7 @@ static void addwhile(int *ptr)
ptr[wqLOOP]=getlabel();
ptr[wqEXIT]=getlabel();
if (wqptr>=(wq+wqTABSZ-wqSIZE))
error(162,"loop table"); /* loop table overflow (too many active loops)*/
error(FATAL_ERROR_ALLOC_OVERFLOW,"loop table"); /* loop table overflow (too many active loops)*/
k=0;
while (k<wqSIZE){ /* copy "ptr" to while queue table */
*wqptr=*ptr;

View File

@ -96,7 +96,7 @@ void pushstk(stkitem val)
assert(newsize>stktop);
newstack=(stkitem*)malloc(newsize*sizeof(stkitem));
if (newstack==NULL)
error(162,"parser stack"); /* stack overflow (recursive include?) */
error(FATAL_ERROR_ALLOC_OVERFLOW,"parser stack");
/* swap the stacks */
memcpy(newstack,stack,stkidx*sizeof(stkitem));
if (stack!=NULL)
@ -172,7 +172,7 @@ int plungequalifiedfile(char *name)
PUSHSTK_I(fline);
inpfname=duplicatestring(name);/* set name of include file */
if (inpfname==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
inpf=fp; /* set input file pointer to include file */
fnumber++;
fline=0; /* set current line number to 0 */
@ -276,7 +276,7 @@ static void doinclude(int silent)
result=plungefile(name,(c!='>'),TRUE);
if (!result && !silent)
error(160,name); /* cannot read from ... (fatal error) */
error(FATAL_ERROR_READ,name);
}
/* readline
@ -890,7 +890,7 @@ static int command(void)
ret=CMD_IF;
assert(iflevel>=0);
if (iflevel>=sCOMP_STACK)
error(162,"Conditional compilation stack"); /* table overflow */
error(FATAL_ERROR_ALLOC_OVERFLOW,"Conditional compilation stack");
iflevel++;
if (SKIPPING)
break; /* break out of switch */
@ -979,7 +979,7 @@ static int command(void)
free(inpfname);
inpfname=duplicatestring(pathname);
if (inpfname==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
fline=0;
} /* if */
} /* if */
@ -1023,7 +1023,7 @@ static int command(void)
name[i]='\0';
} /* if */
if (!cp_set(name))
error(168); /* codepage mapping file not found */
error(FATAL_ERROR_NO_CODEPAGE);
} else if (strcmp(str,"compress")==0) {
cell val;
preproc_expr(&val,NULL);
@ -1292,7 +1292,7 @@ static int command(void)
/* store matched pattern */
pattern=(char*)malloc(count+1);
if (pattern==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
lptr=start;
count=0;
while (lptr!=end) {
@ -1326,7 +1326,7 @@ static int command(void)
/* store matched substitution */
substitution=(char*)malloc(count+1); /* +1 for '\0' */
if (substitution==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
lptr=start;
count=0;
while (lptr!=end) {
@ -1542,7 +1542,7 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
len=(int)(e-s);
args[arg]=(unsigned char*)malloc(len+1);
if (args[arg]==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
strlcpy((char*)args[arg],(char*)s,len+1);
/* character behind the pattern was matched too */
if (*e==*p) {
@ -2469,7 +2469,7 @@ static void chk_grow_litq(void)
litmax+=sDEF_LITMAX;
p=(cell *)realloc(litq,litmax*sizeof(cell));
if (p==NULL)
error(162,"literal table"); /* literal table overflow (fatal error) */
error(FATAL_ERROR_ALLOC_OVERFLOW,"literal table");
litq=p;
} /* if */
}
@ -2662,7 +2662,7 @@ static symbol *add_symbol(symbol *root,symbol *entry,int sort)
root=root->next;
if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL) {
error(163);
error(FATAL_ERROR_OOM);
return NULL;
} /* if */
memcpy(newsym,entry,sizeof(symbol));
@ -3057,7 +3057,7 @@ symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,int usage
/* create an empty referrer list */
if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL) {
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
return NULL;
} /* if */
*refer=NULL;

View File

@ -2212,7 +2212,7 @@ restart:
*/
sym=fetchfunc(lastsymbol);
if (sym==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
markusage(sym,uREAD);
} else {
return error(12); /* invalid function call */
@ -2358,7 +2358,7 @@ static int primary(value *lval)
assert(sc_status==statFIRST);
sym=fetchfunc(st);
if (sym==NULL)
error(163); /* insufficient memory */
error(FATAL_ERROR_OOM);
} /* if */
assert(sym!=NULL);
assert(sym->ident==iFUNCTN || sym->ident==iREFFUNC);

View File

@ -365,24 +365,24 @@ static const char *errmsg[] = {
static const char *fatalmsg[] = {
#ifdef SCPACK
/*160*/ "cannot read from file: \"%s\"\n",
/*161*/ "cannot write to file: \"%s\"\n",
/*162*/ "table overflow: \"%s\"\n",
/*180*/ "cannot read from file: \"%s\"\n",
/*181*/ "cannot write to file: \"%s\"\n",
/*182*/ "table overflow: \"%s\"\n",
/* table can be: loop table
* literal table
* staging buffer
* option table (response file)
* peephole optimizer table
*/
/*163*/ "insufficient memory\n",
/*164*/ "invalid assembler instruction \"%s\"\n",
/*165*/ "numeric overflow, exceeding capacity\n",
/*166*/ "compiled script exceeds the maximum memory size (%ld bytes)\n",
/*167*/ "too many error messages on one line\n",
/*168*/ "codepage mapping file not found\n",
/*169*/ "invalid path: \"%s\"\n",
/*170*/ "assertion failed: %s\n",
/*171*/ "user error: %s\n",
/*183*/ "insufficient memory\n",
/*184*/ "invalid assembler instruction \"%s\"\n",
/*185*/ "numeric overflow, exceeding capacity\n",
/*186*/ "compiled script exceeds the maximum memory size (%ld bytes)\n",
/*187*/ "too many error messages on one line\n",
/*188*/ "codepage mapping file not found\n",
/*189*/ "invalid path: \"%s\"\n",
/*190*/ "assertion failed: %s\n",
/*191*/ "user error: %s\n",
#else
"\256\214a\204from \344le:\354",
"\256writ\200\266 \344le:\354",

View File

@ -89,7 +89,7 @@ static short lastfile;
* the error reporting is enabled only in the second pass (and only when
* actually producing output). Fatal errors may never be ignored.
*/
int not_fatal = (number < 160 || number >= 200);
int not_fatal = (number < FIRST_FATAL_ERROR || number >= 200);
if (errflag && not_fatal)
return 0;
if (sc_status != statWRITE && not_fatal) {
@ -105,13 +105,13 @@ static short lastfile;
return 0;
} /* if */
if (number<160){
if (number<FIRST_FATAL_ERROR) {
msg=errmsg[number-1];
pre=prefix[0];
errflag=TRUE; /* set errflag (skip rest of erroneous expression) */
errnum++;
} else if (number<200){
msg=fatalmsg[number-160];
msg=fatalmsg[number-FIRST_FATAL_ERROR];
pre=prefix[1];
errnum++; /* a fatal error also counts as an error */
} else {
@ -154,7 +154,7 @@ static short lastfile;
} /* if */
va_end(argptr);
if ((number>=160 && number<200) || errnum>25){
if ((number>=FIRST_FATAL_ERROR && number<200) || errnum>25){
if (strlen(errfname)==0) {
va_start(argptr,number);
pc_error(0,"\nCompilation aborted.",NULL,0,0,argptr);
@ -175,7 +175,7 @@ static short lastfile;
if (!is_warning)
errorcount++;
if (errorcount>=3)
error(167); /* too many error/warning messages on one line */
error(FATAL_ERROR_OVERWHELMED_BY_BAD);
return 0;
}

View File

@ -920,12 +920,12 @@ static void splat_to_binary(const char *binfname, void *bytes, size_t size)
// Note: error 161 will setjmp(), which skips destructors :(
FILE *fp = fopen(binfname, "wb");
if (!fp) {
error(161, binfname);
error(FATAL_ERROR_WRITE, binfname);
return;
}
if (fwrite(bytes, 1, size, fp) != size) {
fclose(fp);
error(161, binfname);
error(FATAL_ERROR_WRITE, binfname);
return;
}
fclose(fp);

View File

@ -95,14 +95,14 @@ static void grow_stgbuffer(char **buffer, int *curmax, int requiredsize)
* over a few kBytes, there is probably a run-away expression
*/
if (requiredsize>sSTG_MAX)
error(163); /* staging buffer overflow (fatal error) */
error(FATAL_ERROR_OOM);
*curmax=requiredsize+sSTG_GROW;
if (*buffer!=NULL)
p=(char *)realloc(*buffer,*curmax*sizeof(char));
else
p=(char *)malloc(*curmax*sizeof(char));
if (p==NULL)
error(163); /* staging buffer overflow (fatal error) */
error(FATAL_ERROR_OOM);
*buffer=p;
if (clear)
**buffer='\0';