Split _find_template_match
fennecdjay opened this issue · comments
Currently the function is to big to be really maintanable.
The fix is to split the inner parts in two functions:
Name it has you see it fit. I'm proposing short names because the new functions would be static
and therefore not conflict with anything in other parts of the project.
If moving the functions implies calling them with too many arguments, consider creating a struct (on the stack, see example), a call the function with it.
struct CallHelper {
int myint;
float myfloat;
};
ANN static Func _find_template_match(const Env env, const Value v, const Exp_Call* exp) {
...
struct CallHelper ch = { .myint=1, .myfloat=2.3 };
if(is_fptr(env->gwion, v->type))
fptr_match(env, &ch);
else
func_match(env, &ch);
...
}
I hope this is clear enough. Anyway, I'll be glad to help 😄
Looking at the code, I think there a need for a structure.
at least.
As an example:
struct PeaseFindSomeMeaningfullName {
Value v; // could be const
Exp e; // could be const too
m_str tmpl_name; // could be const, too
Func m_func; // set by the cuntions, so not const
};
Also, IMHO, the function for non pointer function can be split:
one function when exists
exists (sorry), and, well the other 😄
Notice the
if((m_func = ensure_tmpl(env, fdef, exp)))
break;
is redundant.
I think that could be better written:
for(m_uint i = 0; i < v->from->offset + 1; ++i) {
const Value exists = template_get_ready(env, v, tmpl_name, i)
if(exists)
someFptrHandlingFunc( ... )
else
someFuncHandlingFunc( ... )
if((m_func = ensure_tmpl(env, fdef, exp)))
break;
}
It will make easier to make ones mind on what each piece of code does (provided we find sensible names 😄).
Hope this helps.
In the fptr part, it seems probable that Func_Def base
can be declared constant. Also, can't Func_Base *fbase
be written Func_Base *const fbase
?
I would like to work on this.
Thank you.
Are my comments any helpful?
Hi, @Pranav2612000! How is it going?