emit/__emit: Make type mismatch errors more informative
Example: main() { new x; emit load.pri x } Before this commit: error 017: undefined symbol "x" After: error 001: expected token: "-data offset-", but found "-local variable-"
This commit is contained in:
parent
c58fce34cb
commit
abe9c965dc
@ -402,8 +402,13 @@ typedef struct s_valuepair {
|
||||
#define tSYMBOL 336
|
||||
#define tLABEL 337
|
||||
#define tSTRING 338
|
||||
#define tEXPR 339 /* for assigment to "lastst" only (see SC1.C) */
|
||||
#define tENDLESS 340 /* endless loop, for assigment to "lastst" only */
|
||||
/* argument types for emit/__emit */
|
||||
#define teNUMBER 339 /* integer/rational number */
|
||||
#define teDATA 340 /* data (variable name or address) */
|
||||
#define teLOCAL 341 /* local variable (name or offset) */
|
||||
/* for assigment to "lastst" only (see SC1.C) */
|
||||
#define tEXPR 342
|
||||
#define tENDLESS 343 /* endless loop */
|
||||
|
||||
/* (reversed) evaluation of staging buffer */
|
||||
#define sSTARTREORDER 0x01
|
||||
|
@ -5828,16 +5828,18 @@ static void dolabel(void)
|
||||
sym->usage|=uDEFINE; /* label is now defined */
|
||||
}
|
||||
|
||||
static void emit_invalid_token(int need_token,int current_token)
|
||||
static void emit_invalid_token(int expected_token,int found_token)
|
||||
{
|
||||
char s[sNAMEMAX+2];
|
||||
char s[2];
|
||||
extern char *sc_tokens[];
|
||||
|
||||
if (current_token<tFIRST)
|
||||
sprintf(s,"%c",(char)current_token);
|
||||
else
|
||||
strcpy(s,sc_tokens[current_token-tFIRST]);
|
||||
error(1,sc_tokens[need_token-tFIRST],s);
|
||||
assert(expected_token>=tFIRST);
|
||||
if (found_token<tFIRST) {
|
||||
sprintf(s,"%c",(char)found_token);
|
||||
error(1,sc_tokens[expected_token-tFIRST],s);
|
||||
} else {
|
||||
error(1,sc_tokens[expected_token-tFIRST],sc_tokens[found_token-tFIRST]);
|
||||
} /* if */
|
||||
}
|
||||
|
||||
static void emit_param_num(ucell *p,int size)
|
||||
@ -5884,7 +5886,7 @@ static void emit_param_num(ucell *p,int size)
|
||||
error(1,sc_tokens[tSYMBOL-tFIRST],ival);
|
||||
} /* if */
|
||||
} else {
|
||||
emit_invalid_token(tSYMBOL,tok);
|
||||
emit_invalid_token(teNUMBER,tok);
|
||||
} /* if */
|
||||
} /* switch */
|
||||
} while (++curp<size);
|
||||
@ -5908,7 +5910,7 @@ static void emit_param_data(ucell *p,int size)
|
||||
sym=findloc(str);
|
||||
if (sym!=NULL) {
|
||||
if (sym->vclass!=sSTATIC && sym->ident!=iCONSTEXPR) {
|
||||
error(17,str); /* undefined symbol */
|
||||
emit_invalid_token(teDATA,teLOCAL);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -5922,7 +5924,7 @@ static void emit_param_data(ucell *p,int size)
|
||||
p[curp]=sym->addr;
|
||||
break;
|
||||
default:
|
||||
emit_invalid_token(tSYMBOL,tok);
|
||||
emit_invalid_token(teDATA,tok);
|
||||
} /* switch */
|
||||
} while (++curp<size);
|
||||
}
|
||||
@ -5943,13 +5945,17 @@ static void emit_param_local(ucell *p,int size)
|
||||
break;
|
||||
case tSYMBOL:
|
||||
sym=findloc(str);
|
||||
if (sym==NULL) {
|
||||
if (sym!=NULL) {
|
||||
if (sym->vclass==sSTATIC) {
|
||||
emit_invalid_token(teLOCAL,teDATA);
|
||||
break;
|
||||
} /* if */
|
||||
} else {
|
||||
sym=findglb(str,sSTATEVAR);
|
||||
if (sym==NULL || sym->ident!=iCONSTEXPR)
|
||||
if (sym==NULL || sym->ident!=iCONSTEXPR) {
|
||||
error(17,str); /* undefined symbol */
|
||||
} else if (sym->vclass==sSTATIC) {
|
||||
error(17,str); /* undefined symbol */
|
||||
break;
|
||||
break;
|
||||
} /* if */
|
||||
} /* if */
|
||||
markusage(sym,uREAD|uWRITTEN);
|
||||
p[curp]=sym->addr;
|
||||
|
@ -2096,7 +2096,8 @@ char *sc_tokens[] = {
|
||||
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",
|
||||
"#tryinclude", "#undef", "#warning",
|
||||
";", ";", "-integer value-", "-rational value-", "-identifier-",
|
||||
"-label-", "-string-"
|
||||
"-label-", "-string-",
|
||||
"-numeric value-", "-data offset-", "-local variable-"
|
||||
};
|
||||
|
||||
SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
||||
|
Loading…
x
Reference in New Issue
Block a user