emit/__emit: Don't allow to use labels as arguments of type 'numeric value', 'data offset', 'local variable' and 'function'

This commit is contained in:
Daniel_Cortez 2017-12-04 21:36:58 +07:00
parent e922e48aa6
commit 5f716b7f62

View File

@ -5879,24 +5879,28 @@ static void emit_param_any(ucell *p,int size)
assert(size>0); assert(size>0);
do { do {
neg=0; neg=FALSE;
fetchtok: fetchtok:
tok=lex(&val,&str); tok=lex(&val,&str);
switch (tok) { switch (tok) {
case tNUMBER: case tNUMBER:
p[curp]=(neg!=0) ? -val : val; p[curp]=(neg==TRUE) ? -val : val;
break; break;
case tRATIONAL: case tRATIONAL:
p[curp]=(neg!=0) ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val; p[curp]=(neg==TRUE) ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val;
break; break;
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);
if (sym==NULL) if (sym==NULL)
sym=findglb(str,sSTATEVAR); sym=findglb(str,sSTATEVAR);
if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) { if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0)) {
error(17,str); /* undefined symbol */ error(17,str); /* undefined symbol */
break; break;
} /* if */ } /* if */
if (sym->ident==iLABEL) {
emit_invalid_token(teNUMBER,tLABEL);
break;
} /* if */
if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0) if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0)
sym->addr=ntv_funcid++; sym->addr=ntv_funcid++;
@ -5904,7 +5908,7 @@ static void emit_param_any(ucell *p,int size)
} else { } else {
markusage(sym,uREAD|uWRITTEN); markusage(sym,uREAD|uWRITTEN);
} /* if */ } /* if */
p[curp]=(neg!=0) ? -sym->addr : sym->addr; p[curp]=(neg==TRUE) ? -sym->addr : sym->addr;
break; break;
case '(': case '(':
if ((emit_parsing_mode & epmEXPR)==0) if ((emit_parsing_mode & epmEXPR)==0)
@ -5919,11 +5923,11 @@ static void emit_param_any(ucell *p,int size)
if ((emit_parsing_mode & epmEXPR)==0) if ((emit_parsing_mode & epmEXPR)==0)
stgset(FALSE); stgset(FALSE);
needtoken(')'); needtoken(')');
p[curp]=(neg==0) ? val : -val; p[curp]=(neg==TRUE) ? -val : val;
break; break;
case '-': case '-':
if (neg==0) { if (neg==FALSE) {
neg=1; neg=TRUE;
goto fetchtok; goto fetchtok;
} /* if */ } /* if */
char ival[sNAMEMAX+2]="-"; char ival[sNAMEMAX+2]="-";
@ -5954,6 +5958,10 @@ static void emit_param_data(ucell *p,int size)
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);
if (sym!=NULL) { if (sym!=NULL) {
if (sym->ident==iLABEL) {
emit_invalid_token(teDATA,tLABEL);
break;
} /* if */
if (sym->vclass!=sSTATIC && sym->ident!=iCONSTEXPR) { if (sym->vclass!=sSTATIC && sym->ident!=iCONSTEXPR) {
emit_invalid_token(teDATA,teLOCAL); emit_invalid_token(teDATA,teLOCAL);
break; break;
@ -5996,6 +6004,10 @@ static void emit_param_local(ucell *p,int size)
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);
if (sym!=NULL) { if (sym!=NULL) {
if (sym->ident==iLABEL) {
emit_invalid_token(teLOCAL,tLABEL);
break;
} /* if */
if (sym->vclass==sSTATIC) { if (sym->vclass==sSTATIC) {
emit_invalid_token(teLOCAL,teDATA); emit_invalid_token(teLOCAL,teDATA);
break; break;
@ -6021,25 +6033,28 @@ static void emit_param_index(ucell *p,const cell *valid_values,int size)
cell val; cell val;
char *str; char *str;
symbol *sym; symbol *sym;
int tok,i; int tok,i,global;
int neg=0; int neg=FALSE;
assert(size>0); assert(size>0);
fetchtok: fetchtok:
tok=lex(&val,&str); tok=lex(&val,&str);
switch (tok) { switch (tok) {
case tNUMBER: case tNUMBER:
if (neg!=0) if (neg==TRUE)
val=-val; val=-val;
break; break;
case tRATIONAL: case tRATIONAL:
if (neg!=0) if (neg==TRUE)
val=val|((cell)1 << (PAWN_CELL_SIZE-1)); val=val|((cell)1 << (PAWN_CELL_SIZE-1));
break; break;
case tSYMBOL: case tSYMBOL:
sym=findloc(str); global=FALSE;
if (sym==NULL) sym=findloc(str);
if (sym==NULL) {
global=TRUE;
sym=findglb(str,sSTATEVAR); sym=findglb(str,sSTATEVAR);
} /* if */
if (sym==NULL) { if (sym==NULL) {
error(17,str); /* undefined symbol */ error(17,str); /* undefined symbol */
return; return;
@ -6047,22 +6062,25 @@ fetchtok:
switch (sym->ident) { switch (sym->ident) {
case iCONSTEXPR: case iCONSTEXPR:
break; break;
case iLABEL:
tok=tLABEL;
goto invalid_token;
case iFUNCTN: case iFUNCTN:
case iREFFUNC: case iREFFUNC:
tok=((sym->usage & uNATIVE)!=0) ? teNATIVE : teFUNCTN; tok=((sym->usage & uNATIVE)!=0) ? teNATIVE : teFUNCTN;
/* drop through */ goto invalid_token;
default: default:
if (tok==tSYMBOL) tok=(global==FALSE && sym->vclass!=sSTATIC) ? teLOCAL : teDATA;
tok=teDATA; invalid_token:
emit_invalid_token(teNUMBER,tok); emit_invalid_token(teNUMBER,tok);
return; return;
} /* switch */ } /* switch */
markusage(sym,uREAD); markusage(sym,uREAD);
val=(neg!=0) ? -sym->addr : sym->addr; val=(neg==TRUE) ? -sym->addr : sym->addr;
break; break;
case '-': case '-':
if (neg==0) { if (neg==FALSE) {
neg=1; neg=TRUE;
goto fetchtok; goto fetchtok;
} /* if */ } /* if */
/* drop through */ /* drop through */