This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH RFA: Move some more tree codes into the C++ frontend


The tree codes SIZEOF_EXPR, ARROW_EXPR, and ALIGNOF_EXPR are not used
by the C frontend.  They exist only to be used in C++ templates.  This
simple patch moves them from the shared c-common.def into the C++
specific cp/cp-tree.def.

Tested with bootstrap and testsuite run on i686-pc-linux-gnu.

OK for mainline?

Ian


ChangeLog:
2005-04-16  Ian Lance Taylor  <ian@airs.com>

	* c-common.def (SIZEOF_EXPR, ARROW_EXPR, ALIGNOF_EXPR): Remove.
	* c-common.c (c_sizeof_or_alignof_type): Change second parameter
	from enum tree_code op to bool is_sizeof.
	* c-common.h (c_sizeof_or_alignof_type): Update declaration.
	(c_sizeof, c_alignof): Update calls to c_sizeof_or_alignof_type.
	* c-pretty-print.c (pp_c_postfix_expression): Remove ARROW_EXPR
	case.
	(pp_c_unary_expression): Remove SIZEOF_EXPR and ALIGNOF_EXPR
	cases.
	(pp_c_expression): Remove ARROW_EXPR, SIZEOF_EXPR, and
	ALIGNOF_EXPR cases.

cp/ChangeLog:
2005-04-16  Ian Lance Taylor  <ian@airs.com>

	* cp-tree.def: Add SIZEOF_EXPR, ARROW_EXPR and ALIGNOF_EXPR.
	* cxx-pretty-print.c (pp_cxx_postfix_expression): Handle
	ARROW_EXPR.
	(pp_cxx_unary_expression): Handle SIZEOF_EXPR and ALIGNOF_EXPR.
	(pp_cxx_expression): Handle ARROW_EXPR, SIZEOF_EXPR, and
	ALIGNOF_EXPR.
	* typeck.c (cxx_sizeof_or_alignof_type): Update call to
	c_sizeof_or_alignof_type for change in parameter type.


Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.622
diff -p -u -r1.622 c-common.c
--- c-common.c	14 Apr 2005 23:37:31 -0000	1.622
+++ c-common.c	16 Apr 2005 20:24:41 -0000
@@ -2786,19 +2786,19 @@ c_common_get_alias_set (tree t)
    second parameter indicates which OPERATOR is being applied.  The COMPLAIN
    flag controls whether we should diagnose possibly ill-formed
    constructs or not.  */
+
 tree
