* [rfa] linespec.c: lookup_prefix_sym
@ 2003-01-15 22:26 David Carlton
2003-02-04 17:46 ` Elena Zannoni
0 siblings, 1 reply; 3+ messages in thread
From: David Carlton @ 2003-01-15 22:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Elena Zannoni
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 <carlton@math.stanford.edu>
* 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);
}
\f
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rfa] linespec.c: lookup_prefix_sym
2003-01-15 22:26 [rfa] linespec.c: lookup_prefix_sym David Carlton
@ 2003-02-04 17:46 ` Elena Zannoni
2003-02-04 21:25 ` David Carlton
0 siblings, 1 reply; 3+ messages in thread
From: Elena Zannoni @ 2003-02-04 17:46 UTC (permalink / raw)
To: David Carlton; +Cc: gdb-patches, Elena Zannoni
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 <carlton@math.stanford.edu>
>
> * 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);
> }
>
> \f
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rfa] linespec.c: lookup_prefix_sym
2003-02-04 17:46 ` Elena Zannoni
@ 2003-02-04 21:25 ` David Carlton
0 siblings, 0 replies; 3+ messages in thread
From: David Carlton @ 2003-02-04 21:25 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
On Tue, 4 Feb 2003 12:50:08 -0500, Elena Zannoni <ezannoni@redhat.com> said:
> David Carlton writes:
>> Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to commit?
> OK.
Thanks, committed.
David Carlton
carlton@math.stanford.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-02-04 21:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-15 22:26 [rfa] linespec.c: lookup_prefix_sym David Carlton
2003-02-04 17:46 ` Elena Zannoni
2003-02-04 21:25 ` David Carlton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox