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/C++ PATCH: Move expand_stmt into common code



This patch moves the machinery to expand the statement-tree into
common code.

Tested on i686-pc-linux.

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

2000-09-06  Mark Mitchell  <mark@codesourcery.com>

	* c-common.h (prep_stmt): Declare.
	(lang_expand_stmt): Likewise.
	* c-decl.c (lang_expand_stmt): Remove.
	* c-semantics.c (lang_expand_stmt): Define.
	(prep_stmt): New function.
	(expand_stmt): Handle common statement types here.

2000-09-06  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (init_cp_semantics): Declare.
	(genrtl_try_block): Don't declare.
	(genrtl_handler): Likewise.
	(genrtl_catch_block): Likewise.
	(genrtl_ctor_stmt): Likewise.
	(genrtl_subobject): Likewise.
	(genrtl_do_poplevel): Likewise.
	(genrtl_named_return_value): Likewise.
	* lex.c (init_parse): Call init_cp_semantics.
	* semantics.c (genrtl_try_block): Give it internal linkage.
	(genrtl_handler): Likewise.
	(genrtl_catch_block): Likewise.
	(genrtl_ctor_stmt): Likewise.
	(genrtl_subobject): Likewise.
	(genrtl_do_poplevel): Likewise.
	(genrtl_named_return_value): Likewise.
	(lang_expand_stmt): Rename to ...
	(cp_expand_stmt): ... this.  Only handle C++-specific nodes.
	(init_cp_semantics): Define.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.h,v
retrieving revision 1.35
diff -c -p -r1.35 c-common.h
*** c-common.h	2000/09/07 01:36:09	1.35
--- c-common.h	2000/09/07 06:12:39
*************** extern int (*lang_statement_code_p)     
*** 264,269 ****
--- 264,272 ----
  extern tree walk_stmt_tree			PARAMS ((tree *,
  							 walk_tree_fn,
  							 void *));
+ extern void prep_stmt                           PARAMS ((tree));
+ extern void (*lang_expand_stmt)                 PARAMS ((tree));
+ extern void expand_stmt                         PARAMS ((tree));
  
  /* The variant of the C language being processed.  Each C language
     front-end defines this variable.  */
*************** extern int anon_aggr_type_p             
*** 585,592 ****
  extern void emit_local_var                      PARAMS ((tree));
  extern void make_rtl_for_local_static           PARAMS ((tree));
  extern tree expand_cond                         PARAMS ((tree));
- extern tree expand_stmt                         PARAMS ((tree));
- extern tree lang_expand_stmt                    PARAMS ((tree));
  extern void c_expand_return			PARAMS ((tree));
  extern tree c_expand_start_case			PARAMS ((tree));
  extern void do_case				PARAMS ((tree, tree));
--- 588,593 ----
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.153
diff -c -p -r1.153 c-decl.c
*** c-decl.c	2000/09/07 01:36:09	1.153
--- c-decl.c	2000/09/07 06:12:44
*************** do_case (low_value, high_value)
*** 7000,7016 ****
      }
  }
  
- /* Language specific handler of tree nodes used when generating RTL
-    from a tree.  */
- 
- tree
- lang_expand_stmt (t)
-      tree t ATTRIBUTE_UNUSED;
- {
-   abort ();
-   return NULL_TREE;
- }
- 
  /* Accessor to set the 'current_function_name_declared' flag.  */
  
  void
--- 7000,7005 ----
Index: c-semantics.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-semantics.c,v
retrieving revision 1.5
diff -c -p -r1.5 c-semantics.c
*** c-semantics.c	2000/09/07 01:36:09	1.5
--- c-semantics.c	2000/09/07 06:12:44
*************** Boston, MA 02111-1307, USA.  */
*** 36,41 ****
--- 36,45 ----
  #include "output.h"
  #include "timevar.h"
  
+ /* If non-NULL, the address of a language-specific function for
+    expanding statements.  */
+ void (*lang_expand_stmt) PARAMS ((tree));
+ 
  static tree prune_unused_decls PARAMS ((tree *, int *, void *));
  
  /* Create an empty statement tree rooted at T.  */
