From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 721 invoked by alias); 20 Sep 2008 00:19:33 -0000 Received: (qmail 711 invoked by uid 22791); 20 Sep 2008 00:19:32 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 20 Sep 2008 00:18:58 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id BF15D2A96BA; Fri, 19 Sep 2008 20:18:55 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id g+XR1b+-AMgM; Fri, 19 Sep 2008 20:18:55 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 6144C2A968A; Fri, 19 Sep 2008 20:18:55 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id AE500E7ACD; Fri, 19 Sep 2008 17:18:52 -0700 (PDT) Date: Sat, 20 Sep 2008 00:19:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: RFA: implement all missing macro expansion features Message-ID: <20080920001852.GC23372@adacore.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-09/txt/msg00428.txt.bz2 :REVIEWMAIL: > 2008-08-22 Tom Tromey > > * macrocmd.c (extract_identifier): Add is_parameter argument. > (macro_define_command): Update. > (macro_undef_command): Likewise. > * macroexp.c (stringify): New function. > (find_parameter): Likewise. > (gather_arguments): Add nargs argument. Handle varargs. > (substitute_args): Add is_varargs and va_arg_name arguments. > Handle varargs, splicing, stringification. Use find_parameter. > (expand): Handle varargs. Would anyone who is familiar with C macros like to take a look at this one too? I looked at it, and it looks fine to me. In fact, I must compliment Tom on his very nice style with lots of nice comments explaining what he does. Very nice! Tom, give it a few more days to see if we have any reaction, and then go ahead and commit (let's not count the weekend, though). > 2008-08-21 Tom Tromey > > * gdb.base/macscp.exp: Add tests for stringification, splicing, > and varargs. This is OK too. > > diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c > index 8213c0d..9a4fdee 100644 > --- a/gdb/macrocmd.c > +++ b/gdb/macrocmd.c > @@ -197,18 +197,36 @@ skip_ws (char **expp) > ++*expp; > } > > +/* Try to find the bounds of an identifier. If an identifier is > + found, returns a newly allocated string; otherwise returns NULL. > + EXPP is a pointer to an input string; it is updated to point to the > + text following the identifier. If IS_PARAMETER is true, this > + function will also allow "..." forms as used in varargs macro > + parameters. */ > static char * > -extract_identifier (char **expp) > +extract_identifier (char **expp, int is_parameter) Thanks for adding the comment describing the function. Can you add an extra empty line before the function declaration? > +/* A helper function for substitute_args. If the token TOK is the > + name of a parameter, return the parameter's index. ARGV is a > + vector of all the arguments; ARGC is the number of arguments. If > + TOK is not an argument, return -1. */ > +static int > +find_parameter (const struct macro_buffer *tok, > + int is_varargs, const struct macro_buffer *va_arg_name, > + int argc, const char * const *argv) Same here. And perhaps if you wouldn't mind describing the IS_VARARGS and VA_ARG_NAME parameters... > + /* Is this token the splicing operator? */ > + else if (tok.len == 2 > + && tok.text[0] == '#' > + && tok.text[1] == '#') > + { > + /* Just ignore a stray token splicing operator. Really this > + is an error, but there's no reason to penalize the > + user. */ > + } I don't see how this would be penalizing the user. when could this error actually happen? I assume that the compiler would reject an incorrect expression, so it would only happen when defining the macro in GDB? If it were the case, I would rather error out and tell the user to fix its expression. Or perhaps can this happen after expansion? -- Joel