mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 21:21:14 +00:00
[qfcc] Check all generic function variants for dups
Checking only the last function to be added results in false negatives and thus duplicates when defining a generic function. eg: genFType radians (genFType degrees); genDType radians (genDType degrees); genFType radians (genFType degrees) = #0; genDType radians (genDType degrees) = #0;
This commit is contained in:
parent
c236129bbe
commit
4f5fcbd819
1 changed files with 20 additions and 15 deletions
|
@ -133,6 +133,8 @@ cmp_genparams (genfunc_t *g1, genparam_t *p1, genfunc_t *g2, genparam_t *p2)
|
||||||
void
|
void
|
||||||
add_generic_function (genfunc_t *genfunc)
|
add_generic_function (genfunc_t *genfunc)
|
||||||
{
|
{
|
||||||
|
auto name = genfunc->name;
|
||||||
|
|
||||||
for (int i = 0; i < genfunc->num_types; i++) {
|
for (int i = 0; i < genfunc->num_types; i++) {
|
||||||
auto gentype = &genfunc->types[i];
|
auto gentype = &genfunc->types[i];
|
||||||
if (gentype->compute && gentype->valid_types) {
|
if (gentype->compute && gentype->valid_types) {
|
||||||
|
@ -154,28 +156,31 @@ add_generic_function (genfunc_t *genfunc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!gen_params) {
|
if (!gen_params) {
|
||||||
internal_error (0, "%s has no generic parameters", genfunc->name);
|
internal_error (0, "%s has no generic parameters", name);
|
||||||
}
|
}
|
||||||
if (!genfunc->ret_type) {
|
if (!genfunc->ret_type) {
|
||||||
internal_error (0, "%s has no return type", genfunc->name);
|
internal_error (0, "%s has no return type", name);
|
||||||
}
|
}
|
||||||
check_generic_param (genfunc->ret_type, genfunc);
|
check_generic_param (genfunc->ret_type, genfunc);
|
||||||
|
|
||||||
bool is_new = true;
|
bool is_new = true;
|
||||||
genfunc_t *old = Hash_Find (generic_functions, genfunc->name);
|
auto old_list = (genfunc_t **) Hash_FindList (generic_functions, name);
|
||||||
if (old && old->num_params == genfunc->num_params) {
|
for (auto o = old_list; is_new && o && *o; o++) {
|
||||||
is_new = false;
|
auto old = *o;
|
||||||
for (int i = 0; i < genfunc->num_params; i++) {
|
if (old->num_params == genfunc->num_params) {
|
||||||
if (!cmp_genparams (genfunc, &genfunc->params[i],
|
is_new = false;
|
||||||
old, &old->params[i])) {
|
for (int i = 0; i < genfunc->num_params; i++) {
|
||||||
is_new = true;
|
if (!cmp_genparams (genfunc, &genfunc->params[i],
|
||||||
break;
|
old, &old->params[i])) {
|
||||||
|
is_new = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_new && !cmp_genparams (genfunc, genfunc->ret_type,
|
||||||
|
old, old->ret_type)) {
|
||||||
|
error (0, "can't overload on return types");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!is_new && !cmp_genparams (genfunc, genfunc->ret_type,
|
|
||||||
old, old->ret_type)) {
|
|
||||||
error (0, "can't overload on return types");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue