From: drh <> Date: Thu, 8 Jun 2023 12:52:28 +0000 (+0000) Subject: Enhance Lemon so that it remembers which -D command-line options are actually X-Git-Tag: version-3.43.0~215 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4fa5952090ad974d6a11952267662d4af338154a;p=thirdparty%2Fsqlite.git Enhance Lemon so that it remembers which -D command-line options are actually used in the grammar and includes a list of all such options in the header of the generated output file. FossilOrigin-Name: c47a4dbd24b8277c57b7a83a8c0aeac2bc8f6ab75d1b65ba5e1fa83d1868d95f --- diff --git a/manifest b/manifest index 795aba98cf..fdb2d9e731 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sspell-checking\sfor\sall\scomments\sin\smain\ssources.\s(./src/\s.c\s.h\s.in)\smake\starget\s"misspell"\stells\sof\smisspelled\swords\sfor\swhich\sno\sexceptions\shave\sbeen\sput\sinto\stool/custom.txt\s. -D 2023-06-07T23:10:40.610 +C Enhance\sLemon\sso\sthat\sit\sremembers\swhich\s-D\scommand-line\soptions\sare\sactually\nused\sin\sthe\sgrammar\sand\sincludes\sa\slist\sof\sall\ssuch\soptions\sin\sthe\sheader\nof\sthe\sgenerated\soutput\sfile. +D 2023-06-08T12:52:28.968 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1954,7 +1954,7 @@ F tool/genfkey.test b6afd7b825d797a1e1274f519ab5695373552ecad5cd373530c63533638a F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/index_usage.c f62a0c701b2c7ff2f3e21d206f093c123f222dbf07136a10ffd1ca15a5c706c5 F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f -F tool/lemon.c ea5c8589c7749e9bd32ba10432aeeed3c16e215de72a12ada2bc707884837149 +F tool/lemon.c 19e368bc8e97ff4071115119a7911ca3b0c56eba7926d8ada8b4a86fcc69a176 F tool/lempar.c 57478ea48420da05faa873c6d1616321caa5464644588c97fbe8e0ea04450748 F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 @@ -2040,8 +2040,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9a12bac5d24c7a8364d2127fd12c3409a53ef83e408d10f344ddd311cdba98af 8c291d99946eb32b20b743921202f9c7cfb716268ff526817b27adbb7942e40b -R afa3749bf57be03443dd9fb9514c3cf7 -U larrybr -Z 0c523abe03ffdbb3d9d4cf04093ae69e +P 5332abf0ad8ef42c44e9dd7045d017bb8fc9a0262a89ababa3e2c41788a6cdb8 +R 8901e2725cbc66d820e7686f035bb3c9 +U drh +Z e939ccde6d44f5ae271532ac04101d42 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 184b744738..275994dbe8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5332abf0ad8ef42c44e9dd7045d017bb8fc9a0262a89ababa3e2c41788a6cdb8 \ No newline at end of file +c47a4dbd24b8277c57b7a83a8c0aeac2bc8f6ab75d1b65ba5e1fa83d1868d95f \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index fb81292d4d..7804837a06 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -426,7 +426,8 @@ 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 */ - char *argv0; /* Name of the program */ + int argc; /* Number of command-line arguments */ + char **argv; /* Command-line arguments */ }; #define MemoryCheck(X) if((X)==0){ \ @@ -1516,8 +1517,10 @@ void memory_error(void){ exit(1); } -static int nDefine = 0; /* Number of -D options on the command line */ -static char **azDefine = 0; /* Name of the -D macros */ +static int nDefine = 0; /* Number of -D options on the command line */ +static int nDefineUsed = 0; /* Number of -D options actually used */ +static char **azDefine = 0; /* Name of the -D macros */ +static char *bDefineUsed = 0; /* True for every -D macro actually used */ /* This routine is called with the argument to each -D command-line option. ** Add the macro defined to the azDefine array. @@ -1530,6 +1533,12 @@ static void handle_D_option(char *z){ fprintf(stderr,"out of memory\n"); exit(1); } + bDefineUsed = (char*)realloc(bDefineUsed, nDefine); + if( bDefineUsed==0 ){ + fprintf(stderr,"out of memory\n"); + exit(1); + } + bDefineUsed[nDefine-1] = 0; paz = &azDefine[nDefine-1]; *paz = (char *) malloc( lemonStrlen(z)+1 ); if( *paz==0 ){ @@ -1666,7 +1675,6 @@ 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"); @@ -1683,7 +1691,8 @@ int main(int argc, char **argv){ Strsafe_init(); Symbol_init(); State_init(); - lem.argv0 = argv[0]; + lem.argv = argv; + lem.argc = argc; lem.filename = OptArg(0); lem.basisflag = basisflag; lem.nolinenosflag = nolinenosflag; @@ -2856,6 +2865,10 @@ static int eval_preprocessor_boolean(char *z, int lineno){ res = 0; for(j=0; jargv0,templatename,0); + toFree = tpltname = pathsearch(lemp->argv[0],templatename,0); } if( tpltname==0 ){ fprintf(stderr,"Can't find the parser driver template file \"%s\".\n", @@ -4396,7 +4409,17 @@ void ReportTable( fprintf(out, "/* This file is automatically generated by Lemon from input grammar\n" - "** source file \"%s\". */\n", lemp->filename); lineno += 2; + "** source file \"%s\"", lemp->filename); lineno++; + if( nDefineUsed==0 ){ + fprintf(out, ".\n*/\n"); lineno += 2; + }else{ + fprintf(out, " with these options:\n**\n"); lineno += 2; + for(i=0; i