*************** genrtl_decl_cleanup (decl, cleanup)
*** 643,657 ****
      expand_decl_cleanup (decl, cleanup);
  }
  
  /* Generate the RTL for the statement T, its substatements, and any
     other statements at its nesting level. */
  
! tree
  expand_stmt (t)
       tree t;
  {
!   tree rval;
!   rval = lang_expand_stmt (t);
!   return rval;
  }
  
--- 647,756 ----
      expand_decl_cleanup (decl, cleanup);
  }
  
+ /* We're about to expand T, a statement.  Set up appropriate context
+    for the substitution.  */
+ 
+ void
+ prep_stmt (t)
+      tree t;
+ {
+   if (!STMT_LINENO_FOR_FN_P (t))
+     lineno = STMT_LINENO (t);
+   current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
+ }
+ 
  /* Generate the RTL for the statement T, its substatements, and any
     other statements at its nesting level. */
  
! void
  expand_stmt (t)
       tree t;
  {
!   while (t && t != error_mark_node)
!     {
!       int saved_stmts_are_full_exprs_p;
! 
!       /* Set up context appropriately for handling this statement.  */
!       saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
!       prep_stmt (t);
! 
!       switch (TREE_CODE (t))
! 	{
! 	case RETURN_STMT:
! 	  genrtl_return_stmt (RETURN_EXPR (t));
! 	  break;
! 
! 	case EXPR_STMT:
! 	  genrtl_expr_stmt (EXPR_STMT_EXPR (t));
! 	  break;
! 
! 	case DECL_STMT:
! 	  genrtl_decl_stmt (t);
! 	  break;
! 
! 	case FOR_STMT:
! 	  genrtl_for_stmt (t);
! 	  break;
! 
! 	case WHILE_STMT:
! 	  genrtl_while_stmt (t);
! 	  break;
! 
! 	case DO_STMT:
! 	  genrtl_do_stmt (t);
! 	  break;
! 
! 	case IF_STMT:
! 	  genrtl_if_stmt (t);
! 	  break;
! 
! 	case COMPOUND_STMT:
! 	  genrtl_compound_stmt (t);
! 	  break;
! 
! 	case BREAK_STMT:
! 	  genrtl_break_stmt ();
! 	  break;
! 
! 	case CONTINUE_STMT:
! 	  genrtl_continue_stmt ();
! 	  break;
! 
! 	case SWITCH_STMT:
! 	  genrtl_switch_stmt (t);
! 	  break;
! 
! 	case CASE_LABEL:
! 	  genrtl_case_label (CASE_LOW (t), CASE_HIGH (t));
! 	  break;
! 
! 	case LABEL_STMT:
! 	  expand_label (LABEL_STMT_LABEL (t));
! 	  break;
! 
! 	case GOTO_STMT:
! 	  genrtl_goto_stmt (GOTO_DESTINATION (t));
! 	  break;
! 
! 	case ASM_STMT:
! 	  genrtl_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t),
! 			   ASM_OUTPUTS (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
! 	  break;
! 
! 	default:
! 	  if (lang_expand_stmt)
! 	    (*lang_expand_stmt) (t);
! 	  else 
! 	    abort ();
! 	  break;
! 	}
! 
!       /* Restore saved state.  */
!       current_stmt_tree ()->stmts_are_full_exprs_p = 
! 	saved_stmts_are_full_exprs_p;
! 
!       /* Go on to the next statement in this scope.  */
!       t = TREE_CHAIN (t);
!     }
  }
  
Index: cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/ChangeLog,v
retrieving revision 1.1987
diff -c -p -r1.1987 ChangeLog
*** ChangeLog	2000/09/07 03:50:51	1.1987
--- ChangeLog	2000/09/07 06:12:49
***************
*** 1,5 ****
--- 1,25 ----
  2000-09-06  Mark Mitchell  <mark@codesourcery.com>
  
