[patch] Add -CC option to cpplib to save comments in macros

Jason R Thorpe thorpej@wasabisystems.com
Wed Jan 2 15:53:00 GMT 2002


On Wed, Jan 02, 2002 at 03:25:42PM -0800, Jason R Thorpe wrote:

 > 	* doc/cpp.texi: Document the -CC option.

...and after I sent the message, I realized I forgot to include the
cpp.texi change in the patch.

Updated patch attached.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>
-------------- next part --------------
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.194
diff -c -r1.194 cppinit.c
*** cppinit.c	2001/12/15 20:31:04	1.194
--- cppinit.c	2002/01/02 23:31:55
***************
*** 492,497 ****
--- 492,498 ----
    set_lang (pfile, lang);
    CPP_OPTION (pfile, warn_import) = 1;
    CPP_OPTION (pfile, discard_comments) = 1;
+   CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1;
    CPP_OPTION (pfile, show_column) = 1;
    CPP_OPTION (pfile, tabstop) = 8;
    CPP_OPTION (pfile, operator_names) = 1;
***************
*** 1164,1169 ****
--- 1165,1171 ----
    DEF_OPT("-version",                 0,      OPT__version)                   \
    DEF_OPT("A",                        no_ass, OPT_A)                          \
    DEF_OPT("C",                        0,      OPT_C)                          \
+   DEF_OPT("CC",                       0,      OPT_CC)                         \
    DEF_OPT("D",                        no_mac, OPT_D)                          \
    DEF_OPT("H",                        0,      OPT_H)                          \
    DEF_OPT("I",                        no_dir, OPT_I)                          \
***************
*** 1435,1440 ****
--- 1437,1446 ----
  
  	case OPT_C:
  	  CPP_OPTION (pfile, discard_comments) = 0;
+ 	  break;
+ 	case OPT_CC:
+ 	  CPP_OPTION (pfile, discard_comments) = 0;
+ 	  CPP_OPTION (pfile, discard_comments_in_macro_exp) = 0;
  	  break;
  	case OPT_P:
  	  CPP_OPTION (pfile, no_line_commands) = 1;
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.287
diff -c -r1.287 cpplib.c
*** cpplib.c	2001/11/26 23:44:49	1.287
--- cpplib.c	2002/01/02 23:31:56
***************
*** 389,394 ****
--- 389,401 ----
  
    if (dir)
      {
+       /* If we are processing a `#define' directive and we have been
+ 	 requested to expand comments into macros, then re-enable
+ 	 saving of comments.  */
+       if (dir == &dtable[T_DEFINE])
+         pfile->state.save_comments =
+           ! CPP_OPTION (pfile, discard_comments_in_macro_exp);
+ 
        pfile->directive = dir;
        (*pfile->directive->handler) (pfile);
      }
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.198
diff -c -r1.198 cpplib.h
*** cpplib.h	2001/11/15 10:00:27	1.198
--- cpplib.h	2002/01/02 23:31:59
***************
*** 252,257 ****
--- 252,261 ----
    /* Nonzero means don't copy comments into the output file.  */
    unsigned char discard_comments;
  
+   /* Nonzero means don't copy comments into the output file during
+      macro expansion.  */
+   unsigned char discard_comments_in_macro_exp;
+ 
    /* Nonzero means process the ISO trigraph sequences.  */
    unsigned char trigraphs;
  
Index: doc/cpp.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/cpp.texi,v
retrieving revision 1.20
diff -c -r1.20 cpp.texi
*** cpp.texi	2001/12/10 11:26:59	1.20
--- cpp.texi	2002/01/02 23:32:44
***************
*** 4235,4240 ****
--- 4235,4247 ----
  directive line have the effect of turning that line into an ordinary
  source line, since the first token on the line is no longer a @samp{#}.
  
+ @item -CC
+ Do not discard comments, including during macro expansion.  This is
+ like @option{-C}, except that comments contained within macros are
+ also passed through to the output file where the macro is expanded.
+ 
+ The @option{-CC} option is generally used to support lint comments.
+ 
  @item -gcc
  Define the macros @sc{__gnuc__}, @sc{__gnuc_minor__} and
  @sc{__gnuc_patchlevel__}.  These are defined automatically when you use


More information about the Gcc-patches mailing list