Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [rfa] linespec.c: collect_methods
@ 2003-02-28 22:53 David Carlton
  2003-03-02 22:27 ` Elena Zannoni
  0 siblings, 1 reply; 3+ messages in thread
From: David Carlton @ 2003-02-28 22:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Elena Zannoni, Fernando Nasser

The latest linespec patch.  It extracts some code from find_method
into a new function collect_methods.  It doesn't change the extracted
code.

And yes, I do realize that having functions with the similar names
find_methods, find_method, and collect_methods is confusing (not to
mention having a function with a similar functionality but a different
name, namely decode_line_2); I'll rename existing functions to clarify
their roles once I'm done with extracting funcitons in this code.
(find_methods and decode_line_2 were around before I started this
project.)

Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to apply?

David Carlton
carlton@math.stanford.edu

2003-02-28  David Carlton  <carlton@math.stanford.edu>

	* linespec.c (find_method): Extract code into collect_methods.
	(collect_methods): New.

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.44
diff -u -p -r1.44 linespec.c
--- linespec.c	28 Feb 2003 17:21:16 -0000	1.44
+++ linespec.c	28 Feb 2003 22:38:34 -0000
@@ -64,6 +64,9 @@ static struct symtabs_and_lines find_met
 					     struct type *t,
 					     struct symbol *sym_class);
 
+static int collect_methods (char *copy, struct type *t,
+			    struct symbol **sym_arr);
+
 static NORETURN void cplusplus_error (const char *name,
 				      const char *fmt, ...)
      ATTR_NORETURN ATTR_FORMAT (printf, 2, 3);
@@ -1135,29 +1138,15 @@ find_method (int funfirstline, char ***c
 {
   struct symtabs_and_lines values;
   struct symbol *sym = 0;
-  int i1 = 0;	/*  Counter for the symbol array.  */
+  int i1;	/*  Counter for the symbol array.  */
   struct symbol **sym_arr =  alloca (total_number_of_methods (t)
 				     * sizeof (struct symbol *));
 
-  if (destructor_name_p (copy, t))
-    {
-      /* Destructors are a special case.  */
-      int m_index, f_index;
+  /* Find all methods with a matching name, and put them in
+     sym_arr.  */
 
-      if (get_destructor_fn_field (t, &m_index, &f_index))
-	{
-	  struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
+  i1 = collect_methods (copy, t, sym_arr);
 
-	  sym_arr[i1] =
-	    lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
-			   NULL, VAR_NAMESPACE, (int *) NULL,
-			   (struct symtab **) NULL);
-	  if (sym_arr[i1])
-	    i1++;
-	}
-    }
-  else
-    i1 = find_methods (t, copy, sym_arr);
   if (i1 == 1)
     {
       /* There is exactly one field with that name.  */
@@ -1204,6 +1193,38 @@ find_method (int funfirstline, char ***c
 			 "the class %s does not have any method named %s\n",
 			 SYMBOL_PRINT_NAME (sym_class), tmp);
     }
+}
+
+/* Find all methods named COPY in the class whose type is T, and put
+   them in SYM_ARR.  Return the number of methods found.  */
+
+static int
+collect_methods (char *copy, struct type *t,
+		 struct symbol **sym_arr)
+{
+  int i1 = 0;	/*  Counter for the symbol array.  */
+
+  if (destructor_name_p (copy, t))
+    {
+      /* Destructors are a special case.  */
+      int m_index, f_index;
+
+      if (get_destructor_fn_field (t, &m_index, &f_index))
+	{
+	  struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
+
+	  sym_arr[i1] =
+	    lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
+			   NULL, VAR_NAMESPACE, (int *) NULL,
+			   (struct symtab **) NULL);
+	  if (sym_arr[i1])
+	    i1++;
+	}
+    }
+  else
+    i1 = find_methods (t, copy, sym_arr);
+
+  return i1;
 }
 
 \f


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfa] linespec.c: collect_methods
  2003-02-28 22:53 [rfa] linespec.c: collect_methods David Carlton
@ 2003-03-02 22:27 ` Elena Zannoni
  2003-03-03 17:22   ` David Carlton
  0 siblings, 1 reply; 3+ messages in thread
From: Elena Zannoni @ 2003-03-02 22:27 UTC (permalink / raw)
  To: David Carlton; +Cc: gdb-patches, Elena Zannoni, Fernando Nasser

David Carlton writes:
 > The latest linespec patch.  It extracts some code from find_method
 > into a new function collect_methods.  It doesn't change the extracted
 > code.
 > 
 > And yes, I do realize that having functions with the similar names
 > find_methods, find_method, and collect_methods is confusing (not to
 > mention having a function with a similar functionality but a different
 > name, namely decode_line_2); I'll rename existing functions to clarify
 > their roles once I'm done with extracting funcitons in this code.
 > (find_methods and decode_line_2 were around before I started this
 > project.)
 > 
 > Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to apply?
 > 

yes
elena


 > David Carlton
 > carlton@math.stanford.edu
 > 
 > 2003-02-28  David Carlton  <carlton@math.stanford.edu>
 > 
 > 	* linespec.c (find_method): Extract code into collect_methods.
 > 	(collect_methods): New.
 > 
 > Index: linespec.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/linespec.c,v
 > retrieving revision 1.44
 > diff -u -p -r1.44 linespec.c
 > --- linespec.c	28 Feb 2003 17:21:16 -0000	1.44
 > +++ linespec.c	28 Feb 2003 22:38:34 -0000
 > @@ -64,6 +64,9 @@ static struct symtabs_and_lines find_met
 >  					     struct type *t,
 >  					     struct symbol *sym_class);
 >  
 > +static int collect_methods (char *copy, struct type *t,
 > +			    struct symbol **sym_arr);
 > +
 >  static NORETURN void cplusplus_error (const char *name,
 >  				      const char *fmt, ...)
 >       ATTR_NORETURN ATTR_FORMAT (printf, 2, 3);
 > @@ -1135,29 +1138,15 @@ find_method (int funfirstline, char ***c
 >  {
 >    struct symtabs_and_lines values;
 >    struct symbol *sym = 0;
 > -  int i1 = 0;	/*  Counter for the symbol array.  */
 > +  int i1;	/*  Counter for the symbol array.  */
 >    struct symbol **sym_arr =  alloca (total_number_of_methods (t)
 >  				     * sizeof (struct symbol *));
 >  
 > -  if (destructor_name_p (copy, t))
 > -    {
 > -      /* Destructors are a special case.  */
 > -      int m_index, f_index;
 > +  /* Find all methods with a matching name, and put them in
 > +     sym_arr.  */
 >  
 > -      if (get_destructor_fn_field (t, &m_index, &f_index))
 > -	{
 > -	  struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
 > +  i1 = collect_methods (copy, t, sym_arr);
 >  
 > -	  sym_arr[i1] =
 > -	    lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
 > -			   NULL, VAR_NAMESPACE, (int *) NULL,
 > -			   (struct symtab **) NULL);
 > -	  if (sym_arr[i1])
 > -	    i1++;
 > -	}
 > -    }
 > -  else
 > -    i1 = find_methods (t, copy, sym_arr);
 >    if (i1 == 1)
 >      {
 >        /* There is exactly one field with that name.  */
 > @@ -1204,6 +1193,38 @@ find_method (int funfirstline, char ***c
 >  			 "the class %s does not have any method named %s\n",
 >  			 SYMBOL_PRINT_NAME (sym_class), tmp);
 >      }
 > +}
 > +
 > +/* Find all methods named COPY in the class whose type is T, and put
 > +   them in SYM_ARR.  Return the number of methods found.  */
 > +
 > +static int
 > +collect_methods (char *copy, struct type *t,
 > +		 struct symbol **sym_arr)
 > +{
 > +  int i1 = 0;	/*  Counter for the symbol array.  */
 > +
 > +  if (destructor_name_p (copy, t))
 > +    {
 > +      /* Destructors are a special case.  */
 > +      int m_index, f_index;
 > +
 > +      if (get_destructor_fn_field (t, &m_index, &f_index))
 > +	{
 > +	  struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
 > +
 > +	  sym_arr[i1] =
 > +	    lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
 > +			   NULL, VAR_NAMESPACE, (int *) NULL,
 > +			   (struct symtab **) NULL);
 > +	  if (sym_arr[i1])
 > +	    i1++;
 > +	}
 > +    }
 > +  else
 > +    i1 = find_methods (t, copy, sym_arr);
 > +
 > +  return i1;
 >  }
 >  
 >  \f


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfa] linespec.c: collect_methods
  2003-03-02 22:27 ` Elena Zannoni
@ 2003-03-03 17:22   ` David Carlton
  0 siblings, 0 replies; 3+ messages in thread
From: David Carlton @ 2003-03-03 17:22 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches, Fernando Nasser

On Sun, 2 Mar 2003 17:31:37 -0500, Elena Zannoni <ezannoni@redhat.com> said:

>> Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to apply?

> yes

Thanks, committed.

David Carlton
carlton@math.stanford.edu


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-03-03 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-28 22:53 [rfa] linespec.c: collect_methods David Carlton
2003-03-02 22:27 ` Elena Zannoni
2003-03-03 17:22   ` David Carlton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox