On Wed, 16 Dec 2015, Michael Matz wrote:

Hi,

On Mon, 14 Dec 2015, Patrick Palka wrote:

This should use cp_tree_operand_length.
Hmm, I don't immediately see how I can use this function here.  It
expects a tree but I dont have an appropriate tree to give to it, only a
tree_code.

True.  So let's introduce cp_tree_code_length next to cp_tree_operand_length.

Jason



Like this?  Incremental diff followed by patch v4:

Not my turf, but if I may make a suggestion: please use the new function
in the old one instead of duplicating the implementation.

The implementation is not exactly a duplicate since the old function
returns TREE_OPERAND_LENGTH in the default case and the new function
returns TREE_CODE_LENGTH in the default case.

It's still doable though. Defining one in terms of the other would look
like this.  Is this patch OK to commit after testing?

-- 8< --

Subject: [PATCH] Avoid code duplication in cp_tree_[operand|code]_length

gcc/cp/ChangeLog:

        * tree.c (cp_tree_operand_length): Define in terms of
        cp_tree_code_length.
---
 gcc/cp/tree.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 0c0987d..ae176d0 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -4427,23 +4427,10 @@ cp_tree_operand_length (const_tree t)
 {
   enum tree_code code = TREE_CODE (t);

-  switch (code)
-    {
-    case PREINCREMENT_EXPR:
-    case PREDECREMENT_EXPR:
-    case POSTINCREMENT_EXPR:
-    case POSTDECREMENT_EXPR:
-      return 1;
+  if (TREE_CODE_CLASS (code) == tcc_vl_exp)
+    return VL_EXP_OPERAND_LENGTH (t);

-    case ARRAY_REF:
-      return 2;
-
-    case EXPR_PACK_EXPANSION:
-      return 1;
-
-    default:
-      return TREE_OPERAND_LENGTH (t);
-    }
+  return cp_tree_code_length (code);
 }

 /* Like cp_tree_operand_length, but takes a tree_code CODE.  */
--
2.7.0.rc0.50.g1470d8f.dirty





Ciao,
Michael.

Reply via email to