* 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.
This commit is contained in:
Nathan Sidwell 2005-03-08 14:35:20 +00:00
parent 3de11b2ef2
commit 36e9969cac
9 changed files with 93 additions and 3 deletions

View File

@ -1,5 +1,12 @@
2005-03-08 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_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.

View File

@ -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. */

View File

@ -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); }
;

View File

@ -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)

View File

@ -1,5 +1,11 @@
2005-03-08 Nathan Sidwell <nathan@codesourcery.com>
* 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

View File

@ -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 << "-----"<<endl;
three = (+one);
cout << "+ " << three;
three = (-one);
cout << "- " << three;
three = (~one);

View File

@ -121,6 +121,8 @@ gdb_test "print one >> 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

View File

@ -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)

View File

@ -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);