From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5197 invoked by alias); 15 Nov 2002 21:42:12 -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 5190 invoked from network); 15 Nov 2002 21:42:09 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 15 Nov 2002 21:42:09 -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 gAFLIhw03309 for ; Fri, 15 Nov 2002 16:18:43 -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 gAFLg8D31875 for ; Fri, 15 Nov 2002 16:42:08 -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 gAFLg7q02688 for ; Fri, 15 Nov 2002 16:42:07 -0500 Received: by localhost.redhat.com (Postfix, from userid 469) id 59C14FF79; Fri, 15 Nov 2002 16:35:17 -0500 (EST) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15829.26773.104270.579273@localhost.redhat.com> Date: Fri, 15 Nov 2002 13:42:00 -0000 To: David Carlton Cc: gdb-patches@sources.redhat.com Subject: Re: [rfa] linespec.c, part 4 In-Reply-To: References: X-SW-Source: 2002-11/txt/msg00427.txt.bz2 David Carlton writes: > Here's the next part: pulling out code to make the function > locate_first_half. Some comments: > > * This code modifies the variables 'p' and 'is_quote_enclosed'. I > decided to treat those asymmetrically: it returns the new value for > p, whereas it passes is_quote_enclosed by reference. Basically, I'm > expressing the opinion that this code is "really" calculating p, and > the fact that it also is convenient to set the flag > is_quote_enclosed here is kind of an accident. As Elena commented, > we'll probably eventually want to move is_quote_enclosed up to > set_flags anyways. > yes > * The code that I extracted initialized 's' to NULL, but didn't touch > s otherwise; I moved that initialization up to the declaration of s > inside decode_line_1 instead. > yes > * The code refers to 'p1', which is also referred to elsewhere in > decode_line_1. But it's not to hard to check that the other uses of > p1 are unrelated to its use here. > ok thanks. Check it in. Elena > David Carlton > carlton@math.stanford.edu > > 2002-11-12 David Carlton > > * linespec.c (locate_first_half): New function. > (decode_line_1): Move code into locate_first_half. > > Index: linespec.c > =================================================================== > RCS file: /cvs/src/src/gdb/linespec.c,v > retrieving revision 1.28 > diff -u -p -r1.28 linespec.c > --- linespec.c 11 Nov 2002 23:20:07 -0000 1.28 > +++ linespec.c 12 Nov 2002 22:01:48 -0000 > @@ -46,6 +46,8 @@ static void set_flags (char *arg, int *i > > static struct symtabs_and_lines decode_indirect (char **argptr); > > +static char *locate_first_half (char **argptr, int *is_quote_enclosed); > + > static void cplusplus_error (const char *name, const char *fmt, ...) ATTR_FORMAT (printf, 2, 3); > > static int total_number_of_methods (struct type *type); > @@ -530,11 +532,11 @@ decode_line_1 (char **argptr, int funfir > struct symtabs_and_lines values; > struct symtab_and_line val; > register char *p, *p1; > - char *q, *ii, *p2; > + char *q, *p2; > #if 0 > char *q1; > #endif > - register struct symtab *s; > + register struct symtab *s = NULL; > > register struct symbol *sym; > /* The symtab that SYM was found in. */ > @@ -550,8 +552,8 @@ decode_line_1 (char **argptr, int funfir > /* This says whether or not something in *ARGPTR is quoted with > completer_quotes (i.e. with single quotes). */ > int is_quoted; > + /* Is part of *ARGPTR is enclosed in double quotes? */ > int is_quote_enclosed; > - int has_comma = 0; > struct symbol **sym_arr; > struct type *t; > char *saved_arg = *argptr; > @@ -576,84 +578,14 @@ decode_line_1 (char **argptr, int funfir > > set_flags (*argptr, &is_quoted, &paren_pointer); > > - /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM > - and we must isolate the first half. Outer layers will call again later > - for the second half. > + /* Check to see if it's a multipart linespec (with colons or > + periods). */ > > - Don't count commas that appear in argument lists of overloaded > - functions, or in quoted strings. It's stupid to go to this much > - trouble when the rest of the function is such an obvious roach hotel. */ > - ii = find_toplevel_char (*argptr, ','); > - has_comma = (ii != 0); > + /* Locate the end of the first half of the linespec. */ > > - /* Temporarily zap out second half to not > - * confuse the code below. > - * This is undone below. Do not change ii!! > - */ > - if (has_comma) > - { > - *ii = '\0'; > - } > + p = locate_first_half (argptr, &is_quote_enclosed); > > - /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ > - /* May also be CLASS::MEMBER, or NAMESPACE::NAME */ > - /* Look for ':', but ignore inside of <> */ > - > - s = NULL; > - p = *argptr; > - if (p[0] == '"') > - { > - is_quote_enclosed = 1; > - (*argptr)++; > - p++; > - } > - else > - is_quote_enclosed = 0; > - for (; *p; p++) > - { > - if (p[0] == '<') > - { > - char *temp_end = find_template_name_end (p); > - if (!temp_end) > - error ("malformed template specification in command"); > - p = temp_end; > - } > - /* Check for the end of the first half of the linespec. End of line, > - a tab, a double colon or the last single colon, or a space. But > - if enclosed in double quotes we do not break on enclosed spaces */ > - if (!*p > - || p[0] == '\t' > - || ((p[0] == ':') > - && ((p[1] == ':') || (strchr (p + 1, ':') == NULL))) > - || ((p[0] == ' ') && !is_quote_enclosed)) > - break; > - if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */ > - { > - /* Find the *last* '.', since the others are package qualifiers. */ > - for (p1 = p; *p1; p1++) > - { > - if (*p1 == '.') > - p = p1; > - } > - break; > - } > - } > - while (p[0] == ' ' || p[0] == '\t') > - p++; > - > - /* if the closing double quote was left at the end, remove it */ > - if (is_quote_enclosed) > - { > - char *closing_quote = strchr (p - 1, '"'); > - if (closing_quote && closing_quote[1] == '\0') > - *closing_quote = '\0'; > - } > - > - /* Now that we've safely parsed the first half, > - * put back ',' so outer layers can see it > - */ > - if (has_comma) > - *ii = ','; > + /* Does it look like there actually were two parts? */ > > if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL) > { > @@ -1251,6 +1183,101 @@ decode_indirect (char **argptr) > values.sals[0].section = find_pc_overlay (pc); > > return values; > +} > + > + > + > +/* Locate the first half of the linespec, ending in a colon, period, > + or whitespace. (More or less.) Also, check to see if *ARGPTR is > + enclosed in double quotes; if so, set is_quote_enclosed, advance > + ARGPTR past that and zero out the trailing double quote. */ > + > +static char * > +locate_first_half (char **argptr, int *is_quote_enclosed) > +{ > + char *ii; > + char *p, *p1; > + int has_comma; > + > + /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM > + and we must isolate the first half. Outer layers will call again later > + for the second half. > + > + Don't count commas that appear in argument lists of overloaded > + functions, or in quoted strings. It's stupid to go to this much > + trouble when the rest of the function is such an obvious roach hotel. */ > + ii = find_toplevel_char (*argptr, ','); > + has_comma = (ii != 0); > + > + /* Temporarily zap out second half to not > + * confuse the code below. > + * This is undone below. Do not change ii!! > + */ > + if (has_comma) > + { > + *ii = '\0'; > + } > + > + /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ > + /* May also be CLASS::MEMBER, or NAMESPACE::NAME */ > + /* Look for ':', but ignore inside of <> */ > + > + p = *argptr; > + if (p[0] == '"') > + { > + *is_quote_enclosed = 1; > + (*argptr)++; > + p++; > + } > + else > + *is_quote_enclosed = 0; > + for (; *p; p++) > + { > + if (p[0] == '<') > + { > + char *temp_end = find_template_name_end (p); > + if (!temp_end) > + error ("malformed template specification in command"); > + p = temp_end; > + } > + /* Check for the end of the first half of the linespec. End of line, > + a tab, a double colon or the last single colon, or a space. But > + if enclosed in double quotes we do not break on enclosed spaces */ > + if (!*p > + || p[0] == '\t' > + || ((p[0] == ':') > + && ((p[1] == ':') || (strchr (p + 1, ':') == NULL))) > + || ((p[0] == ' ') && !*is_quote_enclosed)) > + break; > + if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */ > + { > + /* Find the *last* '.', since the others are package qualifiers. */ > + for (p1 = p; *p1; p1++) > + { > + if (*p1 == '.') > + p = p1; > + } > + break; > + } > + } > + while (p[0] == ' ' || p[0] == '\t') > + p++; > + > + /* if the closing double quote was left at the end, remove it */ > + if (*is_quote_enclosed) > + { > + char *closing_quote = strchr (p - 1, '"'); > + if (closing_quote && closing_quote[1] == '\0') > + *closing_quote = '\0'; > + } > + > + /* Now that we've safely parsed the first half, > + * put back ',' so outer layers can see it > + */ > + if (has_comma) > + *ii = ','; > + > + return p; > } > >