Merge pull request #191 from Arkshine/fix/compiler-tagof

Fix tagof operator used as a default value for function arguments
This commit is contained in:
Vincent Herbet 2015-01-31 16:39:33 +01:00
commit 53829a1270

View File

@ -1243,6 +1243,7 @@ static int hier2(value *lval)
clear_value(lval); clear_value(lval);
lval->ident=iCONSTEXPR; lval->ident=iCONSTEXPR;
lval->constval= val; lval->constval= val;
lval->tag=pc_addtag("bool");
ldconst(lval->constval,sPRI); ldconst(lval->constval,sPRI);
while (paranthese--) while (paranthese--)
needtoken(')'); needtoken(')');
@ -1335,7 +1336,7 @@ static int hier2(value *lval)
exporttag(tag); exporttag(tag);
clear_value(lval); clear_value(lval);
lval->ident=iCONSTEXPR; lval->ident=iCONSTEXPR;
lval->constval=tag; lval->constval=tag | PUBLICTAG;
ldconst(lval->constval,sPRI); ldconst(lval->constval,sPRI);
while (paranthese--) while (paranthese--)
needtoken(')'); needtoken(')');
@ -1852,6 +1853,7 @@ static int nesting=0;
arginfo *arg; arginfo *arg;
char arglist[sMAXARGS]; char arglist[sMAXARGS];
constvalue arrayszlst = { NULL, "", 0, 0}; /* array size list starts empty */ constvalue arrayszlst = { NULL, "", 0, 0}; /* array size list starts empty */
constvalue taglst = { NULL, "", 0, 0}; /* tag list starts empty */
symbol *symret; symbol *symret;
cell lexval; cell lexval;
char *lexstr; char *lexstr;
@ -2001,6 +2003,8 @@ static int nesting=0;
markusage(lval.sym,uWRITTEN); markusage(lval.sym,uWRITTEN);
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag)) if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
error(213); error(213);
if (lval.tag != 0)
append_constval(&taglst, arg[argidx].name, lval.tag, 0);
break; break;
case iVARIABLE: case iVARIABLE:
if (lval.ident==iLABEL || lval.ident==iFUNCTN || lval.ident==iREFFUNC if (lval.ident==iLABEL || lval.ident==iFUNCTN || lval.ident==iREFFUNC
@ -2013,6 +2017,8 @@ static int nesting=0;
check_userop(NULL,lval.tag,arg[argidx].tags[0],2,NULL,&lval.tag); check_userop(NULL,lval.tag,arg[argidx].tags[0],2,NULL,&lval.tag);
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag)) if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
error(213); error(213);
if (lval.tag != 0)
append_constval(&taglst, arg[argidx].name, lval.tag, 0);
argidx++; /* argument done */ argidx++; /* argument done */
break; break;
case iREFERENCE: case iREFERENCE:
@ -2033,6 +2039,8 @@ static int nesting=0;
/* otherwise, the address is already in PRI */ /* otherwise, the address is already in PRI */
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag)) if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
error(213); error(213);
if (lval.tag != 0)
append_constval(&taglst, arg[argidx].name, lval.tag, 0);
argidx++; /* argument done */ argidx++; /* argument done */
if (lval.sym!=NULL) if (lval.sym!=NULL)
markusage(lval.sym,uWRITTEN); markusage(lval.sym,uWRITTEN);
@ -2108,6 +2116,8 @@ static int nesting=0;
/* address already in PRI */ /* address already in PRI */
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag)) if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
error(213); error(213);
if (lval.tag != 0)
append_constval(&taglst, arg[argidx].name, lval.tag, 0);
// ??? set uWRITTEN? // ??? set uWRITTEN?
argidx++; /* argument done */ argidx++; /* argument done */
break; break;
@ -2215,13 +2225,14 @@ static int nesting=0;
array_sz=1; array_sz=1;
} /* if */ } /* if */
} else { } else {
symbol *sym; asz=find_constval(&taglst,arg[argidx].defvalue.size.symname,
assert((arg[argidx].hasdefault & uTAGOF)!=0); arg[argidx].defvalue.size.level);
sym=findloc(arg[argidx].defvalue.size.symname); if (asz != NULL) {
if (sym==NULL) exporttag(asz->value);
sym=findglb(arg[argidx].defvalue.size.symname); array_sz=asz->value | PUBLICTAG; /* must be set, because it just was exported */
array_sz=(sym!=NULL) ? sym->tag : 0; } else {
exporttag((int)array_sz); array_sz=0;
} /* if */
} /* if */ } /* if */
ldconst(array_sz,sPRI); ldconst(array_sz,sPRI);
pushreg(sPRI); /* store the function argument on the stack */ pushreg(sPRI); /* store the function argument on the stack */
@ -2245,6 +2256,7 @@ static int nesting=0;
sideeffect=TRUE; /* assume functions carry out a side-effect */ sideeffect=TRUE; /* assume functions carry out a side-effect */
sc_allowproccall=FALSE; sc_allowproccall=FALSE;
delete_consttable(&arrayszlst); /* clear list of array sizes */ delete_consttable(&arrayszlst); /* clear list of array sizes */
delete_consttable(&taglst); /* clear list of parameter tags */
/* maintain max. amount of memory used */ /* maintain max. amount of memory used */
{ {
@ -2381,7 +2393,8 @@ static int constant(value *lval)
error(213); /* tagname mismatch */ error(213); /* tagname mismatch */
litadd(item); /* store expression result in literal table */ litadd(item); /* store expression result in literal table */
} while (matchtoken(',')); } while (matchtoken(','));
needtoken('}'); if (!needtoken('}'))
lexclr(FALSE);
ldconst((val+glb_declared)*sizeof(cell),sPRI); ldconst((val+glb_declared)*sizeof(cell),sPRI);
lval->ident=iARRAY; /* pretend this is a global array */ lval->ident=iARRAY; /* pretend this is a global array */
lval->constval=litidx-val; /* constval == the size of the literal array */ lval->constval=litidx-val; /* constval == the size of the literal array */