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

📄 typeck2.c

📁 gcc库的原代码,对编程有很大帮助.
💻 C
📖 第 1 页 / 共 4 页
字号:
	return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);      /* Allow conversions between real types.  */      if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)	return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);      /* Allow length-preserving conversions between integer types.  */      if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE	  && (TYPE_PRECISION (TREE_TYPE (value))	      == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))	return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);      /* Allow conversions between other integer types only if	 explicit value.  */      if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)	{	  tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),						     endtype);	  if (inner == null_pointer_node)	    return null_pointer_node;	  return 0;	}      /* Allow (int) &foo provided int is as wide as a pointer.  */      if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE	  && (TYPE_PRECISION (TREE_TYPE (value))	      >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))	return initializer_constant_valid_p (TREE_OPERAND (value, 0),					     endtype);      /* Likewise conversions from int to pointers.  */      if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE	  && (TYPE_PRECISION (TREE_TYPE (value))	      <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))	return initializer_constant_valid_p (TREE_OPERAND (value, 0),					     endtype);      /* Allow conversions to union types if the value inside is okay.  */      if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)	return initializer_constant_valid_p (TREE_OPERAND (value, 0),					     endtype);      return 0;    case PLUS_EXPR:      if (TREE_CODE (endtype) == INTEGER_TYPE	  && TYPE_PRECISION (endtype) < POINTER_SIZE)	return 0;      {	tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),						    endtype);	tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),						    endtype);	/* If either term is absolute, use the other terms relocation.  */	if (valid0 == null_pointer_node)	  return valid1;	if (valid1 == null_pointer_node)	  return valid0;	return 0;      }    case MINUS_EXPR:      if (TREE_CODE (endtype) == INTEGER_TYPE	  && TYPE_PRECISION (endtype) < POINTER_SIZE)	return 0;      {	tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),						    endtype);	tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),						    endtype);	/* Win if second argument is absolute.  */	if (valid1 == null_pointer_node)	  return valid0;	/* Win if both arguments have the same relocation.	   Then the value is absolute.  */	if (valid0 == valid1)	  return null_pointer_node;	return 0;      }    }  return 0;}/* Perform appropriate conversions on the initial value of a variable,   store it in the declaration DECL,   and print any error messages that are appropriate.   If the init is invalid, store an ERROR_MARK.   C++: Note that INIT might be a TREE_LIST, which would mean that it is   a base class initializer for some aggregate type, hopefully compatible   with DECL.  If INIT is a single element, and DECL is an aggregate   type, we silently convert INIT into a TREE_LIST, allowing a constructor   to be called.   If INIT is a TREE_LIST and there is no constructor, turn INIT   into a CONSTRUCTOR and use standard initialization techniques.   Perhaps a warning should be generated?   Returns value of initializer if initialization could not be   performed for static variable.  In that case, caller must do   the storing.  */treestore_init_value (decl, init)     tree decl, init;{  register tree value, type;  /* If variable's type was invalidly declared, just ignore it.  */  type = TREE_TYPE (decl);  if (TREE_CODE (type) == ERROR_MARK)    return NULL_TREE;#if 0  /* This breaks arrays, and should not have any effect for other decls.  */  /* Take care of C++ business up here.  */  type = TYPE_MAIN_VARIANT (type);#endif  if (IS_AGGR_TYPE (type))    {      if (! TYPE_HAS_TRIVIAL_INIT_REF (type)	  && TREE_CODE (init) != CONSTRUCTOR)	my_friendly_abort (109);      /* Although we are not allowed to declare variables of signature	 type, we complain about a possible constructor call in such a	 declaration as well.  */      if (TREE_CODE (init) == TREE_LIST	  && IS_SIGNATURE (type))	{	  cp_error ("constructor syntax cannot be used with signature type `%T'",		    type);	  init = error_mark_node;	}      else if (TREE_CODE (init) == TREE_LIST)	{	  cp_error ("constructor syntax used, but no constructor declared for type `%T'", type);	  init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (init));	}#if 0      if (TREE_CODE (init) == CONSTRUCTOR)	{	  tree field;	  tree funcs;	  int func;	  /* Check that we're really an aggregate as ARM 8.4.1 defines it.  */	  if (CLASSTYPE_N_BASECLASSES (type))	    cp_error_at ("initializer list construction invalid for derived class object `%D'", decl);	  if (CLASSTYPE_VTBL_PTR (type))	    cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl);	  if (TYPE_NEEDS_CONSTRUCTING (type))	    {	      cp_error_at ("initializer list construction invalid for `%D'", decl);	      error ("due to the presence of a constructor");	    }	  for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))	    if (TREE_PRIVATE (field) || TREE_PROTECTED (field))	      {		cp_error_at ("initializer list construction invalid for `%D'", decl);		cp_error_at ("due to non-public access of member `%D'", field);	      }	  funcs = TYPE_METHODS (type);	  if (funcs)	    for (func = 0; func < TREE_VEC_LENGTH (funcs); func++)	      {		field = TREE_VEC_ELT (funcs, func);		if (field && (TREE_PRIVATE (field) || TREE_PROTECTED (field)))		  {		    cp_error_at ("initializer list construction invalid for `%D'", decl);		    cp_error_at ("due to non-public access of member `%D'", field);		  }	      }	}#endif    }  else if (TREE_CODE (init) == TREE_LIST	   && TREE_TYPE (init) != unknown_type_node)    {      if (TREE_CODE (decl) == RESULT_DECL)	{	  if (TREE_CHAIN (init))	    {	      warning ("comma expression used to initialize return value");	      init = build_compound_expr (init);	    }	  else	    init = TREE_VALUE (init);	}      else if (TREE_TYPE (init) != 0	       && TREE_CODE (TREE_TYPE (init)) == OFFSET_TYPE)	{	  /* Use the type of our variable to instantiate	     the type of our initializer.  */	  init = instantiate_type (type, init, 1);	}      else if (TREE_CODE (init) == TREE_LIST	       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)	{	  error ("cannot initialize arrays using this syntax");	  return NULL_TREE;	}      else	{	  /* We get here with code like `int a (2);' */	     	  if (TREE_CHAIN (init) != NULL_TREE)	    {	      pedwarn ("initializer list being treated as compound expression");	      init = build_compound_expr (init);	    }	  else	    init = TREE_VALUE (init);	}    }  /* End of special C++ code.  */  /* Digest the specified initializer into an expression.  */  value = digest_init (type, init, (tree *) 0);  /* Store the expression if valid; else report error.  */  if (TREE_CODE (value) == ERROR_MARK)    ;  else if (TREE_STATIC (decl)	   && (! TREE_CONSTANT (value)	       || ! initializer_constant_valid_p (value, TREE_TYPE (value))#if 0	       /* A STATIC PUBLIC int variable doesn't have to be		  run time inited when doing pic.  (mrs) */	       /* Since ctors and dtors are the only things that can		  reference vtables, and they are always written down		  the the vtable definition, we can leave the		  vtables in initialized data space.		  However, other initialized data cannot be initialized		  this way.  Instead a global file-level initializer		  must do the job.  */	       || (flag_pic && !DECL_VIRTUAL_P (decl) && TREE_PUBLIC (decl))#endif	       ))    return value;#if 0 /* No, that's C.  jason 9/19/94 */  else    {      if (pedantic && TREE_CODE (value) == CONSTRUCTOR	  /* Don't complain about non-constant initializers of	     signature tables and signature pointers/references.  */	  && ! (TYPE_LANG_SPECIFIC (type)		&& (IS_SIGNATURE (type)		    || IS_SIGNATURE_POINTER (type)		    || IS_SIGNATURE_REFERENCE (type))))	{	  if (! TREE_CONSTANT (value) || ! TREE_STATIC (value))	    pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");	}    }#endif  DECL_INITIAL (decl) = value;  return NULL_TREE;}/* Digest the parser output INIT as an initializer for type TYPE.   Return a C expression of type TYPE to represent the initial value.   If TAIL is nonzero, it points to a variable holding a list of elements   of which INIT is the first.  We update the list stored there by   removing from the head all the elements that we use.   Normally this is only one; we use more than one element only if   TYPE is an aggregate and INIT is not a constructor.  */treedigest_init (type, init, tail)     tree type, init, *tail;{  enum tree_code code = TREE_CODE (type);  tree element = NULL_TREE;  tree old_tail_contents;  /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR     tree node which has no TREE_TYPE.  */  int raw_constructor;  /* By default, assume we use one element from a list.     We correct this later in the sole case where it is not true.  */  if (tail)    {      old_tail_contents = *tail;      *tail = TREE_CHAIN (*tail);    }  if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST				  && TREE_VALUE (init) == error_mark_node))    return error_mark_node;  /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */  if (TREE_CODE (init) == NON_LVALUE_EXPR)    init = TREE_OPERAND (init, 0);  if (init && TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (type))    init = default_conversion (init);  if (init && TYPE_PTRMEMFUNC_P (type)      && ((TREE_CODE (init) == ADDR_EXPR	   && ((TREE_CODE (TREE_TYPE (init)) == POINTER_TYPE		&& TREE_CODE (TREE_TYPE (TREE_TYPE (init))) == METHOD_TYPE)	       || TREE_CODE (TREE_OPERAND (init, 0)) == TREE_LIST))	  || TREE_CODE (init) == TREE_LIST	  || integer_zerop (init)	  || (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init)))))    {      return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), init, 0);    }  raw_constructor = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;  if (init && raw_constructor      && CONSTRUCTOR_ELTS (init) != 0      && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)    {      element = TREE_VALUE (CONSTRUCTOR_ELTS (init));      /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */      if (element && TREE_CODE (element) == NON_LVALUE_EXPR)	element = TREE_OPERAND (element, 0);      if (element == error_mark_node)	return element;    }  /* Any type can be initialized from an expression of the same type,     optionally with braces.  */  if (init && TREE_TYPE (init)      && (TYPE_MAIN_VARIANT (TREE_TYPE (init)) == type	  || (code == ARRAY_TYPE && comptypes (TREE_TYPE (init), type, 1))))    {      if (pedantic && code == ARRAY_TYPE	  && TREE_CODE (init) != STRING_CST)	pedwarn ("ANSI C++ forbids initializing array from array expression");      if (TREE_CODE (init) == CONST_DECL)	init = DECL_INITIAL (init);      else if (TREE_READONLY_DECL_P (init))	init = decl_constant_value (init);      return init;    }  if (element && (TREE_TYPE (element) == type		  || (code == ARRAY_TYPE && TREE_TYPE (element)		      && comptypes (TREE_TYPE (element), type, 1))))    {      if (pedantic && code == ARRAY_TYPE)	pedwarn ("ANSI C++ forbids initializing array from array expression");      if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))	pedwarn ("ANSI C++ forbids single nonscalar initializer with braces");      if (TREE_CODE (element) == CONST_DECL)	element = DECL_INITIAL (element);      else if (TREE_READONLY_DECL_P (element))	element = decl_constant_value (element);      return element;    }  /* Initialization of an array of chars from a string constant     optionally enclosed in braces.  */  if (code == ARRAY_TYPE)    {      tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));      if ((typ1 == char_type_node	   || typ1 == signed_char_type_node	   || typ1 == unsigned_char_type_node	   || typ1 == unsigned_wchar_type_node	   || typ1 == signed_wchar_type_node)	  && ((init && TREE_CODE (init) == STRING_CST)	      || (element && TREE_CODE (element) == STRING_CST)))	{	  tree string = element ? element : init;	  if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))	       != char_type_node)	      && TYPE_PRECISION (typ1) == BITS_PER_UNIT)	    {	      error ("char-array initialized from wide string");	      return error_mark_node;	    }	  if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))	       == char_type_node)	      && TYPE_PRECISION (typ1) != BITS_PER_UNIT)	    {	      error ("int-array initialized from non-wide string");	      return error_mark_node;	    }	  if (pedantic	      && typ1 != char_type_node	      && typ1 != signed_char_type_node	      && typ1 != unsigned_char_type_node)	    pedwarn ("ANSI C++ forbids string initializer except for `char' elements");	  TREE_TYPE (string) = type;	  if (TYPE_DOMAIN (type) != 0	      && TREE_CONSTANT (TYPE_SIZE (type)))	    {	      register int size		= TREE_INT_CST_LOW (TYPE_SIZE (type));	      size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;	      /* In C it is ok to subtract 1 from the length of the string		 because it's ok to ignore the terminating null char that is		 counted in the length of the constant, but in C++ this would		 be invalid.  */	      if (size < TREE_STRING_LENGTH (string))		pedwarn ("initializer-string for array of chars is too long");	    }	  return string;	}

⌨️ 快捷键说明

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