finished decl implementation

--HG--
branch : faluco
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/faluco%4016
This commit is contained in:
Borja Ferrer 2006-07-15 01:24:25 +00:00
parent cb1b5aee35
commit 2a032b6bf7

View File

@ -132,6 +132,7 @@ static void delwhile(void);
static int *readwhile(void); static int *readwhile(void);
static int norun = 0; /* the compiler never ran */ static int norun = 0; /* the compiler never ran */
static int autozero = 0; /* if 1 will zero out the variable, if 0 omit the zeroing */
static int lastst = 0; /* last executed statement type */ static int lastst = 0; /* last executed statement type */
static int nestlevel = 0; /* number of active (open) compound statements */ static int nestlevel = 0; /* number of active (open) compound statements */
static int rettype = 0; /* the type that a "return" expression should have */ static int rettype = 0; /* the type that a "return" expression should have */
@ -1958,11 +1959,15 @@ static int declloc(int fstatic)
int ctag = tag; /* set to "tag" by default */ int ctag = tag; /* set to "tag" by default */
int explicit_init=FALSE;/* is the variable explicitly initialized? */ int explicit_init=FALSE;/* is the variable explicitly initialized? */
if (matchtoken('=')) { if (matchtoken('=')) {
if (!autozero)
error(10);
doexpr(FALSE,FALSE,FALSE,FALSE,&ctag,NULL,TRUE); doexpr(FALSE,FALSE,FALSE,FALSE,&ctag,NULL,TRUE);
explicit_init=TRUE; explicit_init=TRUE;
} else { } else {
if (autozero)
ldconst(0,sPRI); /* uninitialized variable, set to zero */ ldconst(0,sPRI); /* uninitialized variable, set to zero */
} /* if */ } /* if */
if (autozero) {
/* now try to save the value (still in PRI) in the variable */ /* now try to save the value (still in PRI) in the variable */
lval.sym=sym; lval.sym=sym;
lval.ident=iVARIABLE; lval.ident=iVARIABLE;
@ -1971,6 +1976,7 @@ static int declloc(int fstatic)
check_userop(NULL,ctag,lval.tag,2,NULL,&ctag); check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
store(&lval); store(&lval);
markexpr(sEXPR,NULL,0); /* full expression ends after the store */ markexpr(sEXPR,NULL,0); /* full expression ends after the store */
}
assert(staging); /* end staging phase (optimize expression) */ assert(staging); /* end staging phase (optimize expression) */
stgout(staging_start); stgout(staging_start);
stgset(FALSE); stgset(FALSE);
@ -1985,6 +1991,7 @@ static int declloc(int fstatic)
assert(cur_lit>=0 && cur_lit<=litidx && litidx<=litmax); assert(cur_lit>=0 && cur_lit<=litidx && litidx<=litmax);
assert(size>0 && size>=sym->dim.array.length); assert(size>0 && size>=sym->dim.array.length);
assert(numdim>1 || size==sym->dim.array.length); assert(numdim>1 || size==sym->dim.array.length);
if (autozero) {
/* final literal values that are zero make no sense to put in the literal /* final literal values that are zero make no sense to put in the literal
* pool, because values get zero-initialized anyway; we check for this, * pool, because values get zero-initialized anyway; we check for this,
* because users often explicitly initialize strings to "" * because users often explicitly initialize strings to ""
@ -1994,6 +2001,7 @@ static int declloc(int fstatic)
/* if the array is not completely filled, set all values to zero first */ /* if the array is not completely filled, set all values to zero first */
if (litidx-cur_lit<size && (ucell)size<CELL_MAX) if (litidx-cur_lit<size && (ucell)size<CELL_MAX)
fillarray(sym,size*sizeof(cell),0); fillarray(sym,size*sizeof(cell),0);
}
if (cur_lit<litidx) { if (cur_lit<litidx) {
/* check whether the complete array is set to a single value; if /* check whether the complete array is set to a single value; if
* it is, more compact code can be generated */ * it is, more compact code can be generated */
@ -2245,12 +2253,12 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
constvalue *enumroot,int *errorfound) constvalue *enumroot,int *errorfound)
{ {
cell prev1=0,prev2=0; cell prev1=0,prev2=0;
int ellips=FALSE; int ellips=FALSE, hadtoken=0;
int curlit=litidx; int curlit=litidx;
int rtag,ctag; int rtag,ctag;
assert(ident==iARRAY || ident==iREFARRAY); assert(ident==iARRAY || ident==iREFARRAY);
if (matchtoken('{')) { if ((hadtoken=matchtoken('{')) && autozero) {
constvalue *enumfield=(enumroot!=NULL) ? enumroot->next : NULL; constvalue *enumfield=(enumroot!=NULL) ? enumroot->next : NULL;
do { do {
int fieldlit=litidx; int fieldlit=litidx;
@ -2312,6 +2320,8 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
} while (matchtoken(',')); /* do */ } while (matchtoken(',')); /* do */
needtoken('}'); needtoken('}');
} else { } else {
if (hadtoken && !autozero)
error(10);
init(ident,&ctag,errorfound); init(ident,&ctag,errorfound);
if (!matchtag(tag,ctag,TRUE)) if (!matchtag(tag,ctag,TRUE))
error(213); /* tagname mismatch */ error(213); /* tagname mismatch */
@ -4585,6 +4595,7 @@ static void statement(int *lastindent,int allow_decl)
break; break;
case tNEW: case tNEW:
if (allow_decl) { if (allow_decl) {
autozero=1;
declloc(FALSE); declloc(FALSE);
lastst=tNEW; lastst=tNEW;
} else { } else {
@ -4593,6 +4604,7 @@ static void statement(int *lastindent,int allow_decl)
break; break;
case tDECL: case tDECL:
if (allow_decl) { if (allow_decl) {
autozero=0;
declloc(FALSE); declloc(FALSE);
lastst=tDECL; lastst=tDECL;
} else { } else {
@ -4974,6 +4986,7 @@ static void dofor(void)
* 'compound statement' level of it own. * 'compound statement' level of it own.
*/ */
nestlevel++; nestlevel++;
autozero=1;
declloc(FALSE); /* declare local variable */ declloc(FALSE); /* declare local variable */
} else { } else {
doexpr(TRUE,TRUE,TRUE,TRUE,NULL,NULL,FALSE); /* expression 1 */ doexpr(TRUE,TRUE,TRUE,TRUE,NULL,NULL,FALSE); /* expression 1 */