public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Froyd <froydnj@codesourcery.com>
To: gcc-patches@gcc.gnu.org
Cc: Nathan Froyd <froydnj@codesourcery.com>
Subject: [PATCH 08/18] convert cp *FOR_STMTs to use private scope fields
Date: Fri, 11 Mar 2011 04:24:00 -0000	[thread overview]
Message-ID: <1299817406-16745-9-git-send-email-froydnj@codesourcery.com> (raw)
In-Reply-To: <1299817406-16745-1-git-send-email-froydnj@codesourcery.com>

C++'s FOR_STMT and RANGE_FOR_STMT store the scope in which they occur in
the TREE_CHAIN field of tree_exp.  If we're going to remove TREE_CHAIN,
that won't work very well.  This patch introduces an extra tree operand
to both tree kinds, accessor macros for those operands, and tweaks the
code to use those macros instead of TREE_CHAIN.  The end result is nicer
code and less reliance on TREE_CHAIN.

-Nathan

gcc/cp/
	* cp-tree.def (FOR_STMT, RANGE_FOR_STMT): Add an extra operand.
	* cp-objcp-common.c (cp_common_init_ts): Mark them as TS_TYPED.
	* cp-tree.h (FOR_SCOPE, RANGE_FOR_SCOPE): Define.
	* semantics.c (begin_for_stmt): Pass an extra arg to build_stmt.
	Use FOR_SCOPE instead of TREE_CHAIN.
	(begin_range_for_stmt): Likewise, with RANGE_FOR_SCOPE.
	(finish_for_stmt): Likewise.

diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c
index 66d2d27..21fa57f 100644
--- a/gcc/cp/cp-objcp-common.c
+++ b/gcc/cp/cp-objcp-common.c
@@ -234,7 +234,6 @@ cp_common_init_ts (void)
   MARK_TS_COMMON (TEMPLATE_PARM_INDEX);
   MARK_TS_COMMON (OVERLOAD);
   MARK_TS_COMMON (TEMPLATE_INFO);
-  MARK_TS_COMMON (FOR_STMT);
   MARK_TS_COMMON (TYPENAME_TYPE);
   MARK_TS_COMMON (TYPEOF_TYPE);
   MARK_TS_COMMON (IF_STMT);
@@ -245,8 +244,9 @@ cp_common_init_ts (void)
   MARK_TS_COMMON (DECLTYPE_TYPE);
   MARK_TS_COMMON (BOUND_TEMPLATE_TEMPLATE_PARM);
   MARK_TS_COMMON (UNBOUND_CLASS_TEMPLATE);
-  MARK_TS_COMMON (RANGE_FOR_STMT);
 
+  MARK_TS_TYPED (FOR_STMT);
+  MARK_TS_TYPED (RANGE_FOR_STMT);
   MARK_TS_TYPED (AGGR_INIT_EXPR);
   MARK_TS_TYPED (EXPR_STMT);
   MARK_TS_TYPED (EH_SPEC_BLOCK);
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index 509d5e7..fdfe9b5 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -291,12 +291,12 @@ DEFTREECODE (IF_STMT, "if_stmt", tcc_statement, 3)
 
 /* Used to represent a `for' statement. The operands are
    FOR_INIT_STMT, FOR_COND, FOR_EXPR, and FOR_BODY, respectively.  */
-DEFTREECODE (FOR_STMT, "for_stmt", tcc_statement, 4)
+DEFTREECODE (FOR_STMT, "for_stmt", tcc_statement, 5)
 
 /* Used to represent a range-based `for' statement. The operands are
-   RANGE_FOR_DECL, RANGE_FOR_EXPR, RANGE_FOR_BODY, respectively.  Only used
-   in templates.  */
-DEFTREECODE (RANGE_FOR_STMT, "range_for_stmt", tcc_statement, 3)
+   RANGE_FOR_DECL, RANGE_FOR_EXPR, RANGE_FOR_BODY, and RANGE_FOR_SCOPE,
+   respectively.  Only used in templates.  */
+DEFTREECODE (RANGE_FOR_STMT, "range_for_stmt", tcc_statement, 4)
 
 /* Used to represent a 'while' statement. The operands are WHILE_COND
    and WHILE_BODY, respectively.  */
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 1783915..e542388 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -3799,12 +3799,14 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
 #define FOR_COND(NODE)		TREE_OPERAND (FOR_STMT_CHECK (NODE), 1)
 #define FOR_EXPR(NODE)		TREE_OPERAND (FOR_STMT_CHECK (NODE), 2)
 #define FOR_BODY(NODE)		TREE_OPERAND (FOR_STMT_CHECK (NODE), 3)
