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 to add expr_first and expr_length


To go with my earlier patch for expr_last.

Booted and tested athlon-pc-linux-gnu, applied to trunk and tree-ssa.

2003-05-27  Jason Merrill  <jason@redhat.com>

	* tree.c (expr_first, expr_length): New fns.
	* tree.h: Declare them.

*** tree.c.~1~	2003-05-24 14:56:05.000000000 -0400
--- tree.c	2003-05-27 10:31:48.000000000 -0400
*************** tree_cons (purpose, value, chain)
*** 1149,1159 ****
    return node;
  }
  
  /* Return the last expression in a sequence of COMPOUND_EXPRs.  */
  
  tree
! expr_last (expr)
!      tree expr;
  {
    if (expr == NULL_TREE)
      return expr;
--- 1149,1170 ----
    return node;
  }
  
+ /* Return the first expression in a sequence of COMPOUND_EXPRs.  */
+ 
+ tree
+ expr_first (tree expr)
+ {
+   if (expr == NULL_TREE)
+     return expr;
+   while (TREE_CODE (expr) == COMPOUND_EXPR)
+     expr = TREE_OPERAND (expr, 0);
+   return expr;
+ }
+ 
  /* Return the last expression in a sequence of COMPOUND_EXPRs.  */
  
  tree
! expr_last (tree expr)
  {
    if (expr == NULL_TREE)
      return expr;
*************** expr_last (expr)
*** 1161,1166 ****
--- 1172,1192 ----
      expr = TREE_OPERAND (expr, 1);
    return expr;
  }
+ 
+ /* Return the number of subexpressions in a sequence of COMPOUND_EXPRs.  */
+ 
+ int
+ expr_length (tree expr)
+ {
+   int len = 0;
+   
+   if (expr == NULL_TREE)
+     return 0;
+   for (; TREE_CODE (expr) == COMPOUND_EXPR; expr = TREE_OPERAND (expr, 1))
+     len += expr_length (TREE_OPERAND (expr, 0));
+   ++len;
+   return len;
+ }
  
  /* Return the size nominally occupied by an object of type TYPE
     when it resides in memory.  The value is measured in units of bytes,
*** tree.h.~1~	2003-05-24 14:56:05.000000000 -0400
--- tree.h	2003-05-27 10:13:45.000000000 -0400
*************** extern tree pedantic_non_lvalue		PARAMS 
*** 2863,2869 ****
--- 2863,2871 ----
  
  extern tree convert			PARAMS ((tree, tree));
  extern unsigned int expr_align		PARAMS ((tree));
+ extern tree expr_first			PARAMS ((tree));
  extern tree expr_last			PARAMS ((tree));
+ extern int expr_length			PARAMS ((tree));
  extern tree size_in_bytes		PARAMS ((tree));
  extern HOST_WIDE_INT int_size_in_bytes	PARAMS ((tree));
  extern tree bit_position		PARAMS ((tree));

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