+ 	* cp-tree.h (init_cp_semantics): Declare.
+ 	(genrtl_try_block): Don't declare.
+ 	(genrtl_handler): Likewise.
+ 	(genrtl_catch_block): Likewise.
+ 	(genrtl_ctor_stmt): Likewise.
+ 	(genrtl_subobject): Likewise.
+ 	(genrtl_do_poplevel): Likewise.
+ 	(genrtl_named_return_value): Likewise.
+ 	* lex.c (init_parse): Call init_cp_semantics.
+ 	* semantics.c (genrtl_try_block): Give it internal linkage.
+ 	(genrtl_handler): Likewise.
+ 	(genrtl_catch_block): Likewise.
+ 	(genrtl_ctor_stmt): Likewise.
+ 	(genrtl_subobject): Likewise.
+ 	(genrtl_do_poplevel): Likewise.
+ 	(genrtl_named_return_value): Likewise.
+ 	(lang_expand_stmt): Rename to ...
+ 	(cp_expand_stmt): ... this.  Only handle C++-specific nodes.
+ 	(init_cp_semantics): Define.
+ 
  	* decl.c (initialize_local_var): Remove RTL-generating code.
  	* semantics.c (genrtl_try_block): Fix formatting.
  
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.525
diff -c -p -r1.525 cp-tree.h
*** cp-tree.h	2000/09/07 01:36:10	1.525
--- cp-tree.h	2000/09/07 06:12:52
*************** extern tree binfo_for_vbase             
*** 4286,4291 ****
--- 4286,4292 ----
  extern void fixup_all_virtual_upcast_offsets    PARAMS ((tree));
  
  /* in semantics.c */
+ extern void init_cp_semantics                   PARAMS ((void));
  extern void finish_expr_stmt                    PARAMS ((tree));
  extern tree begin_if_stmt                       PARAMS ((void));
  extern void finish_if_stmt_cond                 PARAMS ((tree, tree));
*************** extern void do_pushlevel                
*** 4375,4388 ****
  extern tree do_poplevel                         PARAMS ((void));
  extern void finish_mem_initializers             PARAMS ((tree));
  
- extern void genrtl_try_block                    PARAMS ((tree));
- extern void genrtl_handler                      PARAMS ((tree));
- extern void genrtl_catch_block                  PARAMS ((tree));
- extern void genrtl_ctor_stmt                    PARAMS ((tree));
- extern void genrtl_subobject                    PARAMS ((tree));
- extern tree genrtl_do_poplevel                  PARAMS ((void));
  extern void clear_out_block                     PARAMS ((void));
- extern void genrtl_named_return_value           PARAMS ((void));
  extern tree begin_global_stmt_expr              PARAMS ((void));
  extern tree finish_global_stmt_expr             PARAMS ((tree));
  
--- 4376,4382 ----
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/lex.c,v
retrieving revision 1.214
diff -c -p -r1.214 lex.c
*** lex.c	2000/09/07 00:37:13	1.214
--- lex.c	2000/09/07 06:12:53
*************** init_parse (filename)
*** 714,723 ****
    init_reswords ();
    init_pragma ();
    init_cp_pragma ();
- 
    init_spew ();
    init_tree ();
    init_cplus_expand ();
  
    add_c_tree_codes ();
  
--- 714,723 ----
    init_reswords ();
    init_pragma ();
    init_cp_pragma ();
    init_spew ();
    init_tree ();
    init_cplus_expand ();
