Fix naming and improve test name (#353)

This commit is contained in:
Zeex 2018-09-29 06:59:12 +06:00
parent bc04b2ef04
commit aabd3a5d5d
5 changed files with 88 additions and 88 deletions

View File

@ -489,24 +489,24 @@ static int levenshtein_distance(const char *s,const char*t)
return distance; return distance;
} }
static int get_maxdist(const char *name) static int get_max_dist(const char *name)
{ {
int maxdist=strlen(name)/2; /* for short names, allow only a single edit */ int max_dist=strlen(name)/2; /* for short names, allow only a single edit */
if (maxdist>MAX_EDIT_DIST) if (max_dist>MAX_EDIT_DIST)
maxdist=MAX_EDIT_DIST; max_dist=MAX_EDIT_DIST;
return maxdist; return max_dist;
} }
static int find_closestsymbol_table(const char *name,const symbol *root,int symboltype,symbol **closestsym) static int find_closest_symbol_table(const char *name,const symbol *root,int symboltype,symbol **closest_sym)
{ {
int dist,maxdist,closestdist=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; int ident;
assert(closestsym!=NULL); assert(closest_sym!=NULL);
*closestsym=NULL; *closest_sym =NULL;
assert(name!=NULL); assert(name!=NULL);
maxdist=get_maxdist(name); max_dist=get_max_dist(name);
for (sym=root->next; sym!=NULL; sym=sym->next) { for (sym=root->next; sym!=NULL; sym=sym->next) {
if (sym->fnumber!=-1 && sym->fnumber!=fcurrent) if (sym->fnumber!=-1 && sym->fnumber!=fcurrent)
continue; continue;
@ -532,17 +532,17 @@ static int find_closestsymbol_table(const char *name,const symbol *root,int symb
} /* if */ } /* if */
funcdisplayname(symname,sym->name); funcdisplayname(symname,sym->name);
dist=levenshtein_distance(name,symname); dist=levenshtein_distance(name,symname);
if (dist>maxdist || dist>=closestdist) if (dist>max_dist || dist>=closest_dist)
continue; continue;
*closestsym=sym; *closest_sym =sym;
closestdist=dist; closest_dist=dist;
if (closestdist<=1) if (closest_dist<=1)
break; break;
} /* for */ } /* for */
return closestdist; return closest_dist;
} }
static symbol *find_closestsymbol(const char *name,int symboltype) static symbol *find_closest_symbol(const char *name,int symboltype)
{ {
symbol *symloc,*symglb; symbol *symloc,*symglb;
int distloc,distglb; int distloc,distglb;
@ -552,70 +552,70 @@ static symbol *find_closestsymbol(const char *name,int symboltype)
assert(name!=NULL); assert(name!=NULL);
if (name[0]=='\0') if (name[0]=='\0')
return NULL; return NULL;
distloc=find_closestsymbol_table(name,&loctab,symboltype,&symloc); distloc=find_closest_symbol_table(name,&loctab,symboltype,&symloc);
if (distloc<=1) if (distloc<=1)
distglb=INT_MAX; /* don't bother searching in the global table */ distglb=INT_MAX; /* don't bother searching in the global table */
else else
distglb=find_closestsymbol_table(name,&glbtab,symboltype,&symglb); distglb=find_closest_symbol_table(name,&glbtab,symboltype,&symglb);
return (distglb<distloc) ? symglb : symloc; return (distglb<distloc) ? symglb : symloc;
} }
static constvalue *find_closestautomaton(const char *name) static constvalue *find_closest_automaton(const char *name)
{ {
constvalue *ptr=sc_automaton_tab.first; constvalue *ptr=sc_automaton_tab.first;
constvalue *closestmatch=NULL; constvalue *closest_match=NULL;
int dist,maxdist,closestdist=INT_MAX; int dist,max_dist,closest_dist=INT_MAX;
assert(name!=NULL); assert(name!=NULL);
maxdist=get_maxdist(name); max_dist=get_max_dist(name);
while (ptr!=NULL) { while (ptr!=NULL) {
if (ptr->name[0]!='\0') { if (ptr->name[0]!='\0') {
dist=levenshtein_distance(name,ptr->name); dist=levenshtein_distance(name,ptr->name);
if (dist<closestdist && dist<=maxdist) { if (dist<closest_dist && dist<=max_dist) {
closestmatch=ptr; closest_match=ptr;
closestdist=dist; closest_dist=dist;
if (closestdist<=1) if (closest_dist<=1)
break; break;
} /* if */ } /* if */
} /* if */ } /* if */
ptr=ptr->next; ptr=ptr->next;
} /* while */ } /* while */
return closestmatch; return closest_match;
} }
static constvalue *find_closeststate(const char *name,int fsa) static constvalue *find_closest_state(const char *name,int fsa)
{ {
constvalue *ptr=sc_state_tab.first; constvalue *ptr=sc_state_tab.first;
constvalue *closestmatch=NULL; constvalue *closest_match=NULL;
int dist,maxdist,closestdist=INT_MAX; int dist,max_dist,closest_dist=INT_MAX;
assert(name!=NULL); assert(name!=NULL);
maxdist=get_maxdist(name); max_dist=get_max_dist(name);
while (ptr!=NULL) { while (ptr!=NULL) {
if (ptr->index==fsa && ptr->name[0]!='\0') { if (ptr->index==fsa && ptr->name[0]!='\0') {
dist=levenshtein_distance(name,ptr->name); dist=levenshtein_distance(name,ptr->name);
if (dist<closestdist && dist<=maxdist) { if (dist<closest_dist && dist<=max_dist) {
closestmatch=ptr; closest_match=ptr;
closestdist=dist; closest_dist=dist;
if (closestdist<=1) if (closest_dist<=1)
break; break;
} /* if */ } /* if */
} /* if */ } /* if */
ptr=ptr->next; ptr=ptr->next;
} /* while */ } /* while */
return closestmatch; return closest_match;
} }
static constvalue *findclosest_automaton_for_state(const char *statename,int fsa) static constvalue *find_closest_automaton_for_state(const char *statename,int fsa)
{ {
constvalue *ptr=sc_state_tab.first; constvalue *ptr=sc_state_tab.first;
constvalue *closestmatch=NULL; constvalue *closest_match=NULL;
constvalue *automaton; constvalue *automaton;
const char *fsaname; const char *fsaname;
int dist,maxdist,closestdist=INT_MAX; int dist,max_dist,closest_dist=INT_MAX;
assert(statename!=NULL); assert(statename!=NULL);
maxdist=get_maxdist(statename); max_dist=get_max_dist(statename);
automaton=automaton_findid(ptr->index); automaton=automaton_findid(ptr->index);
assert(automaton!=NULL); assert(automaton!=NULL);
fsaname=automaton->name; fsaname=automaton->name;
@ -624,22 +624,22 @@ static constvalue *findclosest_automaton_for_state(const char *statename,int fsa
automaton=automaton_findid(ptr->index); automaton=automaton_findid(ptr->index);
assert(automaton!=NULL); assert(automaton!=NULL);
dist=levenshtein_distance(fsaname,automaton->name); dist=levenshtein_distance(fsaname,automaton->name);
if (dist<closestdist && dist<=maxdist) { if (dist<closest_dist && dist<=max_dist) {
closestmatch=automaton; closest_match=automaton;
closestdist=dist; closest_dist=dist;
if (closestdist<=1) if (closest_dist<=1)
break; break;
} /* if */ } /* if */
} /* if */ } /* if */
ptr=ptr->next; ptr=ptr->next;
} /* while */ } /* while */
return closestmatch; return closest_match;
} }
SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type,int subtype) SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type,int subtype)
{ {
char string[sNAMEMAX*2+2]; /* for "<automaton>:<state>" */ char string[sNAMEMAX*2+2]; /* for "<automaton>:<state>" */
const char *closestname=NULL; const char *closest_name=NULL;
/* 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
@ -648,40 +648,40 @@ SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type
return 0; return 0;
if (type==estSYMBOL || (type==estNONSYMBOL && tMIDDLE<subtype && subtype<=tLAST)) { if (type==estSYMBOL || (type==estNONSYMBOL && tMIDDLE<subtype && subtype<=tLAST)) {
symbol *closestsym; symbol *closest_sym;
if (type!=estSYMBOL) { if (type!=estSYMBOL) {
extern char *sc_tokens[]; extern char *sc_tokens[];
name=sc_tokens[subtype-tFIRST]; name=sc_tokens[subtype-tFIRST];
subtype=essVARCONST; subtype=essVARCONST;
} /* if */ } /* if */
closestsym=find_closestsymbol(name,subtype); closest_sym =find_closest_symbol(name,subtype);
if (closestsym!=NULL) if (closest_sym !=NULL)
closestname=closestsym->name; closest_name= closest_sym->name;
} else if (type==estAUTOMATON) { } else if (type==estAUTOMATON) {
constvalue *closestautomaton=find_closestautomaton(name); constvalue *closest_automaton=find_closest_automaton(name);
if (closestautomaton!=NULL) if (closest_automaton!=NULL)
closestname=closestautomaton->name; closest_name=closest_automaton->name;
} else if (type==estSTATE) { } else if (type==estSTATE) {
constvalue *closeststate=find_closeststate(name,subtype); constvalue *closest_state=find_closest_state(name,subtype);
if (closeststate!=NULL) { if (closest_state !=NULL) {
closestname=closeststate->name; closest_name=closest_state->name;
} else { } else {
constvalue *closestautomaton=findclosest_automaton_for_state(name,subtype); constvalue *closest_automaton=find_closest_automaton_for_state(name,subtype);
if (closestautomaton!=NULL) { if (closest_automaton !=NULL) {
sprintf(string,"%s:%s",closestautomaton->name,name); sprintf(string,"%s:%s", closest_automaton->name,name);
closestname=string; closest_name=string;
} /* if */ } /* if */
} /* if */ } /* if */
} else { } else {
assert(0); assert(0);
} /* if */ } /* if */
if (closestname==NULL) { if (closest_name==NULL) {
error(number,name,name2); error(number,name,name2);
} else if (name2!=NULL) { } else if (name2!=NULL) {
error(makelong(number,1),name,name2,closestname); error(makelong(number,1),name,name2,closest_name);
} else { } else {
error(makelong(number,1),name,closestname); error(makelong(number,1),name,closest_name);
} /* if */ } /* if */
return 0; return 0;
} }

