* 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.
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.
}
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. */
{ 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); }
;
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)
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
A1 operator=(const A1&);
A1 operator~();
+A1 operator+();
A1 operator-();
int operator!();
A1 operator++();
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);
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);
val = (!one);
cout << "! " << val << endl << "-----"<<endl;
+ three = (+one);
+ cout << "+ " << three;
three = (-one);
cout << "- " << three;
three = (~one);
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}"
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
case UNOP_NEG:
strcpy (ptr, "-");
break;
+ case UNOP_PLUS:
+ strcpy (ptr, "+");
+ break;
case UNOP_IND:
strcpy (ptr, "*");
break;
}
}
\f
-/* 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)
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);