[split-by-name] should not match #define macros
Closed this issue · 3 comments
There is a deeper issue here and this particular line should never have been matched in the first place.
The reason this is matched, is that further down below this line, there's an actual function with an opening brace ({
), and this #define
is being matched all the way down to that brace- which coincidentally cause the real function to be missed, as it would otherwise overlap. See #50 for similar.
Here's the actual code:
#define YouMessage(pointer, prefix, text) \
strcat((YouPrefix(pointer, prefix, text), pointer), text)
/*VARARGS1*/
void You
VA_DECL(const char *, line)
{
char *tmp;
VA_START(line);
VA_INIT(line, const char *);
vpline(YouMessage(tmp, "You ", line), VA_ARGS);
VA_END();
}
This is what is matched as one function implementation:
#define YouMessage(pointer, prefix, text) \
strcat((YouPrefix(pointer, prefix, text), pointer), text)
/*VARARGS1*/
void You
VA_DECL(const char *, line)
{
One way to improve on this is to apply something similar to what we did in the brace-statement-bodies
rule with finding balance of braces:
comply/comply/rules/standard/brace_statement_bodies.py
Lines 50 to 62 in c93a5eb
So we would find what we expect to be a function implementation, then going by the first opening paren we roll on until determining that we hit the closing paren. From this point we can then determine whether what follows is as expected (a {
), or not. If not, discard this match.
This is going into AST territory, but I think doing this would be beneficial for a lot of rules. It could be lazily-loaded in the CheckFile
like other properties already are.
Aside:
If we could improve on function matching, and eventually maybe even get rid of using collapsed
to strip function bodies, we could gain a nice speedup, as that is currently the time hog.