This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Create CPP hashnode accessors


This patch implements accessors to the len and name elements of a
cpp_hashnode.  This is in preparation for them being obtained from
a different place.

I'll commit this once it's bootstrapped.

Neil.

	* cppexp.c (lex): Use NODE_NAME and NODE_LEN.
	* cpphash.c (_cpp_lookup_with_hash): Similarly.
	* cpplex.c (cpp_ideq, parse_identifier, cpp_token_len,
	cpp_spell_token, cpp_output_token): Similarly.
	* cpplib.c (lex_macro_node, do_undef, do_pragma,
	do_pragma_poison, parse_assertion, do_assert): Similarly.
	* cppmacro.c (builtin_macro, parse_args, funlike_invocation_p,
	save_parameter, _cpp_create_definition, check_trad_stringification,
	cpp_macro_definition): Similarly.
	* cppmain.c (cb_define, cb_undef, dump_macro): Similarly.
	* c-lex.c (cb_undef, c_lex): Similarly.
	* fix-header.c (recognized_function): Similarly.
	* cpplib.h (NODE_LEN, NODE_NAME): New.
	(cpp_hashnode): Rename length len.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.136
diff -u -p -r1.136 c-lex.c
--- c-lex.c	2001/05/11 23:48:20	1.136
+++ c-lex.c	2001/05/16 18:29:46
@@ -347,7 +347,7 @@ cb_undef (pfile, node)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      cpp_hashnode *node;
 {
-  debug_undef (lineno, (const char *) node->name);
+  debug_undef (lineno, (const char *) NODE_NAME (node));
 }
 
 /* Parse a '\uNNNN' or '\UNNNNNNNN' sequence.
@@ -997,7 +997,7 @@ c_lex (value)
       goto retry;
       
     case CPP_NAME:
-      *value = get_identifier ((const char *)tok.val.node->name);
+      *value = get_identifier ((const char *) NODE_NAME (tok.val.node));
       break;
 
     case CPP_INT:
Index: cppexp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppexp.c,v
retrieving revision 1.91
diff -u -p -r1.91 cppexp.c
--- cppexp.c	2001/05/11 23:48:20	1.91
+++ cppexp.c	2001/05/16 18:29:49
@@ -345,7 +345,7 @@ lex (pfile, skip_evaluation, token)
 	  if (CPP_PEDANTIC (pfile)
 	      && ! cpp_defined (pfile, DSC("__bool_true_false_are_defined")))
 	    cpp_pedwarn (pfile, "ISO C++ does not permit \"%s\" in #if",
-			 token->val.node->name);
+			 NODE_NAME (token->val.node));
 	  return op;
 	}
       else
@@ -359,7 +359,8 @@ lex (pfile, skip_evaluation, token)
 	  op.value = 0;
 
 	  if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
-	    cpp_warning (pfile, "\"%s\" is not defined", token->val.node->name);
+	    cpp_warning (pfile, "\"%s\" is not defined",
+			 NODE_NAME (token->val.node));
 	  return op;
 	}
 
Index: cpphash.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.c,v
retrieving revision 1.110
diff -u -p -r1.110 cpphash.c
--- cpphash.c	2001/01/28 11:22:22	1.110
+++ cpphash.c	2001/05/16 18:29:49
@@ -136,8 +136,8 @@ _cpp_lookup_with_hash (pfile, len, hash)
     {
       unsigned int hash2;
 
-      if (entry->hash == hash && entry->length == len
-	  && !memcmp (entry->name, name, len))
+      if (entry->hash == hash && NODE_LEN (entry) == len
+	  && !memcmp (NODE_NAME (entry), name, len))
 	return entry;
 
       hash2 = 1 + hash % (size - 2);
@@ -151,8 +151,8 @@ _cpp_lookup_with_hash (pfile, len, hash)
 
 	  if (entry == NULL)
 	    break;
-	  if (entry->hash == hash && entry->length == len
-	      && !memcmp (entry->name, name, len))
+	  if (entry->hash == hash && NODE_LEN (entry) == len
+	      && !memcmp (NODE_NAME (entry), name, len))
 	    return entry;
 	}
     }
@@ -168,9 +168,9 @@ _cpp_lookup_with_hash (pfile, len, hash)
   entry->flags = 0;
   entry->directive_index = 0;
   entry->arg_index = 0;
-  entry->length = len;
+  NODE_LEN (entry) = len;
   entry->hash = hash;
-  entry->name = name;
+  NODE_NAME (entry) = name;
   entry->value.macro = 0;
 
   pfile->hashtab->nelts++;
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.140
diff -u -p -r1.140 cpplex.c
--- cpplex.c	2001/05/16 09:38:47	1.140
+++ cpplex.c	2001/05/16 18:29:54
@@ -121,7 +121,7 @@ cpp_ideq (token, string)
   if (token->type != CPP_NAME)
     return 0;
 
-  return !ustrcmp (token->val.node->name, (const U_CHAR *) string);
+  return !ustrcmp (NODE_NAME (token->val.node), (const U_CHAR *) string);
 }
 
 /* Call when meeting a newline.  Returns the character after the newline
@@ -535,7 +535,8 @@ parse_identifier (pfile, c)
     {
       /* It is allowed to poison the same identifier twice.  */
       if ((result->flags & NODE_POISONED) && !pfile->state.poisoned_ok)
