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]

[gomp RFA] Remove c-semantics.c from C++ front-end


As suggested by Joseph Myers, a first step in the implementation
of GOMP will be to extract actions from the C grammar.

This patch empties c-semantics.c, in order to remove it from the
C++ front-end.  It will become the place where actions of the
C grammar are kept, paralleling cp/semantics.c.  A handful of
functions it contains are moved to c-common.c; re_push_stmt_list
is dead, a few are one-liners that can be inlined and/or belong in C++
only, and emit_local_var is only used in c-common.c exactly.

Moving code to c-semantics.c can be done incrementally of course.

Bootstrapped/regtested C/C++/ObjC on i686-pc-linux-gnu, together
with the following patch. I'll commit it to the branch unless someone has screamed by tomorrow.


Paolo


2004-10-20  Paolo Bonzini  <bonzini@gnu.org>

	* Makefile.in (c-common.o): Adjust dependencies.
	* c-common.c (tree-gimple.h): Include instead of tree-iterator.h.
	(push_stmt_list, pop_stmt_list, add_stmt, build_stmt,
	emit_local_var): Moved from c-semantics.c.
	(c_add_case_label): Do not use build_case_label.
	* c-common.h (re_push_stmt_list, emit_local_var, build_break_stmt,
	build_continue_stmt, build_case_label_expr): Removed.
	* c-semantics.c (re_push_stmt_list, build_break_stmt,
	build_continue_stmt, build_case_label_expr): Removed.
	(push_stmt_list, pop_stmt_list, add_stmt, build_stmt,
	emit_local_var): Moved to c-common.c.

	* cp/Make-lang.in (CXX_C_OBJS): Remove c-semantics.o.
	* cp/decl.c (finish_case_label): Do not use build_case_label.
	* cp/semantics.c (finish_break_stmt): Do not use build_break_stmt.
	(finish_continue_stmt): Do not use build_continue_stmt.

diff -u 3.5/gcc-save/gcc/Makefile.in 3.5/gcc/gcc/Makefile.in
--- 3.5/gcc-save/gcc/Makefile.in	2004-10-20 21:52:32.000000000 +0200
+++ 3.5/gcc/gcc/Makefile.in	2004-10-20 21:52:38.000000000 +0200
@@ -1429,7 +1429,7 @@
 	$(OBSTACK_H) $(C_COMMON_H) $(FLAGS_H) toplev.h output.h $(C_PRAGMA_H) intl.h \
 	$(GGC_H) $(EXPR_H) $(TM_P_H) builtin-types.def builtin-attrs.def \
 	$(DIAGNOSTIC_H) gt-c-common.h langhooks.h varray.h $(RTL_H) \
-	$(TARGET_H) $(C_TREE_H) tree-iterator.h langhooks.h tree-mudflap.h
+	$(TARGET_H) $(C_TREE_H) $(TREE_GIMPLE_H) langhooks.h tree-mudflap.h
 c-pretty-print.o : c-pretty-print.c $(C_PRETTY_PRINT_H) \
 	$(C_COMMON_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) real.h \
 	$(DIAGNOSTIC_H)
diff -u 3.5/gcc-save/gcc/c-common.c 3.5/gcc/gcc/c-common.c
--- 3.5/gcc-save/gcc/c-common.c	2004-10-20 19:50:45.000000000 +0200
+++ 3.5/gcc/gcc/c-common.c	2004-10-20 21:53:36.000000000 +0200
@@ -45,6 +45,7 @@
 #include "tree-iterator.h"
 #include "hashtab.h"
 #include "tree-mudflap.h"
+#include "tree-gimple.h"
 #include "opts.h"
 
 cpp_reader *parse_in;		/* Declared in c-pragma.h.  */
@@ -518,6 +519,7 @@
 static int constant_fits_type_p (tree, tree);
 static tree check_case_value (tree);
 static bool check_case_bounds (tree, tree, tree *, tree *);
+static void emit_local_var (tree);
 
 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
@@ -3620,7 +3622,7 @@
     }
 
   /* Add a CASE_LABEL to the statement-tree.  */
-  case_label = add_stmt (build_case_label (low_value, high_value, label));
+  case_label = add_stmt (build_stmt (CASE_LABEL_EXPR, low_value, high_value, label));
   /* Register this case label in the splay tree.  */
   splay_tree_insert (cases,
 		     (splay_tree_key) low_value,
@@ -5646,4 +5648,152 @@
   return convert (size_type_node, fold_offsetof_1 (expr));
 }
 
