Incremental ... initialization of 2d arrays
This is fully supported now: new arr[3][3] = {{0, 1, ...}, {0, 2, ...}, ...}; will produce: {{0, 1, 2}, {0, 2, 4}, {0, 3, 6}} and this: new arr[3][3] = {{0, 1, ...}, ...}; will yield: {{0, 1, 2}, {0, 1, 2}, {0, 1, 2}} Refs #48
This commit is contained in:
parent
e1082f64bc
commit
35190f55fb
@ -2460,18 +2460,14 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
|
|||||||
int startlit,int counteddim[],constvalue *lastdim,
|
int startlit,int counteddim[],constvalue *lastdim,
|
||||||
constvalue *enumroot,int *errorfound)
|
constvalue *enumroot,int *errorfound)
|
||||||
{
|
{
|
||||||
cell dsize,totalsize;
|
cell dsize,totalsize=0;
|
||||||
int idx,numvectors,abortparse,ellips;
|
int idx=0,vec_idx,abortparse=FALSE;
|
||||||
const char *initptr,*prev_initptr;
|
cell *prev1=NULL,*prev2=NULL;
|
||||||
|
|
||||||
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;
|
|
||||||
abortparse=FALSE;
|
|
||||||
needtoken('{');
|
needtoken('{');
|
||||||
do {
|
do {
|
||||||
int ellips=FALSE;
|
int ellips=FALSE;
|
||||||
@ -2493,28 +2489,29 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
|
|||||||
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 {
|
||||||
initptr=lptr;
|
if (matchtoken(tELLIPS)!=0) {
|
||||||
numvectors=idx+1;
|
if (prev1!=NULL)
|
||||||
if ((ellips=matchtoken(tELLIPS))!=0)
|
while (idx < dim[cur]) {
|
||||||
numvectors=dim[cur];
|
for (vec_idx=0; vec_idx < dsize; vec_idx++) {
|
||||||
dsize=0;
|
if (prev2!=NULL)
|
||||||
while (idx<numvectors) {
|
litadd(prev1[vec_idx]+(prev1[vec_idx]-prev2[vec_idx]));
|
||||||
if (ellips && prev_initptr!=NULL)
|
else
|
||||||
lptr=prev_initptr; /* go back to array initializer */
|
litadd(prev1[vec_idx]);
|
||||||
dsize+=initvector(ident,tag,dim[cur+1],TRUE,enumroot,errorfound);
|
} /* for */
|
||||||
if (*errorfound)
|
append_constval(lastdim,itoh(idx++),dsize,0);
|
||||||
break;
|
} /* while */
|
||||||
|
else
|
||||||
|
error(41); /* invalid ellipsis, array size unknown */
|
||||||
|
} else {
|
||||||
|
prev2=prev1;
|
||||||
|
prev1=&litq[litidx];
|
||||||
|
dsize=initvector(ident,tag,dim[cur+1],TRUE,enumroot,errorfound);
|
||||||
/* The final dimension may be variable length. We need to save the
|
/* The final dimension may be variable length. We need to save the
|
||||||
* lengths of the final dimensions in order to set the indirection
|
* lengths of the final dimensions in order to set the indirection
|
||||||
* vectors for the next-to-last dimension.
|
* vectors for the next-to-last dimension.
|
||||||
*/
|
*/
|
||||||
append_constval(lastdim,itoh(idx++),dsize,0);
|
append_constval(lastdim,itoh(idx++),dsize,0);
|
||||||
} /* for */
|
|
||||||
if (ellips) {
|
|
||||||
needtoken(',');
|
|
||||||
needtoken(tELLIPS);
|
|
||||||
} /* if */
|
} /* if */
|
||||||
prev_initptr=initptr;
|
|
||||||
} /* if */
|
} /* if */
|
||||||
totalsize+=dsize;
|
totalsize+=dsize;
|
||||||
if (*errorfound || !matchtoken(','))
|
if (*errorfound || !matchtoken(','))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user