View File

@ -1,24 +0,0 @@
{
'test_type': 'output_check',
'errors': """
gh_353.pwn(12) : error 017: undefined symbol "abcxyz"
gh_353.pwn(20) : error 017: undefined symbol "length"
gh_353.pwn(30) : error 017: undefined symbol "float"
gh_353.pwn(40) : error 017: undefined symbol "ab"
gh_353.pwn(41) : error 017: undefined symbol "ab"
gh_353.pwn(50) : error 017: undefined symbol "staticval"
gh_353.pwn(58) : error 017: undefined symbol "val"; did you mean "var"?
gh_353.pwn(62) : error 017: undefined symbol "celmax"; did you mean "cellmax"?
gh_353.pwn(66) : error 017: undefined symbol "strcaf"; did you mean "strcat"?
gh_353.pwn(69) : error 017: undefined symbol "test_e17"; did you mean "test_e017"?
gh_353.pwn(78) : error 019: not a label: "lb"; did you mean "lbl"?
gh_353.pwn(85) : error 020: invalid symbol name "assert"; did you mean "asset"?
gh_353.pwn(96) : error 080: unknown symbol, or not a constant symbol (symbol "idx"); did you mean "id"?
gh_353.pwn(107) : error 086: unknown automaton "automaton1"; did you mean "automaton_1"?
gh_353.pwn(107) : error 036: empty statement
gh_353.pwn(114) : error 087: unknown state "BEING1" for automaton "automaton_2"; did you mean "BEING_1"?
gh_353.pwn(114) : error 036: empty statement
gh_353.pwn(117) : error 087: unknown state "STATE_1" for automaton "automaton_2"; did you mean "automaton_1:STATE_1"?
gh_353.pwn(117) : error 036: empty statement
"""
}

