FreeBSD/contrib/gcc/c-decl.c
/* Build and install a CONST_DECL for one value of the
   current enumeration type (one that was begun with start_enum).
   Return a tree-list containing the CONST_DECL and its value.
   Assignment of sequential values by default is handled here.  */
Build and install a CONST_DECL for one value of the
current enumeration type (one that was begun with start_enum).
Return a tree-list containing the CONST_DECL and its value.
Assignment of sequential values by default is handled here.
Build and install a CONST_DECL for one value of the current enumeration type ( one that was begun with start_enum ) . Return a tree - list containing the CONST_DECL and its value . Assignment of sequential values by default is handled here .
tree
build_enumerator (tree name, tree value)
{
  tree decl, type;
  if (value != 0)
    {
      if (value == error_mark_node)
	value = 0;
      else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
	       || TREE_CODE (value) != INTEGER_CST)
	{
	  error ("enumerator value for %qE is not an integer constant", name);
	  value = 0;
	}
      else
	{
	  value = default_conversion (value);
	  constant_expression_warning (value);
	}
    }
  if (value == 0)
    {
      value = enum_next_value;
      if (enum_overflow)
	error ("overflow in enumeration values");
    }
  if (pedantic && !int_fits_type_p (value, integer_type_node))
    {
      pedwarn ("ISO C restricts enumerator values to range of %<int%>");
      value = convert (integer_type_node, value);
    }
  enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
  enum_overflow = tree_int_cst_lt (enum_next_value, value);
  type = TREE_TYPE (value);
  type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
				      TYPE_PRECISION (integer_type_node)),
				 (TYPE_PRECISION (type)
				  >= TYPE_PRECISION (integer_type_node)
				  && TYPE_UNSIGNED (type)));
  decl = build_decl (CONST_DECL, name, type);
  DECL_INITIAL (decl) = convert (type, value);
  pushdecl (decl);
  return tree_cons (decl, value, NULL_TREE);
}
tree build_enumerator ( tree name , tree value ) { tree decl , type ; if ( value != 0 ) { if ( value == error_mark_node ) value = 0 ; else if ( ! INTEGRAL_TYPE_P ( TREE_TYPE ( value ) ) || TREE_CODE ( value ) != INTEGER_CST ) { error ( " " , name ) ; value = 0 ; } else { value = default_conversion ( value ) ; constant_expression_warning ( value ) ; } } if ( value == 0 ) { value = enum_next_value ; if ( enum_overflow ) error ( " " ) ; } if ( pedantic && ! int_fits_type_p ( value , integer_type_node ) ) { pedwarn ( " " ) ; value = convert ( integer_type_node , value ) ; } enum_next_value = build_binary_op ( PLUS_EXPR , value , integer_one_node , 0 ) ; enum_overflow = tree_int_cst_lt ( enum_next_value , value ) ; type = TREE_TYPE ( value ) ; type = c_common_type_for_size ( MAX ( TYPE_PRECISION ( type ) , TYPE_PRECISION ( integer_type_node ) ) , ( TYPE_PRECISION ( type ) >= TYPE_PRECISION ( integer_type_node ) && TYPE_UNSIGNED ( type ) ) ) ; decl = build_decl ( CONST_DECL , name , type ) ; DECL_INITIAL ( decl ) = convert ( type , value ) ; pushdecl ( decl ) ; return tree_cons ( decl , value , NULL_TREE ) ; }
Build and install a CONST_DECL for one value of the
current enumeration type (one that was begun with start_enum).
Build and install a CONST_DECL for one value of the current enumeration type ( one that was begun with start_enum ) .
/* Validate and default VALUE.  */ /* Don't issue more errors for error_mark_node (i.e. an
	 undeclared identifier) - just ignore the value expression.  */ /* Default based on previous value.  */ /* It should no longer be possible to have NON_LVALUE_EXPR
     in the default.  */ /* XXX This causes -pedantic to change the meaning of the program.
	 Remove?  -zw 2004-03-15  */ /* Set basis for default for next value.  */ /* Now create a declaration for the enum value name.  */