Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Elena Zannoni <ezannoni@redhat.com>
To: David Carlton <carlton@math.stanford.edu>
Cc: gdb-patches@sources.redhat.com,
	Elena Zannoni <ezannoni@redhat.com>,
	Fernando Nasser <fnasser@redhat.com>
Subject: Re: [rfa] linespec.c: find_method
Date: Fri, 28 Feb 2003 03:45:00 -0000	[thread overview]
Message-ID: <15966.56408.999084.527143@localhost.redhat.com> (raw)
In-Reply-To: <ro1d6ldnu15.fsf@jackfruit.Stanford.EDU>

David Carlton writes:
 > This patch extracts a chunk of code from decode_compound into
 > a new function called find_method.  It doesn't change the code at all.
 > 
 > Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to commit?

yes
thanks
elena


 > 
 > David Carlton
 > carlton@math.stanford.edu
 > 
 > 2003-02-27  David Carlton  <carlton@math.stanford.edu>
 > 
 > 	* linespec.c (decode_compound): Extract code into find_method.
 > 	(find_method): New.
 > 
 > Index: linespec.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/linespec.c,v
 > retrieving revision 1.43
 > diff -u -p -r1.43 linespec.c
 > --- linespec.c	25 Feb 2003 21:36:18 -0000	1.43
 > +++ linespec.c	28 Feb 2003 00:10:22 -0000
 > @@ -57,6 +57,13 @@ static struct symtabs_and_lines decode_c
 >  
 >  static struct symbol *lookup_prefix_sym (char **argptr, char *p);
 >  
 > +static struct symtabs_and_lines find_method (int funfirstline,
 > +					     char ***canonical,
 > +					     char *saved_arg,
 > +					     char *copy,
 > +					     struct type *t,
 > +					     struct symbol *sym_class);
 > +
 >  static NORETURN void cplusplus_error (const char *name,
 >  				      const char *fmt, ...)
 >       ATTR_NORETURN ATTR_FORMAT (printf, 2, 3);
 > @@ -945,7 +952,6 @@ decode_compound (char **argptr, int funf
 >    struct symtab *sym_symtab;
 >    char *copy;
 >    struct symbol *sym_class;
 > -  int i1;
 >    struct symbol **sym_arr;
 >    struct type *t;
 >  
 > @@ -1037,76 +1043,8 @@ decode_compound (char **argptr, int funf
 >  	    p++;
 >  	  *argptr = p;
 >  
 > -	  sym = 0;
 > -	  i1 = 0;	/*  Counter for the symbol array.  */
 > -	  sym_arr = (struct symbol **) 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;
 > -
 > -	      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);
 > -	  if (i1 == 1)
 > -	    {
 > -	      /* There is exactly one field with that name.  */
 > -	      sym = sym_arr[0];
 > -
 > -	      if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
 > -		{
 > -		  values.sals = (struct symtab_and_line *)
 > -		    xmalloc (sizeof (struct symtab_and_line));
 > -		  values.nelts = 1;
 > -		  values.sals[0] = find_function_start_sal (sym,
 > -							    funfirstline);
 > -		}
 > -	      else
 > -		{
 > -		  values.nelts = 0;
 > -		}
 > -	      return values;
 > -	    }
 > -	  if (i1 > 0)
 > -	    {
 > -	      /* There is more than one field with that name
 > -		 (overloaded).  Ask the user which one to use.  */
 > -	      return decode_line_2 (sym_arr, i1, funfirstline, canonical);
 > -	    }
 > -	  else
 > -	    {
 > -	      char *tmp;
 > -
 > -	      if (is_operator_name (copy))
 > -		{
 > -		  tmp = (char *) alloca (strlen (copy + 3) + 9);
 > -		  strcpy (tmp, "operator ");
 > -		  strcat (tmp, copy + 3);
 > -		}
 > -	      else
 > -		tmp = copy;
 > -	      if (tmp[0] == '~')
 > -		cplusplus_error (saved_arg,
 > -				 "the class `%s' does not have destructor defined\n",
 > -				 SYMBOL_PRINT_NAME (sym_class));
 > -	      else
 > -		cplusplus_error (saved_arg,
 > -				 "the class %s does not have any method named %s\n",
 > -				 SYMBOL_PRINT_NAME (sym_class), tmp);
 > -	    }
 > +	  return find_method (funfirstline, canonical, saved_arg,
 > +			      copy, t, sym_class);
 >  	}
 >  
 >        /* Move pointer up to next possible class/namespace token.  */
 > @@ -1186,6 +1124,86 @@ lookup_prefix_sym (char **argptr, char *
 >  
 >    return lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
 >  			(struct symtab **) NULL);
 > +}
 > +
 > +/* This finds the method COPY in the class whose type is T and whose
 > +   symbol is SYM_CLASS.  */
 > +
 > +static struct symtabs_and_lines
 > +find_method (int funfirstline, char ***canonical, char *saved_arg,
 > +	     char *copy, struct type *t, struct symbol *sym_class)
 > +{
 > +  struct symtabs_and_lines values;
 > +  struct symbol *sym = 0;
 > +  int i1 = 0;	/*  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;
 > +
 > +      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);
 > +  if (i1 == 1)
 > +    {
 > +      /* There is exactly one field with that name.  */
 > +      sym = sym_arr[0];
 > +
 > +      if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
 > +	{
 > +	  values.sals = (struct symtab_and_line *)
 > +	    xmalloc (sizeof (struct symtab_and_line));
 > +	  values.nelts = 1;
 > +	  values.sals[0] = find_function_start_sal (sym,
 > +						    funfirstline);
 > +	}
 > +      else
 > +	{
 > +	  values.nelts = 0;
 > +	}
 > +      return values;
 > +    }
 > +  if (i1 > 0)
 > +    {
 > +      /* There is more than one field with that name
 > +	 (overloaded).  Ask the user which one to use.  */
 > +      return decode_line_2 (sym_arr, i1, funfirstline, canonical);
 > +    }
 > +  else
 > +    {
 > +      char *tmp;
 > +
 > +      if (is_operator_name (copy))
 > +	{
 > +	  tmp = (char *) alloca (strlen (copy + 3) + 9);
 > +	  strcpy (tmp, "operator ");
 > +	  strcat (tmp, copy + 3);
 > +	}
 > +      else
 > +	tmp = copy;
 > +      if (tmp[0] == '~')
 > +	cplusplus_error (saved_arg,
 > +			 "the class `%s' does not have destructor defined\n",
 > +			 SYMBOL_PRINT_NAME (sym_class));
 > +      else
 > +	cplusplus_error (saved_arg,
 > +			 "the class %s does not have any method named %s\n",
 > +			 SYMBOL_PRINT_NAME (sym_class), tmp);
 > +    }
 >  }
 >  
 >  \f


  reply	other threads:[~2003-02-28  3:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-28  0:11 David Carlton
2003-02-28  3:45 ` Elena Zannoni [this message]
2003-02-28 17:21   ` David Carlton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15966.56408.999084.527143@localhost.redhat.com \
    --to=ezannoni@redhat.com \
    --cc=carlton@math.stanford.edu \
    --cc=fnasser@redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox