cp-tree.def (UNARY_PLUS_EXPR): New C++ unary tree code.
authorRoger Sayle <roger@eyesopen.com>
Fri, 27 May 2005 23:17:21 +0000 (23:17 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Fri, 27 May 2005 23:17:21 +0000 (23:17 +0000)
* cp-tree.def (UNARY_PLUS_EXPR): New C++ unary tree code.
* parser.c (cp_parser_unary_expression): Use UNARY_PLUS_EXPR instead
of CONVERT_EXPR.
(cp_parser_unary_expression): Likewise.
* typeck.c (build_unary_op): Likewise.
* call.c (add_builtin_candidate, build_new_op): Likewise.
* error.c (dump_expr): Likewise.
* pt.c (tsubst_copy, tsubst_copy_and_build): Likewise.
* decl.c (ambi_op_p, grok_op_properties): Likewise.
* dump.c (dump_op): Likewise.
* lex.c (init_operators): Likewise.
* operators.def ("+"): Likewise.
* cp-gimplify.c (cp_gimplify_expr): Handle UNARY_PLUS_EXPR like a
conversion, if the result and argument types differ.
* tree.c (fold_if_not_in_template): Fold UNARY_PLUS_EXPR much
like a NOP_EXPR when !processing_template_decl.

* cxx-pretty-print.c (pp_cxx_cast_expression): Prototype.
(pp_cxx_unary_expression): Handle new UNARY_PLUS_EXPR tree code.

Co-Authored-By: Giovanni Bajo <giovannibajo@gcc.gnu.org>
From-SVN: r100285

14 files changed:
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-gimplify.c
gcc/cp/cp-tree.def
gcc/cp/cxx-pretty-print.c
gcc/cp/decl.c
gcc/cp/dump.c
gcc/cp/error.c
gcc/cp/lex.c
gcc/cp/operators.def
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/tree.c
gcc/cp/typeck.c

index 5d70567db7cc89fa58930d7cefa229924a247da1..29bd60037f501ffab3deeae7701596c550f60f88 100644 (file)
@@ -1,3 +1,26 @@
+2005-05-27  Roger Sayle  <roger@eyesopen.com>
+           Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       * cp-tree.def (UNARY_PLUS_EXPR): New C++ unary tree code.
+       * parser.c (cp_parser_unary_expression): Use UNARY_PLUS_EXPR instead
+       of CONVERT_EXPR.
+       (cp_parser_unary_expression): Likewise.
+       * typeck.c (build_unary_op): Likewise.
+       * call.c (add_builtin_candidate, build_new_op): Likewise.
+       * error.c (dump_expr): Likewise.
+       * pt.c (tsubst_copy, tsubst_copy_and_build): Likewise.
+       * decl.c (ambi_op_p, grok_op_properties): Likewise.
+       * dump.c (dump_op): Likewise.
+       * lex.c (init_operators): Likewise.
+       * operators.def ("+"): Likewise.
+       * cp-gimplify.c (cp_gimplify_expr): Handle UNARY_PLUS_EXPR like a
+       conversion, if the result and argument types differ.
+       * tree.c (fold_if_not_in_template): Fold UNARY_PLUS_EXPR much
+       like a NOP_EXPR when !processing_template_decl.
+
+       * cxx-pretty-print.c (pp_cxx_cast_expression): Prototype.
+       (pp_cxx_unary_expression): Handle new UNARY_PLUS_EXPR tree code.
+
 2005-05-27  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/21455
index e9fdc6fa6c4d7cda1e8b4497581dcea353528055..01d4046e0bf069da6f220fc802ca90e52f696556 100644 (file)
@@ -1652,7 +1652,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
             T       operator+(T);
             T       operator-(T);  */
 
-    case CONVERT_EXPR: /* unary + */
+    case UNARY_PLUS_EXPR: /* unary + */
       if (TREE_CODE (type1) == POINTER_TYPE)
        break;
     case NEGATE_EXPR:
@@ -3848,7 +3848,7 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
     case TRUTH_ORIF_EXPR:
       return cp_build_binary_op (code, arg1, arg2);
 
-    case CONVERT_EXPR:
+    case UNARY_PLUS_EXPR:
     case NEGATE_EXPR:
     case BIT_NOT_EXPR:
     case TRUTH_NOT_EXPR:
index fc8c1af2d21422c986f2c9289a4ab1a7c7a666c9..4ad30b98008c7d16450e0650041f63ea4690466c 100644 (file)
@@ -557,6 +557,16 @@ cp_gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p)
       ret = GS_OK;
       break;
 
