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

📄 tree_no_comment.c

📁 使用yacc和lex编写的cmm语言的词法分析和语法分析程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
     tree t1, t2;{  register enum tree_code code1, code2;  int cmp;  if (t1 == t2)    return 1;  if (t1 == 0 || t2 == 0)    return 0;  code1 = TREE_CODE (t1);  code2 = TREE_CODE (t2);  if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)    if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)      return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));    else      return simple_cst_equal (TREE_OPERAND (t1, 0), t2);  else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR	   || code2 == NON_LVALUE_EXPR)    return simple_cst_equal (t1, TREE_OPERAND (t2, 0));  if (code1 != code2)    return 0;  switch (code1)    {    case INTEGER_CST:      return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)	&& TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);    case REAL_CST:      return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));    case STRING_CST:      return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)	&& !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),		  TREE_STRING_LENGTH (t1));    case CONSTRUCTOR:      abort ();    case SAVE_EXPR:      return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));    case CALL_EXPR:      cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));      if (cmp <= 0)	return cmp;      return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));    case TARGET_EXPR:            if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL	   && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE	   && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)	  || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL	      && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE	      && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))	cmp = 1;      else	cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));      if (cmp <= 0)	return cmp;      return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));    case WITH_CLEANUP_EXPR:      cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));      if (cmp <= 0)	return cmp;      return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));    case COMPONENT_REF:      if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))	return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));      return 0;    case BIT_FIELD_REF:      return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))	      && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))	      && simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2)));    case VAR_DECL:    case PARM_DECL:    case CONST_DECL:    case FUNCTION_DECL:      return 0;    case PLUS_EXPR:    case MINUS_EXPR:    case MULT_EXPR:    case TRUNC_DIV_EXPR:    case TRUNC_MOD_EXPR:    case LSHIFT_EXPR:    case RSHIFT_EXPR:      cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));      if (cmp <= 0)	return cmp;      return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));    case NEGATE_EXPR:    case ADDR_EXPR:    case REFERENCE_EXPR:    case INDIRECT_REF:      return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));    default:      return lang_simple_cst_equal (t1, t2);      return -1;    }}treebuild_pointer_type (to_type)     tree to_type;{  register tree t = TYPE_POINTER_TO (to_type);  register struct obstack *ambient_obstack = current_obstack;  register struct obstack *ambient_saveable_obstack = saveable_obstack;    if (t)    return t;    if (TREE_PERMANENT (to_type))    {      current_obstack = &permanent_obstack;      saveable_obstack = &permanent_obstack;    }  t = make_node (POINTER_TYPE);  TREE_TYPE (t) = to_type;    TYPE_POINTER_TO (to_type) = t;    layout_type (t);  current_obstack = ambient_obstack;  saveable_obstack = ambient_saveable_obstack;  return t;}treebuild_index_type (maxval)     tree maxval;{  register tree itype = make_node (INTEGER_TYPE);  TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);  TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);  TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;  TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);  TYPE_MODE (itype) = TYPE_MODE (sizetype);  TYPE_SIZE (itype) = TYPE_SIZE (sizetype);  TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);  if (TREE_CODE (maxval) == INTEGER_CST)    {      int maxint = TREE_INT_CST_LOW (maxval);      return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);    }  else    return itype;}treebuild_index_2_type (lowval,highval)     tree lowval, highval;{  register tree itype = make_node (INTEGER_TYPE);  TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);  TYPE_MIN_VALUE (itype) = convert (sizetype, lowval);  TYPE_MAX_VALUE (itype) = convert (sizetype, highval);  TYPE_MODE (itype) = TYPE_MODE (sizetype);  TYPE_SIZE (itype) = TYPE_SIZE (sizetype);  TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);  if ((TREE_CODE (lowval) == INTEGER_CST)      && (TREE_CODE (highval) == INTEGER_CST))    {      int highint = TREE_INT_CST_LOW (highval);      int lowint = TREE_INT_CST_LOW (lowval);      int maxint = highint - lowint;      return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);    }  else    return itype;}intindex_type_equal (itype1, itype2)     tree itype1, itype2;{  if (TREE_CODE (itype1) != TREE_CODE (itype2))    return 0;  if (TREE_CODE (itype1) == INTEGER_TYPE)    {      if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)	  || TYPE_MODE (itype1) != TYPE_MODE (itype2)	  || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))	  || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))	return 0;      if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))	  && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))	return 1;    }  return 0;}treebuild_array_type (elt_type, index_type)     tree elt_type, index_type;{  register tree t;  int hashcode;  if (TREE_CODE (elt_type) == FUNCTION_TYPE)    {      error ("arrays of functions are not meaningful");      elt_type = integer_type_node;    }    build_pointer_type (elt_type);    t = make_node (ARRAY_TYPE);  TREE_TYPE (t) = elt_type;  TYPE_DOMAIN (t) = index_type;  if (index_type == 0)    return t;  hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);  t = type_hash_canon (hashcode, t);  if (TYPE_SIZE (t) == 0)    layout_type (t);  return t;}treebuild_function_type (value_type, arg_types)     tree value_type, arg_types;{  register tree t;  int hashcode;  if (TREE_CODE (value_type) == FUNCTION_TYPE      || TREE_CODE (value_type) == ARRAY_TYPE)    {      error ("function return type cannot be function or array");      value_type = integer_type_node;    }    t = make_node (FUNCTION_TYPE);  TREE_TYPE (t) = value_type;  TYPE_ARG_TYPES (t) = arg_types;    hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);  t = type_hash_canon (hashcode, t);  if (TYPE_SIZE (t) == 0)    layout_type (t);  return t;}treebuild_reference_type (to_type)     tree to_type;{  register tree t = TYPE_REFERENCE_TO (to_type);  register struct obstack *ambient_obstack = current_obstack;  register struct obstack *ambient_saveable_obstack = saveable_obstack;    if (t)    return t;    if (TREE_PERMANENT (to_type))    {      current_obstack = &permanent_obstack;      saveable_obstack = &permanent_obstack;    }  t = make_node (REFERENCE_TYPE);  TREE_TYPE (t) = to_type;    TYPE_REFERENCE_TO (to_type) = t;  layout_type (t);  current_obstack = ambient_obstack;  saveable_obstack = ambient_saveable_obstack;  return t;}treebuild_method_type (basetype, type)     tree basetype, type;{  register tree t;  int hashcode;    t = make_node (METHOD_TYPE);  if (TREE_CODE (type) != FUNCTION_TYPE)    abort ();  TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);  TREE_TYPE (t) = TREE_TYPE (type);    TYPE_ARG_TYPES (t)    = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));    hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);  t = type_hash_canon (hashcode, t);  if (TYPE_SIZE (t) == 0)    layout_type (t);  return t;}treebuild_offset_type (basetype, type)     tree basetype, type;{  register tree t;  int hashcode;    t = make_node (OFFSET_TYPE);  TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);  TREE_TYPE (t) = type;    hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);  t = type_hash_canon (hashcode, t);  if (TYPE_SIZE (t) == 0)    layout_type (t);  return t;}treebuild_complex_type (component_type)     tree component_type;{  register tree t;  int hashcode;    t = make_node (COMPLEX_TYPE);  TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);  TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);  TYPE_READONLY (t) = TYPE_READONLY (component_type);    hashcode = TYPE_HASH (component_type);  t = type_hash_canon (hashcode, t);  if (TYPE_SIZE (t) == 0)    layout_type (t);  return t;}treeget_unwidened (op, for_type)     register tree op;     tree for_type;{      register tree type = TREE_TYPE (op);  register unsigned final_prec    = TYPE_PRECISION (for_type != 0 ? for_type : type);  register int uns    = (for_type != 0 && for_type != type       && final_prec > TYPE_PRECISION (type)       && TREE_UNSIGNED (type));  register tree win = op;  while (TREE_CODE (op) == NOP_EXPR)    {      register int bitschange	= TYPE_PRECISION (TREE_TYPE (op))	  - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));            if (bitschange < 0	  && final_prec > TYPE_PRECISION (TREE_TYPE (op)))	break;            op = TREE_OPERAND (op, 0);            if (bitschange > 0)	{	  if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))	    win = op;	  	  if ((uns || TREE_CODE (op) == NOP_EXPR)	      && TREE_UNSIGNED (TREE_TYPE (op)))	    {	      uns = 1;	      win = op;	    }	}    }  if (TREE_CODE (op) == COMPONENT_REF            && TREE_CODE (type) != REAL_TYPE)    {      unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));      type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));            if (innerprec < TYPE_PRECISION (TREE_TYPE (op))	  && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))	  && (! uns || final_prec <= innerprec	      || TREE_UNSIGNED (TREE_OPERAND (op, 1)))	  && type != 0)	{	  win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),		       TREE_OPERAND (op, 1));	  TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);	  TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);	  TREE_RAISES (win) = TREE_RAISES (op);	}    }  return win;}treeget_narrower (op, unsignedp_ptr)     register tree op;     int *unsignedp_ptr;{  register int uns = 0;  int first = 1;  register tree win = op;  while (TREE_CODE (op) == NOP_EXPR)    {      register int bitschange	= TYPE_PRECISION (TREE_TYPE (op))	  - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));            if (bitschange < 0)	break;            op = TREE_OPERAND (op, 0);      if (bitschange > 0)	{	  	  if (first)	    uns = TREE_UNSIGNED (TREE_TYPE (op));	  	  else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))	    break;	  first = 0;	}            win = op;    }  if (TREE_CODE (op) == COMPONENT_REF            && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)    {      unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));      tree type = type_for_size (innerprec, TREE_UNSIGNED (op));            if (innerprec < TYPE_PRECISION (TREE_TYPE (op))	  && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))	  && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))	  && type != 0)	{	  if (first)	    uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));	  win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),		       TREE_OPERAND (op, 1));	  TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);	  TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);	  TREE_RAISES (win) = TREE_RAISES (op);	}    }  *unsignedp_ptr = uns;  return win;}inttype_precision (type)     register tree type;{  return ((TREE_CODE (type) == INTEGER_TYPE	   || TREE_CODE (type) == ENUMERAL_TYPE	   || TREE_CODE (type) == REAL_TYPE)	  ? TYPE_PRECISION (type) : POINTER_SIZE);}intint_fits_type_p (c, type)     tree c, type;{  if (TREE_UNSIGNED (type))    return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)	    && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));  else    return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)	    && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));}treedecl_function_context (fndecl)     tree fndecl;{  tree context;  if (TREE_CODE (fndecl) == ERROR_MARK)    return 0;  if (TREE_CODE (fndecl) == SAVE_EXPR)    context = SAVE_EXPR_CONTEXT (fndecl);  else    context = DECL_CONTEXT (fndecl);  while (context && TREE_CODE (context) != FUNCTION_DECL)    {      if (TREE_CODE (context) == RECORD_TYPE	  || TREE_CODE (context) == UNION_TYPE)	context = TYPE_CONTEXT (context);      else if (TREE_CODE (context) == TYPE_DECL)	context = DECL_CONTEXT (context);      else if (TREE_CODE (context) == BLOCK)	context = BLOCK_SUPERCONTEXT (context);      else		abort ();    }  return context;}treedecl_type_context (fndecl)     tree fndecl;{  tree context = DECL_CONTEXT (fndecl);  while (context)    {      if (TREE_CODE (context) == RECORD_TYPE	  || TREE_CODE (context) == UNION_TYPE)	return context;      if (TREE_CODE (context) == TYPE_DECL	  || TREE_CODE (context) == FUNCTION_DECL)	context = DECL_CONTEXT (context);      else if (TREE_CODE (context) == BLOCK)	context = BLOCK_SUPERCONTEXT (context);      else		abort ();    }  return NULL_TREE;}voidprint_obstack_statistics (str, o)     char *str;     struct obstack *o;{  struct _obstack_chunk *chunk = o->chunk;  int n_chunks = 0;  int n_alloc = 0;  while (chunk)    {      n_chunks += 1;      n_alloc += chunk->limit - &chunk->contents[0];      chunk = chunk->prev;    }  fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",	   str, n_alloc, n_chunks);}voiddump_tree_statistics (){  int i;  int total_nodes, total_bytes;  fprintf (stderr, "\n??? tree nodes created\n\n");  fprintf (stderr, "Kind                  Nodes     Bytes\n");  fprintf (stderr, "-------------------------------------\n");  total_nodes = total_bytes = 0;  for (i = 0; i < (int) all_kinds; i++)    {      fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],	       tree_node_counts[i], tree_node_sizes[i]);      total_nodes += tree_node_counts[i];      total_bytes += tree_node_sizes[i];    }  fprintf (stderr, "%-20s        %9d\n", "identifier names", id_string_size);  fprintf (stderr, "-------------------------------------\n");  fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);  fprintf (stderr, "-------------------------------------\n");  fprintf (stderr, "(No per-node statistics)\n");  print_lang_statistics ();}

⌨️ 快捷键说明

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