]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix some issues with lemon. Tickets #2852 and #2835. (CVS 4641)
authordrh <drh@noemail.net>
Fri, 21 Dec 2007 00:02:11 +0000 (00:02 +0000)
committerdrh <drh@noemail.net>
Fri, 21 Dec 2007 00:02:11 +0000 (00:02 +0000)
FossilOrigin-Name: 5283e0d1467e0fc0ebbd1be553b5a8762e9c7975

manifest
manifest.uuid
tool/lemon.c

index 4fe77a7d1bdc57a241b9a41a1660723147bfb969..620d0a9fc5767f96622d4316a95a15b321b3e15e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\sioerr3.test\sfile,\sthat\sfound\san\serror\sin\sbr3317.\sThe\serror\sis\snot\spresent\sin\sthis\sbranch.\s(CVS\s4640)
-D 2007-12-19T09:20:42
+C Fix\ssome\sissues\swith\slemon.\s\sTickets\s#2852\sand\s#2835.\s(CVS\s4641)
+D 2007-12-21T00:02:11
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -524,7 +524,7 @@ F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
 F test/zeroblob.test 7d1854ea79d048e023e5f2e38106a7e99a17435c
 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439
-F tool/lemon.c 5b243377708d5fadb7ed4795ad6b2e9c379e1f0f
+F tool/lemon.c 1c5a788bdeccfcc61f2e11665e77cc74fd5ca92f
 F tool/lempar.c 8f998bf8d08e2123149c2cc5d0597cd5d5d1abdd
 F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
 F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
