From 43c4a5f18b538ccb8fba30cc48373d42e4c3d012 Mon Sep 17 00:00:00 2001 From: Yashas Date: Thu, 25 Jan 2018 23:18:17 +0530 Subject: [PATCH] user friendly tagmm warnings --- source/compiler/sc1.c | 51 +++++++++++++++++++++++++++++-------------- source/compiler/sc5.c | 2 +- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index ccd2c76..473b59b 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3400,14 +3400,18 @@ SC_FUNC void check_tagmismatch(int formaltag,int actualtag,int allowcoerce,int e { 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-"; + char formal_tagname[sNAMEMAX+3]="none (\"_\"),",actual_tagname[sNAMEMAX+2]="none (\"_\")"; /* two extra characters for quotes */ + if(formaltag!=0) { + tagsym=find_tag_byval(formaltag); + sprintf(formal_tagname,"\"%s\",", (tagsym!=NULL) ? tagsym->name : "-unknown-"); + } /* if */ + if(actualtag!=0) { + tagsym=find_tag_byval(actualtag); + sprintf(actual_tagname,"\"%s\"",(tagsym!=NULL) ? tagsym->name : "-unknown-"); + } /* if */ if(errline>0) errorset(sSETPOS,errline); - error(213,formaltag_name,actualtag_name); /* tag mismatch */ + error(213,"tag",formal_tagname,actual_tagname); /* tag mismatch */ if(errline>0) errorset(sSETPOS,-1); } /* if */ @@ -3418,19 +3422,34 @@ SC_FUNC void check_tagmismatch_multiple(int formaltags[],int numtags,int actualt if (!checktag(formaltags, numtags, actualtag)) { int i; constvalue *tagsym; - char formal_tagnames[sLINEMAX],*actual_tagname; - formal_tagnames[0]='\0'; - for (i=0; iname : "-unknown-",sizeof(formal_tagnames)); - if((i+1)!=numtags) - strlcat(formal_tagnames,"\" or \"",sizeof(formal_tagnames)); + char formal_tagnames[sLINEMAX]="",actual_tagname[sNAMEMAX+2]="none (\"_\")"; + int notag_allowed=FALSE,add_comma=FALSE; + for (i=0; iname : "-unknown-"); + } else { + notag_allowed=TRUE; + } /* if */ } /* for */ - tagsym=find_tag_byval(actualtag); - actual_tagname=(tagsym!=NULL) ? tagsym->name : "-unknown-"; + if(notag_allowed==TRUE) { + if(add_comma==TRUE) + strlcat(formal_tagnames,", or ",sizeof(formal_tagnames)); + strlcat(formal_tagnames,"none (\"_\")",sizeof(formal_tagnames)); + } /* if */ + strlcat(formal_tagnames,(numtags==1) ? "," : ";",sizeof(formal_tagnames)); + if(actualtag!=0) { + tagsym=find_tag_byval(actualtag); + sprintf(actual_tagname,"\"%s\"",(tagsym!=NULL) ? tagsym->name : "-unknown-"); + } /* if */ if(errline>0) errorset(sSETPOS,errline); - error(213,formal_tagnames,actual_tagname); /* tag mismatch */ + error(213,(numtags==1) ? "tag" : "tags",formal_tagnames,actual_tagname); /* tag mismatch */ if(errline>0) errorset(sSETPOS,-1); } /* if */ diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index 9c83d76..c6af5a7 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -167,7 +167,7 @@ static char *warnmsg[] = { /*210*/ "possible use of symbol before initialization: \"%s\"\n", /*211*/ "possibly unintended assignment\n", /*212*/ "possibly unintended bitwise operation\n", -/*213*/ "tag mismatch: expected tag(s) \"%s\", but found \"%s\"\n", +/*213*/ "tag mismatch: expected %s %s but found %s\n", /*214*/ "possibly a \"const\" array argument was intended: \"%s\"\n", /*215*/ "expression has no effect\n", /*216*/ "nested comment\n",