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 tSYMBOL 336
|
||||||
#define tLABEL 337
|
#define tLABEL 337
|
||||||
#define tSTRING 338
|
#define tSTRING 338
|
||||||
#define tEXPR 339 /* for assigment to "lastst" only (see SC1.C) */
|
/* argument types for emit/__emit */
|
||||||
#define tENDLESS 340 /* endless loop, for assigment to "lastst" only */
|
#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 */
|
/* (reversed) evaluation of staging buffer */
|
||||||
#define sSTARTREORDER 0x01
|
#define sSTARTREORDER 0x01
|
||||||
|
@ -5828,16 +5828,18 @@ static void dolabel(void)
|
|||||||
sym->usage|=uDEFINE; /* label is now defined */
|
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[];
|
extern char *sc_tokens[];
|
||||||
|
|
||||||
if (current_token<tFIRST)
|
assert(expected_token>=tFIRST);
|
||||||
sprintf(s,"%c",(char)current_token);
|
if (found_token<tFIRST) {
|
||||||
else
|
sprintf(s,"%c",(char)found_token);
|
||||||
strcpy(s,sc_tokens[current_token-tFIRST]);
|
error(1,sc_tokens[expected_token-tFIRST],s);
|
||||||
error(1,sc_tokens[need_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)
|
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);
|
error(1,sc_tokens[tSYMBOL-tFIRST],ival);
|
||||||
} /* if */
|
} /* if */
|
||||||
} else {
|
} else {
|
||||||
emit_invalid_token(tSYMBOL,tok);
|
emit_invalid_token(teNUMBER,tok);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* switch */
|
} /* switch */
|
||||||
} while (++curp<size);
|
} while (++curp<size);
|
||||||
@ -5908,7 +5910,7 @@ static void emit_param_data(ucell *p,int size)
|
|||||||
sym=findloc(str);
|
sym=findloc(str);
|
||||||
if (sym!=NULL) {
|
if (sym!=NULL) {
|
||||||
if (sym->vclass!=sSTATIC && sym->ident!=iCONSTEXPR) {
|
if (sym->vclass!=sSTATIC && sym->ident!=iCONSTEXPR) {
|
||||||
error(17,str); /* undefined symbol */
|
emit_invalid_token(teDATA,teLOCAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -5922,7 +5924,7 @@ static void emit_param_data(ucell *p,int size)
|
|||||||
p[curp]=sym->addr;
|
p[curp]=sym->addr;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
emit_invalid_token(tSYMBOL,tok);
|
emit_invalid_token(teDATA,tok);
|
||||||
} /* switch */
|
} /* switch */
|
||||||
} while (++curp<size);
|
} while (++curp<size);
|
||||||
}
|
}
|
||||||
@ -5943,13 +5945,17 @@ static void emit_param_local(ucell *p,int size)
|
|||||||
break;
|
break;
|
||||||
case tSYMBOL:
|
case tSYMBOL:
|
||||||
sym=findloc(str);
|
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);
|
sym=findglb(str,sSTATEVAR);
|
||||||
if (sym==NULL || sym->ident!=iCONSTEXPR)
|
if (sym==NULL || sym->ident!=iCONSTEXPR) {
|
||||||
error(17,str); /* undefined symbol */
|
error(17,str); /* undefined symbol */
|
||||||
} else if (sym->vclass==sSTATIC) {
|
break;
|
||||||
error(17,str); /* undefined symbol */
|
} /* if */
|
||||||
break;
|
|
||||||
} /* if */
|
} /* if */
|
||||||
markusage(sym,uREAD|uWRITTEN);
|
markusage(sym,uREAD|uWRITTEN);
|
||||||
p[curp]=sym->addr;
|
p[curp]=sym->addr;
|
||||||
|
@ -2096,7 +2096,8 @@ char *sc_tokens[] = {
|
|||||||
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",
|
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",
|
||||||
"#tryinclude", "#undef", "#warning",
|
"#tryinclude", "#undef", "#warning",
|
||||||
";", ";", "-integer value-", "-rational value-", "-identifier-",
|
";", ";", "-integer value-", "-rational value-", "-identifier-",
|
||||||
"-label-", "-string-"
|
"-label-", "-string-",
|
||||||
|
"-numeric value-", "-data offset-", "-local variable-"
|
||||||
};
|
};
|
||||||
|
|
||||||
SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user