+#define FOR_SCOPE(NODE)		TREE_OPERAND (FOR_STMT_CHECK (NODE), 4)
 
 /* RANGE_FOR_STMT accessors. These give access to the declarator,
-   expression and body of the statement, respectively.  */
+   expression, body, and scope of the statement, respectively.  */
 #define RANGE_FOR_DECL(NODE)	TREE_OPERAND (RANGE_FOR_STMT_CHECK (NODE), 0)
 #define RANGE_FOR_EXPR(NODE)	TREE_OPERAND (RANGE_FOR_STMT_CHECK (NODE), 1)
 #define RANGE_FOR_BODY(NODE)	TREE_OPERAND (RANGE_FOR_STMT_CHECK (NODE), 2)
+#define RANGE_FOR_SCOPE(NODE)	TREE_OPERAND (RANGE_FOR_STMT_CHECK (NODE), 3)
 
 #define SWITCH_STMT_COND(NODE)	TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 0)
 #define SWITCH_STMT_BODY(NODE)	TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 1)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 4af007d..c8e5619 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -856,7 +856,7 @@ begin_for_stmt (tree scope, tree init)
   tree r;
 
   r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
-		  NULL_TREE, NULL_TREE);
+		  NULL_TREE, NULL_TREE, NULL_TREE);
 
   if (scope == NULL_TREE)
     {
@@ -865,7 +865,7 @@ begin_for_stmt (tree scope, tree init)
 	scope = begin_for_scope (&init);
     }
   FOR_INIT_STMT (r) = init;
-  TREE_CHAIN (r) = scope;
+  FOR_SCOPE (r) = scope;
 
   return r;
 }
@@ -940,8 +940,12 @@ finish_for_stmt (tree for_stmt)
   /* Pop the scope for the body of the loop.  */
   if (flag_new_for_scope > 0)
     {
-      tree scope = TREE_CHAIN (for_stmt);
-      TREE_CHAIN (for_stmt) = NULL;
+      tree scope;
+      tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
+			 ? &RANGE_FOR_SCOPE (for_stmt)
+			 : &FOR_SCOPE (for_stmt));
+      scope = *scope_ptr;
+      *scope_ptr = NULL;
       add_stmt (do_poplevel (scope));
     }
 
@@ -959,7 +963,7 @@ begin_range_for_stmt (tree scope, tree init)
   tree r;
 
   r = build_stmt (input_location, RANGE_FOR_STMT,
-		  NULL_TREE, NULL_TREE, NULL_TREE);
+		  NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
 
   if (scope == NULL_TREE)
     {
@@ -972,7 +976,7 @@ begin_range_for_stmt (tree scope, tree init)
      pop it now.  */
   if (init)
     pop_stmt_list (init);
-  TREE_CHAIN (r) = scope;
+  RANGE_FOR_SCOPE (r) = scope;
 
   return r;
 }