-	cpp_error (pfile, "attempt to use poisoned \"%s\"", result->name);
+	cpp_error (pfile, "attempt to use poisoned \"%s\"",
+		   NODE_NAME (result));
 
       /* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the
 	 replacement list of a variadic macro.  */
@@ -1290,9 +1291,9 @@ cpp_token_len (token)
 
   switch (TOKEN_SPELL (token))
     {
-    default:		len = 0;			break;
-    case SPELL_STRING:	len = token->val.str.len;	break;
-    case SPELL_IDENT:	len = token->val.node->length;	break;
+    default:		len = 0;				break;
+    case SPELL_STRING:	len = token->val.str.len;		break;
+    case SPELL_IDENT:	len = NODE_LEN (token->val.node);	break;
     }
   /* 1 for whitespace, 4 for comment delimeters.  */
   return len + 5;
@@ -1330,8 +1331,8 @@ cpp_spell_token (pfile, token, buffer)
 
     case SPELL_IDENT:
       spell_ident:
-      memcpy (buffer, token->val.node->name, token->val.node->length);
-      buffer += token->val.node->length;
+      memcpy (buffer, NODE_NAME (token->val.node), NODE_LEN (token->val.node));
+      buffer += NODE_LEN (token->val.node);
       break;
 
     case SPELL_STRING:
@@ -1421,7 +1422,7 @@ cpp_output_token (token, fp)
 
     spell_ident:
     case SPELL_IDENT:
-      ufputs (token->val.node->name, fp);
+      ufputs (NODE_NAME (token->val.node), fp);
     break;
 
     case SPELL_STRING:
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.250
diff -u -p -r1.250 cpplib.c
--- cpplib.c	2001/05/10 00:07:22	1.250
+++ cpplib.c	2001/05/16 18:30:03
@@ -454,7 +454,7 @@ lex_macro_node (pfile)
       else if (token.flags & NAMED_OP)
 	cpp_error (pfile,
 		   "\"%s\" cannot be used as a macro name as it is an operator in C++",
-		   token.val.node->name);
+		   NODE_NAME (token.val.node));
       else
 	cpp_error (pfile, "macro names must be identifiers");
     }
@@ -464,8 +464,9 @@ lex_macro_node (pfile)
 
       /* In Objective C, some keywords begin with '@', but general
 	 identifiers do not, and you're not allowed to #define them.  */
