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] Move struct creation to common


Hi,
this patch moves finish_builtin_type from c++ to common code, and
renames it the more correct finish_builtin_struct.
I also took the opportunity of allowing the alignment to default
and specifying the LENGTH parm to be a length, rather than
index of last element.

There are places in common code which could use the functionality.

booted & tested on i686-pc-linux-gnu, ok?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-08-14  Nathan Sidwell  <nathan@codesourcery.com>

	* stor-layout (finish_builtin_struct): Renamed and moved from c++
	frontend. Allow NULL alignment type.
	* tree.h (finish_builtin_struct): Declare.
cp:
	* cp-tree.h (finish_builtin_type): Remove.
	* decl2.c (finish_builtin_type): Move to common code.
	* decl.c (build_ptrmemfunc_type): Adjust.
	* rtti.c (create_pseudo_type_info): Adjust.
	(create_tinfo_types): Adjust.

Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.128
diff -c -3 -p -r1.128 stor-layout.c
*** stor-layout.c	7 Aug 2002 23:20:34 -0000	1.128
--- stor-layout.c	14 Aug 2002 22:08:20 -0000
*************** finish_record_layout (rli)
*** 1397,1402 ****
--- 1397,1445 ----
    free (rli);
  }
  
+ 
+ /* Finish processing a builtin type TYPE.  It's name is NAME, its
+    fields are in the array FIELDS.  LEN is the number of elements in
+    FIELDS.
+ 
+    If ALIGN_TYPE is non-null, it is given the same alignment as
+    ALIGN_TYPE.  */
+ 
+ void
+ finish_builtin_struct (type, name, fields, len, align_type)
+      tree type;
+      const char *name;
+      tree fields[];
+      int len;
+      tree align_type;
+ {
+   int i;
+   tree tail = NULL_TREE;
+   
+   TYPE_FIELDS (type) = fields[0];
+   for (i = len; i--;)
+     {
+       DECL_FIELD_CONTEXT (fields[i]) = type;
+       TREE_CHAIN (fields[i]) = tail;
+       tail = fields[i];
+     }
+ 
+   if (align_type)
+     {
+       TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
+       TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (align_type);
+     }
+   
+   layout_type (type);
+ #if 0 /* not yet, should get fixed properly later */
+   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
+ #else
+   TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
+ #endif
+   TYPE_STUB_DECL (type) = TYPE_NAME (type);
+   layout_decl (TYPE_NAME (type), 0);
+ }
+ 
  /* Calculate the mode, size, and alignment for TYPE.
     For an array type, calculate the element separation as well.
     Record TYPE on the chain of permanent or temporary types
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.349
diff -c -3 -p -r1.349 tree.h
*** tree.h	14 Aug 2002 02:15:40 -0000	1.349
--- tree.h	14 Aug 2002 22:08:29 -0000
*************** extern tree build_qualified_type        
*** 2363,2368 ****
--- 2363,2374 ----
  
  extern tree build_type_copy		PARAMS ((tree));
  
+ /* Finish up a builtin RECORD_TYPE. Give it a name and provide its
+    fields. Optionally specify an alignment, and then lsy it out.  */
+ 
+ extern void finish_builtin_struct		PARAMS ((tree, const char *,
+ 						 tree *, int, tree));
+ 
  /* Given a ..._TYPE node, calculate the TYPE_SIZE, TYPE_SIZE_UNIT,
     TYPE_ALIGN and TYPE_MODE fields.  If called more than once on one
     node, does nothing except for the first time.  */
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.744
diff -c -3 -p -r1.744 cp-tree.h
*** cp/cp-tree.h	9 Aug 2002 19:57:00 -0000	1.744
--- cp/cp-tree.h	14 Aug 2002 22:08:42 -0000
*************** extern bool constructor_name_p          
*** 3762,3769 ****
  extern void defer_fn            		PARAMS ((tree));
  extern void finish_anon_union			PARAMS ((tree));
  extern tree finish_table			PARAMS ((tree, tree, tree, int));
- extern void finish_builtin_type			PARAMS ((tree, const char *,
- 						       tree *, int, tree));
  extern tree coerce_new_type			PARAMS ((tree));
  extern tree coerce_delete_type			PARAMS ((tree));
  extern void comdat_linkage			PARAMS ((tree));
--- 3762,3767 ----
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.931
diff -c -3 -p -r1.931 decl.c
*** cp/decl.c	13 Aug 2002 16:36:26 -0000	1.931
--- cp/decl.c	14 Aug 2002 22:09:13 -0000
*************** build_ptrmemfunc_type (type)
*** 9293,9299 ****
    fields[0] = build_decl (FIELD_DECL, pfn_identifier, type);
    fields[1] = build_decl (FIELD_DECL, delta_identifier,
  			  delta_type_node);
!   finish_builtin_type (t, "__ptrmemfunc_type", fields, 1, ptr_type_node);
  
    /* Zap out the name so that the back-end will give us the debugging
       information for this anonymous RECORD_TYPE.  */
--- 9293,9299 ----
    fields[0] = build_decl (FIELD_DECL, pfn_identifier, type);
    fields[1] = build_decl (FIELD_DECL, delta_identifier,
  			  delta_type_node);
