debug info for tagmismatch warnings
This commit adds useful information to the "tag mismatch" warning.
This commit is contained in:
parent
9a21fb5a2f
commit
345b415d55
@ -549,6 +549,8 @@ long pc_lengthbin(void *handle); /* return the length of the file */
|
|||||||
SC_FUNC void set_extension(char *filename,char *extension,int force);
|
SC_FUNC void set_extension(char *filename,char *extension,int force);
|
||||||
SC_FUNC symbol *fetchfunc(char *name,int tag);
|
SC_FUNC symbol *fetchfunc(char *name,int tag);
|
||||||
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag);
|
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag);
|
||||||
|
SC_FUNC void check_tagmismatch(int formaltag,int actualtag,int allowcoerce,int errline);
|
||||||
|
SC_FUNC void check_tagmismatch_multiple(int formaltags[],int numtags,int actualtag,int errline);
|
||||||
SC_FUNC char *funcdisplayname(char *dest,char *funcname);
|
SC_FUNC char *funcdisplayname(char *dest,char *funcname);
|
||||||
SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr);
|
SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr);
|
||||||
SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
|
SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
|
||||||
@ -603,6 +605,7 @@ SC_FUNC char *itoh(ucell val);
|
|||||||
SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
|
SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
|
||||||
value *lval,int *resulttag);
|
value *lval,int *resulttag);
|
||||||
SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce);
|
SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce);
|
||||||
|
SC_FUNC int checktag(int tags[],int numtags,int exprtag);
|
||||||
SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult);
|
SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult);
|
||||||
SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state);
|
SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state);
|
||||||
SC_FUNC cell array_totalsize(symbol *sym);
|
SC_FUNC cell array_totalsize(symbol *sym);
|
||||||
|
@ -2352,8 +2352,7 @@ static int declloc(int fstatic)
|
|||||||
assert(staging); /* end staging phase (optimize expression) */
|
assert(staging); /* end staging phase (optimize expression) */
|
||||||
stgout(staging_start);
|
stgout(staging_start);
|
||||||
stgset(FALSE);
|
stgset(FALSE);
|
||||||
if (!matchtag(tag,ctag,TRUE))
|
check_tagmismatch(tag,ctag,TRUE,-1);
|
||||||
error(213); /* tag mismatch */
|
|
||||||
/* if the variable was not explicitly initialized, reset the
|
/* if the variable was not explicitly initialized, reset the
|
||||||
* "uWRITTEN" flag that store() set */
|
* "uWRITTEN" flag that store() set */
|
||||||
if (!explicit_init)
|
if (!explicit_init)
|
||||||
@ -2508,8 +2507,7 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim,
|
|||||||
if (ident==iVARIABLE) {
|
if (ident==iVARIABLE) {
|
||||||
assert(*size==1);
|
assert(*size==1);
|
||||||
init(ident,&ctag,NULL);
|
init(ident,&ctag,NULL);
|
||||||
if (!matchtag(tag,ctag,TRUE))
|
check_tagmismatch(tag,ctag,TRUE,-1);
|
||||||
error(213); /* tag mismatch */
|
|
||||||
} else {
|
} else {
|
||||||
assert(numdim>0);
|
assert(numdim>0);
|
||||||
if (numdim==1) {
|
if (numdim==1) {
|
||||||
@ -2736,14 +2734,12 @@ static cell initvector(int ident,int tag,cell size,int startlit,int fillzero,
|
|||||||
rtag=symfield->x.tags.index; /* set the expected tag to the index tag */
|
rtag=symfield->x.tags.index; /* set the expected tag to the index tag */
|
||||||
enumfield=enumfield->next;
|
enumfield=enumfield->next;
|
||||||
} /* if */
|
} /* if */
|
||||||
if (!matchtag(rtag,ctag,TRUE))
|
check_tagmismatch(rtag,ctag,TRUE,-1);
|
||||||
error(213); /* tag mismatch */
|
|
||||||
} while (matchtoken(',')); /* do */
|
} while (matchtoken(',')); /* do */
|
||||||
needtoken('}');
|
needtoken('}');
|
||||||
} else {
|
} else {
|
||||||
init(ident,&ctag,errorfound);
|
init(ident,&ctag,errorfound);
|
||||||
if (!matchtag(tag,ctag,TRUE))
|
check_tagmismatch(tag,ctag,TRUE,-1);
|
||||||
error(213); /* tagname mismatch */
|
|
||||||
} /* if */
|
} /* if */
|
||||||
/* fill up the literal queue with a series */
|
/* fill up the literal queue with a series */
|
||||||
if (ellips) {
|
if (ellips) {
|
||||||
@ -2854,12 +2850,7 @@ static void decl_const(int vclass)
|
|||||||
needtoken('=');
|
needtoken('=');
|
||||||
constexpr(&val,&exprtag,NULL); /* get value */
|
constexpr(&val,&exprtag,NULL); /* get value */
|
||||||
/* add_constant() checks for duplicate definitions */
|
/* add_constant() checks for duplicate definitions */
|
||||||
if (!matchtag(tag,exprtag,FALSE)) {
|
check_tagmismatch(tag,exprtag,FALSE,symbolline);
|
||||||
/* temporarily reset the line number to where the symbol was defined */
|
|
||||||
errorset(sSETPOS,symbolline);
|
|
||||||
error(213); /* tagname mismatch */
|
|
||||||
errorset(sSETPOS,-1);
|
|
||||||
} /* if */
|
|
||||||
sym=add_constant(constname,val,vclass,tag);
|
sym=add_constant(constname,val,vclass,tag);
|
||||||
if (sym!=NULL)
|
if (sym!=NULL)
|
||||||
sc_attachdocumentation(sym);/* attach any documenation to the constant */
|
sc_attachdocumentation(sym);/* attach any documenation to the constant */
|
||||||
@ -3405,6 +3396,46 @@ static constvalue *find_tag_byval(int tag)
|
|||||||
return tagsym;
|
return tagsym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SC_FUNC void check_tagmismatch(int formaltag,int actualtag,int allowcoerce,int errline)
|
||||||
|
{
|
||||||
|
if (!matchtag(formaltag,actualtag,allowcoerce)) {
|
||||||
|
constvalue *tagsym;
|
||||||
|
char *formaltag_name,*actualtag_name;
|
||||||
|
tagsym=find_tag_byval(formaltag);
|
||||||
|
formaltag_name=(tagsym!=NULL) ? tagsym->name : "-unknown-";
|
||||||
|
tagsym=find_tag_byval(actualtag);
|
||||||
|
actualtag_name=(tagsym!=NULL) ? tagsym->name : "-unknown-";
|
||||||
|
if(errline>0)
|
||||||
|
errorset(sSETPOS,errline);
|
||||||
|
error(213,formaltag_name,actualtag_name); /* tag mismatch */
|
||||||
|
if(errline>0)
|
||||||
|
errorset(sSETPOS,-1);
|
||||||
|
} /* if */
|
||||||
|
}
|
||||||
|
|
||||||
|
SC_FUNC void check_tagmismatch_multiple(int formaltags[],int numtags,int actualtag,int errline)
|
||||||
|
{
|
||||||
|
if (!checktag(formaltags, numtags, actualtag)) {
|
||||||
|
int i;
|
||||||
|
constvalue *tagsym;
|
||||||
|
char formal_tagnames[sLINEMAX],*actual_tagname;
|
||||||
|
formal_tagnames[0]='\0';
|
||||||
|
for (i=0; i<numtags; i++) {
|
||||||
|
tagsym=find_tag_byval(formaltags[i]);
|
||||||
|
strlcat(formal_tagnames,(tagsym!=NULL) ? tagsym->name : "-unknown-",sizeof(formal_tagnames));
|
||||||
|
if((i+1)!=numtags)
|
||||||
|
strlcat(formal_tagnames,"\" or \"",sizeof(formal_tagnames));
|
||||||
|
} /* for */
|
||||||
|
tagsym=find_tag_byval(actualtag);
|
||||||
|
actual_tagname=(tagsym!=NULL) ? tagsym->name : "-unknown-";
|
||||||
|
if(errline>0)
|
||||||
|
errorset(sSETPOS,errline);
|
||||||
|
error(213,formal_tagnames,actual_tagname); /* tag mismatch */
|
||||||
|
if(errline>0)
|
||||||
|
errorset(sSETPOS,-1);
|
||||||
|
} /* if */
|
||||||
|
}
|
||||||
|
|
||||||
SC_FUNC char *funcdisplayname(char *dest,char *funcname)
|
SC_FUNC char *funcdisplayname(char *dest,char *funcname)
|
||||||
{
|
{
|
||||||
int tags[2];
|
int tags[2];
|
||||||
@ -4112,8 +4143,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
|
|||||||
} else {
|
} else {
|
||||||
constexpr(&arg->defvalue.val,&arg->defvalue_tag,NULL);
|
constexpr(&arg->defvalue.val,&arg->defvalue_tag,NULL);
|
||||||
assert(numtags>0);
|
assert(numtags>0);
|
||||||
if (!matchtag(tags[0],arg->defvalue_tag,TRUE))
|
check_tagmismatch(tags[0],arg->defvalue_tag,TRUE,-1);
|
||||||
error(213); /* tagname mismatch */
|
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -6773,8 +6803,7 @@ static void doreturn(void)
|
|||||||
rettype|=uRETVALUE; /* function returns a value */
|
rettype|=uRETVALUE; /* function returns a value */
|
||||||
/* check tagname with function tagname */
|
/* check tagname with function tagname */
|
||||||
assert(curfunc!=NULL);
|
assert(curfunc!=NULL);
|
||||||
if (!matchtag(curfunc->tag,tag,TRUE))
|
check_tagmismatch(curfunc->tag,tag,TRUE,-1);
|
||||||
error(213); /* tagname mismatch */
|
|
||||||
if (ident==iARRAY || ident==iREFARRAY) {
|
if (ident==iARRAY || ident==iREFARRAY) {
|
||||||
int dim[sDIMEN_MAX],numdim=0;
|
int dim[sDIMEN_MAX],numdim=0;
|
||||||
cell arraysize;
|
cell arraysize;
|
||||||
|
@ -293,6 +293,18 @@ SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SC_FUNC int checktag(int tags[],int numtags,int exprtag)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
assert(tags!=0);
|
||||||
|
assert(numtags>0);
|
||||||
|
for (i=0; i<numtags; i++)
|
||||||
|
if (matchtag(tags[i],exprtag,TRUE))
|
||||||
|
return TRUE; /* matching tag */
|
||||||
|
return FALSE; /* no tag matched */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The AMX pseudo-processor has no direct support for logical (boolean)
|
* The AMX pseudo-processor has no direct support for logical (boolean)
|
||||||
* operations. These have to be done via comparing and jumping. Since we are
|
* operations. These have to be done via comparing and jumping. Since we are
|
||||||
@ -613,12 +625,10 @@ static void plnge2(void (*oper)(void),
|
|||||||
} else if (lval1->ident==iCONSTEXPR && lval2->ident==iCONSTEXPR) {
|
} else if (lval1->ident==iCONSTEXPR && lval2->ident==iCONSTEXPR) {
|
||||||
/* only constant expression if both constant */
|
/* only constant expression if both constant */
|
||||||
stgdel(index,cidx); /* scratch generated code and calculate */
|
stgdel(index,cidx); /* scratch generated code and calculate */
|
||||||
if (!matchtag(lval1->tag,lval2->tag,FALSE))
|
check_tagmismatch(lval1->tag,lval2->tag,FALSE,-1);
|
||||||
error(213); /* tagname mismatch */
|
|
||||||
lval1->constval=calc(lval1->constval,oper,lval2->constval,&lval1->boolresult);
|
lval1->constval=calc(lval1->constval,oper,lval2->constval,&lval1->boolresult);
|
||||||
} else {
|
} else {
|
||||||
if (!matchtag(lval1->tag,lval2->tag,FALSE))
|
check_tagmismatch(lval1->tag,lval2->tag,FALSE,-1);
|
||||||
error(213); /* tagname mismatch */
|
|
||||||
(*oper)(); /* do the (signed) operation */
|
(*oper)(); /* do the (signed) operation */
|
||||||
lval1->ident=iEXPRESSION;
|
lval1->ident=iEXPRESSION;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -1044,8 +1054,8 @@ static int hier14(value *lval1)
|
|||||||
check_userop(NULL,lval2.tag,lval3.tag,2,&lval3,&lval2.tag);
|
check_userop(NULL,lval2.tag,lval3.tag,2,&lval3,&lval2.tag);
|
||||||
store(&lval3); /* now, store the expression result */
|
store(&lval3); /* now, store the expression result */
|
||||||
} /* if */
|
} /* if */
|
||||||
if (!oper && !matchtag(lval3.tag,lval2.tag,TRUE))
|
if (!oper)
|
||||||
error(213); /* tagname mismatch (if "oper", warning already given in plunge2()) */
|
check_tagmismatch(lval3.tag,lval2.tag,TRUE,-1); /* tagname mismatch (if "oper", warning already given in plunge2()) */
|
||||||
if (lval3.sym)
|
if (lval3.sym)
|
||||||
markusage(lval3.sym,uWRITTEN);
|
markusage(lval3.sym,uWRITTEN);
|
||||||
pc_sideeffect=TRUE;
|
pc_sideeffect=TRUE;
|
||||||
@ -1119,8 +1129,7 @@ static int hier13(value *lval)
|
|||||||
error(33,ptr); /* array must be indexed */
|
error(33,ptr); /* array must be indexed */
|
||||||
} /* if */
|
} /* if */
|
||||||
/* ??? if both are arrays, should check dimensions */
|
/* ??? if both are arrays, should check dimensions */
|
||||||
if (!matchtag(lval->tag,lval2.tag,FALSE))
|
check_tagmismatch(lval->tag,lval2.tag,FALSE,-1); /* tagname mismatch ('true' and 'false' expressions) */
|
||||||
error(213); /* tagname mismatch ('true' and 'false' expressions) */
|
|
||||||
setlabel(flab2);
|
setlabel(flab2);
|
||||||
if (sc_status==statFIRST) {
|
if (sc_status==statFIRST) {
|
||||||
/* Calculate the max. heap space used by either branch and save values of
|
/* Calculate the max. heap space used by either branch and save values of
|
||||||
@ -1604,8 +1613,7 @@ restart:
|
|||||||
if (lval2.ident==iARRAY || lval2.ident==iREFARRAY)
|
if (lval2.ident==iARRAY || lval2.ident==iREFARRAY)
|
||||||
error(33,lval2.sym->name); /* array must be indexed */
|
error(33,lval2.sym->name); /* array must be indexed */
|
||||||
needtoken(close);
|
needtoken(close);
|
||||||
if (!matchtag(sym->x.tags.index,lval2.tag,TRUE))
|
check_tagmismatch(sym->x.tags.index,lval2.tag,TRUE,-1);
|
||||||
error(213);
|
|
||||||
if (lval2.ident==iCONSTEXPR) { /* constant expression */
|
if (lval2.ident==iCONSTEXPR) { /* constant expression */
|
||||||
stgdel(index,cidx); /* scratch generated code */
|
stgdel(index,cidx); /* scratch generated code */
|
||||||
if (lval1->arrayidx!=NULL) { /* keep constant index, for checking */
|
if (lval1->arrayidx!=NULL) { /* keep constant index, for checking */
|
||||||
@ -1948,18 +1956,6 @@ static int findnamedarg(arginfo *arg,char *name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checktag(int tags[],int numtags,int exprtag)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
assert(tags!=0);
|
|
||||||
assert(numtags>0);
|
|
||||||
for (i=0; i<numtags; i++)
|
|
||||||
if (matchtag(tags[i],exprtag,TRUE))
|
|
||||||
return TRUE; /* matching tag */
|
|
||||||
return FALSE; /* no tag matched */
|
|
||||||
}
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ARG_UNHANDLED,
|
ARG_UNHANDLED,
|
||||||
ARG_IGNORED,
|
ARG_IGNORED,
|
||||||
@ -2156,8 +2152,7 @@ static int nesting=0;
|
|||||||
/* otherwise, the address is already in PRI */
|
/* otherwise, the address is already in PRI */
|
||||||
if (lval.sym!=NULL)
|
if (lval.sym!=NULL)
|
||||||
markusage(lval.sym,uWRITTEN);
|
markusage(lval.sym,uWRITTEN);
|
||||||
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
|
check_tagmismatch_multiple(arg[argidx].tags,arg[argidx].numtags,lval.tag,-1);
|
||||||
error(213);
|
|
||||||
if (lval.tag!=0)
|
if (lval.tag!=0)
|
||||||
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
||||||
break;
|
break;
|
||||||
@ -2170,8 +2165,7 @@ static int nesting=0;
|
|||||||
/* otherwise, the expression result is already in PRI */
|
/* otherwise, the expression result is already in PRI */
|
||||||
assert(arg[argidx].numtags>0);
|
assert(arg[argidx].numtags>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))
|
check_tagmismatch_multiple(arg[argidx].tags,arg[argidx].numtags,lval.tag,-1);
|
||||||
error(213);
|
|
||||||
if (lval.tag!=0)
|
if (lval.tag!=0)
|
||||||
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
||||||
argidx++; /* argument done */
|
argidx++; /* argument done */
|
||||||
@ -2192,8 +2186,7 @@ static int nesting=0;
|
|||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
/* otherwise, the address is already in PRI */
|
/* otherwise, the address is already in PRI */
|
||||||
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
|
check_tagmismatch_multiple(arg[argidx].tags,arg[argidx].numtags,lval.tag,-1);
|
||||||
error(213);
|
|
||||||
if (lval.tag!=0)
|
if (lval.tag!=0)
|
||||||
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
||||||
argidx++; /* argument done */
|
argidx++; /* argument done */
|
||||||
@ -2269,8 +2262,7 @@ static int nesting=0;
|
|||||||
append_constval(&arrayszlst,arg[argidx].name,sym->dim.array.length,level);
|
append_constval(&arrayszlst,arg[argidx].name,sym->dim.array.length,level);
|
||||||
} /* if */
|
} /* if */
|
||||||
/* address already in PRI */
|
/* address already in PRI */
|
||||||
if (!checktag(arg[argidx].tags,arg[argidx].numtags,lval.tag))
|
check_tagmismatch_multiple(arg[argidx].tags,arg[argidx].numtags,lval.tag,-1);
|
||||||
error(213);
|
|
||||||
if (lval.tag!=0)
|
if (lval.tag!=0)
|
||||||
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
append_constval(&taglst,arg[argidx].name,lval.tag,0);
|
||||||
// ??? set uWRITTEN?
|
// ??? set uWRITTEN?
|
||||||
@ -2545,8 +2537,8 @@ static int constant(value *lval)
|
|||||||
error(8); /* must be constant expression */
|
error(8); /* must be constant expression */
|
||||||
if (lasttag<0)
|
if (lasttag<0)
|
||||||
lasttag=tag;
|
lasttag=tag;
|
||||||
else if (!matchtag(lasttag,tag,FALSE))
|
else
|
||||||
error(213); /* tagname mismatch */
|
check_tagmismatch(lasttag,tag,FALSE,-1);
|
||||||
litadd(item); /* store expression result in literal table */
|
litadd(item); /* store expression result in literal table */
|
||||||
} while (matchtoken(','));
|
} while (matchtoken(','));
|
||||||
if (!needtoken('}'))
|
if (!needtoken('}'))
|
||||||
|
@ -167,7 +167,7 @@ static char *warnmsg[] = {
|
|||||||
/*210*/ "possible use of symbol before initialization: \"%s\"\n",
|
/*210*/ "possible use of symbol before initialization: \"%s\"\n",
|
||||||
/*211*/ "possibly unintended assignment\n",
|
/*211*/ "possibly unintended assignment\n",
|
||||||
/*212*/ "possibly unintended bitwise operation\n",
|
/*212*/ "possibly unintended bitwise operation\n",
|
||||||
/*213*/ "tag mismatch\n",
|
/*213*/ "tag mismatch: expected tag(s) \"%s\", but found \"%s\"\n",
|
||||||
/*214*/ "possibly a \"const\" array argument was intended: \"%s\"\n",
|
/*214*/ "possibly a \"const\" array argument was intended: \"%s\"\n",
|
||||||
/*215*/ "expression has no effect\n",
|
/*215*/ "expression has no effect\n",
|
||||||
/*216*/ "nested comment\n",
|
/*216*/ "nested comment\n",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user