@@ -601,7 +601,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P cdd866f59797b81b573c68d5c625f9bd9f0f6fde
-R ff63d5a53b9b64a61cb53c7cb7cd3109
-U danielk1977
-Z 8a273e2b803f60fa9acf4e5a0f85217b
+P d3efec148968538e225f5716359a6a25e8941362
+R 85004d42a22e2eebf7a2858fba477cd5
+U drh
+Z ad03768828df010e4ad9480b93fc71b4
index b7cdcfc2c46c9f4487e587d65a7c06e9e210a2c6..953858c166468b035ec5d17188e784bc4e0f9a79 100644 (file)
@@ -1 +1 @@
-d3efec148968538e225f5716359a6a25e8941362
\ No newline at end of file
+5283e0d1467e0fc0ebbd1be553b5a8762e9c7975
\ No newline at end of file
index 3bea77a9f26de4a66b055348200289e9d00d140d..64b7a28262a9e1be7459f16abb4d001e66706582 100644 (file)
@@ -191,7 +191,9 @@ struct action {
     ACCEPT,
     REDUCE,
     ERROR,
-    CONFLICT,                /* Was a reduce, but part of a conflict */
+    SSCONFLICT,              /* A shift/shift conflict */
+    SRCONFLICT,              /* Was a reduce, but part of a conflict */
+    RRCONFLICT,              /* Was a reduce, but part of a conflict */
     SH_RESOLVED,             /* Was a shift.  Precedence resolved conflict */
     RD_RESOLVED,             /* Was reduce.  Precedence resolved conflict */
     NOT_USED                 /* Deleted by compression */
@@ -337,7 +339,7 @@ static struct action *Action_new(void){
   if( freelist==0 ){
     int i;
     int amt = 100;
-    freelist = (struct action *)malloc( sizeof(struct action)*amt );
+    freelist = (struct action *)calloc(amt, sizeof(struct action));
     if( freelist==0 ){
       fprintf(stderr,"Unable to allocate memory for a new parser action.");
       exit(1);
@@ -360,8 +362,10 @@ static int actioncmp(
 ){
   int rc;
   rc = ap1->sp->index - ap2->sp->index;
-  if( rc==0 ) rc = (int)ap1->type - (int)ap2->type;
   if( rc==0 ){
+    rc = (int)ap1->type - (int)ap2->type;
+  }
+  if( rc==0 && ap1->type==REDUCE ){
     rc = ap1->x.rp->index - ap2->x.rp->index;
   }
   return rc;
@@ -437,7 +441,7 @@ void acttab_free(acttab *p){
 
 /* Allocate a new acttab structure */
 acttab *acttab_alloc(void){
-  acttab *p = malloc( sizeof(*p) );
+  acttab *p = calloc( 1, sizeof(*p) );
   if( p==0 ){
     fprintf(stderr,"Unable to allocate memory for a new acttab.");
     exit(1);
@@ -1010,7 +1014,7 @@ struct symbol *errsym;   /* The error symbol (if defined.  NULL otherwise) */
   int errcnt = 0;
   assert( apx->sp==apy->sp );  /* Otherwise there would be no conflict */
   if( apx->type==SHIFT && apy->type==SHIFT ){
-    apy->type = CONFLICT;
+    apy->type = SSCONFLICT;
     errcnt++;
   }
   if( apx->type==SHIFT && apy->type==REDUCE ){
@@ -1018,7 +1022,7 @@ struct symbol *errsym;   /* The error symbol (if defined.  NULL otherwise) */
     spy = apy->x.rp->precsym;
     if( spy==0 || spx->prec<0 || spy->prec<0 ){
       /* Not enough precedence information. */
-      apy->type = CONFLICT;
+      apy->type = SRCONFLICT;
       errcnt++;
     }else if( spx->prec>spy->prec ){    /* Lower precedence wins */
       apy->type = RD_RESOLVED;
@@ -1030,7 +1034,7 @@ struct symbol *errsym;   /* The error symbol (if defined.  NULL otherwise) */
       apx->type = SH_RESOLVED;
     }else{
       assert( spx->prec==spy->prec && spx->assoc==NONE );
-      apy->type = CONFLICT;
+      apy->type = SRCONFLICT;
       errcnt++;
     }
   }else if( apx->type==REDUCE && apy->type==REDUCE ){
@@ -1038,7 +1042,7 @@ struct symbol *errsym;   /* The error symbol (if defined.  NULL otherwise) */
     spy = apy->x.rp->precsym;
     if( spx==0 || spy==0 || spx->prec<0 ||
     spy->prec<0 || spx->prec==spy->prec ){
-      apy->type = CONFLICT;
+      apy->type = RRCONFLICT;
       errcnt++;
     }else if( spx->prec>spy->prec ){
       apy->type = RD_RESOLVED;
@@ -1049,10 +1053,14 @@ struct symbol *errsym;   /* The error symbol (if defined.  NULL otherwise) */
     assert( 
       apx->type==SH_RESOLVED ||
       apx->type==RD_RESOLVED ||
-      apx->type==CONFLICT ||
+      apx->type==SSCONFLICT ||
+      apx->type==SRCONFLICT ||
+      apx->type==RRCONFLICT ||
       apy->type==SH_RESOLVED ||
       apy->type==RD_RESOLVED ||
-      apy->type==CONFLICT
+      apy->type==SSCONFLICT ||
+      apy->type==SRCONFLICT ||
+      apy->type==RRCONFLICT
     );
     /* The REDUCE/SHIFT case cannot happen because SHIFTs come before
     ** REDUCEs on the list.  If we reach this point it must be because
@@ -1078,7 +1086,7 @@ PRIVATE struct config *newconfig(){
   if( freelist==0 ){
     int i;
     int amt = 3;
-    freelist = (struct config *)malloc( sizeof(struct config)*amt );
+    freelist = (struct config *)calloc( amt, sizeof(struct config) );
     if( freelist==0 ){
       fprintf(stderr,"Unable to allocate memory for a new configuration.");
       exit(1);
@@ -1454,7 +1462,7 @@ char **argv;
     Reprint(&lem);
   }else{
     /* Initialize the size for all follow and first sets */
-    SetSize(lem.nterminal);
+    SetSize(lem.nterminal+1);
 
     /* Find the precedence for every production rule (that has one) */
     FindRulePrecedences(&lem);
@@ -2091,8 +2099,8 @@ to follow the previous rule.");
     case IN_RHS:
       if( x[0]=='.' ){
         struct rule *rp;
-        rp = (struct rule *)malloc( sizeof(struct rule) + 
-             sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs );
+        rp = (struct rule *)calloc( sizeof(struct rule) + 
+             sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs, 1);
         if( rp==0 ){
           ErrorMsg(psp->filename,psp->tokenlineno,
             "Can't allocate enough memory for this rule.");
@@ -2141,11 +2149,11 @@ to follow the previous rule.");
         struct symbol *msp = psp->rhs[psp->nrhs-1];
         if( msp->type!=MULTITERMINAL ){
           struct symbol *origsp = msp;
-          msp = malloc(sizeof(*msp));
+          msp = calloc(1,sizeof(*msp));
           memset(msp, 0, sizeof(*msp));
           msp->type = MULTITERMINAL;
           msp->nsubsym = 1;
-          msp->subsym = malloc(sizeof(struct symbol*));
+          msp->subsym = calloc(1,sizeof(struct symbol*));
           msp->subsym[0] = origsp;
           msp->name = origsp->name;
           psp->rhs[psp->nrhs-1] = msp;
@@ -2598,7 +2606,7 @@ struct plink *Plink_new(){
   if( plink_freelist==0 ){
     int i;
     int amt = 100;
-    plink_freelist = (struct plink *)malloc( sizeof(struct plink)*amt );
+    plink_freelist = (struct plink *)calloc( amt, sizeof(struct plink) );
     if( plink_freelist==0 ){
       fprintf(stderr,
       "Unable to allocate memory for a new follow-set propagation link.\n");
@@ -2824,10 +2832,15 @@ int PrintAction(struct action *ap, FILE *fp, int indent){
     case ERROR:
       fprintf(fp,"%*s error",indent,ap->sp->name);
       break;
-    case CONFLICT:
+    case SRCONFLICT:
+    case RRCONFLICT:
       fprintf(fp,"%*s reduce %-3d ** Parsing conflict **",
         indent,ap->sp->name,ap->x.rp->index);
       break;
+    case SSCONFLICT:
+      fprintf(fp,"%*s shift  %d ** Parsing conflict **", 
+        indent,ap->sp->name,ap->x.stp->statenum);
+      break;
     case SH_RESOLVED:
     case RD_RESOLVED:
     case NOT_USED:
@@ -3336,7 +3349,7 @@ int mhflag;                 /* True if generating makeheaders output */
 
   /* Allocate and initialize types[] and allocate stddt[] */
   arraysize = lemp->nsymbol * 2;
-  types = (char**)malloc( arraysize * sizeof(char*) );
+  types = (char**)calloc( arraysize, sizeof(char*) );
   for(i=0; i<arraysize; i++) types[i] = 0;
   maxdtlength = 0;
   if( lemp->vartype ){
@@ -3582,7 +3595,7 @@ int mhflag;     /* Output in makeheaders format if true */
   */
 
   /* Compute the actions on all states and count them up */
-  ax = malloc( sizeof(ax[0])*lemp->nstate*2 );
+  ax = calloc(lemp->nstate*2, sizeof(ax[0]));
   if( ax==0 ){
     fprintf(stderr,"malloc failed\n");
     exit(1);
@@ -4054,12 +4067,11 @@ int n;
 char *SetNew(){
   char *s;
   int i;
-  s = (char*)malloc( size );
+  s = (char*)calloc( size, 1);
   if( s==0 ){
     extern void memory_error();
     memory_error();
   }
-  for(i=0; i<size; i++) s[i] = 0;
   return s;
 }
 
@@ -4077,6 +4089,7 @@ char *s;
 int e;
 {
   int rv;
+  assert( e>=0 && e<size );
   rv = s[e];
   s[e] = 1;
   return !rv;
@@ -4266,7 +4279,7 @@ char *x;
 
   sp = Symbol_find(x);
   if( sp==0 ){
-    sp = (struct symbol *)malloc( sizeof(struct symbol) );
+    sp = (struct symbol *)calloc(1, sizeof(struct symbol) );
     MemoryCheck(sp);
     sp->name = Strsafe(x);
     sp->type = isupper(*x) ? TERMINAL : NONTERMINAL;
@@ -4449,7 +4462,7 @@ struct symbol **Symbol_arrayof()
   int i,size;
   if( x2a==0 ) return 0;
   size = x2a->count;
-  array = (struct symbol **)malloc( sizeof(struct symbol *)*size );
+  array = (struct symbol **)calloc(size, sizeof(struct symbol *));
   if( array ){
     for(i=0; i<size; i++) array[i] = x2a->tbl[i].data;
   }
@@ -4500,7 +4513,7 @@ struct config *a;
 struct state *State_new()
 {
   struct state *new;
-  new = (struct state *)malloc( sizeof(struct state) );
+  new = (struct state *)calloc(1, sizeof(struct state) );
   MemoryCheck(new);
   return new;
 }