From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2385 invoked by alias); 15 Jan 2003 22:26:49 -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 2376 invoked from network); 15 Jan 2003 22:26:48 -0000 Received: from unknown (HELO jackfruit.Stanford.EDU) (171.64.38.136) by sources.redhat.com with SMTP; 15 Jan 2003 22:26:48 -0000 Received: (from carlton@localhost) by jackfruit.Stanford.EDU (8.11.6/8.11.6) id h0FMQia19064; Wed, 15 Jan 2003 14:26:44 -0800 X-Authentication-Warning: jackfruit.Stanford.EDU: carlton set sender to carlton@math.stanford.edu using -f To: gdb-patches@sources.redhat.com Cc: Elena Zannoni Subject: [rfa] linespec.c: lookup_prefix_sym From: David Carlton Date: Wed, 15 Jan 2003 22:26:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-01/txt/msg00586.txt.bz2 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? 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); }