2005-02-09 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_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 **** } } ! /* The unary operators - and ~. Both free the argument ARG1. */ struct value * value_neg (struct value *arg1) --- 1313,1349 ---- } } ! /* 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);