GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

実装[]

 7085 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.  FUNC is
 7086    called with the DATA and the address of each sub-tree.  If FUNC returns a
 7087    non-NULL value, the traversal is stopped, and the value returned by FUNC
 7088    is returned.  If PSET is non-NULL it is used to record the nodes visited,
 7089    and to avoid visiting a node more than once.  */
7090 
7091 tree
7092 walk_tree (tree *tp, walk_tree_fn func, void *data, struct pointer_set_t *pset)
7093 {
7094   enum tree_code code;
7095   int walk_subtrees;
7096   tree result;
7097 

~

&aname(WALK_SUBTREE_TAIL);
7098 #define WALK_SUBTREE_TAIL(NODE)                         \
7099   do                                                    \
7100     {                                                   \
7101        tp = & (NODE);                                   \
7102        goto tail_recurse;                               \
7103     }                                                   \
7104   while (0)
7105 

~

7106  tail_recurse:
 7107   /* Skip empty subtrees.  */
7108   if (!*tp)
7109     return NULL_TREE;
7110 
 7111   /* Don't walk the same tree twice, if the user has requested
 7112      that we avoid doing so.  */
7113   if (pset && pointer_set_insert (pset, *tp))
7114     return NULL_TREE;
7115 

~
*関数を呼び出し値が返ってきたら返す

 7116   /* Call the function.  */
7117   walk_subtrees = 1;
7118   result = (*func) (tp, &walk_subtrees, data);
7119 
 7120   /* If we found something, return it.  */
7121   if (result)
7122     return result;
7123 

~
*次の値をを取りに行き、この関数の始めに戻る

7124   code = TREE_CODE (*tp);
7125 
 7126   /* Even if we didn't, FUNC may have decided that there was nothing
 7127      interesting below this point in the tree.  */
7128   if (!walk_subtrees)
7129     {
7130       if (code == [[TREE_LIST>enum tree_code]])
 7131         /* But we still need to check our siblings.  */
7132         [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (TREE_CHAIN (*tp));
7133       else
7134         return NULL_TREE;
7135     }

~

7136 
7137   result = lang_hooks.tree_inlining.walk_subtrees (tp, &walk_subtrees, func,
7138                                                    data, pset);
7139   if (result || ! walk_subtrees)
7140     return result;
7141 

~

 7142   /* If this is a DECL_EXPR, walk into various fields of the type that it's
 7143      defining.  We only want to walk into these fields of a type in this
 7144      case.  Note that decls get walked as part of the processing of a
 7145      BIND_EXPR.
 7146 
 7147      ??? Precisely which fields of types that we are supposed to walk in
 7148      this case vs. the normal case aren't well defined.  */
7149   if (code == [[DECL_EXPR>enum tree_code]]
7150       && TREE_CODE (DECL_EXPR_DECL (*tp)) == [[TYPE_DECL>enum tree_code]]
7151       && TREE_CODE (TREE_TYPE (DECL_EXPR_DECL (*tp))) != [[ERROR_MARK>enum tree_code]])
7152     {
7153       tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
7154 
 7155       /* Call the function for the type.  See if it returns anything or
 7156          doesn't want us to continue.  If we are to continue, walk both
 7157          the normal fields and those for the declaration case.  */
7158       result = (*func) (type_p, &walk_subtrees, data);
7159       if (result || !walk_subtrees)
7160         return NULL_TREE;
7161 
7162       result = walk_type_fields (*type_p, func, data, pset);
7163       if (result)
7164         return result;
7165 
7166       WALK_SUBTREE (TYPE_SIZE (*type_p));
7167       WALK_SUBTREE (TYPE_SIZE_UNIT (*type_p));
7168 
 7169       /* If this is a record type, also walk the fields.  */
7170       if (TREE_CODE (*type_p) == [[RECORD_TYPE>enum tree_code]]
7171           || TREE_CODE (*type_p) == [[UNION_TYPE>enum tree_code]]
7172           || TREE_CODE (*type_p) == [[QUAL_UNION_TYPE>enum tree_code]])
7173         {
7174           tree field;
7175 
7176           for (field = TYPE_FIELDS (*type_p); field;
7177                field = TREE_CHAIN (field))
7178             {
 7179               /* We'd like to look at the type of the field, but we can easily
 7180                  get infinite recursion.  So assume it's pointed to elsewhere
 7181                  in the tree.  Also, ignore things that aren't fields.  */
7182               if (TREE_CODE (field) != [[FIELD_DECL>enum tree_code]])
7183                 continue;
7184 
7185               WALK_SUBTREE (DECL_FIELD_OFFSET (field));
7186               WALK_SUBTREE (DECL_SIZE (field));
7187               WALK_SUBTREE (DECL_SIZE_UNIT (field));
7188               if (TREE_CODE (*type_p) == [[QUAL_UNION_TYPE>enum tree_code]])
7189                 WALK_SUBTREE (DECL_QUALIFIER (field));
7190             }
7191         }
7192     }

~

7193 
7194   else if (code != [[SAVE_EXPR>enum tree_code]]
7195            && code != [[BIND_EXPR>enum tree_code]]
7196            && IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
7197     {
7198       int i, len;
7199 
 7200       /* Walk over all the sub-trees of this operand.  */
7201       len = TREE_CODE_LENGTH (code);
 7202       /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
 7203          But, we only want to walk once.  */
7204       if (code == [[TARGET_EXPR>enum tree_code]]
7205           && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1))
7206         --len;
7207 
 7208       /* Go through the subtrees.  We need to do this in forward order so
 7209          that the scope of a FOR_EXPR is handled properly.  */
7210 #ifdef DEBUG_WALK_TREE
7211       for (i = 0; i < len; ++i)
7212         WALK_SUBTREE (TREE_OPERAND (*tp, i));
7213 #else
7214       for (i = 0; i < len - 1; ++i)
7215         WALK_SUBTREE (TREE_OPERAND (*tp, i));
7216 
7217       if (len)
7218         {
 7219           /* The common case is that we may tail recurse here.  */
7220           if (code != [[BIND_EXPR>enum tree_code]]
7221               && !TREE_CHAIN (*tp))
7222             [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (TREE_OPERAND (*tp, len - 1));
7223           else
7224             WALK_SUBTREE (TREE_OPERAND (*tp, len - 1));
7225         }
7226 #endif
7227     }

~

7228 
 7229   /* If this is a type, walk the needed fields in the type.  */
7230   else if (TYPE_P (*tp))
7231     {
7232       result = walk_type_fields (*tp, func, data, pset);
7233       if (result)
7234         return result;
7235     }

~

7236   else
7237     {
 7238       /* Not one of the easy cases.  We must explicitly go through the
 7239          children.  */
7240       switch (code)
7241         {
7242         case [[ERROR_MARK>enum tree_code]]:
7243         case [[IDENTIFIER_NODE>enum tree_code]]:
7244         case [[INTEGER_CST>enum tree_code]]:
7245         case [[REAL_CST>enum tree_code]]:
7246         case [[VECTOR_CST>enum tree_code]]:
7247         case [[STRING_CST>enum tree_code]]:
7248         case [[BLOCK>enum tree_code]]:
7249         case [[PLACEHOLDER_EXPR>enum tree_code]]:
7250         case [[SSA_NAME>enum tree_code]]:
7251         case [[FIELD_DECL>enum tree_code]]:
7252         case [[RESULT_DECL>enum tree_code]]:
 7253           /* None of these have subtrees other than those already walked
 7254              above.  */
7255           break;
7256 
7257         case [[TREE_LIST>enum tree_code]]:
7258           WALK_SUBTREE (TREE_VALUE (*tp));
7259           [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (TREE_CHAIN (*tp));
7260           break;
7261 
7262         case [[TREE_VEC>enum tree_code]]:
7263           {
7264             int len = TREE_VEC_LENGTH (*tp);
7265 
7266             if (len == 0)
7267               break;
7268 
 7269             /* Walk all elements but the first.  */
7270             while (--len)
7271               WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
7272 
 7273             /* Now walk the first one as a tail call.  */
7274             [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (TREE_VEC_ELT (*tp, 0));
7275           }
7276 
7277         case [[COMPLEX_CST>enum tree_code]]:
7278           WALK_SUBTREE (TREE_REALPART (*tp));
7279           [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (TREE_IMAGPART (*tp));
7280 
7281         case [[CONSTRUCTOR>enum tree_code]]:
7282           {
7283             unsigned HOST_WIDE_INT idx;
7284             constructor_elt *ce;
7285 
7286             for (idx = 0;
7287                  VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce);
7288                  idx++)
7289               WALK_SUBTREE (ce->value);
7290           }
7291           break;
7292 
7293         case [[SAVE_EXPR>enum tree_code]]:
7294           [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (TREE_OPERAND (*tp, 0));
7295 
7296         case [[BIND_EXPR>enum tree_code]]:
7297           {
7298             tree decl;
7299             for (decl = BIND_EXPR_VARS (*tp); decl; decl = TREE_CHAIN (decl))
7300               {
 7301                 /* Walk the DECL_INITIAL and DECL_SIZE.  We don't want to walk
 7302                    into declarations that are just mentioned, rather than
 7303                    declared; they don't really belong to this part of the tree.
 7304                    And, we can see cycles: the initializer for a declaration
 7305                    can refer to the declaration itself.  */
7306                 WALK_SUBTREE (DECL_INITIAL (decl));
7307                 WALK_SUBTREE (DECL_SIZE (decl));
7308                 WALK_SUBTREE (DECL_SIZE_UNIT (decl));
7309               }
7310             [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]] (BIND_EXPR_BODY (*tp));
7311           }
7312 
7313         case [[STATEMENT_LIST>enum tree_code]]:
7314           {
7315             tree_stmt_iterator i;
7316             for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
7317               WALK_SUBTREE (*tsi_stmt_ptr (i));
7318           }
7319           break;
7320 
7321         default:
 7322           /* ??? This could be a language-defined node.  We really should make
 7323              a hook for it, but right now just ignore it.  */
7324           break;
7325         }
7326     }
7327 

~
*見つからなかった

 7328   /* We didn't find what we were looking for.  */
7329   return NULL_TREE;
7330 
7331 #undef [[WALK_SUBTREE_TAIL>walk_tree#WALK_SUBTREE_TAIL]]
7332 }


リンク元

Advertisement