Skip to content

Commit

Permalink
Fix find_symbol() returning wrong symbol
Browse files Browse the repository at this point in the history
Stop find_symbol() from exiting too early when have multiple matching
symbols (static and non-static). Ignore non-static symbols (those with
fnumber == -1) unless found nothing else.

Fixes #20.
  • Loading branch information
Zeex committed Apr 26, 2014
1 parent 0145282 commit e35f9c9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions source/compiler/sc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2722,24 +2722,28 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a
|| automaton<0 && sym->states==NULL
|| automaton>=0 && sym->states!=NULL && state_getfsa(sym->states->next->index)==automaton)
{
if (cmptag==NULL)
return sym; /* return first match */
if (cmptag==NULL && sym->fnumber==fnumber)
return sym; /* return first match */
/* return closest match or first match; count number of matches */
if (firstmatch==NULL)
firstmatch=sym;
assert(cmptag!=NULL);
if (*cmptag==0)
if (cmptag!=NULL && *cmptag==0)
count++;
if (*cmptag==sym->tag) {
*cmptag=1; /* good match found, set number of matches to 1 */
return sym;
if (cmptag!=NULL && *cmptag==sym->tag) {
firstmatch=sym; /* good match found */
if (sym->fnumber==fnumber)
break;
} /* if */
} /* if */
} /* */
sym=sym->next;
} /* while */
if (cmptag!=NULL && firstmatch!=NULL)
*cmptag=count;
if (cmptag!=NULL && firstmatch!=NULL) {
if (*cmptag==0)
*cmptag=count;
else
*cmptag=1; /* set number of matches to 1 */
} /* if */
return firstmatch;
}

Expand Down

0 comments on commit e35f9c9

Please sign in to comment.