Commit 5279d739 by Zack Weinberg Committed by Zack Weinberg

c-common.c (STDC_0_IN_SYSTEM_HEADERS, [...]): Default-define here.

	* c-common.c (STDC_0_IN_SYSTEM_HEADERS, REGISTER_PREFIX):
	Default-define here.
	(builtin_define_with_value): Can now wrap the expansion in
	quotation marks if such is wanted.
	(cb_register_builtins): Update calls to	builtin_define_with_value.
	Define __REGISTER_PREFIX__, __USER_LABEL_PREFIX__, and __VERSION__
	here.
	(c_common_init): Set options->stdc_0_in_system_headers.
	* c-lex.h: Update prototype of builtin_define_with_value.
	* cppdefault.h: Remove default definitions of USER_LABEL_PREFIX
	and REGISTER_PREFIX.

	* cppinit.c (VERS, ULP, C, X): Kill.
	(builtin_array): Remove entries for __VERSION__,
	__USER_LABEL_PREFIX__, __REGISTER_PREFIX__, and
	__HAVE_BUILTIN_SETJMP__.  Make __STDC__ always a builtin, not
	a constant.
	(init_builtins): Kill off a bunch of now-dead code.
	(COMMAND_LINE_OPTIONS): Remove -fleading-underscore and
	-fno-leading-underscore.
	(cpp_handle_option): Remove code to set user_label_prefix.
	(cpp_post_options): Likewise.

	* cpplib.h (struct cpp_options): Remove user_label_prefix.
	(stdc_0_in_system_headers): New.
	* cppmacro.c (builtin_macro): Check CPP_OPTION (pfile,
	stdc_0_in_system_headers) too to decide the value of __STDC__.

	* tradcpp.c (user_label_prefix): Kill.
	(main): Remove code handling -f(no-)leading-underscore.
	(initialize_builtins): Don't define __REGISTER_PREFIX__
	or __USER_LABEL_PREFIX__.
	(install_value): Wrap compound statement in dummy loop so the
	macro works properly in an if statement.