-- 
1.7.0.4

  parent reply	other threads:[~2011-03-11  4:24 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-11  4:23 [4.7 PATCH 00/18] slim down a number of tree nodes Nathan Froyd
2011-03-11  4:23 ` [PATCH 04/18] remove TREE_CHAIN from SSA_NAME nodes Nathan Froyd
2011-03-11 13:06   ` Richard Guenther
2011-03-11  4:23 ` [PATCH 05/18] remove TREE_CHAIN from CONSTRUCTOR nodes Nathan Froyd
2011-03-11 13:05   ` Richard Guenther
2011-03-11  4:24 ` [PATCH 14/18] move TS_STATEMENT_LIST to be a substructure of TS_TYPED Nathan Froyd
2011-03-11  6:01   ` Jason Merrill
2011-03-11 12:23     ` Nathan Froyd
2011-03-11  4:24 ` [PATCH 07/18] generalize build_case_label to the rest of the compiler Nathan Froyd
2011-03-11 13:01   ` Joseph S. Myers
2011-03-11 13:10     ` Richard Guenther
2011-03-11 14:56   ` Tom Tromey
2011-03-11  4:24 ` [PATCH 03/18] remove TREE_CHAIN from *_CST nodes Nathan Froyd
2011-03-11 13:05   ` Richard Guenther
2011-03-11  4:24 ` [PATCH 16/18] make TS_IDENTIFIER be a substructure of TS_BASE Nathan Froyd
2011-03-11 13:12   ` Richard Guenther
2011-03-11 17:21     ` Nathan Froyd
2011-03-11  4:24 ` [PATCH 15/18] move REAL_IDENTIFIER_TYPE_VALUE to be a field of lang_identifier Nathan Froyd
2011-03-11 13:40   ` Jason Merrill
2011-03-11 14:04     ` Nathan Froyd
2011-03-11 14:20       ` Nathan Froyd
2011-03-11 15:04         ` Jason Merrill
2011-03-11 16:23           ` Nathan Froyd
2011-03-11 17:17             ` Jason Merrill
2011-03-11 14:41     ` Joseph S. Myers
2011-03-11  4:24 ` [PATCH 10/18] convert cp SWITCH_STMTs to use private scope fields Nathan Froyd
2011-03-11  4:24 ` [PATCH 13/18] move TS_EXP to be a substructure of TS_TYPED Nathan Froyd
2011-05-11  0:34   ` Nathan Froyd
2011-05-17 17:51     ` [PING][PATCH " Nathan Froyd
2011-05-23 14:58       ` Nathan Froyd
2011-05-23 15:34         ` Richard Guenther
2011-05-24 18:52           ` Nathan Froyd
2011-05-25  9:59             ` Richard Guenther
2011-03-11  4:24 ` [PATCH 01/18] add typed_tree structure Nathan Froyd
2011-03-11 13:05   ` Richard Guenther
2011-03-11 15:21   ` Michael Matz
2011-03-11  4:24 ` Nathan Froyd [this message]
2011-03-11  4:24 ` [PATCH 06/18] define CASE_CHAIN accessor for CASE_LABEL_EXPR Nathan Froyd
2011-03-11 13:07   ` Richard Guenther
2011-03-11  4:30 ` [PATCH 09/18] convert cp IF_STMTs to use private scope fields Nathan Froyd
2011-03-11  4:30 ` [PATCH 11/18] mark EXPR_PACK_EXPANSION as typed only Nathan Froyd
2011-03-11  4:31 ` [PATCH 18/18] make TS_BLOCK a substructure of TS_BASE Nathan Froyd
2011-05-26 18:30   ` Nathan Froyd
2011-03-11  4:31 ` [PATCH 02/18] enforce TREE_CHAIN and TREE_TYPE accesses Nathan Froyd
2011-03-11  8:12   ` Mike Stump
2011-03-11 13:21   ` Richard Guenther
2011-03-11 15:24   ` Tom Tromey
2011-03-12 12:13   ` Eric Botcazou
2011-03-21 13:50     ` Nathan Froyd
2011-03-21 17:50       ` Eric Botcazou
2011-04-13  2:43   ` Nathan Froyd
2011-04-13  2:57     ` Diego Novillo
2011-04-13  4:02     ` Ian Lance Taylor
2011-03-11  4:31 ` [PATCH 17/18] introduce block_chainon and use BLOCK_CHAIN more Nathan Froyd
2011-03-11 13:15   ` Richard Guenther
2011-03-11 13:19     ` Nathan Froyd
2011-03-11 15:14   ` Tom Tromey
2011-03-12 12:23   ` Eric Botcazou
2011-03-11  4:50 ` [PATCH 12/18] make CASE_LABEL_EXPR not abuse TREE_CHAIN Nathan Froyd
2011-03-11 13:19   ` Richard Guenther
2011-05-10 20:08     ` Nathan Froyd
2011-05-10 20:19     ` Diego Novillo
2011-05-11  9:21       ` Richard Guenther
2011-05-11 19:22   ` H.J. Lu
2011-03-11  8:18 ` [4.7 PATCH 00/18] slim down a number of tree nodes Mike Stump
2011-03-11 16:00   ` Nathan Froyd
2011-03-11 13:25 ` Richard Guenther
2011-03-11 13:42   ` Nathan Froyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299817406-16745-9-git-send-email-froydnj@codesourcery.com \
    --to=froydnj@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).