public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] harmonize {|c_|cplus_}tree_code
@ 2007-05-18  6:26 Thomas Neumann
  2007-05-18 16:45 ` Andrew Pinski
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Neumann @ 2007-05-18  6:26 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 989 bytes --]

: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.

[-- Attachment #2: treecode.patch --]
[-- Type: text/x-diff, Size: 2616 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] harmonize {|c_|cplus_}tree_code
  2007-05-18  6:26 [patch] harmonize {|c_|cplus_}tree_code Thomas Neumann
@ 2007-05-18 16:45 ` Andrew Pinski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Pinski @ 2007-05-18 16:45 UTC (permalink / raw)
  To: Thomas Neumann; +Cc: gcc-patches

On 5/17/07, Thomas Neumann <tneumann@users.sourceforge.net> wrote:
> :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 is not required by the C standard, as long as the underlying type
is large enough.  The underlying type is an implemenation defined so
it could be needed for some C implementations but GCC does have docs
on how we define this :).

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-05-18 16:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-18  6:26 [patch] harmonize {|c_|cplus_}tree_code Thomas Neumann
2007-05-18 16:45 ` Andrew Pinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).