!   finish_builtin_struct (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
  
    /* Zap out the name so that the back-end will give us the debugging
       information for this anonymous RECORD_TYPE.  */
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.559
diff -c -3 -p -r1.559 decl2.c
*** cp/decl2.c	11 Aug 2002 18:30:24 -0000	1.559
--- cp/decl2.c	14 Aug 2002 22:09:23 -0000
*************** finish_anon_union (anon_union_decl)
*** 1403,1445 ****
    else
      add_decl_stmt (anon_union_decl);
  }
- 
- /* Finish processing a builtin type TYPE.  It's name is NAME,
-    its fields are in the array FIELDS.  LEN is the number of elements
-    in FIELDS minus one, or put another way, it is the maximum subscript
-    used in FIELDS.
- 
-    It is given the same alignment as ALIGN_TYPE.  */
- 
- void
- finish_builtin_type (type, name, fields, len, align_type)
-      tree type;
-      const char *name;
-      tree fields[];
-      int len;
-      tree align_type;
- {
-   register int i;
- 
-   TYPE_FIELDS (type) = fields[0];
-   for (i = 0; i < len; i++)
-     {
-       layout_type (TREE_TYPE (fields[i]));
-       DECL_FIELD_CONTEXT (fields[i]) = type;
-       TREE_CHAIN (fields[i]) = fields[i+1];
-     }
-   DECL_FIELD_CONTEXT (fields[i]) = type;
-   TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
-   TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (align_type);
-   layout_type (type);
- #if 0 /* not yet, should get fixed properly later */
-   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
- #else
-   TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
- #endif
-   TYPE_STUB_DECL (type) = TYPE_NAME (type);
-   layout_decl (TYPE_NAME (type), 0);
- }
  
  /* Auxiliary functions to make type signatures for
     `operator new' and `operator delete' correspond to
--- 1403,1408 ----
Index: cp/rtti.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/rtti.c,v
retrieving revision 1.139
diff -c -3 -p -r1.139 rtti.c
*** cp/rtti.c	17 Jul 2002 11:46:38 -0000	1.139
--- cp/rtti.c	14 Aug 2002 22:09:25 -0000
*************** create_pseudo_type_info VPARAMS((const c
*** 1157,1168 ****
    fields[0] = build_decl (FIELD_DECL, NULL_TREE, ti_desc_type_node);
    
    /* Now add the derived fields.  */
!   for (ix = 0; (field_decl = va_arg (ap, tree));)
!     fields[++ix] = field_decl;
    
    /* Create the pseudo type. */
    pseudo_type = make_aggr_type (RECORD_TYPE);
!   finish_builtin_type (pseudo_type, pseudo_name, fields, ix, ptr_type_node);
    TYPE_HAS_CONSTRUCTOR (pseudo_type) = 1;
  
    result = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
--- 1157,1168 ----
    fields[0] = build_decl (FIELD_DECL, NULL_TREE, ti_desc_type_node);
    
    /* Now add the derived fields.  */
!   for (ix = 1; (field_decl = va_arg (ap, tree)); ix++)
!     fields[ix] = field_decl;
    
    /* Create the pseudo type. */
    pseudo_type = make_aggr_type (RECORD_TYPE);
!   finish_builtin_struct (pseudo_type, pseudo_name, fields, ix, NULL_TREE);
    TYPE_HAS_CONSTRUCTOR (pseudo_type) = 1;
  
    result = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
*************** create_tinfo_types ()
*** 1276,1283 ****
      ti_desc_type_node = make_aggr_type (RECORD_TYPE);
      fields[0] = build_decl (FIELD_DECL, NULL_TREE, const_ptr_type_node);
      fields[1] = build_decl (FIELD_DECL, NULL_TREE, const_string_type_node);
!     finish_builtin_type (ti_desc_type_node, "__type_info_pseudo",
!                          fields, 1, ptr_type_node);
      TYPE_HAS_CONSTRUCTOR (ti_desc_type_node) = 1;
    }
    
--- 1276,1283 ----
      ti_desc_type_node = make_aggr_type (RECORD_TYPE);
      fields[0] = build_decl (FIELD_DECL, NULL_TREE, const_ptr_type_node);
      fields[1] = build_decl (FIELD_DECL, NULL_TREE, const_string_type_node);
!     finish_builtin_struct (ti_desc_type_node, "__type_info_pseudo",
! 			   fields, 2, NULL_TREE);
      TYPE_HAS_CONSTRUCTOR (ti_desc_type_node) = 1;
    }
    
*************** create_tinfo_types ()
*** 1317,1324 ****
      fields[0] = build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type);
      fields[1] = build_decl (FIELD_DECL, NULL_TREE, integer_types[itk_long]);
      base_desc_type_node = make_aggr_type (RECORD_TYPE);
!     finish_builtin_type (base_desc_type_node, "__base_class_type_info_pseudo",
!                          fields, 1, ptr_type_node);
      TYPE_HAS_CONSTRUCTOR (base_desc_type_node) = 1;
    }
    
--- 1317,1324 ----
      fields[0] = build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type);
      fields[1] = build_decl (FIELD_DECL, NULL_TREE, integer_types[itk_long]);
      base_desc_type_node = make_aggr_type (RECORD_TYPE);
!     finish_builtin_struct (base_desc_type_node, "__base_class_type_info_pseudo",
! 			   fields, 2, NULL_TREE);
      TYPE_HAS_CONSTRUCTOR (base_desc_type_node) = 1;
    }
    

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