cppinit.c (MAX_WCHAR_TYPE_SIZE): Move to cpplib.h

* cppinit.c (MAX_WCHAR_TYPE_SIZE): Move to cpplib.h
	(cpp_post_options): Move sanity checks to...
	(sanity_checks): New.
	* cpplex.c (maybe_read_ucs): Fix prototype.
	(parse_string, cpp_parse_escape): Cast for %c format specifier.
	* cpplib.h (cppchar_t): Use unsigned long or unsigned long long
	if necessary.

From-SVN: r53163
This commit is contained in:
Neil Booth 2002-05-04 19:42:01 +00:00 committed by Neil Booth
parent 916b60b71e
commit 625458d0b9
4 changed files with 68 additions and 35 deletions

View File

@ -1,3 +1,13 @@
2002-05-04 Neil Booth <neil@daikokuya.demon.co.uk>
* cppinit.c (MAX_WCHAR_TYPE_SIZE): Move to cpplib.h
(cpp_post_options): Move sanity checks to...
(sanity_checks): New.
* cpplex.c (maybe_read_ucs): Fix prototype.
(parse_string, cpp_parse_escape): Cast for %c format specifier.
* cpplib.h (cppchar_t): Use unsigned long or unsigned long long
if necessary.
2002-05-04 Bernd Schmidt <bernds@redhat.com> 2002-05-04 Bernd Schmidt <bernds@redhat.com>
* config/i386/i386.c (bdesc_2arg): Add a couple of missing SSE2 * config/i386/i386.c (bdesc_2arg): Add a couple of missing SSE2

View File