+   init_cp_semantics ();
  
    add_c_tree_codes ();
  
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/semantics.c,v
retrieving revision 1.171
diff -c -p -r1.171 semantics.c
*** semantics.c	2000/09/07 03:50:52	1.171
--- semantics.c	2000/09/07 06:12:55
*************** static tree maybe_convert_cond PARAMS ((
*** 50,55 ****
--- 50,63 ----
  static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
  static void deferred_type_access_control PARAMS ((void));
  static void emit_associated_thunks PARAMS ((tree));
+ static void genrtl_try_block PARAMS ((tree));
+ static void genrtl_handler PARAMS ((tree));
+ static void genrtl_catch_block PARAMS ((tree));
+ static void genrtl_ctor_stmt PARAMS ((tree));
+ static void genrtl_subobject PARAMS ((tree));
+ static tree genrtl_do_poplevel PARAMS ((void));
+ static void genrtl_named_return_value PARAMS ((void));
+ static void cp_expand_stmt PARAMS ((tree));
  
  /* When parsing a template, LAST_TREE contains the last statement
     parsed.  These are chained together through the TREE_CHAIN field,
*************** finish_case_label (low_value, high_value
*** 592,598 ****
  
  /* Generate the RTL for T, which is a TRY_BLOCK. */
  
! void genrtl_try_block (t)
       tree t;
  {
    if (CLEANUP_P (t))
--- 600,607 ----
  
  /* Generate the RTL for T, which is a TRY_BLOCK. */
  
! static void 
! genrtl_try_block (t)
       tree t;
  {
    if (CLEANUP_P (t))
*************** finish_function_handler_sequence (try_bl
*** 731,737 ****
  
  /* Generate the RTL for T, which is a HANDLER. */
  
! void
  genrtl_handler (t)
       tree t;
  {
--- 740,746 ----
  
  /* Generate the RTL for T, which is a HANDLER. */
  
! static void
  genrtl_handler (t)
       tree t;
  {
*************** finish_handler_parms (decl, handler)
*** 791,797 ****
  
  /* Generate the RTL for a CATCH_BLOCK. */
  
! void
  genrtl_catch_block (type)
       tree type;
  {
--- 800,806 ----
  
  /* Generate the RTL for a CATCH_BLOCK. */
  
! static void
  genrtl_catch_block (type)
       tree type;
  {
*************** finish_handler (blocks, handler)
*** 825,831 ****
  
  /* Generate the RTL for T, which is a CTOR_STMT. */
  
! void
  genrtl_ctor_stmt (t)
       tree t;
  {
--- 834,840 ----
  
  /* Generate the RTL for T, which is a CTOR_STMT. */
  
! static void
  genrtl_ctor_stmt (t)
       tree t;
  {
*************** add_decl_stmt (decl)
*** 991,997 ****
  
  /* Generate the RTL for a SUBOBJECT. */
  
! void 
  genrtl_subobject (cleanup)
       tree cleanup;
  {
--- 1000,1006 ----
  
  /* Generate the RTL for a SUBOBJECT. */
  
! static void 
  genrtl_subobject (cleanup)
       tree cleanup;
  {
*************** finish_decl_cleanup (decl, cleanup)
*** 1022,1028 ****
  
  /* Generate the RTL for a RETURN_INIT. */
  
! void
  genrtl_named_return_value ()
  {
    tree decl;
--- 1031,1037 ----
  
  /* Generate the RTL for a RETURN_INIT. */
  
! static void
  genrtl_named_return_value ()
  {
    tree decl;
*************** finish_typeof (expr)
*** 2216,2362 ****
    return TREE_TYPE (expr);
  }
  
- /* We're about to expand T, a statement.  Set up appropriate context
-    for the substitution.  */
- 
- void
- prep_stmt (t)
-      tree t;
- {
-   if (!STMT_LINENO_FOR_FN_P (t))
-     lineno = STMT_LINENO (t);
-   current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
- }
- 
  /* Generate RTL for the statement T, and its substatements, and any
     other statements at its nesting level.  */
  
! tree
! lang_expand_stmt (t)
       tree t;
  {
!   tree rval = NULL_TREE;
! 
!   while (t && t != error_mark_node)
      {
!       int saved_stmts_are_full_exprs_p;
! 
!       /* Assume we'll have nothing to return.  */
!       rval = NULL_TREE;
! 
!       /* Set up context appropriately for handling this statement.  */
!       saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
!       prep_stmt (t);
! 
!       switch (TREE_CODE (t))
! 	{
! 	case RETURN_STMT:
! 	  genrtl_return_stmt (RETURN_EXPR (t));
! 	  break;
! 
! 	case EXPR_STMT:
! 	  genrtl_expr_stmt (EXPR_STMT_EXPR (t));
! 	  break;
! 
! 	case DECL_STMT:
! 	  genrtl_decl_stmt (t);
! 	  break;
! 
! 	case CLEANUP_STMT:
! 	  genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
! 	  break;
! 
! 	case START_CATCH_STMT:
! 	  genrtl_catch_block (TREE_TYPE (t));
! 	  break;
! 
! 	case CTOR_STMT:
! 	  genrtl_ctor_stmt (t);
! 	  break;
! 
! 	case FOR_STMT:
! 	  genrtl_for_stmt (t);
! 	  break;
! 
! 	case WHILE_STMT:
! 	  genrtl_while_stmt (t);
! 	  break;
! 
! 	case DO_STMT:
! 	  genrtl_do_stmt (t);
! 	  break;
! 
! 	case IF_STMT:
! 	  genrtl_if_stmt (t);
! 	  break;
! 
! 	case COMPOUND_STMT:
! 	  genrtl_compound_stmt (t);
! 	  break;
! 
! 	case BREAK_STMT:
! 	  genrtl_break_stmt ();
! 	  break;
! 
! 	case CONTINUE_STMT:
! 	  genrtl_continue_stmt ();
! 	  break;
! 
! 	case SWITCH_STMT:
! 	  genrtl_switch_stmt (t);
! 	  break;
! 
! 	case CASE_LABEL:
! 	  genrtl_case_label (CASE_LOW (t), CASE_HIGH (t));
! 	  break;
! 
! 	case LABEL_STMT:
! 	  expand_label (LABEL_STMT_LABEL (t));
! 	  break;
! 
! 	case GOTO_STMT:
! 	  genrtl_goto_stmt (GOTO_DESTINATION (t));
! 	  break;
! 
! 	case ASM_STMT:
! 	  genrtl_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t),
! 			   ASM_OUTPUTS (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
! 	  break;
! 
! 	case TRY_BLOCK:
! 	  genrtl_try_block (t);
! 	  break;
! 
! 	case HANDLER:
! 	  genrtl_handler (t);
! 	  break;
! 
! 	case SUBOBJECT:
! 	  genrtl_subobject (SUBOBJECT_CLEANUP (t));
! 	  break;
! 
! 	case SCOPE_STMT:
! 	  genrtl_scope_stmt (t);
! 	  break;
! 
! 	case RETURN_INIT:
! 	  genrtl_named_return_value ();
! 	  break;
! 
! 	default:
! 	  my_friendly_abort (19990810);
! 	  break;
! 	}
! 
!       /* Restore saved state.  */
!       current_stmt_tree ()->stmts_are_full_exprs_p = 
! 	saved_stmts_are_full_exprs_p;
! 
!       /* Go on to the next statement in this scope.  */
!       t = TREE_CHAIN (t);
      }
- 
-   return rval;
  }
  
  /* Called from expand_body via walk_tree.  Replace all AGGR_INIT_EXPRs
--- 2225,2275 ----
    return TREE_TYPE (expr);
  }
  
  /* Generate RTL for the statement T, and its substatements, and any
     other statements at its nesting level.  */
  
! static void
! cp_expand_stmt (t)
       tree t;
  {
!   switch (TREE_CODE (t))
      {
!     case CLEANUP_STMT:
!       genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
!       break;
! 
!     case START_CATCH_STMT:
!       genrtl_catch_block (TREE_TYPE (t));
!       break;
! 
!     case CTOR_STMT:
!       genrtl_ctor_stmt (t);
!       break;
! 
!     case TRY_BLOCK:
!       genrtl_try_block (t);
!       break;
! 
!     case HANDLER:
!       genrtl_handler (t);
!       break;
! 
!     case SUBOBJECT:
!       genrtl_subobject (SUBOBJECT_CLEANUP (t));
!       break;
! 
!     case SCOPE_STMT:
!       genrtl_scope_stmt (t);
!       break;
! 
!     case RETURN_INIT:
!       genrtl_named_return_value ();
!       break;
! 
!     default:
!       my_friendly_abort (19990810);
!       break;
      }
  }
  
  /* Called from expand_body via walk_tree.  Replace all AGGR_INIT_EXPRs
*************** expand_body (fn)
*** 2629,2632 ****
--- 2542,2553 ----
    extract_interface_info ();
  
    timevar_pop (TV_EXPAND);
+ }
+ 
+ /* Perform initialization related to this module.  */
+ 
+ void
+ init_cp_semantics ()
+ {
+   lang_expand_stmt = cp_expand_stmt;
  }

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