scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit a8cd756a8912fe2a544d67110ecbdb28a343bc95
parent 079f3c6e917203d8d5a2043182927231c60ea231
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 28 May 2022 12:29:09 +0200

cc1: Accept empty parameters in macros

A macro accepting a parameter can be instantiated without
anything between the parenthesis, because in that case it
receives an empty parameter. We have to differentiate that
case from the case that acutally has no parameter.

As this patch modifies the behaviour and ahead() is not called
always befor calling parameter() we have to explicit trim
spaces at the beginning of the parameters.

Diffstat:
Msrc/cmd/cc/cc1/cpp.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c @@ -128,6 +128,8 @@ parameter(Macro *mp) end = input->begin - 1; while (end > begin && isspace(end[-1])) --end; + while (begin < end && isspace(begin[0])) + ++begin; siz = end - begin; s = memcpy(xmalloc(siz+1), begin, siz); @@ -153,7 +155,8 @@ parsepars(Macro *mp) disexpand = 1; next(); n = 0; - if (ahead() == ')') { + + if (mp->npars == 0 && ahead() == ')') { next(); } else { do { @@ -161,6 +164,7 @@ parsepars(Macro *mp) mp->arglist[n] = parameter(mp); } while (++n < NR_MACROARG && yytoken == ','); } + if (yytoken != ')') error("incorrect macro function-alike invocation"); disexpand = 0;