-      if (node == pfile->spec_nodes.n_defined || node->name[0] == '@')
-	cpp_error (pfile, "\"%s\" cannot be used as a macro name", node->name);
+      if (node == pfile->spec_nodes.n_defined || NODE_NAME (node)[0] == '@')
+	cpp_error (pfile, "\"%s\" cannot be used as a macro name",
+		   NODE_NAME (node));
       else if (!(node->flags & NODE_POISONED))
 	return node;
     }
@@ -503,7 +504,7 @@ do_undef (pfile)
 	(*pfile->cb.undef) (pfile, node);
 
       if (node->flags & NODE_WARN)
-	cpp_warning (pfile, "undefining \"%s\"", node->name);
+	cpp_warning (pfile, "undefining \"%s\"", NODE_NAME (node));
 
       _cpp_free_definition (node);
     }
@@ -1031,9 +1032,6 @@ do_pragma (pfile)
 {
   const struct pragma_entry *p;
   cpp_token tok;
-  const cpp_hashnode *node;
-  const U_CHAR *name;
-  size_t len;
   int drop = 0;
 
   p = pfile->pragmas;
@@ -1044,9 +1042,10 @@ do_pragma (pfile)
   cpp_get_token (pfile, &tok);
   if (tok.type == CPP_NAME)
     {
-      node = tok.val.node;
-      name = node->name;
-      len = node->length;
+      const cpp_hashnode *node = tok.val.node;
+      const U_CHAR *name = NODE_NAME (node);
+      size_t len = NODE_LEN (node);
+
       while (p)
 	{
 	  if (strlen (p->name) == len && !memcmp (p->name, name, len))
@@ -1114,7 +1113,7 @@ do_pragma_poison (pfile)
 	continue;
 
       if (hp->type == NT_MACRO)
-	cpp_warning (pfile, "poisoning existing macro \"%s\"", hp->name);
+	cpp_warning (pfile, "poisoning existing macro \"%s\"", NODE_NAME (hp));
       _cpp_free_definition (hp);
       hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC;
     }
@@ -1542,12 +1541,12 @@ parse_assertion (pfile, answerp, type)
     cpp_error (pfile, "predicate must be an identifier");
   else if (parse_answer (pfile, answerp, type) == 0)
     {
-      unsigned int len = predicate.val.node->length;
+      unsigned int len = NODE_LEN (predicate.val.node);
       unsigned char *sym = alloca (len + 1);
 
       /* Prefix '#' to get it out of macro namespace.  */
       sym[0] = '#';
-      memcpy (sym + 1, predicate.val.node->name, len);
+      memcpy (sym + 1, NODE_NAME (predicate.val.node), len);
       result = cpp_lookup (pfile, sym, len + 1);
     }
 
@@ -1620,7 +1619,7 @@ do_assert (pfile)
 	{
 	  if (*find_answer (node, new_answer))
 	    {
-	      cpp_warning (pfile, "\"%s\" re-asserted", node->name + 1);
+	      cpp_warning (pfile, "\"%s\" re-asserted", NODE_NAME (node) + 1);
 	      return;
 	    }
 	  new_answer->next = node->value.answers;
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.170
diff -u -p -r1.170 cpplib.h
--- cpplib.h	2001/05/11 23:48:21	1.170
+++ cpplib.h	2001/05/16 18:30:04
@@ -466,17 +466,14 @@ enum builtin_type
   BT_STDC			/* `__STDC__' */
 };
 
-/* There is a slot in the hashnode for use by front ends when integrated
-   with cpplib.  It holds a tree (see tree.h) but we mustn't drag that
-   header into every user of cpplib.h.  cpplib does not do anything with
-   this slot except clear it when a new node is created.  */
-union tree_node;
+#define NODE_LEN(NODE)		(NODE->len)
+#define NODE_NAME(NODE)		(NODE->name)
 
 struct cpp_hashnode
 {
   const unsigned char *name;		/* Null-terminated name.  */
   unsigned int hash;			/* Cached hash value.  */
-  unsigned short length;		/* Length of name excluding null.  */
+  unsigned short len;			/* Length of name excluding null.  */
   unsigned short arg_index;		/* Macro argument index.  */
   unsigned char directive_index;	/* Index into directive table.  */
   ENUM_BITFIELD(node_type) type : 8;	/* Node type.  */
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.50
diff -u -p -r1.50 cppmacro.c
--- cppmacro.c	2001/03/27 21:04:55	1.50
+++ cppmacro.c	2001/05/16 18:30:04
@@ -210,7 +210,7 @@ builtin_macro (pfile, token)
       break;
 
     default:
-      cpp_ice (pfile, "invalid builtin macro \"%s\"", node->name);
+      cpp_ice (pfile, "invalid builtin macro \"%s\"", NODE_NAME (node));
       break;
     }
 
@@ -537,7 +537,7 @@ parse_args (pfile, node)
   if (type == CPP_EOF)
     {
       cpp_error (pfile, "unterminated argument list invoking macro \"%s\"",
-		 node->name);
+		 NODE_NAME (node));
       error = 1;
     }
   else if (argc < macro->paramc)
@@ -559,7 +559,7 @@ parse_args (pfile, node)
 	{
 	  cpp_error (pfile,
 		     "macro \"%s\" requires %u arguments, but only %u given",
-		     node->name, macro->paramc, argc);
+		     NODE_NAME (node), macro->paramc, argc);
 	  error = 1;
 	}
     }
