FreeBSD/contrib/gcc/cp/decl.c
/* Given the SIZE (i.e., number of elements) in an array, compute an
   appropriate index type for the array.  If non-NULL, NAME is the
   name of the thing being declared.  */
Given the SIZE  in an array, compute an
appropriate index type for the array.  If non-NULL, NAME is the
name of the thing being declared.
Given the SIZE in an array compute an appropriate index type for the array . If non - NULL NAME is the name of the thing being declared .
tree
compute_array_index_type (tree name, tree size)
{
  tree type;
  tree itype;
  if (error_operand_p (size))
    return error_mark_node;
  type = TREE_TYPE (size);
  if (!dependent_type_p (type) && !INTEGRAL_TYPE_P (type))
    {
      if (name)
	error ("size of array %qD has non-integral type %qT", name, type);
      else
	error ("size of array has non-integral type %qT", type);
      size = integer_one_node;
      type = TREE_TYPE (size);
    }
  if (abi_version_at_least (2)
      ? value_dependent_expression_p (size)
      : processing_template_decl)
    return build_index_type (build_min (MINUS_EXPR, sizetype,
					size, integer_one_node));
  STRIP_TYPE_NOPS (size);
  size = integral_constant_value (size);
  if (TREE_CODE (size) == INTEGER_CST)
    {
      int old_flag_pedantic_errors = flag_pedantic_errors;
      int old_pedantic = pedantic;
      pedantic = flag_pedantic_errors = 1;
      constant_expression_warning (size);
      pedantic = old_pedantic;
      flag_pedantic_errors = old_flag_pedantic_errors;
      if (INT_CST_LT (size, integer_zero_node))
	{
	  if (name)
	    error ("size of array %qD is negative", name);
	  else
	    error ("size of array is negative");
	  size = integer_one_node;
	}
      else if (integer_zerop (size) && pedantic && !in_system_header)
	{
	  if (name)
	    pedwarn ("ISO C++ forbids zero-size array %qD", name);
	  else
	    pedwarn ("ISO C++ forbids zero-size array");
	}
    }
  else if (TREE_CONSTANT (size))
    {
      if (name)
	error ("size of array %qD is not an integral constant-expression",
	       name);
      else
	error ("size of array is not an integral constant-expression");
      size = integer_one_node;
    }
  else if (pedantic && warn_vla != 0)
    {
      if (name)
	pedwarn ("ISO C++ forbids variable length array %qD", name);
      else
	pedwarn ("ISO C++ forbids variable length array");
    }
  else if (warn_vla > 0)
    {
      if (name)
	warning (OPT_Wvla, 
                 "variable length array %qD is used", name);
      else
	warning (OPT_Wvla, 
                 "variable length array is used");
    }
  if (processing_template_decl && !TREE_CONSTANT (size))
    itype = build_min (MINUS_EXPR, sizetype, size, integer_one_node);
  else
    {
      HOST_WIDE_INT saved_processing_template_decl;
      saved_processing_template_decl = processing_template_decl;
      processing_template_decl = 0;
      itype = cp_build_binary_op (MINUS_EXPR,
				  cp_convert (ssizetype, size),
				  cp_convert (ssizetype, integer_one_node));
      itype = fold (itype);
      processing_template_decl = saved_processing_template_decl;
      if (!TREE_CONSTANT (itype))
	itype = variable_size (itype);
      else if (TREE_CODE (itype) == INTEGER_CST
	       && TREE_OVERFLOW (itype))
	{
	  error ("overflow in array dimension");
	  TREE_OVERFLOW (itype) = 0;
	}
    }
  return build_index_type (itype);
}
tree compute_array_index_type ( tree name , tree size ) { tree type ; tree itype ; if ( error_operand_p ( size ) ) return error_mark_node ; type = TREE_TYPE ( size ) ; if ( ! dependent_type_p ( type ) && ! INTEGRAL_TYPE_P ( type ) ) { if ( name ) error ( " " , name , type ) ; else error ( " " , type ) ; size = integer_one_node ; type = TREE_TYPE ( size ) ; } if ( abi_version_at_least ( 2 ) ? value_dependent_expression_p ( size ) : processing_template_decl ) return build_index_type ( build_min ( MINUS_EXPR , sizetype , size , integer_one_node ) ) ; STRIP_TYPE_NOPS ( size ) ; size = integral_constant_value ( size ) ; if ( TREE_CODE ( size ) == INTEGER_CST ) { int old_flag_pedantic_errors = flag_pedantic_errors ; int old_pedantic = pedantic ; pedantic = flag_pedantic_errors = 1 ; constant_expression_warning ( size ) ; pedantic = old_pedantic ; flag_pedantic_errors = old_flag_pedantic_errors ; if ( INT_CST_LT ( size , integer_zero_node ) ) { if ( name ) error ( " " , name ) ; else error ( " " ) ; size = integer_one_node ; } else if ( integer_zerop ( size ) && pedantic && ! in_system_header ) { if ( name ) pedwarn ( " " , name ) ; else pedwarn ( " " ) ; } } else if ( TREE_CONSTANT ( size ) ) { if ( name ) error ( " " , name ) ; else error ( " " ) ; size = integer_one_node ; } else if ( pedantic && warn_vla != 0 ) { if ( name ) pedwarn ( " " , name ) ; else pedwarn ( " " ) ; } else if ( warn_vla > 0 ) { if ( name ) warning ( OPT_Wvla , " " , name ) ; else warning ( OPT_Wvla , " " ) ; } if ( processing_template_decl && ! TREE_CONSTANT ( size ) ) itype = build_min ( MINUS_EXPR , sizetype , size , integer_one_node ) ; else { HOST_WIDE_INT saved_processing_template_decl ; saved_processing_template_decl = processing_template_decl ; processing_template_decl = 0 ; itype = cp_build_binary_op ( MINUS_EXPR , cp_convert ( ssizetype , size ) , cp_convert ( ssizetype , integer_one_node ) ) ; itype = fold ( itype ) ; processing_template_decl = saved_processing_template_decl ; if ( ! TREE_CONSTANT ( itype ) ) itype = variable_size ( itype ) ; else if ( TREE_CODE ( itype ) == INTEGER_CST && TREE_OVERFLOW ( itype ) ) { error ( " " ) ; TREE_OVERFLOW ( itype ) = 0 ; } } return build_index_type ( itype ) ; }
Given the SIZE (i.e., number of elements) in an array, compute an
appropriate index type for the array.
Given the SIZE ( i . e . number of elements ) in an array compute an appropriate index type for the array .
/* The array bound must be an integer type.  */ /* We should only handle value dependent expressions specially.  */ /* But for abi-1, we handled all instances in templates. This
	 effects the manglings produced.  */ /* The size might be the result of a cast.  */ /* It might be a const variable or enumeration constant.  */ /* Normally, the array-bound will be a constant.  */ /* Check to see if the array bound overflowed.  Make that an
	 error, no matter how generous we're being.  */ /* An array must have a positive number of elements.  */ /* As an extension we allow zero-sized arrays.  We always allow
	 them in system headers because glibc uses them.  */ /* `(int) &fn' is not a valid array bound.  */ /* A variable sized array.  */ /* Compute the index of the largest element in the array.  It is
	 one less than the number of elements in the array.  We save
	 and restore PROCESSING_TEMPLATE_DECL so that computations in
	 cp_build_binary_op will be appropriately folded.  */ /* A variable sized array.  */ /* Make sure that there was no overflow when creating to a signed
	 index type.  (For example, on a 32-bit machine, an array with
	 size 2^32 - 1 is too big.)  */ /* Create and return the appropriate index type.  */