Fuck trailing comma
This commit is contained in:
parent
dbe21979e4
commit
cb0bd85053
@ -2441,7 +2441,7 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim,
|
|||||||
break;
|
break;
|
||||||
ld=ld->next;
|
ld=ld->next;
|
||||||
} /* for */
|
} /* for */
|
||||||
if (d==dim[numdim-2] && d!=0)
|
if (d==dim[numdim-2])
|
||||||
dim[numdim-1]=match;
|
dim[numdim-1]=match;
|
||||||
} /* if */
|
} /* if */
|
||||||
/* after all arrays have been initalized, we know the (major) dimensions
|
/* 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(startlit>=0);
|
||||||
assert(cur+2<=numdim);/* there must be 2 dimensions or more to do */
|
assert(cur+2<=numdim);/* there must be 2 dimensions or more to do */
|
||||||
assert(errorfound!=NULL && *errorfound==FALSE);
|
assert(errorfound!=NULL && *errorfound==FALSE);
|
||||||
/* check for a quick exit */
|
|
||||||
if (matchtoken('}')) {
|
|
||||||
lexpush();
|
|
||||||
return 0;
|
|
||||||
} /* if */
|
|
||||||
totalsize=0;
|
totalsize=0;
|
||||||
needtoken('{');
|
needtoken('{');
|
||||||
for (idx=0,abortparse=FALSE; !abortparse; idx++) {
|
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
|
/* 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.
|
* to the newly detected sub-array into the indirection table; i.e.
|
||||||
* this table needs to be expanded and updated.
|
* 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
|
* necessary at this point to reserve space for an extra cell in the
|
||||||
* indirection vector.
|
* indirection vector.
|
||||||
*/
|
*/
|
||||||
if (dim[cur]==0)
|
if (dim[cur]==0) {
|
||||||
litinsert(0,startlit);
|
litinsert(0,startlit);
|
||||||
|
} else if (idx>=dim[cur]) {
|
||||||
|
error(18); /* initialization data exceeds array size */
|
||||||
|
break;
|
||||||
|
} /* if */
|
||||||
if (cur+2<numdim) {
|
if (cur+2<numdim) {
|
||||||
dsize=initarray(ident,tag,dim,numdim,cur+1,startlit,counteddim,
|
dsize=initarray(ident,tag,dim,numdim,cur+1,startlit,counteddim,
|
||||||
lastdim,enumroot,errorfound);
|
lastdim,enumroot,errorfound);
|
||||||
@ -2502,11 +2496,6 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
|
|||||||
*/
|
*/
|
||||||
append_constval(lastdim,itoh(idx),dsize,0);
|
append_constval(lastdim,itoh(idx),dsize,0);
|
||||||
} /* if */
|
} /* if */
|
||||||
if (dim[cur]!=0 && idx>=dim[cur]) {
|
|
||||||
assert(dsize>0 || *errorfound);
|
|
||||||
error(18); /* initialization data exceeds array size */
|
|
||||||
break; /* avoid incrementing "idx" */
|
|
||||||
} /* if */
|
|
||||||
totalsize+=dsize;
|
totalsize+=dsize;
|
||||||
if (*errorfound || !matchtoken(','))
|
if (*errorfound || !matchtoken(','))
|
||||||
abortparse=TRUE;
|
abortparse=TRUE;
|
||||||
@ -2571,7 +2560,7 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
|
|||||||
error(227); /* more initiallers than enum fields */
|
error(227); /* more initiallers than enum fields */
|
||||||
rtag=tag; /* preset, may be overridden by enum field tag */
|
rtag=tag; /* preset, may be overridden by enum field tag */
|
||||||
if (enumfield!=NULL) {
|
if (enumfield!=NULL) {
|
||||||
cell step, val;
|
cell step;
|
||||||
int cmptag=enumfield->index;
|
int cmptag=enumfield->index;
|
||||||
symbol *symfield=findconst(enumfield->name,&cmptag);
|
symbol *symfield=findconst(enumfield->name,&cmptag);
|
||||||
if (cmptag>1)
|
if (cmptag>1)
|
||||||
@ -2581,15 +2570,14 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
|
|||||||
if (litidx-fieldlit>symfield->dim.array.length)
|
if (litidx-fieldlit>symfield->dim.array.length)
|
||||||
error(228); /* length of initialler exceeds size of the enum field */
|
error(228); /* length of initialler exceeds size of the enum field */
|
||||||
if (ellips) {
|
if (ellips) {
|
||||||
val=prev1;
|
|
||||||
step=prev1-prev2;
|
step=prev1-prev2;
|
||||||
} else {
|
} else {
|
||||||
step=0;
|
step=0;
|
||||||
val=0; /* fill up with zeros */
|
prev1=0;
|
||||||
} /* if */
|
} /* if */
|
||||||
for (i=litidx-fieldlit; i<symfield->dim.array.length; i++) {
|
for (i=litidx-fieldlit; i<symfield->dim.array.length; i++) {
|
||||||
val+=step;
|
prev1+=step;
|
||||||
litadd(val);
|
litadd(prev1);
|
||||||
} /* for */
|
} /* for */
|
||||||
rtag=symfield->x.tags.index; /* set the expected tag to the index tag */
|
rtag=symfield->x.tags.index; /* set the expected tag to the index tag */
|
||||||
enumfield=enumfield->next;
|
enumfield=enumfield->next;
|
||||||
@ -2598,13 +2586,6 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
|
|||||||
error(213); /* tag mismatch */
|
error(213); /* tag mismatch */
|
||||||
} while (matchtoken(',')); /* do */
|
} while (matchtoken(',')); /* do */
|
||||||
needtoken('}');
|
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 {
|
} else {
|
||||||
init(ident,&ctag,errorfound);
|
init(ident,&ctag,errorfound);
|
||||||
if (!matchtag(tag,ctag,TRUE))
|
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)
|
static cell init(int ident,int *tag,int *errorfound)
|
||||||
{
|
{
|
||||||
int curlit=litidx;
|
|
||||||
cell i = 0;
|
cell i = 0;
|
||||||
|
|
||||||
if (matchtoken(tSTRING)){
|
if (matchtoken(tSTRING)){
|
||||||
@ -2650,7 +2630,7 @@ static cell init(int ident,int *tag,int *errorfound)
|
|||||||
*/
|
*/
|
||||||
if (ident==iVARIABLE) {
|
if (ident==iVARIABLE) {
|
||||||
error(6); /* must be assigned to an array */
|
error(6); /* must be assigned to an array */
|
||||||
litidx=curlit+1; /* reset literal queue */
|
litidx=1; /* reset literal queue */
|
||||||
} /* if */
|
} /* if */
|
||||||
*tag=0;
|
*tag=0;
|
||||||
} else if (constexpr(&i,tag,NULL)){
|
} else if (constexpr(&i,tag,NULL)){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user