merged in faluco's decl changes !1

--HG--
branch : dvander
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/dvander%4021
This commit is contained in:
David Anderson 2006-07-15 03:19:23 +00:00
commit 83331994ed
3 changed files with 79 additions and 57 deletions

View File

@ -283,7 +283,7 @@ typedef struct s_stringpair {
*/
#define tFIRST 256 /* value of first multi-character operator */
#define tMIDDLE 280 /* value of last multi-character operator */
#define tLAST 325 /* value of last multi-character match-able token */
#define tLAST 326 /* value of last multi-character match-able token */
/* multi-character operators */
#define taMULT 256 /* *= */
#define taDIV 257 /* /= */
@ -329,44 +329,45 @@ typedef struct s_stringpair {
#define tIF 296
#define tNATIVE 297
#define tNEW 298
#define tOPERATOR 299
#define tPUBLIC 300
#define tRETURN 301
#define tSIZEOF 302
#define tSLEEP 303
#define tSTATE 304
#define tSTATIC 305
#define tSTOCK 306
#define tSWITCH 307
#define tTAGOF 308
#define tWHILE 309
#define tDECL 299
#define tOPERATOR 300
#define tPUBLIC 301
#define tRETURN 302
#define tSIZEOF 303
#define tSLEEP 304
#define tSTATE 305
#define tSTATIC 306
#define tSTOCK 307
#define tSWITCH 308
#define tTAGOF 309
#define tWHILE 310
/* compiler directives */
#define tpASSERT 310 /* #assert */
#define tpDEFINE 311
#define tpELSE 312 /* #else */
#define tpELSEIF 313 /* #elseif */
#define tpEMIT 314
#define tpENDIF 315
#define tpENDINPUT 316
#define tpENDSCRPT 317
#define tpERROR 318
#define tpFILE 319
#define tpIF 320 /* #if */
#define tINCLUDE 321
#define tpLINE 322
#define tpPRAGMA 323
#define tpTRYINCLUDE 324
#define tpUNDEF 325
#define tpASSERT 311 /* #assert */
#define tpDEFINE 312
#define tpELSE 313 /* #else */
#define tpELSEIF 314 /* #elseif */
#define tpEMIT 315
#define tpENDIF 316
#define tpENDINPUT 317
#define tpENDSCRPT 318
#define tpERROR 319
#define tpFILE 320
#define tpIF 321 /* #if */
#define tINCLUDE 322
#define tpLINE 323
#define tpPRAGMA 324
#define tpTRYINCLUDE 325
#define tpUNDEF 326
/* semicolon is a special case, because it can be optional */
#define tTERM 326 /* semicolon or newline */
#define tENDEXPR 327 /* forced end of expression */
#define tTERM 327 /* semicolon or newline */
#define tENDEXPR 328 /* forced end of expression */
/* other recognized tokens */
#define tNUMBER 328 /* integer number */
#define tRATIONAL 329 /* rational number */
#define tSYMBOL 330
#define tLABEL 331
#define tSTRING 332
#define tEXPR 333 /* for assigment to "lastst" only */
#define tNUMBER 329 /* integer number */
#define tRATIONAL 330 /* rational number */
#define tSYMBOL 331
#define tLABEL 332
#define tSTRING 333
#define tEXPR 334 /* for assigment to "lastst" only */
/* (reversed) evaluation of staging buffer */
#define sSTARTREORDER 0x01

View File

@ -135,6 +135,7 @@ static int *readwhile(void);
static void inst_datetime_defines(void);
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 nestlevel = 0; /* number of active (open) compound statements */
static int rettype = 0; /* the type that a "return" expression should have */
@ -1977,19 +1978,24 @@ static int declloc(int fstatic)
int ctag = tag; /* set to "tag" by default */
int explicit_init=FALSE;/* is the variable explicitly initialized? */
if (matchtoken('=')) {
if (!autozero)
error(10);
doexpr(FALSE,FALSE,FALSE,FALSE,&ctag,NULL,TRUE);
explicit_init=TRUE;
} else {
ldconst(0,sPRI); /* uninitialized variable, set to zero */
if (autozero)
ldconst(0,sPRI); /* uninitialized variable, set to zero */
} /* if */
/* now try to save the value (still in PRI) in the variable */
lval.sym=sym;
lval.ident=iVARIABLE;
lval.constval=0;
lval.tag=tag;
check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
store(&lval);
markexpr(sEXPR,NULL,0); /* full expression ends after the store */
if (autozero) {
/* now try to save the value (still in PRI) in the variable */
lval.sym=sym;
lval.ident=iVARIABLE;
lval.constval=0;
lval.tag=tag;
check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
store(&lval);
markexpr(sEXPR,NULL,0); /* full expression ends after the store */
}
assert(staging); /* end staging phase (optimize expression) */
stgout(staging_start);
stgset(FALSE);
@ -2004,15 +2010,17 @@ static int declloc(int fstatic)
assert(cur_lit>=0 && cur_lit<=litidx && litidx<=litmax);
assert(size>0 && size>=sym->dim.array.length);
assert(numdim>1 || size==sym->dim.array.length);
/* 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,
* because users often explicitly initialize strings to ""
*/
while (litidx>cur_lit && litq[litidx-1]==0)
litidx--;
/* if the array is not completely filled, set all values to zero first */
if (litidx-cur_lit<size && (ucell)size<CELL_MAX)
fillarray(sym,size*sizeof(cell),0);
if (autozero) {
/* 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,
* because users often explicitly initialize strings to ""
*/
while (litidx>cur_lit && litq[litidx-1]==0)
litidx--;
/* if the array is not completely filled, set all values to zero first */
if (litidx-cur_lit<size && (ucell)size<CELL_MAX)
fillarray(sym,size*sizeof(cell),0);
}
if (cur_lit<litidx) {
/* check whether the complete array is set to a single value; if
* it is, more compact code can be generated */
@ -2264,12 +2272,12 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
constvalue *enumroot,int *errorfound)
{
cell prev1=0,prev2=0;
int ellips=FALSE;
int ellips=FALSE,hadtoken=0;
int curlit=litidx;
int rtag,ctag;
assert(ident==iARRAY || ident==iREFARRAY);
if (matchtoken('{')) {
if ((hadtoken=matchtoken('{')) && autozero) {
constvalue *enumfield=(enumroot!=NULL) ? enumroot->next : NULL;
do {
int fieldlit=litidx;
@ -2331,6 +2339,8 @@ static cell initvector(int ident,int tag,cell size,int fillzero,
} while (matchtoken(',')); /* do */
needtoken('}');
} else {
if (hadtoken && !autozero)
error(10);
init(ident,&ctag,errorfound);
if (!matchtag(tag,ctag,TRUE))
error(213); /* tagname mismatch */
@ -4612,12 +4622,22 @@ static void statement(int *lastindent,int allow_decl)
break;
case tNEW:
if (allow_decl) {
autozero=1;
declloc(FALSE);
lastst=tNEW;
} else {
error(3); /* declaration only valid in a block */
} /* if */
break;
case tDECL:
if (allow_decl) {
autozero=0;
declloc(FALSE);
lastst=tDECL;
} else {
error(3); /* declaration only valid in a block */
} /* if */
break;
case tSTATIC:
if (allow_decl) {
declloc(TRUE);
@ -4993,6 +5013,7 @@ static void dofor(void)
* 'compound statement' level of it own.
*/
nestlevel++;
autozero=1;
declloc(FALSE); /* declare local variable */
} else {
doexpr(TRUE,TRUE,TRUE,TRUE,NULL,NULL,FALSE); /* expression 1 */

View File

@ -1818,7 +1818,7 @@ char *sc_tokens[] = {
"...", "..", "::",
"assert", "break", "case", "char", "const", "continue", "default",
"defined", "do", "else", "enum", "exit", "for", "forward", "goto",
"if", "native", "new", "operator", "public", "return", "sizeof",
"if", "native", "new", "decl", "operator", "public", "return", "sizeof",
"sleep", "state", "static", "stock", "switch", "tagof", "while",
"#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput",
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",