diff --git a/wmake/etc/lempar.c b/wmake/etc/lempar.c index d0819063b4..e2d0de8cf2 100644 --- a/wmake/etc/lempar.c +++ b/wmake/etc/lempar.c @@ -22,17 +22,13 @@ ** The following is the concatenation of all %include directives from the ** input grammar file: */ -#include -#include /************ Begin %include sections from the grammar ************************/ %% /**************** End of %include directives **********************************/ -/* These constants specify the various numeric values for terminal symbols -** in a format understandable to "makeheaders". This section is blank unless -** "lemon" is run with the "-m" command-line option. -***************** Begin makeheaders token definitions *************************/ +/* These constants specify the various numeric values for terminal symbols. +***************** Begin token definitions *************************************/ %% -/**************** End makeheaders token definitions ***************************/ +/**************** End token definitions ***************************************/ /* The next sections is a series of control #defines. ** various aspects of the generated parser. @@ -93,8 +89,7 @@ /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) -/* Default linkage for exposed parser routines is global -*/ +/* Default linkage for exposed parser routines is global */ #ifndef YYFUNCAPI # define YYFUNCAPI #endif @@ -235,6 +230,7 @@ typedef struct yyParser yyParser; #ifndef NDEBUG #include +#include static FILE *yyTraceFILE = 0; static char *yyTracePrompt = 0; #endif /* NDEBUG */ @@ -575,7 +571,7 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && i=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) ); return yy_action[i]; } }while(1); @@ -734,8 +730,9 @@ static YYACTIONTYPE yy_reduce( (void)yyLookahead; (void)yyLookaheadToken; yymsp = yypParser->yytos; + assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); #ifndef NDEBUG - if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + if( yyTraceFILE ){ yysize = yyRuleInfoNRhs[yyruleno]; if( yysize ){ fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", diff --git a/wmake/etc/lempar.c.patch b/wmake/etc/lempar.c.patch index 86dd2c78b6..f7368ba7e6 100644 --- a/wmake/etc/lempar.c.patch +++ b/wmake/etc/lempar.c.patch @@ -1,11 +1,10 @@ ---- lempar.c.orig 2020-07-09 14:55:42.000000000 +0200 -+++ lempar.c 2020-07-10 11:04:51.991472607 +0200 -@@ -93,6 +93,12 @@ +--- lempar.c.orig 2020-11-05 19:44:09.412097759 +0100 ++++ lempar.c 2020-11-06 09:03:57.932738075 +0100 +@@ -89,6 +89,11 @@ /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) -+/* Default linkage for exposed parser routines is global -+*/ ++/* Default linkage for exposed parser routines is global */ +#ifndef YYFUNCAPI +# define YYFUNCAPI +#endif @@ -13,7 +12,7 @@ /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. ** -@@ -251,6 +257,7 @@ +@@ -248,6 +253,7 @@ ** Outputs: ** None. */ @@ -21,7 +20,7 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ yyTraceFILE = TraceFILE; yyTracePrompt = zTracePrompt; -@@ -320,6 +327,7 @@ +@@ -317,6 +323,7 @@ /* Initialize a new parser that has already been allocated. */ @@ -29,7 +28,7 @@ void ParseInit(void *yypRawParser ParseCTX_PDECL){ yyParser *yypParser = (yyParser*)yypRawParser; ParseCTX_STORE -@@ -359,6 +367,7 @@ +@@ -356,6 +363,7 @@ ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ @@ -37,7 +36,7 @@ void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ yyParser *yypParser; yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); -@@ -427,6 +436,7 @@ +@@ -424,6 +432,7 @@ /* ** Clear all secondary memory allocations from the parser */ @@ -45,7 +44,7 @@ void ParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); -@@ -444,6 +454,7 @@ +@@ -441,6 +450,7 @@ ** is defined in a %include section of the input grammar) then it is ** assumed that the input pointer is never NULL. */ @@ -53,7 +52,7 @@ void ParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ -@@ -460,6 +471,7 @@ +@@ -457,6 +467,7 @@ ** Return the peak depth of the stack for a parser. */ #ifdef YYTRACKMAXSTACKDEPTH @@ -61,7 +60,7 @@ int ParseStackPeak(void *p){ yyParser *pParser = (yyParser*)p; return pParser->yyhwm; -@@ -484,6 +496,7 @@ +@@ -481,6 +492,7 @@ ** Return the number of missed state/lookahead combinations. */ #if defined(YYCOVERAGE) @@ -69,7 +68,7 @@ int ParseCoverage(FILE *out){ int stateno, iLookAhead, i; int nMissed = 0; -@@ -891,6 +904,7 @@ +@@ -889,6 +901,7 @@ ** Outputs: ** None. */ @@ -77,7 +76,7 @@ void Parse( void *yyp, /* The parser */ int yymajor, /* The major token code number */ -@@ -1065,6 +1079,7 @@ +@@ -1063,6 +1076,7 @@ ** Return the fallback token corresponding to canonical token iToken, or ** 0 if iToken has no fallback. */ diff --git a/wmake/src/lemon.c b/wmake/src/lemon.c index 8950d88293..216972677d 100644 --- a/wmake/src/lemon.c +++ b/wmake/src/lemon.c @@ -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; ifirstrule = 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; interminal; 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; interminal; 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 */ diff --git a/wmake/src/lemon.c.patch b/wmake/src/lemon.c.patch index 074c1ee483..0224efc9bf 100644 --- a/wmake/src/lemon.c.patch +++ b/wmake/src/lemon.c.patch @@ -1,14 +1,14 @@ ---- lemon.c.orig 2020-07-09 14:54:53.871102972 +0200 -+++ lemon.c 2020-07-10 12:01:05.488791973 +0200 +--- lemon.c.orig 2020-11-05 19:43:43.780141575 +0100 ++++ lemon.c 2020-11-05 19:59:41.022505205 +0100 @@ -426,6 +426,7 @@ 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 */ }; -@@ -1555,6 +1556,24 @@ +@@ -1555,6 +1560,24 @@ lemon_strcpy(outputDir, z); } @@ -33,7 +33,7 @@ static char *user_templatename = NULL; static void handle_T_option(char *z){ user_templatename = (char *) malloc( lemonStrlen(z)+1 ); -@@ -1644,6 +1663,7 @@ +@@ -1643,6 +1666,7 @@ {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."}, {OPT_FSTR, "d", (char*)&handle_d_option, "Output directory. Default '.'"}, {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."}, @@ -41,15 +41,15 @@ {OPT_FLAG, "E", (char*)&printPP, "Print input file after preprocessing."}, {OPT_FSTR, "f", 0, "Ignored. (Placeholder for -f compiler options.)"}, {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."}, -@@ -2266,6 +2286,7 @@ +@@ -2266,6 +2290,7 @@ psp->preccounter = 0; 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]=='%' ){ -@@ -2551,6 +2572,11 @@ +@@ -2551,6 +2576,11 @@ psp->state = WAITING_FOR_WILDCARD_ID; }else if( strcmp(x,"token_class")==0 ){ psp->state = WAITING_FOR_CLASS_ID; @@ -61,7 +61,7 @@ }else{ ErrorMsg(psp->filename,psp->tokenlineno, "Unknown declaration keyword: \"%%%s\".",x); -@@ -4297,7 +4323,7 @@ +@@ -4311,7 +4341,7 @@ in = tplt_open(lemp); if( in==0 ) return; @@ -70,7 +70,7 @@ if( out==0 ){ fclose(in); return; -@@ -4401,6 +4427,9 @@ +@@ -4435,6 +4465,9 @@ tplt_xfer(lemp->name,in,out,&lineno); /* Generate the defines */