diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index ae05425..5af6d61 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -489,24 +489,24 @@ static int levenshtein_distance(const char *s,const char*t) 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 */ - if (maxdist>MAX_EDIT_DIST) - maxdist=MAX_EDIT_DIST; - return maxdist; + int max_dist=strlen(name)/2; /* for short names, allow only a single edit */ + if (max_dist>MAX_EDIT_DIST) + max_dist=MAX_EDIT_DIST; + 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]; symbol *sym; int ident; - assert(closestsym!=NULL); - *closestsym=NULL; + assert(closest_sym!=NULL); + *closest_sym =NULL; assert(name!=NULL); - maxdist=get_maxdist(name); + max_dist=get_max_dist(name); for (sym=root->next; sym!=NULL; sym=sym->next) { if (sym->fnumber!=-1 && sym->fnumber!=fcurrent) continue; @@ -532,17 +532,17 @@ static int find_closestsymbol_table(const char *name,const symbol *root,int symb } /* if */ funcdisplayname(symname,sym->name); dist=levenshtein_distance(name,symname); - if (dist>maxdist || dist>=closestdist) + if (dist>max_dist || dist>=closest_dist) continue; - *closestsym=sym; - closestdist=dist; - if (closestdist<=1) + *closest_sym =sym; + closest_dist=dist; + if (closest_dist<=1) break; } /* 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; int distloc,distglb; @@ -552,70 +552,70 @@ static symbol *find_closestsymbol(const char *name,int symboltype) assert(name!=NULL); if (name[0]=='\0') return NULL; - distloc=find_closestsymbol_table(name,&loctab,symboltype,&symloc); + distloc=find_closest_symbol_table(name,&loctab,symboltype,&symloc); if (distloc<=1) distglb=INT_MAX; /* don't bother searching in the global table */ else - distglb=find_closestsymbol_table(name,&glbtab,symboltype,&symglb); + distglb=find_closest_symbol_table(name,&glbtab,symboltype,&symglb); return (distglbname[0]!='\0') { dist=levenshtein_distance(name,ptr->name); - if (distnext; } /* 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 *closestmatch=NULL; - int dist,maxdist,closestdist=INT_MAX; + constvalue *closest_match=NULL; + int dist,max_dist,closest_dist=INT_MAX; assert(name!=NULL); - maxdist=get_maxdist(name); + max_dist=get_max_dist(name); while (ptr!=NULL) { if (ptr->index==fsa && ptr->name[0]!='\0') { dist=levenshtein_distance(name,ptr->name); - if (distnext; } /* 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 *closestmatch=NULL; + constvalue *closest_match=NULL; constvalue *automaton; const char *fsaname; - int dist,maxdist,closestdist=INT_MAX; + int dist,max_dist,closest_dist=INT_MAX; assert(statename!=NULL); - maxdist=get_maxdist(statename); + max_dist=get_max_dist(statename); automaton=automaton_findid(ptr->index); assert(automaton!=NULL); fsaname=automaton->name; @@ -624,22 +624,22 @@ static constvalue *findclosest_automaton_for_state(const char *statename,int fsa automaton=automaton_findid(ptr->index); assert(automaton!=NULL); dist=levenshtein_distance(fsaname,automaton->name); - if (distnext; } /* while */ - return closestmatch; + return closest_match; } SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type,int subtype) { char string[sNAMEMAX*2+2]; /* for ":" */ - const char *closestname=NULL; + const char *closest_name=NULL; /* don't bother finding the closest names on errors * 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; if (type==estSYMBOL || (type==estNONSYMBOL && tMIDDLEname; + closest_sym =find_closest_symbol(name,subtype); + if (closest_sym !=NULL) + closest_name= closest_sym->name; } else if (type==estAUTOMATON) { - constvalue *closestautomaton=find_closestautomaton(name); - if (closestautomaton!=NULL) - closestname=closestautomaton->name; + constvalue *closest_automaton=find_closest_automaton(name); + if (closest_automaton!=NULL) + closest_name=closest_automaton->name; } else if (type==estSTATE) { - constvalue *closeststate=find_closeststate(name,subtype); - if (closeststate!=NULL) { - closestname=closeststate->name; + constvalue *closest_state=find_closest_state(name,subtype); + if (closest_state !=NULL) { + closest_name=closest_state->name; } else { - constvalue *closestautomaton=findclosest_automaton_for_state(name,subtype); - if (closestautomaton!=NULL) { - sprintf(string,"%s:%s",closestautomaton->name,name); - closestname=string; + constvalue *closest_automaton=find_closest_automaton_for_state(name,subtype); + if (closest_automaton !=NULL) { + sprintf(string,"%s:%s", closest_automaton->name,name); + closest_name=string; } /* if */ } /* if */ } else { assert(0); } /* if */ - if (closestname==NULL) { + if (closest_name==NULL) { error(number,name,name2); } else if (name2!=NULL) { - error(makelong(number,1),name,name2,closestname); + error(makelong(number,1),name,name2,closest_name); } else { - error(makelong(number,1),name,closestname); + error(makelong(number,1),name,closest_name); } /* if */ return 0; } diff --git a/source/compiler/tests/gh_353.meta b/source/compiler/tests/gh_353.meta deleted file mode 100644 index 7c2391d..0000000 --- a/source/compiler/tests/gh_353.meta +++ /dev/null @@ -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 - """ -} diff --git a/source/compiler/tests/gh_353.inc b/source/compiler/tests/gh_353_symbol_suggestions.inc similarity index 100% rename from source/compiler/tests/gh_353.inc rename to source/compiler/tests/gh_353_symbol_suggestions.inc diff --git a/source/compiler/tests/gh_353_symbol_suggestions.meta b/source/compiler/tests/gh_353_symbol_suggestions.meta new file mode 100644 index 0000000..0344afe --- /dev/null +++ b/source/compiler/tests/gh_353_symbol_suggestions.meta @@ -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 + """ +} diff --git a/source/compiler/tests/gh_353.pwn b/source/compiler/tests/gh_353_symbol_suggestions.pwn similarity index 98% rename from source/compiler/tests/gh_353.pwn rename to source/compiler/tests/gh_353_symbol_suggestions.pwn index e604b47..3a9e792 100644 --- a/source/compiler/tests/gh_353.pwn +++ b/source/compiler/tests/gh_353_symbol_suggestions.pwn @@ -1,7 +1,7 @@ #include #include #include -#include "gh_353.inc" +#include "gh_353_symbol_suggestions.inc" forward test_nosuggest1(); public test_nosuggest1()