Switch from symbol subtypes to symbol subtype flags
The new system should be more flexible as it allows to combine symbol subtypes.
This commit is contained in:
parent
db7efa7cb1
commit
b411e5a7bc
@ -508,13 +508,18 @@ enum { /* identifier types */
|
|||||||
estAUTOMATON,
|
estAUTOMATON,
|
||||||
estSTATE
|
estSTATE
|
||||||
};
|
};
|
||||||
enum { /* symbol types */
|
enum { /* symbol type flags */
|
||||||
essNONLABEL, /* find symbols of any type but labels */
|
esfLABEL = 1 << 0,
|
||||||
essVARCONST, /* array, single variable or named constant */
|
esfCONST = 1 << 1, /* named constant */
|
||||||
essARRAY,
|
esfVARIABLE = 1 << 2, /* single variable */
|
||||||
essCONST,
|
esfARRAY = 1 << 3, /* array */
|
||||||
essFUNCTN,
|
esfFUNCTION = 1 << 4, /* Pawn or native function */
|
||||||
essLABEL
|
|
||||||
|
/* find symbols of any type but labels */
|
||||||
|
esfNONLABEL = esfCONST | esfVARIABLE | esfARRAY | esfFUNCTION,
|
||||||
|
|
||||||
|
/* find an array, a single variable, or a named constant */
|
||||||
|
esfVARCONST = esfCONST | esfVARIABLE | esfARRAY
|
||||||
};
|
};
|
||||||
|
|
||||||
/* interface functions */
|
/* interface functions */
|
||||||
|
@ -2029,7 +2029,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst
|
|||||||
} else {
|
} else {
|
||||||
tag=pc_addtag(NULL);
|
tag=pc_addtag(NULL);
|
||||||
if (lex(&val,&str)!=tSYMBOL) /* read in (new) token */
|
if (lex(&val,&str)!=tSYMBOL) /* read in (new) token */
|
||||||
error_suggest(20,str,NULL,estSYMBOL,essFUNCTN); /* invalid symbol name */
|
error_suggest(20,str,NULL,estSYMBOL,esfFUNCTION); /* invalid symbol name */
|
||||||
assert(strlen(str)<=sNAMEMAX);
|
assert(strlen(str)<=sNAMEMAX);
|
||||||
strcpy(name,str); /* save symbol name */
|
strcpy(name,str); /* save symbol name */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -4880,7 +4880,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst)
|
|||||||
case iLABEL:
|
case iLABEL:
|
||||||
if (testlabs) {
|
if (testlabs) {
|
||||||
if ((sym->usage & uDEFINE)==0) {
|
if ((sym->usage & uDEFINE)==0) {
|
||||||
error_suggest(19,sym->name,NULL,estSYMBOL,essLABEL); /* not a label: ... */
|
error_suggest(19,sym->name,NULL,estSYMBOL,esfLABEL); /* not a label: ... */
|
||||||
} else if ((sym->usage & uREAD)==0) {
|
} else if ((sym->usage & uREAD)==0) {
|
||||||
errorset(sSETPOS,sym->lnumber);
|
errorset(sSETPOS,sym->lnumber);
|
||||||
error(203,sym->name); /* symbol isn't used: ... */
|
error(203,sym->name); /* symbol isn't used: ... */
|
||||||
@ -5984,7 +5984,7 @@ static void dogoto(void)
|
|||||||
// sym->compound (nesting level of the label) against nestlevel;
|
// sym->compound (nesting level of the label) against nestlevel;
|
||||||
// if sym->compound < nestlevel, call the destructor operator
|
// if sym->compound < nestlevel, call the destructor operator
|
||||||
} else {
|
} else {
|
||||||
error_suggest(20,st,NULL,estSYMBOL,essLABEL); /* illegal symbol name */
|
error_suggest(20,st,NULL,estSYMBOL,esfLABEL); /* illegal symbol name */
|
||||||
} /* if */
|
} /* if */
|
||||||
needtoken(tTERM);
|
needtoken(tTERM);
|
||||||
}
|
}
|
||||||
@ -6024,7 +6024,7 @@ static symbol *fetchlab(char *name)
|
|||||||
sym=findloc(name); /* labels are local in scope */
|
sym=findloc(name); /* labels are local in scope */
|
||||||
if (sym) {
|
if (sym) {
|
||||||
if (sym->ident!=iLABEL)
|
if (sym->ident!=iLABEL)
|
||||||
error_suggest(19,sym->name,NULL,estSYMBOL,essLABEL); /* not a label: ... */
|
error_suggest(19,sym->name,NULL,estSYMBOL,esfLABEL); /* not a label: ... */
|
||||||
} else {
|
} else {
|
||||||
sym=addsym(name,getlabel(),iLABEL,sLOCAL,0,0);
|
sym=addsym(name,getlabel(),iLABEL,sLOCAL,0,0);
|
||||||
assert(sym!=NULL); /* fatal error 103 must be given on error */
|
assert(sym!=NULL); /* fatal error 103 must be given on error */
|
||||||
|
@ -1349,13 +1349,13 @@ static int hier2(value *lval)
|
|||||||
if (sym==NULL)
|
if (sym==NULL)
|
||||||
sym=findglb(st,sSTATEVAR);
|
sym=findglb(st,sSTATEVAR);
|
||||||
if (sym==NULL)
|
if (sym==NULL)
|
||||||
return error_suggest(17,st,NULL,estSYMBOL,essVARCONST); /* undefined symbol */
|
return error_suggest(17,st,NULL,estSYMBOL,esfVARCONST); /* undefined symbol */
|
||||||
if (sym->ident==iCONSTEXPR)
|
if (sym->ident==iCONSTEXPR)
|
||||||
error(39); /* constant symbol has no size */
|
error(39); /* constant symbol has no size */
|
||||||
else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC)
|
else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC)
|
||||||
error(72); /* "function" symbol has no size */
|
error(72); /* "function" symbol has no size */
|
||||||
else if ((sym->usage & uDEFINE)==0)
|
else if ((sym->usage & uDEFINE)==0)
|
||||||
return error_suggest(17,st,NULL,estSYMBOL,essVARCONST); /* undefined symbol (symbol is in the table, but it is "used" only) */
|
return error_suggest(17,st,NULL,estSYMBOL,esfVARCONST); /* undefined symbol (symbol is in the table, but it is "used" only) */
|
||||||
clear_value(lval);
|
clear_value(lval);
|
||||||
lval->ident=iCONSTEXPR;
|
lval->ident=iCONSTEXPR;
|
||||||
lval->constval=1; /* preset */
|
lval->constval=1; /* preset */
|
||||||
@ -1370,7 +1370,7 @@ static int hier2(value *lval)
|
|||||||
int cmptag=subsym->x.tags.index;
|
int cmptag=subsym->x.tags.index;
|
||||||
tokeninfo(&val,&idxname);
|
tokeninfo(&val,&idxname);
|
||||||
if ((idxsym=findconst(idxname,&cmptag))==NULL)
|
if ((idxsym=findconst(idxname,&cmptag))==NULL)
|
||||||
error_suggest(80,idxname,NULL,estSYMBOL,essCONST); /* unknown symbol, or non-constant */
|
error_suggest(80,idxname,NULL,estSYMBOL,esfCONST); /* unknown symbol, or non-constant */
|
||||||
else if (cmptag>1)
|
else if (cmptag>1)
|
||||||
error(91,idxname); /* ambiguous constant */
|
error(91,idxname); /* ambiguous constant */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -1406,9 +1406,9 @@ static int hier2(value *lval)
|
|||||||
if (sym==NULL)
|
if (sym==NULL)
|
||||||
sym=findglb(st,sSTATEVAR);
|
sym=findglb(st,sSTATEVAR);
|
||||||
if (sym==NULL)
|
if (sym==NULL)
|
||||||
return error_suggest(17,st,NULL,estSYMBOL,essNONLABEL); /* undefined symbol */
|
return error_suggest(17,st,NULL,estSYMBOL,esfNONLABEL); /* undefined symbol */
|
||||||
if ((sym->usage & uDEFINE)==0)
|
if ((sym->usage & uDEFINE)==0)
|
||||||
return error_suggest(17,st,NULL,estSYMBOL,essNONLABEL); /* undefined symbol (symbol is in the table, but it is "used" only) */
|
return error_suggest(17,st,NULL,estSYMBOL,esfNONLABEL); /* undefined symbol (symbol is in the table, but it is "used" only) */
|
||||||
tag=sym->tag;
|
tag=sym->tag;
|
||||||
} /* if */
|
} /* if */
|
||||||
if (sym!=NULL && (sym->ident==iARRAY || sym->ident==iREFARRAY)) {
|
if (sym!=NULL && (sym->ident==iARRAY || sym->ident==iREFARRAY)) {
|
||||||
@ -1422,7 +1422,7 @@ static int hier2(value *lval)
|
|||||||
int cmptag=subsym->x.tags.index;
|
int cmptag=subsym->x.tags.index;
|
||||||
tokeninfo(&val,&idxname);
|
tokeninfo(&val,&idxname);
|
||||||
if ((idxsym=findconst(idxname,&cmptag))==NULL)
|
if ((idxsym=findconst(idxname,&cmptag))==NULL)
|
||||||
error_suggest(80,idxname,NULL,estSYMBOL,essCONST); /* unknown symbol, or non-constant */
|
error_suggest(80,idxname,NULL,estSYMBOL,esfCONST); /* unknown symbol, or non-constant */
|
||||||
else if (cmptag>1)
|
else if (cmptag>1)
|
||||||
error(91,idxname); /* ambiguous constant */
|
error(91,idxname); /* ambiguous constant */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -1601,7 +1601,7 @@ restart:
|
|||||||
needtoken(close);
|
needtoken(close);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (sym->ident!=iARRAY && sym->ident!=iREFARRAY){
|
} else if (sym->ident!=iARRAY && sym->ident!=iREFARRAY){
|
||||||
error_suggest(28,sym->name,NULL,estSYMBOL,essARRAY);/* cannot subscript, variable is not an array */
|
error_suggest(28,sym->name,NULL,estSYMBOL,esfARRAY);/* cannot subscript, variable is not an array */
|
||||||
needtoken(close);
|
needtoken(close);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (sym->dim.array.level>0 && close!=']') {
|
} else if (sym->dim.array.level>0 && close!=']') {
|
||||||
@ -1854,10 +1854,10 @@ static int primary(value *lval)
|
|||||||
* implemented, issue an error
|
* implemented, issue an error
|
||||||
*/
|
*/
|
||||||
if ((sym->usage & uPROTOTYPED)==0)
|
if ((sym->usage & uPROTOTYPED)==0)
|
||||||
error_suggest(17,st,NULL,estSYMBOL,essFUNCTN); /* undefined symbol */
|
error_suggest(17,st,NULL,estSYMBOL,esfFUNCTION); /* undefined symbol */
|
||||||
} else {
|
} else {
|
||||||
if ((sym->usage & uDEFINE)==0)
|
if ((sym->usage & uDEFINE)==0)
|
||||||
error_suggest(17,st,NULL,estSYMBOL,essVARCONST); /* undefined symbol */
|
error_suggest(17,st,NULL,estSYMBOL,esfVARCONST); /* undefined symbol */
|
||||||
lval->sym=sym;
|
lval->sym=sym;
|
||||||
lval->ident=sym->ident;
|
lval->ident=sym->ident;
|
||||||
lval->tag=sym->tag;
|
lval->tag=sym->tag;
|
||||||
@ -1870,7 +1870,7 @@ static int primary(value *lval)
|
|||||||
} /* if */
|
} /* if */
|
||||||
} else {
|
} else {
|
||||||
if (!sc_allowproccall)
|
if (!sc_allowproccall)
|
||||||
return error_suggest(17,st,NULL,estSYMBOL,essVARCONST); /* undefined symbol */
|
return error_suggest(17,st,NULL,estSYMBOL,esfVARCONST); /* undefined symbol */
|
||||||
/* an unknown symbol, but used in a way compatible with the "procedure
|
/* an unknown symbol, but used in a way compatible with the "procedure
|
||||||
* call" syntax. So assume that the symbol refers to a function.
|
* call" syntax. So assume that the symbol refers to a function.
|
||||||
*/
|
*/
|
||||||
|
@ -502,7 +502,6 @@ static int find_closest_symbol_table(const char *name,const symbol *root,int sym
|
|||||||
int dist,max_dist,closest_dist=INT_MAX;
|
int dist,max_dist,closest_dist=INT_MAX;
|
||||||
char symname[2*sNAMEMAX+16];
|
char symname[2*sNAMEMAX+16];
|
||||||
symbol *sym;
|
symbol *sym;
|
||||||
int ident;
|
|
||||||
assert(closest_sym!=NULL);
|
assert(closest_sym!=NULL);
|
||||||
*closest_sym =NULL;
|
*closest_sym =NULL;
|
||||||
assert(name!=NULL);
|
assert(name!=NULL);
|
||||||
@ -512,31 +511,39 @@ static int find_closest_symbol_table(const char *name,const symbol *root,int sym
|
|||||||
continue;
|
continue;
|
||||||
if ((sym->usage & uDEFINE)==0)
|
if ((sym->usage & uDEFINE)==0)
|
||||||
continue;
|
continue;
|
||||||
ident=sym->ident;
|
switch (sym->ident)
|
||||||
if (symboltype==essNONLABEL) {
|
{
|
||||||
if (ident==iLABEL)
|
case iLABEL:
|
||||||
|
if ((symboltype & esfLABEL)==0)
|
||||||
continue;
|
continue;
|
||||||
} else if (symboltype==essVARCONST) {
|
break;
|
||||||
if (ident!=iCONSTEXPR && ident!=iVARIABLE && ident!=iREFERENCE && ident!=iARRAY && ident!=iREFARRAY)
|
case iCONSTEXPR:
|
||||||
|
if ((symboltype & esfCONST)==0)
|
||||||
continue;
|
continue;
|
||||||
} else if (symboltype==essARRAY) {
|
break;
|
||||||
if (ident!=iARRAY && ident!=iREFARRAY)
|
case iVARIABLE:
|
||||||
|
case iREFERENCE:
|
||||||
|
if ((symboltype & esfVARIABLE)==0)
|
||||||
continue;
|
continue;
|
||||||
} else if (symboltype==essCONST) {
|
break;
|
||||||
if (ident!=iCONSTEXPR)
|
case iARRAY:
|
||||||
|
case iREFARRAY:
|
||||||
|
if ((symboltype & esfARRAY)==0)
|
||||||
continue;
|
continue;
|
||||||
} else if (symboltype==essFUNCTN) {
|
break;
|
||||||
if (ident!=iFUNCTN && ident!=iREFFUNC)
|
case iFUNCTN:
|
||||||
|
case iREFFUNC:
|
||||||
|
if ((symboltype & esfFUNCTION)==0)
|
||||||
continue;
|
continue;
|
||||||
} else if (symboltype==essLABEL) {
|
break;
|
||||||
if (ident!=iLABEL)
|
default:
|
||||||
continue;
|
assert(0);
|
||||||
} /* if */
|
} /* switch */
|
||||||
funcdisplayname(symname,sym->name);
|
funcdisplayname(symname,sym->name);
|
||||||
dist=levenshtein_distance(name,symname);
|
dist=levenshtein_distance(name,symname);
|
||||||
if (dist>max_dist || dist>=closest_dist)
|
if (dist>max_dist || dist>=closest_dist)
|
||||||
continue;
|
continue;
|
||||||
*closest_sym =sym;
|
*closest_sym=sym;
|
||||||
closest_dist=dist;
|
closest_dist=dist;
|
||||||
if (closest_dist<=1)
|
if (closest_dist<=1)
|
||||||
break;
|
break;
|
||||||
@ -642,6 +649,7 @@ SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type
|
|||||||
{
|
{
|
||||||
char string[sNAMEMAX*2+2]; /* for "<automaton>:<state>" */
|
char string[sNAMEMAX*2+2]; /* for "<automaton>:<state>" */
|
||||||
const char *closest_name=NULL;
|
const char *closest_name=NULL;
|
||||||
|
symbol *closest_sym;
|
||||||
|
|
||||||
/* don't bother finding the closest names on errors
|
/* don't bother finding the closest names on errors
|
||||||
* that aren't going to be shown on the 1'st pass
|
* that aren't going to be shown on the 1'st pass
|
||||||
@ -649,16 +657,18 @@ SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type
|
|||||||
if ((errflag || sc_status!=statWRITE) && (number<100 || number>=200))
|
if ((errflag || sc_status!=statWRITE) && (number<100 || number>=200))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (type==estSYMBOL || (type==estNONSYMBOL && tMIDDLE<subtype && subtype<=tLAST)) {
|
if (type==estSYMBOL) {
|
||||||
symbol *closest_sym;
|
find_symbol:
|
||||||
if (type!=estSYMBOL) {
|
closest_sym=find_closest_symbol(name,subtype);
|
||||||
|
if (closest_sym!=NULL)
|
||||||
|
closest_name=closest_sym->name;
|
||||||
|
} else if (type==estNONSYMBOL) {
|
||||||
|
if (tMIDDLE<subtype && subtype<=tLAST) {
|
||||||
extern char *sc_tokens[];
|
extern char *sc_tokens[];
|
||||||
name=sc_tokens[subtype-tFIRST];
|
name=sc_tokens[subtype-tFIRST];
|
||||||
subtype=essVARCONST;
|
subtype=esfVARCONST;
|
||||||
|
goto find_symbol;
|
||||||
} /* if */
|
} /* if */
|
||||||
closest_sym =find_closest_symbol(name,subtype);
|
|
||||||
if (closest_sym !=NULL)
|
|
||||||
closest_name= closest_sym->name;
|
|
||||||
} else if (type==estAUTOMATON) {
|
} else if (type==estAUTOMATON) {
|
||||||
constvalue *closest_automaton=find_closest_automaton(name);
|
constvalue *closest_automaton=find_closest_automaton(name);
|
||||||
if (closest_automaton!=NULL)
|
if (closest_automaton!=NULL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user