+    case UNARY_PLUS_EXPR:
+      {
+       tree arg = TREE_OPERAND (*expr_p, 0);
+       tree type = TREE_TYPE (*expr_p);
+       *expr_p = (TREE_TYPE (arg) != type) ? fold_convert (type, arg)
+                                           : arg;
+       ret = GS_OK;
+      }
+      break;
+
     default:
       ret = c_gimplify_expr (expr_p, pre_p, post_p);
       break;
index 705517a2e4a88a9a22a558e1deed1c6f103b19fe..c42dbfbf7c016fec113cffd44ff1f6b22007d47e 100644 (file)
@@ -340,6 +340,10 @@ DEFTREECODE (ALIGNOF_EXPR, "alignof_expr", tcc_unary, 1)
    STMT_EXPR_STMT is the statement given by the expression.  */
 DEFTREECODE (STMT_EXPR, "stmt_expr", tcc_expression, 1)
 
+/* Unary plus. Operand 0 is the expression to which the unary plus
+   is applied.  */
+DEFTREECODE (UNARY_PLUS_EXPR, "unary_plus_expr", tcc_unary, 1)
+
 /*
 Local variables:
 mode:c
index 0ad1e9a4025799be82577da38b1c348449223283..afa969f9f710f4d4ef4e7737622ba14cfced958c 100644 (file)
@@ -43,6 +43,7 @@ static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
 static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
 static void pp_cxx_statement (cxx_pretty_printer *, tree);
 static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
+static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
 \f
 
 static inline void
@@ -640,6 +641,11 @@ pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
        pp_unary_expression (pp, TREE_OPERAND (t, 0));
       break;
 
+    case UNARY_PLUS_EXPR:
+      pp_plus (pp);
+      pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
+      break;
+
     default:
       pp_c_unary_expression (pp_c_base (pp), t);
       break;
index d3544172bc4cdac038f0b41099c708aedac3ad49..7f919d5c99b2bf4872d64e1c6ff9199394db2a4a 100644 (file)
@@ -8586,7 +8586,7 @@ ambi_op_p (enum tree_code code)
 {
   return (code == INDIRECT_REF
          || code == ADDR_EXPR
-         || code == CONVERT_EXPR
+         || code == UNARY_PLUS_EXPR
          || code == NEGATE_EXPR
          || code == PREINCREMENT_EXPR
          || code == PREDECREMENT_EXPR);
@@ -8806,7 +8806,7 @@ grok_op_properties (tree decl, int friendp, bool complain)
                  operator_code = BIT_AND_EXPR;
                  break;
 
-               case CONVERT_EXPR:
+               case UNARY_PLUS_EXPR:
                  operator_code = PLUS_EXPR;
                  break;
 
index 6b93045e02f0ff2cafab06dc0d0f0da15ff766bb..daf55952c537058efedcdb06c3c2a78775f9bab7 100644 (file)
@@ -65,7 +65,7 @@ dump_op (dump_info_p di, tree t)
     case VEC_DELETE_EXPR:
       dump_string (di, "vecdelete");
       break;
-    case CONVERT_EXPR:
+    case UNARY_PLUS_EXPR:
       dump_string (di, "pos");
       break;
     case NEGATE_EXPR:
index 1748fe0aa69cee052f1d5654df01bdaad051498e..8eab229269675be69c23c62a482dba14eb52e159 100644 (file)
@@ -1511,7 +1511,7 @@ dump_expr (tree t, int flags)
       pp_cxx_right_bracket (cxx_pp);
       break;
 
-    case CONVERT_EXPR:
+    case UNARY_PLUS_EXPR:
       if (TREE_TYPE (t) && VOID_TYPE_P (TREE_TYPE (t)))
        {
          pp_cxx_left_paren (cxx_pp);
index 21fe2a135817f8665603c10985c385c6b5238f73..7e891860306e8bc8b77784cfaa85825d4ab821c1 100644 (file)
@@ -145,7 +145,7 @@ init_operators (void)
   operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
   operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
   operator_name_info [(int) RANGE_EXPR].name = "...";
-  operator_name_info [(int) CONVERT_EXPR].name = "+";
+  operator_name_info [(int) UNARY_PLUS_EXPR].name = "+";
 
   assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
     = "(exact /=)";
index 16e603d31bfe856ab5731f242be6286ec07461f5..19c1b6f9c70dab18e0ff54acc071fda3e8a843c8 100644 (file)
@@ -84,7 +84,7 @@ DEF_SIMPLE_OPERATOR ("delete", DELETE_EXPR, "dl", -1)
 DEF_SIMPLE_OPERATOR ("delete []", VEC_DELETE_EXPR, "da", -1)
 
 /* Unary operators.  */
