parent
eeefc4ba3b
commit
e1082f64bc
@ -2461,15 +2461,20 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
|
|||||||
constvalue *enumroot,int *errorfound)
|
constvalue *enumroot,int *errorfound)
|
||||||
{
|
{
|
||||||
cell dsize,totalsize;
|
cell dsize,totalsize;
|
||||||
int idx,abortparse;
|
int idx,numvectors,abortparse,ellips;
|
||||||
|
const char *initptr,*prev_initptr;
|
||||||
|
|
||||||
assert(cur>=0 && cur<numdim);
|
assert(cur>=0 && cur<numdim);
|
||||||
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);
|
||||||
|
idx=0;
|
||||||
|
prev_initptr=NULL;
|
||||||
totalsize=0;
|
totalsize=0;
|
||||||
|
abortparse=FALSE;
|
||||||
needtoken('{');
|
needtoken('{');
|
||||||
for (idx=0,abortparse=FALSE; !abortparse; idx++) {
|
do {
|
||||||
|
int ellips=FALSE;
|
||||||
/* 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.
|
||||||
@ -2481,24 +2486,40 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
|
|||||||
if (dim[cur]==0) {
|
if (dim[cur]==0) {
|
||||||
litinsert(0,startlit);
|
litinsert(0,startlit);
|
||||||
} else if (idx>=dim[cur]) {
|
} else if (idx>=dim[cur]) {
|
||||||
error(18); /* initialization data exceeds array size */
|
error(18); /* initialization data exceeds array size */
|
||||||
break;
|
break;
|
||||||
} /* if */
|
} /* if */
|
||||||
if (cur+2<numdim) {
|
if (cur<numdim-2) {
|
||||||
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);
|
||||||
} else {
|
} else {
|
||||||
dsize=initvector(ident,tag,dim[cur+1],TRUE,enumroot,errorfound);
|
initptr=lptr;
|
||||||
/* The final dimension may be variable length. We need to save the
|
numvectors=idx+1;
|
||||||
* lengths of the final dimensions in order to set the indirection
|
if ((ellips=matchtoken(tELLIPS))!=0)
|
||||||
* vectors for the next-to-last dimension.
|
numvectors=dim[cur];
|
||||||
*/
|
dsize=0;
|
||||||
append_constval(lastdim,itoh(idx),dsize,0);
|
while (idx<numvectors) {
|
||||||
|
if (ellips && prev_initptr!=NULL)
|
||||||
|
lptr=prev_initptr; /* go back to array initializer */
|
||||||
|
dsize+=initvector(ident,tag,dim[cur+1],TRUE,enumroot,errorfound);
|
||||||
|
if (*errorfound)
|
||||||
|
break;
|
||||||
|
/* The final dimension may be variable length. We need to save the
|
||||||
|
* lengths of the final dimensions in order to set the indirection
|
||||||
|
* vectors for the next-to-last dimension.
|
||||||
|
*/
|
||||||
|
append_constval(lastdim,itoh(idx++),dsize,0);
|
||||||
|
} /* for */
|
||||||
|
if (ellips) {
|
||||||
|
needtoken(',');
|
||||||
|
needtoken(tELLIPS);
|
||||||
|
} /* if */
|
||||||
|
prev_initptr=initptr;
|
||||||
} /* if */
|
} /* if */
|
||||||
totalsize+=dsize;
|
totalsize+=dsize;
|
||||||
if (*errorfound || !matchtoken(','))
|
if (*errorfound || !matchtoken(','))
|
||||||
abortparse=TRUE;
|
abortparse=TRUE;
|
||||||
} /* for */
|
} while (!abortparse);
|
||||||
needtoken('}');
|
needtoken('}');
|
||||||
assert(counteddim!=NULL);
|
assert(counteddim!=NULL);
|
||||||
if (counteddim[cur]>0) {
|
if (counteddim[cur]>0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user