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]

C++ PATCH for aggregate-init exprs



This patch adds a little documentation and a new macro to cleanup
AGGR_INIT_EXPRs a tad.  It allows us to easily understand the
semantics of an AGGR_INIT_EXPR without pulling its guts out.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-08-26  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (AGGR_INIT_VIA_CTOR_P): New macro.
	* tree.c (build_cplus_new): Set it.
	* expr.c (cplus_expand_expr): Use it.
	* dump.c (deque_and_dump): Handle AGGR_INIT_EXPR.

Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.272
diff -c -p -r1.272 cp-tree.h
*** cp-tree.h	1999/08/26 20:47:24	1.272
--- cp-tree.h	1999/08/27 04:56:24
*************** Boston, MA 02111-1307, USA.  */
*** 36,41 ****
--- 36,42 ----
        LOCAL_BINDING_P (in CPLUS_BINDING)
        ICS_USER_FLAG (in _CONV)
        CLEANUP_P (in TRY_BLOCK)
+       AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR)
     1: IDENTIFIER_VIRTUAL_P.
        TI_PENDING_TEMPLATE_FLAG.
        TEMPLATE_PARMS_FOR_INLINE.
*************** struct lang_decl
*** 1527,1532 ****
--- 1528,1537 ----
  #define DELETE_EXPR_USE_GLOBAL(NODE)	TREE_LANG_FLAG_0 (NODE)
  #define DELETE_EXPR_USE_VEC(NODE)	TREE_LANG_FLAG_1 (NODE)
  #define LOOKUP_EXPR_GLOBAL(NODE)	TREE_LANG_FLAG_0 (NODE)
+ 
+ /* Nonzero if this AGGR_INIT_EXPR provides for initialization via a
+    constructor call, rather than an ordinary function call.  */
+ #define AGGR_INIT_VIA_CTOR_P(NODE) TREE_LANG_FLAG_0 (NODE)
  
  /* The TYPE_MAIN_DECL for a class template type is a TYPE_DECL, not a
     TEMPLATE_DECL.  This macro determines whether or not a given class
Index: dump.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/dump.c,v
retrieving revision 1.8
diff -c -p -r1.8 dump.c
*** dump.c	1999/08/25 22:07:03	1.8
--- dump.c	1999/08/27 04:56:24
*************** dequeue_and_dump (di)
*** 850,855 ****
--- 850,865 ----
  	}
        break;
        
+     case AGGR_INIT_EXPR:
+       dump_int ("ctor", AGGR_INIT_VIA_CTOR_P (t));
+       if (dump_children_p)
+ 	{
+ 	  dump_child ("fn", TREE_OPERAND (t, 0));
+ 	  dump_child ("args", TREE_OPERAND (t, 1));
+ 	  dump_child ("decl", TREE_OPERAND (t, 2));
+ 	}
+       break;
+ 
      default:
        /* There are no additional fields to print.  */
        break;
Index: expr.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/expr.c,v
retrieving revision 1.26
diff -c -p -r1.26 expr.c
*** expr.c	1999/08/25 22:07:03	1.26
--- expr.c	1999/08/27 04:56:25
*************** cplus_expand_expr (exp, target, tmode, m
*** 154,162 ****
  	   initialization.  It is left here to show the choices that
  	   exist for C++.  */
  	   
! 	if (TREE_CODE (func) == ADDR_EXPR
! 	    && TREE_CODE (TREE_OPERAND (func, 0)) == FUNCTION_DECL
! 	    && DECL_CONSTRUCTOR_P (TREE_OPERAND (func, 0)))
  	  {
  	    type = build_pointer_type (type);
  	    /* Don't clobber a value that might be part of a default
--- 154,160 ----
  	   initialization.  It is left here to show the choices that
  	   exist for C++.  */
  	   
! 	if (AGGR_INIT_VIA_CTOR_P (exp))
  	  {
  	    type = build_pointer_type (type);
  	    /* Don't clobber a value that might be part of a default
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.140
diff -c -p -r1.140 tree.c
*** tree.c	1999/08/27 00:51:54	1.140
--- tree.c	1999/08/27 04:56:27
*************** build_cplus_new (type, init)
*** 220,225 ****
--- 220,226 ----
       tree type;
       tree init;
  {
+   tree fn;
    tree slot;
    tree rval;
  
*************** build_cplus_new (type, init)
*** 233,241 ****
    slot = build (VAR_DECL, type);
    DECL_ARTIFICIAL (slot) = 1;
    layout_decl (slot, 0);
!   rval = build (AGGR_INIT_EXPR, type,
! 		TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
    TREE_SIDE_EFFECTS (rval) = 1;
    rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE);
    TREE_SIDE_EFFECTS (rval) = 1;
  
--- 234,255 ----
    slot = build (VAR_DECL, type);
    DECL_ARTIFICIAL (slot) = 1;
    layout_decl (slot, 0);
! 
!   /* We split the CALL_EXPR into its function and its arguments here.
!      Then, in expand_expr, we put them back together.  The reason for
!      this is that this expression might be a default argument
!      expression.  In that case, we need a new temporary every time the
!      expression is used.  That's what break_out_target_exprs does; it
!      replaces every AGGR_INIT_EXPR with a copy that uses a fresh
!      temporary slot.  Then, expand_expr builds up a call-expression
!      using the new slot.  */
!   fn = TREE_OPERAND (init, 0);
!   rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot);
    TREE_SIDE_EFFECTS (rval) = 1;
+   AGGR_INIT_VIA_CTOR_P (rval) 
+     = (TREE_CODE (fn) == ADDR_EXPR
+        && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
+        && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
    rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE);
    TREE_SIDE_EFFECTS (rval) = 1;
  


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