From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8267 invoked by alias); 4 Feb 2003 17:46:03 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 8260 invoked from network); 4 Feb 2003 17:46:03 -0000 Received: from unknown (HELO mx1.redhat.com) (172.16.49.200) by 172.16.49.205 with SMTP; 4 Feb 2003 17:46:03 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id h14Hk3f21420 for ; Tue, 4 Feb 2003 12:46:03 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h14Hk3a20925 for ; Tue, 4 Feb 2003 12:46:03 -0500 Received: from localhost.redhat.com (romulus-int.sfbay.redhat.com [172.16.27.46]) by pobox.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h14HjxR16285; Tue, 4 Feb 2003 12:46:00 -0500 Received: by localhost.redhat.com (Postfix, from userid 469) id 9A048FF79; Tue, 4 Feb 2003 12:50:09 -0500 (EST) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15935.64848.617116.327755@localhost.redhat.com> Date: Tue, 04 Feb 2003 17:46:00 -0000 To: David Carlton Cc: gdb-patches@sources.redhat.com, Elena Zannoni Subject: Re: [rfa] linespec.c: lookup_prefix_sym In-Reply-To: References: X-SW-Source: 2003-02/txt/msg00121.txt.bz2 David Carlton writes: > Now I'm starting to decompose decode_compound into pieces. Here's the > first one: this creates a new function lookup_prefix_sym. > > It's pretty straightforward: it doesn't change the code at all. The > only delicate issue is to make sure that decode_compound doesn't need > the values of 'p' and 'copy' after the call, since lookup_prefix_sym > changes them. The other uses of both variables lie in two situations: > if the big "if (sym_class && ...)" branch is taken, and if it isn't. > > If the branch is taken, then p is reset immediately (to either > skip_quoted (*argptr) or *argptr). And 'copy' is reset right after > that, in the code that follows the commented-out bit. (Despite the > presence of braces, that code is commented out: those braces are there > because it was originally the else clause of a commented-out > conditional.) > > And if the branch isn't taken, then p is reset immediately as well. > And the only use of copy outside the branch is right at the end of the > function, and copy is reset there as well. > > Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to commit? > OK. elena > David Carlton > carlton@math.stanford.edu > > 2003-01-15 David Carlton > > * linespec.c (decode_compound): Extract code into > lookup_prefix_sym. > (lookup_prefix_sym): New function. > > Index: linespec.c > =================================================================== > RCS file: /cvs/src/src/gdb/linespec.c,v > retrieving revision 1.38 > diff -u -p -r1.38 linespec.c > --- linespec.c 14 Jan 2003 20:48:50 -0000 1.38 > +++ linespec.c 15 Jan 2003 22:16:07 -0000 > @@ -54,6 +54,8 @@ static struct symtabs_and_lines decode_c > char *saved_arg, > char *p); > > +static struct symbol *lookup_prefix_sym (char **argptr, char *p); > + > static NORETURN void cplusplus_error (const char *name, > const char *fmt, ...) > ATTR_NORETURN ATTR_FORMAT (printf, 2, 3); > @@ -930,7 +932,7 @@ decode_compound (char **argptr, int funf > char *saved_arg, char *p) > { > struct symtabs_and_lines values; > - char *p1, *p2; > + char *p2; > #if 0 > char *q, *q1; > #endif > @@ -975,22 +977,7 @@ decode_compound (char **argptr, int funf > p2 = p; /* Save for restart. */ > while (1) > { > - /* Extract the class name. */ > - p1 = p; > - while (p != *argptr && p[-1] == ' ') > - --p; > - copy = (char *) alloca (p - *argptr + 1); > - memcpy (copy, *argptr, p - *argptr); > - copy[p - *argptr] = 0; > - > - /* Discard the class name from the arg. */ > - p = p1 + (p1[0] == ':' ? 2 : 1); > - while (*p == ' ' || *p == '\t') > - p++; > - *argptr = p; > - > - sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, > - (struct symtab **) NULL); > + sym_class = lookup_prefix_sym (argptr, p); > > if (sym_class && > (t = check_typedef (SYMBOL_TYPE (sym_class)), > @@ -1166,6 +1153,37 @@ decode_compound (char **argptr, int funf > cplusplus_error (saved_arg, > "Can't find member of namespace, class, struct, or union named \"%s\"\n", > copy); > +} > + > +/* Next come some helper functions for decode_compound. */ > + > +/* Return the symbol corresponding to the substring of *ARGPTR ending > + at P, allowing whitespace. Also, advance *ARGPTR past the symbol > + name in question, the compound object separator ("::" or "."), and > + whitespace. */ > + > +static struct symbol * > +lookup_prefix_sym (char **argptr, char *p) > +{ > + char *p1; > + char *copy; > + > + /* Extract the class name. */ > + p1 = p; > + while (p != *argptr && p[-1] == ' ') > + --p; > + copy = (char *) alloca (p - *argptr + 1); > + memcpy (copy, *argptr, p - *argptr); > + copy[p - *argptr] = 0; > + > + /* Discard the class name from the arg. */ > + p = p1 + (p1[0] == ':' ? 2 : 1); > + while (*p == ' ' || *p == '\t') > + p++; > + *argptr = p; > + > + return lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, > + (struct symtab **) NULL); > } > >