Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@codesourcery.com>
To: gdb-patches@sources.redhat.com
Subject: [PATCH] Unary plus
Date: Wed, 09 Feb 2005 13:37:00 -0000	[thread overview]
Message-ID: <4209E2F1.2000504@codesourcery.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

Hi,
gdb doesn't parse or evaluate the unary plus operator (but does have one).
gdb.trace/collection.exp contains such an expression -- 'a[+b]'. This patch
adds the necessary parsing and evaluation machinery.

built & tested on i686-px-linux-gnu and an unreleased architecture. ok?

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk


[-- Attachment #2: unop_plus.patch --]
[-- Type: text/plain, Size: 4363 bytes --]

2005-02-09  Nathan Sidwell  <nathan@codesourcery.com>

	* ax-gdb.c (gen_expr): Add UNOP_PLUS case.
	* c-exp.y (exp): Add unary plus.
	* eval.c (evaluate_subexp_standard): Add UNOP_PLUS case.
	* valarith.c (value_pos): New.
	* value.h (value_pos): Declare.

Index: ax-gdb.c
===================================================================
RCS file: /cvs/src/src/gdb/ax-gdb.c,v
retrieving revision 1.27
diff -c -3 -p -r1.27 ax-gdb.c
*** ax-gdb.c	29 Jan 2005 17:53:25 -0000	1.27
--- ax-gdb.c	9 Feb 2005 09:55:10 -0000
*************** gen_expr (union exp_element **pc, struct
*** 1642,1647 ****
--- 1642,1654 ----
        }
        break;
  
+     case UNOP_PLUS:
+       (*pc)++;
+       /* + FOO is equivalent to 0 + FOO, which can be optimized. */
+       gen_expr (pc, ax, value);
+       gen_usual_unary (ax, value);
+       break;
+       
      case UNOP_NEG:
        (*pc)++;
        /* -FOO is equivalent to 0 - FOO.  */
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.28
diff -c -3 -p -r1.28 c-exp.y
*** c-exp.y	7 Aug 2004 19:45:45 -0000	1.28
--- c-exp.y	9 Feb 2005 09:55:11 -0000
*************** exp	:	'-' exp    %prec UNARY
*** 256,261 ****
--- 256,265 ----
  			{ write_exp_elt_opcode (UNOP_NEG); }
  	;
  
+ exp	:	'+' exp    %prec UNARY
+ 			{ write_exp_elt_opcode (UNOP_PLUS); }
+ 	;
+ 
  exp	:	'!' exp    %prec UNARY
  			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  	;
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.49
diff -c -3 -p -r1.49 eval.c
*** eval.c	7 Feb 2005 00:09:53 -0000	1.49
--- eval.c	9 Feb 2005 09:55:16 -0000
*************** evaluate_subexp_standard (struct type *e
*** 1854,1859 ****
--- 1854,1868 ----
        evaluate_subexp (NULL_TYPE, exp, pos, noside);
        return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  
+     case UNOP_PLUS:
+       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+       if (noside == EVAL_SKIP)
+ 	goto nosideret;
+       if (unop_user_defined_p (op, arg1))
+ 	return value_x_unop (arg1, op, noside);
+       else
+ 	return value_pos (arg1);
+       
      case UNOP_NEG:
        arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
        if (noside == EVAL_SKIP)
Index: valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.35
diff -c -3 -p -r1.35 valarith.c
*** valarith.c	7 Feb 2005 15:04:43 -0000	1.35
--- valarith.c	9 Feb 2005 09:55:25 -0000
*************** value_less (struct value *arg1, struct v
*** 1313,1319 ****
      }
  }
  \f
! /* The unary operators - and ~.  Both free the argument ARG1.  */
  
  struct value *
  value_neg (struct value *arg1)
--- 1313,1349 ----
      }
  }
  \f
! /* The unary operators +, - and ~.  They free the argument ARG1
!    (unless it is returned).  */
! 
! struct value *
! value_pos (struct value *arg1)
! {
!   struct type *type;
! 
!   arg1 = coerce_ref (arg1);
! 
!   type = check_typedef (value_type (arg1));
! 
!   if (TYPE_CODE (type) == TYPE_CODE_FLT)
!     return arg1;
!   else if (is_integral_type (type))
!     {
!       /* Perform integral promotion for ANSI C/C++.  FIXME: What about
!          FORTRAN and (the deleted) chill ?  */
!       if (TYPE_LENGTH (type) >= TYPE_LENGTH (builtin_type_int))
! 	return arg1;
!       
!       type = builtin_type_int;
! 
!       return value_from_longest (type, value_as_long (arg1));
!     }
!   else
!     {
!       error ("Argument to positive operation not a number.");
!       return 0;			/* For lint -- never reached */
!     }
! }
  
  struct value *
  value_neg (struct value *arg1)
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.72
diff -c -3 -p -r1.72 value.h
*** value.h	7 Feb 2005 15:04:43 -0000	1.72
--- value.h	9 Feb 2005 09:55:26 -0000
*************** extern struct value *value_addr (struct 
*** 332,337 ****
--- 332,339 ----
  extern struct value *value_assign (struct value *toval,
  				   struct value *fromval);
  
+ extern struct value *value_pos (struct value *arg1);
+ 
  extern struct value *value_neg (struct value *arg1);
  
  extern struct value *value_complement (struct value *arg1);

             reply	other threads:[~2005-02-09 10:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-09 13:37 Nathan Sidwell [this message]
2005-02-27  4:22 ` Daniel Jacobowitz
2005-03-08 10:51   ` Nathan Sidwell
2005-03-08 13:40     ` Daniel Jacobowitz

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=4209E2F1.2000504@codesourcery.com \
    --to=nathan@codesourcery.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