FreeBSD/contrib/gcc/c-common.c
/* Given a STRING_CST, give it a suitable array-of-chars data type.  */
Given a STRING_CST, give it a suitable array-of-chars data type.
Given a STRING_CST give it a suitable array - of - chars data type .
tree
fix_string_type (tree value)
{
  const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
  const int wide_flag = TREE_TYPE (value) == wchar_array_type_node;
  int length = TREE_STRING_LENGTH (value);
  int nchars;
  tree e_type, i_type, a_type;
  nchars = wide_flag ? length / wchar_bytes : length;
  if (warn_overlength_strings)
    {
      const int nchars_max = flag_isoc99 ? 4095 : 509;
      const int relevant_std = flag_isoc99 ? 99 : 90;
      if (nchars - 1 > nchars_max)
	pedwarn ("string length %qd is greater than the length %qd "
		 "ISO C%d compilers are required to support",
		 nchars - 1, nchars_max, relevant_std);
    }
  e_type = wide_flag ? wchar_type_node : char_type_node;
  i_type = build_index_type (build_int_cst (NULL_TREE, nchars - 1));
  a_type = build_array_type (e_type, i_type);
  if (c_dialect_cxx() || warn_write_strings)
    a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
  TREE_TYPE (value) = a_type;
  TREE_CONSTANT (value) = 1;
  TREE_INVARIANT (value) = 1;
  TREE_READONLY (value) = 1;
  TREE_STATIC (value) = 1;
  return value;
}
tree fix_string_type ( tree value ) { const int wchar_bytes = TYPE_PRECISION ( wchar_type_node ) / BITS_PER_UNIT ; const int wide_flag = TREE_TYPE ( value ) == wchar_array_type_node ; int length = TREE_STRING_LENGTH ( value ) ; int nchars ; tree e_type , i_type , a_type ; nchars = wide_flag ? length / wchar_bytes : length ; if ( warn_overlength_strings ) { const int nchars_max = flag_isoc99 ? 4095 : 509 ; const int relevant_std = flag_isoc99 ? 99 : 90 ; if ( nchars - 1 > nchars_max ) pedwarn ( " " " " , nchars - 1 , nchars_max , relevant_std ) ; } e_type = wide_flag ? wchar_type_node : char_type_node ; i_type = build_index_type ( build_int_cst ( NULL_TREE , nchars - 1 ) ) ; a_type = build_array_type ( e_type , i_type ) ; if ( c_dialect_cxx ( ) || warn_write_strings ) a_type = c_build_qualified_type ( a_type , TYPE_QUAL_CONST ) ; TREE_TYPE ( value ) = a_type ; TREE_CONSTANT ( value ) = 1 ; TREE_INVARIANT ( value ) = 1 ; TREE_READONLY ( value ) = 1 ; TREE_STATIC ( value ) = 1 ; return value ; }
Given a STRING_CST, give it a suitable array-of-chars data type.
Given a STRING_CST give it a suitable array - of - chars data type .
/* Compute the number of elements, for the array type.  */ /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits).  The analogous
     limit in C++98 Annex B is very large (65536) and is not normative,
     so we do not diagnose it (warn_overlength_strings is forced off
     in c_common_post_options).  */ /* Translators: The %d after 'ISO C' will be 90 or 99.  Do not
	   separate the %d from the 'C'.  'ISO' should not be
	   translated, but it may be moved after 'C%d' in languages
	   where modifiers follow nouns.  */ /* Create the array type for the string constant.  The ISO C++
     standard says that a string literal has type `const char[N]' or
     `const wchar_t[N]'.  We use the same logic when invoked as a C
     front-end with -Wwrite-strings.
     ??? We should change the type of an expression depending on the
     state of a warning flag.  We should just be warning -- see how
     this is handled in the C++ front-end for the deprecated implicit
     conversion from string literals to `char*' or `wchar_t*'.

     The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
     array type being the unqualified version of that type.
     Therefore, if we are constructing an array of const char, we must
     construct the matching unqualified array type first.  The C front
     end does not require this, but it does no harm, so we do it
     unconditionally.  */