View File

@ -0,0 +1,24 @@
{
'test_type': 'output_check',
'errors': """
gh_353_symbol_suggestions.pwn(12) : error 017: undefined symbol "abcxyz"
gh_353_symbol_suggestions.pwn(20) : error 017: undefined symbol "length"
gh_353_symbol_suggestions.pwn(30) : error 017: undefined symbol "float"
gh_353_symbol_suggestions.pwn(40) : error 017: undefined symbol "ab"
gh_353_symbol_suggestions.pwn(41) : error 017: undefined symbol "ab"
gh_353_symbol_suggestions.pwn(50) : error 017: undefined symbol "staticval"
gh_353_symbol_suggestions.pwn(58) : error 017: undefined symbol "val"; did you mean "var"?
gh_353_symbol_suggestions.pwn(62) : error 017: undefined symbol "celmax"; did you mean "cellmax"?
gh_353_symbol_suggestions.pwn(66) : error 017: undefined symbol "strcaf"; did you mean "strcat"?
gh_353_symbol_suggestions.pwn(69) : error 017: undefined symbol "test_e17"; did you mean "test_e017"?
gh_353_symbol_suggestions.pwn(78) : error 019: not a label: "lb"; did you mean "lbl"?
gh_353_symbol_suggestions.pwn(85) : error 020: invalid symbol name "assert"; did you mean "asset"?
gh_353_symbol_suggestions.pwn(96) : error 080: unknown symbol, or not a constant symbol (symbol "idx"); did you mean "id"?
gh_353_symbol_suggestions.pwn(107) : error 086: unknown automaton "automaton1"; did you mean "automaton_1"?
gh_353_symbol_suggestions.pwn(107) : error 036: empty statement
gh_353_symbol_suggestions.pwn(114) : error 087: unknown state "BEING1" for automaton "automaton_2"; did you mean "BEING_1"?
gh_353_symbol_suggestions.pwn(114) : error 036: empty statement
gh_353_symbol_suggestions.pwn(117) : error 087: unknown state "STATE_1" for automaton "automaton_2"; did you mean "automaton_1:STATE_1"?
gh_353_symbol_suggestions.pwn(117) : error 036: empty statement
"""
}

View File

@ -1,7 +1,7 @@
#include <console> #include <console>
#include <file> #include <file>
#include <string> #include <string>
#include "gh_353.inc" #include "gh_353_symbol_suggestions.inc"
forward test_nosuggest1(); forward test_nosuggest1();
public test_nosuggest1() public test_nosuggest1()