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] harmonize {|c_|cplus_}tree_code


:ADDPATCH C/C++:

The attached patch harmonizes the definitions of tree_code, c_tree_code,
and cp_tree code by ensuring that the underlying domain is the same.
This is required by the C++ standard to meaningful cast between them
(perhaps by the C standard, too).
It also explicitly casts between c_tree_code and tree_code (only one
occurrence). I did not touch the C++ front end besides the enum
definition itself, it still lacks casts from cp_tree_code to tree_code
for C++ compatibility.

Boostrapped and tested on i686. Is this ok?

Thomas

tree.h (MAX_TREE_CODES): Move before tree_code.
(enum tree code): Use MAX_TREE_CODES to define the domain maximum.
c-common.h (enum c_tree_code): Use dummy entries to explicitly mark the
boundaries of the underlying domain.
c-decl.c (build_compound_literal): Explicitly cast from c_tree_code to
tree_code for C++ compatibility.

cp/
cp-tree.h (enum cplus_tree_code): Use dummy entries to explicitly mark
the boundaries of the underlying domain.
Index: gcc/tree.h
===================================================================
--- gcc/tree.h	(Revision 124812)
+++ gcc/tree.h	(Arbeitskopie)
@@ -31,18 +31,22 @@ Software Foundation, 51 Franklin Street,
 
 /* Codes of tree nodes */
 
+#define MAX_TREE_CODES 512
+
 #define DEFTREECODE(SYM, STRING, TYPE, NARGS)   SYM,
 
 enum tree_code {
 #include "tree.def"
 
-  LAST_AND_UNUSED_TREE_CODE	/* A convenient way to get a value for
+  LAST_AND_UNUSED_TREE_CODE,	/* A convenient way to get a value for
 				   NUM_TREE_CODES.  */
+
+  LAST_POSSIBLE_TREE_CODE = MAX_TREE_CODES - 1 /* Last tree code id potentially
+						  used by a front end */
 };
 
 #undef DEFTREECODE
 
-#define MAX_TREE_CODES 512
 extern unsigned char tree_contains_struct[MAX_TREE_CODES][64];
 #define CODE_CONTAINS_STRUCT(CODE, STRUCT) (tree_contains_struct[(CODE)][(STRUCT)])
 
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(Revision 124812)
+++ gcc/cp/cp-tree.h	(Arbeitskopie)
@@ -932,9 +932,14 @@ struct language_function GTY(())
 /* C++ language-specific tree codes.  */
 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
 enum cplus_tree_code {
+  CP_DUMMY_MIN_TREE_CODE = 0, /* Minimum value of possible tree codes */
+
   CP_DUMMY_TREE_CODE = LAST_C_TREE_CODE,
 #include "cp-tree.def"
-  LAST_CPLUS_TREE_CODE
+  LAST_CPLUS_TREE_CODE,
+
+  CP_DUMMY_MAX_TREE_CODE = LAST_POSSIBLE_TREE_CODE /* Maximum value of possible
+						      tree codes */
 };
 #undef DEFTREECODE
 
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(Revision 124812)
+++ gcc/c-decl.c	(Arbeitskopie)
@@ -3765,7 +3765,7 @@ build_compound_literal (tree type, tree 
     return error_mark_node;
 
   stmt = build_stmt (DECL_EXPR, decl);
-  complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
+  complit = build1 ((enum tree_code) COMPOUND_LITERAL_EXPR, type, stmt);
   TREE_SIDE_EFFECTS (complit) = 1;
 
   layout_decl (decl, 0);
Index: gcc/c-common.h
===================================================================
--- gcc/c-common.h	(Revision 124812)
+++ gcc/c-common.h	(Arbeitskopie)
@@ -757,9 +757,14 @@ extern void finish_file	(void);
 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
 
 enum c_tree_code {
+  C_DUMMY_MIN_TREE_CODE = 0, /* Minimum value of possible tree codes */
+
   C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE,
 #include "c-common.def"
-  LAST_C_TREE_CODE
+  LAST_C_TREE_CODE,
+
+  C_DUMMY_MAX_TREE_CODE = LAST_POSSIBLE_TREE_CODE /* Maximum value of possible
+						     tree codes */
 };
 
 #undef DEFTREECODE

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