From cb0bd850533d9ff841c2002ffe35ec1be83e5f37 Mon Sep 17 00:00:00 2001 From: Zeex Date: Wed, 23 Apr 2014 02:05:20 +0700 Subject: [PATCH] Fuck trailing comma --- source/compiler/sc1.c | 44 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 9f59804..056628e 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2441,7 +2441,7 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim, break; ld=ld->next; } /* for */ - if (d==dim[numdim-2] && d!=0) + if (d==dim[numdim-2]) dim[numdim-1]=match; } /* if */ /* after all arrays have been initalized, we know the (major) dimensions @@ -2468,19 +2468,9 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur, assert(startlit>=0); assert(cur+2<=numdim);/* there must be 2 dimensions or more to do */ assert(errorfound!=NULL && *errorfound==FALSE); - /* check for a quick exit */ - if (matchtoken('}')) { - lexpush(); - return 0; - } /* if */ totalsize=0; needtoken('{'); for (idx=0,abortparse=FALSE; !abortparse; idx++) { - /* check if there was a trailing comma */ - if (matchtoken('}')) { - lexpush(); - break; - } /* In case the major dimension is zero, we need to store the offset * to the newly detected sub-array into the indirection table; i.e. * this table needs to be expanded and updated. @@ -2489,8 +2479,12 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur, * necessary at this point to reserve space for an extra cell in the * indirection vector. */ - if (dim[cur]==0) + if (dim[cur]==0) { litinsert(0,startlit); + } else if (idx>=dim[cur]) { + error(18); /* initialization data exceeds array size */ + break; + } /* if */ if (cur+2=dim[cur]) { - assert(dsize>0 || *errorfound); - error(18); /* initialization data exceeds array size */ - break; /* avoid incrementing "idx" */ - } /* if */ totalsize+=dsize; if (*errorfound || !matchtoken(',')) abortparse=TRUE; @@ -2571,7 +2560,7 @@ static cell initvector(int ident,int tag,cell size,int fillzero, error(227); /* more initiallers than enum fields */ rtag=tag; /* preset, may be overridden by enum field tag */ if (enumfield!=NULL) { - cell step, val; + cell step; int cmptag=enumfield->index; symbol *symfield=findconst(enumfield->name,&cmptag); if (cmptag>1) @@ -2581,30 +2570,22 @@ static cell initvector(int ident,int tag,cell size,int fillzero, if (litidx-fieldlit>symfield->dim.array.length) error(228); /* length of initialler exceeds size of the enum field */ if (ellips) { - val=prev1; step=prev1-prev2; } else { step=0; - val=0; /* fill up with zeros */ + prev1=0; } /* if */ for (i=litidx-fieldlit; idim.array.length; i++) { - val+=step; - litadd(val); + prev1+=step; + litadd(prev1); } /* for */ rtag=symfield->x.tags.index; /* set the expected tag to the index tag */ enumfield=enumfield->next; } /* if */ if (!matchtag(rtag,ctag,TRUE)) - error(213); /* tag mismatch */ + error(213); /* tag mismatch */ } while (matchtoken(',')); /* do */ needtoken('}'); - } else if (matchtoken('}')) { - /* this may be caused by a trailing comma in a declaration of a - * multi-dimensional array - */ - lexpush(); /* push back for later analysis */ - size=0; /* avoid zero filling */ - assert(!ellips); } else { init(ident,&ctag,errorfound); if (!matchtag(tag,ctag,TRUE)) @@ -2641,7 +2622,6 @@ static cell initvector(int ident,int tag,cell size,int fillzero, */ static cell init(int ident,int *tag,int *errorfound) { - int curlit=litidx; cell i = 0; if (matchtoken(tSTRING)){ @@ -2650,7 +2630,7 @@ static cell init(int ident,int *tag,int *errorfound) */ if (ident==iVARIABLE) { error(6); /* must be assigned to an array */ - litidx=curlit+1; /* reset literal queue */ + litidx=1; /* reset literal queue */ } /* if */ *tag=0; } else if (constexpr(&i,tag,NULL)){