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 RFA: Split up add_stmt into C and C++ versions


The function add_stmt is currently shared by the C and C++ versions.
It does one thing that is only need by the C++ frontend: it sets
STMT_IS_FULL_EXPR_P (which requires a function call).  It does one
thing which is only needed by the C frontend: it sets
STATEMENT_LIST_HAS_LABEL (which does not require a function call).

The shared part of add_stmt is also minor: a call to SET_EXPR_LOCATION
and a call to append_to_statement_list_force.

This patch creates two versions of add_stmt: one for the C frontend
and one for the C++ frontend.  It moves STMT_IS_FULL_EXPR_P into the
C++ frontend.

I like this patch, but I can understand why people might object.
Moving STMT_IS_FULL_EXPR_P into the C++ frontend is a clear minor win
for the C frontend.  Creating two versions of add_stmt, on the other
hand, is obviously not ideal.

This patch has been tested with C/C++/ObjC bootstrap and testsuite run
on i686-pc-linux-gnu.

OK for mainline?

Ian


./ChangeLog:
2005-05-26  Ian Lance Taylor  <ian@airs.com>

	* c-decl.c (add_stmt): Add C frontend specific version.
	(stmts_are_full_exprs_p): Remove.
	* c-common.h (STMT_IS_FULL_EXPR_P): Remove.
	(stmts_are_full_exprs_p): Don't declare.
	* c-semantics.c (add_stmt): Remove.

cp/ChangeLog:
2005-05-26  Ian Lance Taylor  <ian@airs.com>

	* semantics.c (add_stmt): Add C++ frontend specific version.
	* cp-tree.h (STMT_IS_FULL_EXPR_P): Define.
	(stmts_are_full_exprs_p): Declare.


Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.293
diff -p -u -r1.293 c-common.h
--- c-common.h	24 May 2005 22:24:28 -0000	1.293
+++ c-common.h	26 May 2005 19:29:34 -0000
@@ -31,7 +31,6 @@ Software Foundation, 59 Temple Place - S
       IDENTIFIER_MARKED (used by search routines).
       DECL_PRETTY_FUNCTION_P (in VAR_DECL)
    1: C_DECLARED_LABEL_FLAG (in LABEL_DECL)
-      STMT_IS_FULL_EXPR_P (in _STMT)
       STATEMENT_LIST_STMT_EXPR (in STATEMENT_LIST)
    2: unused
    3: STATEMENT_LIST_HAS_LABEL (in STATEMENT_LIST)
@@ -704,12 +703,6 @@ extern void finish_file	(void);
 
 /* These macros provide convenient access to the various _STMT nodes.  */
 
-/* Nonzero if this statement should be considered a full-expression,
-   i.e., if temporaries created during this statement should have
-   their destructors run at the end of this statement.  (In C, this
-   will always be false, since there are no destructors.)  */
-#define STMT_IS_FULL_EXPR_P(NODE) TREE_LANG_FLAG_1 ((NODE))
-
 /* Nonzero if a given STATEMENT_LIST represents the outermost binding
    if a statement expression.  */
 #define STATEMENT_LIST_STMT_EXPR(NODE) \
