mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 21:41:03 +00:00
Update lemon.c to August 2012 version from SQLite.
- Add a missing check for out-of-memory in the lemon code generator. - Fix a total unimportant file descriptor leak in lemon. This is to silence warning messages. - Fix a bug in lemon in computation of which non-terminals can generate an empty string. This bug and the fix make absolutely no difference for the grammar used by SQLite, but it can make a difference when lemon is used in other grammars. - In Lemon, when comparing the output to the *.h file to see if it has changed, make sure that the proposed new output and the preexisting output are the same size before deciding that they are the same.
This commit is contained in:
parent
11b588de4a
commit
91207ed3f4
1 changed files with 11 additions and 2 deletions
|
@ -632,7 +632,8 @@ struct lemon *lemp;
|
||||||
if( rp->lhs->lambda ) continue;
|
if( rp->lhs->lambda ) continue;
|
||||||
for(i=0; i<rp->nrhs; i++){
|
for(i=0; i<rp->nrhs; i++){
|
||||||
struct symbol *sp = rp->rhs[i];
|
struct symbol *sp = rp->rhs[i];
|
||||||
if( sp->type!=TERMINAL || sp->lambda==LEMON_FALSE ) break;
|
assert( sp->type==NONTERMINAL || sp->lambda==LEMON_FALSE );
|
||||||
|
if( sp->lambda==LEMON_FALSE ) break;
|
||||||
}
|
}
|
||||||
if( i==rp->nrhs ){
|
if( i==rp->nrhs ){
|
||||||
rp->lhs->lambda = LEMON_TRUE;
|
rp->lhs->lambda = LEMON_TRUE;
|
||||||
|
@ -2549,6 +2550,7 @@ struct lemon *gp;
|
||||||
ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.",
|
ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.",
|
||||||
filesize+1);
|
filesize+1);
|
||||||
gp->errorcnt++;
|
gp->errorcnt++;
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( fread(filebuf,1,filesize,fp)!=filesize ){
|
if( fread(filebuf,1,filesize,fp)!=filesize ){
|
||||||
|
@ -2556,6 +2558,7 @@ struct lemon *gp;
|
||||||
filesize);
|
filesize);
|
||||||
free(filebuf);
|
free(filebuf);
|
||||||
gp->errorcnt++;
|
gp->errorcnt++;
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -3421,6 +3424,10 @@ int mhflag; /* True if generating makeheaders output */
|
||||||
/* Allocate and initialize types[] and allocate stddt[] */
|
/* Allocate and initialize types[] and allocate stddt[] */
|
||||||
arraysize = lemp->nsymbol * 2;
|
arraysize = lemp->nsymbol * 2;
|
||||||
types = (char**)calloc( arraysize, sizeof(char*) );
|
types = (char**)calloc( arraysize, sizeof(char*) );
|
||||||
|
if( types==0 ){
|
||||||
|
fprintf(stderr,"Out of memory.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
maxdtlength = 0;
|
maxdtlength = 0;
|
||||||
if( lemp->vartype ){
|
if( lemp->vartype ){
|
||||||
maxdtlength = lemonStrlen(lemp->vartype);
|
maxdtlength = lemonStrlen(lemp->vartype);
|
||||||
|
@ -4028,12 +4035,14 @@ struct lemon *lemp;
|
||||||
else prefix = "";
|
else prefix = "";
|
||||||
in = file_open(lemp,".h","rb");
|
in = file_open(lemp,".h","rb");
|
||||||
if( in ){
|
if( in ){
|
||||||
|
int nextChar;
|
||||||
for(i=1; i<lemp->nterminal && fgets(line,LINESIZE,in); i++){
|
for(i=1; i<lemp->nterminal && fgets(line,LINESIZE,in); i++){
|
||||||
sprintf(pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
|
sprintf(pattern,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
|
||||||
if( strcmp(line,pattern) ) break;
|
if( strcmp(line,pattern) ) break;
|
||||||
}
|
}
|
||||||
|
nextChar = fgetc(in);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
if( i==lemp->nterminal ){
|
if( i==lemp->nterminal && nextChar==EOF ){
|
||||||
/* No change in the file. Don't rewrite it. */
|
/* No change in the file. Don't rewrite it. */
|
||||||
/* (not the best idea if you use make tools that check the date! */
|
/* (not the best idea if you use make tools that check the date! */
|
||||||
/*return;*/
|
/*return;*/
|
||||||
|
|
Loading…
Reference in a new issue