+
+
+/* Create an empty statement tree rooted at T.  */
+
+tree
+push_stmt_list (void)
+{
+  tree t;
+  t = alloc_stmt_list ();
+  TREE_CHAIN (t) = cur_stmt_list;
+  cur_stmt_list = t;
+  return t;
+}
+
+/* Finish the statement tree rooted at T.  */
+
+tree
+pop_stmt_list (tree t)
+{
+  tree u = cur_stmt_list, chain;
+
+  /* Pop statement lists until we reach the target level.  The extra
+     nestings will be due to outstanding cleanups.  */
+  while (1)
+    {
+      chain = TREE_CHAIN (u);
+      TREE_CHAIN (u) = NULL_TREE;
+      if (t == u)
+	break;
+      u = chain;
+    }
+  cur_stmt_list = chain;
+
+  /* If the statement list is completely empty, just return it.  This is
+     just as good small as build_empty_stmt, with the advantage that 
+     statement lists are merged when they appended to one another.  So
+     using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
+     statements.  */
+  if (TREE_SIDE_EFFECTS (t))
+    {
+      tree_stmt_iterator i = tsi_start (t);
+
+      /* If the statement list contained exactly one statement, then
+	 extract it immediately.  */
+      if (tsi_one_before_end_p (i))
+	{
+	  u = tsi_stmt (i);
+	  tsi_delink (&i);
+	  free_stmt_list (t);
+	  t = u;
+	}
+    }
+
+  return t;
+}
+
+/* T is a statement.  Add it to the statement-tree.  */
+
+tree
+add_stmt (tree t)
+{
+  enum tree_code code = TREE_CODE (t);
+
+  if ((EXPR_P (t) || STATEMENT_CODE_P (code)) && code != LABEL_EXPR)
+    {
+      if (!EXPR_HAS_LOCATION (t))
+	SET_EXPR_LOCATION (t, input_location);
+
+      /* When we expand a statement-tree, we must know whether or not the
+	 statements are full-expressions.  We record that fact here.  */
+      STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
+    }
+
+  if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
+    STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
+
+  /* Add T to the statement-tree.  Non-side-effect statements need to be
+     recorded during statement expressions.  */
+  append_to_statement_list_force (t, &cur_stmt_list);
+
+  return t;
+}
+
+/* Build a generic statement based on the given type of node and
+   arguments. Similar to `build_nt', except that we set
+   EXPR_LOCATION to be the current source location.  */
+/* ??? This should be obsolete with the lineno_stmt productions
+   in the grammar.  */
+
+tree
+build_stmt (enum tree_code code, ...)
+{
+  tree ret;
+  int length, i;
+  va_list p;
+  bool side_effects;
+
+  va_start (p, code);
+
+  ret = make_node (code);
+  TREE_TYPE (ret) = void_type_node;
+  length = TREE_CODE_LENGTH (code);
+  SET_EXPR_LOCATION (ret, input_location);
+
+  /* Most statements have implicit side effects all on their own, 
+     such as control transfer.  For those that do, we'll compute
+     the real value of TREE_SIDE_EFFECTS from its arguments.  */
+  switch (code)
+    {
+    case EXPR_STMT:
+      side_effects = false;
+      break;
+    default:
+      side_effects = true;
+      break;
+    }
+
+  for (i = 0; i < length; i++)
+    {
+      tree t = va_arg (p, tree);
+      if (t && IS_NON_TYPE_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (t))))
+        side_effects |= TREE_SIDE_EFFECTS (t);
+      TREE_OPERAND (ret, i) = t;
+    }
+
+  TREE_SIDE_EFFECTS (ret) = side_effects;
+
+  va_end (p);
+  return ret;
+}
+
+/* Let the back-end know about DECL.  */
+
+void
+emit_local_var (tree decl)
+{
+  /* Create RTL for this variable.  */
+  if (!DECL_RTL_SET_P (decl))
+    {
+      if (DECL_HARD_REGISTER (decl))
+	/* The user specified an assembler name for this variable.
+	   Set that up now.  */
+	rest_of_decl_compilation (decl, 0, 0);
+      else
+	expand_decl (decl);
+    }
+}
+
 #include "gt-c-common.h"
diff -u 3.5/gcc-save/gcc/c-common.h 3.5/gcc/gcc/c-common.h
--- 3.5/gcc-save/gcc/c-common.h	2004-10-20 19:50:45.000000000 +0200
+++ 3.5/gcc/gcc/c-common.h	2004-10-20 21:53:23.000000000 +0200
@@ -295,7 +295,6 @@
 extern int yyparse (void);
 extern stmt_tree current_stmt_tree (void);
 extern tree push_stmt_list (void);
-extern tree re_push_stmt_list (tree);
 extern tree pop_stmt_list (tree);
 extern tree add_stmt (tree);
 extern void push_cleanup (tree, tree, bool);