@@ -735,7 +728,6 @@ enum c_tree_code {
 
 #undef DEFTREECODE
 
-extern int stmts_are_full_exprs_p (void);
 extern int anon_aggr_type_p (tree);
 
 /* For a VAR_DECL that is an anonymous union, these are the various
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.659
diff -p -u -r1.659 c-decl.c
--- c-decl.c	25 May 2005 04:16:32 -0000	1.659
+++ c-decl.c	26 May 2005 19:29:36 -0000
@@ -418,6 +418,31 @@ static tree grokdeclarator (const struct
 static tree grokparms (struct c_arg_info *, bool);
 static void layout_array_type (tree);
 
+/* T is a statement.  Add it to the statement-tree.  This is the
+   C/ObjC version--C++ has a slightly different version of this
+   function.  */
+
+tree
+add_stmt (tree t)
+{
+  enum tree_code code = TREE_CODE (t);
+
+  if (EXPR_P (t) && code != LABEL_EXPR)
+    {
+      if (!EXPR_HAS_LOCATION (t))
+	SET_EXPR_LOCATION (t, input_location);
+    }
+
+  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;
+}
+
 /* States indicating how grokdeclarator() should handle declspecs marked
    with __attribute__((deprecated)).  An object declared as
    __attribute__((deprecated)) suppresses warnings of uses of other
@@ -6717,16 +6742,6 @@ c_dup_lang_specific_decl (tree decl)
    functions are not called from anywhere in the C front end, but as
    these changes continue, that will change.  */
 
-/* Returns nonzero if the current statement is a full expression,
-   i.e. temporaries created during that statement should be destroyed
-   at the end of the statement.  */
-
-int
-stmts_are_full_exprs_p (void)
-{
-  return 0;
-}
-
 /* Returns the stmt_tree (if any) to which statements are currently
    being added.  If there is no active statement-tree, NULL is
    returned.  */
Index: c-semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-semantics.c,v
retrieving revision 1.98
diff -p -u -r1.98 c-semantics.c
--- c-semantics.c	27 Apr 2005 18:06:04 -0000	1.98
+++ c-semantics.c	26 May 2005 19:29:36 -0000
@@ -101,33 +101,6 @@ pop_stmt_list (tree t)
   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) && 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.  */
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.1138
diff -p -u -r1.1138 cp-tree.h
--- cp/cp-tree.h	25 May 2005 22:08:16 -0000	1.1138
+++ cp/cp-tree.h	26 May 2005 19:29:37 -0000
@@ -59,6 +59,7 @@ struct diagnostic_context;
       ICS_ELLIPSIS_FLAG (in _CONV)
       DECL_INITIALIZED_P (in VAR_DECL)
       TYPENAME_IS_CLASS_P (in TYPENAME_TYPE)
+      STMT_IS_FULL_EXPR_P (in _STMT)
    2: IDENTIFIER_OPNAME_P (in IDENTIFIER_NODE)
       ICS_THIS_FLAG (in _CONV)
       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (in VAR_DECL)
@@ -259,6 +260,12 @@ typedef struct ptrmem_cst * ptrmem_cst_t
 #define STATEMENT_LIST_TRY_BLOCK(NODE) \
   TREE_LANG_FLAG_2 (STATEMENT_LIST_CHECK (NODE))
 
+/* Nonzero if this statement should be considered a full-expression,
+   i.e., if temporaries created during this statement should have
+   their destructors run at the end of this statement.  (In C, this
+   will always be false, since there are no destructors.)  */
+#define STMT_IS_FULL_EXPR_P(NODE) TREE_LANG_FLAG_1 ((NODE))
+
 /* Marks the result of a statement expression.  */
 #define EXPR_STMT_STMT_EXPR_RESULT(NODE) \
   TREE_LANG_FLAG_0 (EXPR_STMT_CHECK (NODE))
@@ -4063,6 +4070,7 @@ extern tree get_deferred_access_checks		
 extern void pop_to_parent_deferring_access_checks	(void);
 extern void perform_deferred_access_checks	(void);
 extern void perform_or_defer_access_check	(tree, tree);
+extern int stmts_are_full_exprs_p		(void);
 extern void init_cp_semantics                   (void);
 extern tree do_poplevel				(tree);
 extern void add_decl_expr			(tree);
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.472
diff -p -u -r1.472 semantics.c
--- cp/semantics.c	25 May 2005 09:47:18 -0000	1.472
+++ cp/semantics.c	26 May 2005 19:29:38 -0000
@@ -340,6 +340,32 @@ stmts_are_full_exprs_p (void)
   return current_stmt_tree ()->stmts_are_full_exprs_p;
 }
 
+/* T is a statement.  Add it to the statement-tree.  This is the C++
+   version.  The C/ObjC frontends have a slightly different version of
+   this function.  */
+
+tree
+add_stmt (tree t)
+{
+  enum tree_code code = TREE_CODE (t);
+
+  if (EXPR_P (t) && 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 ();
+    }
+
+  /* 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;
+}
+
 /* Returns the stmt_tree (if any) to which statements are currently
    being added.  If there is no active statement-tree, NULL is
    returned.  */


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