@@ -570,7 +570,7 @@ parse_args (pfile, node)
 	{
 	  cpp_error (pfile,
 		     "macro \"%s\" passed %u arguments, but takes just %u",
-		     node->name, argc, macro->paramc);
+		     NODE_NAME (node), argc, macro->paramc);
 	  error = 1;
 	}
     }
@@ -610,7 +610,7 @@ funlike_invocation_p (pfile, node, list)
   else if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
     cpp_warning (pfile,
 	 "function-like macro \"%s\" must be used with arguments in traditional C",
-		 node->name);
+		 NODE_NAME (node));
 
   /* Restore original context.  */
   pfile->context = orig;
@@ -1233,7 +1233,7 @@ save_parameter (pfile, macro, node)
   /* Constraint 6.10.3.6 - duplicate parameter names.  */
   if (node->arg_index)
     {
-      cpp_error (pfile, "duplicate macro parameter \"%s\"", node->name);
+      cpp_error (pfile, "duplicate macro parameter \"%s\"", NODE_NAME (node));
       return 1;
     }
 
@@ -1475,7 +1475,7 @@ _cpp_create_definition (pfile, node)
 	{
 	  cpp_pedwarn_with_line (pfile, pfile->directive_pos.line,
 				 pfile->directive_pos.col,
-				 "\"%s\" redefined", node->name);
+				 "\"%s\" redefined", NODE_NAME (node));
 
 	  if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
 	    cpp_pedwarn_with_file_and_line (pfile,
@@ -1489,7 +1489,7 @@ _cpp_create_definition (pfile, node)
   /* Enter definition in hash table.  */
   node->type = NT_MACRO;
   node->value.macro = macro;
-  if (! ustrncmp (node->name, DSC ("__STDC_")))
+  if (! ustrncmp (NODE_NAME (node), DSC ("__STDC_")))
     node->flags |= NODE_WARN;
 
  cleanup:
@@ -1536,11 +1536,11 @@ check_trad_stringification (pfile, macro
 	{
 	  const cpp_hashnode *node = macro->params[i];
 
-	  if (node->length == len && !memcmp (p, node->name, len))
+	  if (NODE_LEN (node) == len && !memcmp (p, NODE_NAME (node), len))
 	    {
 	      cpp_warning (pfile,
 	   "macro argument \"%s\" would be stringified with -traditional.",
-			   node->name);
+			   NODE_NAME (node));
 	      break;
 	    }
 	}
@@ -1573,7 +1573,7 @@ cpp_macro_definition (pfile, node)
     {
       len += 3;		/* "()" plus possible final "." of ellipsis.  */
       for (i = 0; i < macro->paramc; i++)
-	len += macro->params[i]->length + 2; /* ", " */
+	len += NODE_LEN (macro->params[i]) + 2; /* ", " */
     }
 
   for (i = 0; i < macro->count; i++)
@@ -1581,7 +1581,7 @@ cpp_macro_definition (pfile, node)
       cpp_token *token = &macro->expansion[i];
 
       if (token->type == CPP_MACRO_ARG)
-	len += macro->params[token->val.arg_no - 1]->length;
+	len += NODE_LEN (macro->params[token->val.arg_no - 1]);
       else
 	len += cpp_token_len (token); /* Includes room for ' '.  */
       if (token->flags & STRINGIFY_ARG)
@@ -1607,8 +1607,8 @@ cpp_macro_definition (pfile, node)
 
 	  if (param != pfile->spec_nodes.n__VA_ARGS__)
 	    {
-	      memcpy (buffer, param->name, param->length);
-	      buffer += param->length;
+	      memcpy (buffer, NODE_NAME (param), NODE_LEN (param));
+	      buffer += NODE_LEN (param);
 	    }
 
 	  if (i + 1 < macro->paramc)
@@ -1634,8 +1634,9 @@ cpp_macro_definition (pfile, node)
 
 	  if (token->type == CPP_MACRO_ARG)
 	    {
-	      len = macro->params[token->val.arg_no - 1]->length;
-	      memcpy (buffer, macro->params[token->val.arg_no - 1]->name, len);
+	      len = NODE_LEN (macro->params[token->val.arg_no - 1]);
+	      memcpy (buffer,
+		      NODE_NAME (macro->params[token->val.arg_no - 1]), len);
 	      buffer += len;
 	    }
 	  else
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.64
diff -u -p -r1.64 cppmain.c
--- cppmain.c	2001/05/10 00:07:22	1.64
+++ cppmain.c	2001/05/16 18:30:06
@@ -364,7 +364,7 @@ cb_define (pfile, node)
      cpp_hashnode *node;
 {
   maybe_print_line (cpp_get_line (pfile)->output_line);
-  fprintf (print.outf, "#define %s", node->name);
+  fprintf (print.outf, "#define %s", NODE_NAME (node));
 
   /* -dD command line option.  */
   if (options->dump_macros == dump_definitions)
@@ -380,7 +380,7 @@ cb_undef (pfile, node)
      cpp_hashnode *node;
 {
   maybe_print_line (cpp_get_line (pfile)->output_line);
-  fprintf (print.outf, "#undef %s\n", node->name);
+  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
   print.lineno++;
 }
 
@@ -446,7 +446,7 @@ dump_macro (pfile, node, v)
 {
   if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
     {
-      fprintf (print.outf, "#define %s", node->name);
+      fprintf (print.outf, "#define %s", NODE_NAME (node));
       fputs ((const char *) cpp_macro_definition (pfile, node), print.outf);
       putc ('\n', print.outf);
       print.lineno++;
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.64
diff -u -p -r1.64 fix-header.c
--- fix-header.c	2001/02/03 13:33:14	1.64
+++ fix-header.c	2001/05/16 18:30:09
@@ -532,8 +532,8 @@ recognized_function (fname, line, kind, 
     missing_extern_C_count++;
 #endif
 
-  fn = lookup_std_proto ((const char *)fname->val.node->name,
-			 fname->val.node->length);
+  fn = lookup_std_proto ((const char *) NODE_NAME (fname->val.node),
+			 NODE_LEN (fname->val.node));
 
   /* Remove the function from the list of required function.  */
   if (fn)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]