From 4dc8ef520a21bcce59fdada5071f0b357955795a Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 1 Jul 2008 17:13:57 +0000 Subject: [PATCH] In lemon: coalesce identical destructors. (CVS 5335) FossilOrigin-Name: 3447086cd3f6e9b89a8cf61afcf4715977bbf4cd --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lemon.c | 27 ++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d1a76f14c5..4288c90631 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sLemon,\sif\sa\snon-terminal\shas\sthe\ssame\stype\sas\sa\sterminal,\sthen\sreuse\sthe\nterminal\stype\sin\sthe\sYYMINORTYPE\sunion\sfor\sthe\snon-terminal.\s\sThis\sgives\nbetter\stable\scompression.\s(CVS\s5334) -D 2008-07-01T16:34:50 +C In\slemon:\scoalesce\sidentical\sdestructors.\s(CVS\s5335) +D 2008-07-01T17:13:57 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -574,7 +574,7 @@ F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 -F tool/lemon.c b7ea2ab73efcae17de678e27311e3a6fb45b9916 +F tool/lemon.c f1f54e93808b09d2000ec1c3ff53888a27067b52 F tool/lempar.c aab54f1758c554e550ff5c4b191053a819279a2b F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133 F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8 @@ -596,7 +596,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 6ee71f4ddb4fa934f58c87dad2d30560af2e55d7 -R abb51076ff7832ca4d7b7efbfab1e246 +P 5c9cc22cd8e9bec3d8622d2c354423281f2db0fb +R 572c6d45547d9cace3b11f3c52551913 U drh -Z 25821389214193632a5f6ed1eb5ed459 +Z d8dbcd09b221a01c995fcf2ef0061da2 diff --git a/manifest.uuid b/manifest.uuid index e0be29f2c7..75e29d7502 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c9cc22cd8e9bec3d8622d2c354423281f2db0fb \ No newline at end of file +3447086cd3f6e9b89a8cf61afcf4715977bbf4cd \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index 85baf4200b..4421b76ded 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -134,6 +134,7 @@ struct symbol { int useCnt; /* Number of times used */ char *destructor; /* Code which executes whenever this symbol is ** popped from the stack during error processing */ + int destLineno; /* Line number for start of destructor */ char *datatype; /* The data type of information held by this ** object. Only used if type==NONTERMINAL */ int dtnum; /* The data type number. In the parser, the value @@ -1961,6 +1962,7 @@ struct pstate { char *declkeyword; /* Keyword of a declaration */ char **declargslot; /* Where the declaration argument should be put */ int insertLineMacro; /* Add #line before declaration insert */ + int *decllinenoslot; /* Where to write declaration line number */ enum e_assoc declassoc; /* Assign this association to decl arguments */ int preccounter; /* Assign this precedence to decl arguments */ struct rule *firstrule; /* Pointer to first rule in the grammar */ @@ -2194,6 +2196,7 @@ to follow the previous rule."); if( isalpha(x[0]) ){ psp->declkeyword = x; psp->declargslot = 0; + psp->decllinenoslot = 0; psp->insertLineMacro = 1; psp->state = WAITING_FOR_DECL_ARG; if( strcmp(x,"name")==0 ){ @@ -2276,6 +2279,7 @@ to follow the previous rule."); }else{ struct symbol *sp = Symbol_new(x); psp->declargslot = &sp->destructor; + psp->decllinenoslot = &sp->destLineno; psp->insertLineMacro = 1; psp->state = WAITING_FOR_DECL_ARG; } @@ -2328,7 +2332,8 @@ to follow the previous rule."); } nOld = strlen(zOld); n = nOld + nNew + 20; - if( psp->insertLineMacro ){ + if( psp->insertLineMacro && psp->decllinenoslot + && psp->decllinenoslot[0] ){ for(z=psp->filename, nBack=0; *z; z++){ if( *z=='\\' ) nBack++; } @@ -2338,7 +2343,8 @@ to follow the previous rule."); } *psp->declargslot = zBuf = realloc(*psp->declargslot, n); zBuf += nOld; - if( psp->insertLineMacro ){ + if( psp->insertLineMacro && psp->decllinenoslot + && psp->decllinenoslot[0] ){ if( nOld && zBuf[-1]!='\n' ){ *(zBuf++) = '\n'; } @@ -2354,6 +2360,9 @@ to follow the previous rule."); *(zBuf++) = '"'; *(zBuf++) = '\n'; } + if( psp->decllinenoslot && psp->decllinenoslot[0]==0 ){ + psp->decllinenoslot[0] = psp->tokenlineno; + } memcpy(zBuf, zNew, nNew); zBuf += nNew; *zBuf = 0; @@ -3137,6 +3146,7 @@ int *lineno; }else if( sp->destructor ){ cp = sp->destructor; fprintf(out,"{\n"); (*lineno)++; + tplt_linedir(out,sp->destLineno,lemp->outname); (*lineno)++; }else if( lemp->vardest ){ cp = lemp->vardest; if( cp==0 ) return; @@ -3833,9 +3843,14 @@ int mhflag; /* Output in makeheaders format if true */ ** (In other words, generate the %destructor actions) */ if( lemp->tokendest ){ + int once = 1; for(i=0; insymbol; i++){ struct symbol *sp = lemp->symbols[i]; if( sp==0 || sp->type!=TERMINAL ) continue; + if( once ){ + fprintf(out, " /* TERMINAL Destructor */\n"); lineno++; + once = 0; + } fprintf(out," case %d: /* %s */\n", sp->index, sp->name); lineno++; } @@ -3847,18 +3862,23 @@ int mhflag; /* Output in makeheaders format if true */ } if( lemp->vardest ){ struct symbol *dflt_sp = 0; + int once = 1; for(i=0; insymbol; i++){ struct symbol *sp = lemp->symbols[i]; if( sp==0 || sp->type==TERMINAL || sp->index<=0 || sp->destructor!=0 ) continue; + if( once ){ + fprintf(out, " /* Default NON-TERMINAL Destructor */\n"); lineno++; + once = 0; + } fprintf(out," case %d: /* %s */\n", sp->index, sp->name); lineno++; dflt_sp = sp; } if( dflt_sp!=0 ){ emit_destructor_code(out,dflt_sp,lemp,&lineno); - fprintf(out," break;\n"); lineno++; } + fprintf(out," break;\n"); lineno++; } for(i=0; insymbol; i++){ struct symbol *sp = lemp->symbols[i]; @@ -4335,6 +4355,7 @@ char *x; sp->firstset = 0; sp->lambda = LEMON_FALSE; sp->destructor = 0; + sp->destLineno = 0; sp->datatype = 0; sp->useCnt = 0; Symbol_insert(sp,sp->name);