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]
Other format: [Raw text]

PATCH: Removing the arg_index field from cpp_hashnode


I've attached the patch.  I've bootstrapped the compiler with it.
I should run the test-suite (once I figure out how), and I'd
like to check it into the basic-improvements branch, unless
someone sees something wrong with it.
--
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
2002-10-31  Per Bothner  <pbothner@apple.com>

	* cpplib.h (NODE_MACRO_ARG):  New flag.
	(struct cpp_hashnode):  Give _cpp_hashnode_value tag to value union.
	Remove value.operator field.  Move arg_index field to value union.
	(directive_index):  Make signed, since also used for C++ operators.
	* cppmacro.c (_cpp_save_parameter):  Use NODE_MACRO_ARG flag to
	check for duplicate parameter.  Set NODE_MACRO_ARG flag.
	Save node->value, and set node->value.arg_index.
	(_cpp_create_definition):  For each paramater, restore node->value.
	(lex_expansion_token):  Use NODE_MACRO_ARG flag, and moved arg_index.
	* cpptrad.c (scan_out_logical_line): Likewise.
	(scan_out_logical_line): Check for directive > 0.
	* cpplib.c (cpp_handle_directive):  Likewise.
	* cpplex.c (_cpp_lex_direct):  Update as value.operator is replaced
	by negative of directive_index.
	* cppinit.c (mark_named_operators):  Likewise.

Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.234.4.2
diff -u -p -r1.234.4.2 cpplib.h
--- cpplib.h	1 Oct 2002 17:31:41 -0000	1.234.4.2
+++ cpplib.h	31 Oct 2002 21:51:48 -0000
@@ -443,6 +443,7 @@ extern const char *progname;
 #define NODE_DIAGNOSTIC (1 << 3)	/* Possible diagnostic when lexed.  */
 #define NODE_WARN	(1 << 4)	/* Warn if redefined or undefined.  */
 #define NODE_DISABLED	(1 << 5)	/* A disabled macro.  */
+#define NODE_MACRO_ARG	(1 << 6)	/* Used during #define processing. */
 
 /* Different flavors of hash node.  */
 enum node_type
@@ -477,18 +478,18 @@ enum builtin_type
 struct cpp_hashnode
 {
   struct ht_identifier ident;
-  unsigned short arg_index;		/* Macro argument index.  */
-  unsigned char directive_index;	/* Index into directive table.  */
+  char directive_index;			/* Index into directive table.
+					   Negative values used for NODE_OPERATOR. */
   unsigned char rid_code;		/* Rid code - for front ends.  */
   ENUM_BITFIELD(node_type) type : 8;	/* CPP node type.  */
   unsigned char flags;			/* CPP flags.  */
 
-  union
+  union _cpp_hashnode_value
   {
     cpp_macro *macro;			/* If a macro.  */
     struct answer *answers;		/* Answers to an assertion.  */
-    enum cpp_ttype operator;		/* Code for a named operator.  */
     enum builtin_type builtin;		/* Code for a builtin macro.  */
+    unsigned short arg_index;		/* Macro argument index.  */
   } value;
 };
 
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.122.4.2
diff -u -p -r1.122.4.2 cppmacro.c
--- cppmacro.c	15 Oct 2002 01:32:47 -0000	1.122.4.2
+++ cppmacro.c	31 Oct 2002 21:51:48 -0000
@@ -1306,8 +1306,9 @@ _cpp_save_parameter (pfile, macro, node)
      cpp_macro *macro;
      cpp_hashnode *node;
 {
+  unsigned int len;
   /* Constraint 6.10.3.6 - duplicate parameter names.  */
-  if (node->arg_index)
+  if (node->flags & NODE_MACRO_ARG)
     {
       cpp_error (pfile, DL_ERROR, "duplicate macro parameter \"%s\"",
 		 NODE_NAME (node));
@@ -1319,7 +1320,17 @@ _cpp_save_parameter (pfile, macro, node)
     _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_hashnode *));
 
   ((cpp_hashnode **) BUFF_FRONT (pfile->a_buff))[macro->paramc++] = node;
-  node->arg_index = macro->paramc;
+  node->flags |= NODE_MACRO_ARG;
+  len = macro->paramc * sizeof (union _cpp_hashnode_value);
+  if (len > pfile->macro_buffer_len)
+    {
+      pfile->macro_buffer = (uchar *) xrealloc (pfile->macro_buffer, len);
+      pfile->macro_buffer_len = len;
+    }
+  ((union _cpp_hashnode_value *) pfile->macro_buffer)[macro->paramc - 1]
+    = node->value;
+  
+  node->value.arg_index  = macro->paramc;
   return false;
 }
 