@ -509,9 +509,6 @@ cpp_create_reader (lang)
#define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE #define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE
#endif #endif
CPP_OPTION (pfile, char_precision) = MAX_CHAR_TYPE_SIZE; CPP_OPTION (pfile, char_precision) = MAX_CHAR_TYPE_SIZE;
#ifndef MAX_WCHAR_TYPE_SIZE
#define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
#endif
CPP_OPTION (pfile, wchar_precision) = MAX_WCHAR_TYPE_SIZE; CPP_OPTION (pfile, wchar_precision) = MAX_WCHAR_TYPE_SIZE;
/* It's simplest to just create this struct whether or not it will /* It's simplest to just create this struct whether or not it will
@ -1793,12 +1790,46 @@ cpp_handle_options (pfile, argc, argv)
return i; return i;
} }
/* Sanity-checks are dependent on command-line options, so it is
called as a subroutine of cpp_post_options (). */
#if ENABLE_CHECKING
static void sanity_checks PARAMS ((cpp_reader *));
static void sanity_checks (pfile)
cpp_reader *pfile;
{
cppchar_t test = 0;
size_t max_prec;
/* Sanity checks for CPP arithmetic. */
test--;
if (test < 1)
cpp_error (pfile, DL_FATAL, "cppchar_t must be an unsigned type");
if (CPP_OPTION (pfile, precision) > BITS_PER_HOST_WIDEST_INT)
cpp_error (pfile, DL_FATAL,
"preprocessor arithmetic has maximum precision of %u bits; target requires %u bits",
BITS_PER_HOST_WIDEST_INT, CPP_OPTION (pfile, precision));
max_prec = CPP_OPTION (pfile, char_precision);
if (max_prec < CPP_OPTION (pfile, wchar_precision))
max_prec = CPP_OPTION (pfile, wchar_precision);
if (max_prec > BITS_PER_CPPCHAR_T)
cpp_error (pfile, DL_FATAL,
"CPP on this host cannot handle (wide) character constants over %u bits, but the target requires %u bits",
BITS_PER_CPPCHAR_T, max_prec);
}
#else
# define sanity_checks(PFILE)
#endif
/* Extra processing when all options are parsed, after all calls to /* Extra processing when all options are parsed, after all calls to
cpp_handle_option[s]. Consistency checks etc. */ cpp_handle_option[s]. Consistency checks etc. */
void void
cpp_post_options (pfile) cpp_post_options (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
sanity_checks (pfile);
if (pfile->print_version) if (pfile->print_version)
{ {
fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string); fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
@ -1808,27 +1839,6 @@ cpp_post_options (pfile)
fputc ('\n', stderr); fputc ('\n', stderr);
} }
#if ENABLE_CHECKING
/* Sanity checks for CPP arithmetic. */
if (CPP_OPTION (pfile, precision) > BITS_PER_HOST_WIDEST_INT)
cpp_error (pfile, DL_FATAL,
"preprocessor arithmetic has maximum precision of %u bits; target requires %u bits",
BITS_PER_HOST_WIDEST_INT, CPP_OPTION (pfile, precision));
if (CPP_OPTION (pfile, char_precision) > BITS_PER_CPPCHAR_T
|| CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T)
cpp_error (pfile, DL_FATAL,
"CPP cannot handle (wide) character constants over %u bits",
BITS_PER_CPPCHAR_T);
{
cppchar_t test = 0;
test--;
if (test < 1)
cpp_error (pfile, DL_FATAL, "cppchar_t must be an unsigned type");
}
#endif
/* Canonicalize in_fname and out_fname. We guarantee they are not /* Canonicalize in_fname and out_fname. We guarantee they are not
NULL, and that the empty string represents stdin / stdout. */ NULL, and that the empty string represents stdin / stdout. */
if (CPP_OPTION (pfile, in_fname) == NULL if (CPP_OPTION (pfile, in_fname) == NULL

View File

@ -80,7 +80,7 @@ static void save_comment PARAMS ((cpp_reader *, cpp_token *, const uchar *,
cppchar_t)); cppchar_t));
static int name_p PARAMS ((cpp_reader *, const cpp_string *)); static int name_p PARAMS ((cpp_reader *, const cpp_string *));
static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **, static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **,
const unsigned char *, unsigned int *)); const unsigned char *, cppchar_t *));
static tokenrun *next_tokenrun PARAMS ((tokenrun *)); static tokenrun *next_tokenrun PARAMS ((tokenrun *));
static unsigned int hex_digit_value PARAMS ((unsigned int)); static unsigned int hex_digit_value PARAMS ((unsigned int));
@ -695,7 +695,7 @@ parse_string (pfile, token, terminator)
unterminated: unterminated:
if (CPP_OPTION (pfile, lang) != CLK_ASM || terminator == '>') if (CPP_OPTION (pfile, lang) != CLK_ASM || terminator == '>')
cpp_error (pfile, DL_ERROR, "missing terminating %c character", cpp_error (pfile, DL_ERROR, "missing terminating %c character",
terminator); (int) terminator);
buffer->cur--; buffer->cur--;
break; break;
} }
@ -1648,7 +1648,7 @@ maybe_read_ucs (pfile, pstr, limit, pc)
cpp_reader *pfile; cpp_reader *pfile;
const unsigned char **pstr; const unsigned char **pstr;
const unsigned char *limit; const unsigned char *limit;
unsigned int *pc; cppchar_t *pc;
{ {
const unsigned char *p = *pstr; const unsigned char *p = *pstr;
unsigned int code = 0; unsigned int code = 0;
@ -1763,7 +1763,7 @@ cpp_parse_escape (pfile, pstr, limit, wide)
case 'e': case 'E': case 'e': case 'E':
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_error (pfile, DL_PEDWARN, cpp_error (pfile, DL_PEDWARN,
"non-ISO-standard escape sequence, '\\%c'", c); "non-ISO-standard escape sequence, '\\%c'", (int) c);
c = TARGET_ESC; c = TARGET_ESC;
break; break;
@ -1838,9 +1838,11 @@ cpp_parse_escape (pfile, pstr, limit, wide)
if (unknown) if (unknown)
{ {
if (ISGRAPH (c)) if (ISGRAPH (c))
cpp_error (pfile, DL_PEDWARN, "unknown escape sequence '\\%c'", c); cpp_error (pfile, DL_PEDWARN,
"unknown escape sequence '\\%c'", (int) c);
else else
cpp_error (pfile, DL_PEDWARN, "unknown escape sequence: '\\%03o'", c); cpp_error (pfile, DL_PEDWARN,
"unknown escape sequence: '\\%03o'", (int) c);
} }
if (c > mask) if (c > mask)

View File

@ -191,11 +191,22 @@ struct cpp_token
}; };
/* A type wide enough to hold any multibyte source character. /* A type wide enough to hold any multibyte source character.
cpplib's character constant interpreter uses shifts, and so cpplib's character constant interpreter requires an unsigned type.
requires an unsigned type. */ Also, a typedef for the signed equivalent. */
typedef unsigned int cppchar_t; #ifndef MAX_WCHAR_TYPE_SIZE
/* Its signed equivalent. */ # define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
typedef int cppchar_signed_t; #endif
#if SIZEOF_INT >= MAX_WCHAR_TYPE_SIZE
# define CPPCHAR_SIGNED_T int
#else
# if SIZEOF_LONG >= MAX_WCHAR_TYPE_SIZE || !HAVE_LONG_LONG
# define CPPCHAR_SIGNED_T long
# else
# define CPPCHAR_SIGNED_T long long
# endif
#endif
typedef unsigned CPPCHAR_SIGNED_T cppchar_t;
typedef CPPCHAR_SIGNED_T cppchar_signed_t;
/* Values for opts.dump_macros. /* Values for opts.dump_macros.
dump_only means inhibit output of the preprocessed text dump_only means inhibit output of the preprocessed text