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]

Some cpplib macro tweaks


This patch fixed Davids bootstrap problem, and changes
cpp_macro_definition() to dump the macro name as well as the definition.
Thus in "#define foo bar" it dumps "foo bar" and not just "bar"; it
"#define foo(x) bar" it dumps "foo(x) bar".

This should clean up your patch of a week ago considerably, Daniel,
and you shouldn't need to change the toplev.c interfaces.

I'm bootstrapping this on x86 Linux; it'll go in when it completes.

Neil.

	* cppmacro.c (make_string_token): Avoid warning.
	(cpp_macro_definition): Prepend the macro name.  Update
	comments.
	* cppmain.c (cb_define, dump_macro): Update for changes
	to cpp_macro_definition.

Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.53
diff -u -p -r1.53 cppmacro.c
--- cppmacro.c	2001/06/21 20:56:07	1.53
+++ cppmacro.c	2001/06/23 10:07:07
@@ -110,7 +110,7 @@ make_string_token (pool, token, text, le
   token->type = CPP_STRING;
   token->val.str.text = buf;
   token->val.str.len = quote_string (buf, text, len) - buf;
-  token->val.str.text[token->val.str.len] = '\0';
+  buf[token->val.str.len] = '\0';
   token->flags = 0;
 }
 
@@ -1549,9 +1549,10 @@ check_trad_stringification (pfile, macro
     }
 }
 
-/* Returns the expansion of a macro, in a format suitable to be read
-   back in again, and therefore also for DWARF 2 debugging info.
-   Caller is expected to generate the "#define NAME" bit.  The
+/* Returns the name, arguments and expansion of a macro, in a format
+   suitable to be read back in again, and therefore also for DWARF 2
+   debugging info.  e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION".
+   Caller is expected to generate the "#define" bit if needed.  The
    returned text is temporary, and automatically freed later.  */
 
 const unsigned char *
@@ -1565,15 +1566,16 @@ cpp_macro_definition (pfile, node)
 
   if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN))
     {
-      cpp_ice (pfile, "invalid hash type %d in dump_definition", node->type);
+      cpp_ice (pfile, "invalid hash type %d in cpp_macro_definition", node->type);
       return 0;
     }
 
   /* Calculate length.  */
-  len = 1;			/* ' ' */
+  len = NODE_LEN (node) + 1;			/* ' ' */
   if (macro->fun_like)
     {
-      len += 3;		/* "()" plus possible final "." of ellipsis.  */
+      len += 3;		/* "()" plus possible final "." of named
+			   varargs (we have + 2 below).  */
       for (i = 0; i < macro->paramc; i++)
 	len += NODE_LEN (macro->params[i]) + 2; /* ", " */
     }
@@ -1597,7 +1599,11 @@ cpp_macro_definition (pfile, node)
       pfile->macro_buffer = (U_CHAR *) xrealloc (pfile->macro_buffer, len);
       pfile->macro_buffer_len = len;
     }
+
+  /* Fill in the buffer.  Start with the macro name.  */
   buffer = pfile->macro_buffer;
+  memcpy (buffer, NODE_NAME (node), NODE_LEN (node));
+  buffer += NODE_LEN (node);
 
   /* Parameter names.  */
   if (macro->fun_like)
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.66
diff -u -p -r1.66 cppmain.c
--- cppmain.c	2001/05/20 06:26:35	1.66
+++ cppmain.c	2001/06/23 10:07:07
@@ -364,11 +364,13 @@ cb_define (pfile, node)
      cpp_hashnode *node;
 {
   maybe_print_line (cpp_get_line (pfile)->output_line);
-  fprintf (print.outf, "#define %s", NODE_NAME (node));
+  fputs ("#define ", print.outf);
 
   /* -dD command line option.  */
   if (options->dump_macros == dump_definitions)
     fputs ((const char *) cpp_macro_definition (pfile, node), print.outf);
+  else
+    fputs ((const char *) NODE_NAME (node), print.outf);
 
   putc ('\n', print.outf);
   print.lineno++;
@@ -446,7 +448,7 @@ dump_macro (pfile, node, v)
 {
   if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
     {
-      fprintf (print.outf, "#define %s", NODE_NAME (node));
+      fputs ("#define ", print.outf);
       fputs ((const char *) cpp_macro_definition (pfile, node), print.outf);
       putc ('\n', print.outf);
       print.lineno++;


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