ENH: update lemon version (#1768)

- upstream fixes: minor compiler warnings, style changes
This commit is contained in:
Mark Olesen
2020-11-06 09:31:32 +01:00
parent 1d544540d9
commit f7c8e39804
4 changed files with 93 additions and 62 deletions

View File

@ -1,6 +1,7 @@
/* https://sqlite.org/src/artifact/600a58b9
* Artifact 600a58b9d1b8ec5419373982428e927ca208826edacb91ca42ab94514d006039:
* File tool/lemon.c part of check-in [951d22b7] at 2020-07-03
/*
* https://www.sqlite.org/src/artifact/70eedc31
* Artifact 70eedc31614a58fe31a71025c17ebd1502a6ce9cfef0ed5e33acb0b5b737b291:
* File tool/lemon.c part of check-in [4591ee03] at 2020-09-21
*/
/*
** This file contains all sources (including headers) to the LEMON
@ -430,7 +431,7 @@ struct lemon {
int printPreprocessed; /* Show preprocessor output on stdout */
int has_fallback; /* True if any %fallback is seen in the grammar */
int nolinenosflag; /* True if #line statements should not be printed */
int linkage; /* 1 if %static provided (use static linkage) */
int linkage; /* True if %static provided (use static linkage) */
char *argv0; /* Name of the program */
};
@ -1614,14 +1615,14 @@ static struct rule *Rule_merge(struct rule *pA, struct rule *pB){
** Sort a list of rules in order of increasing iRule value
*/
static struct rule *Rule_sort(struct rule *rp){
int i;
unsigned int i;
struct rule *pNext;
struct rule *x[32];
memset(x, 0, sizeof(x));
while( rp ){
pNext = rp->next;
rp->next = 0;
for(i=0; i<sizeof(x)/sizeof(x[0]) && x[i]; i++){
for(i=0; i<sizeof(x)/sizeof(x[0])-1 && x[i]; i++){
rp = Rule_merge(x[i], rp);
x[i] = 0;
}
@ -1648,8 +1649,7 @@ static void stats_line(const char *zLabel, int iValue){
}
/* The main program. Parse the command line and do it... */
int main(int argc, char **argv)
{
int main(int argc, char **argv){
static int version = 0;
static int rpflag = 0;
static int basisflag = 0;
@ -1693,6 +1693,7 @@ int main(int argc, char **argv)
struct lemon lem;
struct rule *rp;
(void)argc;
OptInit(argv,options,stderr);
if( version ){
printf("Lemon version 1.0\n");
@ -2291,7 +2292,7 @@ static void parseonetoken(struct pstate *psp)
psp->firstrule = psp->lastrule = 0;
psp->gp->nrule = 0;
psp->gp->linkage = 0;
/* Fall thru to next case */
/* fall through */
case WAITING_FOR_DECL_OR_RULE:
if( x[0]=='%' ){
psp->state = WAITING_FOR_DECL_KEYWORD;
@ -2451,7 +2452,7 @@ static void parseonetoken(struct pstate *psp)
psp->alias[psp->nrhs] = 0;
psp->nrhs++;
}
}else if( (x[0]=='|' || x[0]=='/') && psp->nrhs>0 ){
}else if( (x[0]=='|' || x[0]=='/') && psp->nrhs>0 && ISUPPER(x[1]) ){
struct symbol *msp = psp->rhs[psp->nrhs-1];
if( msp->type!=MULTITERMINAL ){
struct symbol *origsp = msp;
@ -2668,8 +2669,10 @@ static void parseonetoken(struct pstate *psp)
}
nOld = lemonStrlen(zOld);
n = nOld + nNew + 20;
addLineMacro = !psp->gp->nolinenosflag && psp->insertLineMacro &&
(psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
addLineMacro = !psp->gp->nolinenosflag
&& psp->insertLineMacro
&& psp->tokenlineno>1
&& (psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
if( addLineMacro ){
for(z=psp->filename, nBack=0; *z; z++){
if( *z=='\\' ) nBack++;
@ -3545,8 +3548,8 @@ void ReportOutput(struct lemon *lemp)
PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
{
const char *pathlist;
char *pathbufptr;
char *pathbuf;
char *pathbufptr = 0;
char *pathbuf = 0;
char *path,*cp;
char c;
@ -3580,8 +3583,8 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
else pathbuf = &cp[1];
if( access(path,modemask)==0 ) break;
}
free(pathbufptr);
}
free(pathbufptr);
}
return path;
}
@ -3647,6 +3650,16 @@ PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno)
}
}
/* Skip forward past the header of the template file to the first "%%"
*/
PRIVATE void tplt_skip_header(FILE *in, int *lineno)
{
char line[LINESIZE];
while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){
(*lineno)++;
}
}
/* The next function finds the template file and opens it, returning
** a pointer to the opened file. */
PRIVATE FILE *tplt_open(struct lemon *lemp)
@ -3655,6 +3668,7 @@ PRIVATE FILE *tplt_open(struct lemon *lemp)
char buf[1000];
FILE *in;
char *tpltname;
char *toFree = 0;
char *cp;
/* first, see if user specified a template filename on the command line. */
@ -3686,7 +3700,7 @@ PRIVATE FILE *tplt_open(struct lemon *lemp)
}else if( access(templatename,004)==0 ){
tpltname = templatename;
}else{
tpltname = pathsearch(lemp->argv0,templatename,0);
toFree = tpltname = pathsearch(lemp->argv0,templatename,0);
}
if( tpltname==0 ){
fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
@ -3696,10 +3710,10 @@ PRIVATE FILE *tplt_open(struct lemon *lemp)
}
in = fopen(tpltname,"rb");
if( in==0 ){
fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
fprintf(stderr,"Can't open the template file \"%s\".\n",tpltname);
lemp->errorcnt++;
return 0;
}
free(toFree);
return in;
}
@ -4317,6 +4331,7 @@ void ReportTable(
int mnTknOfst, mxTknOfst;
int mnNtOfst, mxNtOfst;
struct axset *ax;
char *prefix;
lemp->minShiftReduce = lemp->nstate;
lemp->errAction = lemp->minShiftReduce + lemp->nrule;
@ -4405,7 +4420,26 @@ void ReportTable(
fprintf(sql, "COMMIT;\n");
}
lineno = 1;
tplt_xfer(lemp->name,in,out,&lineno);
fprintf(out,
"/* This file is automatically generated by Lemon from input grammar\n"
"** source file \"%s\". */\n", lemp->filename); lineno += 2;
/* The first %include directive begins with a C-language comment,
** then skip over the header comment of the template file
*/
if( lemp->include==0 ) lemp->include = "";
for(i=0; ISSPACE(lemp->include[i]); i++){
if( lemp->include[i]=='\n' ){
lemp->include += i+1;
i = -1;
}
}
if( lemp->include[0]=='/' ){
tplt_skip_header(in,&lineno);
}else{
tplt_xfer(lemp->name,in,out,&lineno);
}
/* Generate the include code, if any */
tplt_print(out,lemp,lemp->include,&lineno);
@ -4417,17 +4451,18 @@ void ReportTable(
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate #defines for all tokens */
if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
else prefix = "";
if( mhflag ){
const char *prefix;
fprintf(out,"#if INTERFACE\n"); lineno++;
if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
else prefix = "";
for(i=1; i<lemp->nterminal; i++){
fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
lineno++;
}
fprintf(out,"#endif\n"); lineno++;
}else{
fprintf(out,"#ifndef %s%s\n", prefix, lemp->symbols[1]->name);
}
for(i=1; i<lemp->nterminal; i++){
fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
lineno++;
}
fprintf(out,"#endif\n"); lineno++;
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the defines */