@@ -795,12 +794,8 @@
 #define CLEAR_DECL_C_BIT_FIELD(NODE) \
   (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) = 0)
 
-extern void emit_local_var (tree);
 extern tree do_case (tree, tree);
 extern tree build_stmt (enum tree_code, ...);
-extern tree build_case_label (tree, tree, tree);
-extern tree build_continue_stmt (void);
-extern tree build_break_stmt (void);
 
 /* These functions must be defined by each front-end which implements
    a variant of the C language.  They are used in c-common.c.  */
diff -u 3.5/gcc-save/gcc/c-semantics.c 3.5/gcc/gcc/c-semantics.c
--- 3.5/gcc-save/gcc/c-semantics.c	2004-10-20 19:50:46.000000000 +0200
+++ 3.5/gcc/gcc/c-semantics.c	2004-10-20 19:57:27.000000000 +0200
@@ -26,215 +26,3 @@
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
-#include "function.h"
-#include "splay-tree.h"
-#include "varray.h"
-#include "c-common.h"
-#include "except.h"
-/* In order for the format checking to accept the C frontend
-   diagnostic framework extensions, you must define this token before
-   including toplev.h.  */
-#define GCC_DIAG_STYLE __gcc_cdiag__
-#include "toplev.h"
-#include "flags.h"
-#include "ggc.h"
-#include "rtl.h"
-#include "output.h"
-#include "timevar.h"
-#include "predict.h"
-#include "tree-inline.h"
-#include "tree-gimple.h"
-#include "langhooks.h"
-
-/* Create an empty statement tree rooted at T.  */
-
-tree
-push_stmt_list (void)
-{
-  tree t;
-  t = alloc_stmt_list ();
-  TREE_CHAIN (t) = cur_stmt_list;
-  cur_stmt_list = t;
-  return t;
-}
-
-/* Similarly, except that T may have already been pushed/popped, and
-   thus may already contain statement(s).  Arrage for new statements
-   to be appended.  */
-
-tree
-re_push_stmt_list (tree t)
-{
-  if (t)
-    {
-      if (TREE_CODE (t) != STATEMENT_LIST)
-	{
-	  tree u = alloc_stmt_list ();
-	  append_to_statement_list_force (t, &u);
-	  t = u;
-	}
-    }
-  else
-    t = alloc_stmt_list ();
-  TREE_CHAIN (t) = cur_stmt_list;
-  cur_stmt_list = t;
-  return t;
-}
-
-/* Finish the statement tree rooted at T.  */
-
-tree
-pop_stmt_list (tree t)
-{
-  tree u = cur_stmt_list, chain;
-
-  /* Pop statement lists until we reach the target level.  The extra
-     nestings will be due to outstanding cleanups.  */
-  while (1)
-    {
-      chain = TREE_CHAIN (u);
-      TREE_CHAIN (u) = NULL_TREE;
-      if (t == u)
-	break;
-      u = chain;
-    }
-  cur_stmt_list = chain;
-
-  /* If the statement list is completely empty, just return it.  This is
-     just as good small as build_empty_stmt, with the advantage that 
-     statement lists are merged when they appended to one another.  So
-     using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
-     statements.  */
-  if (TREE_SIDE_EFFECTS (t))
-    {
-      tree_stmt_iterator i = tsi_start (t);
-
-      /* If the statement list contained exactly one statement, then
-	 extract it immediately.  */
-      if (tsi_one_before_end_p (i))
-	{
-	  u = tsi_stmt (i);
-	  tsi_delink (&i);
-	  free_stmt_list (t);
-	  t = u;
-	}
-    }
-
-  return t;
-}
-
-/* T is a statement.  Add it to the statement-tree.  */
-
-tree
-add_stmt (tree t)
-{
-  enum tree_code code = TREE_CODE (t);
-
-  if ((EXPR_P (t) || STATEMENT_CODE_P (code)) && code != LABEL_EXPR)
-    {
-      if (!EXPR_HAS_LOCATION (t))
-	SET_EXPR_LOCATION (t, input_location);
-
-      /* When we expand a statement-tree, we must know whether or not the
-	 statements are full-expressions.  We record that fact here.  */
-      STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
-    }
-
-  if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
-    STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
-
-  /* Add T to the statement-tree.  Non-side-effect statements need to be
-     recorded during statement expressions.  */
-  append_to_statement_list_force (t, &cur_stmt_list);
-
-  return t;
-}
-
-/* Build a generic statement based on the given type of node and
-   arguments. Similar to `build_nt', except that we set
-   EXPR_LOCATION to be the current source location.  */
-/* ??? This should be obsolete with the lineno_stmt productions
-   in the grammar.  */
-
-tree
-build_stmt (enum tree_code code, ...)
-{
-  tree ret;
-  int length, i;
-  va_list p;
-  bool side_effects;
-
-  va_start (p, code);
-
-  ret = make_node (code);
-  TREE_TYPE (ret) = void_type_node;
-  length = TREE_CODE_LENGTH (code);
-  SET_EXPR_LOCATION (ret, input_location);
-
-  /* Most statements have implicit side effects all on their own, 
-     such as control transfer.  For those that do, we'll compute
-     the real value of TREE_SIDE_EFFECTS from its arguments.  */
-  switch (code)
-    {
-    case EXPR_STMT:
-      side_effects = false;
-      break;
-    default:
-      side_effects = true;
-      break;
-    }
-
-  for (i = 0; i < length; i++)
-    {
-      tree t = va_arg (p, tree);
-      if (t && IS_NON_TYPE_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (t))))
-        side_effects |= TREE_SIDE_EFFECTS (t);
-      TREE_OPERAND (ret, i) = t;
-    }
-
-  TREE_SIDE_EFFECTS (ret) = side_effects;
-
-  va_end (p);
-  return ret;
-}
-
-/* Let the back-end know about DECL.  */
-
-void
-emit_local_var (tree decl)
-{
-  /* Create RTL for this variable.  */
-  if (!DECL_RTL_SET_P (decl))
-    {
-      if (DECL_HARD_REGISTER (decl))
-	/* The user specified an assembler name for this variable.
-	   Set that up now.  */
-	rest_of_decl_compilation (decl, 0, 0);
-      else
-	expand_decl (decl);
-    }
-}
-
-/* Build a break statement node and return it.  */
-
-tree
-build_break_stmt (void)
-{
-  return (build_stmt (BREAK_STMT));
-}
-
-/* Build a continue statement node and return it.  */
-
-tree
-build_continue_stmt (void)
-{
-  return (build_stmt (CONTINUE_STMT));
-}
-
-/* Create a CASE_LABEL_EXPR tree node and return it.  */
-
-tree
-build_case_label (tree low_value, tree high_value, tree label_decl)
-{
-  return build_stmt (CASE_LABEL_EXPR, low_value, high_value, label_decl);
-}
diff -u 3.5/gcc-save/gcc/cp/Make-lang.in 3.5/gcc/gcc/cp/Make-lang.in
--- 3.5/gcc-save/gcc/cp/Make-lang.in	2004-10-20 19:50:54.000000000 +0200
+++ 3.5/gcc/gcc/cp/Make-lang.in	2004-10-20 19:57:37.000000000 +0200
@@ -71,7 +71,7 @@
 
 # The compiler itself.
 # Shared with C front end:
-CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-semantics.o c-lex.o \
+CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-lex.o \
 	c-dump.o $(CXX_TARGET_OBJS) c-pretty-print.o c-opts.o c-pch.o \
 	c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
 	c-gimplify.o tree-inline.o
diff -u 3.5/gcc-save/gcc/cp/decl.c 3.5/gcc/gcc/cp/decl.c
--- 3.5/gcc-save/gcc/cp/decl.c	2004-10-20 19:50:54.000000000 +0200
+++ 3.5/gcc/gcc/cp/decl.c	2004-10-20 21:54:00.000000000 +0200
@@ -2500,7 +2500,7 @@
       /* For templates, just add the case label; we'll do semantic
 	 analysis at instantiation-time.  */
       label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
-      return add_stmt (build_case_label (low_value, high_value, label));
+      return add_stmt (build_stmt (CASE_LABEL_EXPR, low_value, high_value, label));
     }
 
   /* Find the condition on which this switch statement depends.  */
diff -u 3.5/gcc-save/gcc/cp/semantics.c 3.5/gcc/gcc/cp/semantics.c
--- 3.5/gcc-save/gcc/cp/semantics.c	2004-10-20 19:50:54.000000000 +0200
+++ 3.5/gcc/gcc/cp/semantics.c	2004-10-20 21:53:42.000000000 +0200
@@ -835,7 +835,7 @@
 tree
 finish_break_stmt (void)
 {
-  return add_stmt (build_break_stmt ());
+  return add_stmt (build_stmt (BREAK_STMT));
 }
 
 /* Finish a continue-statement.  */
@@ -843,7 +843,7 @@
 tree
 finish_continue_stmt (void)
 {
-  return add_stmt (build_continue_stmt ());
+  return add_stmt (build_stmt (CONTINUE_STMT));
 }
 
 /* Begin a switch-statement.  Returns a new SWITCH_STMT if

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