-DEF_SIMPLE_OPERATOR ("+", CONVERT_EXPR, "ps", 1)
+DEF_SIMPLE_OPERATOR ("+", UNARY_PLUS_EXPR, "ps", 1)
 DEF_SIMPLE_OPERATOR ("-", NEGATE_EXPR, "ng", 1)
 DEF_SIMPLE_OPERATOR ("&", ADDR_EXPR, "ad", 1)
 DEF_SIMPLE_OPERATOR ("*", INDIRECT_REF, "de", 1)
index 7f39c91a95a1e7af4fd16b42d125107caaae78a5..27c1751cb02afce13f0a80a43202dd2809643c51 100644 (file)
@@ -4873,7 +4873,7 @@ cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p)
          non_constant_p = (unary_operator == PREINCREMENT_EXPR
                            ? "`++'" : "`--'");
          /* Fall through.  */
-       case CONVERT_EXPR:
+       case UNARY_PLUS_EXPR:
        case NEGATE_EXPR:
        case TRUTH_NOT_EXPR:
          expression = finish_unary_op_expr (unary_operator, cast_expression);
@@ -4909,7 +4909,7 @@ cp_parser_unary_operator (cp_token* token)
       return ADDR_EXPR;
 
     case CPP_PLUS:
-      return CONVERT_EXPR;
+      return UNARY_PLUS_EXPR;
 
     case CPP_MINUS:
       return NEGATE_EXPR;
index dd18567d641aa82eff41c3eca3a6cf73ecd55d12..8a0a430add26b789f1a58f6aa24cbc49fd6c814d 100644 (file)
@@ -7784,7 +7784,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     case TRUTH_NOT_EXPR:
     case BIT_NOT_EXPR:
     case ADDR_EXPR:
-    case CONVERT_EXPR:      /* Unary + */
+    case UNARY_PLUS_EXPR:      /* Unary + */
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
     case ARROW_EXPR:
@@ -8465,7 +8465,7 @@ tsubst_copy_and_build (tree t,
     case BIT_NOT_EXPR:
     case ABS_EXPR:
     case TRUTH_NOT_EXPR:
-    case CONVERT_EXPR:  /* Unary + */
+    case UNARY_PLUS_EXPR:  /* Unary + */
     case REALPART_EXPR:
     case IMAGPART_EXPR:
       return build_x_unary_op (TREE_CODE (t), RECUR (TREE_OPERAND (t, 0)));
index 64a5aa5bd258f49852611e1b33ff95f695712f6c..8ef383c30eeaf8f890120568f383b18837787293 100644 (file)
@@ -2268,7 +2268,14 @@ fold_if_not_in_template (tree expr)
      "fold".  We will call fold later when actually instantiating the
      template.  Integral constant expressions in templates will be
      evaluated via fold_non_dependent_expr, as necessary.  */
-  return (processing_template_decl ? expr : fold (expr));
+  if (processing_template_decl)
+    return expr;
+
+  /* Fold C++ front-end specific tree codes.  */
+  if (TREE_CODE (expr) == UNARY_PLUS_EXPR)
+    return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0));
+
+  return fold (expr);
 }
 
 \f
index 92bbc1e071c2941e2cc430291828e404ee2755bf..464b8efd3fa2dd6854f02bc88f74f196508801b7 100644 (file)
@@ -3692,13 +3692,12 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert)
 
   switch (code)
     {
-    /* CONVERT_EXPR stands for unary plus in this context.  */
-    case CONVERT_EXPR:
+    case UNARY_PLUS_EXPR:
     case NEGATE_EXPR:
       {
        int flags = WANT_ARITH | WANT_ENUM;
        /* Unary plus (but not unary minus) is allowed on pointers.  */
-       if (code == CONVERT_EXPR)
+       if (code == UNARY_PLUS_EXPR)
          flags |= WANT_POINTER;
        arg = build_expr_type_conversion (flags, arg, true);
        if (!arg)