-c_sizeof_or_alignof_type (tree type, enum tree_code op, int complain)
+c_sizeof_or_alignof_type (tree type, bool is_sizeof, int complain)
 {
   const char *op_name;
   tree value = NULL;
   enum tree_code type_code = TREE_CODE (type);
 
-  gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
-  op_name = op == SIZEOF_EXPR ? "sizeof" : "__alignof__";
+  op_name = is_sizeof ? "sizeof" : "__alignof__";
 
   if (type_code == FUNCTION_TYPE)
     {
-      if (op == SIZEOF_EXPR)
+      if (is_sizeof)
 	{
 	  if (complain && (pedantic || warn_pointer_arith))
 	    pedwarn ("invalid application of %<sizeof%> to a function type");
@@ -2823,7 +2823,7 @@ c_sizeof_or_alignof_type (tree type, enu
     }
   else
     {
-      if (op == (enum tree_code) SIZEOF_EXPR)
+      if (is_sizeof)
 	/* Convert in case a char is more than one unit.  */
 	value = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
 			    size_int (TYPE_PRECISION (char_type_node)
Index: c-common.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.def,v
retrieving revision 1.27
diff -p -u -r1.27 c-common.def
--- c-common.def	9 Apr 2005 03:18:09 -0000	1.27
+++ c-common.def	16 Apr 2005 20:24:41 -0000
@@ -25,10 +25,6 @@ Software Foundation, 59 Temple Place - S
 /* Tree nodes relevant to both C and C++. These were originally in
 cp-tree.def in the cp subdir.  */
 
-DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", tcc_unary, 1)
-DEFTREECODE (ARROW_EXPR, "arrow_expr", tcc_expression, 1)
-DEFTREECODE (ALIGNOF_EXPR, "alignof_expr", tcc_unary, 1)
-
 /* Used to represent an expression statement.  Use `EXPR_STMT_EXPR' to
    obtain the expression.  */
 DEFTREECODE (EXPR_STMT, "expr_stmt", tcc_expression, 1)
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.284
diff -p -u -r1.284 c-common.h
--- c-common.h	14 Apr 2005 23:37:33 -0000	1.284
+++ c-common.h	16 Apr 2005 20:24:41 -0000
@@ -636,7 +636,7 @@ extern tree c_common_signed_type (tree);
 extern tree c_common_signed_or_unsigned_type (int, tree);
 extern tree c_common_truthvalue_conversion (tree);
 extern void c_apply_type_quals_to_decl (int, tree);
-extern tree c_sizeof_or_alignof_type (tree, enum tree_code, int);
+extern tree c_sizeof_or_alignof_type (tree, bool, int);
 extern tree c_alignof_expr (tree);
 /* Print an error message for invalid operands to arith operation CODE.
    NOP_EXPR is used as a special case (see truthvalue_conversion).  */
@@ -649,8 +649,8 @@ extern void overflow_warning (tree);
 extern void unsigned_conversion_warning (tree, tree);
 extern bool c_determine_visibility (tree);
 
-#define c_sizeof(T)  c_sizeof_or_alignof_type (T, SIZEOF_EXPR, 1)
-#define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR, 1)
+#define c_sizeof(T)  c_sizeof_or_alignof_type (T, true, 1)
+#define c_alignof(T) c_sizeof_or_alignof_type (T, false, 1)
 
 /* Subroutine of build_binary_op, used for comparison operations.
    See if the operands have both been converted from subword integer types
Index: c-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pretty-print.c,v
retrieving revision 1.60
diff -p -u -r1.60 c-pretty-print.c
--- c-pretty-print.c	9 Apr 2005 03:18:04 -0000	1.60
+++ c-pretty-print.c	16 Apr 2005 20:24:41 -0000
@@ -1223,11 +1223,6 @@ pp_c_postfix_expression (c_pretty_printe
       pp_identifier (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
       break;
 
-    case ARROW_EXPR:
-      pp_postfix_expression (pp, TREE_OPERAND (e, 0));
-      pp_c_arrow (pp);
-      break;
-
     case ARRAY_REF:
       pp_postfix_expression (pp, TREE_OPERAND (e, 0));
       pp_c_left_bracket (pp);
@@ -1430,16 +1425,6 @@ pp_c_unary_expression (c_pretty_printer 
       pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
       break;
 
-    case SIZEOF_EXPR:
-    case ALIGNOF_EXPR:
-      pp_c_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
-      pp_c_whitespace (pp);
-      if (TYPE_P (TREE_OPERAND (e, 0)))
-        pp_c_type_cast (pp, TREE_OPERAND (e, 0));
-      else
-	pp_unary_expression (pp, TREE_OPERAND (e, 0));
-      break;
-
     case REALPART_EXPR:
     case IMAGPART_EXPR:
       pp_c_identifier (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
@@ -1807,7 +1792,6 @@ pp_c_expression (c_pretty_printer *pp, t
 
     case POSTINCREMENT_EXPR:
     case POSTDECREMENT_EXPR:
-    case ARROW_EXPR:
     case ARRAY_REF:
     case CALL_EXPR:
     case COMPONENT_REF:
@@ -1837,8 +1821,6 @@ pp_c_expression (c_pretty_printer *pp, t
     case TRUTH_NOT_EXPR:
     case PREINCREMENT_EXPR:
     case PREDECREMENT_EXPR:
-    case SIZEOF_EXPR:
-    case ALIGNOF_EXPR:
     case REALPART_EXPR:
     case IMAGPART_EXPR:
       pp_c_unary_expression (pp, e);
Index: cp/cp-tree.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.def,v
retrieving revision 1.97
diff -p -u -r1.97 cp-tree.def
--- cp/cp-tree.def	9 Apr 2005 03:18:13 -0000	1.97
+++ cp/cp-tree.def	16 Apr 2005 20:24:42 -0000
@@ -321,6 +321,16 @@ DEFTREECODE (TINST_LEVEL, "TINST_LEVEL",
 /* Represents an 'offsetof' expression during template expansion.  */
 DEFTREECODE (OFFSETOF_EXPR, "offsetof_expr", tcc_expression, 1)
 
+/* Represents a 'sizeof' expression during template expansion.  */
+DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", tcc_unary, 1)
+
+/* Represents the -> operator during template expansion.  */
+DEFTREECODE (ARROW_EXPR, "arrow_expr", tcc_expression, 1)
+
+/* Represents an '__alignof__' expression during template
+   expansion.  */
+DEFTREECODE (ALIGNOF_EXPR, "alignof_expr", tcc_unary, 1)
+
 /*
 Local variables:
 mode:c
Index: cp/cxx-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cxx-pretty-print.c,v
retrieving revision 1.30
diff -p -u -r1.30 cxx-pretty-print.c
--- cp/cxx-pretty-print.c	9 Apr 2005 03:18:14 -0000	1.30
+++ cp/cxx-pretty-print.c	16 Apr 2005 20:24:42 -0000
@@ -490,6 +490,11 @@ pp_cxx_postfix_expression (cxx_pretty_pr
       pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
       break;
 
+    case ARROW_EXPR:
+      pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
+      pp_cxx_arrow (pp);
+      break;
+
     default:
       pp_c_postfix_expression (pp_c_base (pp), t);
       break;
@@ -615,6 +620,20 @@ pp_cxx_unary_expression (cxx_pretty_prin
       pp_cxx_delete_expression (pp, t);
       break;
       
+    case SIZEOF_EXPR:
+    case ALIGNOF_EXPR:
+      pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
+      pp_cxx_whitespace (pp);
+      if (TYPE_P (TREE_OPERAND (t, 0)))
+	{
+	  pp_cxx_left_paren (pp);
+	  pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
+	  pp_cxx_right_paren (pp);
+	}
+      else
+	pp_unary_expression (pp, TREE_OPERAND (t, 0));
+      break;
+
     default:
       pp_c_unary_expression (pp_c_base (pp), t);
       break;
@@ -859,6 +878,7 @@ pp_cxx_expression (cxx_pretty_printer *p
     case TYPEID_EXPR:
     case PSEUDO_DTOR_EXPR:
     case AGGR_INIT_EXPR:
+    case ARROW_EXPR:
       pp_cxx_postfix_expression (pp, t);
       break;
 
@@ -872,6 +892,11 @@ pp_cxx_expression (cxx_pretty_printer *p
       pp_cxx_delete_expression (pp, t);
       break;
 
+    case SIZEOF_EXPR:
+    case ALIGNOF_EXPR:
+      pp_cxx_unary_expression (pp, t);
+      break;
+
     case CAST_EXPR:
       pp_cxx_cast_expression (pp, t);
       break;
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.623
diff -p -u -r1.623 typeck.c
--- cp/typeck.c	6 Apr 2005 05:38:23 -0000	1.623
+++ cp/typeck.c	16 Apr 2005 20:24:43 -0000
@@ -1240,7 +1240,9 @@ cxx_sizeof_or_alignof_type (tree type, e
       value = size_one_node;
     }
   else
-    value = c_sizeof_or_alignof_type (complete_type (type), op, complain);
+    value = c_sizeof_or_alignof_type (complete_type (type),
+				      op == SIZEOF_EXPR,
+				      complain);
 
   return value;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]