Move more predefined macros

Zack Weinberg zack@codesourcery.com
Wed May 15 23:12:00 GMT 2002


This patch moves the definition of __REGISTER_PREFIX__,
__USER_LABEL_PREFIX__, and __VERSION__ into c-common.c, and eliminates
__HAVE_BUILTIN_SETJMP__.  It also adjusts the way the
STDC_0_IN_SYSTEM_HEADERS hack works so that it does not require
#ifdeffage in cpplib.

No target-specific code is affected.  Neil, I'd like your opinion on
the aesthetics of the change to builtin_define_with_value; should the
flag parameter be two separate functions instead?

Future potential changes along these lines are: move the
builtin_define_* routines from c-common to cpplib (they are
semi-duplicates of internal cpplib routines); move the definitions of
__cplusplus etc to c-common.  I'd appreciate opinions on both.

All the default definitions at the top of c-common.c probably belong
somewhere else.  Is there a reason they aren't in defaults.h, which
seems the obvious place to me?

I'm running an i686-linux bootstrap overnight.  Assuming it goes
through, OK for mainline?

zw

	* 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.

===================================================================
Index: c-common.c
--- c-common.c	15 May 2002 05:29:43 -0000	1.322
+++ c-common.c	16 May 2002 05:55:30 -0000
@@ -83,6 +83,14 @@ cpp_reader *parse_in;		/* Declared in c-
 			: "long long unsigned int"))
 #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.  */
 
 enum c_language_kind c_language;
@@ -4331,10 +4339,17 @@ cb_register_builtins (pfile)
     cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
 
   /* stddef.h needs to know these.  */
-  builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE);
-  builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE);
-  builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE);
-  builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE);
+  builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
+  builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
+  builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
+  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
      linking that hook's body when part of non-C front ends.  */
@@ -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
-builtin_define_with_value (macro, expansion)
+builtin_define_with_value (macro, expansion, is_str)
      const char *macro;
      const char *expansion;
+     int is_str;
 {
-  char *buf, *q;
+  char *buf;
   size_t mlen = strlen (macro);
   size_t elen = strlen (expansion);
+  size_t extra = 2;  /* space for an = and a NUL */
+
+  if (is_str)
+    extra += 2;  /* space for two quote marks */
 
-  q = buf = alloca (mlen + elen + 2);
-  memcpy (q, macro, mlen);
-  q += mlen;
-  *q++ = '=';
-  memcpy (q, expansion, elen);
-  q += elen;
-  *q = '\0';
+  buf = alloca (mlen + elen + extra);
+  if (is_str)
+    sprintf (buf, "%s=\"%s\"", macro, expansion);
+  else
+    sprintf (buf, "%s=%s", macro, expansion);
 
   cpp_define (parse_in, buf);
 }
@@ -4429,6 +4449,7 @@ c_common_init (filename)
      options->unsigned_char = !flag_signed_char; */
 
   options->warn_multichar = warn_multichar;
+  options->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
 
   /* Register preprocessor built-ins before calls to
      cpp_main_file.  */
===================================================================
Index: c-lex.h
--- c-lex.h	15 May 2002 05:29:44 -0000	1.29
+++ c-lex.h	16 May 2002 05:55:30 -0000
@@ -49,7 +49,10 @@ extern struct cpp_reader* parse_in;
    "_mips".  */
 extern void builtin_define_std PARAMS ((const char *));
 
-/* Pass an object-like macro and a value to define it to.  */
-extern void builtin_define_with_value PARAMS ((const char *, const char *));
+/* 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.  */
+extern void builtin_define_with_value PARAMS ((const char *, const char *,
+					       int));
 
 #endif /* ! GCC_C_LEX_H */
===================================================================
Index: cppdefault.h
--- cppdefault.h	15 May 2002 05:29:44 -0000	1.5
+++ cppdefault.h	16 May 2002 05:55:30 -0000
@@ -42,24 +42,6 @@ Foundation, 59 Temple Place - Suite 330,
 #undef CROSS_INCLUDE_DIR
 #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.
    It may be overridden by the various -I and -ixxx options.
 
===================================================================
Index: cppinit.c
--- cppinit.c	15 May 2002 05:29:44 -0000	1.223
+++ cppinit.c	16 May 2002 05:55:30 -0000
@@ -623,11 +623,6 @@ cpp_destroy (pfile)
    known at build time should not be flagged BUILTIN, as then they do
    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++.  */
 struct builtin
 {
@@ -638,15 +633,11 @@ struct builtin
   unsigned short flags;
   unsigned short len;
 };
-#define VERS		0x01
-#define ULP		0x02
 #define CPLUS		0x04
 #define BUILTIN		0x08
 #define OPERATOR  	0x10
 
 #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 }
 static const struct builtin builtin_array[] =
 {
@@ -657,16 +648,7 @@ static const struct builtin builtin_arra
   B("__LINE__",		 BT_SPECLINE),
   B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
   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),
-#else
-  C("__STDC__",		 "1"),
-#endif
 
   /* Named operators known to the preprocessor.  These cannot be #defined
      and always have their stated meaning.  They are treated like normal
@@ -685,8 +667,6 @@ static const struct builtin builtin_arra
   O("xor_eq",	CPP_XOR_EQ,  CPLUS)
 };
 #undef B
-#undef C
-#undef X
 #undef O
 #define builtin_array_end (builtin_array + ARRAY_SIZE (builtin_array))
 
@@ -700,51 +680,24 @@ init_builtins (pfile)
 
   for(b = builtin_array; b < builtin_array_end; b++)
     {
+      cpp_hashnode *hp;
       if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus))
 	continue;
 
       if ((b->flags & OPERATOR) && ! CPP_OPTION (pfile, operator_names))
 	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);
-	  if (b->flags & 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;
-	    }
+	  hp->flags |= NODE_OPERATOR;
+	  hp->value.operator = b->operator;
 	}
-      else			/* A standard macro of some kind.  */
+      else
 	{
-	  const char *val;
-	  char *str;
-
-	  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);
+	  hp->type = NT_MACRO;
+	  hp->flags |= NODE_BUILTIN | NODE_WARN;
+	  hp->value.builtin = b->builtin;
 	}
     }
 
@@ -1209,8 +1162,6 @@ new_pending_directive (pend, text, handl
   DEF_OPT("U",                        no_mac, OPT_U)                          \
   DEF_OPT("W",                        no_arg, OPT_W)  /* arg optional */      \
   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-preprocessed",         0,      OPT_fno_preprocessed)           \
   DEF_OPT("fno-show-column",          0,      OPT_fno_show_column)            \
@@ -1408,12 +1359,6 @@ cpp_handle_option (pfile, argc, argv, ig
 	{
 	case N_OPTS: /* Shut GCC up.  */
 	  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:
 	  CPP_OPTION (pfile, operator_names) = 0;
 	  break;
@@ -1842,10 +1787,6 @@ cpp_post_options (pfile)
   /* -Wtraditional is not useful in C++ mode.  */
   if (CPP_OPTION (pfile, cplusplus))
     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
      preprocessed text.  */
===================================================================
Index: cpplib.h
--- cpplib.h	7 May 2002 21:07:15 -0000	1.216
+++ cpplib.h	16 May 2002 05:55:30 -0000
@@ -248,9 +248,6 @@ struct cpp_options
   const char *include_prefix;
   unsigned int include_prefix_len;
 
-  /* -fleading_underscore sets this to "_".  */
-  const char *user_label_prefix;
-
   /* The language we're preprocessing.  */
   enum c_lang lang;
 
@@ -397,6 +394,9 @@ struct cpp_options
 
   /* Nonzero means chars (wide chars) are unsigned.  */
   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.  */
===================================================================
Index: cppmacro.c
--- cppmacro.c	9 May 2002 17:14:10 -0000	1.102
+++ cppmacro.c	16 May 2002 05:55:31 -0000
@@ -184,10 +184,20 @@ builtin_macro (pfile, node)
 					      pfile->cur_token[-1].line));
       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:
       {
-	int stdc = (!CPP_IN_SYSTEM_HEADER (pfile)
-		    || pfile->spec_nodes.n__STRICT_ANSI__->type != NT_VOID);
+	int stdc;
+	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);
       }
       break;
===================================================================
Index: tradcpp.c
--- tradcpp.c	15 May 2002 05:29:46 -0000	1.51
+++ tradcpp.c	16 May 2002 05:55:32 -0000
@@ -103,10 +103,6 @@ int warn_comments;
 
 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.
    The `fname' field is nonzero for source files and #include files
    and for the dummy text used for -D and -U.
@@ -631,11 +627,7 @@ main (argc, argv)
 	break;
 
       case 'f':
-	if (!strcmp (argv[i], "-fleading-underscore"))
-	  user_label_prefix = "_";
-	else if (!strcmp (argv[i], "-fno-leading-underscore"))
-	  user_label_prefix = "";
-	else if (!strcmp (argv[i], "-fsigned-char"))
+	if (!strcmp (argv[i], "-fsigned-char"))
 	  flag_signed_char = 1;
 	else if (!strcmp (argv[i], "-funsigned-char"))
 	  flag_signed_char = 0;
@@ -811,9 +803,6 @@ main (argc, argv)
       && (deps_missing_files || deps_file || print_deps_phony_targets))
     fatal ("you must additionally specify either -M or -MM");
 
-  if (user_label_prefix == 0)
-    user_label_prefix = USER_LABEL_PREFIX;
-
   if (print_deps)
     {
       /* Set the default target (if there is none already), and
@@ -5148,9 +5137,6 @@ initialize_builtins ()
   install_spec ("__VERSION__",       T_VERSION);
   install_spec ("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL);
   install_spec ("__LINE__",          T_SPECLINE);
-
-  install_value ("__REGISTER_PREFIX__",   REGISTER_PREFIX);
-  install_value ("__USER_LABEL_PREFIX__", user_label_prefix);
 
   if (flag_signed_char == 0)
     install_value ("__CHAR_UNSIGNED__", "1");




More information about the Gcc-patches mailing list