mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-22 09:31:40 +00:00
[qfcc] Fix function disambiguation
I was checking for duplicate best matches too early. Local minimum (or inflection point, really) problem.
This commit is contained in:
parent
277c5a2318
commit
9f9aecfeec
1 changed files with 22 additions and 14 deletions
|
@ -659,10 +659,6 @@ find_generic_function (genfunc_t **genfuncs, const expr_t *fexpr,
|
|||
unsigned best_cost = ~0u;
|
||||
int best_ind = -1;
|
||||
for (int i = 0; i < num_funcs; i++) {
|
||||
if (best_ind >= 0 && costs[i] == best_cost) {
|
||||
error (fexpr, "unable to disambiguate %s", fsym->name);
|
||||
return nullptr;
|
||||
}
|
||||
if (costs[i] < best_cost) {
|
||||
best_ind = i;
|
||||
best_cost = costs[i];
|
||||
|
@ -673,6 +669,12 @@ find_generic_function (genfunc_t **genfuncs, const expr_t *fexpr,
|
|||
fsym->name);
|
||||
return nullptr;
|
||||
}
|
||||
for (int i = 0; i < num_funcs; i++) {
|
||||
if (i != best_ind && costs[i] == best_cost) {
|
||||
error (fexpr, "unable to disambiguate %s", fsym->name);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return genfuncs[best_ind];
|
||||
}
|
||||
|
||||
|
@ -918,7 +920,8 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
.params = call_params,
|
||||
};
|
||||
|
||||
const char *fname = fexpr->symbol->name;
|
||||
auto fsym = fexpr->symbol;
|
||||
const char *fname = fsym->name;
|
||||
auto genfuncs = (genfunc_t **) Hash_FindList (generic_functions, fname);
|
||||
if (genfuncs) {
|
||||
auto gen = find_generic_function (genfuncs, fexpr, &calltype, true);
|
||||
|
@ -967,7 +970,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
int best_ind = -1;
|
||||
for (int i = 0; i < num_funcs; i++) {
|
||||
if (best_ind >= 0 && costs[i] == best_cost) {
|
||||
error (fexpr, "unable to disambiguate %s", fexpr->symbol->name);
|
||||
error (fexpr, "unable to disambiguate %s", fsym->name);
|
||||
continue;
|
||||
}
|
||||
if (costs[i] < best_cost) {
|
||||
|
@ -975,16 +978,21 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
best_cost = costs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (best_ind >= 0) {
|
||||
auto best = funcs[best_ind];
|
||||
if (best->meta_type == mf_overload) {
|
||||
fexpr = set_func_symbol (fexpr, best);
|
||||
}
|
||||
if (best_ind < 0) {
|
||||
free (funcs);
|
||||
return fexpr;
|
||||
return error (fexpr, "unable to find function matching");
|
||||
}
|
||||
for (int i = 0; i < num_funcs; i++) {
|
||||
if (i != best_ind && costs[i] == best_cost) {
|
||||
free (funcs);
|
||||
return error (fexpr, "unable to disambiguate %s", fsym->name);
|
||||
}
|
||||
}
|
||||
|
||||
auto best = funcs[best_ind];
|
||||
if (best->meta_type == mf_overload) {
|
||||
fexpr = set_func_symbol (fexpr, best);
|
||||
}
|
||||
error (fexpr, "unable to find function matching");
|
||||
free (funcs);
|
||||
return fexpr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue