⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check-init.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Code to test for "definitive assignment".   Copyright (C) 1999  Free Software Foundation, Inc.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  Java and all Java-based marks are trademarks or registered trademarksof Sun Microsystems, Inc. in the United States and other countries.The Free Software Foundation is independent of Sun Microsystems, Inc.  *//* Written by Per Bothner <bothner@cygnus.com>, January 1999. */#include "config.h"#include "system.h"#include "tree.h"#include "java-tree.h"#include "toplev.h" /* Needed for fatal. *//* The basic idea is that we assign each local variable declaration   an index, and then we pass around bitstrings, where the i'th bit   is set if decl whose DECL_BIT_INDEX is i is definitely assigned. *//* One segment of a bitstring. */typedef unsigned int word;/* Pointer to a bitstring. */typedef word *words;/* For a local VAR_DECL, holds the index into a words bitstring that   specifies if this decl is definitively assigned.   A DECL_BIT_INDEX of -1 means we no longer care. */#define DECL_BIT_INDEX(DECL) DECL_FIELD_SIZE(DECL)/* Number of locals variables currently active. */int num_current_locals = 0;/* The index of the first local variable in the current block.   The variables whose DECL_BIT_INDEX are in the range from   start_current_locals (inclusive) up to num_current_locals (exclusive)   are declared in the "current" block.  If there is a loop or branch   form, we set start_current_locals to num_current_locals to indicate   there is no current block.   The point is that if a variable in the current block is set,   there are no other control paths that we have to worry about.   Hence, we can remove it from the set of variables we are   checking, making its bit index available for some other variable.   For simplicity, we only do that if the variable's bit index   is (num_current_locals-1);  freeing up its bit index is then   just a simple matter of decrementing num_current_locals.   The reason this is worth doing is that it is simple, and   allows us to use short (usually one-word) bit-strings,   even for methods with thousands of local variables, as   long as most of them are initialized immediately after or in   their declaration. */int start_current_locals = 0;int num_current_words = 1;static tree wfl;#define COPYN(DST, SRC, NWORDS) memcpy (DST, SRC, NWORDS * sizeof(word))#define COPY(DST, SRC) COPYN (DST, SRC, num_current_words)#define SET_ALL(DST) memset (DST, ~0, num_current_words * sizeof(word))#define CLEAR_ALL(DST) memset (DST, 0, num_current_words * sizeof(word))#define INTERSECTN(DST, SRC1, SRC2, N) \  do { int n = N; \  while (--n >= 0) DST[n] = SRC1[n] & SRC2[n]; \  } while (0)#define UNION(DST, SRC1, SRC2) \  UNIONN (DST, SRC1, SRC2, num_current_words)#define UNIONN(DST, SRC1, SRC2, N) \  do { int n = N; \  while (--n >= 0) DST[n] = SRC1[n] | SRC2[n]; \  } while (0)#define INTERSECT(DST, SRC1, SRC2) \  INTERSECTN (DST, SRC1, SRC2, num_current_words)#define WORD_SIZE  ((unsigned int)(sizeof(word) * 8))static void check_bool_init PROTO ((tree, words, words, words));static void check_init PROTO ((tree, words));static void check_cond_init PROTO ((tree, tree, tree, words, words, words));#if 0#define ALLOC_WORDS(NUM) ((word*) xmalloc ((NUM) * sizeof (word)))#define FREE_WORDS(PTR) (free (PTR))#else#define ALLOC_WORDS(NUM) ((word*)alloca ((NUM) * sizeof (word)))#define FREE_WORDS(PTR) ((void)0)#endif#define SET_P(WORDS, BIT) \  (WORDS[BIT / WORD_SIZE] & (1 << (BIT % WORD_SIZE)))#define CLEAR_BIT(WORDS, BIT) \  (WORDS[BIT / WORD_SIZE] &= ~ (1 << (BIT % WORD_SIZE)))#define SET_BIT(WORDS, BIT) \  (WORDS[BIT / WORD_SIZE] |= (1 << (BIT % WORD_SIZE)))#define WORDS_NEEDED(BITS) (((BITS)+(WORD_SIZE-1))/(WORD_SIZE))/* Check a conditional form (TEST_EXP ? THEN_EXP : ELSE_EXP) for   definite assignment.   BEFORE, WHEN_FALSE, and WHEN_TRUE are as in check_bool_init. */static voidcheck_cond_init (test_exp, then_exp, else_exp,		 before, when_false, when_true)     tree test_exp, then_exp, else_exp;     words before, when_false, when_true;{  words tmp = ALLOC_WORDS (6 * num_current_words);  words test_false = tmp;  words test_true = tmp + num_current_words;  words then_false = tmp + 2 * num_current_words;  words then_true = tmp + 3 * num_current_words;  words else_false = tmp + 4 * num_current_words;  words else_true = tmp + 5 * num_current_words;  check_bool_init (test_exp, before, test_false, test_true);  check_bool_init (then_exp, test_true, then_false, then_true);  check_bool_init (else_exp, test_false, else_false, else_true);  INTERSECT (when_false, then_false, else_false);  INTERSECT (when_true, then_true, else_true);  FREE_WORDS (tmp);}/* Check a boolean binary form CODE (EXP0, EXP1),   where CODE is one of EQ_EXPR, BIT_AND_EXPR, or BIT_IOR_EXPR.   BEFORE, WHEN_FALSE, and WHEN_TRUE are as in check_bool_init. */static voidcheck_bool2_init (code, exp0, exp1, before, when_false, when_true)     enum tree_code code;  tree exp0, exp1;     words before, when_false, when_true;{  word buf[4];  words tmp = num_current_words <= 1 ? buf    : ALLOC_WORDS (4 * num_current_words);  words when_false_0 = tmp;  words when_false_1 = tmp+num_current_words;  words when_true_0 = tmp+2*num_current_words;  words when_true_1 = tmp+3*num_current_words;  check_bool_init (exp0, before, when_false_0, when_true_0);  INTERSECT (before, when_false_0, when_true_0);  check_bool_init (exp1, before, when_false_1, when_true_1);  INTERSECT (before, when_false_1, when_true_1);  if (code == EQ_EXPR)    {      /* Now set:       * when_true = (when_false_1 INTERSECTION when_true_1)       *   UNION (when_true_0 INTERSECTION when_false_1)       *   UNION (when_false_0 INTERSECTION when_true_1);       * using when_false and before as temporary working areas.  */      INTERSECT (when_true, when_true_0, when_false_1);      INTERSECT (when_false, when_true_0, when_false_1);      UNION (when_true, when_true, when_false);      UNION (when_true, when_true, before);      /* Now set:       * when_false = (when_false_1 INTERSECTION when_true_1)       *   UNION (when_true_0 INTERSECTION when_true_1)       *   UNION (when_false_0 INTERSECTION when_false_1);       * using before as a temporary working area.  */      INTERSECT (when_false, when_true_0, when_true_1);      UNION (when_false, when_false, before);      INTERSECT (before, when_false_0, when_false_1);      UNION (when_false, when_false, before);    }  else if (code == BIT_AND_EXPR || code == TRUTH_AND_EXPR)    {      UNION (when_true, when_true_0, when_true_1);      INTERSECT (when_false, when_false_0, when_false_1);      UNION (when_false, when_false, before);    }  else /* if (code == BIT_IOR_EXPR || code == TRUTH_OR_EXPR) */    {      UNION (when_false, when_false_0, when_false_1);      INTERSECT (when_true, when_true_0, when_true_1);      UNION (when_true, when_true, before);    }  if (tmp != buf)    FREE_WORDS (tmp);}/* Check a boolean expression EXP for definite assignment.   BEFORE is the set of variables definitely assigned before the conditional.   (This bitstring may be modified arbitrarily in this function.)   On output, WHEN_FALSE is the set of variables definitely assigned after   the conditional when the conditional is false.   On output, WHEN_TRUE is the set of variables definitely assigned after   the conditional when the conditional is true.   (WHEN_FALSE and WHEN_TRUE are overwriten with initial values ignored.)   (None of BEFORE, WHEN_FALSE, or WHEN_TRUE can overlap, as they may   be used as temporary working areas. */static voidcheck_bool_init (exp, before, when_false, when_true)     tree exp;     words before, when_false, when_true;{  switch (TREE_CODE (exp))    {    case COND_EXPR:      check_cond_init (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),		       TREE_OPERAND (exp, 2),		       before, when_false, when_true);      return;    case TRUTH_ANDIF_EXPR:      check_cond_init (TREE_OPERAND (exp, 0),		       TREE_OPERAND (exp, 1), boolean_false_node,		       before, when_false, when_true);      return;    case TRUTH_ORIF_EXPR:      check_cond_init (TREE_OPERAND (exp, 0),		       boolean_true_node, TREE_OPERAND (exp, 1),		       before, when_false, when_true);      return;    case TRUTH_NOT_EXPR:      check_bool_init (TREE_OPERAND (exp, 0), before, when_true, when_false);      return;    case MODIFY_EXPR:      {	tree tmp = TREE_OPERAND (exp, 0);	if (TREE_CODE (tmp) == VAR_DECL && ! FIELD_STATIC (tmp))	  {	    int index;	    check_bool_init (TREE_OPERAND (exp, 1), before,			     when_false, when_true);	    index = DECL_BIT_INDEX (tmp);	    if (index >= 0)	      {		SET_BIT (when_false, index);		SET_BIT (when_true, index);	      }	    break;	  }      }      goto do_default;    case BIT_AND_EXPR:    case BIT_IOR_EXPR:    case TRUTH_AND_EXPR:    case TRUTH_OR_EXPR:    case EQ_EXPR:      check_bool2_init (TREE_CODE (exp),			TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),			before, when_false, when_true);      return;    case TRUTH_XOR_EXPR:    case BIT_XOR_EXPR:    case NE_EXPR:      /* Just like EQ_EXPR, but switch when_true and when_false. */      check_bool2_init (EQ_EXPR, TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),			before, when_true, when_false);      return;    case INTEGER_CST:      if (integer_zerop (exp))	{	  SET_ALL (when_true);	  COPY (when_false, before);	}      else	{	  SET_ALL (when_false);	  COPY (when_true, before);	}      break;    default:    do_default:      check_init (exp, before);      COPY (when_false, before);      COPY (when_true, before);    }}/* Used to keep track of control flow branches. */struct alternatives{  struct alternatives *outer;  /* The value of num_current_locals at the start of this compound. */  int num_locals;  /* The value of the "before" set at the start of the control stucture.   Used for SWITCH_EXPR but not set for LABELED_BLOCK_EXPR. */  words saved;  int save_start_current_locals;  /* If num_current_words==1, combined==&one_word, for efficiency. */  word one_word;  /* The intersection of the "after" sets from previous branches. */  words combined;  tree block;};struct alternatives * alternatives = NULL;#define BEGIN_ALTERNATIVES(before, current) \{ \  current.saved = NULL; \  current.num_locals = num_current_locals; \  current.combined = num_current_words <= 1 ? &current.one_word \    : ALLOC_WORDS (num_current_words); \  SET_ALL (current.combined); \  current.outer = alternatives; \  alternatives = &current; \  current.save_start_current_locals = start_current_locals; \  start_current_locals = num_current_locals; \}static voiddone_alternative (after, current)     words after;     struct alternatives *current; {  INTERSECTN (current->combined, current->combined, after,	      WORDS_NEEDED (current->num_locals));}#define END_ALTERNATIVES(after, current) \{ \  alternatives = current.outer; \  COPY (after, current.combined); \  if (current.combined != &current.one_word) \    FREE_WORDS (current.combined); \  start_current_locals = current.save_start_current_locals; \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -