cpplib: Further cleanup (was: Re: cpplib: initialisation cleanup)

Neil Booth NeilB@earthling.net
Thu Aug 17 13:53:00 GMT 2000


Zack Weinberg wrote:-

> I think there are a couple more static table initializations that
> should be done in cpp_init() too.  Look in cpplex.c.

I only found trigraph_map, done below.  Doing this fixed a couple of
minor issues, too.

> Ask rth.  I believe this has to do with user_label_prefix being a
> global in cc1, and cpplib's version possibly not getting set when it's
> integrated into cc1.  This may no longer be a problem; in my tests,
> cpplib and the C front end both see options like -lang-objc of
> interest to both.

OK, I'll come back to this later when I've checked exactly what the
implications might be.

This patch moves init_trigraph_map to cpp_init (), makes the condition
of whether to do run-time initialisation consistent between the header
and the file itself.  Also replaces 256 with UCHAR_MAX + 1.  It also
removes a bunch of accumulated cruft that isn't being used anymore,
and replaces all remaining strncmps with memcmps (apart from one in
cppfiles.c that is not important).

I'm running a bootstrap at present.

Neil.

	* cpphash.h (HAVE_DESIGNATED_INITIALIZERS): New. Use it.
	(trigraph_map): Declaration moved from cpplex.c

	* cppinit.c: Define trigraph_map.  Use UCHAR_MAX + 1 instead
	of 256.  Use consistent test for designated initializers.
	(cpp_init): Initialize trigraph_map.
	(initialize_standard_includes, parse_option):  Use memcmp
	instead of strncmp.

	* cpplex.c (init_trigraph_map): Remove.

	* cpplib.c (str_match, WARNING, ERROR, ICE): Delete.
	(do_unassert): Remove unused "next" local.
	(cpp_defined): Delete unused function.

	* cpplib.h (cpp_defined): Remove prototype.

Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpphash.h,v
retrieving revision 1.68
diff -u -p -r1.68 cpphash.h
--- cpphash.h	2000/08/02 01:13:42	1.68
+++ cpphash.h	2000/08/17 20:50:20
@@ -165,13 +165,17 @@ struct spec_nodes
 #define is_nvspace(x)	((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace)
 #define is_space(x)	(_cpp_IStable[x] & ISspace)
 
-/* This table is constant if it can be initialized at compile time,
+#define HAVE_DESIGNATED_INITIALIZERS \
+  (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
+/* These tables are constant if they can be initialized at compile time,
    which is the case if cpp was compiled with GCC >=2.7, or another
    compiler that supports C99.  */
-#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
-extern const unsigned char _cpp_IStable[256];
+#if HAVE_DESIGNATED_INITIALIZERS
+extern const unsigned char _cpp_IStable[UCHAR_MAX + 1];
+extern const unsigned char trigraph_map[UCHAR_MAX + 1];
 #else
-extern unsigned char _cpp_IStable[256];
+extern unsigned char _cpp_IStable[UCHAR_MAX + 1];
+extern unsigned char trigraph_map[UCHAR_MAX + 1];
 #endif
 
 /* Macros.  */
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.104
diff -u -p -r1.104 cppinit.c
--- cppinit.c	2000/08/17 18:03:58	1.104
+++ cppinit.c	2000/08/17 20:50:20
@@ -119,21 +119,34 @@ static int parse_option			PARAMS ((const
 /* Fourth argument to append_include_chain: chain to use */
 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
 
-/* If we have designated initializers (GCC >2.7) this table can be
-   initialized, constant data.  Otherwise, it has to be filled in at
+/* If we have designated initializers (GCC >2.7) these tables can be
+   initialized, constant data.  Otherwise, they have to be filled in at
    runtime.  */
+#if HAVE_DESIGNATED_INITIALIZERS
 
-#if (GCC_VERSION >= 2007)
 #define init_IStable()  /* nothing */
-#define ISTABLE __extension__ const unsigned char _cpp_IStable[256] = {
+#define ISTABLE __extension__ const U_CHAR _cpp_IStable[UCHAR_MAX + 1] = {
+
+#define init_trigraph_map()  /* nothing */
+#define TRIGRAPH_MAP \
+__extension__ const U_CHAR trigraph_map[UCHAR_MAX + 1] = {
+
 #define END };
 #define s(p, v) [p] = v,
+
 #else
-#define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
+
+#define ISTABLE unsigned char _cpp_IStable[UCHAR_MAX + 1] = { 0 }; \
  static void init_IStable PARAMS ((void)) { \
  unsigned char *x = _cpp_IStable;
+
+#define TRIGRAPH_MAP U_CHAR trigraph_map[UCHAR_MAX + 1] = { 0 }; \
+ static void init_trigraph_map PARAMS ((void)) { \
+ unsigned char *x = trigraph_map;
+
 #define END }
 #define s(p, v) x[p] = v;
+
 #endif
 
 #define A(x) s(x, ISidnum|ISidstart)
@@ -162,6 +175,12 @@ ISTABLE
   S('\0') S('\v') S('\f')
 END
 
+TRIGRAPH_MAP
+  s('=', '#')	s(')', ']')	s('!', '|')
+  s('(', '[')	s('\'', '^')	s('>', '}')
+  s('/', '\\')	s('<', '{')	s('-', '~')
+END
+
 #undef A
 #undef N
 #undef H
@@ -170,6 +189,7 @@ END
 #undef s
 #undef ISTABLE
 #undef END
+#undef TRIGRAPH_MAP
 
 /* Given a colon-separated list of file names PATH,
    add all the names to the search path for include files.  */
@@ -386,6 +406,10 @@ cpp_init (void)
   qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
 #endif
 
+  /* Set up the trigraph map for trigraph_ok, trigraph_replace and
+     lex_line.  */
+  init_trigraph_map ();
+
   /* Set up the IStable.  This doesn't do anything if we were compiled
      with a compiler that supports C99 designated initializers.  */
   init_IStable ();
@@ -720,7 +744,7 @@ initialize_standard_includes (pfile)
 		  && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
 	    {
 	      /* Does this dir start with the prefix?  */
-	      if (!strncmp (p->fname, default_prefix, default_len))
+	      if (!memcmp (p->fname, default_prefix, default_len))
 		{
 		  /* Yes; change prefix and add to search list.  */
 		  int flen = strlen (p->fname);
@@ -1087,7 +1111,7 @@ parse_option (input)
       md = (mn + mx) / 2;
 
       opt_len = cl_options[md].opt_len;
-      comp = strncmp (input, cl_options[md].opt_text, opt_len);
+      comp = memcmp (input, cl_options[md].opt_text, opt_len);
 
       if (comp > 0)
 	mn = md + 1;
@@ -1112,7 +1136,7 @@ parse_option (input)
 	      for (; mn < N_OPTS; mn++)
 		{
 		  opt_len = cl_options[mn].opt_len;
-		  if (strncmp (input, cl_options[mn].opt_text, opt_len))
+		  if (memcmp (input, cl_options[mn].opt_text, opt_len))
 		    break;
 		  if (input[opt_len] == '\0')
 		    return mn;
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.87
diff -u -p -r1.87 cpplex.c
--- cpplex.c	2000/08/09 19:41:12	1.87
+++ cpplex.c	2000/08/17 20:50:34
@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330,
 Cleanups to do:-
 
 o Check line numbers assigned to all errors.
-o Replace strncmp with memcmp almost everywhere.
 o lex_line's use of cur_token, flags and list->token_used is a bit opaque.
 o Distinguish integers, floats, and 'other' pp-numbers.
 o Store ints and char constants as binary values.
@@ -226,34 +225,6 @@ _cpp_token_spellings [N_TTYPES] = {TTYPE
 #undef OP
 #undef TK
 
-/* The following table is used by trigraph_ok/trigraph_replace.  If we
-   have designated initializers, it can be constant data; otherwise,
-   it is set up at runtime by _cpp_init_input_buffer.  */
-
-#if (GCC_VERSION >= 2007)
-#define init_trigraph_map()  /* nothing */
-#define TRIGRAPH_MAP \
-__extension__ static const U_CHAR trigraph_map[UCHAR_MAX + 1] = {
-#define END };
-#define s(p, v) [p] = v,
-#else
-#define TRIGRAPH_MAP static U_CHAR trigraph_map[UCHAR_MAX + 1] = { 0 }; \
- static void init_trigraph_map PARAMS ((void)) { \
- unsigned char *x = trigraph_map;
-#define END }
-#define s(p, v) x[p] = v;
-#endif
-
-TRIGRAPH_MAP
-  s('=', '#')	s(')', ']')	s('!', '|')
-  s('(', '[')	s('\'', '^')	s('>', '}')
-  s('/', '\\')	s('<', '{')	s('-', '~')
-END
-
-#undef TRIGRAPH_MAP
-#undef END
-#undef s
-
 /* Notify the compiler proper that the current line number has jumped,
    or the current file name has changed.  */
 
@@ -3545,7 +3516,6 @@ _cpp_init_input_buffer (pfile)
 {
   cpp_context *base;
 
-  init_trigraph_map ();
   _cpp_init_toklist (&pfile->token_list, DUMMY_TOKEN);
   pfile->no_expand_level = UINT_MAX;
   pfile->context_cap = 20;
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.c,v
retrieving revision 1.198
diff -u -p -r1.198 cpplib.c
--- cpplib.c	2000/08/17 18:01:42	1.198
+++ cpplib.c	2000/08/17 20:50:38
@@ -61,10 +61,6 @@ static cpp_hashnode *
 	    get_define_node	PARAMS ((cpp_reader *));
 static void unwind_if_stack	PARAMS ((cpp_reader *, cpp_buffer *));
 
-/* Utility.  */
-#define str_match(sym, len, str) \
-((len) == (sizeof (str) - 1) && !ustrncmp ((sym), U(str), sizeof (str) - 1))
-
 /* This is the table of directive handlers.  It is ordered by
    frequency of occurrence; the numbers at the end are directive
    counts from all the source code I have lying around (egcs and libc
@@ -1308,9 +1304,6 @@ _cpp_find_answer (node, candidate)
   return result;
 }
 
-#define WARNING(msgid) do { cpp_warning(pfile, msgid); goto error; } while (0)
-#define ERROR(msgid) do { cpp_error(pfile, msgid); goto error; } while (0)
-#define ICE(msgid) do { cpp_ice(pfile, msgid); goto error; } while (0)
 static void
 do_assert (pfile)
      cpp_reader *pfile;
@@ -1346,7 +1339,7 @@ do_unassert (pfile)
      cpp_reader *pfile;
 {
   cpp_hashnode *node;
-  struct answer *answer, *temp, *next;
+  struct answer *answer, *temp;
   
   node = _cpp_parse_assertion (pfile, &answer);
   if (node)
@@ -1442,22 +1435,6 @@ cpp_unassert (pfile, str)
 {
   _cpp_run_directive (pfile, &dtable[T_UNASSERT], str, strlen (str));
 }  
-
-/* Determine whether the identifier ID, of length LEN, is a defined macro.  */
-int
-cpp_defined (pfile, id, len)
-     cpp_reader *pfile;
-     const U_CHAR *id;
-     int len;
-{
-  cpp_hashnode *hp = cpp_lookup (pfile, id, len);
-  if (hp->type == T_POISON)
-    {
-      cpp_error (pfile, "attempt to use poisoned \"%s\"", hp->name);
-      return 0;
-    }
-  return (hp->type != T_VOID);
-}
 
 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
    If BUFFER != NULL, then use the LENGTH characters in BUFFER
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.h,v
retrieving revision 1.118
diff -u -p -r1.118 cpplib.h
--- cpplib.h	2000/08/17 17:52:48	1.118
+++ cpplib.h	2000/08/17 20:50:42
@@ -665,7 +665,6 @@ extern void cpp_free_token_list PARAMS (
 extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
 					    const unsigned char *, long));
 extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
-extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
 
 /* N.B. The error-message-printer prototypes have not been nicely
    formatted because exgettext needs to see 'msgid' on the same line


More information about the Gcc-patches mailing list