From-SVN: r53525
parent 62e6ca55
2002-05-16 Zack Weinberg <zack@codesourcery.com>
* c-common.c (STDC_0_IN_SYSTEM_HEADERS, REGISTER_PREFIX):
Default-define here.
(builtin_define_with_value): Can now wrap the expansion in
quotation marks if such is wanted.
(cb_register_builtins): Update calls to builtin_define_with_value.
Define __REGISTER_PREFIX__, __USER_LABEL_PREFIX__, and __VERSION__
here.
(c_common_init): Set options->stdc_0_in_system_headers.
* c-lex.h: Update prototype of builtin_define_with_value.
* cppdefault.h: Remove default definitions of USER_LABEL_PREFIX
and REGISTER_PREFIX.
* cppinit.c (VERS, ULP, C, X): Kill.
(builtin_array): Remove entries for __VERSION__,
__USER_LABEL_PREFIX__, __REGISTER_PREFIX__, and
__HAVE_BUILTIN_SETJMP__. Make __STDC__ always a builtin, not
a constant.
(init_builtins): Kill off a bunch of now-dead code.
(COMMAND_LINE_OPTIONS): Remove -fleading-underscore and
-fno-leading-underscore.
(cpp_handle_option): Remove code to set user_label_prefix.
(cpp_post_options): Likewise.
* cpplib.h (struct cpp_options): Remove user_label_prefix.
(stdc_0_in_system_headers): New.
* cppmacro.c (builtin_macro): Check CPP_OPTION (pfile,
stdc_0_in_system_headers) too to decide the value of __STDC__.
* tradcpp.c (user_label_prefix): Kill.
(main): Remove code handling -f(no-)leading-underscore.
(initialize_builtins): Don't define __REGISTER_PREFIX__
or __USER_LABEL_PREFIX__.
(install_value): Wrap compound statement in dummy loop so the
macro works properly in an if statement.
2002-05-16 Janis Johnson <janis187@us.ibm.com> 2002-05-16 Janis Johnson <janis187@us.ibm.com>
* loop.h (struct loop_info): Add member has_prefetch. * loop.h (struct loop_info): Add member has_prefetch.
......
...@@ -83,6 +83,14 @@ cpp_reader *parse_in; /* Declared in c-lex.h. */ ...@@ -83,6 +83,14 @@ cpp_reader *parse_in; /* Declared in c-lex.h. */
: "long long unsigned int")) : "long long unsigned int"))
#endif #endif
#ifndef STDC_0_IN_SYSTEM_HEADERS
#define STDC_0_IN_SYSTEM_HEADERS 0
#endif
#ifndef REGISTER_PREFIX
#define REGISTER_PREFIX ""
#endif
/* The variant of the C language being processed. */ /* The variant of the C language being processed. */
enum c_language_kind c_language; enum c_language_kind c_language;
...@@ -4331,10 +4339,17 @@ cb_register_builtins (pfile) ...@@ -4331,10 +4339,17 @@ cb_register_builtins (pfile)
cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__"); cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
/* stddef.h needs to know these. */ /* stddef.h needs to know these. */
builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE); builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE); builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE); builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE); builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
/* For use in assembly language. */
builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
/* Misc. */
builtin_define_with_value ("__VERSION__", version_string, 1);
/* A straightforward target hook doesn't work, because of problems /* A straightforward target hook doesn't work, because of problems
linking that hook's body when part of non-C front ends. */ linking that hook's body when part of non-C front ends. */
...@@ -4385,23 +4400,28 @@ builtin_define_std (macro) ...@@ -4385,23 +4400,28 @@ builtin_define_std (macro)
} }
} }
/* Pass an object-like macro and a value to define it to. */ /* Pass an object-like macro and a value to define it to. The third
parameter says whether or not to turn the value into a string
constant. */
void void
builtin_define_with_value (macro, expansion) builtin_define_with_value (macro, expansion, is_str)
const char *macro; const char *macro;
const char *expansion; const char *expansion;
int is_str;
{ {
char *buf, *q; char *buf;
size_t mlen = strlen (macro); size_t mlen = strlen (macro);
size_t elen = strlen (expansion); size_t elen = strlen (expansion);
size_t extra = 2; /* space for an = and a NUL */
q = buf = alloca (mlen + elen + 2); if (is_str)
memcpy (q, macro, mlen); extra += 2; /* space for two quote marks */
q += mlen;
*q++ = '='; buf = alloca (mlen + elen + extra);
memcpy (q, expansion, elen); if (is_str)
q += elen; sprintf (buf, "%s=\"%s\"", macro, expansion);
*q = '\0'; else
sprintf (buf, "%s=%s", macro, expansion);
cpp_define (parse_in, buf); cpp_define (parse_in, buf);
} }
...@@ -4429,6 +4449,7 @@ c_common_init (filename) ...@@ -4429,6 +4449,7 @@ c_common_init (filename)
options->unsigned_char = !flag_signed_char; */ options->unsigned_char = !flag_signed_char; */
options->warn_multichar = warn_multichar; options->warn_multichar = warn_multichar;
options->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
/* Register preprocessor built-ins before calls to /* Register preprocessor built-ins before calls to
cpp_main_file. */ cpp_main_file. */
......
...@@ -49,7 +49,10 @@ extern struct cpp_reader* parse_in; ...@@ -49,7 +49,10 @@ extern struct cpp_reader* parse_in;
"_mips". */ "_mips". */
extern void builtin_define_std PARAMS ((const char *)); extern void builtin_define_std PARAMS ((const char *));
/* Pass an object-like macro and a value to define it to. */ /* Pass an object-like macro and a value to define it to. The third
extern void builtin_define_with_value PARAMS ((const char *, const char *)); parameter says whether or not to turn the value into a string
constant. */
extern void builtin_define_with_value PARAMS ((const char *, const char *,
int));
#endif /* ! GCC_C_LEX_H */ #endif /* ! GCC_C_LEX_H */
...@@ -42,24 +42,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -42,24 +42,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#undef CROSS_INCLUDE_DIR #undef CROSS_INCLUDE_DIR
#endif #endif
/* We let tm.h override the types used here, to handle trivial differences
such as the choice of unsigned int or long unsigned int for size_t.
When machines start needing nontrivial differences in the size type,
it would be best to do something here to figure out automatically
from other information what type to use. */
/* The string value for __USER_LABEL_PREFIX__ */
#ifndef USER_LABEL_PREFIX
#define USER_LABEL_PREFIX ""
#endif
/* The string value for __REGISTER_PREFIX__ */
#ifndef REGISTER_PREFIX
#define REGISTER_PREFIX ""
#endif
/* This is the default list of directories to search for include files. /* This is the default list of directories to search for include files.
It may be overridden by the various -I and -ixxx options. It may be overridden by the various -I and -ixxx options.
......
...@@ -623,11 +623,6 @@ cpp_destroy (pfile) ...@@ -623,11 +623,6 @@ cpp_destroy (pfile)
known at build time should not be flagged BUILTIN, as then they do known at build time should not be flagged BUILTIN, as then they do
not appear in macro dumps with e.g. -dM or -dD. not appear in macro dumps with e.g. -dM or -dD.
Two values are not compile time constants, so we tag
them in the FLAGS field instead:
VERS value is the global version_string, quoted
ULP value is the global user_label_prefix
Also, macros with CPLUS set in the flags field are entered only for C++. */ Also, macros with CPLUS set in the flags field are entered only for C++. */
struct builtin struct builtin
{ {
...@@ -638,15 +633,11 @@ struct builtin ...@@ -638,15 +633,11 @@ struct builtin
unsigned short flags; unsigned short flags;
unsigned short len; unsigned short len;
}; };
#define VERS 0x01
#define ULP 0x02
#define CPLUS 0x04 #define CPLUS 0x04
#define BUILTIN 0x08 #define BUILTIN 0x08
#define OPERATOR 0x10 #define OPERATOR 0x10
#define B(n, t) { U n, 0, t, 0, BUILTIN, sizeof n - 1 } #define B(n, t) { U n, 0, t, 0, BUILTIN, sizeof n - 1 }
#define C(n, v) { U n, v, 0, 0, 0, sizeof n - 1 }
#define X(n, f) { U n, 0, 0, 0, f, sizeof n - 1 }
#define O(n, c, f) { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 } #define O(n, c, f) { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 }
static const struct builtin builtin_array[] = static const struct builtin builtin_array[] =
{ {
...@@ -657,16 +648,7 @@ static const struct builtin builtin_array[] = ...@@ -657,16 +648,7 @@ static const struct builtin builtin_array[] =
B("__LINE__", BT_SPECLINE), B("__LINE__", BT_SPECLINE),
B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL), B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
B("_Pragma", BT_PRAGMA), B("_Pragma", BT_PRAGMA),
X("__VERSION__", VERS),
X("__USER_LABEL_PREFIX__", ULP),
C("__REGISTER_PREFIX__", REGISTER_PREFIX),
C("__HAVE_BUILTIN_SETJMP__", "1"),
#ifdef STDC_0_IN_SYSTEM_HEADERS
B("__STDC__", BT_STDC), B("__STDC__", BT_STDC),
#else
C("__STDC__", "1"),
#endif
/* Named operators known to the preprocessor. These cannot be #defined /* Named operators known to the preprocessor. These cannot be #defined
and always have their stated meaning. They are treated like normal and always have their stated meaning. They are treated like normal
...@@ -685,8 +667,6 @@ static const struct builtin builtin_array[] = ...@@ -685,8 +667,6 @@ static const struct builtin builtin_array[] =
O("xor_eq", CPP_XOR_EQ, CPLUS) O("xor_eq", CPP_XOR_EQ, CPLUS)
}; };
#undef B #undef B
#undef C
#undef X
#undef O #undef O
#define builtin_array_end (builtin_array + ARRAY_SIZE (builtin_array)) #define builtin_array_end (builtin_array + ARRAY_SIZE (builtin_array))
...@@ -700,51 +680,24 @@ init_builtins (pfile) ...@@ -700,51 +680,24 @@ init_builtins (pfile)
for(b = builtin_array; b < builtin_array_end; b++) for(b = builtin_array; b < builtin_array_end; b++)
{ {
cpp_hashnode *hp;
if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus)) if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus))
continue; continue;
if ((b->flags & OPERATOR) && ! CPP_OPTION (pfile, operator_names)) if ((b->flags & OPERATOR) && ! CPP_OPTION (pfile, operator_names))
continue; continue;
if (b->flags & (OPERATOR | BUILTIN)) hp = cpp_lookup (pfile, b->name, b->len);
if (b->flags & OPERATOR)
{ {
cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); hp->flags |= NODE_OPERATOR;
if (b->flags & OPERATOR) hp->value.operator = b->operator;
{
hp->flags |= NODE_OPERATOR;
hp->value.operator = b->operator;
}
else
{
hp->type = NT_MACRO;
hp->flags |= NODE_BUILTIN | NODE_WARN;
hp->value.builtin = b->builtin;
}
} }
else /* A standard macro of some kind. */ else
{ {
const char *val; hp->type = NT_MACRO;
char *str; hp->flags |= NODE_BUILTIN | NODE_WARN;
hp->value.builtin = b->builtin;
if (b->flags & VERS)
{
/* Allocate enough space for 'name "value"\n\0'. */
str = alloca (b->len + strlen (version_string) + 5);
sprintf (str, "%s \"%s\"\n", b->name, version_string);
}
else
{
if (b->flags & ULP)
val = CPP_OPTION (pfile, user_label_prefix);
else
val = b->value;
/* Allocate enough space for "name value\n\0". */
str = alloca (b->len + strlen (val) + 3);
sprintf(str, "%s %s\n", b->name, val);
}
_cpp_define_builtin (pfile, str);
} }
} }
...@@ -1209,8 +1162,6 @@ new_pending_directive (pend, text, handler) ...@@ -1209,8 +1162,6 @@ new_pending_directive (pend, text, handler)
DEF_OPT("U", no_mac, OPT_U) \ DEF_OPT("U", no_mac, OPT_U) \
DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \ DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
DEF_OPT("d", no_arg, OPT_d) \ DEF_OPT("d", no_arg, OPT_d) \
DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \
DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \
DEF_OPT("fno-operator-names", 0, OPT_fno_operator_names) \ DEF_OPT("fno-operator-names", 0, OPT_fno_operator_names) \
DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \ DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \ DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
...@@ -1408,12 +1359,6 @@ cpp_handle_option (pfile, argc, argv, ignore) ...@@ -1408,12 +1359,6 @@ cpp_handle_option (pfile, argc, argv, ignore)
{ {
case N_OPTS: /* Shut GCC up. */ case N_OPTS: /* Shut GCC up. */
break; break;
case OPT_fleading_underscore:
CPP_OPTION (pfile, user_label_prefix) = "_";
break;
case OPT_fno_leading_underscore:
CPP_OPTION (pfile, user_label_prefix) = "";
break;
case OPT_fno_operator_names: case OPT_fno_operator_names:
CPP_OPTION (pfile, operator_names) = 0; CPP_OPTION (pfile, operator_names) = 0;
break; break;
...@@ -1843,10 +1788,6 @@ cpp_post_options (pfile) ...@@ -1843,10 +1788,6 @@ cpp_post_options (pfile)
if (CPP_OPTION (pfile, cplusplus)) if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0; CPP_OPTION (pfile, warn_traditional) = 0;
/* Set this if it hasn't been set already. */
if (CPP_OPTION (pfile, user_label_prefix) == NULL)
CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
/* Permanently disable macro expansion if we are rescanning /* Permanently disable macro expansion if we are rescanning
preprocessed text. */ preprocessed text. */
if (CPP_OPTION (pfile, preprocessed)) if (CPP_OPTION (pfile, preprocessed))
......
...@@ -248,9 +248,6 @@ struct cpp_options ...@@ -248,9 +248,6 @@ struct cpp_options
const char *include_prefix; const char *include_prefix;
unsigned int include_prefix_len; unsigned int include_prefix_len;
/* -fleading_underscore sets this to "_". */
const char *user_label_prefix;
/* The language we're preprocessing. */ /* The language we're preprocessing. */
enum c_lang lang; enum c_lang lang;
...@@ -397,6 +394,9 @@ struct cpp_options ...@@ -397,6 +394,9 @@ struct cpp_options
/* Nonzero means chars (wide chars) are unsigned. */ /* Nonzero means chars (wide chars) are unsigned. */
unsigned char unsigned_char, unsigned_wchar; unsigned char unsigned_char, unsigned_wchar;
/* Nonzero means __STDC__ should have the value 0 in system headers. */
unsigned char stdc_0_in_system_headers;
}; };
/* Call backs. */ /* Call backs. */
......
...@@ -172,10 +172,20 @@ builtin_macro (pfile, node) ...@@ -172,10 +172,20 @@ builtin_macro (pfile, node)
pfile->cur_token[-1].line)); pfile->cur_token[-1].line));
break; break;
/* __STDC__ has the value 1 under normal circumstances.
However, if (a) we are in a system header, (b) the option
stdc_0_in_system_headers is true, and (c) __STRICT_ANSI__ is
not defined, then it has the value 0. */
case BT_STDC: case BT_STDC:
{ {
int stdc = (!CPP_IN_SYSTEM_HEADER (pfile) int stdc;
|| pfile->spec_nodes.n__STRICT_ANSI__->type != NT_VOID); if (CPP_IN_SYSTEM_HEADER (pfile)
&& CPP_OPTION (pfile, stdc_0_in_system_headers)
&& pfile->spec_nodes.n__STRICT_ANSI__->type == NT_VOID)
stdc = 0;
else
stdc = 1;
result = new_number_token (pfile, stdc); result = new_number_token (pfile, stdc);
} }
break; break;
......
...@@ -103,10 +103,6 @@ int warn_comments; ...@@ -103,10 +103,6 @@ int warn_comments;
int no_output; int no_output;
/* Value of __USER_LABEL_PREFIX__. Target-dependent, also controlled
by -f(no-)leading-underscore. */
static const char *user_label_prefix;
/* I/O buffer structure. /* I/O buffer structure.
The `fname' field is nonzero for source files and #include files The `fname' field is nonzero for source files and #include files
and for the dummy text used for -D and -U. and for the dummy text used for -D and -U.
...@@ -631,11 +627,7 @@ main (argc, argv) ...@@ -631,11 +627,7 @@ main (argc, argv)
break; break;
case 'f': case 'f':
if (!strcmp (argv[i], "-fleading-underscore")) if (!strcmp (argv[i], "-fsigned-char"))
user_label_prefix = "_";
else if (!strcmp (argv[i], "-fno-leading-underscore"))
user_label_prefix = "";
else if (!strcmp (argv[i], "-fsigned-char"))
flag_signed_char = 1; flag_signed_char = 1;
else if (!strcmp (argv[i], "-funsigned-char")) else if (!strcmp (argv[i], "-funsigned-char"))
flag_signed_char = 0; flag_signed_char = 0;
...@@ -811,9 +803,6 @@ main (argc, argv) ...@@ -811,9 +803,6 @@ main (argc, argv)
&& (deps_missing_files || deps_file || print_deps_phony_targets)) && (deps_missing_files || deps_file || print_deps_phony_targets))
fatal ("you must additionally specify either -M or -MM"); fatal ("you must additionally specify either -M or -MM");
if (user_label_prefix == 0)
user_label_prefix = USER_LABEL_PREFIX;
if (print_deps) if (print_deps)
{ {
/* Set the default target (if there is none already), and /* Set the default target (if there is none already), and
...@@ -5134,8 +5123,9 @@ dump_arg_n (defn, argnum) ...@@ -5134,8 +5123,9 @@ dump_arg_n (defn, argnum)
#define DSC(x) U x, sizeof x - 1 #define DSC(x) U x, sizeof x - 1
#define install_spec(name, type) \ #define install_spec(name, type) \
install(DSC(name), type, -1); install(DSC(name), type, -1);
#define install_value(name, val) \ #define install_value(name, val) do { \
hp = install(DSC(name), T_CONST, -1); hp->value.cpval = val; hp = install(DSC(name), T_CONST, -1); hp->value.cpval = val; \
} while (0)
static void static void
initialize_builtins () initialize_builtins ()
{ {
...@@ -5149,9 +5139,6 @@ initialize_builtins () ...@@ -5149,9 +5139,6 @@ initialize_builtins ()
install_spec ("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL); install_spec ("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL);
install_spec ("__LINE__", T_SPECLINE); install_spec ("__LINE__", T_SPECLINE);
install_value ("__REGISTER_PREFIX__", REGISTER_PREFIX);
install_value ("__USER_LABEL_PREFIX__", user_label_prefix);
if (flag_signed_char == 0) if (flag_signed_char == 0)
install_value ("__CHAR_UNSIGNED__", "1"); install_value ("__CHAR_UNSIGNED__", "1");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment