simplify collect_arguments() and fix error handling there

The current logics is too convoluted.  We use collect_arg() to carve
an argument out; it takes a pointer to previous token (either opening
parenthesis or comma), finds how far does the argument extend, cuts the
list at its end and returns the token that follows it (normally either
closing parenthesis or the comma).  collect_arg() is told whether we
want a vararg argument or not - the difference is that normal arguments
terminate on commas.

When macro has N non-vararg arguments and V (0 or 1) vararg ones, we want
	* N calls of collect_arg() asking for non-vararg arguments;
all but the last one must be followed by commas.  The last one may be
followed either by comma or by closing parenthesis.
	* If we have seen exactly N commas, call collect_arg() asking
to collect everything until the closing parenthesis.  That will get us
to the end of arguments.

The only potential gotcha is that there is a case when "exactly N commas"
for non-vararg macro does _not_ mean excessive arguments - N = V = 0.
Not hard to account for - in that case we must look at the chunk carved
out by the last (and only) call of collect_arg(); that would be everything
between the parentheses.  If it's empty, we are fine, otherwise we've
excessive arguments.

Rather than trying to fold all of that into a single loop, separate
the handling of non-vararg arguments from the rest; the logics becomes
simpler that way, especially around the error recovery.

As a side benefit the 'vararg' bit in struct argcount becomes unused
and can be removed.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Chris Li <sparse@chrisli.org>
2 files changed