From: Nathan Sidwell Date: Tue, 8 Mar 2005 14:35:20 +0000 (+0000) Subject: * ax-gdb.c (gen_expr): Add UNOP_PLUS case. X-Git-Tag: csl-arm-20050325-branchpoint~227 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36e9969cac95317f057b47509cf63271bccd98b0;p=platform%2Fupstream%2Fbinutils.git * 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_x_unop): Add UNOP_PLUS case. (value_pos): New. * value.h (value_pos): Declare. * gdb.cp/userdef.cc (A1::operator+): New unary plus. (A2): New class. (main): Test operator+. * gdb.cp/userdef.exp: Test unary plus. Use A2::operator+ for breakpoint test. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b490267..70e4478 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2005-03-08 Nathan Sidwell + * 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_x_unop): Add UNOP_PLUS case. + (value_pos): New. + * value.h (value_pos): Declare. + * remote.c (MIN_REMOTE_PACKET_SIZE): Set to 20. (remote_fetch_registers): Allow uppercase hex when resyncing. (remote_write_bytes): Only call get_memory_write_packet_size once. diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 98d9ef5..1b0097f 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -1642,6 +1642,13 @@ gen_expr (union exp_element **pc, struct agent_expr *ax, } 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. */ diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 27d1848..1988e93 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -256,6 +256,10 @@ exp : '-' exp %prec UNARY { 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); } ; diff --git a/gdb/eval.c b/gdb/eval.c index a25ff46..98f5580 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1855,6 +1855,15 @@ evaluate_subexp_standard (struct type *expect_type, 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) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index ace5929..73f01bd 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2005-03-08 Nathan Sidwell + * gdb.cp/userdef.cc (A1::operator+): New unary plus. + (A2): New class. + (main): Test operator+. + * gdb.cp/userdef.exp: Test unary plus. Use A2::operator+ for + breakpoint test. + * gdb.base/sigbpt.exp: Disable if gdb,nosignals. * gdb.base/signull.exp: Disable if gdb,nosignals. * gdb.cp/bs15503.exp: Disable if skip_cplus_tests diff --git a/gdb/testsuite/gdb.cp/userdef.cc b/gdb/testsuite/gdb.cp/userdef.cc index a40995a..0cf2595 100644 --- a/gdb/testsuite/gdb.cp/userdef.cc +++ b/gdb/testsuite/gdb.cp/userdef.cc @@ -63,6 +63,7 @@ A1 operator/(const A1&); A1 operator=(const A1&); A1 operator~(); +A1 operator+(); A1 operator-(); int operator!(); A1 operator++(); @@ -225,6 +226,15 @@ A1 A1::operator-(void) return (neg); } +A1 A1::operator+(void) +{ + A1 pos(0,0); + pos.x = +x; + pos.y = +y; + + return (pos); +} + A1 A1::operator~(void) { A1 acompl(0,0); @@ -286,6 +296,17 @@ ostream& operator<<(ostream& outs, A1 one) return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl); } +class A2 { + public: +A2 operator+(); +}; + +A2 A2::operator+() +{ + return A2 (); +} + + int main (void) { A1 one(2,3); @@ -342,6 +363,8 @@ int main (void) val = (!one); cout << "! " << val << endl << "-----"<> 31" "\\\$\[0-9\]* = {x = 0, y = 0}" gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]" # Assumes 2's complement. So does everything... +gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}" + gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}" gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}" @@ -138,8 +140,8 @@ gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}" gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}" # Check that GDB tolerates whitespace in operator names. -gdb_test "break A1::'operator+'" ".*Breakpoint $decimal at.*" -gdb_test "break A1::'operator +'" ".*Breakpoint $decimal at.*" +gdb_test "break A2::'operator+'" ".*Breakpoint $decimal at.*" +gdb_test "break A2::'operator +'" ".*Breakpoint $decimal at.*" gdb_exit return 0 diff --git a/gdb/valarith.c b/gdb/valarith.c index 4322c44..7908900 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -560,6 +560,9 @@ value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside) case UNOP_NEG: strcpy (ptr, "-"); break; + case UNOP_PLUS: + strcpy (ptr, "+"); + break; case UNOP_IND: strcpy (ptr, "*"); break; @@ -1313,7 +1316,34 @@ value_less (struct value *arg1, struct value *arg2) } } -/* The unary operators - and ~. Both free the argument ARG1. */ +/* The unary operators +, - and ~. They free the argument ARG1. */ + +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 value_from_double (type, value_as_double (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)) + 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) diff --git a/gdb/value.h b/gdb/value.h index 6688d96..004c7d5 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -326,6 +326,8 @@ extern struct value *value_addr (struct value *arg1); 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);