@@ -1430,10 +1441,11 @@ lex_expansion_token (pfile, macro)
   token = _cpp_lex_direct (pfile);
 
   /* Is this a parameter?  */
-  if (token->type == CPP_NAME && token->val.node->arg_index)
+  if (token->type == CPP_NAME
+      && (token->val.node->flags & NODE_MACRO_ARG) != 0)
     {
       token->type = CPP_MACRO_ARG;
-      token->val.arg_no = token->val.node->arg_index;
+      token->val.arg_no = token->val.node->value.arg_index;
     }
   else if (CPP_WTRADITIONAL (pfile) && macro->paramc > 0
 	   && (token->type == CPP_STRING || token->type == CPP_CHAR))
@@ -1583,7 +1595,11 @@ _cpp_create_definition (pfile, node)
 
   /* Clear the fast argument lookup indices.  */
   for (i = macro->paramc; i-- > 0; )
-    macro->params[i]->arg_index = 0;
+    {
+      struct cpp_hashnode *node = macro->params[i];
+      node->flags &= ~ NODE_MACRO_ARG;
+      node->value = ((union _cpp_hashnode_value *) pfile->macro_buffer)[i];
+    }
 
   if (!ok)
     return ok;
Index: cpptrad.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpptrad.c,v
retrieving revision 1.27
diff -u -p -r1.27 cpptrad.c
--- cpptrad.c	23 Jul 2002 22:57:44 -0000	1.27
+++ cpptrad.c	31 Oct 2002 21:51:48 -0000
@@ -597,12 +597,12 @@ scan_out_logical_line (pfile, macro)
 		      goto new_context;
 		    }
 		}
-	      else if (macro && node->arg_index)
+	      else if (macro && (node->flags & NODE_MACRO_ARG) != 0)
 		{
 		  /* Found a parameter in the replacement text of a
 		     #define.  Remove its name from the output.  */
 		  pfile->out.cur = out_start;
-		  save_replacement_text (pfile, macro, node->arg_index);
+		  save_replacement_text (pfile, macro, node->value.arg_index);
 		  out = pfile->out.base;
 		}
 	      else if (lex_state == ls_hash)
@@ -710,7 +710,7 @@ scan_out_logical_line (pfile, macro)
 		  else if (is_idstart (*cur))
 		    /* Check whether we know this directive, but don't
 		       advance.  */
-		    do_it = lex_identifier (pfile, cur)->directive_index != 0;
+		    do_it = lex_identifier (pfile, cur)->directive_index > 0;
 
 		  if (do_it || CPP_OPTION (pfile, lang) != CLK_ASM)
 		    {
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.321.4.3
diff -u -p -r1.321.4.3 cpplib.c
--- cpplib.c	1 Oct 2002 17:31:41 -0000	1.321.4.3
+++ cpplib.c	31 Oct 2002 21:51:48 -0000
@@ -364,7 +364,7 @@ _cpp_handle_directive (pfile, indented)
 
   if (dname->type == CPP_NAME)
     {
-      if (dname->val.node->directive_index)
+      if (dname->val.node->directive_index > 0)
 	dir = &dtable[dname->val.node->directive_index - 1];
     }
   /* We do not recognize the # followed by a number extension in
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.212.4.2
diff -u -p -r1.212.4.2 cpplex.c
--- cpplex.c	1 Oct 2002 17:31:40 -0000	1.212.4.2
+++ cpplex.c	31 Oct 2002 21:51:48 -0000
@@ -1071,7 +1071,7 @@ _cpp_lex_direct (pfile)
       if (result->val.node->flags & NODE_OPERATOR)
 	{
 	  result->flags |= NAMED_OP;
-	  result->type = result->val.node->value.operator;
+	  result->type = - result->val.node->directive_index;
 	}
       break;
 
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.260.2.3
diff -u -p -r1.260.2.3 cppinit.c
--- cppinit.c	15 Oct 2002 01:32:47 -0000	1.260.2.3
+++ cppinit.c	31 Oct 2002 21:51:48 -0000
@@ -710,7 +710,7 @@ mark_named_operators (pfile)
     {
       cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
       hp->flags |= NODE_OPERATOR;
-      hp->value.operator = b->value;
+      hp->directive_index = - b->value;
     }
 }
 

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